added createalias command to rpcclient
[samba.git] / source3 / 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
154         /* grab the samr unknown 1 */
155         samr_io_q_close_hnd("", &q_u, data, 0);
156
157         /* construct reply.  always indicate success */
158         samr_reply_close_hnd(&q_u, rdata);
159 }
160
161
162 /*******************************************************************
163  samr_reply_open_domain
164  ********************************************************************/
165 static void samr_reply_open_domain(SAMR_Q_OPEN_DOMAIN *q_u,
166                                 prs_struct *rdata)
167 {
168         SAMR_R_OPEN_DOMAIN r_u;
169         BOOL pol_open = False;
170
171         r_u.status = 0x0;
172
173         /* find the connection policy handle. */
174         if (r_u.status == 0x0 && (find_lsa_policy_by_hnd(&(q_u->connect_pol)) == -1))
175         {
176                 r_u.status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
177         }
178
179         /* get a (unique) handle.  open a policy on it. */
180         if (r_u.status == 0x0 && !(pol_open = open_lsa_policy_hnd(&(r_u.domain_pol))))
181         {
182                 r_u.status = 0xC0000000 | NT_STATUS_OBJECT_NAME_NOT_FOUND;
183         }
184
185         /* associate the domain SID with the (unique) handle. */
186         if (r_u.status == 0x0 && !set_lsa_policy_samr_sid(&(r_u.domain_pol), &(q_u->dom_sid.sid)))
187         {
188                 /* oh, whoops.  don't know what error message to return, here */
189                 r_u.status = 0xC0000000 | NT_STATUS_OBJECT_NAME_NOT_FOUND;
190         }
191
192         if (r_u.status != 0 && pol_open)
193         {
194                 close_lsa_policy_hnd(&(r_u.domain_pol));
195         }
196
197         DEBUG(5,("samr_open_domain: %d\n", __LINE__));
198
199         /* store the response in the SMB stream */
200         samr_io_r_open_domain("", &r_u, rdata, 0);
201
202         DEBUG(5,("samr_open_domain: %d\n", __LINE__));
203
204 }
205
206 /*******************************************************************
207  api_samr_open_domain
208  ********************************************************************/
209 static void api_samr_open_domain( uint16 vuid, prs_struct *data, prs_struct *rdata)
210 {
211         SAMR_Q_OPEN_DOMAIN q_u;
212
213         /* grab the samr open */
214         samr_io_q_open_domain("", &q_u, data, 0);
215
216         /* construct reply.  always indicate success */
217         samr_reply_open_domain(&q_u, rdata);
218 }
219
220
221 /*******************************************************************
222  samr_reply_unknown_2c
223  ********************************************************************/
224 static void samr_reply_unknown_2c(SAMR_Q_UNKNOWN_2C *q_u,
225                                 prs_struct *rdata)
226 {
227         SAMR_R_UNKNOWN_2C r_u;
228         uint32 status = 0x0;
229
230         /* find the policy handle.  open a policy on it. */
231         if (status == 0x0 && (find_lsa_policy_by_hnd(&(q_u->user_pol)) == -1))
232         {
233                 status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
234         }
235
236         /* find the user's rid */
237         if ((status == 0x0) && (get_lsa_policy_samr_rid(&(q_u->user_pol)) == 0xffffffff))
238         {
239                 status = NT_STATUS_OBJECT_TYPE_MISMATCH;
240         }
241
242         make_samr_r_unknown_2c(&r_u, status);
243
244         DEBUG(5,("samr_unknown_2c: %d\n", __LINE__));
245
246         /* store the response in the SMB stream */
247         samr_io_r_unknown_2c("", &r_u, rdata, 0);
248
249         DEBUG(5,("samr_unknown_2c: %d\n", __LINE__));
250
251 }
252
253 /*******************************************************************
254  api_samr_unknown_2c
255  ********************************************************************/
256 static void api_samr_unknown_2c( uint16 vuid, prs_struct *data, prs_struct *rdata)
257 {
258         SAMR_Q_UNKNOWN_2C q_u;
259
260         /* grab the samr open */
261         samr_io_q_unknown_2c("", &q_u, data, 0);
262
263         /* construct reply.  always indicate success */
264         samr_reply_unknown_2c(&q_u, rdata);
265 }
266
267
268 /*******************************************************************
269  samr_reply_unknown_3
270  ********************************************************************/
271 static void samr_reply_unknown_3(SAMR_Q_UNKNOWN_3 *q_u,
272                                 prs_struct *rdata)
273 {
274         SAMR_R_UNKNOWN_3 r_u;
275         DOM_SID3 sid[MAX_SAM_SIDS];
276         uint32 rid;
277         uint32 status;
278
279         status = 0x0;
280
281         /* find the policy handle.  open a policy on it. */
282         if (status == 0x0 && (find_lsa_policy_by_hnd(&(q_u->user_pol)) == -1))
283         {
284                 status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
285         }
286
287         /* find the user's rid */
288         if (status == 0x0 && (rid = get_lsa_policy_samr_rid(&(q_u->user_pol))) == 0xffffffff)
289         {
290                 status = NT_STATUS_OBJECT_TYPE_MISMATCH;
291         }
292
293         if (status == 0x0)
294         {
295                 DOM_SID usr_sid;
296
297                 usr_sid = global_sam_sid;
298
299                 SMB_ASSERT_ARRAY(usr_sid.sub_auths, usr_sid.num_auths+1);
300
301                 /*
302                  * Add the user RID.
303                  */
304                 sid_append_rid(&usr_sid, rid);
305                 
306                 /* maybe need another 1 or 2 (S-1-5-0x20-0x220 and S-1-5-20-0x224) */
307                 /* these two are DOMAIN_ADMIN and DOMAIN_ACCT_OP group RIDs */
308                 make_dom_sid3(&(sid[0]), 0x035b, 0x0002, &global_sid_S_1_1);
309                 make_dom_sid3(&(sid[1]), 0x0044, 0x0002, &usr_sid);
310         }
311
312         make_samr_r_unknown_3(&r_u,
313                                 0x0001, 0x8004,
314                                 0x00000014, 0x0002, 0x0070,
315                                 2, sid, status);
316
317         DEBUG(5,("samr_unknown_3: %d\n", __LINE__));
318
319         /* store the response in the SMB stream */
320         samr_io_r_unknown_3("", &r_u, rdata, 0);
321
322         DEBUG(5,("samr_unknown_3: %d\n", __LINE__));
323
324 }
325
326 /*******************************************************************
327  api_samr_unknown_3
328  ********************************************************************/
329 static void api_samr_unknown_3( uint16 vuid, prs_struct *data, prs_struct *rdata)
330 {
331         SAMR_Q_UNKNOWN_3 q_u;
332
333         /* grab the samr open */
334         samr_io_q_unknown_3("", &q_u, data, 0);
335
336         /* construct reply.  always indicate success */
337         samr_reply_unknown_3(&q_u, rdata);
338 }
339
340
341 /*******************************************************************
342  samr_reply_enum_dom_users
343  ********************************************************************/
344 static void samr_reply_enum_dom_users(SAMR_Q_ENUM_DOM_USERS *q_u,
345                                 prs_struct *rdata)
346 {
347         SAMR_R_ENUM_DOM_USERS r_e;
348         SAM_USER_INFO_21 pass[MAX_SAM_ENTRIES];
349         int num_entries;
350         int total_entries;
351
352         r_e.status = 0x0;
353         r_e.total_num_entries = 0;
354
355         /* find the policy handle.  open a policy on it. */
356         if (r_e.status == 0x0 && (find_lsa_policy_by_hnd(&(q_u->pol)) == -1))
357         {
358                 r_e.status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
359         }
360
361         DEBUG(5,("samr_reply_enum_dom_users: %d\n", __LINE__));
362
363         become_root(True);
364         get_sampwd_entries(pass, 0, &total_entries, &num_entries, MAX_SAM_ENTRIES, q_u->acb_mask);
365         unbecome_root(True);
366
367         make_samr_r_enum_dom_users(&r_e, total_entries,
368                                    q_u->unknown_0, num_entries,
369                                    pass, r_e.status);
370
371         /* store the response in the SMB stream */
372         samr_io_r_enum_dom_users("", &r_e, rdata, 0);
373
374         DEBUG(5,("samr_enum_dom_users: %d\n", __LINE__));
375
376 }
377
378 /*******************************************************************
379  api_samr_enum_dom_users
380  ********************************************************************/
381 static void api_samr_enum_dom_users( uint16 vuid, prs_struct *data, prs_struct *rdata)
382 {
383         SAMR_Q_ENUM_DOM_USERS q_e;
384
385         /* grab the samr open */
386         samr_io_q_enum_dom_users("", &q_e, data, 0);
387
388         /* construct reply. */
389         samr_reply_enum_dom_users(&q_e, rdata);
390 }
391
392
393 /*******************************************************************
394  samr_reply_enum_dom_groups
395  ********************************************************************/
396 static void samr_reply_enum_dom_groups(SAMR_Q_ENUM_DOM_GROUPS *q_u,
397                                 prs_struct *rdata)
398 {
399         SAMR_R_ENUM_DOM_GROUPS r_e;
400         DOMAIN_GRP *grps = NULL;
401         int num_entries = 0;
402         BOOL got_grps = False;
403         DOM_SID sid;
404         fstring sid_str;
405
406         r_e.status = 0x0;
407         r_e.num_entries = 0;
408
409         /* find the policy handle.  open a policy on it. */
410         if (r_e.status == 0x0 && !get_lsa_policy_samr_sid(&q_u->pol, &sid))
411         {
412                 r_e.status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
413         }
414
415         sid_to_string(sid_str, &sid);
416
417         DEBUG(5,("samr_reply_enum_dom_groups: sid %s\n", sid_str));
418
419         if (sid_equal(&sid, &global_sam_sid))
420         {
421                 BOOL ret;
422                 got_grps = True;
423
424                 become_root(True);
425                 ret = enumdomgroups(&grps, &num_entries);
426                 unbecome_root(True);
427
428                 if (!ret)
429                 {
430                         r_e.status = 0xC0000000 | NT_STATUS_NO_MEMORY;
431                 }
432         }
433
434         if (r_e.status == 0x0 &&
435             (sid_equal(&sid, &global_sam_sid) ||
436              sid_equal(&sid, &global_sid_S_1_5_20)))
437         {
438                 char *name;
439                 int i = 0;
440                 got_grps = True;
441
442                 while (num_entries < MAX_SAM_ENTRIES && ((name = domain_group_rids[i].name) != NULL))
443                 {
444                         DOMAIN_GRP tmp_grp;
445
446                         fstrcpy(tmp_grp.name   , name);
447                         fstrcpy(tmp_grp.comment, "");
448                         tmp_grp.rid = domain_group_rids[i].rid;
449                         tmp_grp.attr = 0x7;
450
451                         if (!add_domain_group(&grps, &num_entries, &tmp_grp))
452                         {
453                                 r_e.status = 0xC0000000 | NT_STATUS_NO_MEMORY;
454                                 break;
455                         }
456
457                         i++;
458                 }
459         }
460
461         if (r_e.status == 0 && got_grps)
462         {
463                 make_samr_r_enum_dom_groups(&r_e, q_u->start_idx, num_entries, grps, r_e.status);
464         }
465
466         /* store the response in the SMB stream */
467         samr_io_r_enum_dom_groups("", &r_e, rdata, 0);
468
469         if (grps != NULL)
470         {
471                 free(grps);
472         }
473
474         DEBUG(5,("samr_enum_dom_groups: %d\n", __LINE__));
475 }
476
477 /*******************************************************************
478  api_samr_enum_dom_groups
479  ********************************************************************/
480 static void api_samr_enum_dom_groups( uint16 vuid, prs_struct *data, prs_struct *rdata)
481 {
482         SAMR_Q_ENUM_DOM_GROUPS q_e;
483
484         /* grab the samr open */
485         samr_io_q_enum_dom_groups("", &q_e, data, 0);
486
487         /* construct reply. */
488         samr_reply_enum_dom_groups(&q_e, rdata);
489 }
490
491
492 /*******************************************************************
493  samr_reply_enum_dom_aliases
494  ********************************************************************/
495 static void samr_reply_enum_dom_aliases(SAMR_Q_ENUM_DOM_ALIASES *q_u,
496                                 prs_struct *rdata)
497 {
498         SAMR_R_ENUM_DOM_ALIASES r_e;
499         LOCAL_GRP *alss = NULL;
500         int num_entries = 0;
501         DOM_SID sid;
502         fstring sid_str;
503
504         r_e.status = 0x0;
505         r_e.num_entries = 0;
506
507         /* find the policy handle.  open a policy on it. */
508         if (r_e.status == 0x0 && !get_lsa_policy_samr_sid(&q_u->pol, &sid))
509         {
510                 r_e.status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
511         }
512
513         sid_to_string(sid_str, &sid);
514
515         DEBUG(5,("samr_reply_enum_dom_aliases: sid %s\n", sid_str));
516
517         /* well-known aliases */
518         if (sid_equal(&sid, &global_sid_S_1_5_20))
519         {
520                 char *name;
521
522                 while ((name = builtin_alias_rids[num_entries].name) != NULL)
523                 {
524                         LOCAL_GRP tmp_als;
525
526                         fstrcpy(tmp_als.name   , name);
527                         fstrcpy(tmp_als.comment, "");
528                         tmp_als.rid = builtin_alias_rids[num_entries].rid;
529
530                         if (!add_domain_alias(&alss, &num_entries, &tmp_als))
531                         {
532                                 r_e.status = 0xC0000000 | NT_STATUS_NO_MEMORY;
533                                 break;
534                         }
535                 }
536         }
537         else if (sid_equal(&sid, &global_sam_sid))
538         {
539                 BOOL ret;
540                 /* local aliases */
541                 num_entries = 0;
542
543                 become_root(True);
544                 ret = enumdomaliases(&alss, &num_entries);
545                 unbecome_root(True);
546                 if (!ret)
547                 {
548                         r_e.status = 0xC0000000 | NT_STATUS_NO_MEMORY;
549                 }
550         }
551                 
552         if (r_e.status == 0x0)
553         {
554                 make_samr_r_enum_dom_aliases(&r_e, num_entries, alss, r_e.status);
555         }
556
557         /* store the response in the SMB stream */
558         samr_io_r_enum_dom_aliases("", &r_e, rdata, 0);
559
560         if (alss != NULL)
561         {
562                 free(alss);
563         }
564
565         DEBUG(5,("samr_enum_dom_aliases: %d\n", __LINE__));
566
567 }
568
569 /*******************************************************************
570  api_samr_enum_dom_aliases
571  ********************************************************************/
572 static void api_samr_enum_dom_aliases( uint16 vuid, prs_struct *data, prs_struct *rdata)
573 {
574         SAMR_Q_ENUM_DOM_ALIASES q_e;
575
576         /* grab the samr open */
577         samr_io_q_enum_dom_aliases("", &q_e, data, 0);
578
579         /* construct reply. */
580         samr_reply_enum_dom_aliases(&q_e, rdata);
581 }
582
583
584 /*******************************************************************
585  samr_reply_query_dispinfo
586  ********************************************************************/
587 static void samr_reply_query_dispinfo(SAMR_Q_QUERY_DISPINFO *q_u,
588                                 prs_struct *rdata)
589 {
590         SAMR_R_QUERY_DISPINFO r_e;
591         SAM_INFO_CTR ctr;
592         SAM_INFO_1 info1;
593         SAM_INFO_2 info2;
594         SAM_USER_INFO_21 pass[MAX_SAM_ENTRIES];
595         int num_entries = 0;
596         int total_entries = 0;
597         BOOL got_pwds;
598         uint16 switch_level = 0x0;
599
600         ZERO_STRUCT(r_e);
601
602         r_e.status = 0x0;
603
604         DEBUG(5,("samr_reply_query_dispinfo: %d\n", __LINE__));
605
606         /* find the policy handle.  open a policy on it. */
607         if (r_e.status == 0x0 && (find_lsa_policy_by_hnd(&(q_u->pol)) == -1))
608         {
609                 r_e.status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
610                 DEBUG(5,("samr_reply_query_dispinfo: invalid handle\n"));
611         }
612
613         if (r_e.status == 0x0)
614         {
615                 become_root(True);
616                 got_pwds = get_sampwd_entries(pass, q_u->start_idx, &total_entries, &num_entries, MAX_SAM_ENTRIES, 0);
617                 unbecome_root(True);
618
619                 switch (q_u->switch_level)
620                 {
621                         case 0x1:
622                         {
623                         
624                                 /* query disp info is for users */
625                                 switch_level = 0x1;
626                                 make_sam_info_1(&info1, ACB_NORMAL,
627                                         q_u->start_idx, num_entries, pass);
628
629                                 ctr.sam.info1 = &info1;
630
631                                 break;
632                         }
633                         case 0x2:
634                         {
635                                 /* query disp info is for servers */
636                                 switch_level = 0x2;
637                                 make_sam_info_2(&info2, ACB_WSTRUST,
638                                         q_u->start_idx, num_entries, pass);
639
640                                 ctr.sam.info2 = &info2;
641
642                                 break;
643                         }
644                 }
645         }
646
647         if (r_e.status == 0 && got_pwds)
648         {
649                 make_samr_r_query_dispinfo(&r_e, switch_level, &ctr, r_e.status);
650         }
651
652         /* store the response in the SMB stream */
653         samr_io_r_query_dispinfo("", &r_e, rdata, 0);
654
655         DEBUG(5,("samr_query_dispinfo: %d\n", __LINE__));
656
657 }
658
659 /*******************************************************************
660  api_samr_query_dispinfo
661  ********************************************************************/
662 static void api_samr_query_dispinfo( uint16 vuid, prs_struct *data, prs_struct *rdata)
663 {
664         SAMR_Q_QUERY_DISPINFO q_e;
665
666         /* grab the samr open */
667         samr_io_q_query_dispinfo("", &q_e, data, 0);
668
669         /* construct reply. */
670         samr_reply_query_dispinfo(&q_e, rdata);
671 }
672
673 /*******************************************************************
674  samr_reply_query_groupmem
675  ********************************************************************/
676 static void samr_reply_query_groupmem(SAMR_Q_QUERY_GROUPMEM *q_u,
677                                 prs_struct *rdata)
678 {
679         uint32 status = 0;
680
681         DOMAIN_GRP_MEMBER *mem_grp = NULL;
682         uint32 *rid = NULL;
683         uint32 *attr = NULL;
684         int num_rids = 0;
685         DOM_SID group_sid;
686         uint32 group_rid;
687         fstring group_sid_str;
688
689         SAMR_R_QUERY_GROUPMEM r_u;
690
691         DEBUG(5,("samr_query_groupmem: %d\n", __LINE__));
692
693         /* find the policy handle.  open a policy on it. */
694         if (status == 0x0 && !get_lsa_policy_samr_sid(&q_u->group_pol, &group_sid))
695         {
696                 status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
697         }
698         else
699         {
700                 sid_to_string(group_sid_str, &group_sid     );
701                 sid_split_rid(&group_sid, &group_rid);
702         }
703
704         if (status == 0x0)
705         {
706                 DEBUG(10,("sid is %s\n", group_sid_str));
707
708                 if (sid_equal(&group_sid, &global_sam_sid))
709                 {
710                         DEBUG(10,("lookup on Domain SID\n"));
711
712                         become_root(True);
713                         status = getgrouprid(group_rid, &mem_grp, &num_rids) != NULL ? 0x0 : 0xC0000000 | NT_STATUS_NO_SUCH_GROUP;
714                         unbecome_root(True);
715                 }
716                 else
717                 {
718                         status = 0xC0000000 | NT_STATUS_NO_SUCH_USER;
719                 }
720         }
721
722         if (status == 0x0 && num_rids > 0)
723         {
724                 rid  = malloc(num_rids * sizeof(uint32));
725                 attr = malloc(num_rids * sizeof(uint32));
726                 if (mem_grp != NULL && rid != NULL && attr != NULL)
727                 {
728                         int i;
729                         for (i = 0; i < num_rids; i++)
730                         {
731                                 rid [i] = mem_grp[i].rid;
732                                 attr[i] = mem_grp[i].attr;
733                         }
734                         free(mem_grp);
735                 }
736         }
737
738         make_samr_r_query_groupmem(&r_u, num_rids, rid, attr, status);
739
740         /* store the response in the SMB stream */
741         samr_io_r_query_groupmem("", &r_u, rdata, 0);
742
743         if (rid != NULL)
744         {
745                 free(rid);
746         }
747
748         if (attr != NULL)
749         {
750                 free(attr);
751         }
752
753         DEBUG(5,("samr_query_groupmem: %d\n", __LINE__));
754
755 }
756
757 /*******************************************************************
758  api_samr_query_groupmem
759  ********************************************************************/
760 static void api_samr_query_groupmem( uint16 vuid, prs_struct *data, prs_struct *rdata)
761 {
762         SAMR_Q_QUERY_GROUPMEM q_u;
763
764         /* grab the samr 0x19 */
765         samr_io_q_query_groupmem("", &q_u, data, 0);
766
767         /* construct reply.  always indicate success */
768         samr_reply_query_groupmem(&q_u, rdata);
769 }
770
771
772 /*******************************************************************
773  samr_reply_query_groupinfo
774  ********************************************************************/
775 static void samr_reply_query_groupinfo(SAMR_Q_QUERY_GROUPINFO *q_u,
776                                 prs_struct *rdata)
777 {
778         SAMR_R_QUERY_GROUPINFO r_e;
779         GROUP_INFO_CTR ctr;
780         uint32 status = 0x0;
781
782         r_e.ptr = 0;
783
784         /* find the policy handle.  open a policy on it. */
785         if (r_e.status == 0x0 && (find_lsa_policy_by_hnd(&(q_u->pol)) == -1))
786         {
787                 r_e.status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
788         }
789
790         DEBUG(5,("samr_reply_query_groupinfo: %d\n", __LINE__));
791
792         if (status == 0x0)
793         {
794                 if (q_u->switch_level == 1)
795                 {
796                         r_e.ptr = 1;
797                         ctr.switch_value1 = 1;
798                         make_samr_group_info1(&ctr.group.info1, "account name", "account description");
799                 }
800                 else if (q_u->switch_level == 4)
801                 {
802                         r_e.ptr = 1;
803                         ctr.switch_value1 = 4;
804                         make_samr_group_info4(&ctr.group.info4, "account description");
805                 }
806                 else
807                 {
808                         status = NT_STATUS_INVALID_INFO_CLASS;
809                 }
810         }
811
812         make_samr_r_query_groupinfo(&r_e, status == 0 ? &ctr : NULL, status);
813
814         /* store the response in the SMB stream */
815         samr_io_r_query_groupinfo("", &r_e, rdata, 0);
816
817         DEBUG(5,("samr_query_groupinfo: %d\n", __LINE__));
818
819 }
820
821 /*******************************************************************
822  api_samr_query_groupinfo
823  ********************************************************************/
824 static void api_samr_query_groupinfo( uint16 vuid, prs_struct *data, prs_struct *rdata)
825 {
826         SAMR_Q_QUERY_GROUPINFO q_e;
827
828         /* grab the samr open */
829         samr_io_q_query_groupinfo("", &q_e, data, 0);
830
831         /* construct reply. */
832         samr_reply_query_groupinfo(&q_e, rdata);
833 }
834
835
836 /*******************************************************************
837  samr_reply_query_aliasinfo
838  ********************************************************************/
839 static void samr_reply_query_aliasinfo(SAMR_Q_QUERY_ALIASINFO *q_u,
840                                 prs_struct *rdata)
841 {
842         SAMR_R_QUERY_ALIASINFO r_e;
843         ALIAS_INFO_CTR ctr;
844         uint32 status = 0x0;
845
846         r_e.ptr = 0;
847
848         /* find the policy handle.  open a policy on it. */
849         if (r_e.status == 0x0 && (find_lsa_policy_by_hnd(&(q_u->pol)) == -1))
850         {
851                 r_e.status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
852         }
853
854         DEBUG(5,("samr_reply_query_aliasinfo: %d\n", __LINE__));
855
856         if (status == 0x0)
857         {
858                 if (q_u->switch_level == 3)
859                 {
860                         r_e.ptr = 1;
861                         ctr.switch_value1 = 3;
862                         make_samr_alias_info3(&ctr.alias.info3, "<account description>");
863                 }
864                 else
865                 {
866                         status = NT_STATUS_INVALID_INFO_CLASS;
867                 }
868         }
869
870         make_samr_r_query_aliasinfo(&r_e, status == 0 ? &ctr : NULL, status);
871
872         /* store the response in the SMB stream */
873         samr_io_r_query_aliasinfo("", &r_e, rdata, 0);
874
875         DEBUG(5,("samr_query_aliasinfo: %d\n", __LINE__));
876
877 }
878
879 /*******************************************************************
880  api_samr_query_aliasinfo
881  ********************************************************************/
882 static void api_samr_query_aliasinfo( uint16 vuid, prs_struct *data, prs_struct *rdata)
883 {
884         SAMR_Q_QUERY_ALIASINFO q_e;
885
886         /* grab the samr open */
887         samr_io_q_query_aliasinfo("", &q_e, data, 0);
888
889         /* construct reply. */
890         samr_reply_query_aliasinfo(&q_e, rdata);
891 }
892
893
894 /*******************************************************************
895  samr_reply_query_useraliases
896  ********************************************************************/
897 static void samr_reply_query_useraliases(SAMR_Q_QUERY_USERALIASES *q_u,
898                                 prs_struct *rdata)
899 {
900         uint32 status = 0;
901
902         LOCAL_GRP *mem_grp = NULL;
903         uint32 *rid = NULL;
904         int num_rids = 0;
905         struct sam_passwd *sam_pass;
906         DOM_SID usr_sid;
907         DOM_SID dom_sid;
908         uint32 user_rid;
909         fstring sam_sid_str;
910         fstring dom_sid_str;
911         fstring usr_sid_str;
912
913         SAMR_R_QUERY_USERALIASES r_u;
914
915         DEBUG(5,("samr_query_useraliases: %d\n", __LINE__));
916
917         /* find the policy handle.  open a policy on it. */
918         if (status == 0x0 && !get_lsa_policy_samr_sid(&q_u->pol, &dom_sid))
919         {
920                 status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
921         }
922         else
923         {
924                 sid_to_string(dom_sid_str, &dom_sid       );
925                 sid_to_string(sam_sid_str, &global_sam_sid);
926         }
927
928         if (status == 0x0)
929         {
930                 usr_sid = q_u->sid[0].sid;
931                 sid_split_rid(&usr_sid, &user_rid);
932                 sid_to_string(usr_sid_str, &usr_sid);
933
934         }
935
936         if (status == 0x0)
937         {
938                 /* find the user account */
939                 become_root(True);
940                 sam_pass = getsam21pwrid(user_rid);
941                 unbecome_root(True);
942
943                 if (sam_pass == NULL)
944                 {
945                         status = 0xC0000000 | NT_STATUS_NO_SUCH_USER;
946                         num_rids = 0;
947                 }
948         }
949
950         if (status == 0x0)
951         {
952                 DEBUG(10,("sid is %s\n", dom_sid_str));
953
954                 if (sid_equal(&dom_sid, &global_sid_S_1_5_20))
955                 {
956                         DEBUG(10,("lookup on S-1-5-20\n"));
957
958                         become_root(True);
959                         getuserbuiltinntnam(sam_pass->nt_name, &mem_grp, &num_rids);
960                         unbecome_root(True);
961                 }
962                 else if (sid_equal(&dom_sid, &usr_sid))
963                 {
964                         DEBUG(10,("lookup on Domain SID\n"));
965
966                         become_root(True);
967                         getuseraliasntnam(sam_pass->nt_name, &mem_grp, &num_rids);
968                         unbecome_root(True);
969                 }
970                 else
971                 {
972                         status = 0xC0000000 | NT_STATUS_NO_SUCH_USER;
973                 }
974         }
975
976         if (status == 0x0 && num_rids > 0)
977         {
978                         rid = malloc(num_rids * sizeof(uint32));
979                         if (mem_grp != NULL && rid != NULL)
980                         {
981                                 int i;
982                                 for (i = 0; i < num_rids; i++)
983                                 {
984                                         rid[i] = mem_grp[i].rid;
985                                 }
986                                 free(mem_grp);
987                 }
988         }
989
990         make_samr_r_query_useraliases(&r_u, num_rids, rid, status);
991
992         /* store the response in the SMB stream */
993         samr_io_r_query_useraliases("", &r_u, rdata, 0);
994
995         if (rid != NULL)
996         {
997                 free(rid);
998         }
999
1000         DEBUG(5,("samr_query_useraliases: %d\n", __LINE__));
1001
1002 }
1003
1004 /*******************************************************************
1005  api_samr_query_useraliases
1006  ********************************************************************/
1007 static void api_samr_query_useraliases( uint16 vuid, prs_struct *data, prs_struct *rdata)
1008 {
1009         SAMR_Q_QUERY_USERALIASES q_u;
1010
1011         /* grab the samr 0x10 */
1012         samr_io_q_query_useraliases("", &q_u, data, 0);
1013
1014         /* construct reply.  always indicate success */
1015         samr_reply_query_useraliases(&q_u, rdata);
1016 }
1017
1018 /*******************************************************************
1019  samr_reply_query_aliasmem
1020  ********************************************************************/
1021 static void samr_reply_query_aliasmem(SAMR_Q_QUERY_ALIASMEM *q_u,
1022                                 prs_struct *rdata)
1023 {
1024         uint32 status = 0;
1025
1026         LOCAL_GRP_MEMBER *mem_grp = NULL;
1027         DOM_SID2 *sid = NULL;
1028         int num_sids = 0;
1029         DOM_SID alias_sid;
1030         uint32 alias_rid;
1031         fstring alias_sid_str;
1032
1033         SAMR_R_QUERY_ALIASMEM r_u;
1034
1035         DEBUG(5,("samr_query_aliasmem: %d\n", __LINE__));
1036
1037         /* find the policy handle.  open a policy on it. */
1038         if (status == 0x0 && !get_lsa_policy_samr_sid(&q_u->alias_pol, &alias_sid))
1039         {
1040                 status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
1041         }
1042         else
1043         {
1044                 sid_to_string(alias_sid_str, &alias_sid     );
1045                 sid_split_rid(&alias_sid, &alias_rid);
1046         }
1047
1048         if (status == 0x0)
1049         {
1050                 DEBUG(10,("sid is %s\n", alias_sid_str));
1051
1052                 if (sid_equal(&alias_sid, &global_sid_S_1_5_20))
1053                 {
1054                         DEBUG(10,("lookup on S-1-5-20\n"));
1055
1056                         become_root(True);
1057                         status = getbuiltinrid(alias_rid, &mem_grp, &num_sids) != NULL ? 0x0 : 0xC0000000 | NT_STATUS_NO_SUCH_GROUP;
1058                         unbecome_root(True);
1059                 }
1060                 else if (sid_equal(&alias_sid, &global_sam_sid))
1061                 {
1062                         DEBUG(10,("lookup on Domain SID\n"));
1063
1064                         become_root(True);
1065                         status = getaliasrid(alias_rid, &mem_grp, &num_sids) != NULL ? 0x0 : 0xC0000000 | NT_STATUS_NO_SUCH_GROUP;
1066                         unbecome_root(True);
1067                 }
1068                 else
1069                 {
1070                         status = 0xC0000000 | NT_STATUS_NO_SUCH_USER;
1071                 }
1072         }
1073
1074         if (status == 0x0 && num_sids > 0)
1075         {
1076                 sid = malloc(num_sids * sizeof(DOM_SID));
1077                 if (mem_grp != NULL && sid != NULL)
1078                 {
1079                         int i;
1080                         for (i = 0; i < num_sids; i++)
1081                         {
1082                                 make_dom_sid2(&sid[i], &mem_grp[i].sid);
1083                         }
1084                         free(mem_grp);
1085                 }
1086         }
1087
1088         make_samr_r_query_aliasmem(&r_u, num_sids, sid, status);
1089
1090         /* store the response in the SMB stream */
1091         samr_io_r_query_aliasmem("", &r_u, rdata, 0);
1092
1093         if (sid != NULL)
1094         {
1095                 free(sid);
1096         }
1097
1098         DEBUG(5,("samr_query_aliasmem: %d\n", __LINE__));
1099
1100 }
1101
1102 /*******************************************************************
1103  api_samr_query_aliasmem
1104  ********************************************************************/
1105 static void api_samr_query_aliasmem( uint16 vuid, prs_struct *data, prs_struct *rdata)
1106 {
1107         SAMR_Q_QUERY_ALIASMEM q_u;
1108
1109         /* grab the samr 0x21 */
1110         samr_io_q_query_aliasmem("", &q_u, data, 0);
1111
1112         /* construct reply.  always indicate success */
1113         samr_reply_query_aliasmem(&q_u, rdata);
1114 }
1115
1116 /*******************************************************************
1117  samr_reply_lookup_names
1118  ********************************************************************/
1119 static void samr_reply_lookup_names(SAMR_Q_LOOKUP_NAMES *q_u,
1120                                 prs_struct *rdata)
1121 {
1122         uint32 rid [MAX_SAM_ENTRIES];
1123         uint8  type[MAX_SAM_ENTRIES];
1124         uint32 status     = 0;
1125         int i;
1126         int num_rids = q_u->num_rids1;
1127
1128         SAMR_R_LOOKUP_NAMES r_u;
1129
1130         DEBUG(5,("samr_lookup_names: %d\n", __LINE__));
1131
1132         if (num_rids > MAX_SAM_ENTRIES)
1133         {
1134                 num_rids = MAX_SAM_ENTRIES;
1135                 DEBUG(5,("samr_lookup_names: truncating entries to %d\n", num_rids));
1136         }
1137
1138         SMB_ASSERT_ARRAY(q_u->uni_user_name, num_rids);
1139
1140         for (i = 0; i < num_rids && status == 0; i++)
1141         {
1142                 DOM_SID sid;
1143                 fstring name;
1144                 fstrcpy(name, unistrn2(q_u->uni_user_name[i].buffer, q_u->uni_user_name[i].uni_str_len));
1145
1146                 status = lookup_name(name, &sid, &(type[i]));
1147                 if (status == 0x0)
1148                 {
1149                         sid_split_rid(&sid, &rid[i]);
1150                 }
1151                 else
1152                 {
1153                         type[i] = SID_NAME_UNKNOWN;
1154                 }
1155         }
1156
1157         make_samr_r_lookup_names(&r_u, num_rids, rid, type, status);
1158
1159         /* store the response in the SMB stream */
1160         samr_io_r_lookup_names("", &r_u, rdata, 0);
1161
1162         DEBUG(5,("samr_lookup_names: %d\n", __LINE__));
1163
1164 }
1165
1166 /*******************************************************************
1167  api_samr_lookup_names
1168  ********************************************************************/
1169 static void api_samr_lookup_names( uint16 vuid, prs_struct *data, prs_struct *rdata)
1170 {
1171         SAMR_Q_LOOKUP_NAMES q_u;
1172
1173         /* grab the samr lookup names */
1174         samr_io_q_lookup_names("", &q_u, data, 0);
1175
1176         /* construct reply.  always indicate success */
1177         samr_reply_lookup_names(&q_u, rdata);
1178 }
1179
1180 /*******************************************************************
1181  samr_reply_chgpasswd_user
1182  ********************************************************************/
1183 static void samr_reply_chgpasswd_user(SAMR_Q_CHGPASSWD_USER *q_u,
1184                                 prs_struct *rdata)
1185 {
1186         SAMR_R_CHGPASSWD_USER r_u;
1187         uint32 status = 0x0;
1188         fstring user_name;
1189         fstring wks;
1190
1191         fstrcpy(user_name, unistrn2(q_u->uni_user_name.buffer, q_u->uni_user_name.uni_str_len));
1192         fstrcpy(wks      , unistrn2(q_u->uni_dest_host.buffer, q_u->uni_dest_host.uni_str_len));
1193
1194         DEBUG(5,("samr_chgpasswd_user: user: %s wks: %s\n", user_name, wks));
1195
1196         if (!pass_oem_change(user_name,
1197                              q_u->lm_newpass.pass, q_u->lm_oldhash.hash,
1198                              q_u->nt_newpass.pass, q_u->nt_oldhash.hash))
1199         {
1200                 status = 0xC0000000 | NT_STATUS_WRONG_PASSWORD;
1201         }
1202
1203         make_samr_r_chgpasswd_user(&r_u, status);
1204
1205         /* store the response in the SMB stream */
1206         samr_io_r_chgpasswd_user("", &r_u, rdata, 0);
1207
1208         DEBUG(5,("samr_chgpasswd_user: %d\n", __LINE__));
1209 }
1210
1211 /*******************************************************************
1212  api_samr_chgpasswd_user
1213  ********************************************************************/
1214 static void api_samr_chgpasswd_user( uint16 vuid, prs_struct *data, prs_struct *rdata)
1215 {
1216         SAMR_Q_CHGPASSWD_USER q_u;
1217
1218         /* unknown 38 command */
1219         samr_io_q_chgpasswd_user("", &q_u, data, 0);
1220
1221         /* construct reply. */
1222         samr_reply_chgpasswd_user(&q_u, rdata);
1223 }
1224
1225
1226 /*******************************************************************
1227  samr_reply_unknown_38
1228  ********************************************************************/
1229 static void samr_reply_unknown_38(SAMR_Q_UNKNOWN_38 *q_u,
1230                                 prs_struct *rdata)
1231 {
1232         SAMR_R_UNKNOWN_38 r_u;
1233
1234         DEBUG(5,("samr_unknown_38: %d\n", __LINE__));
1235
1236         make_samr_r_unknown_38(&r_u);
1237
1238         /* store the response in the SMB stream */
1239         samr_io_r_unknown_38("", &r_u, rdata, 0);
1240
1241         DEBUG(5,("samr_unknown_38: %d\n", __LINE__));
1242 }
1243
1244 /*******************************************************************
1245  api_samr_unknown_38
1246  ********************************************************************/
1247 static void api_samr_unknown_38( uint16 vuid, prs_struct *data, prs_struct *rdata)
1248 {
1249         SAMR_Q_UNKNOWN_38 q_u;
1250
1251         /* unknown 38 command */
1252         samr_io_q_unknown_38("", &q_u, data, 0);
1253
1254         /* construct reply.  always indicate success */
1255         samr_reply_unknown_38(&q_u, rdata);
1256 }
1257
1258
1259 /*******************************************************************
1260  samr_reply_unknown_12
1261  ********************************************************************/
1262 static void samr_reply_unknown_12(SAMR_Q_UNKNOWN_12 *q_u,
1263                                 prs_struct *rdata)
1264 {
1265         fstring group_names[MAX_SAM_ENTRIES];
1266         uint8   group_attrs[MAX_SAM_ENTRIES];
1267         uint32 status     = 0;
1268         int num_gids = q_u->num_gids1;
1269         DOM_SID pol_sid;
1270
1271         SAMR_R_UNKNOWN_12 r_u;
1272
1273         DEBUG(5,("samr_unknown_12: %d\n", __LINE__));
1274
1275         /* find the policy handle.  open a policy on it. */
1276         if (status == 0x0 && (find_lsa_policy_by_hnd(&(q_u->pol)) == -1))
1277         {
1278                 status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
1279         }
1280
1281         if (status == 0x0 && !get_lsa_policy_samr_sid(&q_u->pol, &pol_sid))
1282         {
1283                 status = NT_STATUS_OBJECT_TYPE_MISMATCH;
1284         }
1285
1286         if (status == 0x0)
1287         {
1288                 int i;
1289                 if (num_gids > MAX_SAM_ENTRIES)
1290                 {
1291                         num_gids = MAX_SAM_ENTRIES;
1292                         DEBUG(5,("samr_unknown_12: truncating entries to %d\n", num_gids));
1293                 }
1294
1295                 for (i = 0; i < num_gids && status == 0; i++)
1296                 {
1297                         DOM_SID sid;
1298                         sid_copy(&sid, &pol_sid);
1299                         sid_append_rid(&sid, q_u->gid[i]);
1300                         lookup_sid(&sid, group_names[i], &group_attrs[i]);
1301                 }
1302         }
1303
1304         make_samr_r_unknown_12(&r_u, num_gids, group_names, group_attrs, status);
1305
1306         /* store the response in the SMB stream */
1307         samr_io_r_unknown_12("", &r_u, rdata, 0);
1308
1309         DEBUG(5,("samr_unknown_12: %d\n", __LINE__));
1310
1311 }
1312
1313 /*******************************************************************
1314  api_samr_unknown_12
1315  ********************************************************************/
1316 static void api_samr_unknown_12( uint16 vuid, prs_struct *data, prs_struct *rdata)
1317 {
1318         SAMR_Q_UNKNOWN_12 q_u;
1319
1320         /* grab the samr lookup names */
1321         samr_io_q_unknown_12("", &q_u, data, 0);
1322
1323         /* construct reply.  always indicate success */
1324         samr_reply_unknown_12(&q_u, rdata);
1325 }
1326
1327
1328 /*******************************************************************
1329  samr_reply_open_user
1330  ********************************************************************/
1331 static void samr_reply_open_user(SAMR_Q_OPEN_USER *q_u,
1332                                 prs_struct *rdata,
1333                                 int status)
1334 {
1335         SAMR_R_OPEN_USER r_u;
1336         struct sam_passwd *sam_pass;
1337         BOOL pol_open = False;
1338
1339         /* set up the SAMR open_user response */
1340         bzero(r_u.user_pol.data, POL_HND_SIZE);
1341
1342         r_u.status = 0x0;
1343
1344         /* find the policy handle.  open a policy on it. */
1345         if (r_u.status == 0x0 && (find_lsa_policy_by_hnd(&(q_u->domain_pol)) == -1))
1346         {
1347                 r_u.status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
1348         }
1349
1350         /* get a (unique) handle.  open a policy on it. */
1351         if (r_u.status == 0x0 && !(pol_open = open_lsa_policy_hnd(&(r_u.user_pol))))
1352         {
1353                 r_u.status = 0xC0000000 | NT_STATUS_OBJECT_NAME_NOT_FOUND;
1354         }
1355
1356         become_root(True);
1357         sam_pass = getsam21pwrid(q_u->user_rid);
1358         unbecome_root(True);
1359
1360         /* check that the RID exists in our domain. */
1361         if (r_u.status == 0x0 && sam_pass == NULL)
1362         {
1363                 r_u.status = 0xC0000000 | NT_STATUS_NO_SUCH_USER;
1364         }
1365
1366         /* associate the RID with the (unique) handle. */
1367         if (r_u.status == 0x0 && !set_lsa_policy_samr_rid(&(r_u.user_pol), q_u->user_rid))
1368         {
1369                 /* oh, whoops.  don't know what error message to return, here */
1370                 r_u.status = 0xC0000000 | NT_STATUS_OBJECT_NAME_NOT_FOUND;
1371         }
1372
1373         if (r_u.status != 0 && pol_open)
1374         {
1375                 close_lsa_policy_hnd(&(r_u.user_pol));
1376         }
1377
1378         DEBUG(5,("samr_open_user: %d\n", __LINE__));
1379
1380         /* store the response in the SMB stream */
1381         samr_io_r_open_user("", &r_u, rdata, 0);
1382
1383         DEBUG(5,("samr_open_user: %d\n", __LINE__));
1384
1385 }
1386
1387 /*******************************************************************
1388  api_samr_open_user
1389  ********************************************************************/
1390 static void api_samr_open_user( uint16 vuid, prs_struct *data, prs_struct *rdata)
1391 {
1392         SAMR_Q_OPEN_USER q_u;
1393
1394         /* grab the samr unknown 22 */
1395         samr_io_q_open_user("", &q_u, data, 0);
1396
1397         /* construct reply.  always indicate success */
1398         samr_reply_open_user(&q_u, rdata, 0x0);
1399 }
1400
1401
1402 /*************************************************************************
1403  get_user_info_10
1404  *************************************************************************/
1405 static BOOL get_user_info_10(SAM_USER_INFO_10 *id10, uint32 user_rid)
1406 {
1407         struct sam_passwd *sam_pass;
1408
1409         become_root(True);
1410         sam_pass = getsam21pwrid(user_rid);
1411         unbecome_root(True);
1412
1413         if (sam_pass == NULL)
1414         {
1415                 DEBUG(4,("User 0x%x not found\n", user_rid));
1416                 return False;
1417         }
1418
1419         DEBUG(3,("User:[%s]\n", sam_pass->nt_name));
1420
1421         make_sam_user_info10(id10, sam_pass->acct_ctrl); 
1422
1423         return True;
1424 }
1425
1426 /*************************************************************************
1427  get_user_info_21
1428  *************************************************************************/
1429 static BOOL get_user_info_21(SAM_USER_INFO_21 *id21, uint32 user_rid)
1430 {
1431         struct sam_passwd *sam_pass;
1432         LOGON_HRS hrs;
1433         int i;
1434
1435         become_root(True);
1436         sam_pass = getsam21pwrid(user_rid);
1437         unbecome_root(True);
1438
1439         if (sam_pass == NULL)
1440         {
1441                 DEBUG(4,("User 0x%x not found\n", user_rid));
1442                 return False;
1443         }
1444
1445         DEBUG(3,("User:[%s]\n", sam_pass->nt_name));
1446
1447         /* create a LOGON_HRS structure */
1448         hrs.len = sam_pass->hours_len;
1449         SMB_ASSERT_ARRAY(hrs.hours, hrs.len);
1450         for (i = 0; i < hrs.len; i++)
1451         {
1452                 hrs.hours[i] = sam_pass->hours[i];
1453         }
1454
1455         make_sam_user_info21(id21,
1456
1457                            &sam_pass->logon_time,
1458                            &sam_pass->logoff_time,
1459                            &sam_pass->kickoff_time,
1460                            &sam_pass->pass_last_set_time,
1461                            &sam_pass->pass_can_change_time,
1462                            &sam_pass->pass_must_change_time,
1463
1464                            sam_pass->nt_name, /* user_name */
1465                            sam_pass->full_name, /* full_name */
1466                            sam_pass->home_dir, /* home_dir */
1467                            sam_pass->dir_drive, /* dir_drive */
1468                            sam_pass->logon_script, /* logon_script */
1469                            sam_pass->profile_path, /* profile_path */
1470                            sam_pass->acct_desc, /* description */
1471                            sam_pass->workstations, /* workstations user can log in from */
1472                            sam_pass->unknown_str, /* don't know, yet */
1473                            sam_pass->munged_dial, /* dialin info.  contains dialin path and tel no */
1474
1475                            sam_pass->user_rid, /* RID user_id */
1476                            sam_pass->group_rid, /* RID group_id */
1477                            sam_pass->acct_ctrl,
1478
1479                            sam_pass->unknown_3, /* unknown_3 */
1480                            sam_pass->logon_divs, /* divisions per week */
1481                            &hrs, /* logon hours */
1482                            sam_pass->unknown_5,
1483                            sam_pass->unknown_6);
1484
1485         return True;
1486 }
1487
1488 /*******************************************************************
1489  samr_reply_query_userinfo
1490  ********************************************************************/
1491 static void samr_reply_query_userinfo(SAMR_Q_QUERY_USERINFO *q_u,
1492                                 prs_struct *rdata)
1493 {
1494         SAMR_R_QUERY_USERINFO r_u;
1495 #if 0
1496         SAM_USER_INFO_11 id11;
1497 #endif
1498         SAM_USER_INFO_10 id10;
1499         SAM_USER_INFO_21 id21;
1500         void *info = NULL;
1501
1502         uint32 status = 0x0;
1503         uint32 rid = 0x0;
1504
1505         DEBUG(5,("samr_reply_query_userinfo: %d\n", __LINE__));
1506
1507         /* search for the handle */
1508         if (status == 0x0 && (find_lsa_policy_by_hnd(&(q_u->pol)) == -1))
1509         {
1510                 status = NT_STATUS_INVALID_HANDLE;
1511         }
1512
1513         /* find the user's rid */
1514         if (status == 0x0 && (rid = get_lsa_policy_samr_rid(&(q_u->pol))) == 0xffffffff)
1515         {
1516                 status = NT_STATUS_OBJECT_TYPE_MISMATCH;
1517         }
1518
1519         DEBUG(5,("samr_reply_query_userinfo: rid:0x%x\n", rid));
1520
1521         /* ok!  user info levels (there are lots: see MSDEV help), off we go... */
1522         if (status == 0x0)
1523         {
1524                 switch (q_u->switch_value)
1525                 {
1526                         case 0x10:
1527                         {
1528                                 info = (void*)&id10;
1529                                 status = get_user_info_10(&id10, rid) ? 0 : NT_STATUS_NO_SUCH_USER;
1530                                 break;
1531                         }
1532 #if 0
1533 /* whoops - got this wrong.  i think.  or don't understand what's happening. */
1534                         case 0x11:
1535                         {
1536                                 NTTIME expire;
1537                                 info = (void*)&id11;
1538                                 
1539                                 expire.low  = 0xffffffff;
1540                                 expire.high = 0x7fffffff;
1541
1542                                 make_sam_user_info11(&id11, &expire, "BROOKFIELDS$", 0x03ef, 0x201, 0x0080);
1543
1544                                 break;
1545                         }
1546 #endif
1547                         case 21:
1548                         {
1549                                 info = (void*)&id21;
1550                                 status = get_user_info_21(&id21, rid) ? 0 : NT_STATUS_NO_SUCH_USER;
1551                                 break;
1552                         }
1553
1554                         default:
1555                         {
1556                                 status = NT_STATUS_INVALID_INFO_CLASS;
1557
1558                                 break;
1559                         }
1560                 }
1561         }
1562
1563         make_samr_r_query_userinfo(&r_u, q_u->switch_value, info, status);
1564
1565         /* store the response in the SMB stream */
1566         samr_io_r_query_userinfo("", &r_u, rdata, 0);
1567
1568         DEBUG(5,("samr_reply_query_userinfo: %d\n", __LINE__));
1569
1570 }
1571
1572 /*******************************************************************
1573  api_samr_query_userinfo
1574  ********************************************************************/
1575 static void api_samr_query_userinfo( uint16 vuid, prs_struct *data, prs_struct *rdata)
1576 {
1577         SAMR_Q_QUERY_USERINFO q_u;
1578
1579         /* grab the samr unknown 24 */
1580         samr_io_q_query_userinfo("", &q_u, data, 0);
1581
1582         /* construct reply.  always indicate success */
1583         samr_reply_query_userinfo(&q_u, rdata);
1584 }
1585
1586
1587 /*******************************************************************
1588  samr_reply_query_usergroups
1589  ********************************************************************/
1590 static void samr_reply_query_usergroups(SAMR_Q_QUERY_USERGROUPS *q_u,
1591                                 prs_struct *rdata)
1592 {
1593         SAMR_R_QUERY_USERGROUPS r_u;
1594         uint32 status = 0x0;
1595
1596         struct sam_passwd *sam_pass;
1597         DOM_GID *gids = NULL;
1598         int num_groups = 0;
1599         uint32 rid;
1600
1601         DEBUG(5,("samr_query_usergroups: %d\n", __LINE__));
1602
1603         /* find the policy handle.  open a policy on it. */
1604         if (status == 0x0 && (find_lsa_policy_by_hnd(&(q_u->pol)) == -1))
1605         {
1606                 status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
1607         }
1608
1609         /* find the user's rid */
1610         if (status == 0x0 && (rid = get_lsa_policy_samr_rid(&(q_u->pol))) == 0xffffffff)
1611         {
1612                 status = NT_STATUS_OBJECT_TYPE_MISMATCH;
1613         }
1614
1615         if (status == 0x0)
1616         {
1617                 become_root(True);
1618                 sam_pass = getsam21pwrid(rid);
1619                 unbecome_root(True);
1620
1621                 if (sam_pass == NULL)
1622                 {
1623                         status = 0xC0000000 | NT_STATUS_NO_SUCH_USER;
1624                 }
1625         }
1626
1627         if (status == 0x0)
1628         {
1629                 DOMAIN_GRP *mem_grp = NULL;
1630
1631                 become_root(True);
1632                 getusergroupsntnam(sam_pass->nt_name, &mem_grp, &num_groups);
1633                 unbecome_root(True);
1634
1635                 gids = NULL;
1636                 num_groups = make_dom_gids(mem_grp, num_groups, &gids);
1637
1638                 if (mem_grp != NULL)
1639                 {
1640                         free(mem_grp);
1641                 }
1642         }
1643
1644         /* construct the response.  lkclXXXX: gids are not copied! */
1645         make_samr_r_query_usergroups(&r_u, num_groups, gids, status);
1646
1647         /* store the response in the SMB stream */
1648         samr_io_r_query_usergroups("", &r_u, rdata, 0);
1649
1650         if (gids)
1651         {
1652                 free((char *)gids);
1653         }
1654
1655         DEBUG(5,("samr_query_usergroups: %d\n", __LINE__));
1656
1657 }
1658
1659 /*******************************************************************
1660  api_samr_query_usergroups
1661  ********************************************************************/
1662 static void api_samr_query_usergroups( uint16 vuid, prs_struct *data, prs_struct *rdata)
1663 {
1664         SAMR_Q_QUERY_USERGROUPS q_u;
1665         /* grab the samr unknown 32 */
1666         samr_io_q_query_usergroups("", &q_u, data, 0);
1667
1668         /* construct reply. */
1669         samr_reply_query_usergroups(&q_u, rdata);
1670 }
1671
1672
1673 /*******************************************************************
1674  samr_reply_query_dom_info
1675  ********************************************************************/
1676 static void samr_reply_query_dom_info(SAMR_Q_QUERY_DOMAIN_INFO *q_u,
1677                                 prs_struct *rdata)
1678 {
1679         SAMR_R_QUERY_DOMAIN_INFO r_u;
1680         SAM_UNK_CTR ctr;
1681         uint16 switch_value = 0x0;
1682         uint32 status = 0x0;
1683
1684         ZERO_STRUCT(r_u);
1685         ZERO_STRUCT(ctr);
1686
1687         r_u.ctr = &ctr;
1688
1689         DEBUG(5,("samr_reply_query_dom_info: %d\n", __LINE__));
1690
1691         /* find the policy handle.  open a policy on it. */
1692         if (r_u.status == 0x0 && (find_lsa_policy_by_hnd(&(q_u->domain_pol)) == -1))
1693         {
1694                 r_u.status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
1695                 DEBUG(5,("samr_reply_query_dom_info: invalid handle\n"));
1696         }
1697
1698         if (status == 0x0)
1699         {
1700                 switch (q_u->switch_value)
1701                 {
1702                         case 0x02:
1703                         {
1704                                 switch_value = 0x2;
1705                                 make_unk_info2(&ctr.info.inf2, global_sam_name, global_myname);
1706
1707                                 break;
1708                         }
1709                         default:
1710                         {
1711                                 status = 0xC0000000 | NT_STATUS_INVALID_INFO_CLASS;
1712                                 break;
1713                         }
1714                 }
1715         }
1716
1717         make_samr_r_query_dom_info(&r_u, switch_value, &ctr, status);
1718
1719         /* store the response in the SMB stream */
1720         samr_io_r_query_dom_info("", &r_u, rdata, 0);
1721
1722         DEBUG(5,("samr_query_dom_info: %d\n", __LINE__));
1723
1724 }
1725
1726 /*******************************************************************
1727  api_samr_query_dom_info
1728  ********************************************************************/
1729 static void api_samr_query_dom_info( uint16 vuid, prs_struct *data, prs_struct *rdata)
1730 {
1731         SAMR_Q_QUERY_DOMAIN_INFO q_e;
1732
1733         /* grab the samr unknown 8 command */
1734         samr_io_q_query_dom_info("", &q_e, data, 0);
1735
1736         /* construct reply. */
1737         samr_reply_query_dom_info(&q_e, rdata);
1738 }
1739
1740
1741
1742 /*******************************************************************
1743  samr_reply_unknown_32
1744  ********************************************************************/
1745 static void samr_reply_unknown_32(SAMR_Q_UNKNOWN_32 *q_u,
1746                                 prs_struct *rdata,
1747                                 int status)
1748 {
1749         int i;
1750         SAMR_R_UNKNOWN_32 r_u;
1751
1752         /* set up the SAMR unknown_32 response */
1753         bzero(r_u.pol.data, POL_HND_SIZE);
1754         if (status == 0)
1755         {
1756                 for (i = 4; i < POL_HND_SIZE; i++)
1757                 {
1758                         r_u.pol.data[i] = i+1;
1759                 }
1760         }
1761
1762         make_dom_rid4(&(r_u.rid4), 0x0030, 0, 0);
1763         r_u.status    = status;
1764
1765         DEBUG(5,("samr_unknown_32: %d\n", __LINE__));
1766
1767         /* store the response in the SMB stream */
1768         samr_io_r_unknown_32("", &r_u, rdata, 0);
1769
1770         DEBUG(5,("samr_unknown_32: %d\n", __LINE__));
1771
1772 }
1773
1774 /*******************************************************************
1775  api_samr_unknown_32
1776  ********************************************************************/
1777 static void api_samr_unknown_32( uint16 vuid, prs_struct *data, prs_struct *rdata)
1778 {
1779         uint32 status = 0;
1780         struct sam_passwd *sam_pass;
1781         fstring mach_acct;
1782
1783         SAMR_Q_UNKNOWN_32 q_u;
1784
1785         /* grab the samr unknown 32 */
1786         samr_io_q_unknown_32("", &q_u, data, 0);
1787
1788         /* find the machine account: tell the caller if it exists.
1789            lkclXXXX i have *no* idea if this is a problem or not
1790            or even if you are supposed to construct a different
1791            reply if the account already exists...
1792          */
1793
1794         fstrcpy(mach_acct, unistrn2(q_u.uni_mach_acct.buffer,
1795                                     q_u.uni_mach_acct.uni_str_len));
1796
1797         become_root(True);
1798         sam_pass = getsam21pwntnam(mach_acct);
1799         unbecome_root(True);
1800
1801         if (sam_pass != NULL)
1802         {
1803                 /* machine account exists: say so */
1804                 status = 0xC0000000 | NT_STATUS_USER_EXISTS;
1805         }
1806         else
1807         {
1808                 /* this could cause trouble... */
1809                 DEBUG(0,("trouble!\n"));
1810                 status = 0;
1811         }
1812
1813         /* construct reply. */
1814         samr_reply_unknown_32(&q_u, rdata, status);
1815 }
1816
1817
1818 /*******************************************************************
1819  samr_reply_connect_anon
1820  ********************************************************************/
1821 static void samr_reply_connect_anon(SAMR_Q_CONNECT_ANON *q_u,
1822                                 prs_struct *rdata)
1823 {
1824         SAMR_R_CONNECT_ANON r_u;
1825         BOOL pol_open = False;
1826
1827         /* set up the SAMR connect_anon response */
1828
1829         r_u.status = 0x0;
1830         /* get a (unique) handle.  open a policy on it. */
1831         if (r_u.status == 0x0 && !(pol_open = open_lsa_policy_hnd(&(r_u.connect_pol))))
1832         {
1833                 r_u.status = 0xC0000000 | NT_STATUS_OBJECT_NAME_NOT_FOUND;
1834         }
1835
1836         /* associate the domain SID with the (unique) handle. */
1837         if (r_u.status == 0x0 && !set_lsa_policy_samr_pol_status(&(r_u.connect_pol), q_u->unknown_0))
1838         {
1839                 /* oh, whoops.  don't know what error message to return, here */
1840                 r_u.status = 0xC0000000 | NT_STATUS_OBJECT_NAME_NOT_FOUND;
1841         }
1842
1843         if (r_u.status != 0 && pol_open)
1844         {
1845                 close_lsa_policy_hnd(&(r_u.connect_pol));
1846         }
1847
1848         DEBUG(5,("samr_connect_anon: %d\n", __LINE__));
1849
1850         /* store the response in the SMB stream */
1851         samr_io_r_connect_anon("", &r_u, rdata, 0);
1852
1853         DEBUG(5,("samr_connect_anon: %d\n", __LINE__));
1854
1855 }
1856
1857 /*******************************************************************
1858  api_samr_connect_anon
1859  ********************************************************************/
1860 static void api_samr_connect_anon( uint16 vuid, prs_struct *data, prs_struct *rdata)
1861 {
1862         SAMR_Q_CONNECT_ANON q_u;
1863
1864         /* grab the samr open policy */
1865         samr_io_q_connect_anon("", &q_u, data, 0);
1866
1867         /* construct reply.  always indicate success */
1868         samr_reply_connect_anon(&q_u, rdata);
1869 }
1870
1871 /*******************************************************************
1872  samr_reply_connect
1873  ********************************************************************/
1874 static void samr_reply_connect(SAMR_Q_CONNECT *q_u,
1875                                 prs_struct *rdata)
1876 {
1877         SAMR_R_CONNECT r_u;
1878         BOOL pol_open = False;
1879
1880         /* set up the SAMR connect response */
1881
1882         r_u.status = 0x0;
1883         /* get a (unique) handle.  open a policy on it. */
1884         if (r_u.status == 0x0 && !(pol_open = open_lsa_policy_hnd(&(r_u.connect_pol))))
1885         {
1886                 r_u.status = 0xC0000000 | NT_STATUS_OBJECT_NAME_NOT_FOUND;
1887         }
1888
1889         /* associate the domain SID with the (unique) handle. */
1890         if (r_u.status == 0x0 && !set_lsa_policy_samr_pol_status(&(r_u.connect_pol), q_u->unknown_0))
1891         {
1892                 /* oh, whoops.  don't know what error message to return, here */
1893                 r_u.status = 0xC0000000 | NT_STATUS_OBJECT_NAME_NOT_FOUND;
1894         }
1895
1896         if (r_u.status != 0 && pol_open)
1897         {
1898                 close_lsa_policy_hnd(&(r_u.connect_pol));
1899         }
1900
1901         DEBUG(5,("samr_connect: %d\n", __LINE__));
1902
1903         /* store the response in the SMB stream */
1904         samr_io_r_connect("", &r_u, rdata, 0);
1905
1906         DEBUG(5,("samr_connect: %d\n", __LINE__));
1907
1908 }
1909
1910 /*******************************************************************
1911  api_samr_connect
1912  ********************************************************************/
1913 static void api_samr_connect( uint16 vuid, prs_struct *data, prs_struct *rdata)
1914 {
1915         SAMR_Q_CONNECT q_u;
1916
1917         /* grab the samr open policy */
1918         samr_io_q_connect("", &q_u, data, 0);
1919
1920         /* construct reply.  always indicate success */
1921         samr_reply_connect(&q_u, rdata);
1922 }
1923
1924 /*******************************************************************
1925  samr_reply_open_alias
1926  ********************************************************************/
1927 static void samr_reply_open_alias(SAMR_Q_OPEN_ALIAS *q_u,
1928                                 prs_struct *rdata)
1929 {
1930         SAMR_R_OPEN_ALIAS r_u;
1931         DOM_SID sid;
1932         BOOL pol_open = False;
1933
1934         /* set up the SAMR open_alias response */
1935
1936         r_u.status = 0x0;
1937         if (r_u.status == 0x0 && !get_lsa_policy_samr_sid(&q_u->dom_pol, &sid))
1938         {
1939                 r_u.status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
1940         }
1941
1942         /* get a (unique) handle.  open a policy on it. */
1943         if (r_u.status == 0x0 && !(pol_open = open_lsa_policy_hnd(&(r_u.pol))))
1944         {
1945                 r_u.status = 0xC0000000 | NT_STATUS_OBJECT_NAME_NOT_FOUND;
1946         }
1947
1948         DEBUG(0,("TODO: verify that the alias rid exists\n"));
1949
1950         /* associate a RID with the (unique) handle. */
1951         if (r_u.status == 0x0 && !set_lsa_policy_samr_rid(&(r_u.pol), q_u->rid_alias))
1952         {
1953                 /* oh, whoops.  don't know what error message to return, here */
1954                 r_u.status = 0xC0000000 | NT_STATUS_OBJECT_NAME_NOT_FOUND;
1955         }
1956
1957         sid_append_rid(&sid, q_u->rid_alias);
1958
1959         /* associate an alias SID with the (unique) handle. */
1960         if (r_u.status == 0x0 && !set_lsa_policy_samr_sid(&(r_u.pol), &sid))
1961         {
1962                 /* oh, whoops.  don't know what error message to return, here */
1963                 r_u.status = 0xC0000000 | NT_STATUS_OBJECT_NAME_NOT_FOUND;
1964         }
1965
1966         if (r_u.status != 0 && pol_open)
1967         {
1968                 close_lsa_policy_hnd(&(r_u.pol));
1969         }
1970
1971         DEBUG(5,("samr_open_alias: %d\n", __LINE__));
1972
1973         /* store the response in the SMB stream */
1974         samr_io_r_open_alias("", &r_u, rdata, 0);
1975
1976         DEBUG(5,("samr_open_alias: %d\n", __LINE__));
1977
1978 }
1979
1980 /*******************************************************************
1981  api_samr_open_alias
1982  ********************************************************************/
1983 static void api_samr_open_alias( uint16 vuid, prs_struct *data, prs_struct *rdata)
1984                                 
1985 {
1986         SAMR_Q_OPEN_ALIAS q_u;
1987
1988         /* grab the samr open policy */
1989         samr_io_q_open_alias("", &q_u, data, 0);
1990
1991         /* construct reply.  always indicate success */
1992         samr_reply_open_alias(&q_u, rdata);
1993 }
1994
1995 /*******************************************************************
1996  samr_reply_open_group
1997  ********************************************************************/
1998 static void samr_reply_open_group(SAMR_Q_OPEN_GROUP *q_u,
1999                                 prs_struct *rdata)
2000 {
2001         SAMR_R_OPEN_GROUP r_u;
2002         DOM_SID sid;
2003         BOOL pol_open = False;
2004
2005         /* set up the SAMR open_group response */
2006
2007         r_u.status = 0x0;
2008         if (r_u.status == 0x0 && !get_lsa_policy_samr_sid(&q_u->domain_pol, &sid))
2009         {
2010                 r_u.status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
2011         }
2012
2013         /* get a (unique) handle.  open a policy on it. */
2014         if (r_u.status == 0x0 && !(pol_open = open_lsa_policy_hnd(&(r_u.pol))))
2015         {
2016                 r_u.status = 0xC0000000 | NT_STATUS_OBJECT_NAME_NOT_FOUND;
2017         }
2018
2019         DEBUG(0,("TODO: verify that the group rid exists\n"));
2020
2021         /* associate a RID with the (unique) handle. */
2022         if (r_u.status == 0x0 && !set_lsa_policy_samr_rid(&(r_u.pol), q_u->rid_group))
2023         {
2024                 /* oh, whoops.  don't know what error message to return, here */
2025                 r_u.status = 0xC0000000 | NT_STATUS_OBJECT_NAME_NOT_FOUND;
2026         }
2027
2028         sid_append_rid(&sid, q_u->rid_group);
2029
2030         /* associate an group SID with the (unique) handle. */
2031         if (r_u.status == 0x0 && !set_lsa_policy_samr_sid(&(r_u.pol), &sid))
2032         {
2033                 /* oh, whoops.  don't know what error message to return, here */
2034                 r_u.status = 0xC0000000 | NT_STATUS_OBJECT_NAME_NOT_FOUND;
2035         }
2036
2037         if (r_u.status != 0 && pol_open)
2038         {
2039                 close_lsa_policy_hnd(&(r_u.pol));
2040         }
2041
2042         DEBUG(5,("samr_open_group: %d\n", __LINE__));
2043
2044         /* store the response in the SMB stream */
2045         samr_io_r_open_group("", &r_u, rdata, 0);
2046
2047         DEBUG(5,("samr_open_group: %d\n", __LINE__));
2048
2049 }
2050
2051 /*******************************************************************
2052  api_samr_open_group
2053  ********************************************************************/
2054 static void api_samr_open_group( uint16 vuid, prs_struct *data, prs_struct *rdata)
2055                                 
2056 {
2057         SAMR_Q_OPEN_GROUP q_u;
2058
2059         /* grab the samr open policy */
2060         samr_io_q_open_group("", &q_u, data, 0);
2061
2062         /* construct reply.  always indicate success */
2063         samr_reply_open_group(&q_u, rdata);
2064 }
2065
2066 /*******************************************************************
2067  array of \PIPE\samr operations
2068  ********************************************************************/
2069 static struct api_struct api_samr_cmds [] =
2070 {
2071         { "SAMR_CLOSE_HND"        , SAMR_CLOSE_HND        , api_samr_close_hnd        },
2072         { "SAMR_CONNECT"          , SAMR_CONNECT          , api_samr_connect          },
2073         { "SAMR_CONNECT_ANON"     , SAMR_CONNECT_ANON     , api_samr_connect_anon     },
2074         { "SAMR_ENUM_DOM_USERS"   , SAMR_ENUM_DOM_USERS   , api_samr_enum_dom_users   },
2075         { "SAMR_ENUM_DOM_GROUPS"  , SAMR_ENUM_DOM_GROUPS  , api_samr_enum_dom_groups  },
2076         { "SAMR_ENUM_DOM_ALIASES" , SAMR_ENUM_DOM_ALIASES , api_samr_enum_dom_aliases },
2077         { "SAMR_QUERY_USERALIASES", SAMR_QUERY_USERALIASES, api_samr_query_useraliases},
2078         { "SAMR_QUERY_ALIASMEM"   , SAMR_QUERY_ALIASMEM   , api_samr_query_aliasmem   },
2079         { "SAMR_QUERY_GROUPMEM"   , SAMR_QUERY_GROUPMEM   , api_samr_query_groupmem   },
2080         { "SAMR_LOOKUP_NAMES"     , SAMR_LOOKUP_NAMES     , api_samr_lookup_names     },
2081         { "SAMR_OPEN_USER"        , SAMR_OPEN_USER        , api_samr_open_user        },
2082         { "SAMR_QUERY_USERINFO"   , SAMR_QUERY_USERINFO   , api_samr_query_userinfo   },
2083         { "SAMR_QUERY_DOMAIN_INFO", SAMR_QUERY_DOMAIN_INFO, api_samr_query_dom_info   },
2084         { "SAMR_QUERY_USERGROUPS" , SAMR_QUERY_USERGROUPS , api_samr_query_usergroups },
2085         { "SAMR_QUERY_DISPINFO"   , SAMR_QUERY_DISPINFO   , api_samr_query_dispinfo   },
2086         { "SAMR_QUERY_ALIASINFO"  , SAMR_QUERY_ALIASINFO  , api_samr_query_aliasinfo  },
2087         { "SAMR_QUERY_GROUPINFO"  , SAMR_QUERY_GROUPINFO  , api_samr_query_groupinfo  },
2088         { "SAMR_0x32"             , 0x32                  , api_samr_unknown_32       },
2089         { "SAMR_UNKNOWN_12"       , SAMR_UNKNOWN_12       , api_samr_unknown_12       },
2090         { "SAMR_UNKNOWN_38"       , SAMR_UNKNOWN_38       , api_samr_unknown_38       },
2091         { "SAMR_CHGPASSWD_USER"   , SAMR_CHGPASSWD_USER   , api_samr_chgpasswd_user   },
2092         { "SAMR_OPEN_ALIAS"       , SAMR_OPEN_ALIAS       , api_samr_open_alias       },
2093         { "SAMR_OPEN_GROUP"       , SAMR_OPEN_GROUP       , api_samr_open_group       },
2094         { "SAMR_OPEN_DOMAIN"      , SAMR_OPEN_DOMAIN      , api_samr_open_domain      },
2095         { "SAMR_UNKNOWN_3"        , SAMR_UNKNOWN_3        , api_samr_unknown_3        },
2096         { "SAMR_UNKNOWN_2C"       , SAMR_UNKNOWN_2C       , api_samr_unknown_2c       },
2097         { NULL                    , 0                     , NULL                      }
2098 };
2099
2100 /*******************************************************************
2101  receives a samr pipe and responds.
2102  ********************************************************************/
2103 BOOL api_samr_rpc(pipes_struct *p, prs_struct *data)
2104 {
2105     return api_rpcTNP(p, "api_samr_rpc", api_samr_cmds, data);
2106 }
2107