2 * Unix SMB/CIFS implementation.
3 * RPC Pipe client / server routines
4 * Almost completely rewritten by (C) Jeremy Allison 2005 - 2010
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
21 #include "srv_pipe_internal.h"
24 #define DBGC_CLASS DBGC_RPC_SRV
31 struct ndr_syntax_id rpc_interface;
32 const struct api_struct *cmds;
36 static struct rpc_table *rpc_lookup;
37 static uint32_t rpc_lookup_size;
39 bool rpc_srv_pipe_exists_by_id(const struct ndr_syntax_id *id)
43 for (i = 0; i < rpc_lookup_size; i++) {
44 if (ndr_syntax_id_equal(&rpc_lookup[i].rpc_interface, id)) {
52 bool rpc_srv_pipe_exists_by_cli_name(const char *cli_name)
56 for (i = 0; i < rpc_lookup_size; i++) {
57 if (strequal(rpc_lookup[i].pipe.clnt, cli_name)) {
65 bool rpc_srv_pipe_exists_by_srv_name(const char *srv_name)
69 for (i = 0; i < rpc_lookup_size; i++) {
70 if (strequal(rpc_lookup[i].pipe.srv, srv_name)) {
78 const char *rpc_srv_get_pipe_cli_name(const struct ndr_syntax_id *id)
82 for (i = 0; i < rpc_lookup_size; i++) {
83 if (ndr_syntax_id_equal(&rpc_lookup[i].rpc_interface, id)) {
84 return rpc_lookup[i].pipe.clnt;
91 const char *rpc_srv_get_pipe_srv_name(const struct ndr_syntax_id *id)
95 for (i = 0; i < rpc_lookup_size; i++) {
96 if (ndr_syntax_id_equal(&rpc_lookup[i].rpc_interface, id)) {
97 return rpc_lookup[i].pipe.srv;
104 uint32_t rpc_srv_get_pipe_num_cmds(const struct ndr_syntax_id *id)
108 for (i = 0; i < rpc_lookup_size; i++) {
109 if (ndr_syntax_id_equal(&rpc_lookup[i].rpc_interface, id)) {
110 return rpc_lookup[i].n_cmds;
117 const struct api_struct *rpc_srv_get_pipe_cmds(const struct ndr_syntax_id *id)
121 for (i = 0; i < rpc_lookup_size; i++) {
122 if (ndr_syntax_id_equal(&rpc_lookup[i].rpc_interface, id)) {
123 return rpc_lookup[i].cmds;
130 bool rpc_srv_get_pipe_interface_by_cli_name(const char *cli_name,
131 struct ndr_syntax_id *id)
135 for (i = 0; i < rpc_lookup_size; i++) {
136 if (strequal(rpc_lookup[i].pipe.clnt, cli_name)) {
138 *id = rpc_lookup[i].rpc_interface;
147 /*******************************************************************
148 Register commands to an RPC pipe
149 *******************************************************************/
151 NTSTATUS rpc_srv_register(int version, const char *clnt, const char *srv,
152 const struct ndr_interface_table *iface,
153 const struct api_struct *cmds, int size)
155 struct rpc_table *rpc_entry;
157 if (!clnt || !srv || !cmds) {
158 return NT_STATUS_INVALID_PARAMETER;
161 if (version != SMB_RPC_INTERFACE_VERSION) {
162 DEBUG(0,("Can't register rpc commands!\n"
163 "You tried to register a rpc module with SMB_RPC_INTERFACE_VERSION %d"
164 ", while this version of samba uses version %d!\n",
165 version,SMB_RPC_INTERFACE_VERSION));
166 return NT_STATUS_OBJECT_TYPE_MISMATCH;
169 /* Don't register the same command twice */
170 if (rpc_srv_pipe_exists_by_id(&iface->syntax_id)) {
175 * We use a temporary variable because this call can fail and
176 * rpc_lookup will still be valid afterwards. It could then succeed if
180 rpc_entry = SMB_REALLOC_ARRAY_KEEP_OLD_ON_ERROR(rpc_lookup, struct rpc_table, rpc_lookup_size);
181 if (NULL == rpc_entry) {
183 DEBUG(0, ("rpc_pipe_register_commands: memory allocation failed\n"));
184 return NT_STATUS_NO_MEMORY;
186 rpc_lookup = rpc_entry;
189 rpc_entry = rpc_lookup + (rpc_lookup_size - 1);
190 ZERO_STRUCTP(rpc_entry);
191 rpc_entry->pipe.clnt = SMB_STRDUP(clnt);
192 rpc_entry->pipe.srv = SMB_STRDUP(srv);
193 rpc_entry->rpc_interface = iface->syntax_id;
194 rpc_entry->cmds = cmds;
195 rpc_entry->n_cmds = size;