iptables: Use printf format for iptables_command argument
authorSamuel Ortiz <sameo@linux.intel.com>
Thu, 28 Oct 2010 22:58:08 +0000 (00:58 +0200)
committerSamuel Ortiz <sameo@linux.intel.com>
Thu, 28 Oct 2010 22:58:31 +0000 (00:58 +0200)
src/connman.h
src/iptables.c

index 2fa1129..adca4d3 100644 (file)
@@ -590,5 +590,5 @@ int __connman_stats_get(struct connman_service *service,
 
 int __connman_iptables_init(void);
 void __connman_iptables_cleanup(void);
-int __connman_iptables_command(char *command);
-int __connman_iptables_commit(char *table_name);
+int __connman_iptables_command(const char *format, ...);
+int __connman_iptables_commit(const char *table_name);
index dcb1b8d..b5ce893 100644 (file)
@@ -918,14 +918,24 @@ out:
        return ret;
 }
 
-int __connman_iptables_command(char *command)
+int __connman_iptables_command(const char *format, ...)
 {
-       char **argv, **arguments;
+       char **argv, **arguments, *command;
        int argc, i, ret;
+       va_list args;
 
-       if (command == NULL)
+       if (format == NULL)
                return -EINVAL;
 
+       va_start(args, format);
+
+       command = g_strdup_vprintf(format, args);
+
+       va_end(args);
+
+       if (command == NULL)
+               return -ENOMEM;
+
        arguments = g_strsplit_set(command, " ", -1);
 
        for (argc = 0; arguments[argc]; argc++);
@@ -934,6 +944,7 @@ int __connman_iptables_command(char *command)
 
        argv = g_try_malloc0(argc * sizeof(char *));
        if (argv == NULL) {
+               g_free(command);
                g_strfreev(arguments);
                return -ENOMEM;
        }
@@ -944,6 +955,7 @@ int __connman_iptables_command(char *command)
 
        ret = iptables_command(argc, argv);
 
+       g_free(command);
        g_strfreev(arguments);
        g_free(argv);
 
@@ -951,7 +963,7 @@ int __connman_iptables_command(char *command)
 }
 
 
-int __connman_iptables_commit(char *table_name)
+int __connman_iptables_commit(const char *table_name)
 {
        struct connman_iptables *table;
        struct ipt_replace *repl;