3 * Routines to handle configuration file for Moira's update_server.
4 * These routines must load the file into memory rather than parse
5 * it each time as one of the things the server may do is chroot()
8 * (c) Copyright 1992 by the Massachusetts Institute of Technology.
9 * For copying and distribution information, please see the file
13 #include <mit-copyright.h>
18 #include <sys/types.h>
25 #define CONFIG_FILE "/etc/athena/moira.conf"
27 /* Variables currently supported:
28 * chroot directory daemon will run chrooted to this directory
29 * user username daemon will run with this user's uid
30 * port portname daemon will listen on this port number
31 * nofork server stays in foreground & logs to stdout
32 * auth krbname this user is authorized to connect
33 * noclobber will not overwrite existing files
34 * noexec will not execute instructions received
37 static char *config_buf = NULL;
38 static char **config_keys, **config_values;
47 /* Only execute once */
51 fd = open(CONFIG_FILE, O_RDONLY, 0);
55 config_keys = malloc(sizeof(char *) * 2);
56 config_keys[0] = config_keys[1] = NULL;
59 if (fstat(fd, &st) < 0)
61 config_buf = malloc(st.st_size + 2);
64 if (read(fd, config_buf, st.st_size) < st.st_size)
70 config_buf[st.st_size] = '\0';
72 for (p = config_buf; *p; p++)
78 config_keys = malloc(count * sizeof(char *));
79 config_values = malloc(count * sizeof(char *));
80 if (!config_keys || !config_values)
87 for (p = strtok(config_buf, "\n"); p; p = strtok(NULL, "\n"))
88 config_keys[count++] = p;
89 config_keys[count] = NULL;
90 for (count = 0; config_keys[count]; count++)
92 config_values[count] = "";
93 for (p = config_keys[count]; *p; p++)
98 while (*p && isspace(*p))
100 config_values[count] = p;
108 /* Given a key, lookup the associated value.
109 * Returns "" on a key without a value, NULL on a non-existant key.
110 * If a key appears multiple times, successive calls will cycle through
111 * the possible values.
114 char *config_lookup(char *key)
119 if (init() != MR_SUCCESS)
130 if (!strcasecmp(key, config_keys[i]))
131 return config_values[i];
132 if (!config_keys[++i])
137 if (!strcasecmp(key, config_keys[i]))
138 return config_values[i];