Fix bug #7743 - Inconsistent use of system name lookup can cause a domain joined...
authorJeremy Allison <jra@samba.org>
Wed, 20 Oct 2010 18:22:57 +0000 (11:22 -0700)
committerKarolin Seeger <kseeger@samba.org>
Sat, 5 Mar 2011 13:34:33 +0000 (14:34 +0100)
Ensure all username lookups go through Get_Pwnam_alloc(), which is the
correct wrapper function. We were using it *some* of the time anyway,
so this just makes us properly consistent.

Jeremy.
(cherry picked from commit 6e9d95f753b2b127268f1eb9a40d601002484bd1)

source3/auth/auth_util.c
source3/lib/util.c
source3/passdb/pdb_interface.c
source3/passdb/pdb_smbpasswd.c
source3/passdb/util_unixsids.c
source3/smbd/password.c
source3/smbd/uid.c
source3/torture/pdbtest.c
source3/utils/net_sam.c
source3/web/cgi.c

index 3fa7224b2e1dd1b048bf77024f7dc092c363c1fb..4a7160accf9bcbcdda68fdb43aa27f01da42c977 100644 (file)
@@ -575,7 +575,7 @@ NTSTATUS make_server_info_sam(auth_serversupplied_info **server_info,
                return NT_STATUS_NO_MEMORY;
        }
 
