]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
winbind: Simplify winbindd_samr.c
authorVolker Lendecke <vl@samba.org>
Tue, 23 Feb 2021 21:09:24 +0000 (22:09 +0100)
committerJeremy Allison <jra@samba.org>
Tue, 16 Mar 2021 17:09:31 +0000 (17:09 +0000)
talloc_stackframe() panics on failure

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/winbindd/winbindd_samr.c

index f5c748edff16d346b3b3564fa23250a1a3200a4a..623195cb2795851b79ea9e986644c22036d8fe73 100644 (file)
@@ -225,7 +225,7 @@ static NTSTATUS sam_enum_dom_groups(struct winbindd_domain *domain,
        struct policy_handle dom_pol = { 0 };
        struct wb_acct_info *info = NULL;
        uint32_t num_info = 0;
-       TALLOC_CTX *tmp_ctx;
+       TALLOC_CTX *tmp_ctx = talloc_stackframe();
        NTSTATUS status;
        bool retry = false;
 
@@ -235,11 +235,6 @@ static NTSTATUS sam_enum_dom_groups(struct winbindd_domain *domain,
                *pnum_info = 0;
        }
 
-       tmp_ctx = talloc_stackframe();
-       if (tmp_ctx == NULL) {
-               return NT_STATUS_NO_MEMORY;
-       }
-
 again:
        status = open_cached_internal_pipe_conn(domain,
                                                &samr_pipe,
@@ -287,17 +282,12 @@ static NTSTATUS sam_query_user_list(struct winbindd_domain *domain,
        struct rpc_pipe_client *samr_pipe = NULL;
        struct policy_handle dom_pol = { 0 };
        uint32_t *rids = NULL;
-       TALLOC_CTX *tmp_ctx;
+       TALLOC_CTX *tmp_ctx = talloc_stackframe();
        NTSTATUS status;
        bool retry = false;
 
        DEBUG(3,("samr_query_user_list\n"));
 
-       tmp_ctx = talloc_stackframe();
-       if (tmp_ctx == NULL) {
-               return NT_STATUS_NO_MEMORY;
-       }
-
 again:
        status = open_cached_internal_pipe_conn(domain,
                                                &samr_pipe,
@@ -341,7 +331,7 @@ static NTSTATUS sam_trusted_domains(struct winbindd_domain *domain,
        struct policy_handle lsa_policy = { 0 };
        struct netr_DomainTrust *trusts = NULL;
        uint32_t num_trusts = 0;
-       TALLOC_CTX *tmp_ctx;
+       TALLOC_CTX *tmp_ctx = talloc_stackframe();
        NTSTATUS status;
        bool retry = false;
 
@@ -351,11 +341,6 @@ static NTSTATUS sam_trusted_domains(struct winbindd_domain *domain,
                ZERO_STRUCTP(ptrust_list);
        }
 
-       tmp_ctx = talloc_stackframe();
-       if (tmp_ctx == NULL) {
-               return NT_STATUS_NO_MEMORY;
-       }
-
 again:
        status = open_cached_internal_pipe_conn(domain,
                                                NULL,
@@ -409,7 +394,7 @@ static NTSTATUS sam_lookup_groupmem(struct winbindd_domain *domain,
        char **names = NULL;
        uint32_t *name_types = NULL;
 
-       TALLOC_CTX *tmp_ctx;
+       TALLOC_CTX *tmp_ctx = talloc_stackframe();
        NTSTATUS status;
        bool retry = false;
 
@@ -418,18 +403,14 @@ static NTSTATUS sam_lookup_groupmem(struct winbindd_domain *domain,
        /* Paranoia check */
        if (sid_check_is_in_builtin(group_sid) && (type != SID_NAME_ALIAS)) {
                /* There's no groups, only aliases in BUILTIN */
-               return NT_STATUS_NO_SUCH_GROUP;
+               status = NT_STATUS_NO_SUCH_GROUP;
+               goto done;
        }
 
        if (pnum_names) {
                *pnum_names = 0;
        }
 
-       tmp_ctx = talloc_stackframe();
-       if (tmp_ctx == NULL) {
-               return NT_STATUS_NO_MEMORY;
-       }
-
 again:
        status = open_cached_internal_pipe_conn(domain,
                                                &samr_pipe,
@@ -527,7 +508,7 @@ static NTSTATUS sam_enum_local_groups(struct winbindd_domain *domain,
        struct policy_handle dom_pol = { 0 };
        struct wb_acct_info *info = NULL;
        uint32_t num_info = 0;
-       TALLOC_CTX *tmp_ctx;
+       TALLOC_CTX *tmp_ctx = talloc_stackframe();
        NTSTATUS status;
        bool retry = false;
 
@@ -537,11 +518,6 @@ static NTSTATUS sam_enum_local_groups(struct winbindd_domain *domain,
                *pnum_info = 0;
        }
 
-       tmp_ctx = talloc_stackframe();
-       if (tmp_ctx == NULL) {
-               return NT_STATUS_NO_MEMORY;
-       }
-
 again:
        status = open_cached_internal_pipe_conn(domain,
                                                &samr_pipe,
@@ -595,17 +571,12 @@ static NTSTATUS sam_name_to_sid(struct winbindd_domain *domain,
        struct dom_sid sid;
        const char *dom_name;
        enum lsa_SidType type;
-       TALLOC_CTX *tmp_ctx;
+       TALLOC_CTX *tmp_ctx = talloc_stackframe();
        NTSTATUS status;
        bool retry = false;
 
        DEBUG(3,("sam_name_to_sid\n"));
 
-       tmp_ctx = talloc_stackframe();
-       if (tmp_ctx == NULL) {
-               return NT_STATUS_NO_MEMORY;
-       }
-
 again:
        status = open_cached_internal_pipe_conn(domain,
                                                NULL,
@@ -668,7 +639,7 @@ static NTSTATUS sam_sid_to_name(struct winbindd_domain *domain,
        char *domain_name = NULL;
        char *name = NULL;
        enum lsa_SidType type;
-       TALLOC_CTX *tmp_ctx;
+       TALLOC_CTX *tmp_ctx = talloc_stackframe();
        NTSTATUS status;
        bool retry = false;
 
@@ -688,12 +659,8 @@ static NTSTATUS sam_sid_to_name(struct winbindd_domain *domain,
                DEBUG(0, ("sam_sid_to_name: possible deadlock - trying to "
                          "lookup SID %s\n",
                          dom_sid_str_buf(sid, &buf)));
-               return NT_STATUS_NONE_MAPPED;
-       }
-
-       tmp_ctx = talloc_stackframe();
-       if (tmp_ctx == NULL) {
-               return NT_STATUS_NO_MEMORY;
+               status = NT_STATUS_NONE_MAPPED;
+               goto done;
        }
 
 again:
@@ -752,7 +719,7 @@ static NTSTATUS sam_rids_to_names(struct winbindd_domain *domain,
        enum lsa_SidType *types = NULL;
        char *domain_name = NULL;
        char **names = NULL;
-       TALLOC_CTX *tmp_ctx;
+       TALLOC_CTX *tmp_ctx = talloc_stackframe();
        NTSTATUS status;
        bool retry = false;
 
@@ -768,12 +735,8 @@ static NTSTATUS sam_rids_to_names(struct winbindd_domain *domain,
                DEBUG(0, ("sam_rids_to_names: possible deadlock - trying to "
                          "lookup SID %s\n",
                          dom_sid_str_buf(domain_sid, &buf)));
-               return NT_STATUS_NONE_MAPPED;
-       }
-
-       tmp_ctx = talloc_stackframe();
-       if (tmp_ctx == NULL) {
-               return NT_STATUS_NO_MEMORY;
+               status = NT_STATUS_NONE_MAPPED;
+               goto done;
        }
 
 again:
@@ -830,18 +793,13 @@ static NTSTATUS sam_lockout_policy(struct winbindd_domain *domain,
        struct rpc_pipe_client *samr_pipe;
        struct policy_handle dom_pol = { 0 };
        union samr_DomainInfo *info = NULL;
-       TALLOC_CTX *tmp_ctx;
+       TALLOC_CTX *tmp_ctx = talloc_stackframe();
        NTSTATUS status, result;
        struct dcerpc_binding_handle *b = NULL;
        bool retry = false;
 
        DEBUG(3,("sam_lockout_policy\n"));
 
-       tmp_ctx = talloc_stackframe();
-       if (tmp_ctx == NULL) {
-               return NT_STATUS_NO_MEMORY;
-       }
-
 again:
        status = open_cached_internal_pipe_conn(domain,
                                                &samr_pipe,
@@ -888,18 +846,13 @@ static NTSTATUS sam_password_policy(struct winbindd_domain *domain,
        struct rpc_pipe_client *samr_pipe;
        struct policy_handle dom_pol = { 0 };
        union samr_DomainInfo *info = NULL;
-       TALLOC_CTX *tmp_ctx;
+       TALLOC_CTX *tmp_ctx = talloc_stackframe();
        NTSTATUS status, result;
        struct dcerpc_binding_handle *b = NULL;
        bool retry = false;
 
        DEBUG(3,("sam_password_policy\n"));
 
-       tmp_ctx = talloc_stackframe();
-       if (tmp_ctx == NULL) {
-               return NT_STATUS_NO_MEMORY;
-       }
-
 again:
        status = open_cached_internal_pipe_conn(domain,
                                                &samr_pipe,
@@ -950,7 +903,7 @@ static NTSTATUS sam_lookup_usergroups(struct winbindd_domain *domain,
        struct policy_handle dom_pol;
        struct dom_sid *user_grpsids = NULL;
        uint32_t num_groups = 0;
-       TALLOC_CTX *tmp_ctx;
+       TALLOC_CTX *tmp_ctx = talloc_stackframe();
        NTSTATUS status;
        bool retry = false;
 
@@ -962,11 +915,6 @@ static NTSTATUS sam_lookup_usergroups(struct winbindd_domain *domain,
                *pnum_groups = 0;
        }
 
-       tmp_ctx = talloc_stackframe();
-       if (tmp_ctx == NULL) {
-               return NT_STATUS_NO_MEMORY;
-       }
-
 again:
        status = open_cached_internal_pipe_conn(domain,
                                                &samr_pipe,
@@ -1019,7 +967,7 @@ static NTSTATUS sam_lookup_useraliases(struct winbindd_domain *domain,
        struct policy_handle dom_pol = { 0 };
        uint32_t num_aliases = 0;
        uint32_t *alias_rids = NULL;
-       TALLOC_CTX *tmp_ctx;
+       TALLOC_CTX *tmp_ctx = talloc_stackframe();
        NTSTATUS status;
        bool retry = false;
 
@@ -1029,11 +977,6 @@ static NTSTATUS sam_lookup_useraliases(struct winbindd_domain *domain,
                *pnum_aliases = 0;
        }
 
-       tmp_ctx = talloc_stackframe();
-       if (tmp_ctx == NULL) {
-               return NT_STATUS_NO_MEMORY;
-       }
-
 again:
        status = open_cached_internal_pipe_conn(domain,
                                                &samr_pipe,
@@ -1082,7 +1025,7 @@ static NTSTATUS sam_sequence_number(struct winbindd_domain *domain,
        struct rpc_pipe_client *samr_pipe;
        struct policy_handle dom_pol = { 0 };
        uint32_t seq = DOM_SEQUENCE_NONE;
-       TALLOC_CTX *tmp_ctx;
+       TALLOC_CTX *tmp_ctx = talloc_stackframe();
        NTSTATUS status;
        bool retry = false;
 
@@ -1092,11 +1035,6 @@ static NTSTATUS sam_sequence_number(struct winbindd_domain *domain,
                *pseq = DOM_SEQUENCE_NONE;
        }
 
-       tmp_ctx = talloc_stackframe();
-       if (tmp_ctx == NULL) {
-               return NT_STATUS_NO_MEMORY;
-       }
-
 again:
        status = open_cached_internal_pipe_conn(domain,
                                                &samr_pipe,