]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - src/misc-progs/setuid.h
git-svn-id: http://svn.ipfire.org/svn/ipfire/IPFire/source@16 ea5c0bd1-69bd-2848...
[people/teissler/ipfire-2.x.git] / src / misc-progs / setuid.h
1 /* SmoothWall helper program - header file
2 *
3 * This program is distributed under the terms of the GNU General Public
4 * Licence. See the file COPYING for details.
5 * Simple header file for all setuid progs.
6 *
7 * $Id: setuid.h,v 1.4.2.4 2005/11/20 23:20:13 franck78 Exp $
8 *
9 */
10
11 #ifndef SETUID_H
12 #define SETUID_H 1
13
14 #include <stdlib.h>
15 #include <sys/types.h>
16
17 /* As nothing in setuid.c uses STRING_SIZE specifically there's no real reason
18 * to redefine it if it already is set */
19 #ifndef STRING_SIZE
20 #define STRING_SIZE 256
21 #endif
22 #define LETTERS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
23 #define NUMBERS "0123456789"
24 #define LETTERS_NUMBERS LETTERS NUMBERS
25 #define IP_NUMBERS "./" NUMBERS
26 #define PORT_NUMBERS ":-" NUMBERS
27 #define VALID_FQDN LETTERS_NUMBERS ".-"
28
29
30 #define VALID_IP(ip) (strlen(ip) > 6 \
31 && strlen(ip) < 16 \
32 && strspn(ip, NUMBERS ".") == strlen(ip))
33
34 #define VALID_IP_AND_MASK(ip) (strlen(ip) > 6 \
35 && strlen(ip) < 32 \
36 && strspn(ip, IP_NUMBERS) == strlen(ip))
37
38 #define VALID_PORT(port) (strlen(port) \
39 && strlen(port) < 6 \
40 && strspn(port, NUMBERS) == strlen(port))
41
42 #define VALID_PORT_RANGE(port) (strlen(port) \
43 && strlen(port) < 12 \
44 && strspn(port, PORT_NUMBERS) == strlen(port))
45
46 #define VALID_SHORT_MASK(ip) (strlen(ip) > 1 \
47 && strlen(ip) < 3 \
48 && strspn(ip, NUMBERS) == strlen(ip))
49
50 /* Can't find any info on valid characters/length hopefully these are
51 * reasonable guesses */
52 #define VALID_DEVICE(dev) (strlen(dev) \
53 && strlen(dev) < 16 \
54 && strspn(dev, LETTERS_NUMBERS ":.") == strlen(dev))
55
56 /* Again, can't find any hard and fast rules for protocol names, these
57 * restrictions are based on the keywords currently listed in
58 * <http://www.iana.org/assignments/protocol-numbers>
59 * though currently the ipcop cgis will only pass tcp, udp or gre anyway */
60 #define VALID_PROTOCOL(prot) (strlen(prot) \
61 && strlen(prot) <16 \
62 && strspn(prot, LETTERS_NUMBERS "-") == strlen(prot))
63
64 extern char * trusted_env[4];
65
66 int system_core(char* command, uid_t uid, gid_t gid, char *error);
67 int safe_system(char* command);
68 int unpriv_system(char* command, uid_t uid, gid_t gid);
69 size_t strlcat(char *dst, const char *src, size_t len);
70 int initsetuid(void);
71
72 /* check whether a file exists */
73 int file_exists(const char *fname);
74 int file_exists_w(const char *fname); //wildcard filename test
75
76 // Backup restore
77 #define MOUNTPOINT "/home/httpd/html/backup"
78 #define BACKUP_KEY CONFIG_ROOT"/backup/backup.key"
79
80 /* defines for config create/restore return status*/
81 #define ERR_ANY 1 // unspecified error
82 #define ERR_KEY 2 // error creating key file
83 #define ERR_TAR 3 // error creating .tar
84 #define ERR_GZ 4 // error creating .tar.gz
85 #define ERR_ENCRYPT 5 // error creating .dat
86 #define ERR_DECRYPT 6 // error decrypting .dat file
87 #define ERR_UNTARTST 7 // error (test) untarring .tar.gz
88 #define ERR_UNTAR 8 // error (real) untarring .tar.gz
89 #define ERR_DAT 9 // missing .dat file
90
91 #endif