Add type-safe policy_handle_create/find
authorVolker Lendecke <vl@samba.org>
Sat, 18 Apr 2009 11:31:20 +0000 (13:31 +0200)
committerVolker Lendecke <vl@samba.org>
Sat, 18 Apr 2009 11:58:48 +0000 (13:58 +0200)
source3/include/proto.h
source3/rpc_server/srv_lsa_hnd.c

index 6156a475a48c925801e15509f007450d120466d8..8eb5c46fbd71d70a5d57732c5dbb03fe7aa5eff6 100644 (file)
@@ -5884,6 +5884,18 @@ bool close_policy_hnd(pipes_struct *p, struct policy_handle *hnd);
 void close_policy_by_pipe(pipes_struct *p);
 bool pipe_access_check(pipes_struct *p);
 
+NTSTATUS _policy_handle_create(struct pipes_struct *p, struct policy_handle *hnd,
+                              void *pdata, size_t size, const char *name);
+#define policy_handle_create(_p, _hnd, _ptr, _type) \
+       _policy_handle_create((_p), (_hnd), (_ptr), sizeof(_type), #_type)
+
+void *_policy_handle_find(struct pipes_struct *p,
+                         const struct policy_handle *hnd,
+                         const char *type);
+#define policy_handle_find(_p, _hnd, _type) \
+       (_type *)_policy_handle_find((_p), (_hnd), #_type)
+
+
 /* The following definitions come from rpc_server/srv_pipe.c  */
 
 bool create_next_pdu(pipes_struct *p);
index f2333764885ad1ebd28fede7a8b6d750903ab367..e1582840c38e4379f12f796ad806d600f35011ba 100644 (file)
@@ -280,3 +280,48 @@ bool pipe_access_check(pipes_struct *p)
 
        return True;
 }
+
+NTSTATUS _policy_handle_create(struct pipes_struct *p, struct policy_handle *hnd,
+                              void *pdata, size_t data_size, const char *type)
+{
+       void **ppdata = (void **)pdata;
+       void *data;
+
+       if (p->pipe_handles->count > MAX_OPEN_POLS) {
+               DEBUG(0, ("policy_handle_create: ERROR: too many handles (%d) "
+                         "on pipe %s.\n", (int)p->pipe_handles->count,
+                         get_pipe_name_from_iface(&p->syntax)));
+               return NT_STATUS_INSUFFICIENT_RESOURCES;
+       }
+
+       data = talloc_size(talloc_tos(), data_size);
+       if (data == NULL) {
+               return NT_STATUS_NO_MEMORY;
+       }
+       talloc_set_name(data, type);
+
+       if (!create_policy_hnd(p, hnd, data)) {
+               TALLOC_FREE(data);
+               return NT_STATUS_NO_MEMORY;
+       }
+       *ppdata = data;
+       return NT_STATUS_OK;
+}
+
+void *_policy_handle_find(struct pipes_struct *p,
+                         const struct policy_handle *hnd,
+                         const char *name)
+{
+       void *data;
+
+       if (find_policy_by_hnd_internal(p, hnd, &data) == NULL) {
+               return NULL;
+       }
+       if (strcmp(name, talloc_get_name(data)) != 0) {
+               DEBUG(10, ("expected %s, got %s\n", name,
+                          talloc_get_name(data)));
+               return NULL;
+       }
+       DEBUG(10, ("found handle of type %s\n", talloc_get_name(data)));
+       return data;
+}