2 * Unix SMB/Netbios implementation.
4 * RPC Pipe client / server routines
5 * Copyright (C) Andrew Tridgell 1992-1997,
6 * Copyright (C) Luke Kenneth Casson Leighton 1996-1997,
7 * Copyright (C) Paul Ashton 1997.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 extern int DEBUGLEVEL;
30 /*******************************************************************
31 creates a LSA_TRANS_NAME structure.
32 ********************************************************************/
33 void make_lsa_trans_name(LSA_TRANS_NAME *trn, uint32 sid_name_use, char *name, uint32 idx)
35 int len_name = strlen(name);
37 trn->sid_name_use = sid_name_use;
38 make_uni_hdr(&(trn->hdr_name), len_name, len_name, len_name != 0);
39 make_unistr2(&(trn->uni_name), name, len_name);
40 trn->domain_idx = idx;
43 /*******************************************************************
44 reads or writes a LSA_TRANS_NAME structure.
45 ********************************************************************/
46 void lsa_io_trans_name(char *desc, LSA_TRANS_NAME *trn, prs_struct *ps, int depth)
48 if (trn == NULL) return;
50 prs_debug(ps, depth, desc, "lsa_io_trans_name");
55 prs_uint32("sid_name_use", ps, depth, &(trn->sid_name_use));
57 smb_io_unihdr ("hdr_name", &(trn->hdr_name), ps, depth);
58 smb_io_unistr2("uni_name", &(trn->uni_name), trn->hdr_name.buffer, ps, depth);
60 prs_uint32("domain_idx ", ps, depth, &(trn->domain_idx ));
63 /*******************************************************************
64 reads or writes a DOM_R_REF structure.
65 ********************************************************************/
66 void lsa_io_dom_r_ref(char *desc, DOM_R_REF *r_r, prs_struct *ps, int depth)
70 prs_debug(ps, depth, desc, "smb_io_dom_r_ref");
73 if (r_r == NULL) return;
77 prs_uint32("undoc_buffer ", ps, depth, &(r_r->undoc_buffer)); /* undocumented buffer pointer. */
78 prs_uint32("num_ref_doms_1 ", ps, depth, &(r_r->num_ref_doms_1)); /* num referenced domains? */
79 prs_uint32("buffer_dom_name", ps, depth, &(r_r->buffer_dom_name)); /* undocumented domain name buffer pointer. */
80 prs_uint32("max_entries ", ps, depth, &(r_r->max_entries)); /* 32 - max number of entries */
81 prs_uint32("num_ref_doms_2 ", ps, depth, &(r_r->num_ref_doms_2)); /* 4 - num referenced domains? */
83 smb_io_unihdr2("", &(r_r->hdr_dom_name), ps, depth); /* domain name unicode string header */
85 SMB_ASSERT_ARRAY(r_r->hdr_ref_dom, r_r->num_ref_doms_1-1);
87 for (i = 0; i < r_r->num_ref_doms_1-1; i++)
89 smb_io_unihdr2("", &(r_r->hdr_ref_dom[i]), ps, depth);
92 smb_io_unistr("", &(r_r->uni_dom_name), ps, depth); /* domain name unicode string */
94 SMB_ASSERT_ARRAY(r_r->ref_dom, r_r->num_ref_doms_2);
96 for (i = 0; i < r_r->num_ref_doms_2; i++)
98 smb_io_dom_sid2("", &(r_r->ref_dom[i]), ps, depth); /* referenced domain SIDs */
102 /*******************************************************************
103 makes an LSA_OBJ_ATTR structure.
104 ********************************************************************/
105 void make_lsa_obj_attr(LSA_OBJ_ATTR *attr, uint32 attributes, uint32 sec_qos)
107 if (attr == NULL) return;
109 DEBUG(5,("make_lsa_obj_attr\n"));
111 attr->len = 0x18; /* length of object attribute block, in bytes */
112 attr->ptr_root_dir = 0;
113 attr->ptr_obj_name = 0;
114 attr->attributes = attributes;
115 attr->ptr_sec_desc = 0;
116 attr->sec_qos = sec_qos;
119 /*******************************************************************
120 reads or writes an LSA_OBJ_ATTR structure.
121 ********************************************************************/
122 void lsa_io_obj_attr(char *desc, LSA_OBJ_ATTR *attr, prs_struct *ps, int depth)
126 if (attr == NULL) return;
128 prs_debug(ps, depth, desc, "lsa_io_obj_attr");
135 /* these pointers had _better_ be zero, because we don't know
138 prs_uint32("len" , ps, depth, &(attr->len )); /* 0x18 - length (in bytes) inc. the length field. */
139 prs_uint32("ptr_root_dir", ps, depth, &(attr->ptr_root_dir)); /* 0 - root directory (pointer) */
140 prs_uint32("ptr_obj_name", ps, depth, &(attr->ptr_obj_name)); /* 0 - object name (pointer) */
141 prs_uint32("attributes" , ps, depth, &(attr->attributes )); /* 0 - attributes (undocumented) */
142 prs_uint32("ptr_sec_desc", ps, depth, &(attr->ptr_sec_desc)); /* 0 - security descriptior (pointer) */
143 prs_uint32("sec_qos" , ps, depth, &(attr->sec_qos )); /* 0 - security quality of service */
145 if (attr->len != ps->offset - start)
147 DEBUG(3,("lsa_io_obj_attr: length %x does not match size %x\n",
148 attr->len, ps->offset - start));
151 /*******************************************************************
152 makes an LSA_Q_OPEN_POL structure.
153 ********************************************************************/
154 void make_q_open_pol(LSA_Q_OPEN_POL *r_q, char *server_name,
155 uint32 attributes, uint32 sec_qos,
156 uint32 desired_access)
158 if (r_q == NULL) return;
160 DEBUG(5,("make_open_pol\n"));
162 r_q->ptr = 1; /* undocumented pointer */
164 make_unistr2 (&(r_q->uni_server_name), server_name, strlen(server_name));
165 make_lsa_obj_attr(&(r_q->attr ), attributes, sec_qos);
167 r_q->des_access = desired_access;
170 /*******************************************************************
171 reads or writes an LSA_Q_OPEN_POL structure.
172 ********************************************************************/
173 void lsa_io_q_open_pol(char *desc, LSA_Q_OPEN_POL *r_q, prs_struct *ps, int depth)
175 if (r_q == NULL) return;
177 prs_debug(ps, depth, desc, "lsa_io_q_open_pol");
180 prs_uint32("ptr ", ps, depth, &(r_q->ptr ));
182 smb_io_unistr2 ("", &(r_q->uni_server_name), r_q->ptr, ps, depth);
183 lsa_io_obj_attr("", &(r_q->attr ), ps, depth);
185 prs_uint32("des_access", ps, depth, &(r_q->des_access));
188 /*******************************************************************
189 reads or writes an LSA_R_OPEN_POL structure.
190 ********************************************************************/
191 void lsa_io_r_open_pol(char *desc, LSA_R_OPEN_POL *r_p, prs_struct *ps, int depth)
193 if (r_p == NULL) return;
195 prs_debug(ps, depth, desc, "lsa_io_r_open_pol");
199 smb_io_pol_hnd("", &(r_p->pol), ps, depth);
201 prs_uint32("status", ps, depth, &(r_p->status));
204 /*******************************************************************
205 makes an LSA_Q_QUERY_INFO structure.
206 ********************************************************************/
207 void make_q_query(LSA_Q_QUERY_INFO *q_q, POLICY_HND *hnd, uint16 info_class)
209 if (q_q == NULL || hnd == NULL) return;
211 DEBUG(5,("make_q_query\n"));
213 memcpy(&(q_q->pol), hnd, sizeof(q_q->pol));
215 q_q->info_class = info_class;
218 /*******************************************************************
219 reads or writes an LSA_Q_QUERY_INFO structure.
220 ********************************************************************/
221 void lsa_io_q_query(char *desc, LSA_Q_QUERY_INFO *q_q, prs_struct *ps, int depth)
223 if (q_q == NULL) return;
225 prs_debug(ps, depth, desc, "lsa_io_q_query");
228 smb_io_pol_hnd("", &(q_q->pol), ps, depth);
230 prs_uint16("info_class", ps, depth, &(q_q->info_class));
233 /*******************************************************************
234 reads or writes an LSA_Q_ENUM_TRUST_DOM structure.
235 ********************************************************************/
236 void lsa_io_q_enum_trust_dom(char *desc, LSA_Q_ENUM_TRUST_DOM *q_e, prs_struct *ps, int depth)
238 if (q_e == NULL) return;
240 prs_debug(ps, depth, desc, "lsa_io_q_enum_trust_dom");
244 smb_io_pol_hnd("", &(q_e->pol), ps, depth);
246 prs_uint32("enum_context ", ps, depth, &(q_e->enum_context ));
247 prs_uint32("preferred_len", ps, depth, &(q_e->preferred_len));
250 /*******************************************************************
251 makes an LSA_R_ENUM_TRUST_DOM structure.
252 ********************************************************************/
253 void make_r_enum_trust_dom(LSA_R_ENUM_TRUST_DOM *r_e,
254 uint32 enum_context, char *domain_name, DOM_SID *domain_sid,
257 if (r_e == NULL) return;
259 DEBUG(5,("make_r_enum_trust_dom\n"));
261 r_e->enum_context = enum_context;
265 int len_domain_name = strlen(domain_name);
267 r_e->num_domains = 1;
268 r_e->ptr_enum_domains = 1;
269 r_e->num_domains2 = 1;
271 make_uni_hdr2(&(r_e->hdr_domain_name ), len_domain_name, len_domain_name, 4);
272 make_unistr2 (&(r_e->uni_domain_name ), domain_name, len_domain_name);
273 make_dom_sid2(&(r_e->other_domain_sid), domain_sid);
277 r_e->num_domains = 0;
278 r_e->ptr_enum_domains = 0;
281 r_e->status = status;
284 /*******************************************************************
285 reads or writes an LSA_R_ENUM_TRUST_DOM structure.
286 ********************************************************************/
287 void lsa_io_r_enum_trust_dom(char *desc, LSA_R_ENUM_TRUST_DOM *r_e, prs_struct *ps, int depth)
289 if (r_e == NULL) return;
291 prs_debug(ps, depth, desc, "lsa_io_r_enum_trust_dom");
294 prs_uint32("enum_context ", ps, depth, &(r_e->enum_context ));
295 prs_uint32("num_domains ", ps, depth, &(r_e->num_domains ));
296 prs_uint32("ptr_enum_domains", ps, depth, &(r_e->ptr_enum_domains));
298 if (r_e->ptr_enum_domains != 0)
300 prs_uint32("num_domains2", ps, depth, &(r_e->num_domains2));
301 smb_io_unihdr2 ("", &(r_e->hdr_domain_name ), ps, depth);
302 smb_io_unistr2 ("", &(r_e->uni_domain_name ), r_e->hdr_domain_name.buffer, ps, depth);
303 smb_io_dom_sid2("", &(r_e->other_domain_sid), ps, depth);
306 prs_uint32("status", ps, depth, &(r_e->status));
309 /*******************************************************************
310 makes an LSA_Q_CLOSE structure.
311 ********************************************************************/
312 void make_lsa_q_close(LSA_Q_CLOSE *q_c, POLICY_HND *hnd)
314 if (q_c == NULL || hnd == NULL) return;
316 DEBUG(5,("make_lsa_q_close\n"));
318 memcpy(&(q_c->pol), hnd, sizeof(q_c->pol));
322 /*******************************************************************
323 reads or writes an LSA_Q_CLOSE structure.
324 ********************************************************************/
325 void lsa_io_q_close(char *desc, LSA_Q_CLOSE *q_c, prs_struct *ps, int depth)
327 if (q_c == NULL) return;
329 prs_debug(ps, depth, desc, "lsa_io_q_close");
332 smb_io_pol_hnd("", &(q_c->pol), ps, depth);
335 /*******************************************************************
336 makes an LSA_R_CLOSE structure.
337 ********************************************************************/
338 void make_lsa_r_close(LSA_R_CLOSE *q_r, POLICY_HND *hnd)
340 if (q_r == NULL || hnd == NULL) return;
342 DEBUG(5,("make_lsa_r_close\n"));
344 memcpy(&(q_r->pol), hnd, sizeof(q_r->pol));
348 /*******************************************************************
349 reads or writes an LSA_R_CLOSE structure.
350 ********************************************************************/
351 void lsa_io_r_close(char *desc, LSA_R_CLOSE *r_c, prs_struct *ps, int depth)
353 if (r_c == NULL) return;
355 prs_debug(ps, depth, desc, "lsa_io_r_close");
358 smb_io_pol_hnd("", &(r_c->pol), ps, depth);
360 prs_uint32("status", ps, depth, &(r_c->status));
363 /*******************************************************************
364 reads or writes an LSA_Q_QUERY_INFO structure.
365 ********************************************************************/
366 void lsa_io_r_query(char *desc, LSA_R_QUERY_INFO *r_q, prs_struct *ps, int depth)
368 if (r_q == NULL) return;
370 prs_debug(ps, depth, desc, "lsa_io_r_query");
373 prs_uint32("undoc_buffer", ps, depth, &(r_q->undoc_buffer));
375 if (r_q->undoc_buffer != 0)
377 prs_uint16("info_class", ps, depth, &(r_q->info_class));
379 switch (r_q->info_class)
383 smb_io_dom_query_3("", &(r_q->dom.id3), ps, depth);
388 smb_io_dom_query_5("", &(r_q->dom.id3), ps, depth);
399 prs_uint32("status", ps, depth, &(r_q->status));
402 /*******************************************************************
403 reads or writes a LSA_SID_ENUM structure.
404 ********************************************************************/
405 void lsa_io_sid_enum(char *desc, LSA_SID_ENUM *sen, prs_struct *ps, int depth)
409 if (sen == NULL) return;
411 prs_debug(ps, depth, desc, "lsa_io_sid_enum");
416 prs_uint32("num_entries ", ps, depth, &(sen->num_entries));
417 prs_uint32("ptr_sid_enum", ps, depth, &(sen->ptr_sid_enum));
418 prs_uint32("num_entries2", ps, depth, &(sen->num_entries2));
420 SMB_ASSERT_ARRAY(sen->ptr_sid, sen->num_entries);
422 for (i = 0; i < sen->num_entries; i++)
425 slprintf(temp, sizeof(temp) - 1, "ptr_sid[%d]", i);
426 prs_uint32(temp, ps, depth, &(sen->ptr_sid[i])); /* domain SID pointers to be looked up. */
429 SMB_ASSERT_ARRAY(sen->sid, sen->num_entries);
431 for (i = 0; i < sen->num_entries; i++)
434 slprintf(temp, sizeof(temp) - 1, "sid[%d]", i);
435 smb_io_dom_sid2(temp, &(sen->sid[i]), ps, depth); /* domain SIDs to be looked up. */
439 /*******************************************************************
440 reads or writes a LSA_Q_LOOKUP_SIDS structure.
441 ********************************************************************/
442 void lsa_io_q_lookup_sids(char *desc, LSA_Q_LOOKUP_SIDS *q_s, prs_struct *ps, int depth)
444 if (q_s == NULL) return;
446 prs_debug(ps, depth, desc, "lsa_io_q_lookup_sids");
451 smb_io_pol_hnd ("pol_hnd", &(q_s->pol_hnd), ps, depth); /* policy handle */
452 lsa_io_sid_enum ("sids ", &(q_s->sids ), ps, depth); /* sids to be looked up */
453 lsa_io_trans_names ("names ", &(q_s->names ), ps, depth); /* translated names */
454 smb_io_lookup_level("switch ", &(q_s->level ), ps, depth); /* lookup level */
456 prs_uint32("mapped_count", ps, depth, &(q_s->mapped_count));
459 /*******************************************************************
460 reads or writes a structure.
461 ********************************************************************/
462 void lsa_io_trans_names(char *desc, LSA_TRANS_NAME_ENUM *trn, prs_struct *ps, int depth)
467 if (trn == NULL) return;
469 prs_debug(ps, depth, desc, "lsa_io_trans_names");
474 prs_uint32("num_entries ", ps, depth, &(trn->num_entries));
475 prs_uint32("ptr_trans_names", ps, depth, &(trn->ptr_trans_names));
476 prs_uint32("num_entries2 ", ps, depth, &(trn->num_entries2));
478 SMB_ASSERT_ARRAY(trn->ptr_name, trn->num_entries);
480 for (i = 0; i < trn->num_entries; i++)
483 slprintf(temp, sizeof(temp) - 1, "ptr_name[%d] ", i);
484 prs_uint32(temp, ps, depth, &(trn->ptr_name[i])); /* pointer to translated name */
487 for (i = 0, i2 = 0; i < trn->num_entries2; i++)
489 if (trn->ptr_name[i] != 0)
492 slprintf(temp, sizeof(temp) - 1, "name[%d] ", i);
493 lsa_io_trans_name(temp, &(trn->name[i2]), ps, depth); /* translated name */
499 /*******************************************************************
500 reads or writes a structure.
501 ********************************************************************/
502 void lsa_io_r_lookup_sids(char *desc, LSA_R_LOOKUP_SIDS *r_s, prs_struct *ps, int depth)
504 if (r_s == NULL) return;
506 prs_debug(ps, depth, desc, "lsa_io_r_lookup_sids");
511 lsa_io_dom_r_ref ("dom_ref", r_s->dom_ref, ps, depth); /* domain reference info */
512 lsa_io_trans_names("names ", r_s->names , ps, depth); /* translated names */
514 prs_uint32("mapped_count", ps, depth, &(r_s->mapped_count));
516 prs_uint32("status ", ps, depth, &(r_s->status));
519 /*******************************************************************
520 reads or writes a structure.
521 ********************************************************************/
522 void lsa_io_q_lookup_rids(char *desc, LSA_Q_LOOKUP_RIDS *q_r, prs_struct *ps, int depth)
526 if (q_r == NULL) return;
528 prs_debug(ps, depth, desc, "lsa_io_q_lookup_rids");
533 smb_io_pol_hnd("", &(q_r->pol_hnd), ps, depth); /* policy handle */
535 prs_uint32("num_entries ", ps, depth, &(q_r->num_entries));
536 prs_uint32("num_entries2 ", ps, depth, &(q_r->num_entries2));
537 prs_uint32("buffer_dom_sid ", ps, depth, &(q_r->buffer_dom_sid)); /* undocumented domain SID buffer pointer */
538 prs_uint32("buffer_dom_name", ps, depth, &(q_r->buffer_dom_name)); /* undocumented domain name buffer pointer */
540 SMB_ASSERT_ARRAY(q_r->lookup_name, q_r->num_entries);
542 for (i = 0; i < q_r->num_entries; i++)
544 smb_io_dom_name("", &(q_r->lookup_name[i]), ps, depth); /* names to be looked up */
547 prs_uint8s (False, "undoc ", ps, depth, q_r->undoc, UNKNOWN_LEN);
550 /*******************************************************************
551 reads or writes a structure.
552 ********************************************************************/
553 void lsa_io_r_lookup_rids(char *desc, LSA_R_LOOKUP_RIDS *r_r, prs_struct *ps, int depth)
557 if (r_r == NULL) return;
559 prs_debug(ps, depth, desc, "lsa_io_r_lookup_rids");
564 lsa_io_dom_r_ref("", &(r_r->dom_ref), ps, depth); /* domain reference info */
566 prs_uint32("num_entries ", ps, depth, &(r_r->num_entries));
567 prs_uint32("undoc_buffer", ps, depth, &(r_r->undoc_buffer));
568 prs_uint32("num_entries2", ps, depth, &(r_r->num_entries2));
570 SMB_ASSERT_ARRAY(r_r->dom_rid, r_r->num_entries2);
572 for (i = 0; i < r_r->num_entries2; i++)
574 smb_io_dom_rid2("", &(r_r->dom_rid[i]), ps, depth); /* domain RIDs being looked up */
577 prs_uint32("num_entries3", ps, depth, &(r_r->num_entries3));
579 prs_uint32("status ", ps, depth, &(r_r->status));