-       if ( !(pwd = getpwnam_alloc(result, username)) ) {
+       if ( !(pwd = Get_Pwnam_alloc(result, username)) ) {
                DEBUG(1, ("User %s in passdb, but getpwnam() fails!\n",
                          pdb_get_username(sampass)));
                TALLOC_FREE(result);
@@ -903,14 +903,14 @@ NTSTATUS create_token_from_username(TALLOC_CTX *mem_ctx, const char *username,
                 * about the mapping of guest sid to lp_guestaccount()
                 * username and will return the unix_pw info for a guest
                 * user. Use it if it's there, else lookup the *uid details
-                * using getpwnam_alloc(). See bug #6291 for details. JRA.
+                * using Get_Pwnam_alloc(). See bug #6291 for details. JRA.
                 */
 
                /* We must always assign the *uid. */
                if (sam_acct->unix_pw == NULL) {
-                       struct passwd *pwd = getpwnam_alloc(sam_acct, *found_username );
+                       struct passwd *pwd = Get_Pwnam_alloc(sam_acct, *found_username );
                        if (!pwd) {
-                               DEBUG(10, ("getpwnam_alloc failed for %s\n",
+                               DEBUG(10, ("Get_Pwnam_alloc failed for %s\n",
                                        *found_username));
                                result = NT_STATUS_NO_SUCH_USER;
                                goto done;
@@ -1326,7 +1326,7 @@ NTSTATUS make_serverinfo_from_username(TALLOC_CTX *mem_ctx,
        struct passwd *pwd;
        NTSTATUS status;
 
-       pwd = getpwnam_alloc(talloc_tos(), username);
+       pwd = Get_Pwnam_alloc(talloc_tos(), username);
        if (pwd == NULL) {
                return NT_STATUS_NO_SUCH_USER;
        }
index 50aa4b0cbc497f08dde04953afea13fc136abc99..fad6c7aa42f4531bacff66d2bf8bba42daf06e98 100644 (file)
@@ -1407,7 +1407,7 @@ uid_t nametouid(const char *name)
        char *p;
        uid_t u;
 
-       pass = getpwnam_alloc(talloc_autofree_context(), name);
+       pass = Get_Pwnam_alloc(talloc_autofree_context(), name);
        if (pass) {
                u = pass->pw_uid;
                TALLOC_FREE(pass);
index de46254dde0e6c1760aa79e649f1b07efe54bf88..e09ad9722f276b12ac878f9eeb814182be899fff 100644 (file)
@@ -254,7 +254,7 @@ bool guest_user_info( struct samu *user )
        NTSTATUS result;
        const char *guestname = lp_guestaccount();
 
-       if ( !(pwd = getpwnam_alloc(talloc_autofree_context(), guestname ) ) ) {
+       if ( !(pwd = Get_Pwnam_alloc(talloc_autofree_context(), guestname ) ) ) {
                DEBUG(0,("guest_user_info: Unable to locate guest account [%s]!\n", 
                        guestname));
                return False;
@@ -1423,7 +1423,7 @@ static NTSTATUS pdb_default_enum_group_memberships(struct pdb_methods *methods,
        /* Ignore the primary group SID.  Honor the real Unix primary group.
           The primary group SID is only of real use to Windows clients */
 
-       if ( !(pw = getpwnam_alloc(mem_ctx, username)) ) {
+       if ( !(pw = Get_Pwnam_alloc(mem_ctx, username)) ) {
                return NT_STATUS_NO_SUCH_USER;
        }
 
index f465d34c8821cb74ff74fe04ff030cbf737ac245..9f2be333c055bf9ae2a3a6d8821bd7dd308a8ee4 100644 (file)
@@ -1196,7 +1196,7 @@ static bool build_smb_pass (struct smb_passwd *smb_pw, const struct samu *sampas
                
                /* If the user specified a RID, make sure its able to be both stored and retreived */
                if (rid == DOMAIN_USER_RID_GUEST) {
-                       struct passwd *passwd = getpwnam_alloc(NULL, lp_guestaccount());
+                       struct passwd *passwd = Get_Pwnam_alloc(NULL, lp_guestaccount());
                        if (!passwd) {
                                DEBUG(0, ("Could not find guest account via getpwnam()! (%s)\n", lp_guestaccount()));
                                return False;
index ad51253058e9a619be4b64c11c3c9afbca3c5d0d..abe088c6c223cab86bbc1e54ede014aa651216c0 100644 (file)
@@ -56,7 +56,7 @@ bool lookup_unix_user_name(const char *name, DOM_SID *sid)
 {
        struct passwd *pwd;
 
-       pwd = getpwnam_alloc(talloc_autofree_context(), name);
+       pwd = Get_Pwnam_alloc(talloc_autofree_context(), name);
        if (pwd == NULL) {
                return False;
        }
index 755ff5d6cdeca1ce9a86a2aca6c8967566eb6893..a4b2eeefe17907b32671b779566214bebad6c22b 100644 (file)
@@ -210,7 +210,7 @@ static int register_homes_share(const char *username)
                return result;
        }
 
-       pwd = getpwnam_alloc(talloc_tos(), username);
+       pwd = Get_Pwnam_alloc(talloc_tos(), username);
 
        if ((pwd == NULL) || (pwd->pw_dir[0] == '\0')) {
                DEBUG(3, ("No home directory defined for user '%s'\n",
index 2ec50cd4d8319307e69a33d3c386117c37c2ee43..d706f7e0a37aa6c07097f5526faaf2da3e1a729d 100644 (file)
@@ -31,7 +31,7 @@ bool change_to_guest(void)
 {
        struct passwd *pass;
 
-       pass = getpwnam_alloc(talloc_autofree_context(), lp_guestaccount());
+       pass = Get_Pwnam_alloc(talloc_autofree_context(), lp_guestaccount());
        if (!pass) {
                return false;
        }
index 950177c3ca97a636af2f964981f49d8b67ed0422..0ad8111e47858234040cc7e80c493cd5888a8b36 100644 (file)
@@ -277,7 +277,7 @@ int main(int argc, char **argv)
                exit(1);
        }
        
-       if ((pwd = getpwnam_alloc(ctx, unix_user)) == NULL) {
+       if ((pwd = Get_Pwnam_alloc(ctx, unix_user)) == NULL) {
                fprintf(stderr, "Error getting user information for %s\n", unix_user);
                exit(1);
        }
index 6e3ccfefaf6cecf3b8ea7e1d34c3e69fec74b658..5456abba98d37264955c4fbc2565d2f4be974ddc 100644 (file)
@@ -1854,7 +1854,7 @@ doma_done:
 
                d_printf(_("Adding the Guest user.\n"));
 
-               pwd = getpwnam_alloc(tc, lp_guestaccount());
+               pwd = Get_Pwnam_alloc(tc, lp_guestaccount());
 
                if (!pwd) {
                        if (domusers_gid == -1) {
@@ -1927,7 +1927,7 @@ doma_done:
 
        d_printf(_("Checking Guest's group.\n"));
 
-       pwd = getpwnam_alloc(talloc_autofree_context(), lp_guestaccount());
+       pwd = Get_Pwnam_alloc(talloc_autofree_context(), lp_guestaccount());
        if (!pwd) {
                d_fprintf(stderr,
                          _("Failed to find just created Guest account!\n"
index a3b7d8952bb24d94dfdf1989fe0cdce373dc0513..cf91b02175b23380633c53e8c91a0f51268eb3f8 100644 (file)
@@ -314,7 +314,7 @@ static void cgi_web_auth(void)
                exit(0);
        }
 
-       pwd = getpwnam_alloc(talloc_autofree_context(), user);
+       pwd = Get_Pwnam_alloc(talloc_autofree_context(), user);
        if (!pwd) {
                printf("%sCannot find user %s<br>%s\n", head, user, tail);
                exit(0);
@@ -367,7 +367,7 @@ static bool cgi_handle_authorization(char *line)
         * Try and get the user from the UNIX password file.
         */
        
-       pass = getpwnam_alloc(talloc_autofree_context(), user);
+       pass = Get_Pwnam_alloc(talloc_autofree_context(), user);
        
        /*
         * Validate the password they have given.