r7711: update callers of ldb_connect() for new syntax
[Samba/ekacnet.git] / source4 / rpc_server / handles.c
blob3cc9e8a42547210a07f82d53402fa416098b7a92
1 /*
2 Unix SMB/CIFS implementation.
4 server side dcerpc handle code
6 Copyright (C) Andrew Tridgell 2003
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include "includes.h"
24 #include "dlinklist.h"
25 #include "rpc_server/dcerpc_server.h"
28 destroy a rpc handle
30 static int dcesrv_handle_destructor(void *ptr)
32 struct dcesrv_handle *h = ptr;
33 DLIST_REMOVE(h->context->handles, h);
34 talloc_free(h);
35 return 0;
40 allocate a new rpc handle
42 struct dcesrv_handle *dcesrv_handle_new(struct dcesrv_connection_context *context,
43 uint8_t handle_type)
45 struct dcesrv_handle *h;
47 h = talloc(context, struct dcesrv_handle);
48 if (!h) {
49 return NULL;
51 h->data = NULL;
52 h->context = context;
54 h->wire_handle.handle_type = handle_type;
55 h->wire_handle.uuid = GUID_random();
57 DLIST_ADD(context->handles, h);
59 talloc_set_destructor(h, dcesrv_handle_destructor);
61 return h;
65 find an internal handle given a wire handle. If the wire handle is NULL then
66 allocate a new handle
68 struct dcesrv_handle *dcesrv_handle_fetch(struct dcesrv_connection_context *context,
69 struct policy_handle *p,
70 uint8_t handle_type)
72 struct dcesrv_handle *h;
74 if (policy_handle_empty(p)) {
75 return dcesrv_handle_new(context, handle_type);
78 for (h=context->handles; h; h=h->next) {
79 if (h->wire_handle.handle_type == p->handle_type &&
80 GUID_equal(&p->uuid, &h->wire_handle.uuid)) {
81 if (handle_type != DCESRV_HANDLE_ANY &&
82 p->handle_type != handle_type) {
83 DEBUG(0,("client gave us the wrong handle type (%d should be %d)\n",
84 p->handle_type, handle_type));
85 return NULL;
87 return h;
91 return NULL;