From c4a5381154b23869c5543ef36dfd064155e70cb1 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 13 Jan 2006 10:26:47 +0000 Subject: r12898: prepare the 'wins hook' feature, but we only debug out a 'TODO: run script ...' metze (This used to be commit d28c8ce66db61cff193ac06e8e5d7d6aa5059e9e) --- source4/nbt_server/wins/wins_hook.c | 47 +++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 source4/nbt_server/wins/wins_hook.c (limited to 'source4/nbt_server/wins/wins_hook.c') diff --git a/source4/nbt_server/wins/wins_hook.c b/source4/nbt_server/wins/wins_hook.c new file mode 100644 index 0000000000..4c798fc18c --- /dev/null +++ b/source4/nbt_server/wins/wins_hook.c @@ -0,0 +1,47 @@ +/* + Unix SMB/CIFS implementation. + + wins hook feature, we run a specified script + which can then do some custom actions + + Copyright (C) Stefan Metzmacher 2005 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" +#include "nbt_server/nbt_server.h" +#include "nbt_server/wins/winsdb.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"; + } + + return "WINS_HOOK_ACTION_UNKNOWN"; +} + +void wins_hook(struct winsdb_handle *h, struct winsdb_record *rec, enum wins_hook_action action) +{ + const char *script = lp_wins_hook(); + 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))); +} -- cgit From 5304f341329d562cb0f3ece28633d21bd8d3b01c Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 24 Jan 2006 19:07:40 +0000 Subject: 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) --- source4/nbt_server/wins/wins_hook.c | 64 ++++++++++++++++++++++++++++++++----- 1 file changed, 56 insertions(+), 8 deletions(-) (limited to 'source4/nbt_server/wins/wins_hook.c') 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)); } -- cgit From 0479a2f1cbae51fcd8dbdc3c148c808421fb4d25 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 02:07:03 +0000 Subject: r23792: convert Samba4 to GPLv3 There are still a few tidyups of old FSF addresses to come (in both s3 and s4). More commits soon. (This used to be commit fcf38a38ac691abd0fa51b89dc951a08e89fdafa) --- source4/nbt_server/wins/wins_hook.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source4/nbt_server/wins/wins_hook.c') diff --git a/source4/nbt_server/wins/wins_hook.c b/source4/nbt_server/wins/wins_hook.c index 53b30c2392..15c0088192 100644 --- a/source4/nbt_server/wins/wins_hook.c +++ b/source4/nbt_server/wins/wins_hook.c @@ -8,7 +8,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -17,8 +17,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ #include "includes.h" -- cgit From 959915a8cbea0c598ef1f29ce666329a521ef2f6 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 7 Sep 2007 15:35:18 +0000 Subject: r25001: Fix more C++ and other warnings, fix some of the indentation with ts=4 lines that I accidently added earlier. (This used to be commit 0bcb21ed740fcec0f48ad36bbc2deee2948e8fc7) --- source4/nbt_server/wins/wins_hook.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source4/nbt_server/wins/wins_hook.c') diff --git a/source4/nbt_server/wins/wins_hook.c b/source4/nbt_server/wins/wins_hook.c index 15c0088192..e5d8b39062 100644 --- a/source4/nbt_server/wins/wins_hook.c +++ b/source4/nbt_server/wins/wins_hook.c @@ -36,7 +36,8 @@ static const char *wins_hook_action_string(enum wins_hook_action action) return "unknown"; } -void wins_hook(struct winsdb_handle *h, const 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; -- cgit From ffeee68e4b72dd94fee57366bd8d38b8c284c3d4 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 8 Sep 2007 12:42:09 +0000 Subject: r25026: Move param/param.h out of includes.h (This used to be commit abe8349f9b4387961ff3665d8c589d61cd2edf31) --- source4/nbt_server/wins/wins_hook.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/nbt_server/wins/wins_hook.c') diff --git a/source4/nbt_server/wins/wins_hook.c b/source4/nbt_server/wins/wins_hook.c index e5d8b39062..e89e6b8d26 100644 --- a/source4/nbt_server/wins/wins_hook.c +++ b/source4/nbt_server/wins/wins_hook.c @@ -24,6 +24,7 @@ #include "nbt_server/nbt_server.h" #include "nbt_server/wins/winsdb.h" #include "system/filesys.h" +#include "param/param.h" static const char *wins_hook_action_string(enum wins_hook_action action) { -- cgit From 9a012df08ee829c1d40fc88ba12a0ea479f60be0 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 14 Sep 2007 23:21:00 +0000 Subject: r25175: Change to talloc_asprintf_append_buffer(). Jeremy. (This used to be commit 0844dbf597191b3e4d35a696695b229e986daec4) --- source4/nbt_server/wins/wins_hook.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/nbt_server/wins/wins_hook.c') diff --git a/source4/nbt_server/wins/wins_hook.c b/source4/nbt_server/wins/wins_hook.c index e89e6b8d26..090621d890 100644 --- a/source4/nbt_server/wins/wins_hook.c +++ b/source4/nbt_server/wins/wins_hook.c @@ -67,7 +67,7 @@ void wins_hook(struct winsdb_handle *h, const struct winsdb_record *rec, if (!cmd) goto failed; for (i=0; rec->addresses[i]; i++) { - cmd = talloc_asprintf_append(cmd, " %s", rec->addresses[i]->address); + cmd = talloc_asprintf_append_buffer(cmd, " %s", rec->addresses[i]->address); if (!cmd) goto failed; } -- cgit From 37d53832a4623653f706e77985a79d84bd7c6694 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 28 Sep 2007 01:17:46 +0000 Subject: r25398: Parse loadparm context to all lp_*() functions. (This used to be commit 3fcc960839c6e5ca4de2c3c042f12f369ac5f238) --- source4/nbt_server/wins/wins_hook.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/nbt_server/wins/wins_hook.c') diff --git a/source4/nbt_server/wins/wins_hook.c b/source4/nbt_server/wins/wins_hook.c index 090621d890..768f9477f6 100644 --- a/source4/nbt_server/wins/wins_hook.c +++ b/source4/nbt_server/wins/wins_hook.c @@ -40,7 +40,7 @@ static const char *wins_hook_action_string(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(); + const char *script = lp_wins_hook(global_loadparm); uint32_t i, length; int child; char *cmd = NULL; -- cgit From 2f5ca872a80ad872ab864061f0c6982d8605393f Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 6 Dec 2007 16:54:34 +0100 Subject: r26313: Fix more uses of static loadparm. (This used to be commit 6fd0d9d3b75546d08c24c513e05b1843d5777608) --- source4/nbt_server/wins/wins_hook.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'source4/nbt_server/wins/wins_hook.c') diff --git a/source4/nbt_server/wins/wins_hook.c b/source4/nbt_server/wins/wins_hook.c index 768f9477f6..ae832774a3 100644 --- a/source4/nbt_server/wins/wins_hook.c +++ b/source4/nbt_server/wins/wins_hook.c @@ -38,15 +38,14 @@ static const char *wins_hook_action_string(enum wins_hook_action action) } void wins_hook(struct winsdb_handle *h, const struct winsdb_record *rec, - enum wins_hook_action action) + enum wins_hook_action action, const char *wins_hook_script) { - const char *script = lp_wins_hook(global_loadparm); uint32_t i, length; int child; char *cmd = NULL; TALLOC_CTX *tmp_mem = NULL; - if (!script || !script[0]) return; + if (!wins_hook_script || !wins_hook_script[0]) return; tmp_mem = talloc_new(h); if (!tmp_mem) goto failed; @@ -59,7 +58,7 @@ void wins_hook(struct winsdb_handle *h, const struct winsdb_record *rec, cmd = talloc_asprintf(tmp_mem, "%s %s %s %02x %ld", - script, + wins_hook_script, wins_hook_action_string(action), rec->name->name, rec->name->type, @@ -92,5 +91,5 @@ void wins_hook(struct winsdb_handle *h, const struct winsdb_record *rec, return; failed: talloc_free(tmp_mem); - DEBUG(0,("FAILED: calling wins hook '%s'\n", script)); + DEBUG(0,("FAILED: calling wins hook '%s'\n", wins_hook_script)); } -- cgit