samba-cvs.cvs
[Top] [All Lists]

[SCM] Samba Shared Repository - branch v3-3-test updated - release-3-2-0

Subject: [SCM] Samba Shared Repository - branch v3-3-test updated - release-3-2-0pre2-2881-ge0b1172
From: Günther Deschner
Date: Tue, 17 Jun 2008 12:55:48 -0500 CDT
The branch, v3-3-test has been updated
       via  e0b117200441f842fbc11cc817ab2cde4d63a22e (commit)
       via  7e7f07ec59d23e909809ed32adc8fc399826310d (commit)
      from  cb7ace209c2051ae02647188715fa6ee324c2bf6 (commit)

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=v3-3-test


- Log -----------------------------------------------------------------
commit e0b117200441f842fbc11cc817ab2cde4d63a22e
Author: Günther Deschner <gd@xxxxxxxxx>
Date:   Tue Jun 17 19:49:58 2008 +0200

    net_vampire: add error and result_message to samsync_context.
    
    Guenther

commit 7e7f07ec59d23e909809ed32adc8fc399826310d
Author: Günther Deschner <gd@xxxxxxxxx>
Date:   Tue Jun 17 18:02:03 2008 +0200

    net_vampire: add domain_name to samsync_context.
    
    Guenther

-----------------------------------------------------------------------

Summary of changes:
 source/libnet/libnet_proto.h        |    1 +
 source/libnet/libnet_samsync.c      |   70 ++++++++++++++++++++++++-----------
 source/libnet/libnet_samsync.h      |    5 ++
 source/libnet/libnet_samsync_ldif.c |    7 +++-
 source/utils/net_rpc_samsync.c      |   51 +++++++++++++++----------
 5 files changed, 91 insertions(+), 43 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source/libnet/libnet_proto.h b/source/libnet/libnet_proto.h
