s4-dns: use a loadparm list for samba_runcmd() commands
authorAndrew Tridgell <tridge@samba.org>
Fri, 26 Feb 2010 06:09:35 +0000 (17:09 +1100)
committerAndrew Tridgell <tridge@samba.org>
Fri, 26 Feb 2010 07:19:27 +0000 (18:19 +1100)
This allows commands with multiple arguments and quoting to be used,
while still avoiding running a shell (and this having shell expansion
problems)

lib/util/util.h
lib/util/util_runcmd.c
source4/dsdb/dns/dns_update.c
source4/param/loadparm.c
source4/param/param.h

index 01831fc826d2ef4aa38d74e29f1c7011c0d9e749..e1608a8ac4baeed75b77ecbf213b290973232817 100644 (file)
@@ -890,7 +890,7 @@ struct composite_context *samba_runcmd(struct tevent_context *ev,
                                       struct timeval timeout,
                                       int stdout_log_level,
                                       int stderr_log_level,
-                                      const char *arg0, ...);
+                                      const char **argv0, ...);
 
 
 #endif /* _SAMBA_UTIL_H_ */
index 80574c4400f96a0230ce0edcac2aa41b4532bd68..dea3ff91b1d5590ffdf588543d30a3d1be43e2b9 100644 (file)
@@ -154,7 +154,7 @@ struct composite_context *samba_runcmd(struct tevent_context *ev,
                                       struct timeval timeout,
                                       int stdout_log_level,
                                       int stderr_log_level,
-                                      const char *arg0, ...)
+                                      const char **argv0, ...)
 {
        struct samba_runcmd *r;
        int p1[2], p2[2];
@@ -174,7 +174,7 @@ struct composite_context *samba_runcmd(struct tevent_context *ev,
        r->stdout_log_level = stdout_log_level;
        r->stderr_log_level = stderr_log_level;
 
-       r->arg0 = talloc_strdup(r, arg0);
+       r->arg0 = talloc_strdup(r, argv0[0]);
        if (composite_nomem(r->arg0, c)) return c;
 
        if (pipe(p1) != 0) {
@@ -228,13 +228,13 @@ struct composite_context *samba_runcmd(struct tevent_context *ev,
        dup2(p1[1], 1);
        dup2(p2[1], 2);
 
-       argv = str_list_make_single(r, r->arg0);
+       argv = str_list_copy(r, argv0);
        if (!argv) {
                fprintf(stderr, "Out of memory in child\n");
                _exit(255);
        }
 
-       va_start(ap, arg0);
+       va_start(ap, argv0);
        while (1) {
                char *arg = va_arg(ap, char *);
                if (arg == NULL) break;
@@ -246,7 +246,7 @@ struct composite_context *samba_runcmd(struct tevent_context *ev,
        }
        va_end(ap);
 
-       ret = execv(arg0, argv);
+       ret = execv(r->arg0, argv);
        fprintf(stderr, "Failed to exec child - %s\n", strerror(errno));
        _exit(255);
        return NULL;
index 82cb7155ac597e027c6641573aed3f612b4823f6..4fefd656d71bbf584fee2f9d583a9841139c025e 100644 (file)
@@ -157,10 +157,10 @@ static void dnsupdate_rebuild(struct dnsupdate_service *service)
 
        DEBUG(2,("Loading new DNS update grant rules\n"));
        service->confupdate.c = samba_runcmd(service->task->event_ctx, service,
-                                          timeval_current_ofs(10, 0),
-                                          2, 0,
-                                          lp_rndc_command(service->task->lp_ctx),
-                                          "reload", NULL);
+                                            timeval_current_ofs(10, 0),
+                                            2, 0,
+                                            lp_rndc_command(service->task->lp_ctx),
+                                            "reload", NULL);
        service->confupdate.c->async.fn = dnsupdate_rndc_done;
        service->confupdate.c->async.private_data = service;
 
index 5eaf67fab52a257f36daf9988e1c2ae89888d22f..46bbceb8620606dbfac70481b9a3402225bae0c3 100644 (file)
@@ -186,8 +186,8 @@ struct loadparm_global
        int bDisableNetbios;
        int bRpcBigEndian;
        char *szNTPSignDSocketDirectory;
-       char *szRNDCCommand;
-       char *szDNSUpdateCommand;
+       const char **szRNDCCommand;
+       const char **szDNSUpdateCommand;
        char *szNSUpdateCommand;
        struct parmlist_entry *param_opt;
 };
@@ -506,8 +506,8 @@ static struct parm_struct parm_table[] = {
        {"idmap trusted only", P_BOOL, P_GLOBAL, GLOBAL_VAR(bIdmapTrustedOnly), NULL, NULL},
 
        {"ntp signd socket directory", P_STRING, P_GLOBAL, GLOBAL_VAR(szNTPSignDSocketDirectory), NULL, NULL },
-       {"rndc command", P_STRING, P_GLOBAL, GLOBAL_VAR(szRNDCCommand), NULL, NULL },
-       {"dns update command", P_STRING, P_GLOBAL, GLOBAL_VAR(szDNSUpdateCommand), NULL, NULL },
+       {"rndc command", P_LIST, P_GLOBAL, GLOBAL_VAR(szRNDCCommand), NULL, NULL },
+       {"dns update command", P_LIST, P_GLOBAL, GLOBAL_VAR(szDNSUpdateCommand), NULL, NULL },
        {"nsupdate command", P_STRING, P_GLOBAL, GLOBAL_VAR(szNSUpdateCommand), NULL, NULL },
 
        {NULL, P_BOOL, P_NONE, 0, NULL, NULL}
@@ -660,8 +660,8 @@ _PUBLIC_ FN_GLOBAL_STRING(lp_dos_charset, dos_charset)
 _PUBLIC_ FN_GLOBAL_STRING(lp_unix_charset, unix_charset)
 _PUBLIC_ FN_GLOBAL_STRING(lp_display_charset, display_charset)
 _PUBLIC_ FN_GLOBAL_STRING(lp_piddir, szPidDir)
-_PUBLIC_ FN_GLOBAL_STRING(lp_rndc_command, szRNDCCommand)
-_PUBLIC_ FN_GLOBAL_STRING(lp_dns_update_command, szDNSUpdateCommand)
+_PUBLIC_ FN_GLOBAL_LIST(lp_rndc_command, szRNDCCommand)
+_PUBLIC_ FN_GLOBAL_LIST(lp_dns_update_command, szDNSUpdateCommand)
 _PUBLIC_ FN_GLOBAL_STRING(lp_nsupdate_command, szNSUpdateCommand)
 _PUBLIC_ FN_GLOBAL_LIST(lp_dcerpc_endpoint_servers, dcerpc_ep_servers)
 _PUBLIC_ FN_GLOBAL_LIST(lp_server_services, server_services)
index 4ac7eef0f17e655d43216323889792a2c343c471..f72fa76174a953c2be655fd63828053d1116cd81 100644 (file)
@@ -130,8 +130,8 @@ const char **lp_wins_server_list(struct loadparm_context *);
 const char **lp_interfaces(struct loadparm_context *);
 const char *lp_socket_address(struct loadparm_context *);
 const char **lp_netbios_aliases(struct loadparm_context *);
-const char *lp_rndc_command(struct loadparm_context *);
-const char *lp_dns_update_command(struct loadparm_context *);
+const char **lp_rndc_command(struct loadparm_context *);
+const char **lp_dns_update_command(struct loadparm_context *);
 bool lp_disable_netbios(struct loadparm_context *);
 bool lp_wins_support(struct loadparm_context *);
 bool lp_wins_dns_proxy(struct loadparm_context *);