summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Adam <obnox@samba.org>2008-07-16 17:12:04 +0200
committerMichael Adam <obnox@samba.org>2008-08-01 16:04:39 +0200
commit16c2190b149a2232aa49a16a41e570410edd2eaf (patch)
treec8e4c451fa4966586a2ff2825bd1dd810b4df402
parentb0fbdbc1bfdc69e116551f75f2fd5eb85a14ecdd (diff)
downloadsamba-16c2190b149a2232aa49a16a41e570410edd2eaf.tar.gz
samba-16c2190b149a2232aa49a16a41e570410edd2eaf.tar.bz2
samba-16c2190b149a2232aa49a16a41e570410edd2eaf.zip
dssync: replace the processing_fn by startup/process/finish ops.
This remove static a variable for the keytab context in the keytab processing function and simplifies the signature. The keytab context is instead in the new private data member of the dssync_context struct. This is in preparation of adding support for keeping track of the up-to-date-ness vector, in order to be able to sync diffs instead of the whole database. Michael (This used to be commit c51c3339f35e3bd921080d2e226e2422fc23e1e6)
-rw-r--r--source3/libnet/libnet_dssync.c36
-rw-r--r--source3/libnet/libnet_dssync.h23
-rw-r--r--source3/libnet/libnet_dssync_keytab.c113
-rw-r--r--source3/utils/net_rpc_samsync.c2
4 files changed, 104 insertions, 70 deletions
diff --git a/source3/libnet/libnet_dssync.c b/source3/libnet/libnet_dssync.c
index b55e6d1906..f33369ee4b 100644
--- a/source3/libnet/libnet_dssync.c
+++ b/source3/libnet/libnet_dssync.c
@@ -355,6 +355,14 @@ static NTSTATUS libnet_dssync_process(TALLOC_CTX *mem_ctx,
nc.guid = GUID_zero();
nc.sid = null_sid;
+ status = ctx->ops->startup(ctx, mem_ctx);
+ if (!NT_STATUS_IS_OK(status)) {
+ ctx->error_message = talloc_asprintf(mem_ctx,
+ "Failed to call startup operation: %s",
+ nt_errstr(status));
+ goto out;
+ }
+
req.req8.naming_context = &nc;
req.req8.replica_flags = DRSUAPI_DS_REPLICA_NEIGHBOUR_WRITEABLE |
DRSUAPI_DS_REPLICA_NEIGHBOUR_SYNC_ON_STARTUP |
@@ -423,12 +431,10 @@ static NTSTATUS libnet_dssync_process(TALLOC_CTX *mem_ctx,
last_query = false;
}
- if (ctx->processing_fn) {
- status = ctx->processing_fn(mem_ctx,
- ctr1->first_object,
- &ctr1->mapping_ctr,
- last_query,
- ctx);
+ if (ctx->ops->process_objects) {
+ status = ctx->ops->process_objects(ctx, mem_ctx,
+ ctr1->first_object,
+ &ctr1->mapping_ctr);
if (!NT_STATUS_IS_OK(status)) {
ctx->error_message = talloc_asprintf(mem_ctx,
"Failed to call processing function: %s",
@@ -466,12 +472,10 @@ static NTSTATUS libnet_dssync_process(TALLOC_CTX *mem_ctx,
last_query = false;
}
- if (ctx->processing_fn) {
- status = ctx->processing_fn(mem_ctx,
- ctr6->first_object,
- &ctr6->mapping_ctr,
- last_query,
- ctx);
+ if (ctx->ops->process_objects) {
+ status = ctx->ops->process_objects(ctx, mem_ctx,
+ ctr6->first_object,
+ &ctr6->mapping_ctr);
if (!NT_STATUS_IS_OK(status)) {
ctx->error_message = talloc_asprintf(mem_ctx,
"Failed to call processing function: %s",
@@ -485,6 +489,14 @@ static NTSTATUS libnet_dssync_process(TALLOC_CTX *mem_ctx,
}
}
+ status = ctx->ops->finish(ctx, mem_ctx);
+ if (!NT_STATUS_IS_OK(status)) {
+ ctx->error_message = talloc_asprintf(mem_ctx,
+ "Failed to call finishing operation: %s",
+ nt_errstr(status));
+ goto out;
+ }
+
break;
}
diff --git a/source3/libnet/libnet_dssync.h b/source3/libnet/libnet_dssync.h
index c98e650fcc..9b18dae4f5 100644
--- a/source3/libnet/libnet_dssync.h
+++ b/source3/libnet/libnet_dssync.h
@@ -19,11 +19,14 @@
struct dssync_context;
-typedef NTSTATUS (*dssync_processing_fn_t)(TALLOC_CTX *,
- struct drsuapi_DsReplicaObjectListItemEx *,
- struct drsuapi_DsReplicaOIDMapping_Ctr *,
- bool,
- struct dssync_context *ctx);
+struct dssync_ops {
+ NTSTATUS (*startup)(struct dssync_context *ctx, TALLOC_CTX *mem_ctx);
+ NTSTATUS (*process_objects)(struct dssync_context *ctx,
+ TALLOC_CTX *mem_ctx,
+ struct drsuapi_DsReplicaObjectListItemEx *objects,
+ struct drsuapi_DsReplicaOIDMapping_Ctr *mappings);
+ NTSTATUS (*finish)(struct dssync_context *ctx, TALLOC_CTX *mem_ctx);
+};
struct dssync_context {
const char *domain_name;
@@ -34,14 +37,12 @@ struct dssync_context {
DATA_BLOB session_key;
const char *output_filename;
- dssync_processing_fn_t processing_fn;
+ void *private_data;
+
+ const struct dssync_ops *ops;
char *result_message;
char *error_message;
};
-NTSTATUS libnet_dssync_dump_keytab(TALLOC_CTX *mem_ctx,
- struct drsuapi_DsReplicaObjectListItemEx *cur,
- struct drsuapi_DsReplicaOIDMapping_Ctr *mapping_ctr,
- bool last_query,
- struct dssync_context *ctx);
+extern const struct dssync_ops libnet_dssync_keytab_ops;
diff --git a/source3/libnet/libnet_dssync_keytab.c b/source3/libnet/libnet_dssync_keytab.c
index 132a58d353..d59efe74fb 100644
--- a/source3/libnet/libnet_dssync_keytab.c
+++ b/source3/libnet/libnet_dssync_keytab.c
@@ -22,6 +22,48 @@
#if defined(HAVE_ADS) && defined(ENCTYPE_ARCFOUR_HMAC)
+static NTSTATUS keytab_startup(struct dssync_context *ctx, TALLOC_CTX *mem_ctx)
+{
+ krb5_error_code ret = 0;
+ struct libnet_keytab_context *keytab_ctx;
+
+ ret = libnet_keytab_init(mem_ctx, ctx->output_filename, &keytab_ctx);
+ if (ret) {
+ return krb5_to_nt_status(ret);
+ }
+
+ keytab_ctx->dns_domain_name = ctx->dns_domain_name;
+ ctx->private_data = keytab_ctx;
+
+ return NT_STATUS_OK;
+}
+
+static NTSTATUS keytab_finish(struct dssync_context *ctx, TALLOC_CTX *mem_ctx)
+{
+ NTSTATUS status = NT_STATUS_OK;
+ krb5_error_code ret = 0;
+ struct libnet_keytab_context *keytab_ctx =
+ (struct libnet_keytab_context *)ctx->private_data;
+
+ ret = libnet_keytab_add(keytab_ctx);
+ if (ret) {
+ status = krb5_to_nt_status(ret);
+ ctx->error_message = talloc_asprintf(mem_ctx,
+ "Failed to add entries to keytab %s: %s",
+ keytab_ctx->keytab_name, error_message(ret));
+ goto done;
+ }
+
+ ctx->result_message = talloc_asprintf(mem_ctx,
+ "Vampired %d accounts to keytab %s",
+ keytab_ctx->count,
+ keytab_ctx->keytab_name);
+
+done:
+ TALLOC_FREE(keytab_ctx);
+ return status;
+}
+
/****************************************************************
****************************************************************/
@@ -171,27 +213,14 @@ static NTSTATUS parse_object(TALLOC_CTX *mem_ctx,
/****************************************************************
****************************************************************/
-NTSTATUS libnet_dssync_dump_keytab(TALLOC_CTX *mem_ctx,
- struct drsuapi_DsReplicaObjectListItemEx *cur,
- struct drsuapi_DsReplicaOIDMapping_Ctr *mapping_ctr,
- bool last_query,
- struct dssync_context *ctx)
+static NTSTATUS keytab_process_objects(struct dssync_context *ctx,
+ TALLOC_CTX *mem_ctx,
+ struct drsuapi_DsReplicaObjectListItemEx *cur,
+ struct drsuapi_DsReplicaOIDMapping_Ctr *mapping_ctr)
{
NTSTATUS status = NT_STATUS_OK;
- krb5_error_code ret = 0;
- static struct libnet_keytab_context *keytab_ctx = NULL;
-
- if (!keytab_ctx) {
- ret = libnet_keytab_init(mem_ctx,
- ctx->output_filename,
- &keytab_ctx);
- if (ret) {
- status = krb5_to_nt_status(ret);
- goto out;
- }
-
- keytab_ctx->dns_domain_name = ctx->dns_domain_name;
- }
+ struct libnet_keytab_context *keytab_ctx =
+ (struct libnet_keytab_context *)ctx->private_data;
for (; cur; cur = cur->next_object) {
status = parse_object(mem_ctx, keytab_ctx, cur);
@@ -200,41 +229,33 @@ NTSTATUS libnet_dssync_dump_keytab(TALLOC_CTX *mem_ctx,
}
}
- if (last_query) {
-
- ret = libnet_keytab_add(keytab_ctx);
- if (ret) {
- status = krb5_to_nt_status(ret);
- ctx->error_message = talloc_asprintf(mem_ctx,
- "Failed to add entries to keytab %s: %s",
- keytab_ctx->keytab_name, error_message(ret));
- goto out;
- }
-
- ctx->result_message = talloc_asprintf(mem_ctx,
- "Vampired %d accounts to keytab %s",
- keytab_ctx->count,
- keytab_ctx->keytab_name);
-
- TALLOC_FREE(keytab_ctx);
- }
-
- return NT_STATUS_OK;
out:
- TALLOC_FREE(keytab_ctx);
-
return status;
}
#else
-NTSTATUS libnet_dssync_dump_keytab(TALLOC_CTX *mem_ctx,
- struct drsuapi_DsReplicaObjectListItemEx *cur,
- struct drsuapi_DsReplicaOIDMapping_Ctr *mapping_ctr,
- bool last_query,
- struct dssync_context *ctx)
+static NTSTATUS keytab_startup(struct dssync_context *ctx, TALLOC_CTX *mem_ctx)
+{
+ return NT_STATUS_NOT_SUPPORTED;
+}
+
+static NTSTATUS keytab_finish(struct dssync_context *ctx, TALLOC_CTX *mem_ctx)
{
return NT_STATUS_NOT_SUPPORTED;
}
+static NTSTATUS keytab_process_objects(struct dssync_context *ctx,
+ TALLOC_CTX *mem_ctx,
+ struct drsuapi_DsReplicaObjectListItemEx *cur,
+ struct drsuapi_DsReplicaOIDMapping_Ctr *mapping_ctr)
+{
+ return NT_STATUS_NOT_SUPPORTED;
+}
#endif /* defined(HAVE_ADS) && defined(ENCTYPE_ARCFOUR_HMAC) */
+
+const struct dssync_ops libnet_dssync_keytab_ops = {
+ .startup = keytab_startup,
+ .process_objects = keytab_process_objects,
+ .finish = keytab_finish,
+};
diff --git a/source3/utils/net_rpc_samsync.c b/source3/utils/net_rpc_samsync.c
index c60d441822..2dd849df34 100644
--- a/source3/utils/net_rpc_samsync.c
+++ b/source3/utils/net_rpc_samsync.c
@@ -302,7 +302,7 @@ static NTSTATUS rpc_vampire_keytab_ds_internals(struct net_context *c,
ctx->cli = pipe_hnd;
ctx->domain_name = domain_name;
- ctx->processing_fn = libnet_dssync_dump_keytab;
+ ctx->ops = &libnet_dssync_keytab_ops;
status = libnet_dssync(mem_ctx, ctx);
if (!NT_STATUS_IS_OK(status) && ctx->error_message) {