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.
9 * Copyright (C) Jeremy Allison 1998.
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
30 extern int DEBUGLEVEL;
31 extern DOM_SID global_machine_sid;
33 /***************************************************************************
35 ***************************************************************************/
36 static void lsa_reply_open_policy(prs_struct *rdata)
41 /* set up the LSA QUERY INFO response */
42 bzero(&(r_o.pol.data), POL_HND_SIZE);
43 for (i = 4; i < POL_HND_SIZE; i++)
49 /* store the response in the SMB stream */
50 lsa_io_r_open_pol("", &r_o, rdata, 0);
53 /***************************************************************************
55 ***************************************************************************/
56 static void make_dom_query(DOM_QUERY *d_q, char *dom_name, DOM_SID *dom_sid)
58 int domlen = strlen(dom_name);
60 d_q->uni_dom_max_len = domlen * 2;
61 d_q->uni_dom_str_len = domlen * 2;
63 d_q->buffer_dom_name = 4; /* domain buffer pointer */
64 d_q->buffer_dom_sid = 2; /* domain sid pointer */
66 /* this string is supposed to be character short */
67 make_unistr2(&(d_q->uni_domain_name), dom_name, domlen);
69 make_dom_sid2(&(d_q->dom_sid), dom_sid);
72 /***************************************************************************
74 ***************************************************************************/
75 static void lsa_reply_enum_trust_dom(LSA_Q_ENUM_TRUST_DOM *q_e,
77 uint32 enum_context, char *dom_name, DOM_SID *dom_sid)
79 LSA_R_ENUM_TRUST_DOM r_e;
81 /* set up the LSA QUERY INFO response */
82 make_r_enum_trust_dom(&r_e, enum_context, dom_name, dom_sid,
83 dom_name != NULL ? 0x0 : 0x80000000 | NT_STATUS_UNABLE_TO_FREE_VM);
85 /* store the response in the SMB stream */
86 lsa_io_r_enum_trust_dom("", &r_e, rdata, 0);
89 /***************************************************************************
91 ***************************************************************************/
92 static void lsa_reply_query_info(LSA_Q_QUERY_INFO *q_q, prs_struct *rdata,
93 char *dom_name, DOM_SID *dom_sid)
97 /* set up the LSA QUERY INFO response */
99 r_q.undoc_buffer = 0x22000000; /* bizarre */
100 r_q.info_class = q_q->info_class;
102 make_dom_query(&r_q.dom.id5, dom_name, dom_sid);
106 /* store the response in the SMB stream */
107 lsa_io_r_query("", &r_q, rdata, 0);
110 /***************************************************************************
113 pretty much hard-coded choice of "other" sids, unfortunately...
115 ***************************************************************************/
116 static void make_dom_ref(DOM_R_REF *ref, char *dom_name, DOM_SID *dom_sid,
117 DOM_SID *other_sid1, DOM_SID *other_sid2, DOM_SID *other_sid3)
119 int len_dom_name = strlen(dom_name);
121 ref->undoc_buffer = 1;
122 ref->num_ref_doms_1 = 4;
123 ref->buffer_dom_name = 1;
124 ref->max_entries = 32;
125 ref->num_ref_doms_2 = 4;
127 make_uni_hdr2(&(ref->hdr_dom_name ), len_dom_name , len_dom_name , 0);
128 make_uni_hdr2(&(ref->hdr_ref_dom[0]), sizeof(DOM_SID), sizeof(DOM_SID), 0);
129 make_uni_hdr2(&(ref->hdr_ref_dom[1]), sizeof(DOM_SID), sizeof(DOM_SID), 0);
130 make_uni_hdr2(&(ref->hdr_ref_dom[2]), sizeof(DOM_SID), sizeof(DOM_SID), 0);
132 if (dom_name != NULL)
134 make_unistr(&(ref->uni_dom_name), dom_name);
137 make_dom_sid2(&(ref->ref_dom[0]), dom_sid );
138 make_dom_sid2(&(ref->ref_dom[1]), other_sid1);
139 make_dom_sid2(&(ref->ref_dom[2]), other_sid2);
140 make_dom_sid2(&(ref->ref_dom[3]), other_sid3);
143 /***************************************************************************
144 make_reply_lookup_rids
145 ***************************************************************************/
146 static void make_reply_lookup_rids(LSA_R_LOOKUP_RIDS *r_l,
147 int num_entries, uint32 dom_rids[MAX_LOOKUP_SIDS],
148 char *dom_name, DOM_SID *dom_sid,
149 DOM_SID *other_sid1, DOM_SID *other_sid2, DOM_SID *other_sid3)
153 make_dom_ref(&(r_l->dom_ref), dom_name, dom_sid,
154 other_sid1, other_sid2, other_sid3);
156 r_l->num_entries = num_entries;
157 r_l->undoc_buffer = 1;
158 r_l->num_entries2 = num_entries;
160 for (i = 0; i < num_entries; i++)
162 make_dom_rid2(&(r_l->dom_rid[i]), dom_rids[i]);
165 r_l->num_entries3 = num_entries;
168 /***************************************************************************
170 ***************************************************************************/
171 static void make_lsa_trans_names(LSA_TRANS_NAME_ENUM *trn,
172 int num_entries, DOM_SID2 sid[MAX_LOOKUP_SIDS],
179 for (i = 0; i < num_entries; i++)
181 uint32 rid = 0xffffffff;
182 uint8 num_auths = sid[i].sid.num_auths;
186 trn->ptr_name[i] = 0;
187 trn->ptr_name[(*total)] = 0;
189 /* find the rid to look up */
192 rid = sid[i].sid.sub_auths[num_auths-1];
194 status = 0xC0000000 | NT_STATUS_NONE_MAPPED;
196 status = (status != 0x0) ? lookup_user_name (rid, name, &type) : status;
197 status = (status != 0x0) ? lookup_group_name(rid, name, &type) : status;
198 status = (status != 0x0) ? lookup_alias_name(rid, name, &type) : status;
203 trn->ptr_name[i] = 1;
204 make_lsa_trans_name(&(trn->name[(*total)]), type, name, (*total));
209 trn->num_entries = (*total);
210 trn->ptr_trans_names = 1;
211 trn->num_entries2 = (*total);
214 /***************************************************************************
215 make_reply_lookup_sids
216 ***************************************************************************/
217 static void make_reply_lookup_sids(LSA_R_LOOKUP_SIDS *r_l,
218 DOM_R_REF *ref, LSA_TRANS_NAME_ENUM *names,
219 uint32 mapped_count, uint32 status)
223 r_l->mapped_count = mapped_count;
224 r_l->status = status;
227 /***************************************************************************
228 lsa_reply_lookup_sids
229 ***************************************************************************/
230 static void lsa_reply_lookup_sids(prs_struct *rdata,
231 int num_entries, DOM_SID2 sid[MAX_LOOKUP_SIDS],
232 char *dom_name, DOM_SID *dom_sid,
233 DOM_SID *other_sid1, DOM_SID *other_sid2, DOM_SID *other_sid3)
235 LSA_R_LOOKUP_SIDS r_l;
237 LSA_TRANS_NAME_ENUM names;
238 uint32 mapped_count = 0;
240 /* set up the LSA Lookup SIDs response */
241 make_dom_ref(&ref, dom_name, dom_sid, other_sid1, other_sid2, other_sid3);
242 make_lsa_trans_names(&names, num_entries, sid, &mapped_count);
243 make_reply_lookup_sids(&r_l, &ref, &names, mapped_count, 0x0);
245 /* store the response in the SMB stream */
246 lsa_io_r_lookup_sids("", &r_l, rdata, 0);
249 /***************************************************************************
250 lsa_reply_lookup_rids
251 ***************************************************************************/
252 static void lsa_reply_lookup_rids(prs_struct *rdata,
253 int num_entries, uint32 dom_rids[MAX_LOOKUP_SIDS],
254 char *dom_name, DOM_SID *dom_sid,
255 DOM_SID *other_sid1, DOM_SID *other_sid2, DOM_SID *other_sid3)
257 LSA_R_LOOKUP_RIDS r_l;
259 /* set up the LSA Lookup RIDs response */
260 make_reply_lookup_rids(&r_l, num_entries, dom_rids,
261 dom_name, dom_sid, other_sid1, other_sid2, other_sid3);
264 /* store the response in the SMB stream */
265 lsa_io_r_lookup_rids("", &r_l, rdata, 0);
268 /***************************************************************************
270 ***************************************************************************/
271 static void api_lsa_open_policy( int uid, prs_struct *data,
276 /* grab the server, object attributes and desired access flag...*/
277 lsa_io_q_open_pol("", &q_o, data, 0);
279 /* lkclXXXX having decoded it, ignore all fields in the open policy! */
281 /* return a 20 byte policy handle */
282 lsa_reply_open_policy(rdata);
285 /***************************************************************************
286 api_lsa_enum_trust_dom
287 ***************************************************************************/
288 static void api_lsa_enum_trust_dom( int uid, prs_struct *data,
291 LSA_Q_ENUM_TRUST_DOM q_e;
293 /* grab the enum trust domain context etc. */
294 lsa_io_q_enum_trust_dom("", &q_e, data, 0);
296 /* construct reply. return status is always 0x0 */
297 lsa_reply_enum_trust_dom(&q_e, rdata,
301 /***************************************************************************
303 ***************************************************************************/
304 static void api_lsa_query_info( int uid, prs_struct *data,
307 LSA_Q_QUERY_INFO q_i;
310 /* grab the info class and policy handle */
311 lsa_io_q_query("", &q_i, data, 0);
313 pstrcpy(dom_name, lp_workgroup());
315 /* construct reply. return status is always 0x0 */
316 lsa_reply_query_info(&q_i, rdata, dom_name, &global_machine_sid);
319 /***************************************************************************
321 ***************************************************************************/
322 static void api_lsa_lookup_sids( int uid, prs_struct *data,
325 LSA_Q_LOOKUP_SIDS q_l;
331 /* grab the info class and policy handle */
332 lsa_io_q_lookup_sids("", &q_l, data, 0);
334 pstrcpy(dom_name, lp_workgroup());
336 string_to_sid(&sid_S_1_1, "S-1-1");
337 string_to_sid(&sid_S_1_3, "S-1-3");
338 string_to_sid(&sid_S_1_5, "S-1-5");
340 /* construct reply. return status is always 0x0 */
341 lsa_reply_lookup_sids(rdata,
342 q_l.sids.num_entries, q_l.sids.sid, /* SIDs */
343 dom_name, &global_machine_sid, /* domain name, domain SID */
344 &sid_S_1_1, &sid_S_1_3, &sid_S_1_5); /* the three other SIDs */
347 /***************************************************************************
349 ***************************************************************************/
350 static void api_lsa_lookup_names( int uid, prs_struct *data,
354 LSA_Q_LOOKUP_RIDS q_l;
359 uint32 dom_rids[MAX_LOOKUP_SIDS];
362 /* grab the info class and policy handle */
363 lsa_io_q_lookup_rids("", &q_l, data, 0);
365 pstrcpy(dom_name, lp_workgroup());
367 string_to_sid(&sid_S_1_1, "S-1-1");
368 string_to_sid(&sid_S_1_3, "S-1-3");
369 string_to_sid(&sid_S_1_5, "S-1-5");
371 /* convert received RIDs to strings, so we can do them. */
372 for (i = 0; i < q_l.num_entries; i++)
374 char *user_name = unistr2(q_l.lookup_name[i].str.buffer);
375 if (!pdb_name_to_rid(user_name, &dom_rids[i], &dummy_g_rid))
377 /* WHOOPS! we should really do something about this... */
382 /* construct reply. return status is always 0x0 */
383 lsa_reply_lookup_rids(rdata,
384 q_l.num_entries, dom_rids, /* text-converted SIDs */
385 dom_name, &global_machine_sid, /* domain name, domain SID */
386 &sid_S_1_1, &sid_S_1_3, &sid_S_1_5); /* the three other SIDs */
389 /***************************************************************************
391 ***************************************************************************/
392 static void api_lsa_close( int uid, prs_struct *data,
395 /* XXXX this is NOT good */
396 char *q = mem_data(&(rdata->data), rdata->offset);
398 SIVAL(q, 0, 0); q += 4;
399 SIVAL(q, 0, 0); q += 4;
400 SIVAL(q, 0, 0); q += 4;
401 SIVAL(q, 0, 0); q += 4;
402 SIVAL(q, 0, 0); q += 4;
403 SIVAL(q, 0, 0); q += 4;
408 /***************************************************************************
410 ***************************************************************************/
411 static void api_lsa_open_secret( int uid, prs_struct *data,
414 /* XXXX this is NOT good */
415 char *q = mem_data(&(rdata->data), rdata->offset);
417 SIVAL(q, 0, 0); q += 4;
418 SIVAL(q, 0, 0); q += 4;
419 SIVAL(q, 0, 0); q += 4;
420 SIVAL(q, 0, 0); q += 4;
421 SIVAL(q, 0, 0); q += 4;
422 SIVAL(q, 0, 0xC0000000 | NT_STATUS_OBJECT_NAME_NOT_FOUND); q += 4;
427 /***************************************************************************
429 ***************************************************************************/
430 static struct api_struct api_lsa_cmds[] =
432 { "LSA_OPENPOLICY" , LSA_OPENPOLICY , api_lsa_open_policy },
433 { "LSA_QUERYINFOPOLICY" , LSA_QUERYINFOPOLICY , api_lsa_query_info },
434 { "LSA_ENUMTRUSTDOM" , LSA_ENUMTRUSTDOM , api_lsa_enum_trust_dom },
435 { "LSA_CLOSE" , LSA_CLOSE , api_lsa_close },
436 { "LSA_OPENSECRET" , LSA_OPENSECRET , api_lsa_open_secret },
437 { "LSA_LOOKUPSIDS" , LSA_LOOKUPSIDS , api_lsa_lookup_sids },
438 { "LSA_LOOKUPNAMES" , LSA_LOOKUPNAMES , api_lsa_lookup_names },
442 /***************************************************************************
444 ***************************************************************************/
445 BOOL api_ntlsa_rpc(pipes_struct *p, prs_struct *data)
447 return api_rpcTNP(p, "api_ntlsa_rpc", api_lsa_cmds, data);