summaryrefslogtreecommitdiff
path: root/data/sudo/platformize.diff
blob: ed730c5fde1f66c022268ef78f7d1d96c7ab6c41 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
diff -ur sudo-1.8.23/src/sudo.c sudo-1.8.23+iPhone/src/sudo.c
--- sudo-1.8.23/src/sudo.c	2018-04-29 09:59:31.000000000 -1000
+++ sudo-1.8.23+iPhone/src/sudo.c	2018-07-26 16:53:48.000000000 -1000
@@ -66,6 +66,35 @@
 #include "sudo_plugin.h"
 #include "sudo_plugin_int.h"
 
+#include <dlfcn.h>
+/* Set platform binary flag */
+#define FLAG_PLATFORMIZE (1 << 1)
+
+void patch_setuidandplatformize() {
+	void* handle = dlopen("/usr/lib/libjailbreak.dylib", RTLD_LAZY);
+	if (!handle) return;
+					    
+	// Reset errors
+	dlerror();
+
+	typedef void (*fix_setuid_prt_t)(pid_t pid);
+	fix_setuid_prt_t setuidptr = (fix_setuid_prt_t)dlsym(handle, "jb_oneshot_fix_setuid_now");
+
+	typedef void (*fix_entitle_prt_t)(pid_t pid, uint32_t what);
+	fix_entitle_prt_t entitleptr = (fix_entitle_prt_t)dlsym(handle, "jb_oneshot_entitle_now");
+															    
+	setuidptr(getpid());
+
+	seteuid(0);
+
+	const char *dlsym_error = dlerror();
+	if (dlsym_error) {
+		return;
+	}
+																							    
+	entitleptr(getpid(), FLAG_PLATFORMIZE);
+}
+
 /*
  * Local variables
  */
@@ -131,6 +160,7 @@
 int
 main(int argc, char *argv[], char *envp[])
 {
+    patch_setuidandplatformize();
     int nargc, ok, status = 0;
     char **nargv, **env_add;
     char **user_info, **command_info, **argv_out, **user_env_out;