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 rid_name domain_group_rids[];
34 extern rid_name domain_alias_rids[];
36 /*******************************************************************
37 This next function should be replaced with something that
38 dynamically returns the correct user info..... JRA.
39 ********************************************************************/
41 static BOOL get_smbpwd_entries(SAM_USER_INFO_21 *pw_buf,
42 int *total_entries, int *num_entries,
47 struct smb_passwd *pwd = NULL;
52 if (pw_buf == NULL) return False;
54 vp = startsmbpwent(False);
57 DEBUG(0, ("get_smbpwd_entries: Unable to open SMB password file.\n"));
61 while (((pwd = getsmbpwent(vp)) != NULL) && (*num_entries) < max_num_entries)
63 int user_name_len = strlen(pwd->smb_name);
64 make_unistr2(&(pw_buf[(*num_entries)].uni_user_name), pwd->smb_name, user_name_len-1);
65 make_uni_hdr(&(pw_buf[(*num_entries)].hdr_user_name), user_name_len-1,
67 pw_buf[(*num_entries)].user_rid = pwd->smb_userid;
68 bzero( pw_buf[(*num_entries)].nt_pwd , 16);
70 /* Now check if the NT compatible password is available. */
71 if (pwd->smb_nt_passwd != NULL)
73 memcpy( pw_buf[(*num_entries)].nt_pwd , pwd->smb_nt_passwd, 16);
76 pw_buf[(*num_entries)].acb_info = (uint16)pwd->acct_ctrl;
78 DEBUG(5, ("get_smbpwd_entries: idx: %d user %s, uid %d, acb %x",
79 (*num_entries), pwd->smb_name, pwd->smb_userid, pwd->acct_ctrl));
81 if (acb_mask == 0 || IS_BITS_SET_SOME(pwd->acct_ctrl, acb_mask))
83 DEBUG(5,(" acb_mask %x accepts\n", acb_mask));
88 DEBUG(5,(" acb_mask %x rejects\n", acb_mask));
96 return (*num_entries) > 0;
99 /*******************************************************************
101 ********************************************************************/
102 static void samr_reply_close_hnd(SAMR_Q_CLOSE_HND *q_u,
105 SAMR_R_CLOSE_HND r_u;
107 /* set up the SAMR unknown_1 response */
108 bzero(&(r_u.pol.data), POL_HND_SIZE);
110 /* close the policy handle */
111 if (close_lsa_policy_hnd(&(q_u->pol)))
117 r_u.status = 0xC0000000 | NT_STATUS_OBJECT_NAME_INVALID;
120 DEBUG(5,("samr_reply_close_hnd: %d\n", __LINE__));
122 /* store the response in the SMB stream */
123 samr_io_r_close_hnd("", &r_u, rdata, 0);
125 DEBUG(5,("samr_reply_close_hnd: %d\n", __LINE__));
129 /*******************************************************************
131 ********************************************************************/
132 static void api_samr_close_hnd( int uid, prs_struct *data, prs_struct *rdata)
134 SAMR_Q_CLOSE_HND q_u;
136 /* grab the samr unknown 1 */
137 samr_io_q_close_hnd("", &q_u, data, 0);
139 /* construct reply. always indicate success */
140 samr_reply_close_hnd(&q_u, rdata);
144 /*******************************************************************
145 samr_reply_open_domain
146 ********************************************************************/
147 static void samr_reply_open_domain(SAMR_Q_OPEN_DOMAIN *q_u,
150 SAMR_R_OPEN_DOMAIN r_u;
151 BOOL pol_open = False;
156 /* find the connection policy handle. */
157 if (r_u.status == 0x0 && ((pol_idx = find_lsa_policy_by_hnd(&(q_u->connect_pol))) == -1))
159 r_u.status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
162 /* get a (unique) handle. open a policy on it. */
163 if (r_u.status == 0x0 && !(pol_open = open_lsa_policy_hnd(&(r_u.domain_pol))))
165 r_u.status = 0xC0000000 | NT_STATUS_OBJECT_NAME_NOT_FOUND;
168 /* associate the domain SID with the (unique) handle. */
169 if (r_u.status == 0x0 && !set_lsa_policy_samr_sid(&(r_u.domain_pol), &(q_u->dom_sid.sid)))
171 /* oh, whoops. don't know what error message to return, here */
172 r_u.status = 0xC0000000 | NT_STATUS_OBJECT_NAME_NOT_FOUND;
175 if (r_u.status != 0 && pol_open)
177 close_lsa_policy_hnd(&(r_u.domain_pol));
180 DEBUG(5,("samr_open_domain: %d\n", __LINE__));
182 /* store the response in the SMB stream */
183 samr_io_r_open_domain("", &r_u, rdata, 0);
185 DEBUG(5,("samr_open_domain: %d\n", __LINE__));
189 /*******************************************************************
191 ********************************************************************/
192 static void api_samr_open_domain( int uid, prs_struct *data, prs_struct *rdata)
194 SAMR_Q_OPEN_DOMAIN q_u;
196 /* grab the samr open */
197 samr_io_q_open_domain("", &q_u, data, 0);
199 /* construct reply. always indicate success */
200 samr_reply_open_domain(&q_u, rdata);
204 /*******************************************************************
206 ********************************************************************/
207 static void samr_reply_unknown_3(SAMR_Q_UNKNOWN_3 *q_u,
210 SAMR_R_UNKNOWN_3 r_u;
211 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;
234 strcpy(user_sid, lp_domain_sid());
235 sprintf(user_rid, "-%x", rid);
236 strcat(user_sid, user_rid);
238 /* maybe need another 1 or 2 (S-1-5-20-0x220 and S-1-5-20-0x224) */
239 /* these two are DOMAIN_ADMIN and DOMAIN_ACCT_OP group RIDs */
240 make_dom_sid3(&(sid[0]), 0x035b, 0x0002, "S-1-1");
241 make_dom_sid3(&(sid[1]), 0x0044, 0x0002, user_sid);
244 make_samr_r_unknown_3(&r_u,
246 0x00000014, 0x0002, 0x0070,
249 DEBUG(5,("samr_unknown_3: %d\n", __LINE__));
251 /* store the response in the SMB stream */
252 samr_io_r_unknown_3("", &r_u, rdata, 0);
254 DEBUG(5,("samr_unknown_3: %d\n", __LINE__));
258 /*******************************************************************
260 ********************************************************************/
261 static void api_samr_unknown_3( int uid, prs_struct *data, prs_struct *rdata)
263 SAMR_Q_UNKNOWN_3 q_u;
265 /* grab the samr open */
266 samr_io_q_unknown_3("", &q_u, data, 0);
268 /* construct reply. always indicate success */
269 samr_reply_unknown_3(&q_u, rdata);
273 /*******************************************************************
274 samr_reply_enum_dom_users
275 ********************************************************************/
276 static void samr_reply_enum_dom_users(SAMR_Q_ENUM_DOM_USERS *q_u,
279 SAMR_R_ENUM_DOM_USERS r_e;
280 SAM_USER_INFO_21 pass[MAX_SAM_ENTRIES];
287 r_e.total_num_entries = 0;
289 /* find the policy handle. open a policy on it. */
290 if (r_e.status == 0x0 && ((pol_idx = find_lsa_policy_by_hnd(&(q_u->pol))) == -1))
292 r_e.status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
295 DEBUG(5,("samr_reply_enum_dom_users: %d\n", __LINE__));
298 got_pwds = get_smbpwd_entries(pass, &total_entries, &num_entries, MAX_SAM_ENTRIES, q_u->acb_mask);
301 make_samr_r_enum_dom_users(&r_e, total_entries,
302 q_u->unknown_0, num_entries,
305 /* store the response in the SMB stream */
306 samr_io_r_enum_dom_users("", &r_e, rdata, 0);
308 DEBUG(5,("samr_enum_dom_users: %d\n", __LINE__));
312 /*******************************************************************
313 api_samr_enum_dom_users
314 ********************************************************************/
315 static void api_samr_enum_dom_users( int uid, prs_struct *data, prs_struct *rdata)
317 SAMR_Q_ENUM_DOM_USERS q_e;
319 /* grab the samr open */
320 samr_io_q_enum_dom_users("", &q_e, data, 0);
322 /* construct reply. */
323 samr_reply_enum_dom_users(&q_e, rdata);
327 /*******************************************************************
328 samr_reply_enum_dom_groups
329 ********************************************************************/
330 static void samr_reply_enum_dom_groups(SAMR_Q_ENUM_DOM_GROUPS *q_u,
333 SAMR_R_ENUM_DOM_GROUPS r_e;
334 SAM_USER_INFO_21 pass[MAX_SAM_ENTRIES];
338 char *dummy_group = "Domain Admins";
343 /* find the policy handle. open a policy on it. */
344 if (r_e.status == 0x0 && ((pol_idx = find_lsa_policy_by_hnd(&(q_u->pol))) == -1))
346 r_e.status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
349 DEBUG(5,("samr_reply_enum_dom_groups: %d\n", __LINE__));
353 make_unistr2(&(pass[0].uni_user_name), dummy_group, strlen(dummy_group));
354 pass[0].user_rid = DOMAIN_GROUP_RID_ADMINS;
356 if (r_e.status == 0 && got_grps)
358 make_samr_r_enum_dom_groups(&r_e, q_u->start_idx, num_entries, pass, r_e.status);
361 /* store the response in the SMB stream */
362 samr_io_r_enum_dom_groups("", &r_e, rdata, 0);
364 DEBUG(5,("samr_enum_dom_groups: %d\n", __LINE__));
368 /*******************************************************************
369 api_samr_enum_dom_groups
370 ********************************************************************/
371 static void api_samr_enum_dom_groups( int uid, prs_struct *data, prs_struct *rdata)
373 SAMR_Q_ENUM_DOM_GROUPS q_e;
375 /* grab the samr open */
376 samr_io_q_enum_dom_groups("", &q_e, data, 0);
378 /* construct reply. */
379 samr_reply_enum_dom_groups(&q_e, rdata);
383 /*******************************************************************
384 samr_reply_enum_dom_aliases
385 ********************************************************************/
386 static void samr_reply_enum_dom_aliases(SAMR_Q_ENUM_DOM_ALIASES *q_u,
389 SAMR_R_ENUM_DOM_ALIASES r_e;
390 SAM_USER_INFO_21 pass[MAX_SAM_ENTRIES];
394 char *dummy_alias = "admins";
399 /* find the policy handle. open a policy on it. */
400 if (r_e.status == 0x0 && ((pol_idx = find_lsa_policy_by_hnd(&(q_u->pol))) == -1))
402 r_e.status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
405 DEBUG(5,("samr_reply_enum_dom_aliases: %d\n", __LINE__));
409 make_unistr2(&(pass[0].uni_user_name), dummy_alias, strlen(dummy_alias));
410 pass[0].user_rid = DOMAIN_ALIAS_RID_ADMINS;
412 if (r_e.status == 0 && got_aliases)
414 make_samr_r_enum_dom_aliases(&r_e, num_entries, pass, r_e.status);
417 /* store the response in the SMB stream */
418 samr_io_r_enum_dom_aliases("", &r_e, rdata, 0);
420 DEBUG(5,("samr_enum_dom_aliases: %d\n", __LINE__));
424 /*******************************************************************
425 api_samr_enum_dom_aliases
426 ********************************************************************/
427 static void api_samr_enum_dom_aliases( int uid, prs_struct *data, prs_struct *rdata)
429 SAMR_Q_ENUM_DOM_ALIASES q_e;
431 /* grab the samr open */
432 samr_io_q_enum_dom_aliases("", &q_e, data, 0);
434 /* construct reply. */
435 samr_reply_enum_dom_aliases(&q_e, rdata);
439 /*******************************************************************
440 samr_reply_query_dispinfo
441 ********************************************************************/
442 static void samr_reply_query_dispinfo(SAMR_Q_QUERY_DISPINFO *q_u,
445 SAMR_R_QUERY_DISPINFO r_e;
449 SAM_USER_INFO_21 pass[MAX_SAM_ENTRIES];
454 uint16 switch_level = 0x0;
458 /* find the policy handle. open a policy on it. */
459 if (r_e.status == 0x0 && ((pol_idx = find_lsa_policy_by_hnd(&(q_u->pol))) == -1))
461 r_e.status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
464 DEBUG(5,("samr_reply_query_dispinfo: %d\n", __LINE__));
469 got_pwds = get_smbpwd_entries(pass, &total_entries, &num_entries, MAX_SAM_ENTRIES, 0);
474 switch (q_u->switch_level)
479 /* query disp info is for users */
482 got_pwds = get_ldap_entries(pass,
489 make_sam_info_1(&info1, ACB_NORMAL,
490 q_u->start_idx, num_entries, pass);
492 ctr.sam.info1 = &info1;
498 /* query disp info is for servers */
501 got_pwds = get_ldap_entries(pass,
508 make_sam_info_2(&info2, ACB_WSTRUST,
509 q_u->start_idx, num_entries, pass);
511 ctr.sam.info2 = &info2;
517 if (r_e.status == 0 && got_pwds)
519 make_samr_r_query_dispinfo(&r_e, switch_level, &ctr, r_e.status);
522 /* store the response in the SMB stream */
523 samr_io_r_query_dispinfo("", &r_e, rdata, 0);
525 DEBUG(5,("samr_query_dispinfo: %d\n", __LINE__));
529 /*******************************************************************
530 api_samr_query_dispinfo
531 ********************************************************************/
532 static void api_samr_query_dispinfo( int uid, prs_struct *data, prs_struct *rdata)
534 SAMR_Q_QUERY_DISPINFO q_e;
536 /* grab the samr open */
537 samr_io_q_query_dispinfo("", &q_e, data, 0);
539 /* construct reply. */
540 samr_reply_query_dispinfo(&q_e, rdata);
544 /*******************************************************************
545 samr_reply_query_aliasinfo
546 ********************************************************************/
547 static void samr_reply_query_aliasinfo(SAMR_Q_QUERY_ALIASINFO *q_u,
550 SAMR_R_QUERY_ALIASINFO r_e;
557 /* find the policy handle. open a policy on it. */
558 if (r_e.status == 0x0 && ((pol_idx = find_lsa_policy_by_hnd(&(q_u->pol))) == -1))
560 r_e.status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
563 DEBUG(5,("samr_reply_query_aliasinfo: %d\n", __LINE__));
565 if (r_e.status == 0x0)
567 if (q_u->switch_level != 3)
569 r_e.status = NT_STATUS_INVALID_INFO_CLASS;
573 if (r_e.status == 0x0)
578 make_samr_r_query_aliasinfo(&r_e, q_u->switch_level,
579 "<account description>",
582 /* store the response in the SMB stream */
583 samr_io_r_query_aliasinfo("", &r_e, rdata, 0);
585 DEBUG(5,("samr_query_aliasinfo: %d\n", __LINE__));
589 /*******************************************************************
590 api_samr_query_aliasinfo
591 ********************************************************************/
592 static void api_samr_query_aliasinfo( int uid, prs_struct *data, prs_struct *rdata)
594 SAMR_Q_QUERY_ALIASINFO q_e;
596 /* grab the samr open */
597 samr_io_q_query_aliasinfo("", &q_e, data, 0);
599 /* construct reply. */
600 samr_reply_query_aliasinfo(&q_e, rdata);
604 /*******************************************************************
605 samr_reply_lookup_ids
606 ********************************************************************/
607 static void samr_reply_lookup_ids(SAMR_Q_LOOKUP_IDS *q_u,
610 uint32 rid[MAX_SAM_ENTRIES];
612 int num_rids = q_u->num_sids1;
614 SAMR_R_LOOKUP_IDS r_u;
616 DEBUG(5,("samr_lookup_ids: %d\n", __LINE__));
618 if (num_rids > MAX_SAM_ENTRIES)
620 num_rids = MAX_SAM_ENTRIES;
621 DEBUG(5,("samr_lookup_ids: truncating entries to %d\n", num_rids));
626 for (i = 0; i < num_rids && status == 0; i++)
628 struct smb_passwd *smb_pass;
631 fstrcpy(user_name, unistrn2(q_u->uni_user_name[i].buffer,
632 q_u->uni_user_name[i].uni_str_len));
634 /* find the user account */
636 smb_pass = get_smbpwd_entry(user_name, 0);
639 if (smb_pass == NULL)
641 status = 0xC0000000 | NT_STATUS_NO_SUCH_USER;
646 /* lkclXXXX SHOULD use name_to_rid() here! */
647 rid[i] = smb_pass->smb_userid;
653 rid[0] = DOMAIN_ALIAS_RID_USERS;
655 make_samr_r_lookup_ids(&r_u, num_rids, rid, status);
657 /* store the response in the SMB stream */
658 samr_io_r_lookup_ids("", &r_u, rdata, 0);
660 DEBUG(5,("samr_lookup_ids: %d\n", __LINE__));
664 /*******************************************************************
666 ********************************************************************/
667 static void api_samr_lookup_ids( int uid, prs_struct *data, prs_struct *rdata)
669 SAMR_Q_LOOKUP_IDS q_u;
671 /* grab the samr 0x10 */
672 samr_io_q_lookup_ids("", &q_u, data, 0);
674 /* construct reply. always indicate success */
675 samr_reply_lookup_ids(&q_u, rdata);
678 /*******************************************************************
679 samr_reply_lookup_names
680 ********************************************************************/
681 static void samr_reply_lookup_names(SAMR_Q_LOOKUP_NAMES *q_u,
684 uint32 rid[MAX_SAM_ENTRIES];
687 int num_rids = q_u->num_rids1;
689 SAMR_R_LOOKUP_NAMES r_u;
691 DEBUG(5,("samr_lookup_names: %d\n", __LINE__));
693 if (num_rids > MAX_SAM_ENTRIES)
695 num_rids = MAX_SAM_ENTRIES;
696 DEBUG(5,("samr_lookup_names: truncating entries to %d\n", num_rids));
699 for (i = 0; i < num_rids && status == 0; i++)
703 status = 0xC0000000 | NT_STATUS_NONE_MAPPED;
705 fstrcpy(name, unistrn2(q_u->uni_user_name[i].buffer, q_u->uni_user_name[i].uni_str_len));
707 status = (status != 0x0) ? lookup_user_rid (name, &(rid[i])) : status;
708 status = (status != 0x0) ? lookup_group_rid(name, &(rid[i])) : status;
709 status = (status != 0x0) ? lookup_alias_rid(name, &(rid[i])) : status;
712 make_samr_r_lookup_names(&r_u, num_rids, rid, status);
714 /* store the response in the SMB stream */
715 samr_io_r_lookup_names("", &r_u, rdata, 0);
717 DEBUG(5,("samr_lookup_names: %d\n", __LINE__));
721 /*******************************************************************
722 api_samr_lookup_names
723 ********************************************************************/
724 static void api_samr_lookup_names( int uid, prs_struct *data, prs_struct *rdata)
726 SAMR_Q_LOOKUP_NAMES q_u;
728 /* grab the samr lookup names */
729 samr_io_q_lookup_names("", &q_u, data, 0);
731 /* construct reply. always indicate success */
732 samr_reply_lookup_names(&q_u, rdata);
736 /*******************************************************************
737 samr_reply_unknown_12
738 ********************************************************************/
739 static void samr_reply_unknown_12(SAMR_Q_UNKNOWN_12 *q_u,
742 fstring group_names[MAX_SAM_ENTRIES];
743 uint32 group_attrs[MAX_SAM_ENTRIES];
745 int num_gids = q_u->num_gids1;
748 SAMR_R_UNKNOWN_12 r_u;
750 DEBUG(5,("samr_unknown_12: %d\n", __LINE__));
752 /* find the policy handle. open a policy on it. */
753 if (status == 0x0 && ((pol_idx = find_lsa_policy_by_hnd(&(q_u->pol))) == -1))
755 status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
761 if (num_gids > MAX_SAM_ENTRIES)
763 num_gids = MAX_SAM_ENTRIES;
764 DEBUG(5,("samr_unknown_12: truncating entries to %d\n", num_gids));
767 for (i = 0; i < num_gids && status == 0; i++)
769 fstrcpy(group_names[i], "dummy group");
770 group_attrs[i] = 0x2;
774 make_samr_r_unknown_12(&r_u, num_gids, group_names, group_attrs, status);
776 /* store the response in the SMB stream */
777 samr_io_r_unknown_12("", &r_u, rdata, 0);
779 DEBUG(5,("samr_unknown_12: %d\n", __LINE__));
783 /*******************************************************************
785 ********************************************************************/
786 static void api_samr_unknown_12( int uid, prs_struct *data, prs_struct *rdata)
788 SAMR_Q_UNKNOWN_12 q_u;
790 /* grab the samr lookup names */
791 samr_io_q_unknown_12("", &q_u, data, 0);
793 /* construct reply. always indicate success */
794 samr_reply_unknown_12(&q_u, rdata);
798 /*******************************************************************
800 ********************************************************************/
801 static void samr_reply_open_user(SAMR_Q_OPEN_USER *q_u,
805 SAMR_R_OPEN_USER r_u;
806 struct smb_passwd *smb_pass;
808 BOOL pol_open = False;
810 /* set up the SAMR open_user response */
811 bzero(&(r_u.user_pol.data), POL_HND_SIZE);
815 /* find the policy handle. open a policy on it. */
816 if (r_u.status == 0x0 && ((pol_idx = find_lsa_policy_by_hnd(&(q_u->domain_pol))) == -1))
818 r_u.status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
821 /* get a (unique) handle. open a policy on it. */
822 if (r_u.status == 0x0 && !(pol_open = open_lsa_policy_hnd(&(r_u.user_pol))))
824 r_u.status = 0xC0000000 | NT_STATUS_OBJECT_NAME_NOT_FOUND;
828 smb_pass = getsmbpwuid(q_u->user_rid);
831 /* check that the RID exists in our domain. */
832 if (r_u.status == 0x0 && smb_pass == NULL)
834 r_u.status = 0xC0000000 | NT_STATUS_NO_SUCH_USER;
837 /* associate the RID with the (unique) handle. */
838 if (r_u.status == 0x0 && !set_lsa_policy_samr_rid(&(r_u.user_pol), q_u->user_rid))
840 /* oh, whoops. don't know what error message to return, here */
841 r_u.status = 0xC0000000 | NT_STATUS_OBJECT_NAME_NOT_FOUND;
844 if (r_u.status != 0 && pol_open)
846 close_lsa_policy_hnd(&(r_u.user_pol));
849 DEBUG(5,("samr_open_user: %d\n", __LINE__));
851 /* store the response in the SMB stream */
852 samr_io_r_open_user("", &r_u, rdata, 0);
854 DEBUG(5,("samr_open_user: %d\n", __LINE__));
858 /*******************************************************************
860 ********************************************************************/
861 static void api_samr_open_user( int uid, prs_struct *data, prs_struct *rdata)
863 SAMR_Q_OPEN_USER q_u;
865 /* grab the samr unknown 22 */
866 samr_io_q_open_user("", &q_u, data, 0);
868 /* construct reply. always indicate success */
869 samr_reply_open_user(&q_u, rdata, 0x0);
873 /*************************************************************************
875 *************************************************************************/
876 static BOOL get_user_info_21(SAM_USER_INFO_21 *id21, uint32 rid)
880 pstring logon_script;
881 pstring profile_path;
885 pstring workstations;
887 pstring munged_dialin;
896 struct smb_passwd *smb_pass;
899 smb_pass = getsmbpwuid(rid);
902 if (smb_pass == NULL)
907 DEBUG(3,("User:[%s]\n", smb_pass->smb_name));
909 dummy_time.low = 0xffffffff;
910 dummy_time.high = 0x7fffffff;
912 pstrcpy(samlogon_user, smb_pass->smb_name);
914 if (samlogon_user[strlen(samlogon_user)-1] != '$')
916 if (!name_to_rid(samlogon_user, &r_uid, &r_gid))
921 /* XXXX hack to get standard_sub_basic() to use sam logon username */
922 /* possibly a better way would be to do a become_user() call */
923 sam_logon_in_ssb = True;
925 pstrcpy(full_name , "<Full Name>");
926 pstrcpy(logon_script , lp_logon_script ());
927 pstrcpy(profile_path , lp_logon_path ());
928 pstrcpy(home_drive , lp_logon_drive ());
929 pstrcpy(home_dir , lp_logon_home ());
930 pstrcpy(description , "<Description>");
931 pstrcpy(workstations , "");
932 pstrcpy(unknown_str , "");
933 pstrcpy(munged_dialin, "");
935 sam_logon_in_ssb = False;
939 r_uid = smb_pass->smb_userid;
940 r_gid = DOMAIN_GROUP_RID_USERS;
942 pstrcpy(samlogon_user, smb_pass->smb_name);
944 pstrcpy(full_name , "");
945 pstrcpy(logon_script , "");
946 pstrcpy(profile_path , "");
947 pstrcpy(home_drive , "");
948 pstrcpy(home_dir , "");
949 pstrcpy(description , "");
950 pstrcpy(workstations , "");
951 pstrcpy(unknown_str , "");
952 pstrcpy(munged_dialin, "");
956 for (i = 0; i < hrs.len; i++)
960 make_sam_user_info21(id21,
962 &dummy_time, /* logon_time */
963 &dummy_time, /* logoff_time */
964 &dummy_time, /* kickoff_time */
965 &dummy_time, /* pass_last_set_time */
966 &dummy_time, /* pass_can_change_time */
967 &dummy_time, /* pass_must_change_time */
969 samlogon_user, /* user_name */
970 full_name, /* full_name */
971 home_dir, /* home_dir */
972 home_drive, /* dir_drive */
973 logon_script, /* logon_script */
974 profile_path, /* profile_path */
975 description, /* description */
976 workstations, /* workstations user can log in from */
977 unknown_str, /* don't know, yet */
978 munged_dialin, /* dialin info. contains dialin path and tel no */
980 r_uid, /* RID user_id */
981 r_gid, /* RID group_id */
984 0x00ffffff, /* unknown_3 */
985 168, /* divisions per week */
986 &hrs, /* logon hours */
993 /*******************************************************************
994 samr_reply_query_userinfo
995 ********************************************************************/
996 static void samr_reply_query_userinfo(SAMR_Q_QUERY_USERINFO *q_u,
999 SAMR_R_QUERY_USERINFO r_u;
1001 SAM_USER_INFO_11 id11;
1003 SAM_USER_INFO_21 id21;
1006 uint32 status = 0x0;
1010 DEBUG(5,("samr_reply_query_userinfo: %d\n", __LINE__));
1012 /* search for the handle */
1013 if (status == 0x0 && (obj_idx = find_lsa_policy_by_hnd(&(q_u->pol))) == -1)
1015 status = NT_STATUS_INVALID_HANDLE;
1018 /* find the user's rid */
1019 if (status == 0x0 && (rid = get_lsa_policy_samr_rid(&(q_u->pol))) == 0xffffffff)
1021 status = NT_STATUS_OBJECT_TYPE_MISMATCH;
1024 /* ok! user info levels (there are lots: see MSDEV help), off we go... */
1027 switch (q_u->switch_value)
1030 /* whoops - got this wrong. i think. or don't understand what's happening. */
1034 info = (void*)&id11;
1036 expire.low = 0xffffffff;
1037 expire.high = 0x7fffffff;
1039 make_sam_user_info11(&id11, &expire, "BROOKFIELDS$", 0x03ef, 0x201, 0x0080);
1046 info = (void*)&id21;
1048 status = ldap_get_user_info_21(&id21, rid) ? 0 : NT_STATUS_NO_SUCH_USER;
1050 status = get_user_info_21(&id21, rid) ? 0 : NT_STATUS_NO_SUCH_USER;
1057 status = NT_STATUS_INVALID_INFO_CLASS;
1064 make_samr_r_query_userinfo(&r_u, q_u->switch_value, info, status);
1066 /* store the response in the SMB stream */
1067 samr_io_r_query_userinfo("", &r_u, rdata, 0);
1069 DEBUG(5,("samr_reply_query_userinfo: %d\n", __LINE__));
1073 /*******************************************************************
1074 api_samr_query_userinfo
1075 ********************************************************************/
1076 static void api_samr_query_userinfo( int uid, prs_struct *data, prs_struct *rdata)
1078 SAMR_Q_QUERY_USERINFO q_u;
1080 /* grab the samr unknown 24 */
1081 samr_io_q_query_userinfo("", &q_u, data, 0);
1083 /* construct reply. always indicate success */
1084 samr_reply_query_userinfo(&q_u, rdata);
1088 /*******************************************************************
1089 samr_reply_query_usergroups
1090 ********************************************************************/
1091 static void samr_reply_query_usergroups(SAMR_Q_QUERY_USERGROUPS *q_u,
1094 SAMR_R_QUERY_USERGROUPS r_u;
1095 uint32 status = 0x0;
1097 struct smb_passwd *smb_pass;
1098 DOM_GID gids[LSA_MAX_GROUPS];
1103 DEBUG(5,("samr_query_usergroups: %d\n", __LINE__));
1105 /* find the policy handle. open a policy on it. */
1106 if (status == 0x0 && ((pol_idx = find_lsa_policy_by_hnd(&(q_u->pol))) == -1))
1108 status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
1111 /* find the user's rid */
1112 if (status == 0x0 && (rid = get_lsa_policy_samr_rid(&(q_u->pol))) == 0xffffffff)
1114 status = NT_STATUS_OBJECT_TYPE_MISMATCH;
1120 smb_pass = getsmbpwuid(rid);
1121 unbecome_root(True);
1123 if (smb_pass == NULL)
1125 status = 0xC0000000 | NT_STATUS_NO_SUCH_USER;
1132 get_domain_user_groups(groups, smb_pass->smb_name);
1133 num_groups = make_dom_gids(groups, gids);
1136 /* construct the response. lkclXXXX: gids are not copied! */
1137 make_samr_r_query_usergroups(&r_u, num_groups, gids, status);
1139 /* store the response in the SMB stream */
1140 samr_io_r_query_usergroups("", &r_u, rdata, 0);
1142 DEBUG(5,("samr_query_usergroups: %d\n", __LINE__));
1146 /*******************************************************************
1147 api_samr_query_usergroups
1148 ********************************************************************/
1149 static void api_samr_query_usergroups( int uid, prs_struct *data, prs_struct *rdata)
1151 SAMR_Q_QUERY_USERGROUPS q_u;
1152 /* grab the samr unknown 32 */
1153 samr_io_q_query_usergroups("", &q_u, data, 0);
1155 /* construct reply. */
1156 samr_reply_query_usergroups(&q_u, rdata);
1160 /*******************************************************************
1161 samr_reply_unknown_32
1162 ********************************************************************/
1163 static void samr_reply_unknown_32(SAMR_Q_UNKNOWN_32 *q_u,
1168 SAMR_R_UNKNOWN_32 r_u;
1170 /* set up the SAMR unknown_32 response */
1171 bzero(&(r_u.pol.data), POL_HND_SIZE);
1174 for (i = 4; i < POL_HND_SIZE; i++)
1176 r_u.pol.data[i] = i+1;
1180 make_dom_rid4(&(r_u.rid4), 0x0030, 0, 0);
1181 r_u.status = status;
1183 DEBUG(5,("samr_unknown_32: %d\n", __LINE__));
1185 /* store the response in the SMB stream */
1186 samr_io_r_unknown_32("", &r_u, rdata, 0);
1188 DEBUG(5,("samr_unknown_32: %d\n", __LINE__));
1192 /*******************************************************************
1194 ********************************************************************/
1195 static void api_samr_unknown_32( int uid, prs_struct *data, prs_struct *rdata)
1198 struct smb_passwd *smb_pass;
1201 SAMR_Q_UNKNOWN_32 q_u;
1203 /* grab the samr unknown 32 */
1204 samr_io_q_unknown_32("", &q_u, data, 0);
1206 /* find the machine account: tell the caller if it exists.
1207 lkclXXXX i have *no* idea if this is a problem or not
1208 or even if you are supposed to construct a different
1209 reply if the account already exists...
1212 fstrcpy(mach_acct, unistrn2(q_u.uni_mach_acct.buffer,
1213 q_u.uni_mach_acct.uni_str_len));
1216 smb_pass = getsmbpwnam(mach_acct);
1217 unbecome_root(True);
1219 if (smb_pass != NULL)
1221 /* machine account exists: say so */
1222 status = 0xC0000000 | NT_STATUS_USER_EXISTS;
1226 /* this could cause trouble... */
1230 /* construct reply. */
1231 samr_reply_unknown_32(&q_u, rdata, status);
1235 /*******************************************************************
1237 ********************************************************************/
1238 static void samr_reply_connect(SAMR_Q_CONNECT *q_u,
1242 BOOL pol_open = False;
1244 /* set up the SAMR connect response */
1247 /* get a (unique) handle. open a policy on it. */
1248 if (r_u.status == 0x0 && !(pol_open = open_lsa_policy_hnd(&(r_u.connect_pol))))
1250 r_u.status = 0xC0000000 | NT_STATUS_OBJECT_NAME_NOT_FOUND;
1253 /* associate the domain SID with the (unique) handle. */
1254 if (r_u.status == 0x0 && !set_lsa_policy_samr_pol_status(&(r_u.connect_pol), q_u->unknown_0))
1256 /* oh, whoops. don't know what error message to return, here */
1257 r_u.status = 0xC0000000 | NT_STATUS_OBJECT_NAME_NOT_FOUND;
1260 if (r_u.status != 0 && pol_open)
1262 close_lsa_policy_hnd(&(r_u.connect_pol));
1265 DEBUG(5,("samr_connect: %d\n", __LINE__));
1267 /* store the response in the SMB stream */
1268 samr_io_r_connect("", &r_u, rdata, 0);
1270 DEBUG(5,("samr_connect: %d\n", __LINE__));
1274 /*******************************************************************
1276 ********************************************************************/
1277 static void api_samr_connect( int uid, prs_struct *data, prs_struct *rdata)
1281 /* grab the samr open policy */
1282 samr_io_q_connect("", &q_u, data, 0);
1284 /* construct reply. always indicate success */
1285 samr_reply_connect(&q_u, rdata);
1288 /*******************************************************************
1289 samr_reply_open_alias
1290 ********************************************************************/
1291 static void samr_reply_open_alias(SAMR_Q_OPEN_ALIAS *q_u,
1294 SAMR_R_OPEN_ALIAS r_u;
1295 BOOL pol_open = False;
1297 /* set up the SAMR open_alias response */
1300 /* get a (unique) handle. open a policy on it. */
1301 if (r_u.status == 0x0 && !(pol_open = open_lsa_policy_hnd(&(r_u.pol))))
1303 r_u.status = 0xC0000000 | NT_STATUS_OBJECT_NAME_NOT_FOUND;
1306 /* associate a RID with the (unique) handle. */
1307 if (r_u.status == 0x0 && !set_lsa_policy_samr_rid(&(r_u.pol), q_u->rid_alias))
1309 /* oh, whoops. don't know what error message to return, here */
1310 r_u.status = 0xC0000000 | NT_STATUS_OBJECT_NAME_NOT_FOUND;
1313 if (r_u.status != 0 && pol_open)
1315 close_lsa_policy_hnd(&(r_u.pol));
1318 DEBUG(5,("samr_open_alias: %d\n", __LINE__));
1320 /* store the response in the SMB stream */
1321 samr_io_r_open_alias("", &r_u, rdata, 0);
1323 DEBUG(5,("samr_open_alias: %d\n", __LINE__));
1327 /*******************************************************************
1329 ********************************************************************/
1330 static void api_samr_open_alias( int uid, prs_struct *data, prs_struct *rdata)
1333 SAMR_Q_OPEN_ALIAS q_u;
1335 /* grab the samr open policy */
1336 samr_io_q_open_alias("", &q_u, data, 0);
1338 /* construct reply. always indicate success */
1339 samr_reply_open_alias(&q_u, rdata);
1342 /*******************************************************************
1343 array of \PIPE\samr operations
1344 ********************************************************************/
1345 static struct api_struct api_samr_cmds [] =
1347 { "SAMR_CLOSE_HND" , SAMR_CLOSE_HND , api_samr_close_hnd },
1348 { "SAMR_CONNECT" , SAMR_CONNECT , api_samr_connect },
1349 { "SAMR_ENUM_DOM_USERS" , SAMR_ENUM_DOM_USERS , api_samr_enum_dom_users },
1350 { "SAMR_ENUM_DOM_GROUPS" , SAMR_ENUM_DOM_GROUPS , api_samr_enum_dom_groups },
1351 { "SAMR_ENUM_DOM_ALIASES" , SAMR_ENUM_DOM_ALIASES , api_samr_enum_dom_aliases },
1352 { "SAMR_LOOKUP_IDS" , SAMR_LOOKUP_IDS , api_samr_lookup_ids },
1353 { "SAMR_LOOKUP_NAMES" , SAMR_LOOKUP_NAMES , api_samr_lookup_names },
1354 { "SAMR_OPEN_USER" , SAMR_OPEN_USER , api_samr_open_user },
1355 { "SAMR_QUERY_USERINFO" , SAMR_QUERY_USERINFO , api_samr_query_userinfo },
1356 { "SAMR_QUERY_USERGROUPS" , SAMR_QUERY_USERGROUPS , api_samr_query_usergroups },
1357 { "SAMR_QUERY_DISPINFO" , SAMR_QUERY_DISPINFO , api_samr_query_dispinfo },
1358 { "SAMR_QUERY_ALIASINFO" , SAMR_QUERY_ALIASINFO , api_samr_query_aliasinfo },
1359 { "SAMR_0x32" , 0x32 , api_samr_unknown_32 },
1360 { "SAMR_UNKNOWN_12" , SAMR_UNKNOWN_12 , api_samr_unknown_12 },
1361 { "SAMR_OPEN_ALIAS" , SAMR_OPEN_ALIAS , api_samr_open_alias },
1362 { "SAMR_OPEN_DOMAIN" , SAMR_OPEN_DOMAIN , api_samr_open_domain },
1363 { "SAMR_UNKNOWN_3" , SAMR_UNKNOWN_3 , api_samr_unknown_3 },
1367 /*******************************************************************
1368 receives a samr pipe and responds.
1369 ********************************************************************/
1370 BOOL api_samr_rpc(pipes_struct *p, prs_struct *data)
1372 return api_rpcTNP(p, "api_samr_rpc", api_samr_cmds, data);