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>
16 #include <sys/types.h>
23 #define CONFIG_FILE "/etc/athena/moira.conf"
25 /* Variables currently supported:
26 * chroot directory daemon will run chrooted to this directory
27 * user username daemon will run with this user's uid
28 * port portname daemon will listen on this port number
29 * nofork server stays in foreground & logs to stdout
30 * auth krbname this user is authorized to connect
31 * noclobber will not overwrite existing files
32 * noexec will not execute instructions received
35 static char *config_buf = NULL;
36 static char **config_keys, **config_values;
45 /* Only execute once */
46 if (config_buf) return(MR_SUCCESS);
48 fd = open(CONFIG_FILE, O_RDONLY, 0);
51 config_keys = (char **)malloc(sizeof(char *) * 2);
52 config_keys[0] = config_keys[1] = NULL;
55 if (fstat(fd, &st) < 0) {
58 config_buf = (char *) malloc(st.st_size + 2);
59 if (config_buf == NULL) {
62 if (read(fd, config_buf, st.st_size) < st.st_size) {
67 config_buf[st.st_size] = '\0';
69 for (p = config_buf; *p; p++)
70 if (*p == '\n') count++;
72 config_keys = (char **)malloc(count * sizeof(char *));
73 config_values = (char **)malloc(count * sizeof(char *));
74 if (config_keys == NULL || config_values == NULL) {
80 for (p = start = config_buf; *p; p++) {
84 config_keys[count++] = start;
88 config_keys[count] = NULL;
89 for (count = 0; config_keys[count]; count++) {
90 config_values[count] = "";
91 for (p = config_keys[count]; *p; p++)
94 while (*p && isspace(*p)) p++;
95 config_values[count] = p;
102 /* Given a key, lookup the associated value.
103 * Returns "" on a key without a value, NULL on a non-existant key.
104 * If a key appears multiple times, successive calls will cycle through
105 * the possible values.
108 char *config_lookup(key)
114 if (init() != MR_SUCCESS)
118 if (config_keys[i] == NULL) i = 0;
119 if (config_keys[i] == NULL) return(NULL);
122 if (!strcasecmp(key, config_keys[i]))
123 return(config_values[i]);
124 if (config_keys[++i] == NULL)
126 } while (i != start);
128 if (!strcasecmp(key, config_keys[i]))
129 return(config_values[i]);