dssync: replace the processing_fn by startup/process/finish ops.
authorMichael Adam <obnox@samba.org>
Wed, 16 Jul 2008 15:12:04 +0000 (17:12 +0200)
committerMichael Adam <obnox@samba.org>
Fri, 1 Aug 2008 14:04:39 +0000 (16:04 +0200)
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)

source3/libnet/libnet_dssync.c
source3/libnet/libnet_dssync.h
source3/libnet/libnet_dssync_keytab.c
source3/utils/net_rpc_samsync.c

index b55e6d1906cefe3855b53099ed98202f022e138f..f33369ee4b86182c1360202f8b4734203d9ac89b 100644 (file)
@@ -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;
        }
 
index c98e650fccab1a8579925f4893c1eaa2bdafa2a6..9b18dae4f5772998e6fd8497916ff51dff034a1d 100644 (file)
 
 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;
index 132a58d353de90000daf8063885523b7169dde01..d59efe74fb77e528e6ec6ef3b259e41111ecafe1 100644 (file)
 
 #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,
+};
index c60d4418224b05b6935d31052cde14120dfab224..2dd849df3405c869447bc85084ea94866a10874d 100644 (file)
@@ -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) {