diff options
author | Andreas Schneider <asn@samba.org> | 2014-02-18 10:02:57 +0100 |
---|---|---|
committer | Andrew Bartlett <abartlet@samba.org> | 2014-02-19 11:29:29 +1300 |
commit | 3dc72266005e87a291f5bf9847257e8c54314d39 (patch) | |
tree | e5521e60156f50f77fe366fad8babb46a4949613 /source3/auth/server_info_sam.c | |
parent | 0d9bb86293c9d39298786df095c73a6251b08b7e (diff) | |
download | samba-3dc72266005e87a291f5bf9847257e8c54314d39.tar.gz samba-3dc72266005e87a291f5bf9847257e8c54314d39.tar.xz samba-3dc72266005e87a291f5bf9847257e8c54314d39.zip |
s3-auth: Pass mem_ctx to make_server_info_sam().
Coverity-Id: 1168009
BUG: https://bugzilla.samba.org/show_bug.cgi?id=8598
Signed-off-by: Andreas Schneider <asn@samba.org>
Change-Id: Ie614b0654c3a7eec1ebb10dbb9763696eec795bd
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Diffstat (limited to 'source3/auth/server_info_sam.c')
-rw-r--r-- | source3/auth/server_info_sam.c | 56 |
1 files changed, 36 insertions, 20 deletions
diff --git a/source3/auth/server_info_sam.c b/source3/auth/server_info_sam.c index 5d657f90c81..47087b1b4fd 100644 --- a/source3/auth/server_info_sam.c +++ b/source3/auth/server_info_sam.c @@ -58,39 +58,51 @@ static bool is_our_machine_account(const char *username) Make (and fill) a user_info struct from a struct samu ***************************************************************************/ -NTSTATUS make_server_info_sam(struct auth_serversupplied_info **server_info, - struct samu *sampass) +NTSTATUS make_server_info_sam(TALLOC_CTX *mem_ctx, + struct samu *sampass, + struct auth_serversupplied_info **pserver_info) { struct passwd *pwd; - struct auth_serversupplied_info *result; + struct auth_serversupplied_info *server_info; const char *username = pdb_get_username(sampass); + TALLOC_CTX *tmp_ctx; NTSTATUS status; - if ( !(result = make_server_info(NULL)) ) { + tmp_ctx = talloc_stackframe(); + if (tmp_ctx == NULL) { return NT_STATUS_NO_MEMORY; } - if ( !(pwd = Get_Pwnam_alloc(result, username)) ) { + server_info = make_server_info(tmp_ctx); + if (server_info == NULL) { + return NT_STATUS_NO_MEMORY; + } + + pwd = Get_Pwnam_alloc(tmp_ctx, username); + if (pwd == NULL) { DEBUG(1, ("User %s in passdb, but getpwnam() fails!\n", pdb_get_username(sampass))); - TALLOC_FREE(result); - return NT_STATUS_NO_SUCH_USER; + status = NT_STATUS_NO_SUCH_USER; + goto out; } - status = samu_to_SamInfo3(result, sampass, lp_netbios_name(), - &result->info3, &result->extra); + status = samu_to_SamInfo3(server_info, + sampass, + lp_netbios_name(), + &server_info->info3, + &server_info->extra); if (!NT_STATUS_IS_OK(status)) { - TALLOC_FREE(result); - return status; + goto out; } - result->unix_name = pwd->pw_name; - /* Ensure that we keep pwd->pw_name, because we will free pwd below */ - talloc_steal(result, pwd->pw_name); - result->utok.gid = pwd->pw_gid; - result->utok.uid = pwd->pw_uid; + server_info->unix_name = talloc_strdup(server_info, pwd->pw_name); + if (server_info->unix_name == NULL) { + status = NT_STATUS_NO_MEMORY; + goto out; + } - TALLOC_FREE(pwd); + server_info->utok.gid = pwd->pw_gid; + server_info->utok.uid = pwd->pw_uid; if (IS_DC && is_our_machine_account(username)) { /* @@ -110,9 +122,13 @@ NTSTATUS make_server_info_sam(struct auth_serversupplied_info **server_info, } DEBUG(5,("make_server_info_sam: made server info for user %s -> %s\n", - pdb_get_username(sampass), result->unix_name)); + pdb_get_username(sampass), server_info->unix_name)); + + *pserver_info = talloc_steal(mem_ctx, server_info); - *server_info = result; + status = NT_STATUS_OK; +out: + talloc_free(tmp_ctx); - return NT_STATUS_OK; + return status; } |