39a9b7591aadbd87b4f1b134667d16f5cc7719a9
[samba.git] / source / rpc_server / srv_samr.c
1
2 /* 
3  *  Unix SMB/Netbios implementation.
4  *  Version 1.9.
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  *  
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.
14  *  
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.
19  *  
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.
23  */
24
25
26 #include "includes.h"
27 #include "nterr.h"
28
29 extern int DEBUGLEVEL;
30
31 extern fstring global_sam_name;
32 extern pstring global_myname;
33 extern DOM_SID global_sam_sid;
34 extern DOM_SID global_sid_S_1_1;
35 extern DOM_SID global_sid_S_1_5_20;
36
37 extern rid_name domain_group_rids[];
38 extern rid_name domain_alias_rids[];
39 extern rid_name builtin_alias_rids[];
40
41 /*******************************************************************
42   This next function should be replaced with something that
43   dynamically returns the correct user info..... JRA.
44  ********************************************************************/
45
46 static BOOL get_sampwd_entries(SAM_USER_INFO_21 *pw_buf,
47                                 int start_idx,
48                                 int *total_entries, int *num_entries,
49                                 int max_num_entries,
50                                 uint16 acb_mask)
51 {
52         void *vp = NULL;
53         struct sam_passwd *pwd = NULL;
54
55         (*num_entries) = 0;
56         (*total_entries) = 0;
57
58         if (pw_buf == NULL) return False;
59
60         vp = startsmbpwent(False);
61         if (!vp)
62         {
63                 DEBUG(0, ("get_sampwd_entries: Unable to open SMB password database.\n"));
64                 return False;
65         }
66
67         while (((pwd = getsam21pwent(vp)) != NULL) && (*num_entries) < max_num_entries)
68         {
69                 int user_name_len;
70
71                 if (start_idx > 0)
72                 {
73                         /* skip the requested number of entries.
74                            not very efficient, but hey...
75                          */
76                         start_idx--;
77                         continue;
78                 }
79
80                 user_name_len = strlen(pwd->nt_name);
81                 make_unistr2(&(pw_buf[(*num_entries)].uni_user_name), pwd->nt_name, user_name_len);
82                 make_uni_hdr(&(pw_buf[(*num_entries)].hdr_user_name), user_name_len, 
83                                user_name_len, 1);
84                 pw_buf[(*num_entries)].user_rid = pwd->user_rid;
85                 bzero( pw_buf[(*num_entries)].nt_pwd , 16);
86
87                 /* Now check if the NT compatible password is available. */
88                 if (pwd->smb_nt_passwd != NULL)
89                 {
90                         memcpy( pw_buf[(*num_entries)].nt_pwd , pwd->smb_nt_passwd, 16);
91                 }
92
93                 pw_buf[(*num_entries)].acb_info = (uint16)pwd->acct_ctrl;
94
95                 DEBUG(5, ("entry idx: %d user %s, rid 0x%x, acb %x",
96                           (*num_entries), pwd->nt_name,
97                           pwd->user_rid, pwd->acct_ctrl));
98
99                 if (acb_mask == 0 || IS_BITS_SET_SOME(pwd->acct_ctrl, acb_mask))
100                 {
101                         DEBUG(5,(" acb_mask %x accepts\n", acb_mask));
102                         (*num_entries)++;
103                 }
104                 else
105                 {
106                         DEBUG(5,(" acb_mask %x rejects\n", acb_mask));
107                 }
108
109                 (*total_entries)++;
110         }
111
112         endsmbpwent(vp);
113
114         return (*num_entries) > 0;
115 }
116
117 /*******************************************************************
118  samr_reply_unknown_1
119  ********************************************************************/
120 static void samr_reply_close_hnd(SAMR_Q_CLOSE_HND *q_u,
121                                 prs_struct *rdata)
122 {
123         SAMR_R_CLOSE_HND r_u;
124
125         /* set up the SAMR unknown_1 response */
126         bzero(r_u.pol.data, POL_HND_SIZE);
127
128         /* close the policy handle */
129         if (close_lsa_policy_hnd(&(q_u->pol)))
130         {
131                 r_u.status = 0;
132         }
133         else
134         {
135                 r_u.status = 0xC0000000 | NT_STATUS_OBJECT_NAME_INVALID;
136         }
137
138         DEBUG(5,("samr_reply_close_hnd: %d\n", __LINE__));
139
140         /* store the response in the SMB stream */
141         samr_io_r_close_hnd("", &r_u, rdata, 0);
142
143         DEBUG(5,("samr_reply_close_hnd: %d\n", __LINE__));
144
145 }
146
147 /*******************************************************************
148  api_samr_close_hnd
149  ********************************************************************/
150 static void api_samr_close_hnd( uint16 vuid, prs_struct *data, prs_struct *rdata)
151 {
152         SAMR_Q_CLOSE_HND q_u;
153         samr_io_q_close_hnd("", &q_u, data, 0);
154         samr_reply_close_hnd(&q_u, rdata);
155 }
156
157
158 /*******************************************************************
159  samr_reply_open_domain
160  ********************************************************************/
161 static void samr_reply_open_domain(SAMR_Q_OPEN_DOMAIN *q_u,
162                                 prs_struct *rdata)
163 {
164         SAMR_R_OPEN_DOMAIN r_u;
165         BOOL pol_open = False;
166
167         r_u.status = 0x0;
168
169         /* find the connection policy handle. */
170         if (r_u.status == 0x0 && (find_lsa_policy_by_hnd(&(q_u->connect_pol)) == -1))
171         {
172                 r_u.status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
173         }
174
175         /* get a (unique) handle.  open a policy on it. */
176         if (r_u.status == 0x0 && !(pol_open = open_lsa_policy_hnd(&(r_u.domain_pol))))
177         {
178                 r_u.status = 0xC0000000 | NT_STATUS_OBJECT_NAME_NOT_FOUND;
179         }
180
181         /* associate the domain SID with the (unique) handle. */
182         if (r_u.status == 0x0 && !set_lsa_policy_samr_sid(&(r_u.domain_pol), &(q_u->dom_sid.sid)))
183         {
184                 /* oh, whoops.  don't know what error message to return, here */
185                 r_u.status = 0xC0000000 | NT_STATUS_OBJECT_NAME_NOT_FOUND;
186         }
187
188         if (r_u.status != 0 && pol_open)
189         {
190                 close_lsa_policy_hnd(&(r_u.domain_pol));
191         }
192
193         DEBUG(5,("samr_open_domain: %d\n", __LINE__));
194
195         /* store the response in the SMB stream */
196         samr_io_r_open_domain("", &r_u, rdata, 0);
197
198         DEBUG(5,("samr_open_domain: %d\n", __LINE__));
199
200 }
201
202 /*******************************************************************
203  api_samr_open_domain
204  ********************************************************************/
205 static void api_samr_open_domain( uint16 vuid, prs_struct *data, prs_struct *rdata)
206 {
207         SAMR_Q_OPEN_DOMAIN q_u;
208         samr_io_q_open_domain("", &q_u, data, 0);
209         samr_reply_open_domain(&q_u, rdata);
210 }
211
212
213 /*******************************************************************
214  samr_reply_unknown_2c
215  ********************************************************************/
216 static void samr_reply_unknown_2c(SAMR_Q_UNKNOWN_2C *q_u,
217                                 prs_struct *rdata)
218 {
219         SAMR_R_UNKNOWN_2C r_u;
220         uint32 status = 0x0;
221
222         /* find the policy handle.  open a policy on it. */
223         if (status == 0x0 && (find_lsa_policy_by_hnd(&(q_u->user_pol)) == -1))
224         {
225                 status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
226         }
227
228         /* find the user's rid */
229         if ((status == 0x0) && (get_lsa_policy_samr_rid(&(q_u->user_pol)) == 0xffffffff))
230         {
231                 status = 0xC0000000 | NT_STATUS_OBJECT_TYPE_MISMATCH;
232         }
233
234         make_samr_r_unknown_2c(&r_u, status);
235
236         DEBUG(5,("samr_unknown_2c: %d\n", __LINE__));
237
238         /* store the response in the SMB stream */
239         samr_io_r_unknown_2c("", &r_u, rdata, 0);
240
241         DEBUG(5,("samr_unknown_2c: %d\n", __LINE__));
242
243 }
244
245 /*******************************************************************
246  api_samr_unknown_2c
247  ********************************************************************/
248 static void api_samr_unknown_2c( uint16 vuid, prs_struct *data, prs_struct *rdata)
249 {
250         SAMR_Q_UNKNOWN_2C q_u;
251         samr_io_q_unknown_2c("", &q_u, data, 0);
252         samr_reply_unknown_2c(&q_u, rdata);
253 }
254
255
256 /*******************************************************************
257  samr_reply_unknown_3
258  ********************************************************************/
259 static void samr_reply_unknown_3(SAMR_Q_UNKNOWN_3 *q_u,
260                                 prs_struct *rdata)
261 {
262         SAMR_R_UNKNOWN_3 r_u;
263         DOM_SID3 sid[MAX_SAM_SIDS];
264         uint32 rid;
265         uint32 status;
266
267         status = 0x0;
268
269         /* find the policy handle.  open a policy on it. */
270         if (status == 0x0 && (find_lsa_policy_by_hnd(&(q_u->user_pol)) == -1))
271         {
272                 status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
273         }
274
275         /* find the user's rid */
276         if (status == 0x0 && (rid = get_lsa_policy_samr_rid(&(q_u->user_pol))) == 0xffffffff)
277         {
278                 status = 0xC0000000 | NT_STATUS_OBJECT_TYPE_MISMATCH;
279         }
280
281         if (status == 0x0)
282         {
283                 DOM_SID usr_sid;
284
285                 usr_sid = global_sam_sid;
286
287                 SMB_ASSERT_ARRAY(usr_sid.sub_auths, usr_sid.num_auths+1);
288
289                 /*
290                  * Add the user RID.
291                  */
292                 sid_append_rid(&usr_sid, rid);
293                 
294                 /* maybe need another 1 or 2 (S-1-5-0x20-0x220 and S-1-5-20-0x224) */
295                 /* these two are DOMAIN_ADMIN and DOMAIN_ACCT_OP group RIDs */
296                 make_dom_sid3(&(sid[0]), 0x035b, 0x0002, &global_sid_S_1_1);
297                 make_dom_sid3(&(sid[1]), 0x0044, 0x0002, &usr_sid);
298         }
299
300         make_samr_r_unknown_3(&r_u,
301                                 0x0001, 0x8004,
302                                 0x00000014, 0x0002, 0x0070,
303                                 2, sid, status);
304
305         DEBUG(5,("samr_unknown_3: %d\n", __LINE__));
306
307         /* store the response in the SMB stream */
308         samr_io_r_unknown_3("", &r_u, rdata, 0);
309
310         DEBUG(5,("samr_unknown_3: %d\n", __LINE__));
311
312 }
313
314 /*******************************************************************
315  api_samr_unknown_3
316  ********************************************************************/
317 static void api_samr_unknown_3( uint16 vuid, prs_struct *data, prs_struct *rdata)
318 {
319         SAMR_Q_UNKNOWN_3 q_u;
320         samr_io_q_unknown_3("", &q_u, data, 0);
321         samr_reply_unknown_3(&q_u, rdata);
322 }
323
324
325 /*******************************************************************
326  samr_reply_enum_dom_users
327  ********************************************************************/
328 static void samr_reply_enum_dom_users(SAMR_Q_ENUM_DOM_USERS *q_u,
329                                 prs_struct *rdata)
330 {
331         SAMR_R_ENUM_DOM_USERS r_e;
332         SAM_USER_INFO_21 pass[MAX_SAM_ENTRIES];
333         int num_entries;
334         int total_entries;
335
336         r_e.status = 0x0;
337
338         /* find the policy handle.  open a policy on it. */
339         if (r_e.status == 0x0 && (find_lsa_policy_by_hnd(&(q_u->pol)) == -1))
340         {
341                 r_e.status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
342         }
343
344         DEBUG(5,("samr_reply_enum_dom_users: %d\n", __LINE__));
345
346         become_root(True);
347         get_sampwd_entries(pass, 0, &total_entries, &num_entries, MAX_SAM_ENTRIES, q_u->acb_mask);
348         unbecome_root(True);
349
350         make_samr_r_enum_dom_users(&r_e, 
351                                    0x00000000, num_entries,
352                                    pass, r_e.status);
353
354         /* store the response in the SMB stream */
355         samr_io_r_enum_dom_users("", &r_e, rdata, 0);
356
357         DEBUG(5,("samr_enum_dom_users: %d\n", __LINE__));
358
359 }
360
361 /*******************************************************************
362  api_samr_enum_dom_users
363  ********************************************************************/
364 static void api_samr_enum_dom_users( uint16 vuid, prs_struct *data, prs_struct *rdata)
365 {
366         SAMR_Q_ENUM_DOM_USERS q_e;
367         samr_io_q_enum_dom_users("", &q_e, data, 0);
368         samr_reply_enum_dom_users(&q_e, rdata);
369 }
370
371
372 /*******************************************************************
373  samr_reply_add_groupmem
374  ********************************************************************/
375 static void samr_reply_add_groupmem(SAMR_Q_ADD_GROUPMEM *q_u,
376                                 prs_struct *rdata)
377 {
378         SAMR_R_ADD_GROUPMEM r_e;
379         DOM_SID group_sid;
380         uint32 group_rid;
381         fstring group_sid_str;
382
383         r_e.status = 0x0;
384
385         /* find the policy handle.  open a policy on it. */
386         if (r_e.status == 0x0 && !get_lsa_policy_samr_sid(&q_u->pol, &group_sid))
387         {
388                 r_e.status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
389         }
390         else
391         {
392                 sid_to_string(group_sid_str, &group_sid);
393                 sid_split_rid(&group_sid, &group_rid);
394         }
395
396         if (r_e.status == 0x0)
397         {
398                 DEBUG(10,("sid is %s\n", group_sid_str));
399
400                 if (sid_equal(&group_sid, &global_sam_sid))
401                 {
402                         DEBUG(10,("lookup on Domain SID\n"));
403
404                         become_root(True);
405                         r_e.status = add_group_member(group_rid, q_u->rid) ? 0x0 : 0xC0000000 | NT_STATUS_ACCESS_DENIED;
406                         unbecome_root(True);
407                 }
408                 else
409                 {
410                         r_e.status = 0xC0000000 | NT_STATUS_NO_SUCH_GROUP;
411                 }
412         }
413
414         /* store the response in the SMB stream */
415         samr_io_r_add_groupmem("", &r_e, rdata, 0);
416
417         DEBUG(5,("samr_add_groupmem: %d\n", __LINE__));
418 }
419
420 /*******************************************************************
421  api_samr_add_groupmem
422  ********************************************************************/
423 static void api_samr_add_groupmem( uint16 vuid, prs_struct *data, prs_struct *rdata)
424 {
425         SAMR_Q_ADD_GROUPMEM q_e;
426         samr_io_q_add_groupmem("", &q_e, data, 0);
427         samr_reply_add_groupmem(&q_e, rdata);
428 }
429
430 /*******************************************************************
431  samr_reply_del_groupmem
432  ********************************************************************/
433 static void samr_reply_del_groupmem(SAMR_Q_DEL_GROUPMEM *q_u,
434                                 prs_struct *rdata)
435 {
436         SAMR_R_DEL_GROUPMEM r_e;
437         DOM_SID group_sid;
438         uint32 group_rid;
439         fstring group_sid_str;
440
441         r_e.status = 0x0;
442
443         /* find the policy handle.  open a policy on it. */
444         if (r_e.status == 0x0 && !get_lsa_policy_samr_sid(&q_u->pol, &group_sid))
445         {
446                 r_e.status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
447         }
448         else
449         {
450                 sid_to_string(group_sid_str, &group_sid);
451                 sid_split_rid(&group_sid, &group_rid);
452         }
453
454         if (r_e.status == 0x0)
455         {
456                 DEBUG(10,("sid is %s\n", group_sid_str));
457
458                 if (sid_equal(&group_sid, &global_sam_sid))
459                 {
460                         DEBUG(10,("lookup on Domain SID\n"));
461
462                         become_root(True);
463                         r_e.status = del_group_member(group_rid, q_u->rid) ? 0x0 : 0xC0000000 | NT_STATUS_ACCESS_DENIED;
464                         unbecome_root(True);
465                 }
466                 else
467                 {
468                         r_e.status = 0xC0000000 | NT_STATUS_NO_SUCH_GROUP;
469                 }
470         }
471
472         /* store the response in the SMB stream */
473         samr_io_r_del_groupmem("", &r_e, rdata, 0);
474
475         DEBUG(5,("samr_del_groupmem: %d\n", __LINE__));
476 }
477
478 /*******************************************************************
479  api_samr_del_groupmem
480  ********************************************************************/
481 static void api_samr_del_groupmem( uint16 vuid, prs_struct *data, prs_struct *rdata)
482 {
483         SAMR_Q_DEL_GROUPMEM q_e;
484         samr_io_q_del_groupmem("", &q_e, data, 0);
485         samr_reply_del_groupmem(&q_e, rdata);
486 }
487
488 /*******************************************************************
489  samr_reply_add_aliasmem
490  ********************************************************************/
491 static void samr_reply_add_aliasmem(SAMR_Q_ADD_ALIASMEM *q_u,
492                                 prs_struct *rdata)
493 {
494         SAMR_R_ADD_ALIASMEM r_e;
495         DOM_SID alias_sid;
496         uint32 alias_rid;
497         fstring alias_sid_str;
498
499         r_e.status = 0x0;
500
501         /* find the policy handle.  open a policy on it. */
502         if (r_e.status == 0x0 && !get_lsa_policy_samr_sid(&q_u->alias_pol, &alias_sid))
503         {
504                 r_e.status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
505         }
506         else
507         {
508                 sid_to_string(alias_sid_str, &alias_sid);
509                 sid_split_rid(&alias_sid, &alias_rid);
510         }
511
512         if (r_e.status == 0x0)
513         {
514                 DEBUG(10,("sid is %s\n", alias_sid_str));
515
516                 if (sid_equal(&alias_sid, &global_sam_sid))
517                 {
518                         DEBUG(10,("add member on Domain SID\n"));
519
520                         become_root(True);
521                         r_e.status = add_alias_member(alias_rid, &q_u->sid.sid) ? 0x0 : 0xC0000000 | NT_STATUS_ACCESS_DENIED;
522                         unbecome_root(True);
523                 }
524                 else if (sid_equal(&alias_sid, &global_sid_S_1_5_20))
525                 {
526                         DEBUG(10,("add member on BUILTIN SID\n"));
527
528                         become_root(True);
529                         r_e.status = add_builtin_member(alias_rid, &q_u->sid.sid) ? 0x0 : 0xC0000000 | NT_STATUS_ACCESS_DENIED;
530                         unbecome_root(True);
531                 }
532                 else
533                 {
534                         r_e.status = 0xC0000000 | NT_STATUS_NO_SUCH_ALIAS;
535                 }
536         }
537
538         /* store the response in the SMB stream */
539         samr_io_r_add_aliasmem("", &r_e, rdata, 0);
540
541         DEBUG(5,("samr_add_aliasmem: %d\n", __LINE__));
542 }
543
544 /*******************************************************************
545  api_samr_add_aliasmem
546  ********************************************************************/
547 static void api_samr_add_aliasmem( uint16 vuid, prs_struct *data, prs_struct *rdata)
548 {
549         SAMR_Q_ADD_ALIASMEM q_e;
550         samr_io_q_add_aliasmem("", &q_e, data, 0);
551         samr_reply_add_aliasmem(&q_e, rdata);
552 }
553
554 /*******************************************************************
555  samr_reply_del_aliasmem
556  ********************************************************************/
557 static void samr_reply_del_aliasmem(SAMR_Q_DEL_ALIASMEM *q_u,
558                                 prs_struct *rdata)
559 {
560         SAMR_R_DEL_ALIASMEM r_e;
561         DOM_SID alias_sid;
562         uint32 alias_rid;
563         fstring alias_sid_str;
564
565         r_e.status = 0x0;
566
567         /* find the policy handle.  open a policy on it. */
568         if (r_e.status == 0x0 && !get_lsa_policy_samr_sid(&q_u->alias_pol, &alias_sid))
569         {
570                 r_e.status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
571         }
572         else
573         {
574                 sid_to_string(alias_sid_str, &alias_sid);
575                 sid_split_rid(&alias_sid, &alias_rid);
576         }
577
578         if (r_e.status == 0x0)
579         {
580                 DEBUG(10,("sid is %s\n", alias_sid_str));
581
582                 if (sid_equal(&alias_sid, &global_sam_sid))
583                 {
584                         DEBUG(10,("del member on Domain SID\n"));
585
586                         become_root(True);
587                         r_e.status = del_alias_member(alias_rid, &q_u->sid.sid) ? 0x0 : 0xC0000000 | NT_STATUS_ACCESS_DENIED;
588                         unbecome_root(True);
589                 }
590                 else if (sid_equal(&alias_sid, &global_sid_S_1_5_20))
591                 {
592                         DEBUG(10,("del member on BUILTIN SID\n"));
593
594                         become_root(True);
595                         r_e.status = del_builtin_member(alias_rid, &q_u->sid.sid) ? 0x0 : 0xC0000000 | NT_STATUS_ACCESS_DENIED;
596                         unbecome_root(True);
597                 }
598                 else
599                 {
600                         r_e.status = 0xC0000000 | NT_STATUS_NO_SUCH_ALIAS;
601                 }
602         }
603
604         /* store the response in the SMB stream */
605         samr_io_r_del_aliasmem("", &r_e, rdata, 0);
606
607         DEBUG(5,("samr_del_aliasmem: %d\n", __LINE__));
608 }
609
610 /*******************************************************************
611  api_samr_del_aliasmem
612  ********************************************************************/
613 static void api_samr_del_aliasmem( uint16 vuid, prs_struct *data, prs_struct *rdata)
614 {
615         SAMR_Q_DEL_ALIASMEM q_e;
616         samr_io_q_del_aliasmem("", &q_e, data, 0);
617         samr_reply_del_aliasmem(&q_e, rdata);
618 }
619
620 /*******************************************************************
621  samr_reply_add_groupmem
622  ********************************************************************/
623 static void samr_reply_enum_dom_groups(SAMR_Q_ENUM_DOM_GROUPS *q_u,
624                                 prs_struct *rdata)
625 {
626         SAMR_R_ENUM_DOM_GROUPS r_e;
627         DOMAIN_GRP *grps = NULL;
628         int num_entries = 0;
629         BOOL got_grps = False;
630         DOM_SID sid;
631         fstring sid_str;
632
633         r_e.status = 0x0;
634         r_e.num_entries = 0;
635
636         /* find the policy handle.  open a policy on it. */
637         if (r_e.status == 0x0 && !get_lsa_policy_samr_sid(&q_u->pol, &sid))
638         {
639                 r_e.status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
640         }
641
642         sid_to_string(sid_str, &sid);
643
644         DEBUG(5,("samr_reply_enum_dom_groups: sid %s\n", sid_str));
645
646         if (sid_equal(&sid, &global_sam_sid))
647         {
648                 BOOL ret;
649                 got_grps = True;
650
651                 become_root(True);
652                 ret = enumdomgroups(&grps, &num_entries);
653                 unbecome_root(True);
654
655                 if (!ret)
656                 {
657                         r_e.status = 0xC0000000 | NT_STATUS_NO_MEMORY;
658                 }
659         }
660
661         if (r_e.status == 0x0 &&
662             (sid_equal(&sid, &global_sam_sid) ||
663              sid_equal(&sid, &global_sid_S_1_5_20)))
664         {
665                 char *name;
666                 int i = 0;
667                 got_grps = True;
668
669                 while (num_entries < MAX_SAM_ENTRIES && ((name = domain_group_rids[i].name) != NULL))
670                 {
671                         DOMAIN_GRP tmp_grp;
672
673                         fstrcpy(tmp_grp.name   , name);
674                         fstrcpy(tmp_grp.comment, "");
675                         tmp_grp.rid = domain_group_rids[i].rid;
676                         tmp_grp.attr = 0x7;
677
678                         if (!add_domain_group(&grps, &num_entries, &tmp_grp))
679                         {
680                                 r_e.status = 0xC0000000 | NT_STATUS_NO_MEMORY;
681                                 break;
682                         }
683
684                         i++;
685                 }
686         }
687
688         if (r_e.status == 0 && got_grps)
689         {
690                 make_samr_r_enum_dom_groups(&r_e, q_u->start_idx, num_entries, grps, r_e.status);
691         }
692
693         /* store the response in the SMB stream */
694         samr_io_r_enum_dom_groups("", &r_e, rdata, 0);
695
696         if (grps != NULL)
697         {
698                 free(grps);
699         }
700
701         DEBUG(5,("samr_enum_dom_groups: %d\n", __LINE__));
702 }
703
704 /*******************************************************************
705  api_samr_enum_dom_groups
706  ********************************************************************/
707 static void api_samr_enum_dom_groups( uint16 vuid, prs_struct *data, prs_struct *rdata)
708 {
709         SAMR_Q_ENUM_DOM_GROUPS q_e;
710         samr_io_q_enum_dom_groups("", &q_e, data, 0);
711         samr_reply_enum_dom_groups(&q_e, rdata);
712 }
713
714
715 /*******************************************************************
716  samr_reply_enum_dom_aliases
717  ********************************************************************/
718 static void samr_reply_enum_dom_aliases(SAMR_Q_ENUM_DOM_ALIASES *q_u,
719                                 prs_struct *rdata)
720 {
721         SAMR_R_ENUM_DOM_ALIASES r_e;
722         LOCAL_GRP *alss = NULL;
723         int num_entries = 0;
724         DOM_SID sid;
725         fstring sid_str;
726
727         r_e.status = 0x0;
728         r_e.num_entries = 0;
729
730         /* find the policy handle.  open a policy on it. */
731         if (r_e.status == 0x0 && !get_lsa_policy_samr_sid(&q_u->pol, &sid))
732         {
733                 r_e.status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
734         }
735
736         sid_to_string(sid_str, &sid);
737
738         DEBUG(5,("samr_reply_enum_dom_aliases: sid %s\n", sid_str));
739
740         /* well-known aliases */
741         if (sid_equal(&sid, &global_sid_S_1_5_20))
742         {
743                 char *name;
744
745                 while ((name = builtin_alias_rids[num_entries].name) != NULL)
746                 {
747                         LOCAL_GRP tmp_als;
748
749                         fstrcpy(tmp_als.name   , name);
750                         fstrcpy(tmp_als.comment, "");
751                         tmp_als.rid = builtin_alias_rids[num_entries].rid;
752
753                         if (!add_domain_alias(&alss, &num_entries, &tmp_als))
754                         {
755                                 r_e.status = 0xC0000000 | NT_STATUS_NO_MEMORY;
756                                 break;
757                         }
758                 }
759         }
760         else if (sid_equal(&sid, &global_sam_sid))
761         {
762                 BOOL ret;
763                 /* local aliases */
764                 num_entries = 0;
765
766                 become_root(True);
767                 ret = enumdomaliases(&alss, &num_entries);
768                 unbecome_root(True);
769                 if (!ret)
770                 {
771                         r_e.status = 0xC0000000 | NT_STATUS_NO_MEMORY;
772                 }
773         }
774                 
775         if (r_e.status == 0x0)
776         {
777                 make_samr_r_enum_dom_aliases(&r_e, num_entries, alss, r_e.status);
778         }
779
780         /* store the response in the SMB stream */
781         samr_io_r_enum_dom_aliases("", &r_e, rdata, 0);
782
783         if (alss != NULL)
784         {
785                 free(alss);
786         }
787
788         DEBUG(5,("samr_enum_dom_aliases: %d\n", __LINE__));
789
790 }
791
792 /*******************************************************************
793  api_samr_enum_dom_aliases
794  ********************************************************************/
795 static void api_samr_enum_dom_aliases( uint16 vuid, prs_struct *data, prs_struct *rdata)
796 {
797         SAMR_Q_ENUM_DOM_ALIASES q_e;
798
799         /* grab the samr open */
800         samr_io_q_enum_dom_aliases("", &q_e, data, 0);
801
802         /* construct reply. */
803         samr_reply_enum_dom_aliases(&q_e, rdata);
804 }
805
806
807 /*******************************************************************
808  samr_reply_query_dispinfo
809  ********************************************************************/
810 static void samr_reply_query_dispinfo(SAMR_Q_QUERY_DISPINFO *q_u,
811                                 prs_struct *rdata)
812 {
813         SAMR_R_QUERY_DISPINFO r_e;
814         SAM_INFO_CTR ctr;
815         SAM_INFO_1 info1;
816         SAM_INFO_2 info2;
817         SAM_USER_INFO_21 pass[MAX_SAM_ENTRIES];
818         int num_entries = 0;
819         int total_entries = 0;
820         BOOL got_pwds;
821         uint16 switch_level = 0x0;
822
823         ZERO_STRUCT(r_e);
824
825         r_e.status = 0x0;
826
827         DEBUG(5,("samr_reply_query_dispinfo: %d\n", __LINE__));
828
829         /* find the policy handle.  open a policy on it. */
830         if (r_e.status == 0x0 && (find_lsa_policy_by_hnd(&(q_u->pol)) == -1))
831         {
832                 r_e.status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
833                 DEBUG(5,("samr_reply_query_dispinfo: invalid handle\n"));
834         }
835
836         if (r_e.status == 0x0)
837         {
838                 become_root(True);
839                 got_pwds = get_sampwd_entries(pass, q_u->start_idx, &total_entries, &num_entries, MAX_SAM_ENTRIES, 0);
840                 unbecome_root(True);
841
842                 switch (q_u->switch_level)
843                 {
844                         case 0x1:
845                         {
846                         
847                                 /* query disp info is for users */
848                                 switch_level = 0x1;
849                                 make_sam_info_1(&info1, ACB_NORMAL,
850                                         q_u->start_idx, num_entries, pass);
851
852                                 ctr.sam.info1 = &info1;
853
854                                 break;
855                         }
856                         case 0x2:
857                         {
858                                 /* query disp info is for servers */
859                                 switch_level = 0x2;
860                                 make_sam_info_2(&info2, ACB_WSTRUST,
861                                         q_u->start_idx, num_entries, pass);
862
863                                 ctr.sam.info2 = &info2;
864
865                                 break;
866                         }
867                 }
868         }
869
870         if (r_e.status == 0 && got_pwds)
871         {
872                 make_samr_r_query_dispinfo(&r_e, switch_level, &ctr, r_e.status);
873         }
874
875         /* store the response in the SMB stream */
876         samr_io_r_query_dispinfo("", &r_e, rdata, 0);
877
878         DEBUG(5,("samr_query_dispinfo: %d\n", __LINE__));
879
880 }
881
882 /*******************************************************************
883  api_samr_query_dispinfo
884  ********************************************************************/
885 static void api_samr_query_dispinfo( uint16 vuid, prs_struct *data, prs_struct *rdata)
886 {
887         SAMR_Q_QUERY_DISPINFO q_e;
888
889         /* grab the samr open */
890         samr_io_q_query_dispinfo("", &q_e, data, 0);
891
892         /* construct reply. */
893         samr_reply_query_dispinfo(&q_e, rdata);
894 }
895
896 /*******************************************************************
897  samr_reply_delete_dom_group
898  ********************************************************************/
899 static void samr_reply_delete_dom_group(SAMR_Q_DELETE_DOM_GROUP *q_u,
900                                 prs_struct *rdata)
901 {
902         uint32 status = 0;
903
904         DOM_SID group_sid;
905         uint32 group_rid;
906         fstring group_sid_str;
907
908         SAMR_R_DELETE_DOM_GROUP r_u;
909
910         DEBUG(5,("samr_delete_dom_group: %d\n", __LINE__));
911
912         /* find the policy handle.  open a policy on it. */
913         if (status == 0x0 && !get_lsa_policy_samr_sid(&q_u->group_pol, &group_sid))
914         {
915                 status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
916         }
917         else
918         {
919                 sid_to_string(group_sid_str, &group_sid     );
920                 sid_split_rid(&group_sid, &group_rid);
921         }
922
923         if (status == 0x0)
924         {
925                 DEBUG(10,("sid is %s\n", group_sid_str));
926
927                 if (sid_equal(&group_sid, &global_sam_sid))
928                 {
929                         DEBUG(10,("lookup on Domain SID\n"));
930
931                         become_root(True);
932                         status = del_group_entry(group_rid) ? 0x0 : 0xC0000000 | NT_STATUS_NO_SUCH_GROUP;
933                         unbecome_root(True);
934                 }
935                 else
936                 {
937                         status = 0xC0000000 | NT_STATUS_NO_SUCH_USER;
938                 }
939         }
940
941         make_samr_r_delete_dom_group(&r_u, status);
942
943         /* store the response in the SMB stream */
944         samr_io_r_delete_dom_group("", &r_u, rdata, 0);
945 }
946
947 /*******************************************************************
948  api_samr_delete_dom_group
949  ********************************************************************/
950 static void api_samr_delete_dom_group( uint16 vuid, prs_struct *data, prs_struct *rdata)
951 {
952         SAMR_Q_DELETE_DOM_GROUP q_u;
953         samr_io_q_delete_dom_group("", &q_u, data, 0);
954         samr_reply_delete_dom_group(&q_u, rdata);
955 }
956
957
958 /*******************************************************************
959  samr_reply_query_groupmem
960  ********************************************************************/
961 static void samr_reply_query_groupmem(SAMR_Q_QUERY_GROUPMEM *q_u,
962                                 prs_struct *rdata)
963 {
964         uint32 status = 0;
965
966         DOMAIN_GRP_MEMBER *mem_grp = NULL;
967         uint32 *rid = NULL;
968         uint32 *attr = NULL;
969         int num_rids = 0;
970         DOM_SID group_sid;
971         uint32 group_rid;
972         fstring group_sid_str;
973
974         SAMR_R_QUERY_GROUPMEM r_u;
975
976         DEBUG(5,("samr_query_groupmem: %d\n", __LINE__));
977
978         /* find the policy handle.  open a policy on it. */
979         if (status == 0x0 && !get_lsa_policy_samr_sid(&q_u->group_pol, &group_sid))
980         {
981                 status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
982         }
983         else
984         {
985                 sid_to_string(group_sid_str, &group_sid     );
986                 sid_split_rid(&group_sid, &group_rid);
987         }
988
989         if (status == 0x0)
990         {
991                 DEBUG(10,("sid is %s\n", group_sid_str));
992
993                 if (sid_equal(&group_sid, &global_sam_sid))
994                 {
995                         DEBUG(10,("lookup on Domain SID\n"));
996
997                         become_root(True);
998                         status = getgrouprid(group_rid, &mem_grp, &num_rids) != NULL ? 0x0 : 0xC0000000 | NT_STATUS_NO_SUCH_GROUP;
999                         unbecome_root(True);
1000                 }
1001                 else
1002                 {
1003                         status = 0xC0000000 | NT_STATUS_NO_SUCH_USER;
1004                 }
1005         }
1006
1007         if (status == 0x0 && num_rids > 0)
1008         {
1009                 rid  = malloc(num_rids * sizeof(uint32));
1010                 attr = malloc(num_rids * sizeof(uint32));
1011                 if (mem_grp != NULL && rid != NULL && attr != NULL)
1012                 {
1013                         int i;
1014                         for (i = 0; i < num_rids; i++)
1015                         {
1016                                 rid [i] = mem_grp[i].rid;
1017                                 attr[i] = mem_grp[i].attr;
1018                         }
1019                         free(mem_grp);
1020                 }
1021         }
1022
1023         make_samr_r_query_groupmem(&r_u, num_rids, rid, attr, status);
1024
1025         /* store the response in the SMB stream */
1026         samr_io_r_query_groupmem("", &r_u, rdata, 0);
1027
1028         if (rid != NULL)
1029         {
1030                 free(rid);
1031         }
1032
1033         if (attr != NULL)
1034         {
1035                 free(attr);
1036         }
1037
1038         DEBUG(5,("samr_query_groupmem: %d\n", __LINE__));
1039
1040 }
1041
1042 /*******************************************************************
1043  api_samr_query_groupmem
1044  ********************************************************************/
1045 static void api_samr_query_groupmem( uint16 vuid, prs_struct *data, prs_struct *rdata)
1046 {
1047         SAMR_Q_QUERY_GROUPMEM q_u;
1048         samr_io_q_query_groupmem("", &q_u, data, 0);
1049         samr_reply_query_groupmem(&q_u, rdata);
1050 }
1051
1052
1053 /*******************************************************************
1054  samr_reply_query_groupinfo
1055  ********************************************************************/
1056 static void samr_reply_query_groupinfo(SAMR_Q_QUERY_GROUPINFO *q_u,
1057                                 prs_struct *rdata)
1058 {
1059         SAMR_R_QUERY_GROUPINFO r_e;
1060         GROUP_INFO_CTR ctr;
1061         uint32 status = 0x0;
1062
1063         r_e.ptr = 0;
1064
1065         /* find the policy handle.  open a policy on it. */
1066         if (r_e.status == 0x0 && (find_lsa_policy_by_hnd(&(q_u->pol)) == -1))
1067         {
1068                 r_e.status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
1069         }
1070
1071         DEBUG(5,("samr_reply_query_groupinfo: %d\n", __LINE__));
1072
1073         if (status == 0x0)
1074         {
1075                 if (q_u->switch_level == 1)
1076                 {
1077                         r_e.ptr = 1;
1078                         ctr.switch_value1 = 1;
1079                         make_samr_group_info1(&ctr.group.info1, "account name", "account description");
1080                 }
1081                 else if (q_u->switch_level == 4)
1082                 {
1083                         r_e.ptr = 1;
1084                         ctr.switch_value1 = 4;
1085                         make_samr_group_info4(&ctr.group.info4, "account description");
1086                 }
1087                 else
1088                 {
1089                         status = 0xC0000000 | NT_STATUS_INVALID_INFO_CLASS;
1090                 }
1091         }
1092
1093         make_samr_r_query_groupinfo(&r_e, status == 0 ? &ctr : NULL, status);
1094
1095         /* store the response in the SMB stream */
1096         samr_io_r_query_groupinfo("", &r_e, rdata, 0);
1097
1098         DEBUG(5,("samr_query_groupinfo: %d\n", __LINE__));
1099
1100 }
1101
1102 /*******************************************************************
1103  api_samr_query_groupinfo
1104  ********************************************************************/
1105 static void api_samr_query_groupinfo( uint16 vuid, prs_struct *data, prs_struct *rdata)
1106 {
1107         SAMR_Q_QUERY_GROUPINFO q_e;
1108         samr_io_q_query_groupinfo("", &q_e, data, 0);
1109         samr_reply_query_groupinfo(&q_e, rdata);
1110 }
1111
1112
1113 /*******************************************************************
1114  samr_reply_query_aliasinfo
1115  ********************************************************************/
1116 static void samr_reply_query_aliasinfo(SAMR_Q_QUERY_ALIASINFO *q_u,
1117                                 prs_struct *rdata)
1118 {
1119         SAMR_R_QUERY_ALIASINFO r_e;
1120         ALIAS_INFO_CTR ctr;
1121         uint32 status = 0x0;
1122
1123         r_e.ptr = 0;
1124
1125         /* find the policy handle.  open a policy on it. */
1126         if (r_e.status == 0x0 && (find_lsa_policy_by_hnd(&(q_u->pol)) == -1))
1127         {
1128                 r_e.status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
1129         }
1130
1131         DEBUG(5,("samr_reply_query_aliasinfo: %d\n", __LINE__));
1132
1133         if (status == 0x0)
1134         {
1135                 if (q_u->switch_level == 3)
1136                 {
1137                         r_e.ptr = 1;
1138                         ctr.switch_value1 = 3;
1139                         make_samr_alias_info3(&ctr.alias.info3, "<account description>");
1140                 }
1141                 else
1142                 {
1143                         status = 0xC0000000 | NT_STATUS_INVALID_INFO_CLASS;
1144                 }
1145         }
1146
1147         make_samr_r_query_aliasinfo(&r_e, status == 0 ? &ctr : NULL, status);
1148
1149         /* store the response in the SMB stream */
1150         samr_io_r_query_aliasinfo("", &r_e, rdata, 0);
1151
1152         DEBUG(5,("samr_query_aliasinfo: %d\n", __LINE__));
1153
1154 }
1155
1156 /*******************************************************************
1157  api_samr_query_aliasinfo
1158  ********************************************************************/
1159 static void api_samr_query_aliasinfo( uint16 vuid, prs_struct *data, prs_struct *rdata)
1160 {
1161         SAMR_Q_QUERY_ALIASINFO q_e;
1162         samr_io_q_query_aliasinfo("", &q_e, data, 0);
1163         samr_reply_query_aliasinfo(&q_e, rdata);
1164 }
1165
1166
1167 /*******************************************************************
1168  samr_reply_query_useraliases
1169  ********************************************************************/
1170 static void samr_reply_query_useraliases(SAMR_Q_QUERY_USERALIASES *q_u,
1171                                 prs_struct *rdata)
1172 {
1173         uint32 status = 0;
1174
1175         LOCAL_GRP *mem_grp = NULL;
1176         uint32 *rid = NULL;
1177         int num_rids = 0;
1178         struct sam_passwd *sam_pass;
1179         DOM_SID usr_sid;
1180         DOM_SID dom_sid;
1181         uint32 user_rid;
1182         fstring sam_sid_str;
1183         fstring dom_sid_str;
1184         fstring usr_sid_str;
1185
1186         SAMR_R_QUERY_USERALIASES r_u;
1187
1188         DEBUG(5,("samr_query_useraliases: %d\n", __LINE__));
1189
1190         /* find the policy handle.  open a policy on it. */
1191         if (status == 0x0 && !get_lsa_policy_samr_sid(&q_u->pol, &dom_sid))
1192         {
1193                 status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
1194         }
1195         else
1196         {
1197                 sid_to_string(dom_sid_str, &dom_sid       );
1198                 sid_to_string(sam_sid_str, &global_sam_sid);
1199         }
1200
1201         if (status == 0x0)
1202         {
1203                 usr_sid = q_u->sid[0].sid;
1204                 sid_split_rid(&usr_sid, &user_rid);
1205                 sid_to_string(usr_sid_str, &usr_sid);
1206
1207         }
1208
1209         if (status == 0x0)
1210         {
1211                 /* find the user account */
1212                 become_root(True);
1213                 sam_pass = getsam21pwrid(user_rid);
1214                 unbecome_root(True);
1215
1216                 if (sam_pass == NULL)
1217                 {
1218                         status = 0xC0000000 | NT_STATUS_NO_SUCH_USER;
1219                         num_rids = 0;
1220                 }
1221         }
1222
1223         if (status == 0x0)
1224         {
1225                 DEBUG(10,("sid is %s\n", dom_sid_str));
1226
1227                 if (sid_equal(&dom_sid, &global_sid_S_1_5_20))
1228                 {
1229                         DEBUG(10,("lookup on S-1-5-20\n"));
1230
1231                         become_root(True);
1232                         getuserbuiltinntnam(sam_pass->nt_name, &mem_grp, &num_rids);
1233                         unbecome_root(True);
1234                 }
1235                 else if (sid_equal(&dom_sid, &usr_sid))
1236                 {
1237                         DEBUG(10,("lookup on Domain SID\n"));
1238
1239                         become_root(True);
1240                         getuseraliasntnam(sam_pass->nt_name, &mem_grp, &num_rids);
1241                         unbecome_root(True);
1242                 }
1243                 else
1244                 {
1245                         status = 0xC0000000 | NT_STATUS_NO_SUCH_USER;
1246                 }
1247         }
1248
1249         if (status == 0x0 && num_rids > 0)
1250         {
1251                         rid = malloc(num_rids * sizeof(uint32));
1252                         if (mem_grp != NULL && rid != NULL)
1253                         {
1254                                 int i;
1255                                 for (i = 0; i < num_rids; i++)
1256                                 {
1257                                         rid[i] = mem_grp[i].rid;
1258                                 }
1259                                 free(mem_grp);
1260                 }
1261         }
1262
1263         make_samr_r_query_useraliases(&r_u, num_rids, rid, status);
1264
1265         /* store the response in the SMB stream */
1266         samr_io_r_query_useraliases("", &r_u, rdata, 0);
1267
1268         if (rid != NULL)
1269         {
1270                 free(rid);
1271         }
1272
1273         DEBUG(5,("samr_query_useraliases: %d\n", __LINE__));
1274
1275 }
1276
1277 /*******************************************************************
1278  api_samr_query_useraliases
1279  ********************************************************************/
1280 static void api_samr_query_useraliases( uint16 vuid, prs_struct *data, prs_struct *rdata)
1281 {
1282         SAMR_Q_QUERY_USERALIASES q_u;
1283         samr_io_q_query_useraliases("", &q_u, data, 0);
1284         samr_reply_query_useraliases(&q_u, rdata);
1285 }
1286
1287 /*******************************************************************
1288  samr_reply_delete_dom_alias
1289  ********************************************************************/
1290 static void samr_reply_delete_dom_alias(SAMR_Q_DELETE_DOM_ALIAS *q_u,
1291                                 prs_struct *rdata)
1292 {
1293         uint32 status = 0;
1294
1295         DOM_SID alias_sid;
1296         uint32 alias_rid;
1297         fstring alias_sid_str;
1298
1299         SAMR_R_DELETE_DOM_ALIAS r_u;
1300
1301         DEBUG(5,("samr_delete_dom_alias: %d\n", __LINE__));
1302
1303         /* find the policy handle.  open a policy on it. */
1304         if (status == 0x0 && !get_lsa_policy_samr_sid(&q_u->alias_pol, &alias_sid))
1305         {
1306                 status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
1307         }
1308         else
1309         {
1310                 sid_to_string(alias_sid_str, &alias_sid     );
1311                 sid_split_rid(&alias_sid, &alias_rid);
1312         }
1313
1314         if (status == 0x0)
1315         {
1316                 DEBUG(10,("sid is %s\n", alias_sid_str));
1317
1318                 if (sid_equal(&alias_sid, &global_sam_sid))
1319                 {
1320                         DEBUG(10,("lookup on Domain SID\n"));
1321
1322                         become_root(True);
1323                         status = del_alias_entry(alias_rid) ? 0x0 : 0xC0000000 | NT_STATUS_NO_SUCH_ALIAS;
1324                         unbecome_root(True);
1325                 }
1326                 else
1327                 {
1328                         status = 0xC0000000 | NT_STATUS_NO_SUCH_USER;
1329                 }
1330         }
1331
1332         make_samr_r_delete_dom_alias(&r_u, status);
1333
1334         /* store the response in the SMB stream */
1335         samr_io_r_delete_dom_alias("", &r_u, rdata, 0);
1336 }
1337
1338 /*******************************************************************
1339  api_samr_delete_dom_alias
1340  ********************************************************************/
1341 static void api_samr_delete_dom_alias( uint16 vuid, prs_struct *data, prs_struct *rdata)
1342 {
1343         SAMR_Q_DELETE_DOM_ALIAS q_u;
1344         samr_io_q_delete_dom_alias("", &q_u, data, 0);
1345         samr_reply_delete_dom_alias(&q_u, rdata);
1346 }
1347
1348
1349 /*******************************************************************
1350  samr_reply_query_aliasmem
1351  ********************************************************************/
1352 static void samr_reply_query_aliasmem(SAMR_Q_QUERY_ALIASMEM *q_u,
1353                                 prs_struct *rdata)
1354 {
1355         uint32 status = 0;
1356
1357         LOCAL_GRP_MEMBER *mem_grp = NULL;
1358         DOM_SID2 *sid = NULL;
1359         int num_sids = 0;
1360         DOM_SID alias_sid;
1361         uint32 alias_rid;
1362         fstring alias_sid_str;
1363
1364         SAMR_R_QUERY_ALIASMEM r_u;
1365
1366         DEBUG(5,("samr_query_aliasmem: %d\n", __LINE__));
1367
1368         /* find the policy handle.  open a policy on it. */
1369         if (status == 0x0 && !get_lsa_policy_samr_sid(&q_u->alias_pol, &alias_sid))
1370         {
1371                 status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
1372         }
1373         else
1374         {
1375                 sid_to_string(alias_sid_str, &alias_sid     );
1376                 sid_split_rid(&alias_sid, &alias_rid);
1377         }
1378
1379         if (status == 0x0)
1380         {
1381                 DEBUG(10,("sid is %s\n", alias_sid_str));
1382
1383                 if (sid_equal(&alias_sid, &global_sid_S_1_5_20))
1384                 {
1385                         DEBUG(10,("lookup on S-1-5-20\n"));
1386
1387                         become_root(True);
1388                         status = getbuiltinrid(alias_rid, &mem_grp, &num_sids) != NULL ? 0x0 : 0xC0000000 | NT_STATUS_NO_SUCH_GROUP;
1389                         unbecome_root(True);
1390                 }
1391                 else if (sid_equal(&alias_sid, &global_sam_sid))
1392                 {
1393                         DEBUG(10,("lookup on Domain SID\n"));
1394
1395                         become_root(True);
1396                         status = getaliasrid(alias_rid, &mem_grp, &num_sids) != NULL ? 0x0 : 0xC0000000 | NT_STATUS_NO_SUCH_GROUP;
1397                         unbecome_root(True);
1398                 }
1399                 else
1400                 {
1401                         status = 0xC0000000 | NT_STATUS_NO_SUCH_USER;
1402                 }
1403         }
1404
1405         if (status == 0x0 && num_sids > 0)
1406         {
1407                 sid = malloc(num_sids * sizeof(DOM_SID));
1408                 if (mem_grp != NULL && sid != NULL)
1409                 {
1410                         int i;
1411                         for (i = 0; i < num_sids; i++)
1412                         {
1413                                 make_dom_sid2(&sid[i], &mem_grp[i].sid);
1414                         }
1415                         free(mem_grp);
1416                 }
1417         }
1418
1419         make_samr_r_query_aliasmem(&r_u, num_sids, sid, status);
1420
1421         /* store the response in the SMB stream */
1422         samr_io_r_query_aliasmem("", &r_u, rdata, 0);
1423
1424         if (sid != NULL)
1425         {
1426                 free(sid);
1427         }
1428
1429         DEBUG(5,("samr_query_aliasmem: %d\n", __LINE__));
1430
1431 }
1432
1433 /*******************************************************************
1434  api_samr_query_aliasmem
1435  ********************************************************************/
1436 static void api_samr_query_aliasmem( uint16 vuid, prs_struct *data, prs_struct *rdata)
1437 {
1438         SAMR_Q_QUERY_ALIASMEM q_u;
1439         samr_io_q_query_aliasmem("", &q_u, data, 0);
1440         samr_reply_query_aliasmem(&q_u, rdata);
1441 }
1442
1443 /*******************************************************************
1444  samr_reply_lookup_names
1445  ********************************************************************/
1446 static void samr_reply_lookup_names(SAMR_Q_LOOKUP_NAMES *q_u,
1447                                 prs_struct *rdata)
1448 {
1449         uint32 rid [MAX_SAM_ENTRIES];
1450         uint8  type[MAX_SAM_ENTRIES];
1451         uint32 status     = 0;
1452         int i;
1453         int num_rids = q_u->num_names1;
1454         DOM_SID pol_sid;
1455
1456         SAMR_R_LOOKUP_NAMES r_u;
1457
1458         DEBUG(5,("samr_lookup_names: %d\n", __LINE__));
1459
1460         if (status == 0x0 && !get_lsa_policy_samr_sid(&q_u->pol, &pol_sid))
1461         {
1462                 status = 0xC0000000 | NT_STATUS_OBJECT_TYPE_MISMATCH;
1463         }
1464
1465         if (num_rids > MAX_SAM_ENTRIES)
1466         {
1467                 num_rids = MAX_SAM_ENTRIES;
1468                 DEBUG(5,("samr_lookup_names: truncating entries to %d\n", num_rids));
1469         }
1470
1471         SMB_ASSERT_ARRAY(q_u->uni_name, num_rids);
1472
1473         for (i = 0; i < num_rids && status == 0; i++)
1474         {
1475                 DOM_SID sid;
1476                 fstring name;
1477                 fstrcpy(name, unistr2_to_str(&q_u->uni_name[i]));
1478
1479                 status = lookup_name(name, &sid, &(type[i]));
1480                 if (status == 0x0)
1481                 {
1482                         sid_split_rid(&sid, &rid[i]);
1483                 }
1484                 else
1485                 {
1486                         type[i] = SID_NAME_UNKNOWN;
1487                         rid [i] = 0xffffffff;
1488                 }
1489                 if (!sid_equal(&pol_sid, &sid))
1490                 {
1491                         rid [i] = 0xffffffff;
1492                         type[i] = SID_NAME_UNKNOWN;
1493                 }
1494         }
1495
1496         make_samr_r_lookup_names(&r_u, num_rids, rid, type, status);
1497
1498         /* store the response in the SMB stream */
1499         samr_io_r_lookup_names("", &r_u, rdata, 0);
1500
1501         DEBUG(5,("samr_lookup_names: %d\n", __LINE__));
1502
1503 }
1504
1505 /*******************************************************************
1506  api_samr_lookup_names
1507  ********************************************************************/
1508 static void api_samr_lookup_names( uint16 vuid, prs_struct *data, prs_struct *rdata)
1509 {
1510         SAMR_Q_LOOKUP_NAMES q_u;
1511         samr_io_q_lookup_names("", &q_u, data, 0);
1512         samr_reply_lookup_names(&q_u, rdata);
1513 }
1514
1515 /*******************************************************************
1516  samr_reply_chgpasswd_user
1517  ********************************************************************/
1518 static void samr_reply_chgpasswd_user(SAMR_Q_CHGPASSWD_USER *q_u,
1519                                 prs_struct *rdata)
1520 {
1521         SAMR_R_CHGPASSWD_USER r_u;
1522         uint32 status = 0x0;
1523         fstring user_name;
1524         fstring wks;
1525
1526         fstrcpy(user_name, unistrn2(q_u->uni_user_name.buffer, q_u->uni_user_name.uni_str_len));
1527         fstrcpy(wks      , unistrn2(q_u->uni_dest_host.buffer, q_u->uni_dest_host.uni_str_len));
1528
1529         DEBUG(5,("samr_chgpasswd_user: user: %s wks: %s\n", user_name, wks));
1530
1531         if (!pass_oem_change(user_name,
1532                              q_u->lm_newpass.pass, q_u->lm_oldhash.hash,
1533                              q_u->nt_newpass.pass, q_u->nt_oldhash.hash))
1534         {
1535                 status = 0xC0000000 | NT_STATUS_WRONG_PASSWORD;
1536         }
1537
1538         make_samr_r_chgpasswd_user(&r_u, status);
1539
1540         /* store the response in the SMB stream */
1541         samr_io_r_chgpasswd_user("", &r_u, rdata, 0);
1542
1543         DEBUG(5,("samr_chgpasswd_user: %d\n", __LINE__));
1544 }
1545
1546 /*******************************************************************
1547  api_samr_chgpasswd_user
1548  ********************************************************************/
1549 static void api_samr_chgpasswd_user( uint16 vuid, prs_struct *data, prs_struct *rdata)
1550 {
1551         SAMR_Q_CHGPASSWD_USER q_u;
1552         samr_io_q_chgpasswd_user("", &q_u, data, 0);
1553         samr_reply_chgpasswd_user(&q_u, rdata);
1554 }
1555
1556
1557 /*******************************************************************
1558  samr_reply_unknown_38
1559  ********************************************************************/
1560 static void samr_reply_unknown_38(SAMR_Q_UNKNOWN_38 *q_u,
1561                                 prs_struct *rdata)
1562 {
1563         SAMR_R_UNKNOWN_38 r_u;
1564
1565         DEBUG(5,("samr_unknown_38: %d\n", __LINE__));
1566
1567         make_samr_r_unknown_38(&r_u);
1568
1569         /* store the response in the SMB stream */
1570         samr_io_r_unknown_38("", &r_u, rdata, 0);
1571
1572         DEBUG(5,("samr_unknown_38: %d\n", __LINE__));
1573 }
1574
1575 /*******************************************************************
1576  api_samr_unknown_38
1577  ********************************************************************/
1578 static void api_samr_unknown_38( uint16 vuid, prs_struct *data, prs_struct *rdata)
1579 {
1580         SAMR_Q_UNKNOWN_38 q_u;
1581         samr_io_q_unknown_38("", &q_u, data, 0);
1582         samr_reply_unknown_38(&q_u, rdata);
1583 }
1584
1585
1586 /*******************************************************************
1587  samr_reply_lookup_rids
1588  ********************************************************************/
1589 static void samr_reply_lookup_rids(SAMR_Q_LOOKUP_RIDS *q_u,
1590                                 prs_struct *rdata)
1591 {
1592         fstring group_names[MAX_SAM_ENTRIES];
1593         uint8   group_attrs[MAX_SAM_ENTRIES];
1594         uint32 status     = 0;
1595         int num_rids = q_u->num_rids1;
1596         DOM_SID pol_sid;
1597
1598         SAMR_R_LOOKUP_RIDS r_u;
1599
1600         DEBUG(5,("samr_lookup_rids: %d\n", __LINE__));
1601
1602         /* find the policy handle.  open a policy on it. */
1603         if (status == 0x0 && (find_lsa_policy_by_hnd(&(q_u->pol)) == -1))
1604         {
1605                 status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
1606         }
1607
1608         if (status == 0x0 && !get_lsa_policy_samr_sid(&q_u->pol, &pol_sid))
1609         {
1610                 status = 0xC0000000 | NT_STATUS_OBJECT_TYPE_MISMATCH;
1611         }
1612
1613         if (status == 0x0)
1614         {
1615                 int i;
1616                 if (num_rids > MAX_SAM_ENTRIES)
1617                 {
1618                         num_rids = MAX_SAM_ENTRIES;
1619                         DEBUG(5,("samr_lookup_rids: truncating entries to %d\n", num_rids));
1620                 }
1621
1622                 for (i = 0; i < num_rids && status == 0; i++)
1623                 {
1624                         DOM_SID sid;
1625                         sid_copy(&sid, &pol_sid);
1626                         sid_append_rid(&sid, q_u->rid[i]);
1627                         lookup_sid(&sid, group_names[i], &group_attrs[i]);
1628                 }
1629         }
1630
1631         make_samr_r_lookup_rids(&r_u, num_rids, group_names, group_attrs, status);
1632
1633         /* store the response in the SMB stream */
1634         samr_io_r_lookup_rids("", &r_u, rdata, 0);
1635
1636         DEBUG(5,("samr_lookup_rids: %d\n", __LINE__));
1637
1638 }
1639
1640 /*******************************************************************
1641  api_samr_lookup_rids
1642  ********************************************************************/
1643 static void api_samr_lookup_rids( uint16 vuid, prs_struct *data, prs_struct *rdata)
1644 {
1645         SAMR_Q_LOOKUP_RIDS q_u;
1646         samr_io_q_lookup_rids("", &q_u, data, 0);
1647         samr_reply_lookup_rids(&q_u, rdata);
1648 }
1649
1650
1651 /*******************************************************************
1652  samr_reply_open_user
1653  ********************************************************************/
1654 static void samr_reply_open_user(SAMR_Q_OPEN_USER *q_u,
1655                                 prs_struct *rdata,
1656                                 int status)
1657 {
1658         SAMR_R_OPEN_USER r_u;
1659         struct sam_passwd *sam_pass;
1660         BOOL pol_open = False;
1661
1662         /* set up the SAMR open_user response */
1663         bzero(r_u.user_pol.data, POL_HND_SIZE);
1664
1665         r_u.status = 0x0;
1666
1667         /* find the policy handle.  open a policy on it. */
1668         if (r_u.status == 0x0 && (find_lsa_policy_by_hnd(&(q_u->domain_pol)) == -1))
1669         {
1670                 r_u.status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
1671         }
1672
1673         /* get a (unique) handle.  open a policy on it. */
1674         if (r_u.status == 0x0 && !(pol_open = open_lsa_policy_hnd(&(r_u.user_pol))))
1675         {
1676                 r_u.status = 0xC0000000 | NT_STATUS_OBJECT_NAME_NOT_FOUND;
1677         }
1678
1679         become_root(True);
1680         sam_pass = getsam21pwrid(q_u->user_rid);
1681         unbecome_root(True);
1682
1683         /* check that the RID exists in our domain. */
1684         if (r_u.status == 0x0 && sam_pass == NULL)
1685         {
1686                 r_u.status = 0xC0000000 | NT_STATUS_NO_SUCH_USER;
1687         }
1688
1689         /* associate the RID with the (unique) handle. */
1690         if (r_u.status == 0x0 && !set_lsa_policy_samr_rid(&(r_u.user_pol), q_u->user_rid))
1691         {
1692                 /* oh, whoops.  don't know what error message to return, here */
1693                 r_u.status = 0xC0000000 | NT_STATUS_OBJECT_NAME_NOT_FOUND;
1694         }
1695
1696         if (r_u.status != 0 && pol_open)
1697         {
1698                 close_lsa_policy_hnd(&(r_u.user_pol));
1699         }
1700
1701         DEBUG(5,("samr_open_user: %d\n", __LINE__));
1702
1703         /* store the response in the SMB stream */
1704         samr_io_r_open_user("", &r_u, rdata, 0);
1705
1706         DEBUG(5,("samr_open_user: %d\n", __LINE__));
1707
1708 }
1709
1710 /*******************************************************************
1711  api_samr_open_user
1712  ********************************************************************/
1713 static void api_samr_open_user( uint16 vuid, prs_struct *data, prs_struct *rdata)
1714 {
1715         SAMR_Q_OPEN_USER q_u;
1716         samr_io_q_open_user("", &q_u, data, 0);
1717         samr_reply_open_user(&q_u, rdata, 0x0);
1718 }
1719
1720
1721 /*************************************************************************
1722  get_user_info_10
1723  *************************************************************************/
1724 static BOOL get_user_info_10(SAM_USER_INFO_10 *id10, uint32 user_rid)
1725 {
1726         struct sam_passwd *sam_pass;
1727
1728         become_root(True);
1729         sam_pass = getsam21pwrid(user_rid);
1730         unbecome_root(True);
1731
1732         if (sam_pass == NULL)
1733         {
1734                 DEBUG(4,("User 0x%x not found\n", user_rid));
1735                 return False;
1736         }
1737
1738         DEBUG(3,("User:[%s]\n", sam_pass->nt_name));
1739
1740         make_sam_user_info10(id10, sam_pass->acct_ctrl); 
1741
1742         return True;
1743 }
1744
1745 /*************************************************************************
1746  get_user_info_21
1747  *************************************************************************/
1748 static BOOL get_user_info_21(SAM_USER_INFO_21 *id21, uint32 user_rid)
1749 {
1750         struct sam_passwd *sam_pass;
1751         LOGON_HRS hrs;
1752         int i;
1753
1754         become_root(True);
1755         sam_pass = getsam21pwrid(user_rid);
1756         unbecome_root(True);
1757
1758         if (sam_pass == NULL)
1759         {
1760                 DEBUG(4,("User 0x%x not found\n", user_rid));
1761                 return False;
1762         }
1763
1764         DEBUG(3,("User:[%s]\n", sam_pass->nt_name));
1765
1766         /* create a LOGON_HRS structure */
1767         hrs.len = sam_pass->hours_len;
1768         SMB_ASSERT_ARRAY(hrs.hours, hrs.len);
1769         for (i = 0; i < hrs.len; i++)
1770         {
1771                 hrs.hours[i] = sam_pass->hours[i];
1772         }
1773
1774         make_sam_user_info21(id21,
1775
1776                            &sam_pass->logon_time,
1777                            &sam_pass->logoff_time,
1778                            &sam_pass->kickoff_time,
1779                            &sam_pass->pass_last_set_time,
1780                            &sam_pass->pass_can_change_time,
1781                            &sam_pass->pass_must_change_time,
1782
1783                            sam_pass->nt_name, /* user_name */
1784                            sam_pass->full_name, /* full_name */
1785                            sam_pass->home_dir, /* home_dir */
1786                            sam_pass->dir_drive, /* dir_drive */
1787                            sam_pass->logon_script, /* logon_script */
1788                            sam_pass->profile_path, /* profile_path */
1789                            sam_pass->acct_desc, /* description */
1790                            sam_pass->workstations, /* workstations user can log in from */
1791                            sam_pass->unknown_str, /* don't know, yet */
1792                            sam_pass->munged_dial, /* dialin info.  contains dialin path and tel no */
1793
1794                            sam_pass->user_rid, /* RID user_id */
1795                            sam_pass->group_rid, /* RID group_id */
1796                            sam_pass->acct_ctrl,
1797
1798                            sam_pass->unknown_3, /* unknown_3 */
1799                            sam_pass->logon_divs, /* divisions per week */
1800                            &hrs, /* logon hours */
1801                            sam_pass->unknown_5,
1802                            sam_pass->unknown_6);
1803
1804         return True;
1805 }
1806
1807 /*******************************************************************
1808  samr_reply_query_userinfo
1809  ********************************************************************/
1810 static void samr_reply_query_userinfo(SAMR_Q_QUERY_USERINFO *q_u,
1811                                 prs_struct *rdata)
1812 {
1813         SAMR_R_QUERY_USERINFO r_u;
1814 #if 0
1815         SAM_USER_INFO_11 id11;
1816 #endif
1817         SAM_USER_INFO_10 id10;
1818         SAM_USER_INFO_21 id21;
1819         void *info = NULL;
1820
1821         uint32 status = 0x0;
1822         uint32 rid = 0x0;
1823
1824         DEBUG(5,("samr_reply_query_userinfo: %d\n", __LINE__));
1825
1826         /* search for the handle */
1827         if (status == 0x0 && (find_lsa_policy_by_hnd(&(q_u->pol)) == -1))
1828         {
1829                 status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
1830         }
1831
1832         /* find the user's rid */
1833         if (status == 0x0 && (rid = get_lsa_policy_samr_rid(&(q_u->pol))) == 0xffffffff)
1834         {
1835                 status = 0xC0000000 | NT_STATUS_OBJECT_TYPE_MISMATCH;
1836         }
1837
1838         DEBUG(5,("samr_reply_query_userinfo: rid:0x%x\n", rid));
1839
1840         /* ok!  user info levels (there are lots: see MSDEV help), off we go... */
1841         if (status == 0x0)
1842         {
1843                 switch (q_u->switch_value)
1844                 {
1845                         case 0x10:
1846                         {
1847                                 info = (void*)&id10;
1848                                 status = get_user_info_10(&id10, rid) ? 0 : NT_STATUS_NO_SUCH_USER;
1849                                 break;
1850                         }
1851 #if 0
1852 /* whoops - got this wrong.  i think.  or don't understand what's happening. */
1853                         case 0x11:
1854                         {
1855                                 NTTIME expire;
1856                                 info = (void*)&id11;
1857                                 
1858                                 expire.low  = 0xffffffff;
1859                                 expire.high = 0x7fffffff;
1860
1861                                 make_sam_user_info11(&id11, &expire, "BROOKFIELDS$", 0x03ef, 0x201, 0x0080);
1862
1863                                 break;
1864                         }
1865 #endif
1866                         case 21:
1867                         {
1868                                 info = (void*)&id21;
1869                                 status = get_user_info_21(&id21, rid) ? 0 : NT_STATUS_NO_SUCH_USER;
1870                                 break;
1871                         }
1872
1873                         default:
1874                         {
1875                                 status = 0xC0000000 | NT_STATUS_INVALID_INFO_CLASS;
1876
1877                                 break;
1878                         }
1879                 }
1880         }
1881
1882         make_samr_r_query_userinfo(&r_u, q_u->switch_value, info, status);
1883
1884         /* store the response in the SMB stream */
1885         samr_io_r_query_userinfo("", &r_u, rdata, 0);
1886
1887         DEBUG(5,("samr_reply_query_userinfo: %d\n", __LINE__));
1888
1889 }
1890
1891 /*******************************************************************
1892  api_samr_query_userinfo
1893  ********************************************************************/
1894 static void api_samr_query_userinfo( uint16 vuid, prs_struct *data, prs_struct *rdata)
1895 {
1896         SAMR_Q_QUERY_USERINFO q_u;
1897         samr_io_q_query_userinfo("", &q_u, data, 0);
1898         samr_reply_query_userinfo(&q_u, rdata);
1899 }
1900
1901
1902 /*******************************************************************
1903  samr_reply_query_usergroups
1904  ********************************************************************/
1905 static void samr_reply_query_usergroups(SAMR_Q_QUERY_USERGROUPS *q_u,
1906                                 prs_struct *rdata)
1907 {
1908         SAMR_R_QUERY_USERGROUPS r_u;
1909         uint32 status = 0x0;
1910
1911         struct sam_passwd *sam_pass;
1912         DOM_GID *gids = NULL;
1913         int num_groups = 0;
1914         uint32 rid;
1915
1916         DEBUG(5,("samr_query_usergroups: %d\n", __LINE__));
1917
1918         /* find the policy handle.  open a policy on it. */
1919         if (status == 0x0 && (find_lsa_policy_by_hnd(&(q_u->pol)) == -1))
1920         {
1921                 status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
1922         }
1923
1924         /* find the user's rid */
1925         if (status == 0x0 && (rid = get_lsa_policy_samr_rid(&(q_u->pol))) == 0xffffffff)
1926         {
1927                 status = 0xC0000000 | NT_STATUS_OBJECT_TYPE_MISMATCH;
1928         }
1929
1930         if (status == 0x0)
1931         {
1932                 become_root(True);
1933                 sam_pass = getsam21pwrid(rid);
1934                 unbecome_root(True);
1935
1936                 if (sam_pass == NULL)
1937                 {
1938                         status = 0xC0000000 | NT_STATUS_NO_SUCH_USER;
1939                 }
1940         }
1941
1942         if (status == 0x0)
1943         {
1944                 DOMAIN_GRP *mem_grp = NULL;
1945
1946                 become_root(True);
1947                 getusergroupsntnam(sam_pass->nt_name, &mem_grp, &num_groups);
1948                 unbecome_root(True);
1949
1950                 gids = NULL;
1951                 num_groups = make_dom_gids(mem_grp, num_groups, &gids);
1952
1953                 if (mem_grp != NULL)
1954                 {
1955                         free(mem_grp);
1956                 }
1957         }
1958
1959         /* construct the response.  lkclXXXX: gids are not copied! */
1960         make_samr_r_query_usergroups(&r_u, num_groups, gids, status);
1961
1962         /* store the response in the SMB stream */
1963         samr_io_r_query_usergroups("", &r_u, rdata, 0);
1964
1965         if (gids)
1966         {
1967                 free((char *)gids);
1968         }
1969
1970         DEBUG(5,("samr_query_usergroups: %d\n", __LINE__));
1971
1972 }
1973
1974 /*******************************************************************
1975  api_samr_query_usergroups
1976  ********************************************************************/
1977 static void api_samr_query_usergroups( uint16 vuid, prs_struct *data, prs_struct *rdata)
1978 {
1979         SAMR_Q_QUERY_USERGROUPS q_u;
1980         samr_io_q_query_usergroups("", &q_u, data, 0);
1981         samr_reply_query_usergroups(&q_u, rdata);
1982 }
1983
1984
1985 /*******************************************************************
1986  opens a samr alias by rid, returns a policy handle.
1987  ********************************************************************/
1988 static uint32 open_samr_alias(DOM_SID *sid, POLICY_HND *alias_pol,
1989                                 uint32 alias_rid)
1990 {
1991         BOOL pol_open = False;
1992         uint32 status = 0x0;
1993
1994         /* get a (unique) handle.  open a policy on it. */
1995         if (status == 0x0 && !(pol_open = open_lsa_policy_hnd(alias_pol)))
1996         {
1997                 status = 0xC0000000 | NT_STATUS_OBJECT_NAME_NOT_FOUND;
1998         }
1999
2000         DEBUG(0,("TODO: verify that the alias rid exists\n"));
2001
2002         /* associate a RID with the (unique) handle. */
2003         if (status == 0x0 && !set_lsa_policy_samr_rid(alias_pol, alias_rid))
2004         {
2005                 /* oh, whoops.  don't know what error message to return, here */
2006                 status = 0xC0000000 | NT_STATUS_OBJECT_NAME_NOT_FOUND;
2007         }
2008
2009         sid_append_rid(sid, alias_rid);
2010
2011         /* associate an alias SID with the (unique) handle. */
2012         if (status == 0x0 && !set_lsa_policy_samr_sid(alias_pol, sid))
2013         {
2014                 /* oh, whoops.  don't know what error message to return, here */
2015                 status = 0xC0000000 | NT_STATUS_OBJECT_NAME_NOT_FOUND;
2016         }
2017
2018         if (status != 0 && pol_open)
2019         {
2020                 close_lsa_policy_hnd(alias_pol);
2021         }
2022
2023         return status;
2024 }
2025
2026 /*******************************************************************
2027  samr_reply_create_dom_alias
2028  ********************************************************************/
2029 static void samr_reply_create_dom_alias(SAMR_Q_CREATE_DOM_ALIAS *q_u,
2030                                 prs_struct *rdata)
2031 {
2032         SAMR_R_CREATE_DOM_ALIAS r_u;
2033         DOM_SID dom_sid;
2034         LOCAL_GRP grp;
2035         POLICY_HND alias_pol;
2036         uint32 status = 0x0;
2037
2038         bzero(&alias_pol, sizeof(alias_pol));
2039
2040         DEBUG(5,("samr_create_dom_alias: %d\n", __LINE__));
2041
2042         /* find the policy handle.  open a policy on it. */
2043         if (status == 0x0 && (find_lsa_policy_by_hnd(&(q_u->dom_pol)) == -1))
2044         {
2045                 status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
2046         }
2047
2048         /* find the domain sid */
2049         if (status == 0x0 && !get_lsa_policy_samr_sid(&q_u->dom_pol, &dom_sid))
2050         {
2051                 status = 0xC0000000 | NT_STATUS_OBJECT_TYPE_MISMATCH;
2052         }
2053
2054         if (!sid_equal(&dom_sid, &global_sam_sid))
2055         {
2056                 status = 0xC0000000 | NT_STATUS_ACCESS_DENIED;
2057         }
2058
2059         if (status == 0x0)
2060         {
2061                 fstrcpy(grp.name, unistr2_to_str(&q_u->uni_acct_desc));
2062                 fstrcpy(grp.comment, "");
2063                 grp.rid = 0xffffffff;
2064
2065                 become_root(True);
2066                 status = add_alias_entry(&grp) ? 0 : 0xC0000000 | NT_STATUS_ACCESS_DENIED;
2067                 unbecome_root(True);
2068         }
2069
2070         if (status == 0x0)
2071         {
2072                 status = open_samr_alias(&dom_sid, &alias_pol, grp.rid);
2073         }
2074
2075         /* construct the response. */
2076         make_samr_r_create_dom_alias(&r_u, &alias_pol, grp.rid, status);
2077
2078         /* store the response in the SMB stream */
2079         samr_io_r_create_dom_alias("", &r_u, rdata, 0);
2080
2081         DEBUG(5,("samr_create_dom_alias: %d\n", __LINE__));
2082
2083 }
2084
2085 /*******************************************************************
2086  api_samr_create_dom_alias
2087  ********************************************************************/
2088 static void api_samr_create_dom_alias( uint16 vuid, prs_struct *data, prs_struct *rdata)
2089 {
2090         SAMR_Q_CREATE_DOM_ALIAS q_u;
2091         samr_io_q_create_dom_alias("", &q_u, data, 0);
2092         samr_reply_create_dom_alias(&q_u, rdata);
2093 }
2094
2095
2096 /*******************************************************************
2097  opens a samr group by rid, returns a policy handle.
2098  ********************************************************************/
2099 static uint32 open_samr_group(DOM_SID *sid, POLICY_HND *group_pol,
2100                                 uint32 group_rid)
2101 {
2102         BOOL pol_open = False;
2103         uint32 status = 0x0;
2104
2105         /* get a (unique) handle.  open a policy on it. */
2106         if (status == 0x0 && !(pol_open = open_lsa_policy_hnd(group_pol)))
2107         {
2108                 status = 0xC0000000 | NT_STATUS_OBJECT_NAME_NOT_FOUND;
2109         }
2110
2111         DEBUG(0,("TODO: verify that the group rid exists\n"));
2112
2113         /* associate a RID with the (unique) handle. */
2114         if (status == 0x0 && !set_lsa_policy_samr_rid(group_pol, group_rid))
2115         {
2116                 /* oh, whoops.  don't know what error message to return, here */
2117                 status = 0xC0000000 | NT_STATUS_OBJECT_NAME_NOT_FOUND;
2118         }
2119
2120         sid_append_rid(sid, group_rid);
2121
2122         /* associate an group SID with the (unique) handle. */
2123         if (status == 0x0 && !set_lsa_policy_samr_sid(group_pol, sid))
2124         {
2125                 /* oh, whoops.  don't know what error message to return, here */
2126                 status = 0xC0000000 | NT_STATUS_OBJECT_NAME_NOT_FOUND;
2127         }
2128
2129         if (status != 0 && pol_open)
2130         {
2131                 close_lsa_policy_hnd(group_pol);
2132         }
2133
2134         return status;
2135 }
2136
2137 /*******************************************************************
2138  samr_reply_create_dom_group
2139  ********************************************************************/
2140 static void samr_reply_create_dom_group(SAMR_Q_CREATE_DOM_GROUP *q_u,
2141                                 prs_struct *rdata)
2142 {
2143         SAMR_R_CREATE_DOM_GROUP r_u;
2144         DOM_SID dom_sid;
2145         DOMAIN_GRP grp;
2146         POLICY_HND group_pol;
2147         uint32 status = 0x0;
2148
2149         bzero(&group_pol, sizeof(group_pol));
2150
2151         DEBUG(5,("samr_create_dom_group: %d\n", __LINE__));
2152
2153         /* find the policy handle.  open a policy on it. */
2154         if (status == 0x0 && (find_lsa_policy_by_hnd(&(q_u->pol)) == -1))
2155         {
2156                 status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
2157         }
2158
2159         /* find the domain sid */
2160         if (status == 0x0 && !get_lsa_policy_samr_sid(&q_u->pol, &dom_sid))
2161         {
2162                 status = 0xC0000000 | NT_STATUS_OBJECT_TYPE_MISMATCH;
2163         }
2164
2165         if (!sid_equal(&dom_sid, &global_sam_sid))
2166         {
2167                 status = 0xC0000000 | NT_STATUS_ACCESS_DENIED;
2168         }
2169
2170         if (status == 0x0)
2171         {
2172                 fstrcpy(grp.name, unistr2_to_str(&q_u->uni_acct_desc));
2173                 fstrcpy(grp.comment, "");
2174                 grp.rid = 0xffffffff;
2175                 grp.attr = 0x07;
2176
2177                 become_root(True);
2178                 status = add_group_entry(&grp) ? 0x0 : 0xC0000000 | NT_STATUS_ACCESS_DENIED;
2179                 unbecome_root(True);
2180         }
2181
2182         if (status == 0x0)
2183         {
2184                 status = open_samr_group(&dom_sid, &group_pol, grp.rid);
2185         }
2186
2187         /* construct the response. */
2188         make_samr_r_create_dom_group(&r_u, &group_pol, grp.rid, status);
2189
2190         /* store the response in the SMB stream */
2191         samr_io_r_create_dom_group("", &r_u, rdata, 0);
2192
2193         DEBUG(5,("samr_create_dom_group: %d\n", __LINE__));
2194
2195 }
2196
2197 /*******************************************************************
2198  api_samr_create_dom_group
2199  ********************************************************************/
2200 static void api_samr_create_dom_group( uint16 vuid, prs_struct *data, prs_struct *rdata)
2201 {
2202         SAMR_Q_CREATE_DOM_GROUP q_u;
2203         samr_io_q_create_dom_group("", &q_u, data, 0);
2204         samr_reply_create_dom_group(&q_u, rdata);
2205 }
2206
2207
2208 /*******************************************************************
2209  samr_reply_query_dom_info
2210  ********************************************************************/
2211 static void samr_reply_query_dom_info(SAMR_Q_QUERY_DOMAIN_INFO *q_u,
2212                                 prs_struct *rdata)
2213 {
2214         SAMR_R_QUERY_DOMAIN_INFO r_u;
2215         SAM_UNK_CTR ctr;
2216         uint16 switch_value = 0x0;
2217         uint32 status = 0x0;
2218
2219         ZERO_STRUCT(r_u);
2220         ZERO_STRUCT(ctr);
2221
2222         r_u.ctr = &ctr;
2223
2224         DEBUG(5,("samr_reply_query_dom_info: %d\n", __LINE__));
2225
2226         /* find the policy handle.  open a policy on it. */
2227         if (r_u.status == 0x0 && (find_lsa_policy_by_hnd(&(q_u->domain_pol)) == -1))
2228         {
2229                 r_u.status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
2230                 DEBUG(5,("samr_reply_query_dom_info: invalid handle\n"));
2231         }
2232
2233         if (status == 0x0)
2234         {
2235                 switch (q_u->switch_value)
2236                 {
2237                         case 0x06:
2238                         {
2239                                 switch_value = 0x6;
2240                                 make_unk_info6(&ctr.info.inf6);
2241
2242                                 break;
2243                         }
2244                         case 0x07:
2245                         {
2246                                 switch_value = 0x7;
2247                                 make_unk_info7(&ctr.info.inf7);
2248
2249                                 break;
2250                         }
2251                         case 0x02:
2252                         {
2253                                 switch_value = 0x2;
2254                                 make_unk_info2(&ctr.info.inf2, global_sam_name, global_myname);
2255
2256                                 break;
2257                         }
2258                         default:
2259                         {
2260                                 status = 0xC0000000 | NT_STATUS_INVALID_INFO_CLASS;
2261                                 break;
2262                         }
2263                 }
2264         }
2265
2266         make_samr_r_query_dom_info(&r_u, switch_value, &ctr, status);
2267
2268         /* store the response in the SMB stream */
2269         samr_io_r_query_dom_info("", &r_u, rdata, 0);
2270
2271         DEBUG(5,("samr_query_dom_info: %d\n", __LINE__));
2272
2273 }
2274
2275 /*******************************************************************
2276  api_samr_query_dom_info
2277  ********************************************************************/
2278 static void api_samr_query_dom_info( uint16 vuid, prs_struct *data, prs_struct *rdata)
2279 {
2280         SAMR_Q_QUERY_DOMAIN_INFO q_e;
2281         samr_io_q_query_dom_info("", &q_e, data, 0);
2282         samr_reply_query_dom_info(&q_e, rdata);
2283 }
2284
2285
2286
2287 /*******************************************************************
2288  samr_reply_unknown_32
2289  ********************************************************************/
2290 static void samr_reply_unknown_32(SAMR_Q_UNKNOWN_32 *q_u,
2291                                 prs_struct *rdata,
2292                                 int status)
2293 {
2294         int i;
2295         SAMR_R_UNKNOWN_32 r_u;
2296
2297         /* set up the SAMR unknown_32 response */
2298         bzero(r_u.pol.data, POL_HND_SIZE);
2299         if (status == 0)
2300         {
2301                 for (i = 4; i < POL_HND_SIZE; i++)
2302                 {
2303                         r_u.pol.data[i] = i+1;
2304                 }
2305         }
2306
2307         make_dom_rid4(&(r_u.rid4), 0x0030, 0, 0);
2308         r_u.status    = status;
2309
2310         DEBUG(5,("samr_unknown_32: %d\n", __LINE__));
2311
2312         /* store the response in the SMB stream */
2313         samr_io_r_unknown_32("", &r_u, rdata, 0);
2314
2315         DEBUG(5,("samr_unknown_32: %d\n", __LINE__));
2316
2317 }
2318
2319 /*******************************************************************
2320  api_samr_unknown_32
2321  ********************************************************************/
2322 static void api_samr_unknown_32( uint16 vuid, prs_struct *data, prs_struct *rdata)
2323 {
2324         uint32 status = 0;
2325         struct sam_passwd *sam_pass;
2326         fstring mach_acct;
2327
2328         SAMR_Q_UNKNOWN_32 q_u;
2329
2330         /* grab the samr unknown 32 */
2331         samr_io_q_unknown_32("", &q_u, data, 0);
2332
2333         /* find the machine account: tell the caller if it exists.
2334            lkclXXXX i have *no* idea if this is a problem or not
2335            or even if you are supposed to construct a different
2336            reply if the account already exists...
2337          */
2338
2339         fstrcpy(mach_acct, unistrn2(q_u.uni_mach_acct.buffer,
2340                                     q_u.uni_mach_acct.uni_str_len));
2341
2342         become_root(True);
2343         sam_pass = getsam21pwntnam(mach_acct);
2344         unbecome_root(True);
2345
2346         if (sam_pass != NULL)
2347         {
2348                 /* machine account exists: say so */
2349                 status = 0xC0000000 | NT_STATUS_USER_EXISTS;
2350         }
2351         else
2352         {
2353                 /* this could cause trouble... */
2354                 DEBUG(0,("trouble!\n"));
2355                 status = 0;
2356         }
2357
2358         /* construct reply. */
2359         samr_reply_unknown_32(&q_u, rdata, status);
2360 }
2361
2362
2363 /*******************************************************************
2364  samr_reply_connect_anon
2365  ********************************************************************/
2366 static void samr_reply_connect_anon(SAMR_Q_CONNECT_ANON *q_u,
2367                                 prs_struct *rdata)
2368 {
2369         SAMR_R_CONNECT_ANON r_u;
2370         BOOL pol_open = False;
2371
2372         /* set up the SAMR connect_anon response */
2373
2374         r_u.status = 0x0;
2375         /* get a (unique) handle.  open a policy on it. */
2376         if (r_u.status == 0x0 && !(pol_open = open_lsa_policy_hnd(&(r_u.connect_pol))))
2377         {
2378                 r_u.status = 0xC0000000 | NT_STATUS_OBJECT_NAME_NOT_FOUND;
2379         }
2380
2381         /* associate the domain SID with the (unique) handle. */
2382         if (r_u.status == 0x0 && !set_lsa_policy_samr_pol_status(&(r_u.connect_pol), q_u->unknown_0))
2383         {
2384                 /* oh, whoops.  don't know what error message to return, here */
2385                 r_u.status = 0xC0000000 | NT_STATUS_OBJECT_NAME_NOT_FOUND;
2386         }
2387
2388         if (r_u.status != 0 && pol_open)
2389         {
2390                 close_lsa_policy_hnd(&(r_u.connect_pol));
2391         }
2392
2393         DEBUG(5,("samr_connect_anon: %d\n", __LINE__));
2394
2395         /* store the response in the SMB stream */
2396         samr_io_r_connect_anon("", &r_u, rdata, 0);
2397
2398         DEBUG(5,("samr_connect_anon: %d\n", __LINE__));
2399
2400 }
2401
2402 /*******************************************************************
2403  api_samr_connect_anon
2404  ********************************************************************/
2405 static void api_samr_connect_anon( uint16 vuid, prs_struct *data, prs_struct *rdata)
2406 {
2407         SAMR_Q_CONNECT_ANON q_u;
2408         samr_io_q_connect_anon("", &q_u, data, 0);
2409         samr_reply_connect_anon(&q_u, rdata);
2410 }
2411
2412 /*******************************************************************
2413  samr_reply_connect
2414  ********************************************************************/
2415 static void samr_reply_connect(SAMR_Q_CONNECT *q_u,
2416                                 prs_struct *rdata)
2417 {
2418         SAMR_R_CONNECT r_u;
2419         BOOL pol_open = False;
2420
2421         /* set up the SAMR connect response */
2422
2423         r_u.status = 0x0;
2424         /* get a (unique) handle.  open a policy on it. */
2425         if (r_u.status == 0x0 && !(pol_open = open_lsa_policy_hnd(&(r_u.connect_pol))))
2426         {
2427                 r_u.status = 0xC0000000 | NT_STATUS_OBJECT_NAME_NOT_FOUND;
2428         }
2429
2430         /* associate the domain SID with the (unique) handle. */
2431         if (r_u.status == 0x0 && !set_lsa_policy_samr_pol_status(&(r_u.connect_pol), q_u->unknown_0))
2432         {
2433                 /* oh, whoops.  don't know what error message to return, here */
2434                 r_u.status = 0xC0000000 | NT_STATUS_OBJECT_NAME_NOT_FOUND;
2435         }
2436
2437         if (r_u.status != 0 && pol_open)
2438         {
2439                 close_lsa_policy_hnd(&(r_u.connect_pol));
2440         }
2441
2442         DEBUG(5,("samr_connect: %d\n", __LINE__));
2443
2444         /* store the response in the SMB stream */
2445         samr_io_r_connect("", &r_u, rdata, 0);
2446
2447         DEBUG(5,("samr_connect: %d\n", __LINE__));
2448
2449 }
2450
2451 /*******************************************************************
2452  api_samr_connect
2453  ********************************************************************/
2454 static void api_samr_connect( uint16 vuid, prs_struct *data, prs_struct *rdata)
2455 {
2456         SAMR_Q_CONNECT q_u;
2457         samr_io_q_connect("", &q_u, data, 0);
2458         samr_reply_connect(&q_u, rdata);
2459 }
2460
2461 /*******************************************************************
2462  samr_reply_open_alias
2463  ********************************************************************/
2464 static void samr_reply_open_alias(SAMR_Q_OPEN_ALIAS *q_u,
2465                                 prs_struct *rdata)
2466 {
2467         SAMR_R_OPEN_ALIAS r_u;
2468         DOM_SID sid;
2469         BOOL pol_open = False;
2470
2471         /* set up the SAMR open_alias response */
2472
2473         r_u.status = 0x0;
2474         if (r_u.status == 0x0 && !get_lsa_policy_samr_sid(&q_u->dom_pol, &sid))
2475         {
2476                 r_u.status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
2477         }
2478
2479         /* get a (unique) handle.  open a policy on it. */
2480         if (r_u.status == 0x0 && !(pol_open = open_lsa_policy_hnd(&(r_u.pol))))
2481         {
2482                 r_u.status = 0xC0000000 | NT_STATUS_OBJECT_NAME_NOT_FOUND;
2483         }
2484
2485         DEBUG(0,("TODO: verify that the alias rid exists\n"));
2486
2487         /* associate a RID with the (unique) handle. */
2488         if (r_u.status == 0x0 && !set_lsa_policy_samr_rid(&(r_u.pol), q_u->rid_alias))
2489         {
2490                 /* oh, whoops.  don't know what error message to return, here */
2491                 r_u.status = 0xC0000000 | NT_STATUS_OBJECT_NAME_NOT_FOUND;
2492         }
2493
2494         sid_append_rid(&sid, q_u->rid_alias);
2495
2496         /* associate an alias SID with the (unique) handle. */
2497         if (r_u.status == 0x0 && !set_lsa_policy_samr_sid(&(r_u.pol), &sid))
2498         {
2499                 /* oh, whoops.  don't know what error message to return, here */
2500                 r_u.status = 0xC0000000 | NT_STATUS_OBJECT_NAME_NOT_FOUND;
2501         }
2502
2503         if (r_u.status != 0 && pol_open)
2504         {
2505                 close_lsa_policy_hnd(&(r_u.pol));
2506         }
2507
2508         DEBUG(5,("samr_open_alias: %d\n", __LINE__));
2509
2510         /* store the response in the SMB stream */
2511         samr_io_r_open_alias("", &r_u, rdata, 0);
2512
2513         DEBUG(5,("samr_open_alias: %d\n", __LINE__));
2514
2515 }
2516
2517 /*******************************************************************
2518  api_samr_open_alias
2519  ********************************************************************/
2520 static void api_samr_open_alias( uint16 vuid, prs_struct *data, prs_struct *rdata)
2521                                 
2522 {
2523         SAMR_Q_OPEN_ALIAS q_u;
2524         samr_io_q_open_alias("", &q_u, data, 0);
2525         samr_reply_open_alias(&q_u, rdata);
2526 }
2527
2528 /*******************************************************************
2529  samr_reply_open_group
2530  ********************************************************************/
2531 static void samr_reply_open_group(SAMR_Q_OPEN_GROUP *q_u,
2532                                 prs_struct *rdata)
2533 {
2534         SAMR_R_OPEN_GROUP r_u;
2535         DOM_SID sid;
2536
2537         DEBUG(5,("samr_open_group: %d\n", __LINE__));
2538
2539         r_u.status = 0x0;
2540
2541         /* find the domain sid associated with the policy handle */
2542         if (r_u.status == 0x0 && !get_lsa_policy_samr_sid(&q_u->domain_pol, &sid))
2543         {
2544                 r_u.status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
2545         }
2546
2547         if (r_u.status == 0x0 && !sid_equal(&sid, &global_sam_sid))
2548         {
2549                 r_u.status = 0xC0000000 | NT_STATUS_ACCESS_DENIED;
2550         }
2551
2552         if (r_u.status == 0x0)
2553         {
2554                 r_u.status = open_samr_group(&sid, &r_u.pol, q_u->rid_group);
2555         }
2556
2557         /* store the response in the SMB stream */
2558         samr_io_r_open_group("", &r_u, rdata, 0);
2559
2560         DEBUG(5,("samr_open_group: %d\n", __LINE__));
2561
2562 }
2563
2564 /*******************************************************************
2565  api_samr_open_group
2566  ********************************************************************/
2567 static void api_samr_open_group( uint16 vuid, prs_struct *data, prs_struct *rdata)
2568                                 
2569 {
2570         SAMR_Q_OPEN_GROUP q_u;
2571         samr_io_q_open_group("", &q_u, data, 0);
2572         samr_reply_open_group(&q_u, rdata);
2573 }
2574
2575 /*******************************************************************
2576  array of \PIPE\samr operations
2577  ********************************************************************/
2578 static struct api_struct api_samr_cmds [] =
2579 {
2580         { "SAMR_CLOSE_HND"        , SAMR_CLOSE_HND        , api_samr_close_hnd        },
2581         { "SAMR_CONNECT"          , SAMR_CONNECT          , api_samr_connect          },
2582         { "SAMR_CONNECT_ANON"     , SAMR_CONNECT_ANON     , api_samr_connect_anon     },
2583         { "SAMR_ENUM_DOM_USERS"   , SAMR_ENUM_DOM_USERS   , api_samr_enum_dom_users   },
2584         { "SAMR_ENUM_DOM_GROUPS"  , SAMR_ENUM_DOM_GROUPS  , api_samr_enum_dom_groups  },
2585         { "SAMR_ENUM_DOM_ALIASES" , SAMR_ENUM_DOM_ALIASES , api_samr_enum_dom_aliases },
2586         { "SAMR_QUERY_USERALIASES", SAMR_QUERY_USERALIASES, api_samr_query_useraliases},
2587         { "SAMR_QUERY_ALIASMEM"   , SAMR_QUERY_ALIASMEM   , api_samr_query_aliasmem   },
2588         { "SAMR_QUERY_GROUPMEM"   , SAMR_QUERY_GROUPMEM   , api_samr_query_groupmem   },
2589         { "SAMR_ADD_ALIASMEM"     , SAMR_ADD_ALIASMEM     , api_samr_del_aliasmem     },
2590         { "SAMR_DEL_ALIASMEM"     , SAMR_DEL_ALIASMEM     , api_samr_add_aliasmem     },
2591         { "SAMR_ADD_GROUPMEM"     , SAMR_ADD_GROUPMEM     , api_samr_del_groupmem     },
2592         { "SAMR_DEL_GROUPMEM"     , SAMR_DEL_GROUPMEM     , api_samr_add_groupmem     },
2593         { "SAMR_DELETE_DOM_GROUP" , SAMR_DELETE_DOM_GROUP , api_samr_delete_dom_group },
2594         { "SAMR_DELETE_DOM_ALIAS" , SAMR_DELETE_DOM_ALIAS , api_samr_delete_dom_alias },
2595         { "SAMR_CREATE_DOM_GROUP" , SAMR_CREATE_DOM_GROUP , api_samr_create_dom_group },
2596         { "SAMR_CREATE_DOM_ALIAS" , SAMR_CREATE_DOM_ALIAS , api_samr_create_dom_alias },
2597         { "SAMR_LOOKUP_NAMES"     , SAMR_LOOKUP_NAMES     , api_samr_lookup_names     },
2598         { "SAMR_OPEN_USER"        , SAMR_OPEN_USER        , api_samr_open_user        },
2599         { "SAMR_QUERY_USERINFO"   , SAMR_QUERY_USERINFO   , api_samr_query_userinfo   },
2600         { "SAMR_QUERY_DOMAIN_INFO", SAMR_QUERY_DOMAIN_INFO, api_samr_query_dom_info   },
2601         { "SAMR_QUERY_USERGROUPS" , SAMR_QUERY_USERGROUPS , api_samr_query_usergroups },
2602         { "SAMR_QUERY_DISPINFO"   , SAMR_QUERY_DISPINFO   , api_samr_query_dispinfo   },
2603         { "SAMR_QUERY_ALIASINFO"  , SAMR_QUERY_ALIASINFO  , api_samr_query_aliasinfo  },
2604         { "SAMR_QUERY_GROUPINFO"  , SAMR_QUERY_GROUPINFO  , api_samr_query_groupinfo  },
2605         { "SAMR_0x32"             , SAMR_UNKNOWN_32       , api_samr_unknown_32       },
2606         { "SAMR_LOOKUP_RIDS"      , SAMR_LOOKUP_RIDS      , api_samr_lookup_rids      },
2607         { "SAMR_UNKNOWN_38"       , SAMR_UNKNOWN_38       , api_samr_unknown_38       },
2608         { "SAMR_CHGPASSWD_USER"   , SAMR_CHGPASSWD_USER   , api_samr_chgpasswd_user   },
2609         { "SAMR_OPEN_ALIAS"       , SAMR_OPEN_ALIAS       , api_samr_open_alias       },
2610         { "SAMR_OPEN_GROUP"       , SAMR_OPEN_GROUP       , api_samr_open_group       },
2611         { "SAMR_OPEN_DOMAIN"      , SAMR_OPEN_DOMAIN      , api_samr_open_domain      },
2612         { "SAMR_UNKNOWN_3"        , SAMR_UNKNOWN_3        , api_samr_unknown_3        },
2613         { "SAMR_UNKNOWN_2C"       , SAMR_UNKNOWN_2C       , api_samr_unknown_2c       },
2614         { NULL                    , 0                     , NULL                      }
2615 };
2616
2617 /*******************************************************************
2618  receives a samr pipe and responds.
2619  ********************************************************************/
2620 BOOL api_samr_rpc(pipes_struct *p, prs_struct *data)
2621 {
2622     return api_rpcTNP(p, "api_samr_rpc", api_samr_cmds, data);
2623 }
2624