mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-23 09:51:57 -05:00
Userland: Minor tweaks in /bin/su
This commit is contained in:
parent
920e8e58ed
commit
b30773638e
1 changed files with 5 additions and 14 deletions
|
@ -8,12 +8,9 @@ extern "C" int main(int, char**);
|
|||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
uid_t uid;
|
||||
gid_t gid;
|
||||
if (argc == 1) {
|
||||
uid = 0;
|
||||
gid = 0;
|
||||
} else {
|
||||
uid_t uid = 0;
|
||||
gid_t gid = 0;
|
||||
if (argc > 1) {
|
||||
auto* pwd = getpwnam(argv[1]);
|
||||
if (!pwd) {
|
||||
fprintf(stderr, "No such user: %s\n", argv[1]);
|
||||
|
@ -22,23 +19,17 @@ int main(int argc, char** argv)
|
|||
uid = pwd->pw_uid;
|
||||
gid = pwd->pw_gid;
|
||||
}
|
||||
|
||||
int rc = setgid(uid);
|
||||
if (rc < 0) {
|
||||
perror("setgid");
|
||||
return 1;
|
||||
}
|
||||
|
||||
rc = setuid(gid);
|
||||
if (rc < 0) {
|
||||
perror("setuid");
|
||||
return 1;
|
||||
}
|
||||
|
||||
rc = execl("/bin/sh", "sh", nullptr);
|
||||
if (rc < 0) {
|
||||
perror("execl");
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
perror("execl");
|
||||
return 1;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue