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>
22 #define CONFIG_FILE "/etc/athena/moira.conf"
24 /* Variables currently supported:
25 * chroot directory daemon will run chrooted to this directory
26 * user username daemon will run with this user's uid
27 * port portname daemon will listen on this port number
28 * nofork server stays in foreground & logs to stdout
29 * auth krbname this user is authorized to connect
30 * noclobber will not overwrite existing files
31 * noexec will not execute instructions received
34 static char *config_buf = NULL;
35 static char **config_keys, **config_values;
44 /* Only execute once */
45 if (config_buf) return(MR_SUCCESS);
47 fd = open(CONFIG_FILE, O_RDONLY, 0);
50 config_keys = (char **)malloc(sizeof(char *) * 2);
51 config_keys[0] = config_keys[1] = NULL;
54 if (fstat(fd, &st) < 0) {
57 config_buf = (char *) malloc(st.st_size + 2);
58 if (config_buf == NULL) {
61 if (read(fd, config_buf, st.st_size) < st.st_size) {
66 config_buf[st.st_size] = '\0';
68 for (p = config_buf; *p; p++)
69 if (*p == '\n') count++;
71 config_keys = (char **)malloc(count * sizeof(char *));
72 config_values = (char **)malloc(count * sizeof(char *));
73 if (config_keys == NULL || config_values == NULL) {
79 for (p = start = config_buf; *p; p++) {
83 config_keys[count++] = start;
87 config_keys[count] = NULL;
88 for (count = 0; config_keys[count]; count++) {
89 config_values[count] = "";
90 for (p = config_keys[count]; *p; p++)
93 while (*p && isspace(*p)) p++;
94 config_values[count] = p;
101 /* Given a key, lookup the associated value.
102 * Returns "" on a key without a value, NULL on a non-existant key.
103 * If a key appears multiple times, successive calls will cycle through
104 * the possible values.
107 char *config_lookup(key)
113 if (init() != MR_SUCCESS)
117 if (config_keys[i] == NULL) i = 0;
120 if (!strcasecmp(key, config_keys[i]))
121 return(config_values[i]);
122 if (config_keys[++i] == NULL)
124 } while (i != start);
126 if (!strcasecmp(key, config_keys[i]))
127 return(config_values[i]);