2004-02-24 00:41:20 +01:00
|
|
|
/* the Music Player Daemon (MPD)
|
2007-04-05 05:22:33 +02:00
|
|
|
* Copyright (C) 2003-2007 by Warren Dukes (warren.dukes@gmail.com)
|
2004-02-24 00:41:20 +01:00
|
|
|
* This project's homepage is: http://www.musicpd.org
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "conf.h"
|
|
|
|
|
|
|
|
#include "log.h"
|
|
|
|
|
|
|
|
#include "utils.h"
|
|
|
|
#include "buffer2array.h"
|
2004-10-28 07:14:55 +02:00
|
|
|
#include "list.h"
|
2004-02-24 00:41:20 +01:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2004-02-24 22:20:16 +01:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <pwd.h>
|
2004-11-02 06:29:22 +01:00
|
|
|
#include <errno.h>
|
2004-02-24 00:41:20 +01:00
|
|
|
|
|
|
|
#define MAX_STRING_SIZE MAXPATHLEN+80
|
|
|
|
|
2004-10-28 07:14:55 +02:00
|
|
|
#define CONF_COMMENT '#'
|
|
|
|
#define CONF_BLOCK_BEGIN "{"
|
|
|
|
#define CONF_BLOCK_END "}"
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2004-10-28 07:14:55 +02:00
|
|
|
#define CONF_REPEATABLE_MASK 0x01
|
|
|
|
#define CONF_BLOCK_MASK 0x02
|
2006-10-06 12:33:27 +02:00
|
|
|
#define CONF_LINE_TOKEN_MAX 3
|
2004-10-28 07:14:55 +02:00
|
|
|
|
|
|
|
typedef struct _configEntry {
|
|
|
|
unsigned char mask;
|
2006-07-20 18:02:40 +02:00
|
|
|
List *configParamList;
|
2004-10-28 07:14:55 +02:00
|
|
|
} ConfigEntry;
|
|
|
|
|
2007-01-14 04:07:53 +01:00
|
|
|
static List *configEntriesList;
|
2004-10-28 07:14:55 +02:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
static ConfigParam *newConfigParam(char *value, int line)
|
|
|
|
{
|
2006-08-26 08:25:57 +02:00
|
|
|
ConfigParam *ret = xmalloc(sizeof(ConfigParam));
|
2004-10-28 07:14:55 +02:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (!value)
|
|
|
|
ret->value = NULL;
|
|
|
|
else
|
2006-08-26 08:25:57 +02:00
|
|
|
ret->value = xstrdup(value);
|
2004-10-28 07:14:55 +02:00
|
|
|
|
|
|
|
ret->line = line;
|
|
|
|
|
|
|
|
ret->numberOfBlockParams = 0;
|
|
|
|
ret->blockParams = NULL;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
static void freeConfigParam(ConfigParam * param)
|
|
|
|
{
|
2004-02-24 00:41:20 +01:00
|
|
|
int i;
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (param->value)
|
|
|
|
free(param->value);
|
2004-10-28 07:14:55 +02:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
for (i = 0; i < param->numberOfBlockParams; i++) {
|
|
|
|
if (param->blockParams[i].name) {
|
2004-10-28 07:14:55 +02:00
|
|
|
free(param->blockParams[i].name);
|
|
|
|
}
|
2006-07-20 18:02:40 +02:00
|
|
|
if (param->blockParams[i].value) {
|
2004-10-28 07:14:55 +02:00
|
|
|
free(param->blockParams[i].value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (param->numberOfBlockParams)
|
|
|
|
free(param->blockParams);
|
2004-10-28 07:14:55 +02:00
|
|
|
|
|
|
|
free(param);
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
|
|
|
|
2006-08-20 02:50:44 +02:00
|
|
|
static ConfigEntry *newConfigEntry(int repeatable, int block)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2006-08-26 08:25:57 +02:00
|
|
|
ConfigEntry *ret = xmalloc(sizeof(ConfigEntry));
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2004-10-28 07:14:55 +02:00
|
|
|
ret->mask = 0;
|
2006-07-20 18:02:40 +02:00
|
|
|
ret->configParamList =
|
|
|
|
makeList((ListFreeDataFunc *) freeConfigParam, 1);
|
2004-10-28 07:14:55 +02:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (repeatable)
|
|
|
|
ret->mask |= CONF_REPEATABLE_MASK;
|
|
|
|
if (block)
|
|
|
|
ret->mask |= CONF_BLOCK_MASK;
|
2004-10-28 07:14:55 +02:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2006-08-20 02:50:44 +02:00
|
|
|
static void freeConfigEntry(ConfigEntry * entry)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2004-10-28 07:14:55 +02:00
|
|
|
freeList(entry->configParamList);
|
|
|
|
free(entry);
|
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
static void registerConfigParam(char *name, int repeatable, int block)
|
|
|
|
{
|
|
|
|
ConfigEntry *entry;
|
2004-10-28 07:14:55 +02:00
|
|
|
|
2007-05-26 20:15:54 +02:00
|
|
|
if (findInList(configEntriesList, name, NULL))
|
|
|
|
FATAL("config parameter \"%s\" already registered\n", name);
|
2004-10-28 07:14:55 +02:00
|
|
|
|
|
|
|
entry = newConfigEntry(repeatable, block);
|
|
|
|
|
|
|
|
insertInList(configEntriesList, name, entry);
|
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
void finishConf(void)
|
|
|
|
{
|
2005-11-18 13:09:05 +01:00
|
|
|
freeList(configEntriesList);
|
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
void initConf(void)
|
|
|
|
{
|
|
|
|
configEntriesList = makeList((ListFreeDataFunc *) freeConfigEntry, 1);
|
2004-10-28 07:14:55 +02:00
|
|
|
|
2006-07-27 21:10:08 +02:00
|
|
|
/* registerConfigParam(name, repeatable, block); */
|
|
|
|
registerConfigParam(CONF_MUSIC_DIR, 0, 0);
|
|
|
|
registerConfigParam(CONF_PLAYLIST_DIR, 0, 0);
|
2006-08-28 22:47:50 +02:00
|
|
|
registerConfigParam(CONF_DB_FILE, 0, 0);
|
2006-07-27 21:10:08 +02:00
|
|
|
registerConfigParam(CONF_LOG_FILE, 0, 0);
|
|
|
|
registerConfigParam(CONF_ERROR_FILE, 0, 0);
|
2006-08-28 22:47:50 +02:00
|
|
|
registerConfigParam(CONF_PID_FILE, 0, 0);
|
2006-07-27 21:10:08 +02:00
|
|
|
registerConfigParam(CONF_STATE_FILE, 0, 0);
|
|
|
|
registerConfigParam(CONF_USER, 0, 0);
|
2006-08-28 22:47:50 +02:00
|
|
|
registerConfigParam(CONF_BIND_TO_ADDRESS, 1, 0);
|
|
|
|
registerConfigParam(CONF_PORT, 0, 0);
|
2006-07-27 21:10:08 +02:00
|
|
|
registerConfigParam(CONF_LOG_LEVEL, 0, 0);
|
2007-01-11 21:41:17 +01:00
|
|
|
registerConfigParam(CONF_ZEROCONF_NAME, 0, 0);
|
2007-06-03 20:08:51 +02:00
|
|
|
registerConfigParam(CONF_ZEROCONF_ENABLED, 0, 0);
|
2006-07-27 21:10:08 +02:00
|
|
|
registerConfigParam(CONF_PASSWORD, 1, 0);
|
|
|
|
registerConfigParam(CONF_DEFAULT_PERMS, 0, 0);
|
2006-08-28 22:47:50 +02:00
|
|
|
registerConfigParam(CONF_AUDIO_OUTPUT, 1, 1);
|
2006-07-27 21:10:08 +02:00
|
|
|
registerConfigParam(CONF_AUDIO_OUTPUT_FORMAT, 0, 0);
|
2006-08-28 22:47:50 +02:00
|
|
|
registerConfigParam(CONF_MIXER_TYPE, 0, 0);
|
|
|
|
registerConfigParam(CONF_MIXER_DEVICE, 0, 0);
|
|
|
|
registerConfigParam(CONF_MIXER_CONTROL, 0, 0);
|
|
|
|
registerConfigParam(CONF_REPLAYGAIN, 0, 0);
|
|
|
|
registerConfigParam(CONF_REPLAYGAIN_PREAMP, 0, 0);
|
|
|
|
registerConfigParam(CONF_VOLUME_NORMALIZATION, 0, 0);
|
2007-02-02 04:51:07 +01:00
|
|
|
registerConfigParam(CONF_SAMPLERATE_CONVERTER, 0, 0);
|
2006-08-28 22:47:50 +02:00
|
|
|
registerConfigParam(CONF_AUDIO_BUFFER_SIZE, 0, 0);
|
|
|
|
registerConfigParam(CONF_BUFFER_BEFORE_PLAY, 0, 0);
|
|
|
|
registerConfigParam(CONF_HTTP_BUFFER_SIZE, 0, 0);
|
|
|
|
registerConfigParam(CONF_HTTP_PREBUFFER_SIZE, 0, 0);
|
2006-07-27 21:10:08 +02:00
|
|
|
registerConfigParam(CONF_HTTP_PROXY_HOST, 0, 0);
|
|
|
|
registerConfigParam(CONF_HTTP_PROXY_PORT, 0, 0);
|
|
|
|
registerConfigParam(CONF_HTTP_PROXY_USER, 0, 0);
|
|
|
|
registerConfigParam(CONF_HTTP_PROXY_PASSWORD, 0, 0);
|
2006-08-28 22:47:50 +02:00
|
|
|
registerConfigParam(CONF_CONN_TIMEOUT, 0, 0);
|
|
|
|
registerConfigParam(CONF_MAX_CONN, 0, 0);
|
|
|
|
registerConfigParam(CONF_MAX_PLAYLIST_LENGTH, 0, 0);
|
|
|
|
registerConfigParam(CONF_MAX_COMMAND_LIST_SIZE, 0, 0);
|
|
|
|
registerConfigParam(CONF_MAX_OUTPUT_BUFFER_SIZE, 0, 0);
|
|
|
|
registerConfigParam(CONF_FS_CHARSET, 0, 0);
|
2006-07-27 21:10:08 +02:00
|
|
|
registerConfigParam(CONF_ID3V1_ENCODING, 0, 0);
|
2006-08-28 22:47:50 +02:00
|
|
|
registerConfigParam(CONF_METADATA_TO_USE, 0, 0);
|
|
|
|
registerConfigParam(CONF_SAVE_ABSOLUTE_PATHS, 0, 0);
|
2006-12-23 19:00:15 +01:00
|
|
|
registerConfigParam(CONF_GAPLESS_MP3_PLAYBACK, 0, 0);
|
2004-10-28 07:14:55 +02:00
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
static void addBlockParam(ConfigParam * param, char *name, char *value,
|
|
|
|
int line)
|
2004-10-28 07:14:55 +02:00
|
|
|
{
|
|
|
|
param->numberOfBlockParams++;
|
|
|
|
|
2006-08-26 08:25:57 +02:00
|
|
|
param->blockParams = xrealloc(param->blockParams,
|
2006-07-20 18:02:40 +02:00
|
|
|
param->numberOfBlockParams *
|
|
|
|
sizeof(BlockParam));
|
|
|
|
|
2006-08-26 08:25:57 +02:00
|
|
|
param->blockParams[param->numberOfBlockParams - 1].name = xstrdup(name);
|
2006-07-20 18:02:40 +02:00
|
|
|
param->blockParams[param->numberOfBlockParams - 1].value =
|
2006-08-26 08:25:57 +02:00
|
|
|
xstrdup(value);
|
2006-07-20 18:02:40 +02:00
|
|
|
param->blockParams[param->numberOfBlockParams - 1].line = line;
|
2004-10-28 07:14:55 +02:00
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
static ConfigParam *readConfigBlock(FILE * fp, int *count, char *string)
|
|
|
|
{
|
|
|
|
ConfigParam *ret = newConfigParam(NULL, *count);
|
2004-10-28 07:14:55 +02:00
|
|
|
|
|
|
|
int i;
|
|
|
|
int numberOfArgs;
|
|
|
|
int argsMinusComment;
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
while (myFgets(string, MAX_STRING_SIZE, fp)) {
|
2006-10-06 12:33:27 +02:00
|
|
|
char *array[CONF_LINE_TOKEN_MAX] = { NULL };
|
|
|
|
|
2004-10-28 07:14:55 +02:00
|
|
|
(*count)++;
|
|
|
|
|
2006-10-06 12:33:27 +02:00
|
|
|
numberOfArgs = buffer2array(string, array, CONF_LINE_TOKEN_MAX);
|
2004-10-28 07:14:55 +02:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
for (i = 0; i < numberOfArgs; i++) {
|
|
|
|
if (array[i][0] == CONF_COMMENT)
|
|
|
|
break;
|
2004-10-28 07:14:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
argsMinusComment = i;
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (0 == argsMinusComment) {
|
2004-11-11 04:20:49 +01:00
|
|
|
continue;
|
|
|
|
}
|
2004-10-28 07:14:55 +02:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (1 == argsMinusComment &&
|
|
|
|
0 == strcmp(array[0], CONF_BLOCK_END)) {
|
2004-10-28 07:14:55 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (2 != argsMinusComment) {
|
2007-05-26 20:15:54 +02:00
|
|
|
FATAL("improperly formatted config file at line %i:"
|
2006-07-20 18:02:40 +02:00
|
|
|
" %s\n", *count, string);
|
2004-10-28 07:14:55 +02:00
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (0 == strcmp(array[0], CONF_BLOCK_BEGIN) ||
|
|
|
|
0 == strcmp(array[1], CONF_BLOCK_BEGIN) ||
|
|
|
|
0 == strcmp(array[0], CONF_BLOCK_END) ||
|
|
|
|
0 == strcmp(array[1], CONF_BLOCK_END)) {
|
2007-05-26 20:15:54 +02:00
|
|
|
FATAL("improperly formatted config file at line %i: %s\n"
|
|
|
|
"in block beginning at line %i\n",
|
|
|
|
*count, string, ret->line);;
|
2004-10-28 07:14:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
addBlockParam(ret, array[0], array[1], *count);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
void readConf(char *file)
|
|
|
|
{
|
|
|
|
FILE *fp;
|
|
|
|
char string[MAX_STRING_SIZE + 1];
|
2004-02-24 00:41:20 +01:00
|
|
|
int i;
|
|
|
|
int numberOfArgs;
|
2004-10-28 07:14:55 +02:00
|
|
|
int argsMinusComment;
|
2004-08-10 18:03:03 +02:00
|
|
|
int count = 0;
|
2006-07-20 18:02:40 +02:00
|
|
|
ConfigEntry *entry;
|
|
|
|
void *voidPtr;
|
|
|
|
ConfigParam *param;
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (!(fp = fopen(file, "r"))) {
|
2007-05-26 20:15:54 +02:00
|
|
|
FATAL("problems opening file %s for reading: %s\n", file,
|
2006-07-20 18:02:40 +02:00
|
|
|
strerror(errno));
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
while (myFgets(string, MAX_STRING_SIZE, fp)) {
|
2006-10-06 12:33:27 +02:00
|
|
|
char *array[CONF_LINE_TOKEN_MAX] = { NULL };
|
2004-08-10 18:03:03 +02:00
|
|
|
count++;
|
|
|
|
|
2006-10-06 12:33:27 +02:00
|
|
|
numberOfArgs = buffer2array(string, array, CONF_LINE_TOKEN_MAX);
|
2004-10-28 07:14:55 +02:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
for (i = 0; i < numberOfArgs; i++) {
|
|
|
|
if (array[i][0] == CONF_COMMENT)
|
|
|
|
break;
|
2004-10-28 07:14:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
argsMinusComment = i;
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (0 == argsMinusComment) {
|
2004-11-11 04:20:49 +01:00
|
|
|
continue;
|
|
|
|
}
|
2004-10-28 07:14:55 +02:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (2 != argsMinusComment) {
|
2007-05-26 20:15:54 +02:00
|
|
|
FATAL("improperly formatted config file at line %i:"
|
2006-07-20 18:02:40 +02:00
|
|
|
" %s\n", count, string);
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
2004-10-28 07:14:55 +02:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (!findInList(configEntriesList, array[0], &voidPtr)) {
|
2007-05-26 20:15:54 +02:00
|
|
|
FATAL("unrecognized parameter in config file at line "
|
2006-07-20 18:02:40 +02:00
|
|
|
"%i: %s\n", count, string);
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
2004-10-28 07:14:55 +02:00
|
|
|
|
|
|
|
entry = (ConfigEntry *) voidPtr;
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (!(entry->mask & CONF_REPEATABLE_MASK) &&
|
|
|
|
entry->configParamList->numberOfNodes) {
|
2004-10-28 07:14:55 +02:00
|
|
|
param = entry->configParamList->firstNode->data;
|
2007-05-26 20:15:54 +02:00
|
|
|
FATAL("config parameter \"%s\" is first defined on line "
|
2006-07-20 18:02:40 +02:00
|
|
|
"%i and redefined on line %i\n", array[0],
|
|
|
|
param->line, count);
|
2004-10-28 07:14:55 +02:00
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (entry->mask & CONF_BLOCK_MASK) {
|
|
|
|
if (0 != strcmp(array[1], CONF_BLOCK_BEGIN)) {
|
2007-05-26 20:15:54 +02:00
|
|
|
FATAL("improperly formatted config file at "
|
2006-07-20 18:02:40 +02:00
|
|
|
"line %i: %s\n", count, string);
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
2004-10-28 07:14:55 +02:00
|
|
|
param = readConfigBlock(fp, &count, string);
|
2006-07-20 18:02:40 +02:00
|
|
|
} else
|
|
|
|
param = newConfigParam(array[1], count);
|
2004-10-28 07:14:55 +02:00
|
|
|
|
|
|
|
insertInListWithoutKey(entry->configParamList, param);
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
2005-11-18 13:09:05 +01:00
|
|
|
fclose(fp);
|
2004-10-28 07:14:55 +02:00
|
|
|
}
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
ConfigParam *getNextConfigParam(char *name, ConfigParam * last)
|
|
|
|
{
|
|
|
|
void *voidPtr;
|
|
|
|
ConfigEntry *entry;
|
|
|
|
ListNode *node;
|
|
|
|
ConfigParam *param;
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (!findInList(configEntriesList, name, &voidPtr))
|
|
|
|
return NULL;
|
2004-10-28 07:14:55 +02:00
|
|
|
|
|
|
|
entry = voidPtr;
|
|
|
|
|
|
|
|
node = entry->configParamList->firstNode;
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (last) {
|
|
|
|
while (node != NULL) {
|
2004-10-28 07:14:55 +02:00
|
|
|
param = node->data;
|
|
|
|
node = node->nextNode;
|
2006-07-20 18:02:40 +02:00
|
|
|
if (param == last)
|
|
|
|
break;
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (node == NULL)
|
|
|
|
return NULL;
|
2004-10-28 07:14:55 +02:00
|
|
|
|
|
|
|
param = node->data;
|
|
|
|
|
|
|
|
return param;
|
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
char *getConfigParamValue(char *name)
|
|
|
|
{
|
|
|
|
ConfigParam *param = getConfigParam(name);
|
2004-10-28 07:14:55 +02:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (!param)
|
|
|
|
return NULL;
|
2004-10-28 07:14:55 +02:00
|
|
|
|
|
|
|
return param->value;
|
|
|
|
}
|
|
|
|
|
2006-07-21 19:06:20 +02:00
|
|
|
int getBoolConfigParam(char *name)
|
|
|
|
{
|
|
|
|
ConfigParam *param;
|
|
|
|
|
|
|
|
param = getConfigParam(name);
|
|
|
|
if (!param) return -1;
|
|
|
|
|
|
|
|
if (strcmp("yes", param->value) == 0) return 1;
|
|
|
|
else if (strcmp("no", param->value) == 0) return 0;
|
|
|
|
|
2006-07-27 02:50:59 +02:00
|
|
|
ERROR("%s is not \"yes\" or \"no\" on line %i\n", name, param->line);
|
|
|
|
|
2006-07-21 19:20:38 +02:00
|
|
|
return -2;
|
2006-07-21 19:06:20 +02:00
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
BlockParam *getBlockParam(ConfigParam * param, char *name)
|
|
|
|
{
|
|
|
|
BlockParam *ret = NULL;
|
2004-10-28 07:14:55 +02:00
|
|
|
int i;
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
for (i = 0; i < param->numberOfBlockParams; i++) {
|
|
|
|
if (0 == strcmp(name, param->blockParams[i].name)) {
|
|
|
|
if (ret) {
|
2004-10-28 07:14:55 +02:00
|
|
|
ERROR("\"%s\" first defined on line %i, and "
|
2006-07-20 18:02:40 +02:00
|
|
|
"redefined on line %i\n", name,
|
|
|
|
ret->line, param->blockParams[i].line);
|
2004-10-28 07:14:55 +02:00
|
|
|
}
|
2006-07-20 18:02:40 +02:00
|
|
|
ret = param->blockParams + i;
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
2004-10-28 07:14:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
ConfigParam *parseConfigFilePath(char *name, int force)
|
|
|
|
{
|
|
|
|
ConfigParam *param = getConfigParam(name);
|
|
|
|
char *path;
|
2004-10-28 07:14:55 +02:00
|
|
|
|
2007-05-26 20:15:54 +02:00
|
|
|
if (!param && force)
|
|
|
|
FATAL("config parameter \"%s\" not found\n", name);
|
2004-10-28 07:14:55 +02:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (!param)
|
|
|
|
return NULL;
|
2004-10-28 07:14:55 +02:00
|
|
|
|
|
|
|
path = param->value;
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (path[0] != '/' && path[0] != '~') {
|
2007-05-26 20:15:54 +02:00
|
|
|
FATAL("\"%s\" is not an absolute path at line %i\n",
|
2006-07-20 18:02:40 +02:00
|
|
|
param->value, param->line);
|
2004-10-28 07:14:55 +02:00
|
|
|
}
|
2005-11-19 11:52:47 +01:00
|
|
|
/* Parse ~ in path */
|
2006-07-20 18:02:40 +02:00
|
|
|
else if (path[0] == '~') {
|
|
|
|
struct passwd *pwd = NULL;
|
|
|
|
char *newPath;
|
2004-10-28 07:14:55 +02:00
|
|
|
int pos = 1;
|
2006-07-20 18:02:40 +02:00
|
|
|
if (path[1] == '/' || path[1] == '\0') {
|
|
|
|
ConfigParam *userParam = getConfigParam(CONF_USER);
|
2004-10-28 07:14:55 +02:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (userParam) {
|
2004-10-28 07:14:55 +02:00
|
|
|
pwd = getpwnam(userParam->value);
|
2006-07-20 18:02:40 +02:00
|
|
|
if (!pwd) {
|
2007-05-26 20:15:54 +02:00
|
|
|
FATAL("no such user %s at line %i\n",
|
2006-07-20 18:02:40 +02:00
|
|
|
userParam->value,
|
|
|
|
userParam->line);
|
2004-02-24 22:20:16 +01:00
|
|
|
}
|
2006-07-20 18:02:40 +02:00
|
|
|
} else {
|
2004-10-28 07:14:55 +02:00
|
|
|
uid_t uid = geteuid();
|
2006-07-20 18:02:40 +02:00
|
|
|
if ((pwd = getpwuid(uid)) == NULL) {
|
2007-05-26 20:15:54 +02:00
|
|
|
FATAL("problems getting passwd entry "
|
2006-07-20 18:02:40 +02:00
|
|
|
"for current user\n");
|
2004-02-24 22:20:16 +01:00
|
|
|
}
|
|
|
|
}
|
2006-07-20 18:02:40 +02:00
|
|
|
} else {
|
2004-10-28 07:14:55 +02:00
|
|
|
int foundSlash = 0;
|
2006-07-20 18:02:40 +02:00
|
|
|
char *ch = path + 1;
|
|
|
|
for (; *ch != '\0' && *ch != '/'; ch++) ;
|
|
|
|
if (*ch == '/')
|
|
|
|
foundSlash = 1;
|
|
|
|
*ch = '\0';
|
|
|
|
pos += ch - path - 1;
|
|
|
|
if ((pwd = getpwnam(path + 1)) == NULL) {
|
2007-05-26 20:15:54 +02:00
|
|
|
FATAL("user \"%s\" not found at line %i\n",
|
2006-07-20 18:02:40 +02:00
|
|
|
path + 1, param->line);
|
2004-10-28 07:14:55 +02:00
|
|
|
}
|
2006-07-20 18:02:40 +02:00
|
|
|
if (foundSlash)
|
|
|
|
*ch = '/';
|
2004-10-28 07:14:55 +02:00
|
|
|
}
|
2006-08-26 08:25:57 +02:00
|
|
|
newPath = xmalloc(strlen(pwd->pw_dir) + strlen(path + pos) + 1);
|
2004-10-28 07:14:55 +02:00
|
|
|
strcpy(newPath, pwd->pw_dir);
|
2006-07-20 18:02:40 +02:00
|
|
|
strcat(newPath, path + pos);
|
2004-10-28 07:14:55 +02:00
|
|
|
free(param->value);
|
|
|
|
param->value = newPath;
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
|
|
|
|
2005-03-06 20:00:58 +01:00
|
|
|
return param;
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|