summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source3/libnet/libnet_proto.h6
-rw-r--r--source3/libnet/libnet_samsync.c24
-rw-r--r--source3/libnet/libnet_samsync.h16
-rw-r--r--source3/utils/net_rpc_samsync.c56
4 files changed, 48 insertions, 54 deletions
diff --git a/source3/libnet/libnet_proto.h b/source3/libnet/libnet_proto.h
index ba73a3e8bc..2440cd3c7f 100644
--- a/source3/libnet/libnet_proto.h
+++ b/source3/libnet/libnet_proto.h
@@ -47,12 +47,8 @@ _PUBLIC_ void ndr_print_libnet_UnjoinCtx(struct ndr_print *ndr, const char *name
NTSTATUS libnet_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 libnet_samsync(struct rpc_pipe_client *pipe_hnd,
- enum netr_SamDatabaseID database_id,
- samsync_fn_t callback_fn,
+NTSTATUS libnet_samsync(enum netr_SamDatabaseID database_id,
struct samsync_context *ctx);
NTSTATUS pull_netr_AcctLockStr(TALLOC_CTX *mem_ctx,
struct lsa_BinaryString *r,
diff --git a/source3/libnet/libnet_samsync.c b/source3/libnet/libnet_samsync.c
index 7dd47b6399..e170acc560 100644
--- a/source3/libnet/libnet_samsync.c
+++ b/source3/libnet/libnet_samsync.c
@@ -193,8 +193,6 @@ static NTSTATUS samsync_fix_delta_array(TALLOC_CTX *mem_ctx,
NTSTATUS libnet_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)
{
struct samsync_context *ctx;
@@ -204,11 +202,6 @@ NTSTATUS libnet_samsync_init_context(TALLOC_CTX *mem_ctx,
ctx = TALLOC_ZERO_P(mem_ctx, struct samsync_context);
NT_STATUS_HAVE_NO_MEMORY(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);
@@ -274,14 +267,12 @@ static const char *samsync_debug_str(TALLOC_CTX *mem_ctx,
* libnet_samsync
*/
-NTSTATUS libnet_samsync(struct rpc_pipe_client *pipe_hnd,
- enum netr_SamDatabaseID database_id,
- samsync_fn_t callback_fn,
+NTSTATUS libnet_samsync(enum netr_SamDatabaseID database_id,
struct samsync_context *ctx)
{
NTSTATUS result;
TALLOC_CTX *mem_ctx;
- const char *logon_server = pipe_hnd->desthost;
+ const char *logon_server = ctx->cli->desthost;
const char *computername = global_myname();
struct netr_Authenticator credential;
struct netr_Authenticator return_authenticator;
@@ -305,9 +296,9 @@ NTSTATUS libnet_samsync(struct rpc_pipe_client *pipe_hnd,
struct netr_DELTA_ENUM_ARRAY *delta_enum_array = NULL;
NTSTATUS callback_status;
- netlogon_creds_client_step(pipe_hnd->dc, &credential);
+ netlogon_creds_client_step(ctx->cli->dc, &credential);
- result = rpccli_netr_DatabaseSync2(pipe_hnd, mem_ctx,
+ result = rpccli_netr_DatabaseSync2(ctx->cli, mem_ctx,
logon_server,
computername,
&credential,
@@ -322,7 +313,7 @@ NTSTATUS libnet_samsync(struct rpc_pipe_client *pipe_hnd,
}
/* Check returned credentials. */
- if (!netlogon_creds_client_check(pipe_hnd->dc,
+ if (!netlogon_creds_client_check(ctx->cli->dc,
&return_authenticator.cred)) {
DEBUG(0,("credentials chain check failed\n"));
return NT_STATUS_ACCESS_DENIED;
@@ -332,7 +323,7 @@ NTSTATUS libnet_samsync(struct rpc_pipe_client *pipe_hnd,
break;
}
- session_key = data_blob_const(pipe_hnd->dc->sess_key, 16);
+ session_key = data_blob_const(ctx->cli->dc->sess_key, 16);
samsync_fix_delta_array(mem_ctx,
&session_key,
@@ -341,7 +332,8 @@ NTSTATUS libnet_samsync(struct rpc_pipe_client *pipe_hnd,
delta_enum_array);
/* Process results */
- callback_status = callback_fn(mem_ctx, database_id, delta_enum_array, result, ctx);
+ callback_status = ctx->delta_fn(mem_ctx, database_id,
+ delta_enum_array, result, ctx);
if (!NT_STATUS_IS_OK(callback_status)) {
result = callback_status;
goto out;
diff --git a/source3/libnet/libnet_samsync.h b/source3/libnet/libnet_samsync.h
index 24b72f3ab1..03d4f5366c 100644
--- a/source3/libnet/libnet_samsync.h
+++ b/source3/libnet/libnet_samsync.h
@@ -24,6 +24,14 @@ enum net_samsync_mode {
NET_SAMSYNC_MODE_DUMP = 2
};
+struct samsync_context;
+
+typedef NTSTATUS (*samsync_delta_fn_t)(TALLOC_CTX *,
+ enum netr_SamDatabaseID,
+ struct netr_DELTA_ENUM_ARRAY *,
+ NTSTATUS,
+ struct samsync_context *);
+
struct samsync_context {
enum net_samsync_mode mode;
const struct dom_sid *domain_sid;
@@ -34,15 +42,11 @@ struct samsync_context {
char *result_message;
char *error_message;
+ struct rpc_pipe_client *cli;
+ samsync_delta_fn_t delta_fn;
void *private_data;
};
-typedef NTSTATUS (*samsync_fn_t)(TALLOC_CTX *,
- enum netr_SamDatabaseID,
- struct netr_DELTA_ENUM_ARRAY *,
- NTSTATUS,
- struct samsync_context *);
-
NTSTATUS fetch_sam_entries_ldif(TALLOC_CTX *mem_ctx,
enum netr_SamDatabaseID database_id,
struct netr_DELTA_ENUM_ARRAY *r,
diff --git a/source3/utils/net_rpc_samsync.c b/source3/utils/net_rpc_samsync.c
index 4dfa72dcc9..c941338b32 100644
--- a/source3/utils/net_rpc_samsync.c
+++ b/source3/utils/net_rpc_samsync.c
@@ -41,21 +41,21 @@ NTSTATUS rpc_samdump_internals(struct net_context *c,
status = libnet_samsync_init_context(mem_ctx,
domain_sid,
- domain_name,
- NET_SAMSYNC_MODE_DUMP,
&ctx);
if (!NT_STATUS_IS_OK(status)) {
return status;
}
- libnet_samsync(pipe_hnd, SAM_DATABASE_DOMAIN,
- display_sam_entries, ctx);
+ ctx->mode = NET_SAMSYNC_MODE_DUMP;
+ ctx->cli = pipe_hnd;
+ ctx->delta_fn = display_sam_entries;
+ ctx->domain_name = domain_name;
- libnet_samsync(pipe_hnd, SAM_DATABASE_BUILTIN,
- display_sam_entries, ctx);
+ libnet_samsync(SAM_DATABASE_DOMAIN, ctx);
- libnet_samsync(pipe_hnd, SAM_DATABASE_PRIVS,
- display_sam_entries, ctx);
+ libnet_samsync(SAM_DATABASE_BUILTIN, ctx);
+
+ libnet_samsync(SAM_DATABASE_PRIVS, ctx);
TALLOC_FREE(ctx);
@@ -97,15 +97,6 @@ NTSTATUS rpc_vampire_internals(struct net_context *c,
NTSTATUS result;
struct samsync_context *ctx = NULL;
- result = libnet_samsync_init_context(mem_ctx,
- domain_sid,
- domain_name,
- NET_SAMSYNC_MODE_FETCH_PASSDB,
- &ctx);
- if (!NT_STATUS_IS_OK(result)) {
- return result;
- }
-
if (!sid_equal(domain_sid, get_global_sam_sid())) {
d_printf("Cannot import users from %s at this time, "
"as the current domain:\n\t%s: %s\nconflicts "
@@ -121,9 +112,20 @@ NTSTATUS rpc_vampire_internals(struct net_context *c,
return NT_STATUS_UNSUCCESSFUL;
}
+ result = libnet_samsync_init_context(mem_ctx,
+ domain_sid,
+ &ctx);
+ if (!NT_STATUS_IS_OK(result)) {
+ return result;
+ }
+
+ ctx->mode = NET_SAMSYNC_MODE_FETCH_PASSDB;
+ ctx->cli = pipe_hnd;
+ ctx->delta_fn = fetch_sam_entries;
+ ctx->domain_name = domain_name;
+
/* fetch domain */
- result = libnet_samsync(pipe_hnd, SAM_DATABASE_DOMAIN,
- fetch_sam_entries, ctx);
+ result = libnet_samsync(SAM_DATABASE_DOMAIN, ctx);
if (!NT_STATUS_IS_OK(result) && ctx->error_message) {
d_fprintf(stderr, "%s\n", ctx->error_message);
@@ -137,8 +139,7 @@ NTSTATUS rpc_vampire_internals(struct net_context *c,
/* 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 = libnet_samsync(pipe_hnd, SAM_DATABASE_BUILTIN,
- fetch_sam_entries, ctx);
+ result = libnet_samsync(SAM_DATABASE_BUILTIN, ctx);
if (!NT_STATUS_IS_OK(result) && ctx->error_message) {
d_fprintf(stderr, "%s\n", ctx->error_message);
@@ -168,8 +169,6 @@ NTSTATUS rpc_vampire_ldif_internals(struct net_context *c,
status = libnet_samsync_init_context(mem_ctx,
domain_sid,
- domain_name,
- NET_SAMSYNC_MODE_FETCH_LDIF,
&ctx);
if (!NT_STATUS_IS_OK(status)) {
return status;
@@ -179,9 +178,13 @@ NTSTATUS rpc_vampire_ldif_internals(struct net_context *c,
ctx->output_filename = argv[0];
}
+ ctx->mode = NET_SAMSYNC_MODE_FETCH_LDIF;
+ ctx->cli = pipe_hnd;
+ ctx->delta_fn = fetch_sam_entries_ldif;
+ ctx->domain_name = domain_name;
+
/* fetch domain */
- status = libnet_samsync(pipe_hnd, SAM_DATABASE_DOMAIN,
- fetch_sam_entries_ldif, ctx);
+ status = libnet_samsync(SAM_DATABASE_DOMAIN, ctx);
if (!NT_STATUS_IS_OK(status) && ctx->error_message) {
d_fprintf(stderr, "%s\n", ctx->error_message);
@@ -195,8 +198,7 @@ NTSTATUS rpc_vampire_ldif_internals(struct net_context *c,
/* 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 = libnet_samsync(pipe_hnd, SAM_DATABASE_BUILTIN,
- fetch_sam_entries_ldif, ctx);
+ status = libnet_samsync(SAM_DATABASE_BUILTIN, ctx);
if (!NT_STATUS_IS_OK(status) && ctx->error_message) {
d_fprintf(stderr, "%s\n", ctx->error_message);