multiuser_utils: Add bool chngdir option to setup_environment.
This commit is contained in:
@@ -172,7 +172,7 @@ authenticate_user(const char* prompt, const char* user, passwd** _passwd,
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
setup_environment(struct passwd* passwd, bool preserveEnvironment)
|
setup_environment(struct passwd* passwd, bool preserveEnvironment, bool chngdir)
|
||||||
{
|
{
|
||||||
const char* term = getenv("TERM");
|
const char* term = getenv("TERM");
|
||||||
if (!preserveEnvironment) {
|
if (!preserveEnvironment) {
|
||||||
@@ -200,12 +200,14 @@ setup_environment(struct passwd* passwd, bool preserveEnvironment)
|
|||||||
if (passwd->pw_uid && setuid(passwd->pw_uid) != 0)
|
if (passwd->pw_uid && setuid(passwd->pw_uid) != 0)
|
||||||
return errno;
|
return errno;
|
||||||
|
|
||||||
const char* home = getenv("HOME");
|
if (chngdir) {
|
||||||
if (home == NULL)
|
const char* home = getenv("HOME");
|
||||||
return B_ENTRY_NOT_FOUND;
|
if (home == NULL)
|
||||||
|
return B_ENTRY_NOT_FOUND;
|
||||||
|
|
||||||
if (chdir(home) != 0)
|
if (chdir(home) != 0)
|
||||||
return errno;
|
return errno;
|
||||||
|
}
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,8 @@ status_t authenticate_user(const char* prompt, passwd* passwd, spwd* spwd,
|
|||||||
status_t authenticate_user(const char* prompt, const char* user,
|
status_t authenticate_user(const char* prompt, const char* user,
|
||||||
passwd** _passwd, spwd** _spwd, int maxTries, bool useStdio);
|
passwd** _passwd, spwd** _spwd, int maxTries, bool useStdio);
|
||||||
|
|
||||||
status_t setup_environment(struct passwd* passwd, bool preserveEnvironment);
|
status_t setup_environment(struct passwd* passwd, bool preserveEnvironment,
|
||||||
|
bool chngdir = true);
|
||||||
|
|
||||||
|
|
||||||
#endif // MULTIUSER_UTILS_H
|
#endif // MULTIUSER_UTILS_H
|
||||||
|
|||||||
Reference in New Issue
Block a user