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)
43 /* set up the LSA QUERY INFO response */
45 for (i = 4; i < POL_HND_SIZE; i++)
51 /* store the response in the SMB stream */
52 lsa_io_r_open_pol("", &r_o, rdata, 0);
55 /***************************************************************************
57 ***************************************************************************/
58 static void make_dom_query(DOM_QUERY *d_q, char *dom_name, DOM_SID *dom_sid)
60 int domlen = strlen(dom_name);
62 d_q->uni_dom_max_len = domlen * 2;
63 d_q->uni_dom_str_len = domlen * 2;
65 d_q->buffer_dom_name = 4; /* domain buffer pointer */
66 d_q->buffer_dom_sid = 2; /* domain sid pointer */
68 /* this string is supposed to be character short */
69 make_unistr2(&(d_q->uni_domain_name), dom_name, domlen);
71 make_dom_sid2(&(d_q->dom_sid), dom_sid);
74 /***************************************************************************
76 ***************************************************************************/
77 static void lsa_reply_enum_trust_dom(LSA_Q_ENUM_TRUST_DOM *q_e,
79 uint32 enum_context, char *dom_name, DOM_SID *dom_sid)
81 LSA_R_ENUM_TRUST_DOM r_e;
85 /* set up the LSA QUERY INFO response */
86 make_r_enum_trust_dom(&r_e, enum_context, dom_name, dom_sid,
87 dom_name != NULL ? 0x0 : 0x80000000 | NT_STATUS_UNABLE_TO_FREE_VM);
89 /* store the response in the SMB stream */
90 lsa_io_r_enum_trust_dom("", &r_e, rdata, 0);
93 /***************************************************************************
95 ***************************************************************************/
96 static void lsa_reply_query_info(LSA_Q_QUERY_INFO *q_q, prs_struct *rdata,
97 char *dom_name, DOM_SID *dom_sid)
103 /* set up the LSA QUERY INFO response */
105 r_q.undoc_buffer = 0x22000000; /* bizarre */
106 r_q.info_class = q_q->info_class;
108 make_dom_query(&r_q.dom.id5, dom_name, dom_sid);
112 /* store the response in the SMB stream */
113 lsa_io_r_query("", &r_q, rdata, 0);
117 /***************************************************************************
119 ***************************************************************************/
120 static void make_dom_ref(DOM_R_REF *ref, int num_domains,
121 char **dom_names, DOM_SID **dom_sids)
126 if (num_domains > MAX_REF_DOMAINS)
128 num_domains = MAX_REF_DOMAINS;
131 ref->undoc_buffer = 1;
132 ref->num_ref_doms_1 = num_domains;
133 ref->undoc_buffer2 = 1;
134 ref->max_entries = MAX_REF_DOMAINS;
135 ref->num_ref_doms_2 = num_domains;
137 for (i = 0; i < num_domains; i++)
139 int len = dom_names[i] != NULL ? strlen(dom_names[i]) : 0;
141 make_uni_hdr(&(ref->hdr_ref_dom[i].hdr_dom_name), len, len, len != 0 ? 1 : 0);
142 ref->hdr_ref_dom[i].ptr_dom_sid = dom_sids[i] != NULL ? 1 : 0;
144 make_unistr2 (&(ref->ref_dom[i].uni_dom_name), dom_names[i], len);
145 make_dom_sid2(&(ref->ref_dom[i].ref_dom ), dom_sids [i]);
150 /***************************************************************************
151 make_reply_lookup_rids
152 ***************************************************************************/
153 static void make_reply_lookup_rids(LSA_R_LOOKUP_RIDS *r_l,
154 int num_entries, uint32 dom_rids[MAX_LOOKUP_SIDS],
156 char **dom_names, DOM_SID **dom_sids)
160 make_dom_ref(&(r_l->dom_ref), num_ref_doms, dom_names, dom_sids);
162 r_l->num_entries = num_entries;
163 r_l->undoc_buffer = 1;
164 r_l->num_entries2 = num_entries;
166 SMB_ASSERT_ARRAY(r_l->dom_rid, num_entries);
168 for (i = 0; i < num_entries; i++)
170 make_dom_rid2(&(r_l->dom_rid[i]), dom_rids[i]);
173 r_l->num_entries3 = num_entries;
176 /***************************************************************************
178 ***************************************************************************/
179 static void make_lsa_trans_names(LSA_TRANS_NAME_ENUM *trn,
180 int num_entries, DOM_SID2 sid[MAX_LOOKUP_SIDS],
187 SMB_ASSERT(num_entries <= MAX_LOOKUP_SIDS);
189 for (i = 0; i < num_entries; i++)
191 uint32 rid = 0xffffffff;
192 uint8 num_auths = sid[i].sid.num_auths;
196 SMB_ASSERT_ARRAY(sid[i].sid.sub_auths, num_auths);
198 /* find the rid to look up */
201 rid = sid[i].sid.sub_auths[num_auths-1];
203 status = 0xC0000000 | NT_STATUS_NONE_MAPPED;
205 status = (status != 0x0) ? lookup_user_name (rid, name, &type) : status;
206 status = (status != 0x0) ? lookup_group_name(rid, name, &type) : status;
207 status = (status != 0x0) ? lookup_alias_name(rid, name, &type) : status;
212 make_lsa_trans_name(&(trn->name[(*total)]), type, name, (*total));
217 trn->num_entries = (*total);
218 trn->ptr_trans_names = 1;
219 trn->num_entries2 = (*total);
222 /***************************************************************************
223 make_reply_lookup_sids
224 ***************************************************************************/
225 static void make_reply_lookup_sids(LSA_R_LOOKUP_SIDS *r_l,
226 DOM_R_REF *ref, LSA_TRANS_NAME_ENUM *names,
227 uint32 mapped_count, uint32 status)
231 r_l->mapped_count = mapped_count;
232 r_l->status = status;
235 /***************************************************************************
236 lsa_reply_lookup_sids
237 ***************************************************************************/
238 static void lsa_reply_lookup_sids(prs_struct *rdata,
239 int num_entries, DOM_SID2 sid[MAX_LOOKUP_SIDS],
241 char **dom_names, DOM_SID **dom_sids)
243 LSA_R_LOOKUP_SIDS r_l;
245 LSA_TRANS_NAME_ENUM names;
246 uint32 mapped_count = 0;
252 /* set up the LSA Lookup SIDs response */
253 make_dom_ref(&ref, num_ref_doms, dom_names, dom_sids);
254 make_lsa_trans_names(&names, num_entries, sid, &mapped_count);
255 make_reply_lookup_sids(&r_l, &ref, &names, mapped_count, 0x0);
257 /* store the response in the SMB stream */
258 lsa_io_r_lookup_sids("", &r_l, rdata, 0);
261 /***************************************************************************
262 lsa_reply_lookup_rids
263 ***************************************************************************/
264 static void lsa_reply_lookup_rids(prs_struct *rdata,
265 int num_entries, uint32 dom_rids[MAX_LOOKUP_SIDS],
267 char **dom_names, DOM_SID **dom_sids)
269 LSA_R_LOOKUP_RIDS r_l;
273 /* set up the LSA Lookup RIDs response */
274 make_reply_lookup_rids(&r_l, num_entries, dom_rids,
275 num_ref_doms, dom_names, dom_sids);
278 /* store the response in the SMB stream */
279 lsa_io_r_lookup_rids("", &r_l, rdata, 0);
282 /***************************************************************************
284 ***************************************************************************/
285 static void api_lsa_open_policy( uint16 vuid, prs_struct *data,
292 /* grab the server, object attributes and desired access flag...*/
293 lsa_io_q_open_pol("", &q_o, data, 0);
295 /* lkclXXXX having decoded it, ignore all fields in the open policy! */
297 /* return a 20 byte policy handle */
298 lsa_reply_open_policy(rdata);
301 /***************************************************************************
302 api_lsa_enum_trust_dom
303 ***************************************************************************/
304 static void api_lsa_enum_trust_dom( uint16 vuid, prs_struct *data,
307 LSA_Q_ENUM_TRUST_DOM q_e;
311 /* grab the enum trust domain context etc. */
312 lsa_io_q_enum_trust_dom("", &q_e, data, 0);
314 /* construct reply. return status is always 0x0 */
315 lsa_reply_enum_trust_dom(&q_e, rdata, 0, NULL, NULL);
318 /***************************************************************************
320 ***************************************************************************/
321 static void api_lsa_query_info( uint16 vuid, prs_struct *data,
324 LSA_Q_QUERY_INFO q_i;
329 /* grab the info class and policy handle */
330 lsa_io_q_query("", &q_i, data, 0);
332 pstrcpy(dom_name, lp_workgroup());
334 /* construct reply. return status is always 0x0 */
335 lsa_reply_query_info(&q_i, rdata, dom_name, &global_machine_sid);
338 /***************************************************************************
340 ***************************************************************************/
341 static void api_lsa_lookup_sids( uint16 vuid, prs_struct *data,
344 LSA_Q_LOOKUP_SIDS q_l;
350 DOM_SID *sid_array[4];
354 ZERO_STRUCT(sid_S_1_1);
355 ZERO_STRUCT(sid_S_1_3);
356 ZERO_STRUCT(sid_S_1_5);
358 /* grab the info class and policy handle */
359 lsa_io_q_lookup_sids("", &q_l, data, 0);
361 pstrcpy(dom_name, lp_workgroup());
363 string_to_sid(&sid_S_1_1, "S-1-1");
364 string_to_sid(&sid_S_1_3, "S-1-3");
365 string_to_sid(&sid_S_1_5, "S-1-5");
367 dom_names[0] = dom_name;
368 sid_array[0] = &global_machine_sid;
370 dom_names[1] = "Everyone";
371 sid_array[1] = &sid_S_1_1;
373 dom_names[2] = "don't know";
374 sid_array[2] = &sid_S_1_3;
376 dom_names[3] = "NT AUTHORITY";
377 sid_array[3] = &sid_S_1_5;
379 /* construct reply. return status is always 0x0 */
380 lsa_reply_lookup_sids(rdata,
381 q_l.sids.num_entries, q_l.sids.sid, /* SIDs */
382 4, dom_names, sid_array);
385 /***************************************************************************
387 ***************************************************************************/
388 static void api_lsa_lookup_names( uint16 vuid, prs_struct *data,
392 LSA_Q_LOOKUP_RIDS q_l;
394 uint32 dom_rids[MAX_LOOKUP_SIDS];
401 DOM_SID *sid_array[4];
405 ZERO_STRUCT(sid_S_1_1);
406 ZERO_STRUCT(sid_S_1_3);
407 ZERO_STRUCT(sid_S_1_5);
408 ZERO_ARRAY(dom_rids);
410 /* grab the info class and policy handle */
411 lsa_io_q_lookup_rids("", &q_l, data, 0);
413 pstrcpy(dom_name, lp_workgroup());
415 string_to_sid(&sid_S_1_1, "S-1-1");
416 string_to_sid(&sid_S_1_3, "S-1-3");
417 string_to_sid(&sid_S_1_5, "S-1-5");
419 dom_names[0] = dom_name;
420 sid_array[0] = &global_machine_sid;
422 dom_names[1] = "Everyone";
423 sid_array[1] = &sid_S_1_1;
425 dom_names[2] = "don't know";
426 sid_array[2] = &sid_S_1_3;
428 dom_names[3] = "NT AUTHORITY";
429 sid_array[3] = &sid_S_1_5;
431 SMB_ASSERT_ARRAY(q_l.lookup_name, q_l.num_entries);
433 /* convert received RIDs to strings, so we can do them. */
434 for (i = 0; i < q_l.num_entries; i++)
437 fstrcpy(user_name, unistr2(q_l.lookup_name[i].str.buffer));
439 * Map to the UNIX username.
441 map_username(user_name);
444 * Do any case conversions.
446 (void)Get_Pwnam(user_name, True);
448 if (!pdb_name_to_rid(user_name, &dom_rids[i], &dummy_g_rid))
450 /* WHOOPS! we should really do something about this... */
455 /* construct reply. return status is always 0x0 */
456 lsa_reply_lookup_rids(rdata,
457 q_l.num_entries, dom_rids, /* text-converted SIDs */
458 4, dom_names, sid_array);
461 /***************************************************************************
463 ***************************************************************************/
464 static void api_lsa_close( uint16 vuid, prs_struct *data,
467 /* XXXX this is NOT good */
468 char *q = mem_data(&(rdata->data), rdata->offset);
486 /***************************************************************************
488 ***************************************************************************/
489 static void api_lsa_open_secret( uint16 vuid, prs_struct *data,
492 /* XXXX this is NOT good */
493 char *q = mem_data(&(rdata->data), rdata->offset);
505 SIVAL(q, 0, 0xC0000000 | NT_STATUS_OBJECT_NAME_NOT_FOUND);
511 /***************************************************************************
513 ***************************************************************************/
514 static struct api_struct api_lsa_cmds[] =
516 { "LSA_OPENPOLICY" , LSA_OPENPOLICY , api_lsa_open_policy },
517 { "LSA_QUERYINFOPOLICY" , LSA_QUERYINFOPOLICY , api_lsa_query_info },
518 { "LSA_ENUMTRUSTDOM" , LSA_ENUMTRUSTDOM , api_lsa_enum_trust_dom },
519 { "LSA_CLOSE" , LSA_CLOSE , api_lsa_close },
520 { "LSA_OPENSECRET" , LSA_OPENSECRET , api_lsa_open_secret },
521 { "LSA_LOOKUPSIDS" , LSA_LOOKUPSIDS , api_lsa_lookup_sids },
522 { "LSA_LOOKUPNAMES" , LSA_LOOKUPNAMES , api_lsa_lookup_names },
526 /***************************************************************************
528 ***************************************************************************/
529 BOOL api_ntlsa_rpc(pipes_struct *p, prs_struct *data)
531 return api_rpcTNP(p, "api_ntlsa_rpc", api_lsa_cmds, data);