From 52e54c1c9a0f530edca461da31279113647fe787 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Sat, 12 Oct 2013 18:22:51 +0200 Subject: [PATCH] misc-progs: Move network stuff to own header file. --- src/misc-progs/ipsecctrl.c | 2 ++ src/misc-progs/netutil.h | 48 +++++++++++++++++++++++++++++++++++ src/misc-progs/openvpnctrl.c | 1 + src/misc-progs/rebuildhosts.c | 2 ++ src/misc-progs/setaliases.c | 6 +++-- src/misc-progs/setuid.h | 41 ------------------------------ src/misc-progs/syslogdctrl.c | 2 ++ src/misc-progs/wirelessctrl.c | 4 ++- 8 files changed, 62 insertions(+), 44 deletions(-) create mode 100644 src/misc-progs/netutil.h diff --git a/src/misc-progs/ipsecctrl.c b/src/misc-progs/ipsecctrl.c index 365807c9e..570fdebab 100644 --- a/src/misc-progs/ipsecctrl.c +++ b/src/misc-progs/ipsecctrl.c @@ -13,7 +13,9 @@ #include #include #include + #include "setuid.h" +#include "netutil.h" /* This module is responsible for start stop of the vpn system. diff --git a/src/misc-progs/netutil.h b/src/misc-progs/netutil.h new file mode 100644 index 000000000..e96eb5de2 --- /dev/null +++ b/src/misc-progs/netutil.h @@ -0,0 +1,48 @@ + +#ifndef NETUTIL_H +#define NETUTIL_H 1 + +#include + +#define LETTERS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" +#define NUMBERS "0123456789" +#define LETTERS_NUMBERS LETTERS NUMBERS +#define IP_NUMBERS "./" NUMBERS +#define PORT_NUMBERS ":-" NUMBERS +#define VALID_FQDN LETTERS_NUMBERS ".-" + +#define VALID_IP(ip) (strlen(ip) > 6 \ + && strlen(ip) < 16 \ + && strspn(ip, NUMBERS ".") == strlen(ip)) + +#define VALID_IP_AND_MASK(ip) (strlen(ip) > 6 \ + && strlen(ip) < 32 \ + && strspn(ip, IP_NUMBERS) == strlen(ip)) + +#define VALID_PORT(port) (strlen(port) \ + && strlen(port) < 6 \ + && strspn(port, NUMBERS) == strlen(port)) + +#define VALID_PORT_RANGE(port) (strlen(port) \ + && strlen(port) < 12 \ + && strspn(port, PORT_NUMBERS) == strlen(port)) + +#define VALID_SHORT_MASK(ip) (strlen(ip) > 1 \ + && strlen(ip) < 3 \ + && strspn(ip, NUMBERS) == strlen(ip)) + +/* Can't find any info on valid characters/length hopefully these are + * reasonable guesses */ +#define VALID_DEVICE(dev) (strlen(dev) \ + && strlen(dev) < 16 \ + && strspn(dev, LETTERS_NUMBERS ":.") == strlen(dev)) + +/* Again, can't find any hard and fast rules for protocol names, these + * restrictions are based on the keywords currently listed in + * + * though currently the ipcop cgis will only pass tcp, udp or gre anyway */ +#define VALID_PROTOCOL(prot) (strlen(prot) \ + && strlen(prot) <16 \ + && strspn(prot, LETTERS_NUMBERS "-") == strlen(prot)) + +#endif diff --git a/src/misc-progs/openvpnctrl.c b/src/misc-progs/openvpnctrl.c index 4c1d1c3bb..257778892 100644 --- a/src/misc-progs/openvpnctrl.c +++ b/src/misc-progs/openvpnctrl.c @@ -8,6 +8,7 @@ #include #include #include "setuid.h" +#include "netutil.h" #include "libsmooth.h" #define noovpndebug diff --git a/src/misc-progs/rebuildhosts.c b/src/misc-progs/rebuildhosts.c index e83185881..21c523600 100644 --- a/src/misc-progs/rebuildhosts.c +++ b/src/misc-progs/rebuildhosts.c @@ -19,7 +19,9 @@ #include #include #include + #include "setuid.h" +#include "netutil.h" FILE *fd = NULL; FILE *hosts = NULL; diff --git a/src/misc-progs/setaliases.c b/src/misc-progs/setaliases.c index ea4bc11db..93af1cb0a 100644 --- a/src/misc-progs/setaliases.c +++ b/src/misc-progs/setaliases.c @@ -13,8 +13,6 @@ * */ -#include "libsmooth.h" -#include "setuid.h" #include #include #include @@ -23,6 +21,10 @@ #include #include +#include "libsmooth.h" +#include "setuid.h" +#include "netutil.h" + struct keyvalue *kv = NULL; FILE *file = NULL; diff --git a/src/misc-progs/setuid.h b/src/misc-progs/setuid.h index 1e0aed2a0..d1155c5e8 100644 --- a/src/misc-progs/setuid.h +++ b/src/misc-progs/setuid.h @@ -17,47 +17,6 @@ #ifndef STRING_SIZE #define STRING_SIZE 256 #endif -#define LETTERS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" -#define NUMBERS "0123456789" -#define LETTERS_NUMBERS LETTERS NUMBERS -#define IP_NUMBERS "./" NUMBERS -#define PORT_NUMBERS ":-" NUMBERS -#define VALID_FQDN LETTERS_NUMBERS ".-" - - -#define VALID_IP(ip) (strlen(ip) > 6 \ - && strlen(ip) < 16 \ - && strspn(ip, NUMBERS ".") == strlen(ip)) - -#define VALID_IP_AND_MASK(ip) (strlen(ip) > 6 \ - && strlen(ip) < 32 \ - && strspn(ip, IP_NUMBERS) == strlen(ip)) - -#define VALID_PORT(port) (strlen(port) \ - && strlen(port) < 6 \ - && strspn(port, NUMBERS) == strlen(port)) - -#define VALID_PORT_RANGE(port) (strlen(port) \ - && strlen(port) < 12 \ - && strspn(port, PORT_NUMBERS) == strlen(port)) - -#define VALID_SHORT_MASK(ip) (strlen(ip) > 1 \ - && strlen(ip) < 3 \ - && strspn(ip, NUMBERS) == strlen(ip)) - -/* Can't find any info on valid characters/length hopefully these are - * reasonable guesses */ -#define VALID_DEVICE(dev) (strlen(dev) \ - && strlen(dev) < 16 \ - && strspn(dev, LETTERS_NUMBERS ":.") == strlen(dev)) - -/* Again, can't find any hard and fast rules for protocol names, these - * restrictions are based on the keywords currently listed in - * - * though currently the ipcop cgis will only pass tcp, udp or gre anyway */ -#define VALID_PROTOCOL(prot) (strlen(prot) \ - && strlen(prot) <16 \ - && strspn(prot, LETTERS_NUMBERS "-") == strlen(prot)) extern char * trusted_env[4]; diff --git a/src/misc-progs/syslogdctrl.c b/src/misc-progs/syslogdctrl.c index 993cc938d..8111c84c5 100644 --- a/src/misc-progs/syslogdctrl.c +++ b/src/misc-progs/syslogdctrl.c @@ -19,8 +19,10 @@ #include #include #include + #include "libsmooth.h" #include "setuid.h" +#include "netutil.h" #define ERR_ANY 1 #define ERR_SETTINGS 2 /* error in settings file */ diff --git a/src/misc-progs/wirelessctrl.c b/src/misc-progs/wirelessctrl.c index 8ca7a81ae..e3a1107c2 100644 --- a/src/misc-progs/wirelessctrl.c +++ b/src/misc-progs/wirelessctrl.c @@ -16,9 +16,11 @@ #include #include #include -#include "setuid.h" #include +#include "setuid.h" +#include "netutil.h" + FILE *fd = NULL; char blue_dev[STRING_SIZE] = ""; char command[STRING_SIZE]; -- 2.39.2