Starting service as @user chdir() to their $HOME

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson
2016-07-28 23:48:39 +02:00
parent 0710fdd2a3
commit 57514130fc
3 changed files with 11 additions and 4 deletions
+4 -2
View File
@@ -189,9 +189,10 @@ int print_result(int fail)
return fail;
}
int getuser(char *username)
int getuser(char *username, char **home)
{
#ifdef ENABLE_STATIC
home = NULL; /* XXX: Fixme */
return fgetint("/etc/passwd", "x:\n", username);
#else
struct passwd *usr;
@@ -199,7 +200,8 @@ int getuser(char *username)
if (!username || (usr = getpwnam(username)) == NULL)
return -1;
return usr->pw_uid;
*home = usr->pw_dir;
return usr->pw_uid;
#endif
}
+1 -1
View File
@@ -76,7 +76,7 @@ void print_desc (char *action, char *desc);
int print_result (int fail);
int start_process (char *cmd, char *args[], int console);
void do_sleep (unsigned int sec);
int getuser (char *username);
int getuser (char *username, char **home);
int getgroup (char *group);
void set_hostname (char **hostname);
+6 -1
View File
@@ -151,10 +151,11 @@ static int service_start(svc_t *svc)
pid = fork();
if (pid == 0) {
int status;
char *home = NULL;
#ifdef ENABLE_STATIC
int uid = 0; /* XXX: Fix better warning that dropprivs is disabled. */
#else
int uid = getuser(svc->username);
int uid = getuser(svc->username, &home);
#endif
char *args[MAX_NUM_SVC_ARGS];
@@ -165,6 +166,10 @@ static int service_start(svc_t *svc)
/* Set default path for regular users */
if (uid > 0)
setenv("PATH", _PATH_DEFPATH, 1);
if (home) {
setenv("HOME", home, 1);
chdir(home);
}
}
/* Serve copy of args to process in case it modifies them. */