summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2009-04-18 13:31:20 +0200
committerVolker Lendecke <vl@samba.org>2009-04-18 13:58:48 +0200
commitc9bc1728f971318ab291639f34b326157e918f5f (patch)
treeb31b6334f35ffcda7d6f7e43a4feaf16df9fc3cf /source3
parentfd558b37f601b5286f227a77aa593255d75c2484 (diff)
downloadsamba-c9bc1728f971318ab291639f34b326157e918f5f.tar.gz
samba-c9bc1728f971318ab291639f34b326157e918f5f.tar.bz2
samba-c9bc1728f971318ab291639f34b326157e918f5f.zip
Add type-safe policy_handle_create/find
Diffstat (limited to 'source3')
-rw-r--r--source3/include/proto.h12
-rw-r--r--source3/rpc_server/srv_lsa_hnd.c45
2 files changed, 57 insertions, 0 deletions
diff --git a/source3/include/proto.h b/source3/include/proto.h
index 6156a475a4..8eb5c46fbd 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -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);
diff --git a/source3/rpc_server/srv_lsa_hnd.c b/source3/rpc_server/srv_lsa_hnd.c
index f233376488..e1582840c3 100644
--- a/source3/rpc_server/srv_lsa_hnd.c
+++ b/source3/rpc_server/srv_lsa_hnd.c
@@ -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;
+}