From b455c5e155f7e7ba4cc07cd4415a304163213e0f Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sat, 29 May 2010 04:14:27 +1000 Subject: [PATCH] s3:auth Fix segfault when the user cannot be found by getpwnam() Add comment to notify when getpwnam() fails. Reviewed-by: Simo Sorce --- source3/auth/auth_util.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/source3/auth/auth_util.c b/source3/auth/auth_util.c index bccec8080b8..1f9bc7b6d73 100644 --- a/source3/auth/auth_util.c +++ b/source3/auth/auth_util.c @@ -964,7 +964,6 @@ static NTSTATUS check_account(TALLOC_CTX *mem_ctx, const char *domain, bool *username_was_mapped) { struct smbd_server_connection *sconn = smbd_server_conn; - NTSTATUS nt_status; fstring dom_user, lower_username; fstring real_username; struct passwd *passwd; @@ -979,8 +978,12 @@ static NTSTATUS check_account(TALLOC_CTX *mem_ctx, const char *domain, *username_was_mapped = map_username(sconn, dom_user); - if ( !(passwd = smb_getpwnam( NULL, dom_user, real_username, True )) ) + passwd = smb_getpwnam( NULL, dom_user, real_username, True ); + if (!passwd) { + DEBUG(3, ("Failed to find authenticated user %s via " + "getpwnam(), denying access.\n", dom_user)); return NT_STATUS_NO_SUCH_USER; + } *uid = passwd->pw_uid; *gid = passwd->pw_gid; @@ -995,7 +998,7 @@ static NTSTATUS check_account(TALLOC_CTX *mem_ctx, const char *domain, TALLOC_FREE(passwd); - return nt_status; + return NT_STATUS_OK; } /**************************************************************************** @@ -1154,6 +1157,10 @@ NTSTATUS make_server_info_info3(TALLOC_CTX *mem_ctx, &found_username, &uid, &gid, &username_was_mapped); + if (!NT_STATUS_IS_OK(nt_status)) { + return nt_status; + } + result = make_server_info(NULL); if (result == NULL) { DEBUG(4, ("make_server_info failed!\n")); -- 2.11.4.GIT