libnet4: Use dom_sid_str_buf
authorVolker Lendecke <vl@samba.org>
Sun, 16 Dec 2018 16:24:36 +0000 (17:24 +0100)
committerJeremy Allison <jra@samba.org>
Tue, 8 Jan 2019 02:40:28 +0000 (03:40 +0100)
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source4/libnet/libnet_join.c
source4/libnet/libnet_samdump.c
source4/libnet/libnet_samsync_ldb.c

index 245485f..825a815 100644 (file)
@@ -610,10 +610,13 @@ NTSTATUS libnet_JoinDomain(struct libnet_context *ctx, TALLOC_CTX *mem_ctx, stru
                status = od.out.result;
        }
        if (!NT_STATUS_IS_OK(status)) {
-               r->out.error_string = talloc_asprintf(mem_ctx,
-                                                     "samr_OpenDomain for [%s] failed: %s",
-                                                     dom_sid_string(tmp_ctx, connect_with_info->out.domain_sid),
-                                                     nt_errstr(status));
+               struct dom_sid_buf buf;
+               r->out.error_string = talloc_asprintf(
+                       mem_ctx,
+                       "samr_OpenDomain for [%s] failed: %s",
+                       dom_sid_str_buf(connect_with_info->out.domain_sid,
+                                       &buf),
+                       nt_errstr(status));
                talloc_free(tmp_ctx);
                return status;
        }
index 326d804..097a6ef 100644 (file)
@@ -183,6 +183,7 @@ NTSTATUS libnet_SamDump(struct libnet_context *ctx, TALLOC_CTX *mem_ctx,
                for (s=samdump_state->secrets; s; s=s->next) {
                        size_t converted_size = 0;
                        char *secret_string;
+                       struct dom_sid_buf buf;
                        if (strcasecmp_m(s->name, secret_name) != 0) {
                                continue;
                        }
@@ -196,7 +197,8 @@ NTSTATUS libnet_SamDump(struct libnet_context *ctx, TALLOC_CTX *mem_ctx,
                                return NT_STATUS_INVALID_PARAMETER;
                        }
                        printf("%s\t%s\t%s\n", 
-                              t->name, dom_sid_string(mem_ctx, t->sid), 
+                              t->name,
+                              dom_sid_str_buf(t->sid, &buf),
                               secret_string);
                }
        }
index 9ea7dce..3171138 100644 (file)
@@ -71,7 +71,7 @@ static NTSTATUS samsync_ldb_add_foreignSecurityPrincipal(TALLOC_CTX *mem_ctx,
                                                         struct ldb_dn **fsp_dn,
                                                         char **error_string)
 {
-       const char *sidstr = dom_sid_string(mem_ctx, sid);
+       struct dom_sid_buf buf;
        /* We assume that ForeignSecurityPrincipals are under the BASEDN of the main domain */
        struct ldb_dn *basedn = samdb_search_dn(state->sam_ldb, mem_ctx,
                                                state->base_dn[SAM_DATABASE_DOMAIN],
@@ -79,10 +79,6 @@ static NTSTATUS samsync_ldb_add_foreignSecurityPrincipal(TALLOC_CTX *mem_ctx,
        struct ldb_message *msg;
        int ret;
 
-       if (!sidstr) {
-               return NT_STATUS_NO_MEMORY;
-       }
-
        if (basedn == NULL) {
                *error_string = talloc_asprintf(mem_ctx, 
                                                "Failed to find DN for "
@@ -98,7 +94,8 @@ static NTSTATUS samsync_ldb_add_foreignSecurityPrincipal(TALLOC_CTX *mem_ctx,
 
        /* add core elements to the ldb_message for the alias */
        msg->dn = basedn;
-       if ( ! ldb_dn_add_child_fmt(msg->dn, "CN=%s", sidstr))
+       if ( ! ldb_dn_add_child_fmt(
+                    msg->dn, "CN=%s", dom_sid_str_buf(sid, &buf)))
                return NT_STATUS_UNSUCCESSFUL;
        
        ldb_msg_add_string(msg, "objectClass", "foreignSecurityPrincipal");
@@ -973,20 +970,15 @@ static NTSTATUS samsync_ldb_handle_account(TALLOC_CTX *mem_ctx,
        struct ldb_message *msg;
        int ret;
        uint32_t i;
-       char *dnstr, *sidstr;
+       char *dnstr;
+       struct dom_sid_buf buf;
 
        msg = ldb_msg_new(mem_ctx);
        if (msg == NULL) {
                return NT_STATUS_NO_MEMORY;
        }
 
-       sidstr = dom_sid_string(msg, sid);
-       if (sidstr == NULL) {
-               TALLOC_FREE(msg);
-               return NT_STATUS_NO_MEMORY;
-       }
-
-       dnstr = talloc_asprintf(msg, "sid=%s", sidstr);
+       dnstr = talloc_asprintf(msg, "sid=%s", dom_sid_str_buf(sid, &buf));
        if (dnstr == NULL) {
                TALLOC_FREE(msg);
                return NT_STATUS_NO_MEMORY;
@@ -1050,8 +1042,11 @@ static NTSTATUS samsync_ldb_delete_account(TALLOC_CTX *mem_ctx,
        } else if (ret == 0) {
                return NT_STATUS_NO_SUCH_USER;
        } else if (ret > 1) {
-               *error_string = talloc_asprintf(mem_ctx, "More than one account with SID: %s", 
-                                               dom_sid_string(mem_ctx, sid));
+               struct dom_sid_buf buf;
+               *error_string = talloc_asprintf(
+                       mem_ctx,
+                       "More than one account with SID: %s",
+                       dom_sid_str_buf(sid, &buf));
                return NT_STATUS_INTERNAL_DB_CORRUPTION;
        } else {
                msg->dn = talloc_steal(msg, msgs[0]->dn);