GeezerVison is showing github.com — 添加su设置身份代码 · code699/SKRoot-linuxKernelRoot@07e078b
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: su/su.cpp +16Lines changed: 16 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -20,6 +20,18 @@ namespace { |
20 | 20 | return val; |
21 | 21 | } |
22 | 22 |
|
| 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 | + } |
23 | 35 | } |
24 | 36 |
|
25 | 37 | void usage(int status) { |
@@ -155,6 +167,10 @@ int su_client_main(int argc, char* argv[]) { |
155 | 167 | new_argv[1] = "-c"; |
156 | 168 | new_argv[2] = su_req.command.data(); |
157 | 169 | } |
| 170 | + |
| 171 | + // If you need it, you can unblock this line of code yourself |
| 172 | + //set_identity(su_req.uid); |
| 173 | + |
158 | 174 | execvp(su_req.shell.data(), (char**)new_argv); |
159 | 175 | } else { |
160 | 176 | wait(NULL); |
|