return NT_STATUS_OK;
}
+/**
+ * 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
*/
enum netr_SamDatabaseID database_id)
{
const char *action = NULL;
- const char *str = NULL;
switch (mode) {
case NET_SAMSYNC_MODE_DUMP:
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));
}
/**
do {
struct netr_DELTA_ENUM_ARRAY *delta_enum_array = NULL;
+ NTSTATUS callback_status;
netlogon_creds_client_step(pipe_hnd->dc, &credential);
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);
} 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;
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;
}
/* 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;
}
/* 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;
}
/* 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;
}