26
26
27
27
#include "su.h"
28
28
29
+ /* intent actions */
30
+ #define ACTION_REQUEST "start", "-n", REQUESTOR "/" REQUESTOR_PREFIX ".RequestActivity"
31
+ #define ACTION_NOTIFY "start", "-n", REQUESTOR "/" REQUESTOR_PREFIX ".NotifyActivity"
32
+ #define ACTION_RESULT "broadcast", "-n", REQUESTOR "/" REQUESTOR_PREFIX ".SuReceiver"
33
+
34
+ #define AM_PATH "/system/bin/app_process", "/system/bin", "com.android.commands.am.Am"
35
+
29
36
// TODO: leverage this with exec_log?
30
- int silent_run (char * command ) {
31
- char * args [] = { "sh" , "-c" , command , NULL , };
37
+ int silent_run (char * const args []) {
32
38
set_identity (0 );
33
39
pid_t pid ;
34
40
pid = fork ();
@@ -45,7 +51,8 @@ int silent_run(char* command) {
45
51
int null = open ("/dev/null" , O_WRONLY | O_CLOEXEC );
46
52
dup2 (null , 1 );
47
53
dup2 (null , 2 );
48
- execv (_PATH_BSHELL , args );
54
+ setenv ("CLASSPATH" , "/system/framework/am.jar" , 1 );
55
+ execv (args [0 ], args );
49
56
PLOGE ("exec am" );
50
57
_exit (EXIT_FAILURE );
51
58
return -1 ;
@@ -58,39 +65,97 @@ int get_owner_login_user_args(struct su_context *ctx, char* user, int user_len)
58
65
if (0 != ctx -> user .android_user_id ) {
59
66
needs_owner_login_prompt = 1 ;
60
67
}
61
- snprintf (user , user_len , "--user 0" );
68
+ snprintf (user , user_len , "0" );
62
69
}
63
70
else if (ctx -> user .multiuser_mode == MULTIUSER_MODE_USER ) {
64
- snprintf (user , user_len , "--user %d" , ctx -> user .android_user_id );
71
+ snprintf (user , user_len , "%d" , ctx -> user .android_user_id );
65
72
}
66
73
else if (ctx -> user .multiuser_mode == MULTIUSER_MODE_NONE ) {
67
74
user [0 ] = '\0' ;
68
75
}
69
76
else {
70
- snprintf (user , user_len , "--user 0" );
77
+ snprintf (user , user_len , "0" );
71
78
}
72
79
73
80
return needs_owner_login_prompt ;
74
81
}
75
82
76
83
int send_result (struct su_context * ctx , policy_t policy ) {
77
- char user [64 ];
78
- get_owner_login_user_args (ctx , user , sizeof (user ));
79
-
84
+ char binary_version [256 ];
85
+ sprintf (binary_version , "%d" , VERSION_CODE );
86
+
87
+ char uid [256 ];
88
+ sprintf (uid , "%d" , ctx -> from .uid );
89
+
90
+ char desired_uid [256 ];
91
+ sprintf (desired_uid , "%d" , ctx -> to .uid );
92
+
80
93
if (0 != ctx -> user .android_user_id ) {
81
- char user_result_command [ARG_MAX ];
82
- snprintf (user_result_command , sizeof (user_result_command ), "exec /system/bin/am " ACTION_RESULT " --ei binary_version %d --es from_name '%s' --es desired_name '%s' --ei uid %d --ei desired_uid %d --es command '%s' --es action %s --user %d" ,
83
- VERSION_CODE ,
84
- ctx -> from .name , ctx -> to .name ,
85
- ctx -> from .uid , ctx -> to .uid , get_command (& ctx -> to ), policy == ALLOW ? "allow" : "deny" , ctx -> user .android_user_id );
94
+ char android_user_id [256 ];
95
+ sprintf (android_user_id , "%d" , ctx -> user .android_user_id );
96
+
97
+ char * user_result_command [] = {
98
+ AM_PATH ,
99
+ ACTION_RESULT ,
100
+ "--ei" ,
101
+ "binary_version" ,
102
+ binary_version ,
103
+ "--es" ,
104
+ "from_name" ,
105
+ ctx -> from .name ,
106
+ "--es" ,
107
+ "desired_name" ,
108
+ ctx -> to .name ,
109
+ "--ei" ,
110
+ "uid" ,
111
+ uid ,
112
+ "--ei" ,
113
+ "desired_uid" ,
114
+ desired_uid ,
115
+ "--es" ,
116
+ "command" ,
117
+ get_command (& ctx -> to ),
118
+ "--es" ,
119
+ "action" ,
120
+ policy == ALLOW ? "allow" : "deny" ,
121
+ "--user" ,
122
+ android_user_id ,
123
+ NULL
124
+ };
86
125
silent_run (user_result_command );
87
126
}
88
127
89
- char result_command [ARG_MAX ];
90
- snprintf (result_command , sizeof (result_command ), "exec /system/bin/am " ACTION_RESULT " --ei binary_version %d --es from_name '%s' --es desired_name '%s' --ei uid %d --ei desired_uid %d --es command '%s' --es action %s %s" ,
91
- VERSION_CODE ,
92
- ctx -> from .name , ctx -> to .name ,
93
- ctx -> from .uid , ctx -> to .uid , get_command (& ctx -> to ), policy == ALLOW ? "allow" : "deny" , user );
128
+ char user [64 ];
129
+ get_owner_login_user_args (ctx , user , sizeof (user ));
130
+
131
+ char * result_command [] = {
132
+ AM_PATH ,
133
+ ACTION_RESULT ,
134
+ "--ei" ,
135
+ "binary_version" ,
136
+ binary_version ,
137
+ "--es" ,
138
+ "from_name" ,
139
+ ctx -> from .name ,
140
+ "--es" ,
141
+ "desired_name" ,
142
+ ctx -> to .name ,
143
+ "--ei" ,
144
+ "uid" ,
145
+ uid ,
146
+ "--ei" ,
147
+ "desired_uid" ,
148
+ desired_uid ,
149
+ "--es" ,
150
+ "command" ,
151
+ get_command (& ctx -> to ),
152
+ "--es" ,
153
+ "action" ,
154
+ policy == ALLOW ? "allow" : "deny" ,
155
+ "--user" ,
156
+ user ,
157
+ NULL
158
+ };
94
159
return silent_run (result_command );
95
160
}
96
161
@@ -104,26 +169,40 @@ int send_request(struct su_context *ctx) {
104
169
105
170
int ret ;
106
171
if (needs_owner_login_prompt ) {
107
- // in multiuser mode, the owner gets the su prompt
108
- char notify_command [ARG_MAX ];
172
+ char uid [256 ];
173
+ sprintf (uid , "%d" , ctx -> from .uid );
174
+
175
+ char android_user_id [256 ];
176
+ sprintf (android_user_id , "%d" , ctx -> user .android_user_id );
109
177
110
- // start the activity that confirms the request
111
- snprintf (notify_command , sizeof (notify_command ),
112
- "exec /system/bin/am " ACTION_NOTIFY " --ei caller_uid %d --user %d" ,
113
- ctx -> from .uid , ctx -> user .android_user_id );
178
+ // in multiuser mode, the owner gets the su prompt
179
+ char * notify_command [] = {
180
+ AM_PATH ,
181
+ ACTION_NOTIFY ,
182
+ "--ei" ,
183
+ "caller_uid" ,
184
+ uid ,
185
+ "--user" ,
186
+ android_user_id ,
187
+ NULL
188
+ };
114
189
115
190
int ret = silent_run (notify_command );
116
191
if (ret ) {
117
192
return ret ;
118
193
}
119
194
}
120
195
121
- char request_command [ARG_MAX ];
122
-
123
- // start the activity that confirms the request
124
- snprintf (request_command , sizeof (request_command ),
125
- "exec /system/bin/am " ACTION_REQUEST " --es socket '%s' %s" ,
126
- ctx -> sock_path , user );
196
+ char * request_command [] = {
197
+ AM_PATH ,
198
+ ACTION_REQUEST ,
199
+ "--es" ,
200
+ "socket" ,
201
+ ctx -> sock_path ,
202
+ "--user" ,
203
+ user ,
204
+ NULL
205
+ };
127
206
128
207
return silent_run (request_command );
129
208
}
0 commit comments