mirror of
https://github.com/troglobit/finit.git
synced 2026-11-10 16:31:21 +00:00
Starting service as @user chdir() to their $HOME
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
0710fdd2a3
commit
57514130fc
3 files changed
+11
-4
No files matched your search
@@ -189,9 +189,10 @@ int print_result(int fail)
|
|||||||
return fail;
|
return fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
int getuser(char *username)
|
int getuser(char *username, char **home)
|
||||||
{
|
{
|
||||||
#ifdef ENABLE_STATIC
|
#ifdef ENABLE_STATIC
|
||||||
|
home = NULL; /* XXX: Fixme */
|
||||||
return fgetint("/etc/passwd", "x:\n", username);
|
return fgetint("/etc/passwd", "x:\n", username);
|
||||||
#else
|
#else
|
||||||
struct passwd *usr;
|
struct passwd *usr;
|
||||||
@@ -199,7 +200,8 @@ int getuser(char *username)
|
|||||||
if (!username || (usr = getpwnam(username)) == NULL)
|
if (!username || (usr = getpwnam(username)) == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return usr->pw_uid;
|
*home = usr->pw_dir;
|
||||||
|
return usr->pw_uid;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ void print_desc (char *action, char *desc);
|
|||||||
int print_result (int fail);
|
int print_result (int fail);
|
||||||
int start_process (char *cmd, char *args[], int console);
|
int start_process (char *cmd, char *args[], int console);
|
||||||
void do_sleep (unsigned int sec);
|
void do_sleep (unsigned int sec);
|
||||||
int getuser (char *username);
|
int getuser (char *username, char **home);
|
||||||
int getgroup (char *group);
|
int getgroup (char *group);
|
||||||
void set_hostname (char **hostname);
|
void set_hostname (char **hostname);
|
||||||
|
|
||||||
|
|||||||
@@ -151,10 +151,11 @@ static int service_start(svc_t *svc)
|
|||||||
pid = fork();
|
pid = fork();
|
||||||
if (pid == 0) {
|
if (pid == 0) {
|
||||||
int status;
|
int status;
|
||||||
|
char *home = NULL;
|
||||||
#ifdef ENABLE_STATIC
|
#ifdef ENABLE_STATIC
|
||||||
int uid = 0; /* XXX: Fix better warning that dropprivs is disabled. */
|
int uid = 0; /* XXX: Fix better warning that dropprivs is disabled. */
|
||||||
#else
|
#else
|
||||||
int uid = getuser(svc->username);
|
int uid = getuser(svc->username, &home);
|
||||||
#endif
|
#endif
|
||||||
char *args[MAX_NUM_SVC_ARGS];
|
char *args[MAX_NUM_SVC_ARGS];
|
||||||
|
|
||||||
@@ -165,6 +166,10 @@ static int service_start(svc_t *svc)
|
|||||||
/* Set default path for regular users */
|
/* Set default path for regular users */
|
||||||
if (uid > 0)
|
if (uid > 0)
|
||||||
setenv("PATH", _PATH_DEFPATH, 1);
|
setenv("PATH", _PATH_DEFPATH, 1);
|
||||||
|
if (home) {
|
||||||
|
setenv("HOME", home, 1);
|
||||||
|
chdir(home);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Serve copy of args to process in case it modifies them. */
|
/* Serve copy of args to process in case it modifies them. */
|
||||||
|
|||||||
Reference in new issue
Block a user