s4-repl: added repl_secret handling
authorAndrew Tridgell <tridge@samba.org>
Wed, 15 Sep 2010 09:00:01 +0000 (19:00 +1000)
committerAndrew Tridgell <tridge@samba.org>
Wed, 15 Sep 2010 21:24:01 +0000 (07:24 +1000)
initiate a repl secret extended op when requested

Pair-Programmed-With: Andrew Bartlett <abartlet@samba.org>

source4/dsdb/repl/drepl_secret.c
source4/dsdb/wscript_build

index 8a405e794d2ad1d03b634104b603cbb61a64ea0c..2b5fae2d5b961ecf0a97faaacded5de946ebd97d 100644 (file)
 #include "dsdb/repl/drepl_service.h"
 #include "param/param.h"
 
+struct repl_secret_state {
+       const char *user_dn;
+};
+
+/*
+  called when a repl secret has completed
+ */
+static void drepl_repl_secret_callback(struct dreplsrv_service *service,
+                                      WERROR werr,
+                                      enum drsuapi_DsExtendedError ext_err,
+                                      void *cb_data)
+{
+       struct repl_secret_state *state = talloc_get_type_abort(cb_data, struct repl_secret_state);
+       if (!W_ERROR_IS_OK(werr)) {
+               DEBUG(3,(__location__ ": repl secret failed for user %s - %s: extended_ret[0x%X]\n",
+                        state->user_dn, win_errstr(werr), ext_err));
+       } else {
+               DEBUG(3,(__location__ ": repl secret completed OK for '%s'\n", state->user_dn));
+       }
+       talloc_free(state);
+}
+
 
 /**
  * Called when the auth code wants us to try and replicate
 void drepl_repl_secret(struct dreplsrv_service *service,
                       const char *user_dn)
 {
-       DEBUG(0,(__location__ ": got drepl_repl_secret with %s\n", user_dn));
+       WERROR werr;
+       struct ldb_dn *nc_dn, *nc_root, *source_dsa_dn;
+       struct dreplsrv_partition *p;
+       struct GUID *source_dsa_guid;
+       struct repl_secret_state *state;
+       int ret;
+
+       state = talloc_zero(service, struct repl_secret_state);
+       if (state == NULL) {
+               /* nothing to do, no return value */
+               return;
+       }
+
+       /* keep a copy for logging in the callback */
+       state->user_dn = talloc_strdup(state, user_dn);
+
+       nc_dn = ldb_dn_new(state, service->samdb, user_dn);
+       if (!ldb_dn_validate(nc_dn)) {
+               DEBUG(0,(__location__ ": Failed to parse user_dn '%s'\n", user_dn));
+               talloc_free(state);
+               return;
+       }
+
+       /* work out which partition this is in */
+       ret = dsdb_find_nc_root(service->samdb, state, nc_dn, &nc_root);
+       if (ret != LDB_SUCCESS) {
+               DEBUG(0,(__location__ ": Failed to find nc_root for user_dn '%s'\n", user_dn));
+               talloc_free(state);
+               return;
+       }
+
+       /* find the partition in our list */
+       for (p=service->partitions; p; p=p->next) {
+               if (ldb_dn_compare(p->dn, nc_root) == 0) {
+                       break;
+               }
+       }
+       if (p == NULL) {
+               DEBUG(0,(__location__ ": Failed to find partition for nc_root '%s'\n", ldb_dn_get_linearized(nc_root)));
+               talloc_free(state);
+               return;
+       }
+
+       if (p->sources == NULL) {
+               DEBUG(0,(__location__ ": No sources for nc_root '%s' for user_dn '%s'\n",
+                        ldb_dn_get_linearized(nc_root), user_dn));
+               talloc_free(state);
+               return;
+       }
+
+       /* use the first source, for no particularly good reason */
+       source_dsa_guid = &p->sources->repsFrom1->source_dsa_obj_guid;
+
+       source_dsa_dn = ldb_dn_new(state, service->samdb,
+                                  talloc_asprintf(state, "<GUID=%s>",
+                                                  GUID_string(state, source_dsa_guid)));
+       if (!ldb_dn_validate(source_dsa_dn)) {
+               DEBUG(0,(__location__ ": Invalid source DSA GUID '%s' for user_dn '%s'\n",
+                        GUID_string(state, source_dsa_guid), user_dn));
+               talloc_free(state);
+               return;
+       }
+
+       werr = drepl_request_extended_op(service,
+                                        nc_dn,
+                                        source_dsa_dn,
+                                        DRSUAPI_EXOP_REPL_SECRET,
+                                        0,
+                                        drepl_repl_secret_callback, state);
+       if (!W_ERROR_IS_OK(werr)) {
+               DEBUG(2,(__location__ ": Failed to setup secret replication for user_dn '%s'\n", user_dn));
+               talloc_free(state);
+               return;
+       }
+       DEBUG(3,(__location__ ": started secret replication for %s\n", user_dn));
 }
index bc9bd13656d52e15c1ad199be52b81067a1d0c52..615fd1032ae9546091a75efb2ada811559fe1f78 100644 (file)
@@ -25,7 +25,7 @@ bld.SAMBA_SUBSYSTEM('SAMDB_SCHEMA',
 
 
 bld.SAMBA_MODULE('DREPL_SRV',
-       source='repl/drepl_service.c repl/drepl_periodic.c repl/drepl_partitions.c repl/drepl_out_pull.c repl/drepl_out_helpers.c repl/drepl_notify.c repl/drepl_ridalloc.c repl/drepl_extended.c repl/drepl_fsmo.c',
+       source='repl/drepl_service.c repl/drepl_periodic.c repl/drepl_partitions.c repl/drepl_out_pull.c repl/drepl_out_helpers.c repl/drepl_notify.c repl/drepl_ridalloc.c repl/drepl_extended.c repl/drepl_fsmo.c repl/drepl_secret.c',
        autoproto='repl/drepl_service_proto.h',
        subsystem='service',
        init_function='server_service_drepl_init',