r11407: Push 'recreate account' logic into libnet/libnet_join.c. We don't
authorAndrew Bartlett <abartlet@samba.org>
Mon, 31 Oct 2005 03:03:32 +0000 (03:03 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:45:32 +0000 (13:45 -0500)
return the pesky USER_EXISTS 'error' code any more, and it is much
easier to handle this inline.

Andrew Bartlett
(This used to be commit a7eb796cf544db3fe16986d8e233d2defe7a7d1b)

source4/libnet/libnet_join.c
source4/libnet/libnet_join.h
source4/torture/rpc/testjoin.c

index daa840f76e52e1417cba20319179b1a15a8b969c..a438c5962df4e17ab17964a9eb233fbe0d2f1220 100644 (file)
@@ -144,9 +144,9 @@ static NTSTATUS libnet_JoinSite(struct libnet_context *ctx,
        if (rtn != 0) {
                libnet_r->out.error_string
                        = talloc_asprintf(libnet_r,
-                               "Failed to add server entry %s: %s.",
+                               "Failed to add server entry %s: %s: %d",
                                server_dn_str,
-                               ldb_errstring(remote_ldb));
+                                         ldb_errstring(remote_ldb), rtn);
                talloc_free(tmp_ctx);
                return NT_STATUS_INTERNAL_DB_CORRUPTION;
        }
@@ -881,6 +881,36 @@ NTSTATUS libnet_JoinDomain(struct libnet_context *ctx, TALLOC_CTX *mem_ctx, stru
                        talloc_free(tmp_ctx);
                        return status;
                }
+
+               if (r->in.recreate_account) {
+                       struct samr_DeleteUser d;
+                       d.in.user_handle = u_handle;
+                       d.out.user_handle = u_handle;
+                       status = dcerpc_samr_DeleteUser(samr_pipe, mem_ctx, &d);
+                       if (!NT_STATUS_IS_OK(status)) {
+                               r->out.error_string = talloc_asprintf(mem_ctx,
+                                                                     "samr_DeleteUser (for recreate) of [%s] failed: %s",
+                                                                     r->in.account_name,
+                                                                     nt_errstr(status));
+                               talloc_free(tmp_ctx);
+                               return status;
+                       }
+
+                       /* We want to recreate, so delete and another samr_CreateUser2 */
+                       
+                       /* &cu filled in above */
+                       cu_status = dcerpc_samr_CreateUser2(samr_pipe, tmp_ctx, &cu);                   
+                       status = cu_status;
+                       if (!NT_STATUS_IS_OK(status) && !NT_STATUS_EQUAL(status, NT_STATUS_USER_EXISTS)) {
+                               r->out.error_string = talloc_asprintf(mem_ctx,
+                                                                     "samr_CreateUser2 (recreate) for [%s] failed: %s\n",
+                                                                     r->in.domain_name, nt_errstr(status));
+                               talloc_free(tmp_ctx);
+                               return status;
+                       }
+                       DEBUG(0, ("Recreated account in domain %s\n", domain_name));
+
+               }
        }
        /* Find out what password policy this user has */
        pwp.in.user_handle = u_handle;
@@ -1093,6 +1123,7 @@ static NTSTATUS libnet_Join_primary_domain(struct libnet_context *ctx,
        r2->in.netbios_name     = netbios_name;
        r2->in.level            = LIBNET_JOINDOMAIN_AUTOMATIC;
        r2->in.acct_type        = acct_type;
+       r2->in.recreate_account = False;
        status = libnet_JoinDomain(ctx, r2, r2);
        if (!NT_STATUS_IS_OK(status)) {
                r->out.error_string = talloc_steal(mem_ctx, r2->out.error_string);
index a08147b6d66c46fc1c6c2d3dd71888bcd3244cac..d1ddc623f00f069a840b80cd1fdb984bff680a7b 100644 (file)
@@ -40,6 +40,7 @@ struct libnet_JoinDomain {
                const char *binding;
                enum libnet_JoinDomain_level level;
                uint32_t  acct_type;
+               BOOL recreate_account;
        } in;
 
        struct {
index d0b1e5c9bf69a78cff9efbca97d44d1debe1e8af..66cb4a42c14ee1dca207a3ded47e9f3299a1cc80 100644 (file)
@@ -319,21 +319,6 @@ struct test_join *torture_join_domain(const char *machine_name,
        libnet_r->in.recreate_account = True;
 
        status = libnet_JoinDomain(libnet_ctx, libnet_r, libnet_r);
-       if (NT_STATUS_EQUAL(status, NT_STATUS_USER_EXISTS)) {
-               struct samr_DeleteUser d;
-               d.in.user_handle = libnet_r->out.user_handle;
-               d.out.user_handle = libnet_r->out.user_handle;
-               
-               /* Delete machine account */
-               status = dcerpc_samr_DeleteUser(libnet_r->out.samr_pipe, tj, &d);
-               if (!NT_STATUS_IS_OK(status)) {
-                       printf("Delete of machine account failed\n");
-               } else {
-                       printf("Delete of machine account was successful.\n");
-               }
-               status = libnet_JoinDomain(libnet_ctx, libnet_r, libnet_r);
-       }
-
        if (!NT_STATUS_IS_OK(status)) {
                if (libnet_r->out.error_string) {
                        DEBUG(0, ("Domain join failed - %s.\n", libnet_r->out.error_string));