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_sampwd_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 = startsampwent(False);
57 DEBUG(0, ("get_sampwd_entries: Unable to open SMB password file.\n"));
61 while (((pwd = getsampwent(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_sampwd_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 fstrcpy(user_sid, lp_domain_sid());
235 slprintf(user_rid, sizeof(user_rid) - 1, "-%x", rid);
236 fstrcat(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_sampwd_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__));
467 got_pwds = get_sampwd_entries(pass, &total_entries, &num_entries, MAX_SAM_ENTRIES, 0);
470 switch (q_u->switch_level)
475 /* query disp info is for users */
477 make_sam_info_1(&info1, ACB_NORMAL,
478 q_u->start_idx, num_entries, pass);
480 ctr.sam.info1 = &info1;
486 /* query disp info is for servers */
488 make_sam_info_2(&info2, ACB_WSTRUST,
489 q_u->start_idx, num_entries, pass);
491 ctr.sam.info2 = &info2;
497 if (r_e.status == 0 && got_pwds)
499 make_samr_r_query_dispinfo(&r_e, switch_level, &ctr, r_e.status);
502 /* store the response in the SMB stream */
503 samr_io_r_query_dispinfo("", &r_e, rdata, 0);
505 DEBUG(5,("samr_query_dispinfo: %d\n", __LINE__));
509 /*******************************************************************
510 api_samr_query_dispinfo
511 ********************************************************************/
512 static void api_samr_query_dispinfo( int uid, prs_struct *data, prs_struct *rdata)
514 SAMR_Q_QUERY_DISPINFO q_e;
516 /* grab the samr open */
517 samr_io_q_query_dispinfo("", &q_e, data, 0);
519 /* construct reply. */
520 samr_reply_query_dispinfo(&q_e, rdata);
524 /*******************************************************************
525 samr_reply_query_aliasinfo
526 ********************************************************************/
527 static void samr_reply_query_aliasinfo(SAMR_Q_QUERY_ALIASINFO *q_u,
530 SAMR_R_QUERY_ALIASINFO r_e;
537 /* find the policy handle. open a policy on it. */
538 if (r_e.status == 0x0 && ((pol_idx = find_lsa_policy_by_hnd(&(q_u->pol))) == -1))
540 r_e.status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
543 DEBUG(5,("samr_reply_query_aliasinfo: %d\n", __LINE__));
545 if (r_e.status == 0x0)
547 if (q_u->switch_level != 3)
549 r_e.status = NT_STATUS_INVALID_INFO_CLASS;
553 if (r_e.status == 0x0)
558 make_samr_r_query_aliasinfo(&r_e, q_u->switch_level,
559 "<account description>",
562 /* store the response in the SMB stream */
563 samr_io_r_query_aliasinfo("", &r_e, rdata, 0);
565 DEBUG(5,("samr_query_aliasinfo: %d\n", __LINE__));
569 /*******************************************************************
570 api_samr_query_aliasinfo
571 ********************************************************************/
572 static void api_samr_query_aliasinfo( int uid, prs_struct *data, prs_struct *rdata)
574 SAMR_Q_QUERY_ALIASINFO q_e;
576 /* grab the samr open */
577 samr_io_q_query_aliasinfo("", &q_e, data, 0);
579 /* construct reply. */
580 samr_reply_query_aliasinfo(&q_e, rdata);
584 /*******************************************************************
585 samr_reply_lookup_ids
586 ********************************************************************/
587 static void samr_reply_lookup_ids(SAMR_Q_LOOKUP_IDS *q_u,
590 uint32 rid[MAX_SAM_ENTRIES];
592 int num_rids = q_u->num_sids1;
594 SAMR_R_LOOKUP_IDS r_u;
596 DEBUG(5,("samr_lookup_ids: %d\n", __LINE__));
598 if (num_rids > MAX_SAM_ENTRIES)
600 num_rids = MAX_SAM_ENTRIES;
601 DEBUG(5,("samr_lookup_ids: truncating entries to %d\n", num_rids));
606 for (i = 0; i < num_rids && status == 0; i++)
608 struct smb_passwd *smb_pass;
611 fstrcpy(user_name, unistrn2(q_u->uni_user_name[i].buffer,
612 q_u->uni_user_name[i].uni_str_len));
614 /* find the user account */
616 smb_pass = get_sampwd_entry(user_name, 0);
619 if (smb_pass == NULL)
621 status = 0xC0000000 | NT_STATUS_NO_SUCH_USER;
626 /* lkclXXXX SHOULD use name_to_rid() here! */
627 rid[i] = smb_pass->smb_userid;
633 rid[0] = DOMAIN_ALIAS_RID_USERS;
635 make_samr_r_lookup_ids(&r_u, num_rids, rid, status);
637 /* store the response in the SMB stream */
638 samr_io_r_lookup_ids("", &r_u, rdata, 0);
640 DEBUG(5,("samr_lookup_ids: %d\n", __LINE__));
644 /*******************************************************************
646 ********************************************************************/
647 static void api_samr_lookup_ids( int uid, prs_struct *data, prs_struct *rdata)
649 SAMR_Q_LOOKUP_IDS q_u;
651 /* grab the samr 0x10 */
652 samr_io_q_lookup_ids("", &q_u, data, 0);
654 /* construct reply. always indicate success */
655 samr_reply_lookup_ids(&q_u, rdata);
658 /*******************************************************************
659 samr_reply_lookup_names
660 ********************************************************************/
661 static void samr_reply_lookup_names(SAMR_Q_LOOKUP_NAMES *q_u,
664 uint32 rid[MAX_SAM_ENTRIES];
667 int num_rids = q_u->num_rids1;
669 SAMR_R_LOOKUP_NAMES r_u;
671 DEBUG(5,("samr_lookup_names: %d\n", __LINE__));
673 if (num_rids > MAX_SAM_ENTRIES)
675 num_rids = MAX_SAM_ENTRIES;
676 DEBUG(5,("samr_lookup_names: truncating entries to %d\n", num_rids));
679 for (i = 0; i < num_rids && status == 0; i++)
683 status = 0xC0000000 | NT_STATUS_NONE_MAPPED;
685 fstrcpy(name, unistrn2(q_u->uni_user_name[i].buffer, q_u->uni_user_name[i].uni_str_len));
687 status = (status != 0x0) ? lookup_user_rid (name, &(rid[i])) : status;
688 status = (status != 0x0) ? lookup_group_rid(name, &(rid[i])) : status;
689 status = (status != 0x0) ? lookup_alias_rid(name, &(rid[i])) : status;
692 make_samr_r_lookup_names(&r_u, num_rids, rid, status);
694 /* store the response in the SMB stream */
695 samr_io_r_lookup_names("", &r_u, rdata, 0);
697 DEBUG(5,("samr_lookup_names: %d\n", __LINE__));
701 /*******************************************************************
702 api_samr_lookup_names
703 ********************************************************************/
704 static void api_samr_lookup_names( int uid, prs_struct *data, prs_struct *rdata)
706 SAMR_Q_LOOKUP_NAMES q_u;
708 /* grab the samr lookup names */
709 samr_io_q_lookup_names("", &q_u, data, 0);
711 /* construct reply. always indicate success */
712 samr_reply_lookup_names(&q_u, rdata);
716 /*******************************************************************
717 samr_reply_unknown_12
718 ********************************************************************/
719 static void samr_reply_unknown_12(SAMR_Q_UNKNOWN_12 *q_u,
722 fstring group_names[MAX_SAM_ENTRIES];
723 uint32 group_attrs[MAX_SAM_ENTRIES];
725 int num_gids = q_u->num_gids1;
728 SAMR_R_UNKNOWN_12 r_u;
730 DEBUG(5,("samr_unknown_12: %d\n", __LINE__));
732 /* find the policy handle. open a policy on it. */
733 if (status == 0x0 && ((pol_idx = find_lsa_policy_by_hnd(&(q_u->pol))) == -1))
735 status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
741 if (num_gids > MAX_SAM_ENTRIES)
743 num_gids = MAX_SAM_ENTRIES;
744 DEBUG(5,("samr_unknown_12: truncating entries to %d\n", num_gids));
747 for (i = 0; i < num_gids && status == 0; i++)
749 fstrcpy(group_names[i], "dummy group");
750 group_attrs[i] = 0x2;
754 make_samr_r_unknown_12(&r_u, num_gids, group_names, group_attrs, status);
756 /* store the response in the SMB stream */
757 samr_io_r_unknown_12("", &r_u, rdata, 0);
759 DEBUG(5,("samr_unknown_12: %d\n", __LINE__));
763 /*******************************************************************
765 ********************************************************************/
766 static void api_samr_unknown_12( int uid, prs_struct *data, prs_struct *rdata)
768 SAMR_Q_UNKNOWN_12 q_u;
770 /* grab the samr lookup names */
771 samr_io_q_unknown_12("", &q_u, data, 0);
773 /* construct reply. always indicate success */
774 samr_reply_unknown_12(&q_u, rdata);
778 /*******************************************************************
780 ********************************************************************/
781 static void samr_reply_open_user(SAMR_Q_OPEN_USER *q_u,
785 SAMR_R_OPEN_USER r_u;
786 struct smb_passwd *smb_pass;
788 BOOL pol_open = False;
790 /* set up the SAMR open_user response */
791 bzero(&(r_u.user_pol.data), POL_HND_SIZE);
795 /* find the policy handle. open a policy on it. */
796 if (r_u.status == 0x0 && ((pol_idx = find_lsa_policy_by_hnd(&(q_u->domain_pol))) == -1))
798 r_u.status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
801 /* get a (unique) handle. open a policy on it. */
802 if (r_u.status == 0x0 && !(pol_open = open_lsa_policy_hnd(&(r_u.user_pol))))
804 r_u.status = 0xC0000000 | NT_STATUS_OBJECT_NAME_NOT_FOUND;
808 smb_pass = getsampwuid(q_u->user_rid);
811 /* check that the RID exists in our domain. */
812 if (r_u.status == 0x0 && smb_pass == NULL)
814 r_u.status = 0xC0000000 | NT_STATUS_NO_SUCH_USER;
817 /* associate the RID with the (unique) handle. */
818 if (r_u.status == 0x0 && !set_lsa_policy_samr_rid(&(r_u.user_pol), q_u->user_rid))
820 /* oh, whoops. don't know what error message to return, here */
821 r_u.status = 0xC0000000 | NT_STATUS_OBJECT_NAME_NOT_FOUND;
824 if (r_u.status != 0 && pol_open)
826 close_lsa_policy_hnd(&(r_u.user_pol));
829 DEBUG(5,("samr_open_user: %d\n", __LINE__));
831 /* store the response in the SMB stream */
832 samr_io_r_open_user("", &r_u, rdata, 0);
834 DEBUG(5,("samr_open_user: %d\n", __LINE__));
838 /*******************************************************************
840 ********************************************************************/
841 static void api_samr_open_user( int uid, prs_struct *data, prs_struct *rdata)
843 SAMR_Q_OPEN_USER q_u;
845 /* grab the samr unknown 22 */
846 samr_io_q_open_user("", &q_u, data, 0);
848 /* construct reply. always indicate success */
849 samr_reply_open_user(&q_u, rdata, 0x0);
853 /*************************************************************************
855 *************************************************************************/
856 static BOOL get_user_info_21(SAM_USER_INFO_21 *id21, uint32 rid)
859 struct sam_passwd *sam_pass;
865 sam_pass = getsam21pwrid(rid);
868 if (sam_pass == NULL)
873 DEBUG(3,("User:[%s]\n", sam_pass->smb_name));
875 dummy_time.low = 0xffffffff;
876 dummy_time.high = 0x7fffffff;
878 DEBUG(0,("get_user_info_21 - TODO: convert unix times to NTTIMEs\n"));
880 /* create a LOGON_HRS structure */
881 hrs.len = sam_pass->hours_len;
882 for (i = 0; i < hrs.len; i++)
884 hrs.hours[i] = sam_pass->hours[i];
887 make_sam_user_info21(id21,
889 &dummy_time, /* logon_time */
890 &dummy_time, /* logoff_time */
891 &dummy_time, /* kickoff_time */
892 &dummy_time, /* pass_last_set_time */
893 &dummy_time, /* pass_can_change_time */
894 &dummy_time, /* pass_must_change_time */
896 sam_pass->smb_name, /* user_name */
897 sam_pass->full_name, /* full_name */
898 sam_pass->home_dir, /* home_dir */
899 sam_pass->dir_drive, /* dir_drive */
900 sam_pass->logon_script, /* logon_script */
901 sam_pass->profile_path, /* profile_path */
902 sam_pass->acct_desc, /* description */
903 sam_pass->workstations, /* workstations user can log in from */
904 sam_pass->unknown_str, /* don't know, yet */
905 sam_pass->munged_dial, /* dialin info. contains dialin path and tel no */
907 sam_pass->user_rid, /* RID user_id */
908 sam_pass->group_rid, /* RID group_id */
911 sam_pass->unknown_3, /* unknown_3 */
912 sam_pass->logon_divs, /* divisions per week */
913 &hrs, /* logon hours */
915 sam_pass->unknown_6);
920 /*******************************************************************
921 samr_reply_query_userinfo
922 ********************************************************************/
923 static void samr_reply_query_userinfo(SAMR_Q_QUERY_USERINFO *q_u,
926 SAMR_R_QUERY_USERINFO r_u;
928 SAM_USER_INFO_11 id11;
930 SAM_USER_INFO_21 id21;
937 DEBUG(5,("samr_reply_query_userinfo: %d\n", __LINE__));
939 /* search for the handle */
940 if (status == 0x0 && (obj_idx = find_lsa_policy_by_hnd(&(q_u->pol))) == -1)
942 status = NT_STATUS_INVALID_HANDLE;
945 /* find the user's rid */
946 if (status == 0x0 && (rid = get_lsa_policy_samr_rid(&(q_u->pol))) == 0xffffffff)
948 status = NT_STATUS_OBJECT_TYPE_MISMATCH;
951 /* ok! user info levels (there are lots: see MSDEV help), off we go... */
954 switch (q_u->switch_value)
957 /* whoops - got this wrong. i think. or don't understand what's happening. */
963 expire.low = 0xffffffff;
964 expire.high = 0x7fffffff;
966 make_sam_user_info11(&id11, &expire, "BROOKFIELDS$", 0x03ef, 0x201, 0x0080);
974 status = get_user_info_21(&id21, rid) ? 0 : NT_STATUS_NO_SUCH_USER;
980 status = NT_STATUS_INVALID_INFO_CLASS;
987 make_samr_r_query_userinfo(&r_u, q_u->switch_value, info, status);
989 /* store the response in the SMB stream */
990 samr_io_r_query_userinfo("", &r_u, rdata, 0);
992 DEBUG(5,("samr_reply_query_userinfo: %d\n", __LINE__));
996 /*******************************************************************
997 api_samr_query_userinfo
998 ********************************************************************/
999 static void api_samr_query_userinfo( int uid, prs_struct *data, prs_struct *rdata)
1001 SAMR_Q_QUERY_USERINFO q_u;
1003 /* grab the samr unknown 24 */
1004 samr_io_q_query_userinfo("", &q_u, data, 0);
1006 /* construct reply. always indicate success */
1007 samr_reply_query_userinfo(&q_u, rdata);
1011 /*******************************************************************
1012 samr_reply_query_usergroups
1013 ********************************************************************/
1014 static void samr_reply_query_usergroups(SAMR_Q_QUERY_USERGROUPS *q_u,
1017 SAMR_R_QUERY_USERGROUPS r_u;
1018 uint32 status = 0x0;
1020 struct smb_passwd *smb_pass;
1021 DOM_GID gids[LSA_MAX_GROUPS];
1026 DEBUG(5,("samr_query_usergroups: %d\n", __LINE__));
1028 /* find the policy handle. open a policy on it. */
1029 if (status == 0x0 && ((pol_idx = find_lsa_policy_by_hnd(&(q_u->pol))) == -1))
1031 status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
1034 /* find the user's rid */
1035 if (status == 0x0 && (rid = get_lsa_policy_samr_rid(&(q_u->pol))) == 0xffffffff)
1037 status = NT_STATUS_OBJECT_TYPE_MISMATCH;
1043 smb_pass = getsampwuid(rid);
1044 unbecome_root(True);
1046 if (smb_pass == NULL)
1048 status = 0xC0000000 | NT_STATUS_NO_SUCH_USER;
1055 get_domain_user_groups(groups, smb_pass->smb_name);
1056 num_groups = make_dom_gids(groups, gids);
1059 /* construct the response. lkclXXXX: gids are not copied! */
1060 make_samr_r_query_usergroups(&r_u, num_groups, gids, status);
1062 /* store the response in the SMB stream */
1063 samr_io_r_query_usergroups("", &r_u, rdata, 0);
1065 DEBUG(5,("samr_query_usergroups: %d\n", __LINE__));
1069 /*******************************************************************
1070 api_samr_query_usergroups
1071 ********************************************************************/
1072 static void api_samr_query_usergroups( int uid, prs_struct *data, prs_struct *rdata)
1074 SAMR_Q_QUERY_USERGROUPS q_u;
1075 /* grab the samr unknown 32 */
1076 samr_io_q_query_usergroups("", &q_u, data, 0);
1078 /* construct reply. */
1079 samr_reply_query_usergroups(&q_u, rdata);
1083 /*******************************************************************
1084 samr_reply_unknown_32
1085 ********************************************************************/
1086 static void samr_reply_unknown_32(SAMR_Q_UNKNOWN_32 *q_u,
1091 SAMR_R_UNKNOWN_32 r_u;
1093 /* set up the SAMR unknown_32 response */
1094 bzero(&(r_u.pol.data), POL_HND_SIZE);
1097 for (i = 4; i < POL_HND_SIZE; i++)
1099 r_u.pol.data[i] = i+1;
1103 make_dom_rid4(&(r_u.rid4), 0x0030, 0, 0);
1104 r_u.status = status;
1106 DEBUG(5,("samr_unknown_32: %d\n", __LINE__));
1108 /* store the response in the SMB stream */
1109 samr_io_r_unknown_32("", &r_u, rdata, 0);
1111 DEBUG(5,("samr_unknown_32: %d\n", __LINE__));
1115 /*******************************************************************
1117 ********************************************************************/
1118 static void api_samr_unknown_32( int uid, prs_struct *data, prs_struct *rdata)
1121 struct smb_passwd *smb_pass;
1124 SAMR_Q_UNKNOWN_32 q_u;
1126 /* grab the samr unknown 32 */
1127 samr_io_q_unknown_32("", &q_u, data, 0);
1129 /* find the machine account: tell the caller if it exists.
1130 lkclXXXX i have *no* idea if this is a problem or not
1131 or even if you are supposed to construct a different
1132 reply if the account already exists...
1135 fstrcpy(mach_acct, unistrn2(q_u.uni_mach_acct.buffer,
1136 q_u.uni_mach_acct.uni_str_len));
1139 smb_pass = getsampwnam(mach_acct);
1140 unbecome_root(True);
1142 if (smb_pass != NULL)
1144 /* machine account exists: say so */
1145 status = 0xC0000000 | NT_STATUS_USER_EXISTS;
1149 /* this could cause trouble... */
1153 /* construct reply. */
1154 samr_reply_unknown_32(&q_u, rdata, status);
1158 /*******************************************************************
1160 ********************************************************************/
1161 static void samr_reply_connect(SAMR_Q_CONNECT *q_u,
1165 BOOL pol_open = False;
1167 /* set up the SAMR connect response */
1170 /* get a (unique) handle. open a policy on it. */
1171 if (r_u.status == 0x0 && !(pol_open = open_lsa_policy_hnd(&(r_u.connect_pol))))
1173 r_u.status = 0xC0000000 | NT_STATUS_OBJECT_NAME_NOT_FOUND;
1176 /* associate the domain SID with the (unique) handle. */
1177 if (r_u.status == 0x0 && !set_lsa_policy_samr_pol_status(&(r_u.connect_pol), q_u->unknown_0))
1179 /* oh, whoops. don't know what error message to return, here */
1180 r_u.status = 0xC0000000 | NT_STATUS_OBJECT_NAME_NOT_FOUND;
1183 if (r_u.status != 0 && pol_open)
1185 close_lsa_policy_hnd(&(r_u.connect_pol));
1188 DEBUG(5,("samr_connect: %d\n", __LINE__));
1190 /* store the response in the SMB stream */
1191 samr_io_r_connect("", &r_u, rdata, 0);
1193 DEBUG(5,("samr_connect: %d\n", __LINE__));
1197 /*******************************************************************
1199 ********************************************************************/
1200 static void api_samr_connect( int uid, prs_struct *data, prs_struct *rdata)
1204 /* grab the samr open policy */
1205 samr_io_q_connect("", &q_u, data, 0);
1207 /* construct reply. always indicate success */
1208 samr_reply_connect(&q_u, rdata);
1211 /*******************************************************************
1212 samr_reply_open_alias
1213 ********************************************************************/
1214 static void samr_reply_open_alias(SAMR_Q_OPEN_ALIAS *q_u,
1217 SAMR_R_OPEN_ALIAS r_u;
1218 BOOL pol_open = False;
1220 /* set up the SAMR open_alias response */
1223 /* get a (unique) handle. open a policy on it. */
1224 if (r_u.status == 0x0 && !(pol_open = open_lsa_policy_hnd(&(r_u.pol))))
1226 r_u.status = 0xC0000000 | NT_STATUS_OBJECT_NAME_NOT_FOUND;
1229 /* associate a RID with the (unique) handle. */
1230 if (r_u.status == 0x0 && !set_lsa_policy_samr_rid(&(r_u.pol), q_u->rid_alias))
1232 /* oh, whoops. don't know what error message to return, here */
1233 r_u.status = 0xC0000000 | NT_STATUS_OBJECT_NAME_NOT_FOUND;
1236 if (r_u.status != 0 && pol_open)
1238 close_lsa_policy_hnd(&(r_u.pol));
1241 DEBUG(5,("samr_open_alias: %d\n", __LINE__));
1243 /* store the response in the SMB stream */
1244 samr_io_r_open_alias("", &r_u, rdata, 0);
1246 DEBUG(5,("samr_open_alias: %d\n", __LINE__));
1250 /*******************************************************************
1252 ********************************************************************/
1253 static void api_samr_open_alias( int uid, prs_struct *data, prs_struct *rdata)
1256 SAMR_Q_OPEN_ALIAS q_u;
1258 /* grab the samr open policy */
1259 samr_io_q_open_alias("", &q_u, data, 0);
1261 /* construct reply. always indicate success */
1262 samr_reply_open_alias(&q_u, rdata);
1265 /*******************************************************************
1266 array of \PIPE\samr operations
1267 ********************************************************************/
1268 static struct api_struct api_samr_cmds [] =
1270 { "SAMR_CLOSE_HND" , SAMR_CLOSE_HND , api_samr_close_hnd },
1271 { "SAMR_CONNECT" , SAMR_CONNECT , api_samr_connect },
1272 { "SAMR_ENUM_DOM_USERS" , SAMR_ENUM_DOM_USERS , api_samr_enum_dom_users },
1273 { "SAMR_ENUM_DOM_GROUPS" , SAMR_ENUM_DOM_GROUPS , api_samr_enum_dom_groups },
1274 { "SAMR_ENUM_DOM_ALIASES" , SAMR_ENUM_DOM_ALIASES , api_samr_enum_dom_aliases },
1275 { "SAMR_LOOKUP_IDS" , SAMR_LOOKUP_IDS , api_samr_lookup_ids },
1276 { "SAMR_LOOKUP_NAMES" , SAMR_LOOKUP_NAMES , api_samr_lookup_names },
1277 { "SAMR_OPEN_USER" , SAMR_OPEN_USER , api_samr_open_user },
1278 { "SAMR_QUERY_USERINFO" , SAMR_QUERY_USERINFO , api_samr_query_userinfo },
1279 { "SAMR_QUERY_USERGROUPS" , SAMR_QUERY_USERGROUPS , api_samr_query_usergroups },
1280 { "SAMR_QUERY_DISPINFO" , SAMR_QUERY_DISPINFO , api_samr_query_dispinfo },
1281 { "SAMR_QUERY_ALIASINFO" , SAMR_QUERY_ALIASINFO , api_samr_query_aliasinfo },
1282 { "SAMR_0x32" , 0x32 , api_samr_unknown_32 },
1283 { "SAMR_UNKNOWN_12" , SAMR_UNKNOWN_12 , api_samr_unknown_12 },
1284 { "SAMR_OPEN_ALIAS" , SAMR_OPEN_ALIAS , api_samr_open_alias },
1285 { "SAMR_OPEN_DOMAIN" , SAMR_OPEN_DOMAIN , api_samr_open_domain },
1286 { "SAMR_UNKNOWN_3" , SAMR_UNKNOWN_3 , api_samr_unknown_3 },
1290 /*******************************************************************
1291 receives a samr pipe and responds.
1292 ********************************************************************/
1293 BOOL api_samr_rpc(pipes_struct *p, prs_struct *data)
1295 return api_rpcTNP(p, "api_samr_rpc", api_samr_cmds, data);