misc-progs: Move network stuff to own header file.

This commit is contained in:
Michael Tremer
2013-10-12 18:22:51 +02:00
parent 42ec14cf2b
commit 52e54c1c9a
8 changed files with 62 additions and 44 deletions

View File

@@ -13,7 +13,9 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <signal.h>
#include "setuid.h"
#include "netutil.h"
/*
This module is responsible for start stop of the vpn system.

48
src/misc-progs/netutil.h Normal file
View File

@@ -0,0 +1,48 @@
#ifndef NETUTIL_H
#define NETUTIL_H 1
#include <stdlib.h>
#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
* <http://www.iana.org/assignments/protocol-numbers>
* 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

View File

@@ -8,6 +8,7 @@
#include <netinet/in.h>
#include <fcntl.h>
#include "setuid.h"
#include "netutil.h"
#include "libsmooth.h"
#define noovpndebug

View File

@@ -19,7 +19,9 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <signal.h>
#include "setuid.h"
#include "netutil.h"
FILE *fd = NULL;
FILE *hosts = NULL;

View File

@@ -13,8 +13,6 @@
*
*/
#include "libsmooth.h"
#include "setuid.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -23,6 +21,10 @@
#include <sys/stat.h>
#include <fcntl.h>
#include "libsmooth.h"
#include "setuid.h"
#include "netutil.h"
struct keyvalue *kv = NULL;
FILE *file = NULL;

View File

@@ -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
* <http://www.iana.org/assignments/protocol-numbers>
* 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];

View File

@@ -19,8 +19,10 @@
#include <fcntl.h>
#include <signal.h>
#include <errno.h>
#include "libsmooth.h"
#include "setuid.h"
#include "netutil.h"
#define ERR_ANY 1
#define ERR_SETTINGS 2 /* error in settings file */

View File

@@ -16,9 +16,11 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <signal.h>
#include "setuid.h"
#include <errno.h>
#include "setuid.h"
#include "netutil.h"
FILE *fd = NULL;
char blue_dev[STRING_SIZE] = "";
char command[STRING_SIZE];