summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGünther Deschner <gd@samba.org>2008-06-17 19:49:58 +0200
committerGünther Deschner <gd@samba.org>2008-06-17 19:55:16 +0200
commitfefcb70f870cae351d29a937df674db8c4ee9abe (patch)
tree7834142cc66f48f796f5641302d4ff8e438ed1df
parent49b269f50fc2fc2817bdee97e9670b8579113060 (diff)
downloadsamba-fefcb70f870cae351d29a937df674db8c4ee9abe.tar.gz
samba-fefcb70f870cae351d29a937df674db8c4ee9abe.tar.bz2
samba-fefcb70f870cae351d29a937df674db8c4ee9abe.zip
net_vampire: add error and result_message to samsync_context.
Guenther (This used to be commit e0b117200441f842fbc11cc817ab2cde4d63a22e)
-rw-r--r--source3/libnet/libnet_samsync.c66
-rw-r--r--source3/libnet/libnet_samsync.h4
-rw-r--r--source3/libnet/libnet_samsync_ldif.c7
-rw-r--r--source3/utils/net_rpc_samsync.c48
4 files changed, 82 insertions, 43 deletions
diff --git a/source3/libnet/libnet_samsync.c b/source3/libnet/libnet_samsync.c
index b5632aed69..c86c5c12e1 100644
--- a/source3/libnet/libnet_samsync.c
+++ b/source3/libnet/libnet_samsync.c
@@ -223,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
*/
@@ -231,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:
@@ -248,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));
}
/**
@@ -303,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);
@@ -340,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);
@@ -349,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/source3/libnet/libnet_samsync.h b/source3/libnet/libnet_samsync.h
index 1e3995614f..bd64c24d93 100644
--- a/source3/libnet/libnet_samsync.h
+++ b/source3/libnet/libnet_samsync.h
@@ -30,6 +30,10 @@ struct samsync_context {
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/source3/libnet/libnet_samsync_ldif.c b/source3/libnet/libnet_samsync_ldif.c
index 86de2ab253..60acb7db40 100644
--- a/source3/libnet/libnet_samsync_ldif.c
+++ b/source3/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/source3/utils/net_rpc_samsync.c b/source3/utils/net_rpc_samsync.c
index 797598c48e..5161bb3ef5 100644
--- a/source3/utils/net_rpc_samsync.c
+++ b/source3/utils/net_rpc_samsync.c
@@ -1199,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;
}
@@ -1253,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;
}