2 Unix SMB/Netbios implementation.
5 Copyright (C) Jeremy Allison 1998.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 * UNIX gid and Local or Domain SID resolution. This module resolves
24 * only those entries in the map files, it is *NOT* responsible for
25 * resolving UNIX groups not listed: that is an entirely different
26 * matter, altogether...
33 format of the file is:
35 unixname NT Group name
36 unixname Domain Admins (well-known Domain Group)
37 unixname DOMAIN_NAME\NT Group name
38 unixname OTHER_DOMAIN_NAME\NT Group name
39 unixname DOMAIN_NAME\Domain Admins (well-known Domain Group)
42 if the DOMAIN_NAME\ component is left off, then your own domain is assumed.
50 extern int DEBUGLEVEL;
52 extern fstring global_sam_name;
53 extern DOM_SID global_sam_sid;
54 extern DOM_SID global_sid_S_1_5_20;
56 /*******************************************************************
57 converts UNIX uid to an NT User RID. NOTE: IS SOMETHING SPECIFIC TO SAMBA
58 ********************************************************************/
59 static uid_t pwdb_user_rid_to_uid(uint32 user_rid)
61 return ((user_rid & (~RID_TYPE_USER))- 1000)/RID_MULTIPLIER;
64 /*******************************************************************
65 converts NT Group RID to a UNIX uid. NOTE: IS SOMETHING SPECIFIC TO SAMBA
66 ********************************************************************/
67 static uint32 pwdb_group_rid_to_gid(uint32 group_rid)
69 return ((group_rid & (~RID_TYPE_GROUP))- 1000)/RID_MULTIPLIER;
72 /*******************************************************************
73 converts NT Alias RID to a UNIX uid. NOTE: IS SOMETHING SPECIFIC TO SAMBA
74 ********************************************************************/
75 static uint32 pwdb_alias_rid_to_gid(uint32 alias_rid)
77 return ((alias_rid & (~RID_TYPE_ALIAS))- 1000)/RID_MULTIPLIER;
80 /*******************************************************************
81 converts NT Group RID to a UNIX uid. NOTE: IS SOMETHING SPECIFIC TO SAMBA
82 ********************************************************************/
83 static uint32 pwdb_gid_to_group_rid(uint32 gid)
85 uint32 grp_rid = ((((gid)*RID_MULTIPLIER) + 1000) | RID_TYPE_GROUP);
89 /******************************************************************
90 converts UNIX gid to an NT Alias RID. NOTE: IS SOMETHING SPECIFIC TO SAMBA
91 ********************************************************************/
92 static uint32 pwdb_gid_to_alias_rid(uint32 gid)
94 uint32 alias_rid = ((((gid)*RID_MULTIPLIER) + 1000) | RID_TYPE_ALIAS);
98 /*******************************************************************
99 converts UNIX uid to an NT User RID. NOTE: IS SOMETHING SPECIFIC TO SAMBA
100 ********************************************************************/
101 static uint32 pwdb_uid_to_user_rid(uint32 uid)
103 uint32 user_rid = ((((uid)*RID_MULTIPLIER) + 1000) | RID_TYPE_USER);
107 /******************************************************************
108 converts SID + SID_NAME_USE type to a UNIX id. the Domain SID is,
109 and can only be, our own SID.
110 ********************************************************************/
111 static BOOL pwdb_sam_sid_to_unixid(DOM_SID *sid, uint8 type, uint32 *id)
116 sid_copy(&tmp_sid, sid);
117 sid_split_rid(&tmp_sid, &rid);
118 if (!sid_equal(&global_sam_sid, &tmp_sid))
127 *id = pwdb_user_rid_to_uid(rid);
132 *id = pwdb_alias_rid_to_gid(rid);
135 case SID_NAME_DOM_GRP:
136 case SID_NAME_WKN_GRP:
138 *id = pwdb_group_rid_to_gid(rid);
145 /******************************************************************
146 converts UNIX gid + SID_NAME_USE type to a SID. the Domain SID is,
147 and can only be, our own SID.
148 ********************************************************************/
149 static BOOL pwdb_unixid_to_sam_sid(uint32 id, uint8 type, DOM_SID *sid)
151 sid_copy(sid, &global_sam_sid);
156 sid_append_rid(sid, pwdb_uid_to_user_rid(id));
161 sid_append_rid(sid, pwdb_gid_to_alias_rid(id));
164 case SID_NAME_DOM_GRP:
165 case SID_NAME_WKN_GRP:
167 sid_append_rid(sid, pwdb_gid_to_group_rid(id));
174 /*******************************************************************
175 Decides if a RID is a well known RID.
176 ********************************************************************/
177 static BOOL pwdb_rid_is_well_known(uint32 rid)
182 /*******************************************************************
183 determines a rid's type. NOTE: THIS IS SOMETHING SPECIFIC TO SAMBA
184 ********************************************************************/
185 static uint32 pwdb_rid_type(uint32 rid)
187 /* lkcl i understand that NT attaches an enumeration to a RID
188 * such that it can be identified as either a user, group etc
189 * type: SID_ENUM_TYPE.
191 if (pwdb_rid_is_well_known(rid))
194 * The only well known user RIDs are DOMAIN_USER_RID_ADMIN
195 * and DOMAIN_USER_RID_GUEST.
197 if (rid == DOMAIN_USER_RID_ADMIN || rid == DOMAIN_USER_RID_GUEST)
199 return RID_TYPE_USER;
201 if (DOMAIN_GROUP_RID_ADMINS <= rid && rid <= DOMAIN_GROUP_RID_GUESTS)
203 return RID_TYPE_GROUP;
205 if (BUILTIN_ALIAS_RID_ADMINS <= rid && rid <= BUILTIN_ALIAS_RID_REPLICATOR)
207 return RID_TYPE_ALIAS;
210 return (rid & RID_TYPE_MASK);
213 /*******************************************************************
214 checks whether rid is a user rid. NOTE: THIS IS SOMETHING SPECIFIC TO SAMBA
215 ********************************************************************/
216 BOOL pwdb_rid_is_user(uint32 rid)
218 return pwdb_rid_type(rid) == RID_TYPE_USER;
221 /**************************************************************************
222 Groupname map functionality. The code loads a groupname map file and
223 (currently) loads it into a linked list. This is slow and memory
224 hungry, but can be changed into a more efficient storage format
225 if the demands on it become excessive.
226 ***************************************************************************/
228 typedef struct name_map
235 static ubi_slList groupname_map_list;
236 static ubi_slList aliasname_map_list;
237 static ubi_slList ntusrname_map_list;
239 static void delete_name_entry(name_map_entry *gmep)
241 if (gmep->grp.nt_name)
243 free(gmep->grp.nt_name);
245 if (gmep->grp.nt_domain)
247 free(gmep->grp.nt_domain);
249 if (gmep->grp.unix_name)
251 free(gmep->grp.unix_name);
256 /**************************************************************************
257 Delete all the entries in the name map list.
258 ***************************************************************************/
260 static void delete_map_list(ubi_slList *map_list)
262 name_map_entry *gmep;
264 while ((gmep = (name_map_entry *)ubi_slRemHead(map_list )) != NULL)
266 delete_name_entry(gmep);
271 /**************************************************************************
272 makes a group sid out of a domain sid and a _unix_ gid.
273 ***************************************************************************/
274 static BOOL make_mydomain_sid(DOM_NAME_MAP *grp, DOM_MAP_TYPE type)
276 DEBUG(10,("make_mydomain_sid\n"));
278 if (!map_domain_name_to_sid(&grp->sid, &(grp->nt_domain)))
280 DEBUG(0,("make_mydomain_sid: unknown domain %s\n",
285 if (sid_equal(&grp->sid, &global_sid_S_1_5_20))
288 * only builtin aliases are recognised in S-1-5-20
291 if (!lookup_builtin_alias_name(grp->nt_name, "BUILTIN", &grp->sid, &grp->type))
293 DEBUG(0,("unix group %s mapped to an unrecognised BUILTIN domain name %s\n",
294 grp->unix_name, grp->nt_name));
299 else if (lookup_wk_user_name(grp->nt_name, grp->nt_domain, &grp->sid, &grp->type) == 0x0)
301 if (type != DOM_MAP_USER)
303 DEBUG(0,("well-known NT user %s\%s listed in wrong map file\n",
304 grp->nt_domain, grp->nt_name));
309 else if (lookup_wk_group_name(grp->nt_name, grp->nt_domain, &grp->sid, &grp->type) == 0x0)
311 if (type != DOM_MAP_DOMAIN)
313 DEBUG(0,("well-known NT group %s\%s listed in wrong map file\n",
314 grp->nt_domain, grp->nt_name));
327 grp->type = SID_NAME_USER;
332 grp->type = SID_NAME_DOM_GRP;
337 grp->type = SID_NAME_ALIAS;
342 ret = pwdb_unixid_to_sam_sid(grp->unix_id, grp->type, &grp->sid);
343 sid_to_string(sid_str, &grp->sid);
344 DEBUG(10,("nt name %s gid %d mapped to %s\n",
345 grp->nt_name, grp->unix_id, sid_str));
352 /**************************************************************************
353 makes a group sid out of an nt domain, nt group name or a unix group name.
354 ***************************************************************************/
355 static BOOL unix_name_to_group_info(DOM_NAME_MAP *grp, DOM_MAP_TYPE type)
357 struct group *gptr = NULL;
360 * Attempt to get the unix gid_t for this name.
363 DEBUG(5,("unix_name_to_group_info: unix_name:%s\n", grp->unix_name));
365 gptr = (struct group *)getgrnam(grp->unix_name);
368 DEBUG(0,("unix_name_to_group_info: getgrnam for group %s\
369 failed. Error was %s.\n", grp->unix_name, strerror(errno) ));
373 grp->unix_id = (uint32)gptr->gr_gid;
375 DEBUG(5,("unix_name_to_group_info: unix gid:%d\n", grp->unix_id));
378 * Now map the name to an NT SID+RID.
381 if (grp->nt_domain != NULL && !strequal(grp->nt_domain, global_sam_name))
383 /* Must add client-call lookup code here, to
384 * resolve remote domain's sid and the group's rid,
387 * NOTE: it is _incorrect_ to put code here that assumes
388 * we are responsible for lookups for foriegn domains' RIDs.
390 * for foriegn domains for which we are *NOT* the PDC, all
391 * we can be responsible for is the unix gid_t to which
392 * the foriegn SID+rid maps to, on this _local_ machine.
393 * we *CANNOT* make any short-cuts or assumptions about
394 * RIDs in a foriegn domain.
397 if (!map_domain_name_to_sid(&grp->sid, &(grp->nt_domain)))
399 DEBUG(0,("unix_name_to_group_info: no known sid for %s\n",
405 return make_mydomain_sid(grp, type);
408 static BOOL make_name_entry(name_map_entry **new_ep,
409 char *nt_domain, char *nt_group, char *unix_group,
413 * Create the list entry and add it onto the list.
416 DEBUG(5,("make_name_entry:%s,%s,%s\n", nt_domain, nt_group, unix_group));
418 (*new_ep) = (name_map_entry *)malloc(sizeof(name_map_entry));
419 if ((*new_ep) == NULL)
421 DEBUG(0,("make_name_entry: malloc fail for name_map_entry.\n"));
425 ZERO_STRUCTP(*new_ep);
427 (*new_ep)->grp.nt_name = strdup(nt_group );
428 (*new_ep)->grp.nt_domain = strdup(nt_domain );
429 (*new_ep)->grp.unix_name = strdup(unix_group);
431 if ((*new_ep)->grp.nt_name == NULL ||
432 (*new_ep)->grp.unix_name == NULL)
434 DEBUG(0,("make_name_entry: malloc fail for names in name_map_entry.\n"));
435 delete_name_entry((*new_ep));
440 * look up the group names, make the Group-SID and unix gid
443 if (!unix_name_to_group_info(&(*new_ep)->grp, type))
445 delete_name_entry((*new_ep));
452 /**************************************************************************
453 Load a name map file. Sets last accessed timestamp.
454 ***************************************************************************/
455 static ubi_slList *load_name_map(DOM_MAP_TYPE type)
457 static time_t groupmap_file_last_modified = (time_t)0;
458 static time_t aliasmap_file_last_modified = (time_t)0;
459 static time_t ntusrmap_file_last_modified = (time_t)0;
460 static BOOL initialised_group = False;
461 static BOOL initialised_alias = False;
462 static BOOL initialised_ntusr = False;
463 char *groupname_map_file = lp_groupname_map();
464 char *aliasname_map_file = lp_aliasname_map();
465 char *ntusrname_map_file = lp_ntusrname_map();
471 name_map_entry *new_ep;
473 time_t *file_last_modified = NULL;
474 int *initialised = NULL;
475 char *map_file = NULL;
476 ubi_slList *map_list = NULL;
482 file_last_modified = &groupmap_file_last_modified;
483 initialised = &initialised_group;
484 map_file = groupname_map_file;
485 map_list = &groupname_map_list;
491 file_last_modified = &aliasmap_file_last_modified;
492 initialised = &initialised_alias;
493 map_file = aliasname_map_file;
494 map_list = &aliasname_map_list;
500 file_last_modified = &ntusrmap_file_last_modified;
501 initialised = &initialised_ntusr;
502 map_file = ntusrname_map_file;
503 map_list = &ntusrname_map_list;
511 DEBUG(10,("initialising map %s\n", map_file));
512 ubi_slInitList(map_list);
513 (*initialised) = True;
521 if (sys_stat(map_file, &st) != 0)
523 DEBUG(0, ("load_name_map: Unable to stat file %s. Error was %s\n",
524 map_file, strerror(errno) ));
529 * Check if file has changed.
531 if (st.st_mtime <= (*file_last_modified))
536 (*file_last_modified) = st.st_mtime;
542 fp = fopen(map_file,"r");
545 DEBUG(0,("load_name_map: can't open name map %s. Error was %s\n",
546 map_file, strerror(errno)));
551 * Throw away any previous list.
553 delete_map_list(map_list);
555 DEBUG(4,("load_name_map: Scanning name map %s\n",map_file));
557 while ((s = fgets_slash(buf, sizeof(buf), fp)) != NULL)
565 DEBUG(10,("Read line |%s|\n", s));
567 memset(nt_name, 0, sizeof(nt_name));
569 if (!*s || strchr("#;",*s))
572 if (!next_token(&s,unixname, "\t\n\r=", sizeof(unixname)))
575 if (!next_token(&s,nt_name, "\t\n\r=", sizeof(nt_name)))
578 trim_string(unixname, " ", " ");
579 trim_string(nt_name, " ", " ");
587 DEBUG(5,("unixname = %s, ntname = %s.\n",
590 p = strchr(nt_name, '\\');
594 memset(nt_domain, 0, sizeof(nt_domain));
595 fstrcpy(nt_group, nt_name);
601 fstrcpy(nt_domain, nt_name);
602 fstrcpy(nt_group , p);
605 if (make_name_entry(&new_ep, nt_domain, nt_name, unixname, type))
607 ubi_slAddTail(map_list, (ubi_slNode *)new_ep);
611 DEBUG(10,("load_name_map: Added %ld entries to name map.\n",
612 ubi_slCount(map_list)));
619 static void copy_grp_map_entry(DOM_NAME_MAP *grp, const DOM_NAME_MAP *from)
621 sid_copy(&grp->sid, &from->sid);
622 grp->unix_id = from->unix_id;
623 grp->nt_name = from->nt_name;
624 grp->nt_domain = from->nt_domain;
625 grp->unix_name = from->unix_name;
626 grp->type = from->type;
630 /***********************************************************
632 ************************************************************/
633 static BOOL map_unixname(DOM_MAP_TYPE type,
634 char *unixname, DOM_NAME_MAP *grp_info)
636 name_map_entry *gmep;
637 ubi_slList *map_list;
640 * Initialise and load if not already loaded.
642 map_list = load_name_map(type);
644 for (gmep = (name_map_entry *)ubi_slFirst(map_list);
646 gmep = (name_map_entry *)ubi_slNext(gmep ))
648 if (strequal(gmep->grp.unix_name, unixname))
650 copy_grp_map_entry(grp_info, &gmep->grp);
651 DEBUG(7,("map_unixname: Mapping unix group %s to nt group %s.\n",
652 gmep->grp.unix_name, gmep->grp.nt_name ));
662 /***********************************************************
664 ************************************************************/
665 static BOOL map_ntname(DOM_MAP_TYPE type, char *ntname, char *ntdomain,
666 DOM_NAME_MAP *grp_info)
668 name_map_entry *gmep;
669 ubi_slList *map_list;
672 * Initialise and load if not already loaded.
674 map_list = load_name_map(type);
676 for (gmep = (name_map_entry *)ubi_slFirst(map_list);
678 gmep = (name_map_entry *)ubi_slNext(gmep ))
680 if (strequal(gmep->grp.nt_name , ntname) &&
681 strequal(gmep->grp.nt_domain, ntdomain))
683 copy_grp_map_entry(grp_info, &gmep->grp);
684 DEBUG(7,("map_ntname: Mapping unix group %s to nt group %s.\n",
685 gmep->grp.unix_name, gmep->grp.nt_name ));
694 /***********************************************************
696 ************************************************************/
697 static BOOL map_sid(DOM_MAP_TYPE type,
698 DOM_SID *psid, DOM_NAME_MAP *grp_info)
700 name_map_entry *gmep;
701 ubi_slList *map_list;
704 * Initialise and load if not already loaded.
706 map_list = load_name_map(type);
708 for (gmep = (name_map_entry *)ubi_slFirst(map_list);
710 gmep = (name_map_entry *)ubi_slNext(gmep ))
712 if (sid_equal(&gmep->grp.sid, psid))
714 copy_grp_map_entry(grp_info, &gmep->grp);
715 DEBUG(7,("map_sid: Mapping unix group %s to nt group %s.\n",
716 gmep->grp.unix_name, gmep->grp.nt_name ));
724 /***********************************************************
726 ************************************************************/
727 static BOOL map_unixid(DOM_MAP_TYPE type, uint32 unix_id, DOM_NAME_MAP *grp_info)
729 name_map_entry *gmep;
730 ubi_slList *map_list;
733 * Initialise and load if not already loaded.
735 map_list = load_name_map(type);
737 for (gmep = (name_map_entry *)ubi_slFirst(map_list);
739 gmep = (name_map_entry *)ubi_slNext(gmep ))
742 sid_to_string(sid_str, &gmep->grp.sid);
743 DEBUG(10,("map_unixid: enum entry unix group %s %d nt %s %s\n",
744 gmep->grp.unix_name, gmep->grp.unix_id, gmep->grp.nt_name, sid_str));
745 if (gmep->grp.unix_id == unix_id)
747 copy_grp_map_entry(grp_info, &gmep->grp);
748 DEBUG(7,("map_unixid: Mapping unix group %s to nt group %s type %d\n",
749 gmep->grp.unix_name, gmep->grp.nt_name, gmep->grp.type));
757 /***********************************************************
759 * Call four functions to resolve unix group ids and either
760 * local group SIDs or domain group SIDs listed in the local group
761 * or domain group map files.
763 * Note that it is *NOT* the responsibility of these functions to
764 * resolve entries that are not in the map files.
766 * Any SID can be in the map files (i.e from any Domain).
768 ***********************************************************/
772 /***********************************************************
773 Lookup a UNIX Group entry by name.
774 ************************************************************/
775 BOOL map_unix_group_name(char *group_name, DOM_NAME_MAP *grp_info)
777 return map_unixname(DOM_MAP_DOMAIN, group_name, grp_info);
780 /***********************************************************
781 Lookup a UNIX Alias entry by name.
782 ************************************************************/
783 BOOL map_unix_alias_name(char *alias_name, DOM_NAME_MAP *grp_info)
785 return map_unixname(DOM_MAP_LOCAL, alias_name, grp_info);
788 /***********************************************************
789 Lookup an Alias name entry
790 ************************************************************/
791 BOOL map_nt_alias_name(char *ntalias_name, char *nt_domain, DOM_NAME_MAP *grp_info)
793 return map_ntname(DOM_MAP_LOCAL, ntalias_name, nt_domain, grp_info);
796 /***********************************************************
798 ************************************************************/
799 BOOL map_nt_group_name(char *ntgroup_name, char *nt_domain, DOM_NAME_MAP *grp_info)
801 return map_ntname(DOM_MAP_DOMAIN, ntgroup_name, nt_domain, grp_info);
806 /***********************************************************
807 Lookup a Username entry by name.
808 ************************************************************/
809 static BOOL map_nt_username(char *nt_name, char *nt_domain, DOM_NAME_MAP *grp_info)
811 return map_ntname(DOM_MAP_USER, nt_name, nt_domain, grp_info);
814 /***********************************************************
815 Lookup a Username entry by SID.
816 ************************************************************/
817 static BOOL map_username_sid(DOM_SID *sid, DOM_NAME_MAP *grp_info)
819 return map_sid(DOM_MAP_USER, sid, grp_info);
822 /***********************************************************
823 Lookup a Username SID entry by uid.
824 ************************************************************/
825 static BOOL map_username_uid(uid_t gid, DOM_NAME_MAP *grp_info)
827 return map_unixid(DOM_MAP_USER, (uint32)gid, grp_info);
830 /***********************************************************
831 Lookup an Alias SID entry by name.
832 ************************************************************/
833 BOOL map_alias_sid(DOM_SID *psid, DOM_NAME_MAP *grp_info)
835 return map_sid(DOM_MAP_LOCAL, psid, grp_info);
838 /***********************************************************
839 Lookup a Group entry by sid.
840 ************************************************************/
841 BOOL map_group_sid(DOM_SID *psid, DOM_NAME_MAP *grp_info)
843 return map_sid(DOM_MAP_DOMAIN, psid, grp_info);
846 /***********************************************************
847 Lookup an Alias SID entry by gid_t.
848 ************************************************************/
849 static BOOL map_alias_gid(gid_t gid, DOM_NAME_MAP *grp_info)
851 return map_unixid(DOM_MAP_LOCAL, (uint32)gid, grp_info);
854 /***********************************************************
855 Lookup a Group SID entry by gid_t.
856 ************************************************************/
857 static BOOL map_group_gid( gid_t gid, DOM_NAME_MAP *grp_info)
859 return map_unixid(DOM_MAP_DOMAIN, (uint32)gid, grp_info);
863 /************************************************************************
864 Routine to look up User details by UNIX name
865 *************************************************************************/
866 BOOL lookupsmbpwnam(const char *unix_usr_name, DOM_NAME_MAP *grp)
869 DEBUG(10,("lookupsmbpwnam: unix user name %s\n", unix_usr_name));
870 if (nametouid(unix_usr_name, &uid))
872 return lookupsmbpwuid(uid, grp);
881 * used by lookup functions below
884 static fstring nt_name;
885 static fstring unix_name;
886 static fstring nt_domain;
888 /*************************************************************************
889 looks up a uid, returns User Information.
890 *************************************************************************/
891 BOOL lookupsmbpwuid(uid_t uid, DOM_NAME_MAP *gmep)
893 DEBUG(10,("lookupsmbpwuid: unix uid %d\n", uid));
894 if (map_username_uid(uid, gmep))
898 if (lp_server_role() != ROLE_DOMAIN_NONE)
900 gmep->nt_name = nt_name;
901 gmep->unix_name = unix_name;
903 gmep->unix_id = (uint32)uid;
906 * here we should do a LsaLookupNames() call
907 * to check the status of the name with the PDC.
908 * if the PDC know nothing of the name, it's ours.
911 if (lp_server_role() == ROLE_DOMAIN_MEMBER)
914 do_lsa_lookup_names(global_myworkgroup, gmep->nt_name, &gmep->sid...);
918 gmep->type = SID_NAME_USER;
919 fstrcpy(gmep->nt_name, uidtoname(uid));
920 fstrcpy(gmep->unix_name, gmep->nt_name);
921 gmep->nt_domain = global_sam_name;
922 pwdb_unixid_to_sam_sid(gmep->unix_id, gmep->type, &gmep->sid);
932 /*************************************************************************
933 looks up by NT name, returns User Information.
934 *************************************************************************/
935 BOOL lookupsmbpwntnam(char *fullntname, DOM_NAME_MAP *gmep)
937 DEBUG(10,("lookupsmbpwntnam: nt user name %s\n", fullntname));
939 if (!split_domain_name(fullntname, nt_name, nt_domain))
944 if (map_nt_username(nt_name, nt_domain, gmep))
948 if (lp_server_role() != ROLE_DOMAIN_NONE)
951 gmep->nt_name = nt_name;
952 gmep->unix_name = unix_name;
953 gmep->nt_domain = nt_domain;
956 * here we should do a LsaLookupNames() call
957 * to check the status of the name with the PDC.
958 * if the PDC know nothing of the name, it's ours.
961 if (lp_server_role() == ROLE_DOMAIN_MEMBER)
964 do_lsa_lookup_names(global_myworkgroup, gmep->nt_name, gmep->nt_domain, &gmep->sid...);
968 gmep->type = SID_NAME_USER;
969 fstrcpy(gmep->unix_name, gmep->nt_name);
970 if (!nametouid(gmep->unix_name, &uid))
974 gmep->unix_id = (uint32)uid;
975 if (!pwdb_unixid_to_sam_sid(gmep->unix_id, gmep->type, &gmep->sid))
988 /*************************************************************************
989 looks up by RID, returns User Information.
990 *************************************************************************/
991 BOOL lookupsmbpwsid(DOM_SID *sid, DOM_NAME_MAP *gmep)
994 sid_to_string(sid_str, sid);
995 DEBUG(10,("lookupsmbpwsid: nt sid %s\n", sid_str));
997 if (map_username_sid(sid, gmep))
1001 if (lp_server_role() != ROLE_DOMAIN_NONE)
1003 gmep->nt_name = nt_name;
1004 gmep->unix_name = unix_name;
1005 gmep->nt_domain = nt_domain;
1008 * here we should do a LsaLookupNames() call
1009 * to check the status of the name with the PDC.
1010 * if the PDC know nothing of the name, it's ours.
1013 if (lp_server_role() == ROLE_DOMAIN_MEMBER)
1016 do_lsa_lookup_sids(global_myworkgroup, gmep->sid, gmep->nt_name, gmep->nt_domain...);
1020 gmep->type = SID_NAME_USER;
1021 sid_copy(&gmep->sid, sid);
1022 if (!pwdb_sam_sid_to_unixid(&gmep->sid, gmep->type, &gmep->unix_id))
1026 fstrcpy(gmep->nt_name, uidtoname((uid_t)gmep->unix_id));
1027 fstrcpy(gmep->unix_name, gmep->nt_name);
1028 gmep->nt_domain = global_sam_name;
1038 /************************************************************************
1039 Routine to look up group / alias / well-known group RID by UNIX name
1040 *************************************************************************/
1041 BOOL lookupsmbgrpnam(const char *unix_grp_name, DOM_NAME_MAP *grp)
1044 DEBUG(10,("lookupsmbgrpnam: unix user group %s\n", unix_grp_name));
1045 if (nametogid(unix_grp_name, &gid))
1047 return lookupsmbgrpgid(gid, grp);
1055 /*************************************************************************
1056 looks up a SID, returns name map entry
1057 *************************************************************************/
1058 BOOL lookupsmbgrpsid(DOM_SID *sid, DOM_NAME_MAP *gmep)
1061 sid_to_string(sid_str, sid);
1062 DEBUG(10,("lookupsmbgrpsid: nt sid %s\n", sid_str));
1064 if (map_alias_sid(sid, gmep))
1068 if (map_group_sid(sid, gmep))
1072 if (lp_server_role() != ROLE_DOMAIN_NONE)
1074 gmep->nt_name = nt_name;
1075 gmep->unix_name = unix_name;
1076 gmep->nt_domain = nt_domain;
1079 * here we should do a LsaLookupNames() call
1080 * to check the status of the name with the PDC.
1081 * if the PDC know nothing of the name, it's ours.
1084 if (lp_server_role() == ROLE_DOMAIN_MEMBER)
1087 do_lsa_lookup_sids(global_myworkgroup, gmep->sid, gmep->nt_name, gmep->nt_domain...);
1091 /* name is not explicitly mapped
1092 * with map files or the PDC
1093 * so we are responsible for it...
1096 if (lp_server_role() == ROLE_DOMAIN_MEMBER)
1098 /* ... as a LOCAL group. */
1099 gmep->type = SID_NAME_ALIAS;
1103 /* ... as a DOMAIN group. */
1104 gmep->type = SID_NAME_DOM_GRP;
1107 sid_copy(&gmep->sid, sid);
1108 if (!pwdb_sam_sid_to_unixid(&gmep->sid, gmep->type, &gmep->unix_id))
1112 fstrcpy(gmep->nt_name, gidtoname((gid_t)gmep->unix_id));
1113 fstrcpy(gmep->unix_name, gmep->nt_name);
1114 gmep->nt_domain = global_sam_name;
1123 /*************************************************************************
1124 looks up a gid, returns RID and type local, domain or well-known domain group
1125 *************************************************************************/
1126 BOOL lookupsmbgrpgid(gid_t gid, DOM_NAME_MAP *gmep)
1128 DEBUG(10,("lookupsmbgrpgid: unix gid %d\n", (int)gid));
1129 if (map_alias_gid(gid, gmep))
1133 if (map_group_gid(gid, gmep))
1137 if (lp_server_role() != ROLE_DOMAIN_NONE)
1139 gmep->nt_name = nt_name;
1140 gmep->unix_name = unix_name;
1142 gmep->unix_id = (uint32)gid;
1145 * here we should do a LsaLookupNames() call
1146 * to check the status of the name with the PDC.
1147 * if the PDC know nothing of the name, it's ours.
1150 if (lp_server_role() == ROLE_DOMAIN_MEMBER)
1153 do_lsa_lookup_names(global_myworkgroup, gmep->nt_name, &gmep->sid...);
1160 /* name is not explicitly mapped
1161 * with map files or the PDC
1162 * so we are responsible for it...
1165 if (lp_server_role() == ROLE_DOMAIN_MEMBER)
1167 /* ... as a LOCAL group. */
1168 gmep->type = SID_NAME_ALIAS;
1172 /* ... as a DOMAIN group. */
1173 gmep->type = SID_NAME_DOM_GRP;
1175 fstrcpy(gmep->nt_name, gidtoname(gid));
1176 fstrcpy(gmep->unix_name, gmep->nt_name);
1177 gmep->nt_domain = global_sam_name;
1178 pwdb_unixid_to_sam_sid(gmep->unix_id, gmep->type, &gmep->sid);