index eeb4a72..b30b94a 100644
--- a/source/libnet/libnet_proto.h
+++ b/source/libnet/libnet_proto.h
@@ -52,6 +52,7 @@ NTSTATUS samsync_fix_delta_array(TALLOC_CTX *mem_ctx,
                                 struct netr_DELTA_ENUM_ARRAY *r);
 NTSTATUS samsync_init_context(TALLOC_CTX *mem_ctx,
                              const struct dom_sid *domain_sid,
+                             const char *domain_name,
                              enum net_samsync_mode mode,
                              struct samsync_context **ctx_p);
 NTSTATUS samsync_process_database(struct rpc_pipe_client *pipe_hnd,
diff --git a/source/libnet/libnet_samsync.c b/source/libnet/libnet_samsync.c
index 3c6a87a..c86c5c1 100644
--- a/source/libnet/libnet_samsync.c
+++ b/source/libnet/libnet_samsync.c
@@ -193,6 +193,7 @@ NTSTATUS samsync_fix_delta_array(TALLOC_CTX *mem_ctx,
 
 NTSTATUS samsync_init_context(TALLOC_CTX *mem_ctx,
                              const struct dom_sid *domain_sid,
+                             const char *domain_name,
                              enum net_samsync_mode mode,
                              struct samsync_context **ctx_p)
 {
@@ -205,6 +206,9 @@ NTSTATUS samsync_init_context(TALLOC_CTX *mem_ctx,
 
        ctx->mode = mode;
 
+       ctx->domain_name = talloc_strdup(mem_ctx, domain_name);
+       NT_STATUS_HAVE_NO_MEMORY(ctx->domain_name);
+
        if (domain_sid) {
                ctx->domain_sid = sid_dup_talloc(mem_ctx, domain_sid);
                NT_STATUS_HAVE_NO_MEMORY(ctx->domain_sid);
@@ -219,6 +223,25 @@ NTSTATUS samsync_init_context(TALLOC_CTX *mem_ctx,
 }
 
 /**
+ * samsync_database_str
+ */
+
+static const char *samsync_database_str(enum netr_SamDatabaseID database_id)
+{
+
+       switch (database_id) {
+               case SAM_DATABASE_DOMAIN:
+                       return "DOMAIN";
+               case SAM_DATABASE_BUILTIN:
+                       return "BUILTIN";
+               case SAM_DATABASE_PRIVS:
+                       return "PRIVS";
+               default:
+                       return "unknown";
+       }
+}
+
+/**
  * samsync_debug_str
  */
 
@@ -227,7 +250,6 @@ static const char *samsync_debug_str(TALLOC_CTX *mem_ctx,
                                     enum netr_SamDatabaseID database_id)
 {
        const char *action = NULL;
-       const char *str = NULL;
 
        switch (mode) {
                case NET_SAMSYNC_MODE_DUMP:
@@ -244,26 +266,8 @@ static const char *samsync_debug_str(TALLOC_CTX *mem_ctx,
                        break;
        }
 
-       switch (database_id) {
-               case SAM_DATABASE_DOMAIN:
-                       str = talloc_asprintf(mem_ctx, "%s DOMAIN database",
-                               action);
-                       break;
-               case SAM_DATABASE_BUILTIN:
-                       str = talloc_asprintf(mem_ctx, "%s BUILTIN database",
-                               action);
-                       break;
-               case SAM_DATABASE_PRIVS:
-                       str = talloc_asprintf(mem_ctx, "%s PRIVS database",
-                               action);
-                       break;
-               default:
-                       str = talloc_asprintf(mem_ctx, "%s unknown database 
type %u",
-                               action, database_id);
-                       break;
-       }
-
-       return str;
+       return talloc_asprintf(mem_ctx, "%s %s database",
+                               action, samsync_database_str(database_id));
 }
 
 /**
@@ -299,6 +303,7 @@ NTSTATUS samsync_process_database(struct rpc_pipe_client 
*pipe_hnd,
 
        do {
                struct netr_DELTA_ENUM_ARRAY *delta_enum_array = NULL;
+               NTSTATUS callback_status;
 
                netlogon_creds_client_step(pipe_hnd->dc, &credential);
 
@@ -336,7 +341,11 @@ NTSTATUS samsync_process_database(struct rpc_pipe_client 
*pipe_hnd,
                                        delta_enum_array);
 
                /* Process results */
-               callback_fn(mem_ctx, database_id, delta_enum_array, result, 
ctx);
+               callback_status = callback_fn(mem_ctx, database_id, 
delta_enum_array, result, ctx);
+               if (!NT_STATUS_IS_OK(callback_status)) {
+                       result = callback_status;
+                       goto out;
+               }
 
                TALLOC_FREE(delta_enum_array);
 
@@ -345,6 +354,23 @@ NTSTATUS samsync_process_database(struct rpc_pipe_client 
*pipe_hnd,
 
        } while (NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES));
 
+ out:
+       if (NT_STATUS_IS_ERR(result) && !ctx->error_message) {
+
+               ctx->error_message = talloc_asprintf(ctx,
+                       "Failed to fetch %s database: %s",
+                       samsync_database_str(database_id),
+                       nt_errstr(result));
+
+               if (NT_STATUS_EQUAL(result, NT_STATUS_NOT_SUPPORTED)) {
+
+                       ctx->error_message =
+                               talloc_asprintf_append(ctx->error_message,
+                                       "\nPerhaps %s is a Windows native mode 
domain?",
+                                       ctx->domain_name);
+               }
+       }
+
        talloc_destroy(mem_ctx);
 
        return result;
diff --git a/source/libnet/libnet_samsync.h b/source/libnet/libnet_samsync.h
index 38ef9c5..bd64c24 100644
--- a/source/libnet/libnet_samsync.h
+++ b/source/libnet/libnet_samsync.h
@@ -28,7 +28,12 @@ struct samsync_context {
        enum net_samsync_mode mode;
        const struct dom_sid *domain_sid;
        const char *domain_sid_str;
+       const char *domain_name;
        const char *output_filename;
+
+       char *result_message;
+       char *error_message;
+
        void *private_data;
 };
 
diff --git a/source/libnet/libnet_samsync_ldif.c 
b/source/libnet/libnet_samsync_ldif.c
index 86de2ab..60acb7d 100644
--- a/source/libnet/libnet_samsync_ldif.c
+++ b/source/libnet/libnet_samsync_ldif.c
@@ -1186,7 +1186,7 @@ NTSTATUS fetch_sam_entries_ldif(TALLOC_CTX *mem_ctx,
        for (i = 0; i < r->num_deltas; i++) {
                status = fetch_sam_entry_ldif(mem_ctx, database_id,
                                              &r->delta_enum[i], ctx,
-                                             &g_index, &a_index);
+                                             &a_index, &g_index);
                if (!NT_STATUS_IS_OK(status)) {
                        goto failed;
                }
@@ -1195,6 +1195,11 @@ NTSTATUS fetch_sam_entries_ldif(TALLOC_CTX *mem_ctx,
        /* This was the last query */
        if (NT_STATUS_IS_OK(result)) {
                ldif_write_output(database_id, ldif_ctx);
+               if (ldif_ctx->ldif_file != stdout) {
+                       ctx->result_message = talloc_asprintf(mem_ctx,
+                               "Vampired %d accounts and %d groups to %s",
+                               a_index, g_index, ctx->output_filename);
+               }
                ldif_free_context(ldif_ctx);
                ctx->private_data = NULL;
        }
diff --git a/source/utils/net_rpc_samsync.c b/source/utils/net_rpc_samsync.c
index 90637e2..5161bb3 100644
--- a/source/utils/net_rpc_samsync.c
+++ b/source/utils/net_rpc_samsync.c
@@ -354,6 +354,7 @@ NTSTATUS rpc_samdump_internals(struct net_context *c,
 
        status = samsync_init_context(mem_ctx,
                                      domain_sid,
+                                     domain_name,
                                      NET_SAMSYNC_MODE_DUMP,
                                      &ctx);
        if (!NT_STATUS_IS_OK(status)) {
@@ -1173,6 +1174,7 @@ NTSTATUS rpc_vampire_internals(struct net_context *c,
 
        result = samsync_init_context(mem_ctx,
                                      domain_sid,
+                                     domain_name,
                                      NET_SAMSYNC_MODE_FETCH_PASSDB,
                                      &ctx);
        if (!NT_STATUS_IS_OK(result)) {
@@ -1197,29 +1199,33 @@ NTSTATUS rpc_vampire_internals(struct net_context *c,
        /* fetch domain */
        result = samsync_process_database(pipe_hnd, SAM_DATABASE_DOMAIN,
                                          fetch_sam_entries, ctx);
-       if (!NT_STATUS_IS_OK(result)) {
-               d_fprintf(stderr, "Failed to fetch domain database: %s\n",
-                         nt_errstr(result));
-               if (NT_STATUS_EQUAL(result, NT_STATUS_NOT_SUPPORTED))
-                       d_fprintf(stderr, "Perhaps %s is a Windows 2000 "
-                                 "native mode domain?\n", domain_name);
+
+       if (!NT_STATUS_IS_OK(result) && ctx->error_message) {
+               d_fprintf(stderr, "%s\n", ctx->error_message);
                goto fail;
        }
 
+       if (ctx->result_message) {
+               d_fprintf(stdout, "%s\n", ctx->result_message);
+       }
+
        /* fetch builtin */
        ctx->domain_sid = sid_dup_talloc(mem_ctx, &global_sid_Builtin);
        ctx->domain_sid_str = sid_string_talloc(mem_ctx, ctx->domain_sid);
        result = samsync_process_database(pipe_hnd, SAM_DATABASE_BUILTIN,
                                          fetch_sam_entries, ctx);
-       if (!NT_STATUS_IS_OK(result)) {
-               d_fprintf(stderr, "Failed to fetch builtin database: %s\n",
-                         nt_errstr(result));
+
+       if (!NT_STATUS_IS_OK(result) && ctx->error_message) {
+               d_fprintf(stderr, "%s\n", ctx->error_message);
                goto fail;
        }
 
-       TALLOC_FREE(ctx);
+       if (ctx->result_message) {
+               d_fprintf(stdout, "%s\n", ctx->result_message);
+       }
 
  fail:
+       TALLOC_FREE(ctx);
        return result;
 }
 
@@ -1237,6 +1243,7 @@ NTSTATUS rpc_vampire_ldif_internals(struct net_context *c,
 
        status = samsync_init_context(mem_ctx,
                                      domain_sid,
+                                     domain_name,
                                      NET_SAMSYNC_MODE_FETCH_LDIF,
                                      &ctx);
        if (!NT_STATUS_IS_OK(status)) {
@@ -1250,29 +1257,33 @@ NTSTATUS rpc_vampire_ldif_internals(struct net_context 
*c,
        /* fetch domain */
        status = samsync_process_database(pipe_hnd, SAM_DATABASE_DOMAIN,
                                          fetch_sam_entries_ldif, ctx);
-       if (!NT_STATUS_IS_OK(status)) {
-               d_fprintf(stderr, "Failed to fetch domain database: %s\n",
-                         nt_errstr(status));
-               if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_SUPPORTED))
-                       d_fprintf(stderr, "Perhaps %s is a Windows 2000 "
-                                 "native mode domain?\n", domain_name);
+
+       if (!NT_STATUS_IS_OK(status) && ctx->error_message) {
+               d_fprintf(stderr, "%s\n", ctx->error_message);
                goto fail;
        }
 
+       if (ctx->result_message) {
+               d_fprintf(stdout, "%s\n", ctx->result_message);
+       }
+
        /* fetch builtin */
        ctx->domain_sid = sid_dup_talloc(mem_ctx, &global_sid_Builtin);
        ctx->domain_sid_str = sid_string_talloc(mem_ctx, ctx->domain_sid);
        status = samsync_process_database(pipe_hnd, SAM_DATABASE_BUILTIN,
                                          fetch_sam_entries_ldif, ctx);
-       if (!NT_STATUS_IS_OK(status)) {
-               d_fprintf(stderr, "Failed to fetch builtin database: %s\n",
-                         nt_errstr(status));
+
+       if (!NT_STATUS_IS_OK(status) && ctx->error_message) {
+               d_fprintf(stderr, "%s\n", ctx->error_message);
                goto fail;
        }
 
-       TALLOC_FREE(ctx);
+       if (ctx->result_message) {
+               d_fprintf(stdout, "%s\n", ctx->result_message);
+       }
 
  fail:
+       TALLOC_FREE(ctx);
        return status;
 }
 


-- 
Samba Shared Repository

<Prev in Thread] Current Thread [Next in Thread>
  • [SCM] Samba Shared Repository - branch v3-3-test updated - release-3-2-0pre2-2881-ge0b1172, Günther Deschner <=