From 0d13e02edaab03350a66fc9ac9a2dab6304a8085 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 20 Oct 2010 11:22:57 -0700 Subject: [PATCH] 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. --- source3/auth/auth_util.c | 10 +++++----- source3/lib/util.c | 2 +- source3/passdb/pdb_interface.c | 4 ++-- source3/passdb/pdb_smbpasswd.c | 2 +- source3/passdb/util_unixsids.c | 2 +- source3/smbd/password.c | 2 +- source3/smbd/uid.c | 2 +- source3/torture/pdbtest.c | 2 +- source3/utils/net_sam.c | 4 ++-- source3/web/cgi.c | 4 ++-- 10 files changed, 17 insertions(+), 17 deletions(-) diff --git a/source3/auth/auth_util.c b/source3/auth/auth_util.c index 3fa7224..4a7160a 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 50aa4b0..fad6c7a 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 de46254..e09ad97 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 f465d34..9f2be33 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 ad51253..abe088c 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 755ff5d..a4b2eee 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 2ec50cd..d706f7e 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 950177c..0ad8111 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 6e3ccfe..5456abb 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 a3b7d89..cf91b02 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. -- 1.7.1