added rid and sid_name_use to DOMAIN_GRP_MEMBER, for use in group member
[samba.git] / source3 / groupdb / groupunix.c
index 0f850f347c3e8d74f1d57f5a7f9097369eb1dbce..154e23338d9ce9dd10aa79aae41ff810d5494609 100644 (file)
@@ -25,7 +25,6 @@ extern int DEBUGLEVEL;
 
 
 extern DOM_SID global_sam_sid;
-extern fstring global_sam_name;
 
 /***************************************************************
  Start to enumerate the grppasswd list. Returns a void pointer
@@ -65,48 +64,6 @@ static BOOL setgrpunixpwpos(void *vp, SMB_BIG_UINT tok)
        return False;
 }
 
-/*************************************************************************
- maps a unix group to a domain sid and an nt group name.  
-*************************************************************************/
-static void map_unix_grp_to_nt_grp(char *unix_name,
-       struct group *unix_grp, char *nt_name, DOM_SID *sid)
-{
-       BOOL found = False;
-       uint32 rid;
-
-       if (isdigit(unix_name[0]))
-       {
-               unix_grp->gr_gid = get_number(unix_name);
-               unix_grp->gr_name = unix_name;
-               found = map_group_gid(unix_grp->gr_gid, sid, nt_name, NULL);
-       }
-       else
-       {
-               unix_grp->gr_name = unix_name;
-               found = map_unix_group_name(unix_grp->gr_name, sid, nt_name, NULL);
-       }
-
-       if (found)
-       {
-               /*
-                * find the NT name represented by this UNIX gid.
-                * then, only accept NT groups that are in our domain
-                */
-
-               sid_split_rid(sid, &rid);
-       }
-       else
-       {
-               /*
-                * assume that the UNIX group is an NT group with
-                * the same name.  convert gid to a group rid.
-                */
-               
-               fstrcpy(nt_name, unix_grp->gr_name);
-               sid_copy(sid, &global_sam_sid);
-       }
-}
-
 /*************************************************************************
  Routine to return the next entry in the smbdomaingroup list.
  *************************************************************************/
@@ -115,7 +72,6 @@ BOOL get_unixgroup_members(struct group *grp,
 {
        int i;
        char *unix_name;
-       fstring nt_name;
 
        if (num_mem == NULL || members == NULL)
        {
@@ -127,15 +83,30 @@ BOOL get_unixgroup_members(struct group *grp,
 
        for (i = 0; (unix_name = grp->gr_mem[i]) != NULL; i++)
        {
-               DOM_SID sid;
-               struct group unix_grp;
+               DOM_NAME_MAP gmep;
+               DOMAIN_GRP_MEMBER *mem;
+               uint32 rid;
 
-               map_unix_grp_to_nt_grp(unix_name, &unix_grp, nt_name, &sid);
+               if (!lookupsmbpwnam (unix_name, &gmep) &&
+                   !lookupsmbgrpnam(unix_name, &gmep))
+               {
+                       continue;
+               }
 
-               if (!sid_equal(&sid, &global_sam_sid))
+               if (gmep.type != SID_NAME_DOM_GRP &&
+                   gmep.type != SID_NAME_USER &&
+                   gmep.type != SID_NAME_WKN_GRP)
+               {
+                       DEBUG(0,("group database: name %s is not in a Domain Group\n",
+                                 unix_name));
+                       continue;
+               }
+                       
+               sid_split_rid(&gmep.sid, &rid);
+               if (!sid_equal(&global_sam_sid, &gmep.sid))
                {
-                       DEBUG(0,("group database: could not resolve name %s in domain %s\n",
-                                 unix_name, global_sam_name));
+                       DEBUG(0,("group database: could not resolve name %s (wrong Domain SID)\n",
+                                 unix_name));
                        continue;
                }
 
@@ -145,15 +116,27 @@ BOOL get_unixgroup_members(struct group *grp,
                        return False;
                }
 
-               fstrcpy((*members)[(*num_mem)].name, nt_name);
-               (*members)[(*num_mem)].attr = 0x07;
+               mem = &(*members)[(*num_mem)];
                (*num_mem)++;
+
+               fstrcpy(mem->name, gmep.nt_name);
+               mem->attr    = 0x07;
+               mem->sid_use = gmep.type;
+               mem->rid     = rid;
        }
        return True;
 }
 
 /*************************************************************************
  Routine to return the next entry in the domain group list.
+
+ if we are not a PDC or BDC, then we do NOT support Domain groups, only
+ aliases.  try running MUSRMGR.EXE or running USRMGR.EXE selected on a
+ workstation, you will find that no Domain groups are listed: only aliases.
+
+ so, as a PDC or BDC, all unix groups not explicitly mapped using
+ map_group_gid() are treated as Domain groups.
+
  *************************************************************************/
 static DOMAIN_GRP *getgrpunixpwent(void *vp, DOMAIN_GRP_MEMBER **mem, int *num_mem)
 {
@@ -181,34 +164,29 @@ static DOMAIN_GRP *getgrpunixpwent(void *vp, DOMAIN_GRP_MEMBER **mem, int *num_m
        /* cycle through unix groups */
        while ((unix_grp = getgrent()) != NULL)
        {
-               DOM_SID sid;
+               DOM_NAME_MAP gmep;
                DEBUG(10,("getgrpunixpwent: enum unix group entry %s\n",
                           unix_grp->gr_name));
-               if (map_group_gid(unix_grp->gr_gid, &sid, gp_buf.name, NULL))
+                       
+               if (!lookupsmbgrpgid(unix_grp->gr_gid, &gmep))
                {
-                       /*
-                        * find the NT name represented by this UNIX gid.
-                        * then, only accept NT groups that are in our domain
-                        */
-
-                       sid_split_rid(&sid, &gp_buf.rid);
-                       if (sid_equal(&sid, &global_sam_sid))
-                       {
-                               break; /* hooray. */
-                       }
+                       continue;
                }
-               else
+
+               if (gmep.type != SID_NAME_DOM_GRP &&
+                   gmep.type != SID_NAME_WKN_GRP)
                {
-                       /*
-                        * assume that the UNIX group is an NT group with
-                        * the same name.  convert gid to a group rid.
-                        */
-                       
-                       fstrcpy(gp_buf.name, unix_grp->gr_name);
-                       gp_buf.rid = pwdb_gid_to_group_rid(unix_grp->gr_gid);
+                       continue;
+               }
 
-                       break;
+               sid_split_rid(&gmep.sid, &gp_buf.rid);
+               if (!sid_equal(&gmep.sid, &global_sam_sid))
+               {
+                       continue;
                }
+
+               fstrcpy(gp_buf.name, gmep.nt_name);
+               break;
        }
 
        if (unix_grp == NULL)
@@ -268,7 +246,7 @@ static struct groupdb_ops unix_ops =
        getgrpunixpwpos,
        setgrpunixpwpos,
 
-       iterate_getgroupnam,          /* In groupdb.c */
+       iterate_getgroupntnam,          /* In groupdb.c */
        iterate_getgroupgid,          /* In groupdb.c */
        iterate_getgrouprid,          /* In groupdb.c */
        getgrpunixpwent,