From: Jeremy Allison Date: Wed, 20 Oct 2010 18:22:57 +0000 (-0700) Subject: Fix bug #7743 - Inconsistent use of system name lookup can cause a domain joined... X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6e9d95f753b2b127268f1eb9a40d601002484bd1;p=thirdparty%2Fsamba.git Fix bug #7743 - Inconsistent use of system name lookup can cause a domain joined machine to fail to find users. 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. --- diff --git a/source3/auth/auth_util.c b/source3/auth/auth_util.c index 3fa7224b2e1..4a7160accf9 100644 --- a/source3/auth/auth_util.c +++ b/source3/auth/auth_util.c @@ -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; } diff --git a/source3/lib/util.c b/source3/lib/util.c index 50aa4b0cbc4..fad6c7aa42f 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -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); diff --git a/source3/passdb/pdb_interface.c b/source3/passdb/pdb_interface.c index de46254dde0..e09ad9722f2 100644 --- a/source3/passdb/pdb_interface.c +++ b/source3/passdb/pdb_interface.c @@ -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; } diff --git a/source3/passdb/pdb_smbpasswd.c b/source3/passdb/pdb_smbpasswd.c index f465d34c882..9f2be333c05 100644 --- a/source3/passdb/pdb_smbpasswd.c +++ b/source3/passdb/pdb_smbpasswd.c @@ -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; diff --git a/source3/passdb/util_unixsids.c b/source3/passdb/util_unixsids.c index ad51253058e..abe088c6c22 100644 --- a/source3/passdb/util_unixsids.c +++ b/source3/passdb/util_unixsids.c @@ -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; } diff --git a/source3/smbd/password.c b/source3/smbd/password.c index 755ff5d6cde..a4b2eeefe17 100644 --- a/source3/smbd/password.c +++ b/source3/smbd/password.c @@ -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", diff --git a/source3/smbd/uid.c b/source3/smbd/uid.c index 2ec50cd4d83..d706f7e0a37 100644 --- a/source3/smbd/uid.c +++ b/source3/smbd/uid.c @@ -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; } diff --git a/source3/torture/pdbtest.c b/source3/torture/pdbtest.c index 950177c3ca9..0ad8111e478 100644 --- a/source3/torture/pdbtest.c +++ b/source3/torture/pdbtest.c @@ -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); } diff --git a/source3/utils/net_sam.c b/source3/utils/net_sam.c index 6e3ccfefaf6..5456abba98d 100644 --- a/source3/utils/net_sam.c +++ b/source3/utils/net_sam.c @@ -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" diff --git a/source3/web/cgi.c b/source3/web/cgi.c index a3b7d8952bb..cf91b02175b 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -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
%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.