s3:passdb: factor pdb_sid_to_id_unix_users_and_groups() out of pdb_default_sid_to_id()
authorMichael Adam <obnox@samba.org>
Mon, 3 Dec 2012 00:34:32 +0000 (01:34 +0100)
committerStefan Metzmacher <metze@samba.org>
Mon, 3 Dec 2012 07:48:30 +0000 (08:48 +0100)
The special treatment of the "Unix User" and "Unix Group" pseudo domains
can be reused.

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
source3/include/passdb.h
source3/passdb/pdb_interface.c

index 5202bd3af4fc8799fcd0612cb2349b8cceecf682..908631de315ffdb0a8cc84dda4a631558ccf2965 100644 (file)
@@ -908,6 +908,9 @@ NTSTATUS pdb_set_secret(const char *secret_name,
                        DATA_BLOB *secret_old,
                        struct security_descriptor *sd);
 NTSTATUS pdb_delete_secret(const char *secret_name);
+bool pdb_sid_to_id_unix_users_and_groups(const struct dom_sid *sid,
+                                        struct unixid *id);
+
 
 /* The following definitions come from passdb/pdb_util.c  */
 
index 1527b39b7fb29308d4bfc004c40d1d84839f72a7..436e7743027fae308d36b2ae077f10e4464be241 100644 (file)
@@ -1421,6 +1421,32 @@ static bool pdb_default_gid_to_sid(struct pdb_methods *methods, gid_t gid,
        return true;
 }
 
+/**
+ * The "Unix User" and "Unix Group" domains have a special
+ * id mapping that is a rid-algorithm with range starting at 0.
+ */
+_PRIVATE_ bool pdb_sid_to_id_unix_users_and_groups(const struct dom_sid *sid,
+                                                  struct unixid *id)
+{
+       uint32_t rid;
+
+       id->id = -1;
+
+       if (sid_peek_check_rid(&global_sid_Unix_Users, sid, &rid)) {
+               id->id = rid;
+               id->type = ID_TYPE_UID;
+               return true;
+       }
+
+       if (sid_peek_check_rid(&global_sid_Unix_Groups, sid, &rid)) {
+               id->id = rid;
+               id->type = ID_TYPE_GID;
+               return true;
+       }
+
+       return false;
+}
+
 static bool pdb_default_sid_to_id(struct pdb_methods *methods,
                                  const struct dom_sid *sid,
                                  struct unixid *id)
@@ -1467,22 +1493,12 @@ static bool pdb_default_sid_to_id(struct pdb_methods *methods,
                goto done;
        }
 
-       /* check for "Unix User" */
-
-       if ( sid_peek_check_rid(&global_sid_Unix_Users, sid, &rid) ) {
-               id->id = rid;
-               id->type = ID_TYPE_UID;
-               ret = True;             
-               goto done;              
-       }
-
-       /* check for "Unix Group" */
-
-       if ( sid_peek_check_rid(&global_sid_Unix_Groups, sid, &rid) ) {
-               id->id = rid;
-               id->type = ID_TYPE_GID;
-               ret = True;             
-               goto done;              
+       /*
+        * "Unix User" and "Unix Group"
+        */
+       ret = pdb_sid_to_id_unix_users_and_groups(sid, id);
+       if (ret == true) {
+               goto done;
        }
 
        /* BUILTIN */