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 * Copyright (C) 1992-1998 by the Massachusetts Institute of Technology.
9 * For copying and distribution information, please see the file
13 #include <mit-copyright.h>
15 #include "update_server.h"
29 #define CONFIG_FILE "/etc/athena/moira.conf"
31 /* Variables currently supported:
32 * chroot directory daemon will run chrooted to this directory
33 * user username daemon will run with this user's uid
34 * port portname daemon will listen on this port number
35 * nofork server stays in foreground & logs to stdout
36 * auth krbname this user is authorized to connect
37 * noclobber will not overwrite existing files
38 * noexec will not execute instructions received
41 static char *config_buf = NULL;
42 static char **config_keys, **config_values;
50 /* Only execute once */
54 fd = open(CONFIG_FILE, O_RDONLY, 0);
58 config_keys = malloc(sizeof(char *) * 2);
61 config_keys[0] = config_keys[1] = NULL;
65 if (fstat(fd, &st) < 0)
68 config_buf = malloc(st.st_size + 2);
72 if (read(fd, config_buf, st.st_size) < st.st_size)
78 config_buf[st.st_size] = '\0';
80 for (p = config_buf; *p; p++)
86 config_keys = malloc(count * sizeof(char *));
87 config_values = malloc(count * sizeof(char *));
88 if (!config_keys || !config_values)
98 for (p = strtok(config_buf, "\n"); p; p = strtok(NULL, "\n"))
99 config_keys[count++] = p;
100 config_keys[count] = NULL;
102 for (count = 0; config_keys[count]; count++)
104 config_values[count] = "";
105 for (p = config_keys[count]; *p; p++)
110 while (*p && isspace(*p))
112 config_values[count] = p;
120 /* Given a key, lookup the associated value.
121 * Returns "" on a key without a value, NULL on a non-existant key.
122 * If a key appears multiple times, successive calls will cycle through
123 * the possible values.
126 char *config_lookup(char *key)
131 if (init() != MR_SUCCESS)
142 if (!strcasecmp(key, config_keys[i]))
143 return config_values[i];
144 if (!config_keys[++i])
149 if (!strcasecmp(key, config_keys[i]))
150 return config_values[i];