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"
28 #define CONFIG_FILE "/etc/athena/moira.conf"
30 /* Variables currently supported:
31 * chroot directory daemon will run chrooted to this directory
32 * user username daemon will run with this user's uid
33 * port portname daemon will listen on this port number
34 * nofork server stays in foreground & logs to stdout
35 * auth krbname this user is authorized to connect
36 * noclobber will not overwrite existing files
37 * noexec will not execute instructions received
40 static char *config_buf = NULL;
41 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);
59 config_keys[0] = config_keys[1] = NULL;
62 if (fstat(fd, &st) < 0)
64 config_buf = malloc(st.st_size + 2);
67 if (read(fd, config_buf, st.st_size) < st.st_size)
73 config_buf[st.st_size] = '\0';
75 for (p = config_buf; *p; p++)
81 config_keys = malloc(count * sizeof(char *));
82 config_values = malloc(count * sizeof(char *));
83 if (!config_keys || !config_values)
90 for (p = strtok(config_buf, "\n"); p; p = strtok(NULL, "\n"))
91 config_keys[count++] = p;
92 config_keys[count] = NULL;
93 for (count = 0; config_keys[count]; count++)
95 config_values[count] = "";
96 for (p = config_keys[count]; *p; p++)
101 while (*p && isspace(*p))
103 config_values[count] = p;
111 /* Given a key, lookup the associated value.
112 * Returns "" on a key without a value, NULL on a non-existant key.
113 * If a key appears multiple times, successive calls will cycle through
114 * the possible values.
117 char *config_lookup(char *key)
122 if (init() != MR_SUCCESS)
133 if (!strcasecmp(key, config_keys[i]))
134 return config_values[i];
135 if (!config_keys[++i])
140 if (!strcasecmp(key, config_keys[i]))
141 return config_values[i];