Skip to content

Commit 07e078b

Browse files
unkn0wNameunkn0wName
authored andcommitted
添加su设置身份代码
1 parent 7ab9f55 commit 07e078b

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

‎su/su.cpp‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,18 @@ namespace {
2020
return val;
2121
}
2222

23+
// Set effective uid back to root, otherwise setres[ug]id will fail if uid isn't root
24+
void set_identity(unsigned uid) {
25+
if (seteuid(0)) {
26+
TRACE("seteuid (root)");
27+
}
28+
if (setresgid(uid, uid, uid)) {
29+
TRACE("setresgid (%u)", uid);
30+
}
31+
if (setresuid(uid, uid, uid)) {
32+
TRACE("setresuid (%u)", uid);
33+
}
34+
}
2335
}
2436

2537
void usage(int status) {
@@ -155,6 +167,10 @@ int su_client_main(int argc, char* argv[]) {
155167
new_argv[1] = "-c";
156168
new_argv[2] = su_req.command.data();
157169
}
170+
171+
// If you need it, you can unblock this line of code yourself
172+
//set_identity(su_req.uid);
173+
158174
execvp(su_req.shell.data(), (char**)new_argv);
159175
} else {
160176
wait(NULL);

0 commit comments

Comments
 (0)