s3-rpc_server: remove unnecessary talloc_free
[kai/samba.git] / source3 / rpc_server / rpc_handles.c
index f3a97b37a22f922e3e3d97c22af8ac5b67f2b23b..2b35328e620d5dbc0b79e3ddd14e1cd327cd702b 100644 (file)
 #include "../librpc/gen_ndr/ndr_lsa.h"
 #include "../librpc/gen_ndr/ndr_samr.h"
 #include "auth.h"
-#include "ntdomain.h"
-#include "rpc_server/rpc_ncacn_np.h"
+#include "rpc_server/rpc_pipes.h"
+#include "../libcli/security/security.h"
+#include "lib/tsocket/tsocket.h"
 
 #undef DBGC_CLASS
 #define DBGC_CLASS DBGC_RPC_SRV
 
+static struct pipes_struct *InternalPipes;
+
+/* TODO
+ * the following prototypes are declared here to avoid
+ * code being moved about too much for a patch to be
+ * disrupted / less obvious.
+ *
+ * these functions, and associated functions that they
+ * call, should be moved behind a .so module-loading
+ * system _anyway_.  so that's the next step...
+ */
+
+int make_base_pipes_struct(TALLOC_CTX *mem_ctx,
+                          struct messaging_context *msg_ctx,
+                          const char *pipe_name,
+                          enum dcerpc_transport_t transport,
+                          bool endian, bool ncalrpc_as_system,
+                          const struct tsocket_address *remote_address,
+                          const struct tsocket_address *local_address,
+                          struct pipes_struct **_p)
+{
+       struct pipes_struct *p;
+
+       p = talloc_zero(mem_ctx, struct pipes_struct);
+       if (!p) {
+               return ENOMEM;
+       }
+
+       p->mem_ctx = talloc_named(p, 0, "pipe %s %p", pipe_name, p);
+       if (!p->mem_ctx) {
+               talloc_free(p);
+               return ENOMEM;
+       }
+
+       p->msg_ctx = msg_ctx;
+       p->transport = transport;
+       p->endian = endian;
+       p->ncalrpc_as_system = ncalrpc_as_system;
+
+       p->remote_address = tsocket_address_copy(remote_address, p);
+       if (p->remote_address == NULL) {
+               talloc_free(p);
+               return ENOMEM;
+       }
+
+       if (local_address) {
+               p->local_address = tsocket_address_copy(local_address, p);
+               if (p->local_address == NULL) {
+                       talloc_free(p);
+                       return ENOMEM;
+               }
+       }
+
+       DLIST_ADD(InternalPipes, p);
+       talloc_set_destructor(p, close_internal_rpc_pipe_hnd);
+
+       *_p = p;
+       return 0;
+}
+
+
+bool check_open_pipes(void)
+{
+       struct pipes_struct *p;
+
+       for (p = InternalPipes; p != NULL; p = p->next) {
+               if (num_pipe_handles(p) != 0) {
+                       return true;
+               }
+       }
+       return false;
+}
+
+/****************************************************************************
+ Close an rpc pipe.
+****************************************************************************/
+
+static void free_pipe_rpc_context_internal(struct pipe_rpc_fns *list)
+{
+       struct pipe_rpc_fns *tmp = list;
+       struct pipe_rpc_fns *tmp2;
+
+       while (tmp) {
+               tmp2 = tmp->next;
+               SAFE_FREE(tmp);
+               tmp = tmp2;
+       }
+
+       return;
+}
+
+int close_internal_rpc_pipe_hnd(struct pipes_struct *p)
+{
+       if (!p) {
+               DEBUG(0,("Invalid pipe in close_internal_rpc_pipe_hnd\n"));
+               return False;
+       }
+
+       /* Free the handles database. */
+       close_policy_by_pipe(p);
+
+       free_pipe_rpc_context_internal( p->contexts );
+
+       DLIST_REMOVE(InternalPipes, p);
+
+       ZERO_STRUCTP(p);
+
+       return 0;
+}
+
 /*
  * Handle database - stored per pipe.
  */
@@ -81,9 +192,7 @@ bool init_pipe_handles(struct pipes_struct *p, const struct ndr_syntax_id *synta
        struct pipes_struct *plist;
        struct handle_list *hl;
 
-       for (plist = get_first_internal_pipe();
-            plist;
-            plist = get_next_internal_pipe(plist)) {
+       for (plist = InternalPipes; plist; plist = plist->next) {
                struct pipe_rpc_fns *p_ctx;
                bool stop = false;
 
@@ -346,7 +455,7 @@ bool pipe_access_check(struct pipes_struct *p)
                        return True;
                }
 
-               if (p->session_info->unix_info->guest) {
+               if (security_session_user_level(p->session_info, NULL) < SECURITY_USER) {
                        return False;
                }
        }