3 * Unix SMB/Netbios implementation.
5 * RPC Pipe client / server routines
6 * Copyright (C) Andrew Tridgell 1992-1997,
7 * Copyright (C) Luke Kenneth Casson Leighton 1996-1997,
8 * Copyright (C) Paul Ashton 1997.
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.
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.
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.
29 extern int DEBUGLEVEL;
31 extern BOOL sam_logon_in_ssb;
32 extern pstring samlogon_user;
33 extern DOM_SID global_machine_sid;
35 extern rid_name domain_group_rids[];
36 extern rid_name domain_alias_rids[];
38 /*******************************************************************
39 This next function should be replaced with something that
40 dynamically returns the correct user info..... JRA.
41 ********************************************************************/
43 static BOOL get_sampwd_entries(SAM_USER_INFO_21 *pw_buf,
44 int *total_entries, int *num_entries,
49 struct sam_passwd *pwd = NULL;
54 if (pw_buf == NULL) return False;
56 vp = startsmbpwent(False);
59 DEBUG(0, ("get_sampwd_entries: Unable to open SMB password database.\n"));
63 while (((pwd = getsam21pwent(vp)) != NULL) && (*num_entries) < max_num_entries)
65 int user_name_len = strlen(pwd->smb_name);
66 make_unistr2(&(pw_buf[(*num_entries)].uni_user_name), pwd->smb_name, user_name_len-1);
67 make_uni_hdr(&(pw_buf[(*num_entries)].hdr_user_name), user_name_len-1,
69 pw_buf[(*num_entries)].user_rid = pwd->user_rid;
70 bzero( pw_buf[(*num_entries)].nt_pwd , 16);
72 /* Now check if the NT compatible password is available. */
73 if (pwd->smb_nt_passwd != NULL)
75 memcpy( pw_buf[(*num_entries)].nt_pwd , pwd->smb_nt_passwd, 16);
78 pw_buf[(*num_entries)].acb_info = (uint16)pwd->acct_ctrl;
80 DEBUG(5, ("entry idx: %d user %s, rid 0x%x, acb %x",
81 (*num_entries), pwd->smb_name, pwd->user_rid, pwd->acct_ctrl));
83 if (acb_mask == 0 || IS_BITS_SET_SOME(pwd->acct_ctrl, acb_mask))
85 DEBUG(5,(" acb_mask %x accepts\n", acb_mask));
90 DEBUG(5,(" acb_mask %x rejects\n", acb_mask));
98 return (*num_entries) > 0;
101 /*******************************************************************
103 ********************************************************************/
104 static void samr_reply_close_hnd(SAMR_Q_CLOSE_HND *q_u,
107 SAMR_R_CLOSE_HND r_u;
109 /* set up the SAMR unknown_1 response */
110 bzero(r_u.pol.data, POL_HND_SIZE);
112 /* close the policy handle */
113 if (close_lsa_policy_hnd(&(q_u->pol)))
119 r_u.status = 0xC0000000 | NT_STATUS_OBJECT_NAME_INVALID;
122 DEBUG(5,("samr_reply_close_hnd: %d\n", __LINE__));
124 /* store the response in the SMB stream */
125 samr_io_r_close_hnd("", &r_u, rdata, 0);
127 DEBUG(5,("samr_reply_close_hnd: %d\n", __LINE__));
131 /*******************************************************************
133 ********************************************************************/
134 static void api_samr_close_hnd( int uid, prs_struct *data, prs_struct *rdata)
136 SAMR_Q_CLOSE_HND q_u;
138 /* grab the samr unknown 1 */
139 samr_io_q_close_hnd("", &q_u, data, 0);
141 /* construct reply. always indicate success */
142 samr_reply_close_hnd(&q_u, rdata);
146 /*******************************************************************
147 samr_reply_open_domain
148 ********************************************************************/
149 static void samr_reply_open_domain(SAMR_Q_OPEN_DOMAIN *q_u,
152 SAMR_R_OPEN_DOMAIN r_u;
153 BOOL pol_open = False;
158 /* find the connection policy handle. */
159 if (r_u.status == 0x0 && ((pol_idx = find_lsa_policy_by_hnd(&(q_u->connect_pol))) == -1))
161 r_u.status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
164 /* get a (unique) handle. open a policy on it. */
165 if (r_u.status == 0x0 && !(pol_open = open_lsa_policy_hnd(&(r_u.domain_pol))))
167 r_u.status = 0xC0000000 | NT_STATUS_OBJECT_NAME_NOT_FOUND;
170 /* associate the domain SID with the (unique) handle. */
171 if (r_u.status == 0x0 && !set_lsa_policy_samr_sid(&(r_u.domain_pol), &(q_u->dom_sid.sid)))
173 /* oh, whoops. don't know what error message to return, here */
174 r_u.status = 0xC0000000 | NT_STATUS_OBJECT_NAME_NOT_FOUND;
177 if (r_u.status != 0 && pol_open)
179 close_lsa_policy_hnd(&(r_u.domain_pol));
182 DEBUG(5,("samr_open_domain: %d\n", __LINE__));
184 /* store the response in the SMB stream */
185 samr_io_r_open_domain("", &r_u, rdata, 0);
187 DEBUG(5,("samr_open_domain: %d\n", __LINE__));
191 /*******************************************************************
193 ********************************************************************/
194 static void api_samr_open_domain( int uid, prs_struct *data, prs_struct *rdata)
196 SAMR_Q_OPEN_DOMAIN q_u;
198 /* grab the samr open */
199 samr_io_q_open_domain("", &q_u, data, 0);
201 /* construct reply. always indicate success */
202 samr_reply_open_domain(&q_u, rdata);
206 /*******************************************************************
208 ********************************************************************/
209 static void samr_reply_unknown_3(SAMR_Q_UNKNOWN_3 *q_u,
212 SAMR_R_UNKNOWN_3 r_u;
213 DOM_SID3 sid[MAX_SAM_SIDS];
220 /* find the policy handle. open a policy on it. */
221 if (status == 0x0 && ((pol_idx = find_lsa_policy_by_hnd(&(q_u->user_pol))) == -1))
223 status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
226 /* find the user's rid */
227 if (status == 0x0 && (rid = get_lsa_policy_samr_rid(&(q_u->user_pol))) == 0xffffffff)
229 status = NT_STATUS_OBJECT_TYPE_MISMATCH;
237 user_sid = global_machine_sid;
239 SMB_ASSERT_ARRAY(user_sid.sub_auths, user_sid.num_auths+1);
244 user_sid.sub_auths[user_sid.num_auths++] = rid;
246 string_to_sid(&other_sid, "S-1-1");
248 /* maybe need another 1 or 2 (S-1-5-20-0x220 and S-1-5-20-0x224) */
249 /* these two are DOMAIN_ADMIN and DOMAIN_ACCT_OP group RIDs */
250 make_dom_sid3(&(sid[0]), 0x035b, 0x0002, &other_sid);
251 make_dom_sid3(&(sid[1]), 0x0044, 0x0002, &user_sid);
254 make_samr_r_unknown_3(&r_u,
256 0x00000014, 0x0002, 0x0070,
259 DEBUG(5,("samr_unknown_3: %d\n", __LINE__));
261 /* store the response in the SMB stream */
262 samr_io_r_unknown_3("", &r_u, rdata, 0);
264 DEBUG(5,("samr_unknown_3: %d\n", __LINE__));
268 /*******************************************************************
270 ********************************************************************/
271 static void api_samr_unknown_3( int uid, prs_struct *data, prs_struct *rdata)
273 SAMR_Q_UNKNOWN_3 q_u;
275 /* grab the samr open */
276 samr_io_q_unknown_3("", &q_u, data, 0);
278 /* construct reply. always indicate success */
279 samr_reply_unknown_3(&q_u, rdata);
283 /*******************************************************************
284 samr_reply_enum_dom_users
285 ********************************************************************/
286 static void samr_reply_enum_dom_users(SAMR_Q_ENUM_DOM_USERS *q_u,
289 SAMR_R_ENUM_DOM_USERS r_e;
290 SAM_USER_INFO_21 pass[MAX_SAM_ENTRIES];
297 r_e.total_num_entries = 0;
299 /* find the policy handle. open a policy on it. */
300 if (r_e.status == 0x0 && ((pol_idx = find_lsa_policy_by_hnd(&(q_u->pol))) == -1))
302 r_e.status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
305 DEBUG(5,("samr_reply_enum_dom_users: %d\n", __LINE__));
308 got_pwds = get_sampwd_entries(pass, &total_entries, &num_entries, MAX_SAM_ENTRIES, q_u->acb_mask);
311 make_samr_r_enum_dom_users(&r_e, total_entries,
312 q_u->unknown_0, num_entries,
315 /* store the response in the SMB stream */
316 samr_io_r_enum_dom_users("", &r_e, rdata, 0);
318 DEBUG(5,("samr_enum_dom_users: %d\n", __LINE__));
322 /*******************************************************************
323 api_samr_enum_dom_users
324 ********************************************************************/
325 static void api_samr_enum_dom_users( int uid, prs_struct *data, prs_struct *rdata)
327 SAMR_Q_ENUM_DOM_USERS q_e;
329 /* grab the samr open */
330 samr_io_q_enum_dom_users("", &q_e, data, 0);
332 /* construct reply. */
333 samr_reply_enum_dom_users(&q_e, rdata);
337 /*******************************************************************
338 samr_reply_enum_dom_groups
339 ********************************************************************/
340 static void samr_reply_enum_dom_groups(SAMR_Q_ENUM_DOM_GROUPS *q_u,
343 SAMR_R_ENUM_DOM_GROUPS r_e;
344 SAM_USER_INFO_21 pass[MAX_SAM_ENTRIES];
348 char *dummy_group = "Domain Admins";
353 /* find the policy handle. open a policy on it. */
354 if (r_e.status == 0x0 && ((pol_idx = find_lsa_policy_by_hnd(&(q_u->pol))) == -1))
356 r_e.status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
359 DEBUG(5,("samr_reply_enum_dom_groups: %d\n", __LINE__));
363 make_unistr2(&(pass[0].uni_user_name), dummy_group, strlen(dummy_group));
364 pass[0].user_rid = DOMAIN_GROUP_RID_ADMINS;
366 if (r_e.status == 0 && got_grps)
368 make_samr_r_enum_dom_groups(&r_e, q_u->start_idx, num_entries, pass, r_e.status);
371 /* store the response in the SMB stream */
372 samr_io_r_enum_dom_groups("", &r_e, rdata, 0);
374 DEBUG(5,("samr_enum_dom_groups: %d\n", __LINE__));
378 /*******************************************************************
379 api_samr_enum_dom_groups
380 ********************************************************************/
381 static void api_samr_enum_dom_groups( int uid, prs_struct *data, prs_struct *rdata)
383 SAMR_Q_ENUM_DOM_GROUPS q_e;
385 /* grab the samr open */
386 samr_io_q_enum_dom_groups("", &q_e, data, 0);
388 /* construct reply. */
389 samr_reply_enum_dom_groups(&q_e, rdata);
393 /*******************************************************************
394 samr_reply_enum_dom_aliases
395 ********************************************************************/
396 static void samr_reply_enum_dom_aliases(SAMR_Q_ENUM_DOM_ALIASES *q_u,
399 SAMR_R_ENUM_DOM_ALIASES r_e;
400 SAM_USER_INFO_21 pass[MAX_SAM_ENTRIES];
404 char *dummy_alias = "admins";
409 /* find the policy handle. open a policy on it. */
410 if (r_e.status == 0x0 && ((pol_idx = find_lsa_policy_by_hnd(&(q_u->pol))) == -1))
412 r_e.status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
415 DEBUG(5,("samr_reply_enum_dom_aliases: %d\n", __LINE__));
419 make_unistr2(&(pass[0].uni_user_name), dummy_alias, strlen(dummy_alias));
420 pass[0].user_rid = BUILTIN_ALIAS_RID_ADMINS;
422 if (r_e.status == 0 && got_aliases)
424 make_samr_r_enum_dom_aliases(&r_e, num_entries, pass, r_e.status);
427 /* store the response in the SMB stream */
428 samr_io_r_enum_dom_aliases("", &r_e, rdata, 0);
430 DEBUG(5,("samr_enum_dom_aliases: %d\n", __LINE__));
434 /*******************************************************************
435 api_samr_enum_dom_aliases
436 ********************************************************************/
437 static void api_samr_enum_dom_aliases( int uid, prs_struct *data, prs_struct *rdata)
439 SAMR_Q_ENUM_DOM_ALIASES q_e;
441 /* grab the samr open */
442 samr_io_q_enum_dom_aliases("", &q_e, data, 0);
444 /* construct reply. */
445 samr_reply_enum_dom_aliases(&q_e, rdata);
449 /*******************************************************************
450 samr_reply_query_dispinfo
451 ********************************************************************/
452 static void samr_reply_query_dispinfo(SAMR_Q_QUERY_DISPINFO *q_u,
455 SAMR_R_QUERY_DISPINFO r_e;
459 SAM_USER_INFO_21 pass[MAX_SAM_ENTRIES];
464 uint16 switch_level = 0x0;
468 /* find the policy handle. open a policy on it. */
469 if (r_e.status == 0x0 && ((pol_idx = find_lsa_policy_by_hnd(&(q_u->pol))) == -1))
471 r_e.status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
474 DEBUG(5,("samr_reply_query_dispinfo: %d\n", __LINE__));
477 got_pwds = get_sampwd_entries(pass, &total_entries, &num_entries, MAX_SAM_ENTRIES, 0);
480 switch (q_u->switch_level)
485 /* query disp info is for users */
487 make_sam_info_1(&info1, ACB_NORMAL,
488 q_u->start_idx, num_entries, pass);
490 ctr.sam.info1 = &info1;
496 /* query disp info is for servers */
498 make_sam_info_2(&info2, ACB_WSTRUST,
499 q_u->start_idx, num_entries, pass);
501 ctr.sam.info2 = &info2;
507 if (r_e.status == 0 && got_pwds)
509 make_samr_r_query_dispinfo(&r_e, switch_level, &ctr, r_e.status);
512 /* store the response in the SMB stream */
513 samr_io_r_query_dispinfo("", &r_e, rdata, 0);
515 DEBUG(5,("samr_query_dispinfo: %d\n", __LINE__));
519 /*******************************************************************
520 api_samr_query_dispinfo
521 ********************************************************************/
522 static void api_samr_query_dispinfo( int uid, prs_struct *data, prs_struct *rdata)
524 SAMR_Q_QUERY_DISPINFO q_e;
526 /* grab the samr open */
527 samr_io_q_query_dispinfo("", &q_e, data, 0);
529 /* construct reply. */
530 samr_reply_query_dispinfo(&q_e, rdata);
534 /*******************************************************************
535 samr_reply_query_aliasinfo
536 ********************************************************************/
537 static void samr_reply_query_aliasinfo(SAMR_Q_QUERY_ALIASINFO *q_u,
540 SAMR_R_QUERY_ALIASINFO r_e;
547 /* find the policy handle. open a policy on it. */
548 if (r_e.status == 0x0 && ((pol_idx = find_lsa_policy_by_hnd(&(q_u->pol))) == -1))
550 r_e.status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
553 DEBUG(5,("samr_reply_query_aliasinfo: %d\n", __LINE__));
555 if (r_e.status == 0x0)
557 if (q_u->switch_level != 3)
559 r_e.status = NT_STATUS_INVALID_INFO_CLASS;
563 if (r_e.status == 0x0)
568 make_samr_r_query_aliasinfo(&r_e, q_u->switch_level,
569 "<account description>",
572 /* store the response in the SMB stream */
573 samr_io_r_query_aliasinfo("", &r_e, rdata, 0);
575 DEBUG(5,("samr_query_aliasinfo: %d\n", __LINE__));
579 /*******************************************************************
580 api_samr_query_aliasinfo
581 ********************************************************************/
582 static void api_samr_query_aliasinfo( int uid, prs_struct *data, prs_struct *rdata)
584 SAMR_Q_QUERY_ALIASINFO q_e;
586 /* grab the samr open */
587 samr_io_q_query_aliasinfo("", &q_e, data, 0);
589 /* construct reply. */
590 samr_reply_query_aliasinfo(&q_e, rdata);
594 /*******************************************************************
595 samr_reply_lookup_ids
596 ********************************************************************/
597 static void samr_reply_lookup_ids(SAMR_Q_LOOKUP_IDS *q_u,
600 uint32 rid[MAX_SAM_ENTRIES];
602 int num_rids = q_u->num_sids1;
604 SAMR_R_LOOKUP_IDS r_u;
606 DEBUG(5,("samr_lookup_ids: %d\n", __LINE__));
608 if (num_rids > MAX_SAM_ENTRIES)
610 num_rids = MAX_SAM_ENTRIES;
611 DEBUG(5,("samr_lookup_ids: truncating entries to %d\n", num_rids));
616 SMB_ASSERT_ARRAY(q_u->uni_user_name, num_rids);
618 for (i = 0; i < num_rids && status == 0; i++)
620 struct sam_passwd *sam_pass;
624 fstrcpy(user_name, unistrn2(q_u->uni_user_name[i].buffer,
625 q_u->uni_user_name[i].uni_str_len));
627 /* find the user account */
629 sam_pass = get_smb21pwd_entry(user_name, 0);
632 if (sam_pass == NULL)
634 status = 0xC0000000 | NT_STATUS_NO_SUCH_USER;
639 rid[i] = sam_pass->user_rid;
645 rid[0] = BUILTIN_ALIAS_RID_USERS;
647 make_samr_r_lookup_ids(&r_u, num_rids, rid, status);
649 /* store the response in the SMB stream */
650 samr_io_r_lookup_ids("", &r_u, rdata, 0);
652 DEBUG(5,("samr_lookup_ids: %d\n", __LINE__));
656 /*******************************************************************
658 ********************************************************************/
659 static void api_samr_lookup_ids( int uid, prs_struct *data, prs_struct *rdata)
661 SAMR_Q_LOOKUP_IDS q_u;
663 /* grab the samr 0x10 */
664 samr_io_q_lookup_ids("", &q_u, data, 0);
666 /* construct reply. always indicate success */
667 samr_reply_lookup_ids(&q_u, rdata);
670 /*******************************************************************
671 samr_reply_lookup_names
672 ********************************************************************/
673 static void samr_reply_lookup_names(SAMR_Q_LOOKUP_NAMES *q_u,
676 uint32 rid[MAX_SAM_ENTRIES];
679 int num_rids = q_u->num_rids1;
681 SAMR_R_LOOKUP_NAMES r_u;
683 DEBUG(5,("samr_lookup_names: %d\n", __LINE__));
685 if (num_rids > MAX_SAM_ENTRIES)
687 num_rids = MAX_SAM_ENTRIES;
688 DEBUG(5,("samr_lookup_names: truncating entries to %d\n", num_rids));
691 SMB_ASSERT_ARRAY(q_u->uni_user_name, num_rids);
693 for (i = 0; i < num_rids && status == 0; i++)
697 status = 0xC0000000 | NT_STATUS_NONE_MAPPED;
699 fstrcpy(name, unistrn2(q_u->uni_user_name[i].buffer, q_u->uni_user_name[i].uni_str_len));
701 status = (status != 0x0) ? lookup_user_rid (name, &(rid[i])) : status;
702 status = (status != 0x0) ? lookup_group_rid(name, &(rid[i])) : status;
703 status = (status != 0x0) ? lookup_alias_rid(name, &(rid[i])) : status;
706 make_samr_r_lookup_names(&r_u, num_rids, rid, status);
708 /* store the response in the SMB stream */
709 samr_io_r_lookup_names("", &r_u, rdata, 0);
711 DEBUG(5,("samr_lookup_names: %d\n", __LINE__));
715 /*******************************************************************
716 api_samr_lookup_names
717 ********************************************************************/
718 static void api_samr_lookup_names( int uid, prs_struct *data, prs_struct *rdata)
720 SAMR_Q_LOOKUP_NAMES q_u;
722 /* grab the samr lookup names */
723 samr_io_q_lookup_names("", &q_u, data, 0);
725 /* construct reply. always indicate success */
726 samr_reply_lookup_names(&q_u, rdata);
730 /*******************************************************************
731 samr_reply_unknown_12
732 ********************************************************************/
733 static void samr_reply_unknown_12(SAMR_Q_UNKNOWN_12 *q_u,
736 fstring group_names[MAX_SAM_ENTRIES];
737 uint32 group_attrs[MAX_SAM_ENTRIES];
739 int num_gids = q_u->num_gids1;
742 SAMR_R_UNKNOWN_12 r_u;
744 DEBUG(5,("samr_unknown_12: %d\n", __LINE__));
746 /* find the policy handle. open a policy on it. */
747 if (status == 0x0 && ((pol_idx = find_lsa_policy_by_hnd(&(q_u->pol))) == -1))
749 status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
755 if (num_gids > MAX_SAM_ENTRIES)
757 num_gids = MAX_SAM_ENTRIES;
758 DEBUG(5,("samr_unknown_12: truncating entries to %d\n", num_gids));
761 for (i = 0; i < num_gids && status == 0; i++)
763 fstrcpy(group_names[i], "dummy group");
764 group_attrs[i] = 0x2;
768 make_samr_r_unknown_12(&r_u, num_gids, group_names, group_attrs, status);
770 /* store the response in the SMB stream */
771 samr_io_r_unknown_12("", &r_u, rdata, 0);
773 DEBUG(5,("samr_unknown_12: %d\n", __LINE__));
777 /*******************************************************************
779 ********************************************************************/
780 static void api_samr_unknown_12( int uid, prs_struct *data, prs_struct *rdata)
782 SAMR_Q_UNKNOWN_12 q_u;
784 /* grab the samr lookup names */
785 samr_io_q_unknown_12("", &q_u, data, 0);
787 /* construct reply. always indicate success */
788 samr_reply_unknown_12(&q_u, rdata);
792 /*******************************************************************
794 ********************************************************************/
795 static void samr_reply_open_user(SAMR_Q_OPEN_USER *q_u,
799 SAMR_R_OPEN_USER r_u;
800 struct sam_passwd *sam_pass;
802 BOOL pol_open = False;
804 /* set up the SAMR open_user response */
805 bzero(r_u.user_pol.data, POL_HND_SIZE);
809 /* find the policy handle. open a policy on it. */
810 if (r_u.status == 0x0 && ((pol_idx = find_lsa_policy_by_hnd(&(q_u->domain_pol))) == -1))
812 r_u.status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
815 /* get a (unique) handle. open a policy on it. */
816 if (r_u.status == 0x0 && !(pol_open = open_lsa_policy_hnd(&(r_u.user_pol))))
818 r_u.status = 0xC0000000 | NT_STATUS_OBJECT_NAME_NOT_FOUND;
822 sam_pass = getsam21pwrid(q_u->user_rid);
825 /* check that the RID exists in our domain. */
826 if (r_u.status == 0x0 && sam_pass == NULL)
828 r_u.status = 0xC0000000 | NT_STATUS_NO_SUCH_USER;
831 /* associate the RID with the (unique) handle. */
832 if (r_u.status == 0x0 && !set_lsa_policy_samr_rid(&(r_u.user_pol), q_u->user_rid))
834 /* oh, whoops. don't know what error message to return, here */
835 r_u.status = 0xC0000000 | NT_STATUS_OBJECT_NAME_NOT_FOUND;
838 if (r_u.status != 0 && pol_open)
840 close_lsa_policy_hnd(&(r_u.user_pol));
843 DEBUG(5,("samr_open_user: %d\n", __LINE__));
845 /* store the response in the SMB stream */
846 samr_io_r_open_user("", &r_u, rdata, 0);
848 DEBUG(5,("samr_open_user: %d\n", __LINE__));
852 /*******************************************************************
854 ********************************************************************/
855 static void api_samr_open_user( int rid, prs_struct *data, prs_struct *rdata)
857 SAMR_Q_OPEN_USER q_u;
859 /* grab the samr unknown 22 */
860 samr_io_q_open_user("", &q_u, data, 0);
862 /* construct reply. always indicate success */
863 samr_reply_open_user(&q_u, rdata, 0x0);
867 /*************************************************************************
869 *************************************************************************/
870 static BOOL get_user_info_21(SAM_USER_INFO_21 *id21, uint32 user_rid)
873 struct sam_passwd *sam_pass;
877 #ifdef DONT_CHECK_THIS_FOR_NOW
878 if (!pdb_rid_is_user(user_rid))
880 DEBUG(4,("RID 0x%x is not a user RID\n", user_rid));
886 sam_pass = getsam21pwrid(user_rid);
889 if (sam_pass == NULL)
891 DEBUG(4,("User 0x%x not found\n", user_rid));
895 DEBUG(3,("User:[%s]\n", sam_pass->smb_name));
897 dummy_time.low = 0xffffffff;
898 dummy_time.high = 0x7fffffff;
900 DEBUG(0,("get_user_info_21 - TODO: convert unix times to NTTIMEs\n"));
902 /* create a LOGON_HRS structure */
903 hrs.len = sam_pass->hours_len;
904 SMB_ASSERT_ARRAY(hrs.hours, hrs.len);
905 for (i = 0; i < hrs.len; i++)
907 hrs.hours[i] = sam_pass->hours[i];
910 make_sam_user_info21(id21,
912 &dummy_time, /* logon_time */
913 &dummy_time, /* logoff_time */
914 &dummy_time, /* kickoff_time */
915 &dummy_time, /* pass_last_set_time */
916 &dummy_time, /* pass_can_change_time */
917 &dummy_time, /* pass_must_change_time */
919 sam_pass->smb_name, /* user_name */
920 sam_pass->full_name, /* full_name */
921 sam_pass->home_dir, /* home_dir */
922 sam_pass->dir_drive, /* dir_drive */
923 sam_pass->logon_script, /* logon_script */
924 sam_pass->profile_path, /* profile_path */
925 sam_pass->acct_desc, /* description */
926 sam_pass->workstations, /* workstations user can log in from */
927 sam_pass->unknown_str, /* don't know, yet */
928 sam_pass->munged_dial, /* dialin info. contains dialin path and tel no */
930 sam_pass->user_rid, /* RID user_id */
931 sam_pass->group_rid, /* RID group_id */
934 sam_pass->unknown_3, /* unknown_3 */
935 sam_pass->logon_divs, /* divisions per week */
936 &hrs, /* logon hours */
938 sam_pass->unknown_6);
943 /*******************************************************************
944 samr_reply_query_userinfo
945 ********************************************************************/
946 static void samr_reply_query_userinfo(SAMR_Q_QUERY_USERINFO *q_u,
949 SAMR_R_QUERY_USERINFO r_u;
951 SAM_USER_INFO_11 id11;
953 SAM_USER_INFO_21 id21;
960 DEBUG(5,("samr_reply_query_userinfo: %d\n", __LINE__));
962 /* search for the handle */
963 if (status == 0x0 && (obj_idx = find_lsa_policy_by_hnd(&(q_u->pol))) == -1)
965 status = NT_STATUS_INVALID_HANDLE;
968 /* find the user's rid */
969 if (status == 0x0 && (rid = get_lsa_policy_samr_rid(&(q_u->pol))) == 0xffffffff)
971 status = NT_STATUS_OBJECT_TYPE_MISMATCH;
974 DEBUG(5,("samr_reply_query_userinfo: rid:0x%x\n", rid));
976 /* ok! user info levels (there are lots: see MSDEV help), off we go... */
979 switch (q_u->switch_value)
982 /* whoops - got this wrong. i think. or don't understand what's happening. */
988 expire.low = 0xffffffff;
989 expire.high = 0x7fffffff;
991 make_sam_user_info11(&id11, &expire, "BROOKFIELDS$", 0x03ef, 0x201, 0x0080);
999 status = get_user_info_21(&id21, rid) ? 0 : NT_STATUS_NO_SUCH_USER;
1005 status = NT_STATUS_INVALID_INFO_CLASS;
1012 make_samr_r_query_userinfo(&r_u, q_u->switch_value, info, status);
1014 /* store the response in the SMB stream */
1015 samr_io_r_query_userinfo("", &r_u, rdata, 0);
1017 DEBUG(5,("samr_reply_query_userinfo: %d\n", __LINE__));
1021 /*******************************************************************
1022 api_samr_query_userinfo
1023 ********************************************************************/
1024 static void api_samr_query_userinfo( int uid, prs_struct *data, prs_struct *rdata)
1026 SAMR_Q_QUERY_USERINFO q_u;
1028 /* grab the samr unknown 24 */
1029 samr_io_q_query_userinfo("", &q_u, data, 0);
1031 /* construct reply. always indicate success */
1032 samr_reply_query_userinfo(&q_u, rdata);
1036 /*******************************************************************
1037 samr_reply_query_usergroups
1038 ********************************************************************/
1039 static void samr_reply_query_usergroups(SAMR_Q_QUERY_USERGROUPS *q_u,
1042 SAMR_R_QUERY_USERGROUPS r_u;
1043 uint32 status = 0x0;
1045 struct sam_passwd *sam_pass;
1046 DOM_GID *gids = NULL;
1051 DEBUG(5,("samr_query_usergroups: %d\n", __LINE__));
1053 /* find the policy handle. open a policy on it. */
1054 if (status == 0x0 && ((pol_idx = find_lsa_policy_by_hnd(&(q_u->pol))) == -1))
1056 status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
1059 /* find the user's rid */
1060 if (status == 0x0 && (rid = get_lsa_policy_samr_rid(&(q_u->pol))) == 0xffffffff)
1062 status = NT_STATUS_OBJECT_TYPE_MISMATCH;
1068 sam_pass = getsam21pwrid(rid);
1069 unbecome_root(True);
1071 if (sam_pass == NULL)
1073 status = 0xC0000000 | NT_STATUS_NO_SUCH_USER;
1080 get_domain_user_groups(groups, sam_pass->smb_name);
1082 num_groups = make_dom_gids(groups, &gids);
1085 /* construct the response. lkclXXXX: gids are not copied! */
1086 make_samr_r_query_usergroups(&r_u, num_groups, gids, status);
1088 /* store the response in the SMB stream */
1089 samr_io_r_query_usergroups("", &r_u, rdata, 0);
1096 DEBUG(5,("samr_query_usergroups: %d\n", __LINE__));
1100 /*******************************************************************
1101 api_samr_query_usergroups
1102 ********************************************************************/
1103 static void api_samr_query_usergroups( int uid, prs_struct *data, prs_struct *rdata)
1105 SAMR_Q_QUERY_USERGROUPS q_u;
1106 /* grab the samr unknown 32 */
1107 samr_io_q_query_usergroups("", &q_u, data, 0);
1109 /* construct reply. */
1110 samr_reply_query_usergroups(&q_u, rdata);
1114 /*******************************************************************
1115 samr_reply_unknown_32
1116 ********************************************************************/
1117 static void samr_reply_unknown_32(SAMR_Q_UNKNOWN_32 *q_u,
1122 SAMR_R_UNKNOWN_32 r_u;
1124 /* set up the SAMR unknown_32 response */
1125 bzero(r_u.pol.data, POL_HND_SIZE);
1128 for (i = 4; i < POL_HND_SIZE; i++)
1130 r_u.pol.data[i] = i+1;
1134 make_dom_rid4(&(r_u.rid4), 0x0030, 0, 0);
1135 r_u.status = status;
1137 DEBUG(5,("samr_unknown_32: %d\n", __LINE__));
1139 /* store the response in the SMB stream */
1140 samr_io_r_unknown_32("", &r_u, rdata, 0);
1142 DEBUG(5,("samr_unknown_32: %d\n", __LINE__));
1146 /*******************************************************************
1148 ********************************************************************/
1149 static void api_samr_unknown_32( int uid, prs_struct *data, prs_struct *rdata)
1152 struct sam_passwd *sam_pass;
1155 SAMR_Q_UNKNOWN_32 q_u;
1157 /* grab the samr unknown 32 */
1158 samr_io_q_unknown_32("", &q_u, data, 0);
1160 /* find the machine account: tell the caller if it exists.
1161 lkclXXXX i have *no* idea if this is a problem or not
1162 or even if you are supposed to construct a different
1163 reply if the account already exists...
1166 fstrcpy(mach_acct, unistrn2(q_u.uni_mach_acct.buffer,
1167 q_u.uni_mach_acct.uni_str_len));
1170 sam_pass = getsam21pwnam(mach_acct);
1171 unbecome_root(True);
1173 if (sam_pass != NULL)
1175 /* machine account exists: say so */
1176 status = 0xC0000000 | NT_STATUS_USER_EXISTS;
1180 /* this could cause trouble... */
1181 DEBUG(0,("trouble!\n"));
1185 /* construct reply. */
1186 samr_reply_unknown_32(&q_u, rdata, status);
1190 /*******************************************************************
1192 ********************************************************************/
1193 static void samr_reply_connect(SAMR_Q_CONNECT *q_u,
1197 BOOL pol_open = False;
1199 /* set up the SAMR connect response */
1202 /* get a (unique) handle. open a policy on it. */
1203 if (r_u.status == 0x0 && !(pol_open = open_lsa_policy_hnd(&(r_u.connect_pol))))
1205 r_u.status = 0xC0000000 | NT_STATUS_OBJECT_NAME_NOT_FOUND;
1208 /* associate the domain SID with the (unique) handle. */
1209 if (r_u.status == 0x0 && !set_lsa_policy_samr_pol_status(&(r_u.connect_pol), q_u->unknown_0))
1211 /* oh, whoops. don't know what error message to return, here */
1212 r_u.status = 0xC0000000 | NT_STATUS_OBJECT_NAME_NOT_FOUND;
1215 if (r_u.status != 0 && pol_open)
1217 close_lsa_policy_hnd(&(r_u.connect_pol));
1220 DEBUG(5,("samr_connect: %d\n", __LINE__));
1222 /* store the response in the SMB stream */
1223 samr_io_r_connect("", &r_u, rdata, 0);
1225 DEBUG(5,("samr_connect: %d\n", __LINE__));
1229 /*******************************************************************
1231 ********************************************************************/
1232 static void api_samr_connect( int uid, prs_struct *data, prs_struct *rdata)
1236 /* grab the samr open policy */
1237 samr_io_q_connect("", &q_u, data, 0);
1239 /* construct reply. always indicate success */
1240 samr_reply_connect(&q_u, rdata);
1243 /*******************************************************************
1244 samr_reply_open_alias
1245 ********************************************************************/
1246 static void samr_reply_open_alias(SAMR_Q_OPEN_ALIAS *q_u,
1249 SAMR_R_OPEN_ALIAS r_u;
1250 BOOL pol_open = False;
1252 /* set up the SAMR open_alias response */
1255 /* get a (unique) handle. open a policy on it. */
1256 if (r_u.status == 0x0 && !(pol_open = open_lsa_policy_hnd(&(r_u.pol))))
1258 r_u.status = 0xC0000000 | NT_STATUS_OBJECT_NAME_NOT_FOUND;
1261 /* associate a RID with the (unique) handle. */
1262 if (r_u.status == 0x0 && !set_lsa_policy_samr_rid(&(r_u.pol), q_u->rid_alias))
1264 /* oh, whoops. don't know what error message to return, here */
1265 r_u.status = 0xC0000000 | NT_STATUS_OBJECT_NAME_NOT_FOUND;
1268 if (r_u.status != 0 && pol_open)
1270 close_lsa_policy_hnd(&(r_u.pol));
1273 DEBUG(5,("samr_open_alias: %d\n", __LINE__));
1275 /* store the response in the SMB stream */
1276 samr_io_r_open_alias("", &r_u, rdata, 0);
1278 DEBUG(5,("samr_open_alias: %d\n", __LINE__));
1282 /*******************************************************************
1284 ********************************************************************/
1285 static void api_samr_open_alias( int uid, prs_struct *data, prs_struct *rdata)
1288 SAMR_Q_OPEN_ALIAS q_u;
1290 /* grab the samr open policy */
1291 samr_io_q_open_alias("", &q_u, data, 0);
1293 /* construct reply. always indicate success */
1294 samr_reply_open_alias(&q_u, rdata);
1297 /*******************************************************************
1298 array of \PIPE\samr operations
1299 ********************************************************************/
1300 static struct api_struct api_samr_cmds [] =
1302 { "SAMR_CLOSE_HND" , SAMR_CLOSE_HND , api_samr_close_hnd },
1303 { "SAMR_CONNECT" , SAMR_CONNECT , api_samr_connect },
1304 { "SAMR_ENUM_DOM_USERS" , SAMR_ENUM_DOM_USERS , api_samr_enum_dom_users },
1305 { "SAMR_ENUM_DOM_GROUPS" , SAMR_ENUM_DOM_GROUPS , api_samr_enum_dom_groups },
1306 { "SAMR_ENUM_DOM_ALIASES" , SAMR_ENUM_DOM_ALIASES , api_samr_enum_dom_aliases },
1307 { "SAMR_LOOKUP_IDS" , SAMR_LOOKUP_IDS , api_samr_lookup_ids },
1308 { "SAMR_LOOKUP_NAMES" , SAMR_LOOKUP_NAMES , api_samr_lookup_names },
1309 { "SAMR_OPEN_USER" , SAMR_OPEN_USER , api_samr_open_user },
1310 { "SAMR_QUERY_USERINFO" , SAMR_QUERY_USERINFO , api_samr_query_userinfo },
1311 { "SAMR_QUERY_USERGROUPS" , SAMR_QUERY_USERGROUPS , api_samr_query_usergroups },
1312 { "SAMR_QUERY_DISPINFO" , SAMR_QUERY_DISPINFO , api_samr_query_dispinfo },
1313 { "SAMR_QUERY_ALIASINFO" , SAMR_QUERY_ALIASINFO , api_samr_query_aliasinfo },
1314 { "SAMR_0x32" , 0x32 , api_samr_unknown_32 },
1315 { "SAMR_UNKNOWN_12" , SAMR_UNKNOWN_12 , api_samr_unknown_12 },
1316 { "SAMR_OPEN_ALIAS" , SAMR_OPEN_ALIAS , api_samr_open_alias },
1317 { "SAMR_OPEN_DOMAIN" , SAMR_OPEN_DOMAIN , api_samr_open_domain },
1318 { "SAMR_UNKNOWN_3" , SAMR_UNKNOWN_3 , api_samr_unknown_3 },
1322 /*******************************************************************
1323 receives a samr pipe and responds.
1324 ********************************************************************/
1325 BOOL api_samr_rpc(pipes_struct *p, prs_struct *data)
1327 return api_rpcTNP(p, "api_samr_rpc", api_samr_cmds, data);