mirror of
https://github.com/owntone/owntone-server.git
synced 2025-01-25 21:53:17 -05:00
Resolve runas username when loading configuration and export uid/gid
This commit is contained in:
parent
6feac7dd45
commit
a40f3f0629
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2009-2010 Julien BLACHE <jb@jblache.org>
|
* Copyright (C) 2009-2011 Julien BLACHE <jb@jblache.org>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -25,7 +25,9 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
#include <sys/utsname.h>
|
#include <sys/utsname.h>
|
||||||
|
#include <pwd.h>
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
@ -96,6 +98,8 @@ static cfg_opt_t toplvl_cfg[] =
|
|||||||
|
|
||||||
cfg_t *cfg;
|
cfg_t *cfg;
|
||||||
uint64_t libhash;
|
uint64_t libhash;
|
||||||
|
uid_t runas_uid;
|
||||||
|
gid_t runas_gid;
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -241,6 +245,8 @@ int
|
|||||||
conffile_load(char *file)
|
conffile_load(char *file)
|
||||||
{
|
{
|
||||||
cfg_t *lib;
|
cfg_t *lib;
|
||||||
|
struct passwd *pw;
|
||||||
|
char *runas;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
cfg = cfg_init(toplvl_cfg, CFGF_NONE);
|
cfg = cfg_init(toplvl_cfg, CFGF_NONE);
|
||||||
@ -260,6 +266,19 @@ conffile_load(char *file)
|
|||||||
goto out_fail;
|
goto out_fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Resolve runas username */
|
||||||
|
runas = cfg_getstr(cfg_getsec(cfg, "general"), "uid");
|
||||||
|
pw = getpwnam(runas);
|
||||||
|
if (!pw)
|
||||||
|
{
|
||||||
|
DPRINTF(E_FATAL, L_CONF, "Could not lookup user %s: %s\n", runas, strerror(errno));
|
||||||
|
|
||||||
|
goto out_fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
runas_uid = pw->pw_uid;
|
||||||
|
runas_gid = pw->pw_gid;
|
||||||
|
|
||||||
lib = cfg_getsec(cfg, "library");
|
lib = cfg_getsec(cfg, "library");
|
||||||
|
|
||||||
if (cfg_size(lib, "directories") == 0)
|
if (cfg_size(lib, "directories") == 0)
|
||||||
|
@ -2,12 +2,16 @@
|
|||||||
#ifndef __CONFFILE_H__
|
#ifndef __CONFFILE_H__
|
||||||
#define __CONFFILE_H__
|
#define __CONFFILE_H__
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <confuse.h>
|
#include <confuse.h>
|
||||||
|
|
||||||
#define CONFFILE CONFDIR "/forked-daapd.conf"
|
#define CONFFILE CONFDIR "/forked-daapd.conf"
|
||||||
|
|
||||||
extern cfg_t *cfg;
|
extern cfg_t *cfg;
|
||||||
extern uint64_t libhash;
|
extern uint64_t libhash;
|
||||||
|
extern uid_t runas_uid;
|
||||||
|
extern gid_t runas_gid;
|
||||||
|
|
||||||
int
|
int
|
||||||
conffile_load(char *file);
|
conffile_load(char *file);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user