summaryrefslogtreecommitdiff
path: root/source4
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2006-01-24 19:07:40 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:51:27 -0500
commit5304f341329d562cb0f3ece28633d21bd8d3b01c (patch)
tree434f244f7a00473ddd8ac0e0cc24e87d9168372e /source4
parent0e7fed29ec24f5de1709a41f64998a90b51a1ec7 (diff)
downloadsamba-5304f341329d562cb0f3ece28633d21bd8d3b01c.tar.gz
samba-5304f341329d562cb0f3ece28633d21bd8d3b01c.tar.bz2
samba-5304f341329d562cb0f3ece28633d21bd8d3b01c.zip
r13115: call the wins hook script on modifications of the wins.ldb
tridge: can you please look at the /* TODO: close file handles */ btw I'm not interessted in any result from the script... metze (This used to be commit 93409faddf610e7fd6cc910a1e2fd32e69aa7c1d)
Diffstat (limited to 'source4')
-rw-r--r--source4/nbt_server/wins/wins_hook.c64
1 files changed, 56 insertions, 8 deletions
diff --git a/source4/nbt_server/wins/wins_hook.c b/source4/nbt_server/wins/wins_hook.c
index 4c798fc18c..53b30c2392 100644
--- a/source4/nbt_server/wins/wins_hook.c
+++ b/source4/nbt_server/wins/wins_hook.c
@@ -24,24 +24,72 @@
#include "includes.h"
#include "nbt_server/nbt_server.h"
#include "nbt_server/wins/winsdb.h"
+#include "system/filesys.h"
static const char *wins_hook_action_string(enum wins_hook_action action)
{
switch (action) {
- case WINS_HOOK_ADD: return "WINS_HOOK_ADD";
- case WINS_HOOK_MODIFY: return "WINS_HOOK_MODIFY";
- case WINS_HOOK_DELETE: return "WINS_HOOK_DELETE";
+ case WINS_HOOK_ADD: return "add";
+ case WINS_HOOK_MODIFY: return "refresh";
+ case WINS_HOOK_DELETE: return "delete";
}
- return "WINS_HOOK_ACTION_UNKNOWN";
+ return "unknown";
}
-void wins_hook(struct winsdb_handle *h, struct winsdb_record *rec, enum wins_hook_action action)
+void wins_hook(struct winsdb_handle *h, const struct winsdb_record *rec, enum wins_hook_action action)
{
const char *script = lp_wins_hook();
+ uint32_t i, length;
+ int child;
+ char *cmd = NULL;
+ TALLOC_CTX *tmp_mem = NULL;
+
if (!script || !script[0]) return;
- DEBUG(0,("TODO: call wins hook '%s' '%s' for name '%s'\n",
- script, wins_hook_action_string(action),
- nbt_name_string(rec, rec->name)));
+ tmp_mem = talloc_new(h);
+ if (!tmp_mem) goto failed;
+
+ length = winsdb_addr_list_length(rec->addresses);
+
+ if (action == WINS_HOOK_MODIFY && length < 1) {
+ action = WINS_HOOK_DELETE;
+ }
+
+ cmd = talloc_asprintf(tmp_mem,
+ "%s %s %s %02x %ld",
+ script,
+ wins_hook_action_string(action),
+ rec->name->name,
+ rec->name->type,
+ rec->expire_time);
+ if (!cmd) goto failed;
+
+ for (i=0; rec->addresses[i]; i++) {
+ cmd = talloc_asprintf_append(cmd, " %s", rec->addresses[i]->address);
+ if (!cmd) goto failed;
+ }
+
+ DEBUG(10,("call wins hook '%s'\n", cmd));
+
+ /* signal handling in posix really sucks - doing this in a library
+ affects the whole app, but what else to do?? */
+ signal(SIGCHLD, SIG_IGN);
+
+ child = fork();
+ if (child == (pid_t)-1) {
+ goto failed;
+ }
+
+ if (child == 0) {
+/* TODO: close file handles */
+ execl("/bin/sh", "sh", "-c", cmd, NULL);
+ _exit(0);
+ }
+
+ talloc_free(tmp_mem);
+ return;
+failed:
+ talloc_free(tmp_mem);
+ DEBUG(0,("FAILED: calling wins hook '%s'\n", script));
}