From 427deccbd4479dcb943bc7eab14f228c23b264b6 Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Thu, 18 Jul 2019 14:44:09 +0200 Subject: xtables-save: Use argv[0] as program name Don't hard-code program names. This also fixes for bogus 'xtables-save' name which is no longer used. Signed-off-by: Phil Sutter Signed-off-by: Pablo Neira Ayuso --- iptables/xtables-save.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'iptables/xtables-save.c') diff --git a/iptables/xtables-save.c b/iptables/xtables-save.c index 98e004af..b8d19705 100644 --- a/iptables/xtables-save.c +++ b/iptables/xtables-save.c @@ -9,6 +9,7 @@ #include "config.h" #include #include +#include #include #include #include @@ -80,8 +81,8 @@ __do_output(struct nft_handle *h, const char *tablename, bool counters) time_t now = time(NULL); - printf("# Generated by xtables-save v%s on %s", - PACKAGE_VERSION, ctime(&now)); + printf("# Generated by %s v%s on %s", prog_name, + prog_vers, ctime(&now)); printf("*%s\n", tablename); /* Dump out chain names first, @@ -122,7 +123,7 @@ do_output(struct nft_handle *h, const char *tablename, bool counters) * rule */ static int -xtables_save_main(int family, const char *progname, int argc, char *argv[]) +xtables_save_main(int family, int argc, char *argv[]) { const struct builtin_table *tables; const char *tablename = NULL; @@ -133,7 +134,7 @@ xtables_save_main(int family, const char *progname, int argc, char *argv[]) FILE *file = NULL; int ret, c; - xtables_globals.program_name = progname; + xtables_globals.program_name = basename(*argv);; c = xtables_init_all(&xtables_globals, family); if (c < 0) { fprintf(stderr, "%s/%s Failed to initialize xtables\n", @@ -237,12 +238,12 @@ xtables_save_main(int family, const char *progname, int argc, char *argv[]) int xtables_ip4_save_main(int argc, char *argv[]) { - return xtables_save_main(NFPROTO_IPV4, "iptables-save", argc, argv); + return xtables_save_main(NFPROTO_IPV4, argc, argv); } int xtables_ip6_save_main(int argc, char *argv[]) { - return xtables_save_main(NFPROTO_IPV6, "ip6tables-save", argc, argv); + return xtables_save_main(NFPROTO_IPV6, argc, argv); } static int __ebt_save(struct nft_handle *h, const char *tablename, bool counters) @@ -266,8 +267,8 @@ static int __ebt_save(struct nft_handle *h, const char *tablename, bool counters if (first) { now = time(NULL); - printf("# Generated by ebtables-save v%s on %s", - PACKAGE_VERSION, ctime(&now)); + printf("# Generated by %s v%s on %s", prog_name, + prog_vers, ctime(&now)); first = false; } printf("*%s\n", tablename); @@ -307,7 +308,7 @@ int xtables_eb_save_main(int argc_, char *argv_[]) } } - xtables_globals.program_name = "ebtables-save"; + xtables_globals.program_name = basename(*argv_); c = xtables_init_all(&xtables_globals, h.family); if (c < 0) { fprintf(stderr, "%s/%s Failed to initialize xtables\n", @@ -361,7 +362,7 @@ int xtables_arp_save_main(int argc, char **argv) }; int c; - xtables_globals.program_name = "arptables-save"; + xtables_globals.program_name = basename(*argv);; c = xtables_init_all(&xtables_globals, h.family); if (c < 0) { fprintf(stderr, "%s/%s Failed to initialize xtables\n", -- cgit v1.2.3