configdefs.h 4.73 KB
Newer Older
1
/*
2
 * Copyright (c) 2010-2018 University of Utah and the Flux Group.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 * 
 * {{{EMULAB-LICENSE
 * 
 * This file is part of the Emulab network testbed software.
 * 
 * This file is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or (at
 * your option) any later version.
 * 
 * This file is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
 * License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with this file.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * }}}
 */

24 25 26
#include <netinet/in.h>
#include <arpa/inet.h>

27 28
/*
 * Maximum groups for a server process.
29
 * We limit NGROUPS_MAX because it is huge on Linux (64K).
30
 */
31 32 33 34 35
#if NGROUPS_MAX < 1024
#define MAXGIDS (NGROUPS_MAX+1)
#else
#define MAXGIDS	1024
#endif
36

37 38
#define MAXIMAGEDIRS 4

39 40
#define NOUID (-1)

41 42 43 44 45 46
/*
 * Config info for a single image
 * XXX needs to be extended for REs.
 */
struct config_imageinfo {
	char *imageid;		/* unique name of image */
47
	char *dir;		/* directory to which path must resolve */
48
	char *path;		/* path where image is stored */
49
	void *sig;		/* signature of image */
50
	int flags;		/* */
51
	int uid;		/* UID to run server process as */
52 53
	gid_t gids[MAXGIDS];	/* GIDs to run server process as */
	int ngids;		/* number of valid GIDs */
54
	char *get_options;	/* command line options for GET server */
55
	int get_methods;	/* allowed GET transfer mechanisms */
56 57 58 59
	int get_timeout;	/* max time to allow GET server to run */
	char *put_options;	/* command line options for PUT server */
	uint64_t put_maxsize;	/* maximum size for this image */
	int put_timeout;	/* max time to allow PUT server to run */
60
	int put_itimeout;	/* max time to allow per-socket-op to run */
61
	char *put_oldversion;	/* where to save the old version */
62
	char *pget_options;	/* options for parent-fetch client */
63 64 65 66
	void *extra;		/* config-type specific info */
};

/* flags */
67 68 69 70
#define CONFIG_PATH_ISFILE	0x1	/* path is an image file */
#define CONFIG_PATH_ISDIR	0x2	/* path is a directory */
#define CONFIG_PATH_ISGLOB	0x4	/* path is a file glob */
#define CONFIG_PATH_ISRE	0x8	/* path is a perl RE */
71 72 73
#define CONFIG_PATH_ISSIGFILE	0x10	/* path is an image sigfile */
#define CONFIG_PATH_RESOLVE	0x20	/* path needs resolution at use */
#define CONFIG_PATH_EXISTS	0x40	/* imaged named by path arg exists */
74 75 76
#define CONFIG_SIG_ISMTIME	0x1000	/* sig is path mtime */
#define CONFIG_SIG_ISMD5	0x2000	/* sig is MD5 hash of path */
#define CONFIG_SIG_ISSHA1	0x4000	/* sig is SHA1 hash of path */
77 78 79 80 81 82

/* methods */
#define CONFIG_IMAGE_UNKNOWN	0x0
#define CONFIG_IMAGE_UCAST	0x1
#define CONFIG_IMAGE_MCAST	0x2
#define CONFIG_IMAGE_BCAST	0x4
83
#define CONFIG_IMAGE_ANY	0x7
84 85 86 87 88 89 90 91 92 93 94 95 96 97

struct config_host_authinfo {
	char *hostid;		/* unique name of host */
	int numimages;		/* number of images in info array */
	struct config_imageinfo *imageinfo; /* info array */
	void *extra;		/* config-type specific info */
};

/*
 * Config file functions
 */
struct config {
	void (*config_deinit)(void);
	int (*config_read)(void);
98 99
	int (*config_get_host_authinfo)(struct in_addr *,
					struct in_addr *, char *,
100 101 102
					struct config_host_authinfo **,
					struct config_host_authinfo **);
	void (*config_free_host_authinfo)(struct config_host_authinfo *);
Mike Hibler's avatar
Mike Hibler committed
103
	int (*config_get_server_address)(struct config_imageinfo *, int, int,
104 105
					 in_addr_t *, in_port_t *, in_port_t *,
					 int *);
106
	char *(*config_canonicalize_imageid)(char *);
107 108 109 110 111 112
	void *(*config_save)(void);
	int (*config_restore)(void *);
	void (*config_free)(void *);
	void (*config_dump)(FILE *);
};

113
extern int	config_init(char *, int, char *);
114 115
extern void	config_deinit(void);
extern int	config_read(void);
116 117
extern int	config_get_host_authinfo(struct in_addr *,
					 struct in_addr *, char *,
118 119
					 struct config_host_authinfo **,
					 struct config_host_authinfo **);
120
extern void	config_dump_host_authinfo(struct config_host_authinfo *);
121
extern void	config_free_host_authinfo(struct config_host_authinfo *);
122 123
extern int	config_auth_by_IP(int, struct in_addr *, struct in_addr *,
				  char *, struct config_host_authinfo **);
Mike Hibler's avatar
Mike Hibler committed
124
extern int	config_get_server_address(struct config_imageinfo *, int, int,
125 126
					  in_addr_t *, in_port_t *, in_port_t *,
					  int *);
127
extern char *	config_canonicalize_imageid(char *);
128 129 130
extern void *	config_save(void);
extern int	config_restore(void *);
extern void	config_dump(FILE *);
131 132 133 134 135 136

/* Common utility functions */
extern char *	isindir(char *dir, char *path);
extern char *	myrealpath(char *path, char rpath[PATH_MAX]);
extern char *	resolvepath(char *path, char *dir, int create);