3 * Unix SMB/Netbios implementation.
5 * RPC Pipe client / server routines
6 * Copyright (C) Andrew Tridgell 1992-1997,
7 * Copyright (C) Luke Kenneth Casson Leighton 1996-1997,
8 * Copyright (C) Paul Ashton 1997.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 extern int DEBUGLEVEL;
32 /*******************************************************************
34 ********************************************************************/
35 static void svc_reply_close(SVC_Q_CLOSE *q_r,
40 /* set up the REG unknown_1 response */
41 bzero(r_u.pol.data, POL_HND_SIZE);
43 /* close the policy handle */
44 if (close_lsa_policy_hnd(&(q_r->pol)))
50 r_u.status = 0xC0000000 | NT_STATUS_OBJECT_NAME_INVALID;
53 DEBUG(5,("svc_unknown_1: %d\n", __LINE__));
55 /* store the response in the SMB stream */
56 svc_io_r_close("", &r_u, rdata, 0);
58 DEBUG(5,("svc_unknown_1: %d\n", __LINE__));
61 /*******************************************************************
63 ********************************************************************/
64 static void api_svc_close( uint16 vuid, prs_struct *data,
68 svc_io_q_close("", &q_r, data, 0);
69 svc_reply_close(&q_r, rdata);
73 /*******************************************************************
75 ********************************************************************/
76 static void svc_reply_open_sc_man(SVC_Q_OPEN_SC_MAN *q_u,
81 SVC_R_OPEN_SC_MAN r_u;
84 DEBUG(5,("svc_open_sc_man: %d\n", __LINE__));
86 if (status == 0x0 && !open_lsa_policy_hnd(&pol))
88 status = 0xC000000 | NT_STATUS_TOO_MANY_SECRETS; /* ha ha very droll */
91 fstrcpy(name, unistr2_to_str(&q_u->uni_srv_name));
95 DEBUG(5,("svc_open_sc_man: %s\n", name));
96 /* lkcl XXXX do a check on the name, here */
99 if (status == 0x0 && !set_lsa_policy_reg_name(&pol, name))
101 status = 0xC000000 | NT_STATUS_TOO_MANY_SECRETS; /* ha ha very droll */
104 make_svc_r_open_sc_man(&r_u, &pol, status);
106 /* store the response in the SMB stream */
107 svc_io_r_open_sc_man("", &r_u, rdata, 0);
109 DEBUG(5,("svc_open_sc_man: %d\n", __LINE__));
112 /*******************************************************************
114 ********************************************************************/
115 static void api_svc_open_sc_man( uint16 vuid, prs_struct *data,
118 SVC_Q_OPEN_SC_MAN q_u;
119 svc_io_q_open_sc_man("", &q_u, data, 0);
120 svc_reply_open_sc_man(&q_u, rdata);
123 static char *dummy_services[] =
135 /*******************************************************************
136 svc_reply_enum_svcs_status
137 ********************************************************************/
138 static void svc_reply_enum_svcs_status(SVC_Q_ENUM_SVCS_STATUS *q_u,
141 uint32 dos_status = 0;
142 SVC_R_ENUM_SVCS_STATUS r_u;
143 ENUM_SRVC_STATUS *svcs = NULL;
146 int i = get_enum_hnd(&q_u->resume_hnd);
147 uint32 resume_hnd = 0;
148 int max_buf_size = 0x80;
152 DEBUG(5,("svc_enum_svcs_status: %d\n", __LINE__));
154 if (dos_status == 0x0 && find_lsa_policy_by_hnd(&q_u->pol) == -1)
156 dos_status = 0xC000000 | NT_STATUS_INVALID_HANDLE;
159 if (dos_status == 0x0)
161 DEBUG(5,("svc_enum_svcs_status:\n"));
162 while (dummy_services[i] != NULL)
165 ENUM_SRVC_STATUS *svc = NULL;
167 buf_size += strlen(dummy_services[i] + 1) * 2;
168 buf_size += 9 * sizeof(uint32);
170 DEBUG(10,("buf_size: %d q_u->buf_size: %d\n",
171 buf_size, q_u->buf_size));
173 if (buf_size > q_u->buf_size)
175 if (buf_size >= max_buf_size)
183 svcs = Realloc(svcs, num_svcs * sizeof(ENUM_SRVC_STATUS));
186 dos_status = ERRnomem;
191 svc = &svcs[num_svcs-1];
194 make_unistr(&svc->uni_srvc_name, dummy_services[i]);
195 make_unistr(&svc->uni_disp_name, dummy_services[i]);
197 DEBUG(10,("show service: %s\n", dummy_services[i]));
203 * check for finished condition: no resume handle and last buffer fits
206 if (resume_hnd == 0 && buf_size <= q_u->buf_size)
208 /* this indicates, along with resume_hnd of 0, an end. */
212 make_svc_r_enum_svcs_status(&r_u, svcs, max_buf_size, num_svcs, resume_hnd, dos_status);
214 /* store the response in the SMB stream */
215 svc_io_r_enum_svcs_status("", &r_u, rdata, 0);
222 DEBUG(5,("svc_enum_svcs_status: %d\n", __LINE__));
225 /*******************************************************************
226 api_svc_enum_svcs_status
227 ********************************************************************/
228 static void api_svc_enum_svcs_status( uint16 vuid, prs_struct *data,
231 SVC_Q_ENUM_SVCS_STATUS q_u;
232 svc_io_q_enum_svcs_status("", &q_u, data, 0);
233 svc_reply_enum_svcs_status(&q_u, rdata);
236 /*******************************************************************
237 array of \PIPE\svcctl operations
238 ********************************************************************/
239 static struct api_struct api_svc_cmds[] =
241 { "SVC_CLOSE" , SVC_CLOSE , api_svc_close },
242 { "SVC_OPEN_SC_MAN" , SVC_OPEN_SC_MAN , api_svc_open_sc_man },
243 { "SVC_ENUM_SVCS_STATUS", SVC_ENUM_SVCS_STATUS, api_svc_enum_svcs_status },
247 /*******************************************************************
248 receives a svcctl pipe and responds.
249 ********************************************************************/
250 BOOL api_svcctl_rpc(pipes_struct *p, prs_struct *data)
252 return api_rpcTNP(p, "api_svc_rpc", api_svc_cmds, data);