lib: Fix the 32-bit build
[Samba.git] / librpc / ndr / ndr_table.c
blobf64e5ac4d20afdfe46a68ea603f6f54eb5ac37c4
1 /*
2 Unix SMB/CIFS implementation.
4 dcerpc utility functions
6 Copyright (C) Andrew Tridgell 2003
7 Copyright (C) Jelmer Vernooij 2004
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "includes.h"
24 #include "../lib/util/dlinklist.h"
25 #include "librpc/ndr/libndr.h"
26 #include "librpc/ndr/ndr_table.h"
27 #undef strcasecmp
29 static struct ndr_interface_list *ndr_interfaces;
32 register a ndr interface table
34 NTSTATUS ndr_table_register(const struct ndr_interface_table *table)
36 struct ndr_interface_list *l;
38 for (l = ndr_interfaces; l; l = l->next) {
39 if (GUID_equal(&table->syntax_id.uuid, &l->table->syntax_id.uuid)) {
40 DEBUG(0, ("Attempt to register interface %s which has the "
41 "same UUID as already registered interface %s\n",
42 table->name, l->table->name));
43 return NT_STATUS_OBJECT_NAME_COLLISION;
48 * This is a singleton instance guarenteed
49 * by the above check to be only added once
50 * into the list so we can allocate off the NULL
51 * context. We never want this to be freed
52 * until process shutdown. If needed we could
53 * add a deregister function that walks and
54 * frees the list.
57 l = talloc(NULL, struct ndr_interface_list);
58 l->table = table;
60 DLIST_ADD(ndr_interfaces, l);
62 return NT_STATUS_OK;
66 find the pipe name for a local IDL interface
68 const char *ndr_interface_name(const struct GUID *uuid, uint32_t if_version)
70 const struct ndr_interface_list *l;
71 for (l=ndr_table_list();l;l=l->next) {
72 if (GUID_equal(&l->table->syntax_id.uuid, uuid) &&
73 l->table->syntax_id.if_version == if_version) {
74 return l->table->name;
77 return "UNKNOWN";
81 find the number of calls defined by local IDL
83 int ndr_interface_num_calls(const struct GUID *uuid, uint32_t if_version)
85 const struct ndr_interface_list *l;
86 for (l=ndr_table_list();l;l=l->next){
87 if (GUID_equal(&l->table->syntax_id.uuid, uuid) &&
88 l->table->syntax_id.if_version == if_version) {
89 return l->table->num_calls;
92 return -1;
97 find a dcerpc interface by name
99 const struct ndr_interface_table *ndr_table_by_name(const char *name)
101 const struct ndr_interface_list *l;
102 for (l=ndr_table_list();l;l=l->next) {
103 if (strcasecmp(l->table->name, name) == 0) {
104 return l->table;
107 return NULL;
111 find a dcerpc interface by syntax
113 const struct ndr_interface_table *ndr_table_by_syntax(const struct ndr_syntax_id *syntax)
115 const struct ndr_interface_list *l;
116 for (l=ndr_table_list();l;l=l->next) {
117 if (ndr_syntax_id_equal(&l->table->syntax_id, syntax)) {
118 return l->table;
121 return NULL;
125 find a dcerpc interface by uuid
127 const struct ndr_interface_table *ndr_table_by_uuid(const struct GUID *uuid)
129 const struct ndr_interface_list *l;
130 for (l=ndr_table_list();l;l=l->next) {
131 if (GUID_equal(&l->table->syntax_id.uuid, uuid)) {
132 return l->table;
135 return NULL;
139 return the list of registered dcerpc_pipes
141 const struct ndr_interface_list *ndr_table_list(void)
143 ndr_table_init();
144 return ndr_interfaces;
148 NTSTATUS ndr_table_init(void)
150 static bool initialized = false;
152 if (initialized) return NT_STATUS_OK;
153 initialized = true;
155 ndr_table_register_builtin_tables();
157 return NT_STATUS_OK;