Skip to content

Commit

Permalink
s3:rpc_client: Clenup copy_netr_SamInfo3() code
Browse files Browse the repository at this point in the history
This gets rid of some strange macro and makes sure we clenaup at the
end.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=13209

Signed-off-by: Andreas Schneider <[email protected]>
Reviewed-by: Ralph Boehme <[email protected]>

Autobuild-User(master): Andreas Schneider <[email protected]>
Autobuild-Date(master): Mon Jan 15 22:16:13 CET 2018 on sn-devel-144
  • Loading branch information
cryptomilk committed Jan 15, 2018
1 parent bfc727f commit 05ebafd
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 61 deletions.
14 changes: 9 additions & 5 deletions source3/auth/auth_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,7 @@ static struct auth_serversupplied_info *copy_session_info_serverinfo_guest(TALLO
struct auth_serversupplied_info *server_info)
{
struct auth_serversupplied_info *dst;
NTSTATUS status;

dst = make_server_info(mem_ctx);
if (dst == NULL) {
Expand Down Expand Up @@ -1055,8 +1056,10 @@ static struct auth_serversupplied_info *copy_session_info_serverinfo_guest(TALLO
dst->lm_session_key = data_blob_talloc(dst, src->session_key.data,
src->session_key.length);

dst->info3 = copy_netr_SamInfo3(dst, server_info->info3);
if (!dst->info3) {
status = copy_netr_SamInfo3(dst,
server_info->info3,
&dst->info3);
if (!NT_STATUS_IS_OK(status)) {
TALLOC_FREE(dst);
return NULL;
}
Expand Down Expand Up @@ -1433,9 +1436,10 @@ NTSTATUS make_server_info_info3(TALLOC_CTX *mem_ctx,
result->unix_name = talloc_strdup(result, found_username);

/* copy in the info3 */
result->info3 = copy_netr_SamInfo3(result, info3);
if (result->info3 == NULL) {
nt_status = NT_STATUS_NO_MEMORY;
nt_status = copy_netr_SamInfo3(result,
info3,
&result->info3);
if (!NT_STATUS_IS_OK(nt_status)) {
goto out;
}

Expand Down
45 changes: 29 additions & 16 deletions source3/auth/server_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,14 @@ struct auth_serversupplied_info *make_server_info(TALLOC_CTX *mem_ctx)
NTSTATUS serverinfo_to_SamInfo2(struct auth_serversupplied_info *server_info,
struct netr_SamInfo2 *sam2)
{
struct netr_SamInfo3 *info3;
struct netr_SamInfo3 *info3 = NULL;
NTSTATUS status;

info3 = copy_netr_SamInfo3(sam2, server_info->info3);
if (!info3) {
return NT_STATUS_NO_MEMORY;
status = copy_netr_SamInfo3(sam2,
server_info->info3,
&info3);
if (!NT_STATUS_IS_OK(status)) {
return status;
}

if (server_info->session_key.length) {
Expand Down Expand Up @@ -96,11 +99,14 @@ NTSTATUS serverinfo_to_SamInfo2(struct auth_serversupplied_info *server_info,
NTSTATUS serverinfo_to_SamInfo3(const struct auth_serversupplied_info *server_info,
struct netr_SamInfo3 *sam3)
{
struct netr_SamInfo3 *info3;
struct netr_SamInfo3 *info3 = NULL;
NTSTATUS status;

info3 = copy_netr_SamInfo3(sam3, server_info->info3);
if (!info3) {
return NT_STATUS_NO_MEMORY;
status = copy_netr_SamInfo3(sam3,
server_info->info3,
&info3);
if (!NT_STATUS_IS_OK(status)) {
return status;
}

if (server_info->session_key.length) {
Expand Down Expand Up @@ -133,7 +139,8 @@ NTSTATUS serverinfo_to_SamInfo6(struct auth_serversupplied_info *server_info,
struct netr_SamInfo6 *sam6)
{
struct pdb_domain_info *dominfo;
struct netr_SamInfo3 *info3;
struct netr_SamInfo3 *info3 = NULL;
NTSTATUS status;

if ((pdb_capabilities() & PDB_CAP_ADS) == 0) {
DEBUG(10,("Not adding validation info level 6 "
Expand All @@ -146,9 +153,11 @@ NTSTATUS serverinfo_to_SamInfo6(struct auth_serversupplied_info *server_info,
return NT_STATUS_NO_MEMORY;
}

info3 = copy_netr_SamInfo3(sam6, server_info->info3);
if (!info3) {
return NT_STATUS_NO_MEMORY;
status = copy_netr_SamInfo3(sam6,
server_info->info3,
&info3);
if (!NT_STATUS_IS_OK(status)) {
return status;
}

if (server_info->session_key.length) {
Expand Down Expand Up @@ -335,11 +344,15 @@ NTSTATUS create_info3_from_pac_logon_info(TALLOC_CTX *mem_ctx,
struct netr_SamInfo3 **pp_info3)
{
NTSTATUS status;
struct netr_SamInfo3 *info3 = copy_netr_SamInfo3(mem_ctx,
&logon_info->info3);
if (info3 == NULL) {
return NT_STATUS_NO_MEMORY;
struct netr_SamInfo3 *info3 = NULL;

status = copy_netr_SamInfo3(mem_ctx,
&logon_info->info3,
&info3);
if (!NT_STATUS_IS_OK(status)) {
return status;
}

status = merge_resource_sids(logon_info, info3);
if (!NT_STATUS_IS_OK(status)) {
TALLOC_FREE(info3);
Expand Down
80 changes: 46 additions & 34 deletions source3/rpc_client/util_netlogon.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,53 +62,60 @@ NTSTATUS copy_netr_SamBaseInfo(TALLOC_CTX *mem_ctx,
return NT_STATUS_OK;
}

#undef RET_NOMEM

#define RET_NOMEM(ptr) do { \
if (!ptr) { \
TALLOC_FREE(info3); \
return NULL; \
} } while(0)

struct netr_SamInfo3 *copy_netr_SamInfo3(TALLOC_CTX *mem_ctx,
const struct netr_SamInfo3 *orig)
NTSTATUS copy_netr_SamInfo3(TALLOC_CTX *mem_ctx,
const struct netr_SamInfo3 *in,
struct netr_SamInfo3 **pout)
{
struct netr_SamInfo3 *info3;
struct netr_SamInfo3 *info3 = NULL;
unsigned int i;
NTSTATUS status;
NTSTATUS status = NT_STATUS_UNSUCCESSFUL;

info3 = talloc_zero(mem_ctx, struct netr_SamInfo3);
if (!info3) return NULL;
if (info3 == NULL) {
status = NT_STATUS_NO_MEMORY;
goto out;
}

status = copy_netr_SamBaseInfo(info3, &orig->base, &info3->base);
status = copy_netr_SamBaseInfo(info3, &in->base, &info3->base);
if (!NT_STATUS_IS_OK(status)) {
TALLOC_FREE(info3);
return NULL;
goto out;
}

if (orig->sidcount) {
info3->sidcount = orig->sidcount;
if (in->sidcount) {
info3->sidcount = in->sidcount;
info3->sids = talloc_array(info3, struct netr_SidAttr,
orig->sidcount);
RET_NOMEM(info3->sids);
for (i = 0; i < orig->sidcount; i++) {
in->sidcount);
if (info3->sids == NULL) {
status = NT_STATUS_NO_MEMORY;
goto out;
}

for (i = 0; i < in->sidcount; i++) {
info3->sids[i].sid = dom_sid_dup(info3->sids,
orig->sids[i].sid);
RET_NOMEM(info3->sids[i].sid);
info3->sids[i].attributes =
orig->sids[i].attributes;
in->sids[i].sid);
if (info3->sids[i].sid == NULL) {
status = NT_STATUS_NO_MEMORY;
goto out;
}
info3->sids[i].attributes = in->sids[i].attributes;
}
}

return info3;
*pout = info3;
info3 = NULL;

status = NT_STATUS_OK;
out:
TALLOC_FREE(info3);
return status;
}

NTSTATUS map_validation_to_info3(TALLOC_CTX *mem_ctx,
uint16_t validation_level,
union netr_Validation *validation,
struct netr_SamInfo3 **info3_p)
{
struct netr_SamInfo3 *info3;
struct netr_SamInfo3 *info3 = NULL;
struct netr_SamInfo6 *info6 = NULL;
NTSTATUS status;

Expand All @@ -122,10 +129,13 @@ NTSTATUS map_validation_to_info3(TALLOC_CTX *mem_ctx,
return NT_STATUS_INVALID_PARAMETER;
}

info3 = copy_netr_SamInfo3(mem_ctx, validation->sam3);
if (info3 == NULL) {
return NT_STATUS_NO_MEMORY;
status = copy_netr_SamInfo3(mem_ctx,
validation->sam3,
&info3);
if (!NT_STATUS_IS_OK(status)) {
return status;
}

break;
case 6:
if (validation->sam6 == NULL) {
Expand Down Expand Up @@ -186,16 +196,18 @@ NTSTATUS map_info3_to_validation(TALLOC_CTX *mem_ctx,
union netr_Validation **_validation)
{
union netr_Validation *validation = NULL;
NTSTATUS status;

validation = talloc_zero(mem_ctx, union netr_Validation);
if (validation == NULL) {
return NT_STATUS_NO_MEMORY;
}

validation->sam3 = copy_netr_SamInfo3(mem_ctx, info3);
if (validation->sam3 == NULL) {
TALLOC_FREE(validation);
return NT_STATUS_NO_MEMORY;
status = copy_netr_SamInfo3(mem_ctx,
info3,
&validation->sam3);
if (!NT_STATUS_IS_OK(status)) {
return status;
}

* _validation_level = 3;
Expand Down
5 changes: 3 additions & 2 deletions source3/rpc_client/util_netlogon.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@
NTSTATUS copy_netr_SamBaseInfo(TALLOC_CTX *mem_ctx,
const struct netr_SamBaseInfo *in,
struct netr_SamBaseInfo *out);
struct netr_SamInfo3 *copy_netr_SamInfo3(TALLOC_CTX *mem_ctx,
const struct netr_SamInfo3 *orig);
NTSTATUS copy_netr_SamInfo3(TALLOC_CTX *mem_ctx,
const struct netr_SamInfo3 *in,
struct netr_SamInfo3 **pout);
NTSTATUS map_validation_to_info3(TALLOC_CTX *mem_ctx,
uint16_t validation_level,
union netr_Validation *validation,
Expand Down
9 changes: 5 additions & 4 deletions source3/winbindd/winbindd_pam.c
Original file line number Diff line number Diff line change
Expand Up @@ -2916,10 +2916,11 @@ NTSTATUS winbindd_pam_auth_pac_send(struct winbindd_cli_state *state,
* returning a copy talloc'ed off
* the state->mem_ctx.
*/
info3_copy = copy_netr_SamInfo3(state->mem_ctx,
&logon_info->info3);
if (info3_copy == NULL) {
return NT_STATUS_NO_MEMORY;
result = copy_netr_SamInfo3(state->mem_ctx,
&logon_info->info3,
&info3_copy);
if (!NT_STATUS_IS_OK(result)) {
return result;
}
}
}
Expand Down

0 comments on commit 05ebafd

Please sign in to comment.