Removed some annoying debug messages.
authorTim Potter <tpot@samba.org>
Thu, 13 Apr 2000 02:14:37 +0000 (02:14 +0000)
committerTim Potter <tpot@samba.org>
Thu, 13 Apr 2000 02:14:37 +0000 (02:14 +0000)
Decoupled domain related information from uid and gid ranges.

Don't try to process machine accounts when enumerating users.

source/nsswitch/winbindd.c
source/nsswitch/winbindd_group.c
source/nsswitch/winbindd_surs.c
source/nsswitch/winbindd_user.c

index e3c62191d011b6a124c6d7a6e3ec03fd3e34a11e..2b1e54b74a75815c09c3fcdf31a3c4c7e949ba03 100644 (file)
@@ -47,9 +47,6 @@ BOOL lookup_domain_sid(fstring domain_name, DOM_SID *domain_sid,
         fstrcpy(domain_controller, system_name);
     }
 
-    DEBUG(0, ("lookup_domain_sid: Found domain controller %s for domain %s\n",
-              system_name, domain_name));
-
     /* Get SID from domain controller */
 
     res = lsa_open_policy(system_name, &lsa_handle, False, 
index fb4cc25b86d604e8bea195dea8e5ea8b7d3772c4..067f2fd8f84d871585811ecb8158d850885cd3b4 100644 (file)
@@ -59,15 +59,6 @@ static BOOL winbindd_fill_grent_mem(char *server_name, DOM_SID *domain_sid,
         
     /* Lookup group information */
 
-    {
-        fstring sid_str;
-
-        sid_to_string(sid_str, domain_sid);
-
-        DEBUG(0, ("server/domain %s/%s sid=%s group rid=%d\n",
-                  server_name, domain_name, sid_str, group_rid));
-    }
-
     if (!winbindd_lookup_groupmem(server_name, domain_sid, group_rid, 
                                   &num_names, &rid_mem, &names, &name_types) &&
         !winbindd_lookup_aliasmem(server_name, global_sid_builtin, 
@@ -131,7 +122,7 @@ enum winbindd_result winbindd_getgrnam_from_group(char *groupname,
 
     /* Get domain sid for the domain */
 
-    if (!find_domain_sid_from_domain(name_domain, &domain_sid, 
+    if (!find_domain_sid_from_name(name_domain, &domain_sid, 
                                      domain_controller)) {
         DEBUG(0, ("getgrname_from_group(): could not get domain sid for "
                   "domain %s\n", name_domain));
@@ -273,8 +264,8 @@ struct winbindd_enum_grent {
 
 static struct winbindd_enum_grent *enum_grent_list = NULL;
 
-extern int num_domain_gid;
-extern struct winbind_domain_gid *domain_gid;
+extern struct winbind_domain *domain_list;
+extern int num_domain;
 
 /* Return the winbindd_enum_grent structure for a given pid */
 
@@ -296,7 +287,7 @@ static struct winbindd_enum_grent *get_grent_static(pid_t pid)
 enum winbindd_result winbindd_setgrent(pid_t pid)
 {
     struct winbindd_enum_grent *enum_grent = get_grent_static(pid);
-    struct winbind_domain_gid *tmp;
+    struct winbind_domain *tmp;
     int i;
 
     /* Free old static data if it exists */
@@ -326,21 +317,21 @@ enum winbindd_result winbindd_setgrent(pid_t pid)
     enum_grent->pid = pid;
 
     if ((enum_grent->sam_pipes = (struct winbindd_enum_grent_sam_pipes *)
-         malloc(sizeof(*enum_grent->sam_pipes) * num_domain_gid)) == NULL) {
+         malloc(sizeof(*enum_grent->sam_pipes) * num_domain)) == NULL) {
 
         free(enum_grent);
         return WINBINDD_ERROR;
     }
 
-    enum_grent->num_sam_pipes = num_domain_gid;
+    enum_grent->num_sam_pipes = num_domain;
     memset(enum_grent->sam_pipes, 0, sizeof(*enum_grent->sam_pipes) *
-           num_domain_gid);
+           num_domain);
 
     /* Connect to samr pipe for each domain */
 
     i = 0;
 
-    for (tmp = domain_gid; tmp != NULL; tmp = tmp->next) {
+    for (tmp = domain_list; tmp != NULL; tmp = tmp->next) {
         BOOL res;
 
         /* Connect to sam database */
index 8ebd1868ca910646ac65980250a59b2f014d37f2..b8a4759e8aa6d464f38e2d2f4e65c97edb0d612c 100644 (file)
 #include "sids.h"
 #include "lib/surs.h"
 
-struct winbind_domain_uid *domain_uid = NULL;
-struct winbind_domain_gid *domain_gid = NULL;
+struct winbind_domain_uid *domain_uid_list = NULL;
+struct winbind_domain_gid *domain_gid_list = NULL;
+struct winbind_domain *domain_list = NULL;
+
 int num_domain_uid = 0;
 int num_domain_gid = 0;
+int num_domain = 0;
+
+/* Given a domain name, return the struct winbindd domain info for it */
+
+struct winbind_domain *find_domain_from_name(char *domain_name)
+{
+    struct winbind_domain *tmp;
+
+    /* Search through list */
+
+    for (tmp = domain_list; tmp != NULL; tmp = tmp->next) {
+        if (strcmp(domain_name, tmp->domain_name) == 0) {
+            return tmp;
+        }
+    }
+
+    /* Not found */
+
+    return NULL;
+}
 
 /* Given a domain name, return the domain sid and domain controller we
    found in winbindd_surs_init(). */
 
-BOOL find_domain_sid_from_domain(char *domain_name, DOM_SID *domain_sid, 
-                                 char *domain_controller)
+BOOL find_domain_sid_from_name(char *domain_name, DOM_SID *domain_sid, 
+                               char *domain_controller)
 {
-    struct winbind_domain_uid *tmp;
+    struct winbind_domain *tmp;
 
     /* Search through list */
 
-    for(tmp = domain_uid; tmp != NULL; tmp = tmp->next) {
+    for(tmp = domain_list; tmp != NULL; tmp = tmp->next) {
         if (strcmp(domain_name, tmp->domain_name) == 0) {
 
             /* Copy domain sid */
@@ -57,6 +79,8 @@ BOOL find_domain_sid_from_domain(char *domain_name, DOM_SID *domain_sid,
         }
     }
 
+    /* Not found */
+
     return False;
 }
 
@@ -68,31 +92,34 @@ BOOL find_domain_sid_from_uid(uid_t uid, DOM_SID *domain_sid,
 {
     struct winbind_domain_uid *tmp;
 
-    for(tmp = domain_uid; tmp != NULL; tmp = tmp->next) {
-        if ((uid >= tmp->uid_low) && (uid <= tmp->uid_high)) {
+    for(tmp = domain_uid_list; tmp != NULL; tmp = tmp->next) {
+        if ((uid >= tmp->uid_low) && (uid <= tmp->uid_high) &&
+            (tmp->domain != NULL)) {
 
             /* Copy domain sid */
 
             if (domain_sid != NULL) {
-                sid_copy(domain_sid, &tmp->domain_sid);
+                sid_copy(domain_sid, &tmp->domain->domain_sid);
             }
             
             /* Copy domain controller */
 
             if (domain_controller != NULL) {
-                fstrcpy(domain_controller, tmp->domain_controller);
+                fstrcpy(domain_controller, tmp->domain->domain_controller);
             }
 
             /* Copy domain name */
 
             if (domain_name != NULL) {
-                fstrcpy(domain_name, tmp->domain_name);
+                fstrcpy(domain_name, tmp->domain->domain_name);
             }
 
             return True;
         }
     }
 
+    /* Not found */
+
     return False;
 }
 
@@ -104,40 +131,41 @@ BOOL find_domain_sid_from_gid(gid_t gid, DOM_SID *domain_sid,
 {
     struct winbind_domain_gid *tmp;
 
-    for(tmp = domain_gid; tmp != NULL; tmp = tmp->next) {
-        if ((gid >= tmp->gid_low) && (gid <= tmp->gid_high)) {
+    for(tmp = domain_gid_list; tmp != NULL; tmp = tmp->next) {
+        if ((gid >= tmp->gid_low) && (gid <= tmp->gid_high) &&
+            (tmp->domain != NULL)) {
 
             /* Copy domain sid */
 
             if (domain_sid != NULL) {
-                sid_copy(domain_sid, &tmp->domain_sid);
+                sid_copy(domain_sid, &tmp->domain->domain_sid);
             }
             
             /* Copy domain controller */
 
             if (domain_controller != NULL) {
-                fstrcpy(domain_controller, tmp->domain_controller);
+                fstrcpy(domain_controller, tmp->domain->domain_controller);
             }
 
             /* Copy domain name */
 
             if (domain_name != NULL) {
-                fstrcpy(domain_name, tmp->domain_name);
+                fstrcpy(domain_name, tmp->domain->domain_name);
             }
 
             return True;
         }
     }
 
+    /* Not found */
+
     return False;
 }
 
 /* Initialise winbindd_surs database */
 
-int winbindd_surs_init(void)
+BOOL winbindd_surs_init(void)
 {
-    struct winbind_domain_gid *gid;
-    struct winbind_domain_uid *uid;
     fstring value;
     char *p;
 
@@ -146,8 +174,11 @@ int winbindd_surs_init(void)
     fstrcpy(value, lp_winbind_uid());
 
     for (p = strtok(value, LIST_SEP); p; p = strtok(NULL, LIST_SEP)) {
+        struct winbind_domain_uid *uid;
+        struct winbind_domain *domain;
+        fstring domain_name;
 
-        /* Create new domain entry */
+        /* Create new domain uid entry */
 
         if ((uid = (struct winbind_domain_uid *)
              malloc(sizeof(*uid))) == NULL) {
@@ -159,40 +190,59 @@ int winbindd_surs_init(void)
 
         /* Store info */
 
-        if ((sscanf(p, "%[^/]/%u-%u", uid->domain_name, &uid->uid_low,
+        if ((sscanf(p, "%[^/]/%u-%u", domain_name, &uid->uid_low,
                     &uid->uid_high) != 3) && 
-            (sscanf(p, "%[^/]/%u", uid->domain_name, &uid->uid_low) != 2)) {
+            (sscanf(p, "%[^/]/%u", domain_name, &uid->uid_low) != 2)) {
 
             DEBUG(0, ("surs_init(): winbid uid parameter invalid\n"));
             free(uid);
             return False;
         }
 
-        /* Lookup domain sid */
-        
-        if (strequal(uid->domain_name, "BUILTIN")) {
-            sid_copy(&uid->domain_sid, global_sid_builtin);
-            lookup_domain_sid(lp_workgroup(), NULL, uid->domain_controller);
-        } else if (!lookup_domain_sid(uid->domain_name, &uid->domain_sid, 
-                                      uid->domain_controller)) {
-            DEBUG(0, ("surs_init(): could not find domain sid for domain %s\n",
-                      uid->domain_name));
-            free(uid);
-            continue;
+        if (uid->uid_high == 0) {
+            uid->uid_high = -1;
         }
 
-        {
-            fstring temp;
+        if ((domain = find_domain_from_name(domain_name)) == NULL) {
+            fstring sid_str;
 
-            sid_to_string(temp, &uid->domain_sid);
+            /* Create new domain entry */
 
-            DEBUG(0, ("*** domain = %s, sid = %s, controller = %s\n",
-                      uid->domain_name, temp, uid->domain_controller));
+            if ((domain = (struct winbind_domain *)malloc(sizeof(*domain)))
+                == NULL) {
+                return False;
+            }
+            
+            fstrcpy(domain->domain_name, domain_name);
+
+            /* Lookup domain sid */
+        
+            if (strequal(domain_name, "BUILTIN")) {
+                sid_copy(&domain->domain_sid, global_sid_builtin);
+                lookup_domain_sid(lp_workgroup(), NULL, 
+                                  domain->domain_controller);
+            } else if (!lookup_domain_sid(domain->domain_name, 
+                                          &domain->domain_sid, 
+                                          domain->domain_controller)) {
+                DEBUG(0, ("surs_init(): could not find domain sid for "
+                          "domain %s\n", domain->domain_name));
+                return False;
+            }
+
+            sid_to_string(sid_str, &domain->domain_sid);
+            DEBUG(0, ("Found sid %s for domain %s, controller %s\n",
+                      sid_str, domain->domain_name, 
+                      domain->domain_controller));
+
+            DLIST_ADD(domain_list, domain);
+            num_domain++;
         }
 
+        uid->domain = domain;
+
         /* Add to list */
 
-        DLIST_ADD(domain_uid, uid);
+        DLIST_ADD(domain_uid_list, uid);
         num_domain_uid++;
     }
     
@@ -201,6 +251,9 @@ int winbindd_surs_init(void)
     fstrcpy(value, lp_winbind_gid());
 
     for (p = strtok(value, LIST_SEP); p; p = strtok(NULL, LIST_SEP)) {
+        struct winbind_domain_gid *gid;
+        struct winbind_domain *domain;
+        fstring domain_name;
 
         /* Create new domain entry */
 
@@ -214,38 +267,54 @@ int winbindd_surs_init(void)
 
         /* Store info */
 
-        if ((sscanf(p, "%[^/]/%u-%u", gid->domain_name, &gid->gid_low,
+        if ((sscanf(p, "%[^/]/%u-%u", domain_name, &gid->gid_low,
                     &gid->gid_high) != 3) &&
-            (sscanf(p, "%[^/]/%u", gid->domain_name, &gid->gid_low) != 2)) {
+            (sscanf(p, "%[^/]/%u", domain_name, &gid->gid_low) != 2)) {
             DEBUG(0, ("surs_init(): winbid gid parameter invalid\n"));
             free(gid);
             return False;
         }
 
-        if (uid->uid_high == 0) {
-            uid->uid_high = -1;
-        }
-
         if (gid->gid_high == 0) {
             gid->gid_high = -1;
         }
 
         /* Lookup domain sid */
 
-        if (strequal(gid->domain_name, "BUILTIN")) {
-            sid_copy(&gid->domain_sid, global_sid_builtin);
-            lookup_domain_sid(lp_workgroup(), NULL, gid->domain_controller);
-        } else if (!lookup_domain_sid(gid->domain_name, &gid->domain_sid, 
-                                      gid->domain_controller)) {
-            DEBUG(0, ("surs_init(): could not find domain sid for domain %s\n",
-                      gid->domain_name));
-            free(gid);
-            continue;
+        if ((domain = find_domain_from_name(domain_name)) == NULL) {
+
+            /* Create new domain entry */
+
+            if ((domain = (struct winbind_domain *)malloc(sizeof(*domain)))
+                == NULL) {
+                return False;
+            }
+            
+            fstrcpy(domain->domain_name, domain_name);
+
+            /* Lookup domain sid */
+        
+            if (strequal(domain_name, "BUILTIN")) {
+                sid_copy(&domain->domain_sid, global_sid_builtin);
+                lookup_domain_sid(lp_workgroup(), NULL, 
+                                  domain->domain_controller);
+            } else if (!lookup_domain_sid(domain->domain_name, 
+                                          &domain->domain_sid, 
+                                          domain->domain_controller)) {
+                DEBUG(0, ("surs_init(): could not find domain sid for "
+                          "domain %s\n", domain->domain_name));
+                return False;
+            }
+
+            DLIST_ADD(domain_list, domain);
+            num_domain++;
         }
 
+        gid->domain = domain;
+
         /* Add to list */
 
-        DLIST_ADD(domain_gid, gid);
+        DLIST_ADD(domain_gid_list, gid);
         num_domain_gid++;
     }
 
@@ -267,19 +336,14 @@ BOOL winbindd_surs_sam_sid_to_unixid(DOM_SID *sid,
 
     sid_to_string(temp, &tmp_sid);
 
-    DEBUG(0, ("** sam_sid_to_unixid(): Converting sid %s rid %d type %d to "
-              "unixid\n", temp, rid, name_type));
-
     /* User names */
 
     if (name_type == SID_NAME_USER) {
         struct winbind_domain_uid *uid;
 
-        for(uid = domain_uid; uid != NULL; uid = uid->next) {
+        for(uid = domain_uid_list; uid != NULL; uid = uid->next) {
 
-            if (sid_equal(&uid->domain_sid, &tmp_sid)) {
-
-                DEBUG(0, ("Spotted sid in domain %s\n", uid->domain_name));
+            if (sid_equal(&uid->domain->domain_sid, &tmp_sid)) {
 
                 if ((uid->uid_low + rid) > uid->uid_high) {
                     DEBUG(0, ("uid range to small for rid %d\n", rid));
@@ -289,12 +353,9 @@ BOOL winbindd_surs_sam_sid_to_unixid(DOM_SID *sid,
                 id->id = uid->uid_low + rid;
                 id->type = SURS_POSIX_UID_AS_USR;
 
-                DEBUG(0, ("allocated rid %d as uid %d\n", rid, id->id));
                 return True;
             }
         }
-
-        return False;
     }
 
     /* Domain groups */
@@ -302,12 +363,9 @@ BOOL winbindd_surs_sam_sid_to_unixid(DOM_SID *sid,
     if ((name_type == SID_NAME_DOM_GRP) || (name_type == SID_NAME_ALIAS)) {
         struct winbind_domain_gid *gid;
         
-        for(gid = domain_gid; gid != NULL; gid = gid->next) {
+        for(gid = domain_gid_list; gid != NULL; gid = gid->next) {
 
-            if (sid_equal(&gid->domain_sid, &tmp_sid)) {
-
-                DEBUG(0, ("Spotted group sid in domain %s\n",
-                          gid->domain_name));
+            if (sid_equal(&gid->domain->domain_sid, &tmp_sid)) {
 
                 if ((gid->gid_low + rid) > gid->gid_high) {
                     DEBUG(0, ("gid range too small for rid %d\n", rid));
@@ -316,13 +374,10 @@ BOOL winbindd_surs_sam_sid_to_unixid(DOM_SID *sid,
 
                 id->id = gid->gid_low + rid;
                 id->type = SURS_POSIX_GID_AS_GRP;
-
-                DEBUG(0, ("allocated rid %d as gid %d\n", rid, id->id));
+                
                 return True;
             }
         }
-
-        return False;
     }
 
     return False;
@@ -332,27 +387,18 @@ BOOL winbindd_surs_sam_sid_to_unixid(DOM_SID *sid,
 
 BOOL winbindd_surs_unixid_to_sam_sid(POSIX_ID *id, DOM_SID *sid, BOOL create)
 {
-    DEBUG(0, ("** unixid_to_sam_sid(): converting id %s/%d to sid\n", 
-              (id->type == SURS_POSIX_UID_AS_USR) ? "user" :
-              ((id->type == SURS_POSIX_GID_AS_GRP) ? "group" : 
-               ((id->type == SURS_POSIX_GID_AS_ALS) ? "alias" : "???")),
-              id->id));
-
     /* Process user uid */
 
     if (id->type == SURS_POSIX_UID_AS_USR) {
         struct winbind_domain_uid *uid;
 
-        for(uid = domain_uid; uid != NULL; uid = uid->next) {
+        for(uid = domain_uid_list; uid != NULL; uid = uid->next) {
             if ((id->id >= uid->uid_low) && (id->id <= uid->uid_high)) {
 
                 /* uid falls within range for this domain */
 
-                DEBUG(0, ("found uid in range for domain %s\n",
-                          uid->domain_name));
-
                 if (sid != NULL) {
-                    sid_copy(sid, &uid->domain_sid);
+                    sid_copy(sid, &uid->domain->domain_sid);
                     sid_append_rid(sid, id->id - uid->uid_low);
                 }
 
@@ -368,24 +414,13 @@ BOOL winbindd_surs_unixid_to_sam_sid(POSIX_ID *id, DOM_SID *sid, BOOL create)
         
         struct winbind_domain_gid *gid;
 
-        for(gid = domain_gid; gid != NULL; gid = gid->next) {
+        for(gid = domain_gid_list; gid != NULL; gid = gid->next) {
             if ((id->id >= gid->gid_low) && (id->id <= gid->gid_high)) {
 
                 /* gid falls within range for this domain */
 
-                DEBUG(0, ("found gid in range for domain %s\n",
-                          gid->domain_name));
-
-                {
-                    fstring temp;
-
-                    sid_to_string(temp, &gid->domain_sid);
-                    DEBUG(0, ("domain %s has sid %s\n", gid->domain_name, 
-                              temp));
-                }
-
                 if (sid != NULL) {
-                    sid_copy(sid, &gid->domain_sid);
+                    sid_copy(sid, &gid->domain->domain_sid);
                     sid_append_rid(sid, id->id - gid->gid_low);
                 }
 
index 404d000179f6e22d7f5f105600708aa150b5f44b..80aa5392d046a580fd8afa43cea983ad35e17641 100644 (file)
@@ -88,8 +88,8 @@ enum winbindd_result winbindd_getpwnam_from_user(char *user_name,
 
     /* Get domain sid for the domain */
 
-    if (!find_domain_sid_from_domain(name_domain, &domain_sid,
-                                     domain_controller)) {
+    if (!find_domain_sid_from_name(name_domain, &domain_sid,
+                                   domain_controller)) {
         DEBUG(0, ("Could not get domain sid for domain %s\n", name_domain));
         return WINBINDD_ERROR;
     }
@@ -256,8 +256,8 @@ struct winbindd_enum_pwent {
 
 static struct winbindd_enum_pwent *enum_pwent_list = NULL;
 
-extern int num_domain_uid;
-extern struct winbind_domain_uid *domain_uid;
+extern int num_domain;
+extern struct winbind_domain *domain_list;
 
 /* Get static data for getpwent() and friends */
 
@@ -281,7 +281,7 @@ static struct winbindd_enum_pwent *get_pwent_static(pid_t pid)
 enum winbindd_result winbindd_setpwent(pid_t pid)
 {
     struct winbindd_enum_pwent *enum_pwent = get_pwent_static(pid);
-    struct winbind_domain_uid *tmp;
+    struct winbind_domain *tmp;
     int i;
 
     /* Free old static data if it exists */
@@ -311,26 +311,27 @@ enum winbindd_result winbindd_setpwent(pid_t pid)
     enum_pwent->pid = pid;
     
     if ((enum_pwent->sam_pipes = (struct winbindd_enum_pwent_sam_pipes *)
-         malloc(sizeof(*enum_pwent->sam_pipes) * num_domain_uid)) == NULL) {
+         malloc(sizeof(*enum_pwent->sam_pipes) * num_domain)) == NULL) {
         
         free(enum_pwent);
         return WINBINDD_ERROR;
     }
 
-    enum_pwent->num_sam_pipes = num_domain_uid;
+    enum_pwent->num_sam_pipes = num_domain;
     memset(enum_pwent->sam_pipes, 0, sizeof(*enum_pwent->sam_pipes) * 
-           num_domain_uid);
+           num_domain);
 
     /* Create sam pipes for each domain we know about */
 
     i = 0;
 
-    for(tmp = domain_uid; tmp != NULL; tmp = tmp->next) {
+    for(tmp = domain_list; tmp != NULL; tmp = tmp->next) {
         BOOL res;
 
         /* Connect to sam database */
 
-        res = samr_connect(tmp->domain_controller, SEC_RIGHTS_MAXIMUM_ALLOWED, 
+        res = samr_connect(tmp->domain_controller, 
+                           SEC_RIGHTS_MAXIMUM_ALLOWED, 
                            &enum_pwent->sam_pipes[i].sam_handle);
 
         res = res ? samr_open_domain(&enum_pwent->sam_pipes[i].sam_handle,
@@ -437,6 +438,13 @@ enum winbindd_result winbindd_getpwent(pid_t pid, struct winbindd_pw *pw)
                 char *user_name = (sam_pipe->sam_entries)
                     [sam_pipe->index].acct_name; 
                 
+                /* Don't bother with machine accounts */
+
+                if (user_name[strlen(user_name) - 1] == '$') {
+                    sam_pipe->index++;
+                    continue;
+                }
+
                 /* Prepend domain to name */
         
                 fstrcpy(domain_user_name, sam_pipe->domain_name);