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 smb_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 = getsmbpwent(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->smb_userid;
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, ("get_smbpwd_entries: idx: %d user %s, uid %d, acb %x",
81 (*num_entries), pwd->smb_name, pwd->smb_userid, 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 smb_passwd *smb_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 smb_pass = get_sampwd_entry(user_name, 0);
632 if (smb_pass == NULL)
634 status = 0xC0000000 | NT_STATUS_NO_SUCH_USER;
639 /* lkclXXXX SHOULD use name_to_rid() here! */
640 rid[i] = smb_pass->smb_userid;
646 rid[0] = BUILTIN_ALIAS_RID_USERS;
648 make_samr_r_lookup_ids(&r_u, num_rids, rid, status);
650 /* store the response in the SMB stream */
651 samr_io_r_lookup_ids("", &r_u, rdata, 0);
653 DEBUG(5,("samr_lookup_ids: %d\n", __LINE__));
657 /*******************************************************************
659 ********************************************************************/
660 static void api_samr_lookup_ids( int uid, prs_struct *data, prs_struct *rdata)
662 SAMR_Q_LOOKUP_IDS q_u;
664 /* grab the samr 0x10 */
665 samr_io_q_lookup_ids("", &q_u, data, 0);
667 /* construct reply. always indicate success */
668 samr_reply_lookup_ids(&q_u, rdata);
671 /*******************************************************************
672 samr_reply_lookup_names
673 ********************************************************************/
674 static void samr_reply_lookup_names(SAMR_Q_LOOKUP_NAMES *q_u,
677 uint32 rid[MAX_SAM_ENTRIES];
680 int num_rids = q_u->num_rids1;
682 SAMR_R_LOOKUP_NAMES r_u;
684 DEBUG(5,("samr_lookup_names: %d\n", __LINE__));
686 if (num_rids > MAX_SAM_ENTRIES)
688 num_rids = MAX_SAM_ENTRIES;
689 DEBUG(5,("samr_lookup_names: truncating entries to %d\n", num_rids));
692 SMB_ASSERT_ARRAY(q_u->uni_user_name, num_rids);
694 for (i = 0; i < num_rids && status == 0; i++)
698 status = 0xC0000000 | NT_STATUS_NONE_MAPPED;
700 fstrcpy(name, unistrn2(q_u->uni_user_name[i].buffer, q_u->uni_user_name[i].uni_str_len));
702 status = (status != 0x0) ? lookup_user_rid (name, &(rid[i])) : status;
703 status = (status != 0x0) ? lookup_group_rid(name, &(rid[i])) : status;
704 status = (status != 0x0) ? lookup_alias_rid(name, &(rid[i])) : status;
707 make_samr_r_lookup_names(&r_u, num_rids, rid, status);
709 /* store the response in the SMB stream */
710 samr_io_r_lookup_names("", &r_u, rdata, 0);
712 DEBUG(5,("samr_lookup_names: %d\n", __LINE__));
716 /*******************************************************************
717 api_samr_lookup_names
718 ********************************************************************/
719 static void api_samr_lookup_names( int uid, prs_struct *data, prs_struct *rdata)
721 SAMR_Q_LOOKUP_NAMES q_u;
723 /* grab the samr lookup names */
724 samr_io_q_lookup_names("", &q_u, data, 0);
726 /* construct reply. always indicate success */
727 samr_reply_lookup_names(&q_u, rdata);
731 /*******************************************************************
732 samr_reply_unknown_12
733 ********************************************************************/
734 static void samr_reply_unknown_12(SAMR_Q_UNKNOWN_12 *q_u,
737 fstring group_names[MAX_SAM_ENTRIES];
738 uint32 group_attrs[MAX_SAM_ENTRIES];
740 int num_gids = q_u->num_gids1;
743 SAMR_R_UNKNOWN_12 r_u;
745 DEBUG(5,("samr_unknown_12: %d\n", __LINE__));
747 /* find the policy handle. open a policy on it. */
748 if (status == 0x0 && ((pol_idx = find_lsa_policy_by_hnd(&(q_u->pol))) == -1))
750 status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
756 if (num_gids > MAX_SAM_ENTRIES)
758 num_gids = MAX_SAM_ENTRIES;
759 DEBUG(5,("samr_unknown_12: truncating entries to %d\n", num_gids));
762 for (i = 0; i < num_gids && status == 0; i++)
764 fstrcpy(group_names[i], "dummy group");
765 group_attrs[i] = 0x2;
769 make_samr_r_unknown_12(&r_u, num_gids, group_names, group_attrs, status);
771 /* store the response in the SMB stream */
772 samr_io_r_unknown_12("", &r_u, rdata, 0);
774 DEBUG(5,("samr_unknown_12: %d\n", __LINE__));
778 /*******************************************************************
780 ********************************************************************/
781 static void api_samr_unknown_12( int uid, prs_struct *data, prs_struct *rdata)
783 SAMR_Q_UNKNOWN_12 q_u;
785 /* grab the samr lookup names */
786 samr_io_q_unknown_12("", &q_u, data, 0);
788 /* construct reply. always indicate success */
789 samr_reply_unknown_12(&q_u, rdata);
793 /*******************************************************************
795 ********************************************************************/
796 static void samr_reply_open_user(SAMR_Q_OPEN_USER *q_u,
800 SAMR_R_OPEN_USER r_u;
801 struct smb_passwd *smb_pass;
803 BOOL pol_open = False;
805 /* set up the SAMR open_user response */
806 bzero(r_u.user_pol.data, POL_HND_SIZE);
810 /* find the policy handle. open a policy on it. */
811 if (r_u.status == 0x0 && ((pol_idx = find_lsa_policy_by_hnd(&(q_u->domain_pol))) == -1))
813 r_u.status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
816 /* get a (unique) handle. open a policy on it. */
817 if (r_u.status == 0x0 && !(pol_open = open_lsa_policy_hnd(&(r_u.user_pol))))
819 r_u.status = 0xC0000000 | NT_STATUS_OBJECT_NAME_NOT_FOUND;
823 smb_pass = getsmbpwuid(q_u->user_rid);
826 /* check that the RID exists in our domain. */
827 if (r_u.status == 0x0 && smb_pass == NULL)
829 r_u.status = 0xC0000000 | NT_STATUS_NO_SUCH_USER;
832 /* associate the RID with the (unique) handle. */
833 if (r_u.status == 0x0 && !set_lsa_policy_samr_rid(&(r_u.user_pol), q_u->user_rid))
835 /* oh, whoops. don't know what error message to return, here */
836 r_u.status = 0xC0000000 | NT_STATUS_OBJECT_NAME_NOT_FOUND;
839 if (r_u.status != 0 && pol_open)
841 close_lsa_policy_hnd(&(r_u.user_pol));
844 DEBUG(5,("samr_open_user: %d\n", __LINE__));
846 /* store the response in the SMB stream */
847 samr_io_r_open_user("", &r_u, rdata, 0);
849 DEBUG(5,("samr_open_user: %d\n", __LINE__));
853 /*******************************************************************
855 ********************************************************************/
856 static void api_samr_open_user( int uid, prs_struct *data, prs_struct *rdata)
858 SAMR_Q_OPEN_USER q_u;
860 /* grab the samr unknown 22 */
861 samr_io_q_open_user("", &q_u, data, 0);
863 /* construct reply. always indicate success */
864 samr_reply_open_user(&q_u, rdata, 0x0);
868 /*************************************************************************
870 *************************************************************************/
871 static BOOL get_user_info_21(SAM_USER_INFO_21 *id21, uint32 user_rid)
874 struct sam_passwd *sam_pass;
878 if (!pdb_rid_is_user(user_rid))
884 sam_pass = getsam21pwrid(user_rid);
887 if (sam_pass == NULL)
892 DEBUG(3,("User:[%s]\n", sam_pass->smb_name));
894 dummy_time.low = 0xffffffff;
895 dummy_time.high = 0x7fffffff;
897 DEBUG(0,("get_user_info_21 - TODO: convert unix times to NTTIMEs\n"));
899 /* create a LOGON_HRS structure */
900 hrs.len = sam_pass->hours_len;
901 SMB_ASSERT_ARRAY(hrs.hours, hrs.len);
902 for (i = 0; i < hrs.len; i++)
904 hrs.hours[i] = sam_pass->hours[i];
907 make_sam_user_info21(id21,
909 &dummy_time, /* logon_time */
910 &dummy_time, /* logoff_time */
911 &dummy_time, /* kickoff_time */
912 &dummy_time, /* pass_last_set_time */
913 &dummy_time, /* pass_can_change_time */
914 &dummy_time, /* pass_must_change_time */
916 sam_pass->smb_name, /* user_name */
917 sam_pass->full_name, /* full_name */
918 sam_pass->home_dir, /* home_dir */
919 sam_pass->dir_drive, /* dir_drive */
920 sam_pass->logon_script, /* logon_script */
921 sam_pass->profile_path, /* profile_path */
922 sam_pass->acct_desc, /* description */
923 sam_pass->workstations, /* workstations user can log in from */
924 sam_pass->unknown_str, /* don't know, yet */
925 sam_pass->munged_dial, /* dialin info. contains dialin path and tel no */
927 sam_pass->user_rid, /* RID user_id */
928 sam_pass->group_rid, /* RID group_id */
931 sam_pass->unknown_3, /* unknown_3 */
932 sam_pass->logon_divs, /* divisions per week */
933 &hrs, /* logon hours */
935 sam_pass->unknown_6);
940 /*******************************************************************
941 samr_reply_query_userinfo
942 ********************************************************************/
943 static void samr_reply_query_userinfo(SAMR_Q_QUERY_USERINFO *q_u,
946 SAMR_R_QUERY_USERINFO r_u;
948 SAM_USER_INFO_11 id11;
950 SAM_USER_INFO_21 id21;
957 DEBUG(5,("samr_reply_query_userinfo: %d\n", __LINE__));
959 /* search for the handle */
960 if (status == 0x0 && (obj_idx = find_lsa_policy_by_hnd(&(q_u->pol))) == -1)
962 status = NT_STATUS_INVALID_HANDLE;
965 /* find the user's rid */
966 if (status == 0x0 && (rid = get_lsa_policy_samr_rid(&(q_u->pol))) == 0xffffffff)
968 status = NT_STATUS_OBJECT_TYPE_MISMATCH;
971 /* ok! user info levels (there are lots: see MSDEV help), off we go... */
974 switch (q_u->switch_value)
977 /* whoops - got this wrong. i think. or don't understand what's happening. */
983 expire.low = 0xffffffff;
984 expire.high = 0x7fffffff;
986 make_sam_user_info11(&id11, &expire, "BROOKFIELDS$", 0x03ef, 0x201, 0x0080);
994 status = get_user_info_21(&id21, rid) ? 0 : NT_STATUS_NO_SUCH_USER;
1000 status = NT_STATUS_INVALID_INFO_CLASS;
1007 make_samr_r_query_userinfo(&r_u, q_u->switch_value, info, status);
1009 /* store the response in the SMB stream */
1010 samr_io_r_query_userinfo("", &r_u, rdata, 0);
1012 DEBUG(5,("samr_reply_query_userinfo: %d\n", __LINE__));
1016 /*******************************************************************
1017 api_samr_query_userinfo
1018 ********************************************************************/
1019 static void api_samr_query_userinfo( int uid, prs_struct *data, prs_struct *rdata)
1021 SAMR_Q_QUERY_USERINFO q_u;
1023 /* grab the samr unknown 24 */
1024 samr_io_q_query_userinfo("", &q_u, data, 0);
1026 /* construct reply. always indicate success */
1027 samr_reply_query_userinfo(&q_u, rdata);
1031 /*******************************************************************
1032 samr_reply_query_usergroups
1033 ********************************************************************/
1034 static void samr_reply_query_usergroups(SAMR_Q_QUERY_USERGROUPS *q_u,
1037 SAMR_R_QUERY_USERGROUPS r_u;
1038 uint32 status = 0x0;
1040 struct smb_passwd *smb_pass;
1041 DOM_GID *gids = NULL;
1046 DEBUG(5,("samr_query_usergroups: %d\n", __LINE__));
1048 /* find the policy handle. open a policy on it. */
1049 if (status == 0x0 && ((pol_idx = find_lsa_policy_by_hnd(&(q_u->pol))) == -1))
1051 status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
1054 /* find the user's rid */
1055 if (status == 0x0 && (rid = get_lsa_policy_samr_rid(&(q_u->pol))) == 0xffffffff)
1057 status = NT_STATUS_OBJECT_TYPE_MISMATCH;
1063 smb_pass = getsmbpwuid(rid);
1064 unbecome_root(True);
1066 if (smb_pass == NULL)
1068 status = 0xC0000000 | NT_STATUS_NO_SUCH_USER;
1075 get_domain_user_groups(groups, smb_pass->smb_name);
1077 num_groups = make_dom_gids(groups, &gids);
1080 /* construct the response. lkclXXXX: gids are not copied! */
1081 make_samr_r_query_usergroups(&r_u, num_groups, gids, status);
1083 /* store the response in the SMB stream */
1084 samr_io_r_query_usergroups("", &r_u, rdata, 0);
1088 DEBUG(5,("samr_query_usergroups: %d\n", __LINE__));
1092 /*******************************************************************
1093 api_samr_query_usergroups
1094 ********************************************************************/
1095 static void api_samr_query_usergroups( int uid, prs_struct *data, prs_struct *rdata)
1097 SAMR_Q_QUERY_USERGROUPS q_u;
1098 /* grab the samr unknown 32 */
1099 samr_io_q_query_usergroups("", &q_u, data, 0);
1101 /* construct reply. */
1102 samr_reply_query_usergroups(&q_u, rdata);
1106 /*******************************************************************
1107 samr_reply_unknown_32
1108 ********************************************************************/
1109 static void samr_reply_unknown_32(SAMR_Q_UNKNOWN_32 *q_u,
1114 SAMR_R_UNKNOWN_32 r_u;
1116 /* set up the SAMR unknown_32 response */
1117 bzero(r_u.pol.data, POL_HND_SIZE);
1120 for (i = 4; i < POL_HND_SIZE; i++)
1122 r_u.pol.data[i] = i+1;
1126 make_dom_rid4(&(r_u.rid4), 0x0030, 0, 0);
1127 r_u.status = status;
1129 DEBUG(5,("samr_unknown_32: %d\n", __LINE__));
1131 /* store the response in the SMB stream */
1132 samr_io_r_unknown_32("", &r_u, rdata, 0);
1134 DEBUG(5,("samr_unknown_32: %d\n", __LINE__));
1138 /*******************************************************************
1140 ********************************************************************/
1141 static void api_samr_unknown_32( int uid, prs_struct *data, prs_struct *rdata)
1144 struct smb_passwd *smb_pass;
1147 SAMR_Q_UNKNOWN_32 q_u;
1149 /* grab the samr unknown 32 */
1150 samr_io_q_unknown_32("", &q_u, data, 0);
1152 /* find the machine account: tell the caller if it exists.
1153 lkclXXXX i have *no* idea if this is a problem or not
1154 or even if you are supposed to construct a different
1155 reply if the account already exists...
1158 fstrcpy(mach_acct, unistrn2(q_u.uni_mach_acct.buffer,
1159 q_u.uni_mach_acct.uni_str_len));
1162 smb_pass = getsmbpwnam(mach_acct);
1163 unbecome_root(True);
1165 if (smb_pass != NULL)
1167 /* machine account exists: say so */
1168 status = 0xC0000000 | NT_STATUS_USER_EXISTS;
1172 /* this could cause trouble... */
1176 /* construct reply. */
1177 samr_reply_unknown_32(&q_u, rdata, status);
1181 /*******************************************************************
1183 ********************************************************************/
1184 static void samr_reply_connect(SAMR_Q_CONNECT *q_u,
1188 BOOL pol_open = False;
1190 /* set up the SAMR connect response */
1193 /* get a (unique) handle. open a policy on it. */
1194 if (r_u.status == 0x0 && !(pol_open = open_lsa_policy_hnd(&(r_u.connect_pol))))
1196 r_u.status = 0xC0000000 | NT_STATUS_OBJECT_NAME_NOT_FOUND;
1199 /* associate the domain SID with the (unique) handle. */
1200 if (r_u.status == 0x0 && !set_lsa_policy_samr_pol_status(&(r_u.connect_pol), q_u->unknown_0))
1202 /* oh, whoops. don't know what error message to return, here */
1203 r_u.status = 0xC0000000 | NT_STATUS_OBJECT_NAME_NOT_FOUND;
1206 if (r_u.status != 0 && pol_open)
1208 close_lsa_policy_hnd(&(r_u.connect_pol));
1211 DEBUG(5,("samr_connect: %d\n", __LINE__));
1213 /* store the response in the SMB stream */
1214 samr_io_r_connect("", &r_u, rdata, 0);
1216 DEBUG(5,("samr_connect: %d\n", __LINE__));
1220 /*******************************************************************
1222 ********************************************************************/
1223 static void api_samr_connect( int uid, prs_struct *data, prs_struct *rdata)
1227 /* grab the samr open policy */
1228 samr_io_q_connect("", &q_u, data, 0);
1230 /* construct reply. always indicate success */
1231 samr_reply_connect(&q_u, rdata);
1234 /*******************************************************************
1235 samr_reply_open_alias
1236 ********************************************************************/
1237 static void samr_reply_open_alias(SAMR_Q_OPEN_ALIAS *q_u,
1240 SAMR_R_OPEN_ALIAS r_u;
1241 BOOL pol_open = False;
1243 /* set up the SAMR open_alias response */
1246 /* get a (unique) handle. open a policy on it. */
1247 if (r_u.status == 0x0 && !(pol_open = open_lsa_policy_hnd(&(r_u.pol))))
1249 r_u.status = 0xC0000000 | NT_STATUS_OBJECT_NAME_NOT_FOUND;
1252 /* associate a RID with the (unique) handle. */
1253 if (r_u.status == 0x0 && !set_lsa_policy_samr_rid(&(r_u.pol), q_u->rid_alias))
1255 /* oh, whoops. don't know what error message to return, here */
1256 r_u.status = 0xC0000000 | NT_STATUS_OBJECT_NAME_NOT_FOUND;
1259 if (r_u.status != 0 && pol_open)
1261 close_lsa_policy_hnd(&(r_u.pol));
1264 DEBUG(5,("samr_open_alias: %d\n", __LINE__));
1266 /* store the response in the SMB stream */
1267 samr_io_r_open_alias("", &r_u, rdata, 0);
1269 DEBUG(5,("samr_open_alias: %d\n", __LINE__));
1273 /*******************************************************************
1275 ********************************************************************/
1276 static void api_samr_open_alias( int uid, prs_struct *data, prs_struct *rdata)
1279 SAMR_Q_OPEN_ALIAS q_u;
1281 /* grab the samr open policy */
1282 samr_io_q_open_alias("", &q_u, data, 0);
1284 /* construct reply. always indicate success */
1285 samr_reply_open_alias(&q_u, rdata);
1288 /*******************************************************************
1289 array of \PIPE\samr operations
1290 ********************************************************************/
1291 static struct api_struct api_samr_cmds [] =
1293 { "SAMR_CLOSE_HND" , SAMR_CLOSE_HND , api_samr_close_hnd },
1294 { "SAMR_CONNECT" , SAMR_CONNECT , api_samr_connect },
1295 { "SAMR_ENUM_DOM_USERS" , SAMR_ENUM_DOM_USERS , api_samr_enum_dom_users },
1296 { "SAMR_ENUM_DOM_GROUPS" , SAMR_ENUM_DOM_GROUPS , api_samr_enum_dom_groups },
1297 { "SAMR_ENUM_DOM_ALIASES" , SAMR_ENUM_DOM_ALIASES , api_samr_enum_dom_aliases },
1298 { "SAMR_LOOKUP_IDS" , SAMR_LOOKUP_IDS , api_samr_lookup_ids },
1299 { "SAMR_LOOKUP_NAMES" , SAMR_LOOKUP_NAMES , api_samr_lookup_names },
1300 { "SAMR_OPEN_USER" , SAMR_OPEN_USER , api_samr_open_user },
1301 { "SAMR_QUERY_USERINFO" , SAMR_QUERY_USERINFO , api_samr_query_userinfo },
1302 { "SAMR_QUERY_USERGROUPS" , SAMR_QUERY_USERGROUPS , api_samr_query_usergroups },
1303 { "SAMR_QUERY_DISPINFO" , SAMR_QUERY_DISPINFO , api_samr_query_dispinfo },
1304 { "SAMR_QUERY_ALIASINFO" , SAMR_QUERY_ALIASINFO , api_samr_query_aliasinfo },
1305 { "SAMR_0x32" , 0x32 , api_samr_unknown_32 },
1306 { "SAMR_UNKNOWN_12" , SAMR_UNKNOWN_12 , api_samr_unknown_12 },
1307 { "SAMR_OPEN_ALIAS" , SAMR_OPEN_ALIAS , api_samr_open_alias },
1308 { "SAMR_OPEN_DOMAIN" , SAMR_OPEN_DOMAIN , api_samr_open_domain },
1309 { "SAMR_UNKNOWN_3" , SAMR_UNKNOWN_3 , api_samr_unknown_3 },
1313 /*******************************************************************
1314 receives a samr pipe and responds.
1315 ********************************************************************/
1316 BOOL api_samr_rpc(pipes_struct *p, prs_struct *data)
1318 return api_rpcTNP(p, "api_samr_rpc", api_samr_cmds, data);