summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2010-02-17 19:29:37 +1100
committerAndrew Tridgell <tridge@samba.org>2010-02-17 19:43:32 +1100
commitfd2556317f22ee02b341ca7ebbd02d7197fb1e4d (patch)
tree4ee17cc7a5d6485b9a47bf2f166668cb25c2cac7
parent8633d8126bdf5c31c079d64428492bf1ab2d4cb2 (diff)
downloadsamba-fd2556317f22ee02b341ca7ebbd02d7197fb1e4d.tar.gz
samba-fd2556317f22ee02b341ca7ebbd02d7197fb1e4d.tar.bz2
samba-fd2556317f22ee02b341ca7ebbd02d7197fb1e4d.zip
s4-dnsupdate: use samba_runcmd() in the dns update task
Pair-Programmed-With: Andrew Bartlett <abartlet@samba.org>
-rw-r--r--source4/dsdb/config.mk3
-rw-r--r--source4/dsdb/dns/dns_update.c51
2 files changed, 37 insertions, 17 deletions
diff --git a/source4/dsdb/config.mk b/source4/dsdb/config.mk
index 94e6e39be1..9a1cee979f 100644
--- a/source4/dsdb/config.mk
+++ b/source4/dsdb/config.mk
@@ -98,7 +98,8 @@ INIT_FUNCTION = server_service_dnsupdate_init
SUBSYSTEM = service
PRIVATE_DEPENDENCIES = \
SAMDB \
- process_model
+ process_model \
+ UTIL_RUNCMD
# End SUBSYSTEM DNS_UPDATE_SRV
#######################
diff --git a/source4/dsdb/dns/dns_update.c b/source4/dsdb/dns/dns_update.c
index 13f37e3c6b..efaea168e2 100644
--- a/source4/dsdb/dns/dns_update.c
+++ b/source4/dsdb/dns/dns_update.c
@@ -29,12 +29,10 @@
#include "dsdb/samdb/samdb.h"
#include "auth/auth.h"
#include "smbd/service.h"
-#include "lib/events/events.h"
#include "lib/messaging/irpc.h"
-#include "lib/ldb/include/ldb_errors.h"
#include "param/param.h"
#include "system/filesys.h"
-#include "lib/tevent/tevent.h"
+#include "libcli/composite/composite.h"
struct dnsupdate_service {
struct task_server *task;
@@ -44,10 +42,29 @@ struct dnsupdate_service {
struct {
uint32_t interval;
struct tevent_timer *te;
+ struct composite_context *c;
+ NTSTATUS status;
} periodic;
};
/*
+ called when rndc reload has finished
+ */
+static void dnsupdate_rndc_done(struct composite_context *c)
+{
+ struct dnsupdate_service *service = talloc_get_type_abort(c->async.private_data,
+ struct dnsupdate_service);
+ service->periodic.status = composite_wait(c);
+ if (!NT_STATUS_IS_OK(service->periodic.status)) {
+ DEBUG(0,(__location__ ": Failed rndc update - %s\n",
+ nt_errstr(service->periodic.status)));
+ return;
+ }
+ talloc_free(c);
+ service->periodic.c = NULL;
+}
+
+/*
called every dnsupdate:interval seconds
*/
static void dnsupdate_rebuild(struct dnsupdate_service *service)
@@ -59,7 +76,6 @@ static void dnsupdate_rebuild(struct dnsupdate_service *service)
const char *attrs[] = { "sAMAccountName", NULL };
const char *realm = lp_realm(service->task->lp_ctx);
TALLOC_CTX *tmp_ctx = talloc_new(service);
- const char *rndc_cmd;
ret = ldb_search(service->samdb, tmp_ctx, &res, NULL, LDB_SCOPE_SUBTREE,
attrs, "(&(primaryGroupID=%u)(objectClass=computer))",
@@ -106,7 +122,13 @@ static void dnsupdate_rebuild(struct dnsupdate_service *service)
dprintf(fd, "};\n");
close(fd);
- if (file_compare(tmp_path, path) == true) {
+ if (service->periodic.c != NULL) {
+ talloc_free(service->periodic.c);
+ service->periodic.c = NULL;
+ }
+
+ if (NT_STATUS_IS_OK(service->periodic.status) &&
+ file_compare(tmp_path, path) == true) {
unlink(tmp_path);
talloc_free(tmp_ctx);
return;
@@ -119,17 +141,14 @@ static void dnsupdate_rebuild(struct dnsupdate_service *service)
return;
}
- DEBUG(1,("Loaded new DNS update grant rules\n"));
-
- rndc_cmd = lp_parm_string(service->task->lp_ctx, NULL, "dnsupdate", "rndc reload command");
- if (!rndc_cmd) {
- rndc_cmd = "/usr/sbin/rndc reload";
- }
- ret = system(rndc_cmd);
- if (ret != 0) {
- DEBUG(0,(__location__ ": Failed rndc reload command: '%s' - %d\n",
- rndc_cmd, ret));
- }
+ DEBUG(2,("Loading new DNS update grant rules\n"));
+ service->periodic.c = samba_runcmd(service->task->event_ctx, service,
+ timeval_current_ofs(10, 0),
+ 2, 0,
+ lp_rndc_command(service->task->lp_ctx),
+ "reload", NULL);
+ service->periodic.c->async.fn = dnsupdate_rndc_done;
+ service->periodic.c->async.private_data = service;
talloc_free(tmp_ctx);
}