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>
17 #include <sys/types.h>
24 #define CONFIG_FILE "/etc/athena/moira.conf"
26 /* Variables currently supported:
27 * chroot directory daemon will run chrooted to this directory
28 * user username daemon will run with this user's uid
29 * port portname daemon will listen on this port number
30 * nofork server stays in foreground & logs to stdout
31 * auth krbname this user is authorized to connect
32 * noclobber will not overwrite existing files
33 * noexec will not execute instructions received
36 static char *config_buf = NULL;
37 static char **config_keys, **config_values;
46 /* Only execute once */
47 if (config_buf) return(MR_SUCCESS);
49 fd = open(CONFIG_FILE, O_RDONLY, 0);
52 config_keys = (char **)malloc(sizeof(char *) * 2);
53 config_keys[0] = config_keys[1] = NULL;
56 if (fstat(fd, &st) < 0) {
59 config_buf = (char *) malloc(st.st_size + 2);
60 if (config_buf == NULL) {
63 if (read(fd, config_buf, st.st_size) < st.st_size) {
68 config_buf[st.st_size] = '\0';
70 for (p = config_buf; *p; p++)
71 if (*p == '\n') count++;
73 config_keys = (char **)malloc(count * sizeof(char *));
74 config_values = (char **)malloc(count * sizeof(char *));
75 if (config_keys == NULL || config_values == NULL) {
81 for (p = strtok(config_buf, "\n"); p; p = strtok(NULL, "\n")) {
82 config_keys[count++] = p;
84 config_keys[count] = NULL;
85 for (count = 0; config_keys[count]; count++) {
86 config_values[count] = "";
87 for (p = config_keys[count]; *p; p++)
90 while (*p && isspace(*p)) p++;
91 config_values[count] = p;
98 /* Given a key, lookup the associated value.
99 * Returns "" on a key without a value, NULL on a non-existant key.
100 * If a key appears multiple times, successive calls will cycle through
101 * the possible values.
104 char *config_lookup(key)
110 if (init() != MR_SUCCESS)
114 if (config_keys[i] == NULL) i = 0;
115 if (config_keys[i] == NULL) return(NULL);
118 if (!strcasecmp(key, config_keys[i]))
119 return(config_values[i]);
120 if (config_keys[++i] == NULL)
122 } while (i != start);
124 if (!strcasecmp(key, config_keys[i]))
125 return(config_values[i]);