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);
116 /***************************************************************************
119 pretty much hard-coded choice of "other" sids, unfortunately...
121 ***************************************************************************/
122 static void make_dom_ref(DOM_R_REF *ref, char *dom_name, DOM_SID *dom_sid,
123 DOM_SID *other_sid1, DOM_SID *other_sid2, DOM_SID *other_sid3)
125 int len_dom_name = strlen(dom_name);
127 ref->undoc_buffer = 1;
128 ref->num_ref_doms_1 = 4;
129 ref->buffer_dom_name = 1;
130 ref->max_entries = 32;
131 ref->num_ref_doms_2 = 4;
133 make_uni_hdr2(&(ref->hdr_dom_name ), len_dom_name , len_dom_name , 0);
134 make_uni_hdr2(&(ref->hdr_ref_dom[0]), sizeof(DOM_SID), sizeof(DOM_SID), 0);
135 make_uni_hdr2(&(ref->hdr_ref_dom[1]), sizeof(DOM_SID), sizeof(DOM_SID), 0);
136 make_uni_hdr2(&(ref->hdr_ref_dom[2]), sizeof(DOM_SID), sizeof(DOM_SID), 0);
138 if (dom_name != NULL)
140 make_unistr(&(ref->uni_dom_name), dom_name);
143 make_dom_sid2(&(ref->ref_dom[0]), dom_sid );
144 make_dom_sid2(&(ref->ref_dom[1]), other_sid1);
145 make_dom_sid2(&(ref->ref_dom[2]), other_sid2);
146 make_dom_sid2(&(ref->ref_dom[3]), other_sid3);
149 /***************************************************************************
150 make_reply_lookup_rids
151 ***************************************************************************/
152 static void make_reply_lookup_rids(LSA_R_LOOKUP_RIDS *r_l,
153 int num_entries, uint32 dom_rids[MAX_LOOKUP_SIDS],
154 char *dom_name, DOM_SID *dom_sid,
155 DOM_SID *other_sid1, DOM_SID *other_sid2, DOM_SID *other_sid3)
159 make_dom_ref(&(r_l->dom_ref), dom_name, dom_sid,
160 other_sid1, other_sid2, other_sid3);
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 trn->ptr_name[i] = 0;
197 trn->ptr_name[(*total)] = 0;
199 SMB_ASSERT_ARRAY(sid[i].sid.sub_auths, num_auths);
201 /* find the rid to look up */
204 rid = sid[i].sid.sub_auths[num_auths-1];
206 status = 0xC0000000 | NT_STATUS_NONE_MAPPED;
208 status = (status != 0x0) ? lookup_user_name (rid, name, &type) : status;
209 status = (status != 0x0) ? lookup_group_name(rid, name, &type) : status;
210 status = (status != 0x0) ? lookup_alias_name(rid, name, &type) : status;
215 trn->ptr_name[i] = 1;
216 make_lsa_trans_name(&(trn->name[(*total)]), type, name, (*total));
221 trn->num_entries = (*total);
222 trn->ptr_trans_names = 1;
223 trn->num_entries2 = (*total);
226 /***************************************************************************
227 make_reply_lookup_sids
228 ***************************************************************************/
229 static void make_reply_lookup_sids(LSA_R_LOOKUP_SIDS *r_l,
230 DOM_R_REF *ref, LSA_TRANS_NAME_ENUM *names,
231 uint32 mapped_count, uint32 status)
235 r_l->mapped_count = mapped_count;
236 r_l->status = status;
239 /***************************************************************************
240 lsa_reply_lookup_sids
241 ***************************************************************************/
242 static void lsa_reply_lookup_sids(prs_struct *rdata,
243 int num_entries, DOM_SID2 sid[MAX_LOOKUP_SIDS],
244 char *dom_name, DOM_SID *dom_sid,
245 DOM_SID *other_sid1, DOM_SID *other_sid2, DOM_SID *other_sid3)
247 LSA_R_LOOKUP_SIDS r_l;
249 LSA_TRANS_NAME_ENUM names;
250 uint32 mapped_count = 0;
256 /* set up the LSA Lookup SIDs response */
257 make_dom_ref(&ref, dom_name, dom_sid, other_sid1, other_sid2, other_sid3);
258 make_lsa_trans_names(&names, num_entries, sid, &mapped_count);
259 make_reply_lookup_sids(&r_l, &ref, &names, mapped_count, 0x0);
261 /* store the response in the SMB stream */
262 lsa_io_r_lookup_sids("", &r_l, rdata, 0);
265 /***************************************************************************
266 lsa_reply_lookup_rids
267 ***************************************************************************/
268 static void lsa_reply_lookup_rids(prs_struct *rdata,
269 int num_entries, uint32 dom_rids[MAX_LOOKUP_SIDS],
270 char *dom_name, DOM_SID *dom_sid,
271 DOM_SID *other_sid1, DOM_SID *other_sid2, DOM_SID *other_sid3)
273 LSA_R_LOOKUP_RIDS r_l;
277 /* set up the LSA Lookup RIDs response */
278 make_reply_lookup_rids(&r_l, num_entries, dom_rids,
279 dom_name, dom_sid, other_sid1, other_sid2, other_sid3);
282 /* store the response in the SMB stream */
283 lsa_io_r_lookup_rids("", &r_l, rdata, 0);
286 /***************************************************************************
288 ***************************************************************************/
289 static void api_lsa_open_policy( uint16 vuid, prs_struct *data,
296 /* grab the server, object attributes and desired access flag...*/
297 lsa_io_q_open_pol("", &q_o, data, 0);
299 /* lkclXXXX having decoded it, ignore all fields in the open policy! */
301 /* return a 20 byte policy handle */
302 lsa_reply_open_policy(rdata);
305 /***************************************************************************
306 api_lsa_enum_trust_dom
307 ***************************************************************************/
308 static void api_lsa_enum_trust_dom( uint16 vuid, prs_struct *data,
311 LSA_Q_ENUM_TRUST_DOM q_e;
315 /* grab the enum trust domain context etc. */
316 lsa_io_q_enum_trust_dom("", &q_e, data, 0);
318 /* construct reply. return status is always 0x0 */
319 lsa_reply_enum_trust_dom(&q_e, rdata, 0, NULL, NULL);
322 /***************************************************************************
324 ***************************************************************************/
325 static void api_lsa_query_info( uint16 vuid, prs_struct *data,
328 LSA_Q_QUERY_INFO q_i;
333 /* grab the info class and policy handle */
334 lsa_io_q_query("", &q_i, data, 0);
336 pstrcpy(dom_name, lp_workgroup());
338 /* construct reply. return status is always 0x0 */
339 lsa_reply_query_info(&q_i, rdata, dom_name, &global_machine_sid);
342 /***************************************************************************
344 ***************************************************************************/
345 static void api_lsa_lookup_sids( uint16 vuid, prs_struct *data,
348 LSA_Q_LOOKUP_SIDS q_l;
355 ZERO_STRUCT(sid_S_1_1);
356 ZERO_STRUCT(sid_S_1_3);
357 ZERO_STRUCT(sid_S_1_5);
359 /* grab the info class and policy handle */
360 lsa_io_q_lookup_sids("", &q_l, data, 0);
362 pstrcpy(dom_name, lp_workgroup());
364 string_to_sid(&sid_S_1_1, "S-1-1");
365 string_to_sid(&sid_S_1_3, "S-1-3");
366 string_to_sid(&sid_S_1_5, "S-1-5");
368 /* construct reply. return status is always 0x0 */
369 lsa_reply_lookup_sids(rdata,
370 q_l.sids.num_entries, q_l.sids.sid, /* SIDs */
371 dom_name, &global_machine_sid, /* domain name, domain SID */
372 &sid_S_1_1, &sid_S_1_3, &sid_S_1_5); /* the three other SIDs */
375 /***************************************************************************
377 ***************************************************************************/
378 static void api_lsa_lookup_names( uint16 vuid, prs_struct *data,
382 LSA_Q_LOOKUP_RIDS q_l;
387 uint32 dom_rids[MAX_LOOKUP_SIDS];
391 ZERO_STRUCT(sid_S_1_1);
392 ZERO_STRUCT(sid_S_1_3);
393 ZERO_STRUCT(sid_S_1_5);
394 ZERO_ARRAY(dom_rids);
396 /* grab the info class and policy handle */
397 lsa_io_q_lookup_rids("", &q_l, data, 0);
399 pstrcpy(dom_name, lp_workgroup());
401 string_to_sid(&sid_S_1_1, "S-1-1");
402 string_to_sid(&sid_S_1_3, "S-1-3");
403 string_to_sid(&sid_S_1_5, "S-1-5");
405 SMB_ASSERT_ARRAY(q_l.lookup_name, q_l.num_entries);
407 /* convert received RIDs to strings, so we can do them. */
408 for (i = 0; i < q_l.num_entries; i++)
411 fstrcpy(user_name, unistr2(q_l.lookup_name[i].str.buffer));
413 * Map to the UNIX username.
415 map_username(user_name);
418 * Do any case conversions.
420 (void)Get_Pwnam(user_name, True);
422 if (!pdb_name_to_rid(user_name, &dom_rids[i], &dummy_g_rid))
424 /* WHOOPS! we should really do something about this... */
429 /* construct reply. return status is always 0x0 */
430 lsa_reply_lookup_rids(rdata,
431 q_l.num_entries, dom_rids, /* text-converted SIDs */
432 dom_name, &global_machine_sid, /* domain name, domain SID */
433 &sid_S_1_1, &sid_S_1_3, &sid_S_1_5); /* the three other SIDs */
436 /***************************************************************************
438 ***************************************************************************/
439 static void api_lsa_close( uint16 vuid, prs_struct *data,
442 /* XXXX this is NOT good */
443 char *q = mem_data(&(rdata->data), rdata->offset);
461 /***************************************************************************
463 ***************************************************************************/
464 static void api_lsa_open_secret( uint16 vuid, prs_struct *data,
467 /* XXXX this is NOT good */
468 char *q = mem_data(&(rdata->data), rdata->offset);
480 SIVAL(q, 0, 0xC0000000 | NT_STATUS_OBJECT_NAME_NOT_FOUND);
486 /***************************************************************************
488 ***************************************************************************/
489 static struct api_struct api_lsa_cmds[] =
491 { "LSA_OPENPOLICY" , LSA_OPENPOLICY , api_lsa_open_policy },
492 { "LSA_QUERYINFOPOLICY" , LSA_QUERYINFOPOLICY , api_lsa_query_info },
493 { "LSA_ENUMTRUSTDOM" , LSA_ENUMTRUSTDOM , api_lsa_enum_trust_dom },
494 { "LSA_CLOSE" , LSA_CLOSE , api_lsa_close },
495 { "LSA_OPENSECRET" , LSA_OPENSECRET , api_lsa_open_secret },
496 { "LSA_LOOKUPSIDS" , LSA_LOOKUPSIDS , api_lsa_lookup_sids },
497 { "LSA_LOOKUPNAMES" , LSA_LOOKUPNAMES , api_lsa_lookup_names },
501 /***************************************************************************
503 ***************************************************************************/
504 BOOL api_ntlsa_rpc(pipes_struct *p, prs_struct *data)
506 return api_rpcTNP(p, "api_ntlsa_rpc", api_lsa_cmds, data);