r23792: convert Samba4 to GPLv3
[ira/wip.git] / source4 / librpc / rpc / table.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    dcerpc utility functions
5
6    Copyright (C) Andrew Tridgell 2003
7    Copyright (C) Jelmer Vernooij 2004
8    
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.
13    
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.
18    
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/>.
21 */
22
23 #include "includes.h"
24 #include "lib/util/dlinklist.h"
25 #include "librpc/rpc/dcerpc.h"
26 #include "librpc/rpc/dcerpc_table.h"
27
28 struct dcerpc_interface_list *dcerpc_pipes = NULL;
29
30 /*
31   register a dcerpc client interface
32 */
33 NTSTATUS librpc_register_interface(const struct dcerpc_interface_table *interface)
34 {
35         struct dcerpc_interface_list *l;
36
37         for (l = dcerpc_pipes; l; l = l->next) {
38                 if (GUID_equal(&interface->syntax_id.uuid, &l->table->syntax_id.uuid)) {
39                         DEBUG(0, ("Attempt to register interface %s which has the "
40                                           "same UUID as already registered interface %s\n", 
41                                           interface->name, l->table->name));
42                         return NT_STATUS_OBJECT_NAME_COLLISION;
43                 }
44         }
45                 
46         l = talloc(talloc_autofree_context(), struct dcerpc_interface_list);
47         l->table = interface;
48
49         DLIST_ADD(dcerpc_pipes, l);
50         
51         return NT_STATUS_OK;
52 }
53
54 /*
55   find the pipe name for a local IDL interface
56 */
57 const char *idl_pipe_name(const struct GUID *uuid, uint32_t if_version)
58 {
59         const struct dcerpc_interface_list *l;
60         for (l=librpc_dcerpc_pipes();l;l=l->next) {
61                 if (GUID_equal(&l->table->syntax_id.uuid, uuid) &&
62                     l->table->syntax_id.if_version == if_version) {
63                         return l->table->name;
64                 }
65         }
66         return "UNKNOWN";
67 }
68
69 /*
70   find the number of calls defined by local IDL
71 */
72 int idl_num_calls(const struct GUID *uuid, uint32_t if_version)
73 {
74         const struct dcerpc_interface_list *l;
75         for (l=librpc_dcerpc_pipes();l;l=l->next){
76                 if (GUID_equal(&l->table->syntax_id.uuid, uuid) &&
77                     l->table->syntax_id.if_version == if_version) {
78                         return l->table->num_calls;
79                 }
80         }
81         return -1;
82 }
83
84
85 /*
86   find a dcerpc interface by name
87 */
88 const struct dcerpc_interface_table *idl_iface_by_name(const char *name)
89 {
90         const struct dcerpc_interface_list *l;
91         for (l=librpc_dcerpc_pipes();l;l=l->next) {
92                 if (strcasecmp(l->table->name, name) == 0) {
93                         return l->table;
94                 }
95         }
96         return NULL;
97 }
98
99 /*
100   find a dcerpc interface by uuid
101 */
102 const struct dcerpc_interface_table *idl_iface_by_uuid(const struct GUID *uuid)
103 {
104         const struct dcerpc_interface_list *l;
105         for (l=librpc_dcerpc_pipes();l;l=l->next) {
106                 if (GUID_equal(&l->table->syntax_id.uuid, uuid)) {
107                         return l->table;
108                 }
109         }
110         return NULL;
111 }
112
113 /*
114   return the list of registered dcerpc_pipes
115 */
116 const struct dcerpc_interface_list *librpc_dcerpc_pipes(void)
117 {
118         return dcerpc_pipes;
119 }
120
121
122 NTSTATUS dcerpc_register_builtin_interfaces(void);
123
124 NTSTATUS dcerpc_table_init(void)
125 {
126         static BOOL initialized = False;
127
128         if (initialized) return NT_STATUS_OK;
129         initialized = True;
130
131         dcerpc_register_builtin_interfaces();
132
133         return NT_STATUS_OK;
134 }