s3:rpc_client: Clenup copy_netr_SamInfo3() code
authorAndreas Schneider <asn@samba.org>
Thu, 11 Jan 2018 08:06:31 +0000 (09:06 +0100)
committerAndreas Schneider <asn@cryptomilk.org>
Mon, 15 Jan 2018 21:16:13 +0000 (22:16 +0100)
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 <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org>
Autobuild-Date(master): Mon Jan 15 22:16:13 CET 2018 on sn-devel-144

source3/auth/auth_util.c
source3/auth/server_info.c
source3/rpc_client/util_netlogon.c
source3/rpc_client/util_netlogon.h
source3/winbindd/winbindd_pam.c

index 5bb5a69dfa7c808677e588a20694feb9d3bff607..f543b33eead379abb7f6e82974677014538bcf53 100644 (file)
@@ -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) {
@@ -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;
        }
@@ -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;
        }
 
index 20d43d237fa6ebbb555c9a4a090e0964e6d0cbc0..789817512860a4a0bddff0c9f4d342c0a2bf5c36 100644 (file)
@@ -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) {
@@ -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) {
@@ -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 "
@@ -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) {
@@ -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);
index ac804f8419660e3ecbf83ca0c75f46becd4a0f0c..15c769ffe41b7c8fef88a306c2730941419bc43c 100644 (file)
@@ -62,45 +62,52 @@ 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,
@@ -108,7 +115,7 @@ NTSTATUS map_validation_to_info3(TALLOC_CTX *mem_ctx,
                                 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;
 
@@ -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) {
@@ -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;
index 80c7bff99d1837947f77dc52f1e84b6c6fd85143..8b3a372ee8e411edd2fecc5e5bc59601ddf6b3f5 100644 (file)
@@ -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,
index 01d08c1e2b398b65350f141ee1a38ed839922dc8..9a61cd3a5782ac317dd99ef2be2bfeec37f390ee 100644 (file)
@@ -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;
                        }
                }
        }