2 ** Copyright 2010, Adam Shanks (@ChainsDD)
3 ** Copyright 2008, Zinx Verituse (@zinxv)
5 ** Licensed under the Apache License, Version 2.0 (the "License");
6 ** you may not use this file except in compliance with the License.
7 ** You may obtain a copy of the License at
9 ** http://www.apache.org/licenses/LICENSE-2.0
11 ** Unless required by applicable law or agreed to in writing, software
12 ** distributed under the License is distributed on an "AS IS" BASIS,
13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 ** See the License for the specific language governing permissions and
15 ** limitations under the License.
27 #define AID_SHELL (get_shell_uid())
35 #define AID_SYSTEM (get_system_uid())
39 #define AID_RADIO (get_radio_uid())
42 // CyanogenMod-specific behavior
43 #define CM_ROOT_ACCESS_DISABLED 0
44 #define CM_ROOT_ACCESS_APPS_ONLY 1
45 #define CM_ROOT_ACCESS_ADB_ONLY 2
46 #define CM_ROOT_ACCESS_APPS_AND_ADB 3
48 // DO NOT CHANGE LINE BELOW, java package name will always be the same
49 #define JAVA_PACKAGE_NAME "com.koushikdutta.superuser"
51 // If --rename-manifest-package is used in AAPT, this
52 // must be changed to correspond to the new APK package name
53 // See the two Android.mk files for more details.
55 #define REQUESTOR JAVA_PACKAGE_NAME
57 // This is used if wrapping the fragment classes and activities
58 // with classes in another package. CM requirement.
59 #ifndef REQUESTOR_PREFIX
60 #define REQUESTOR_PREFIX JAVA_PACKAGE_NAME
62 #define REQUESTOR_DATA_PATH "/data/data/"
63 #define REQUESTOR_FILES_PATH REQUESTOR_DATA_PATH REQUESTOR "/files"
64 #define REQUESTOR_USER_PATH "/data/user/"
65 #define REQUESTOR_CACHE_PATH "/dev/" REQUESTOR
67 // there's no guarantee that the db or files are actually created named as such by
68 // SQLiteOpenHelper, etc. Though that is the behavior as of current.
69 // it is up to the Android application to symlink as appropriate.
70 #define REQUESTOR_DATABASE_PATH REQUESTOR "/databases/su.sqlite"
71 #define REQUESTOR_MULTIUSER_MODE REQUESTOR_FILES_PATH "/multiuser_mode"
74 #define ACTION_REQUEST "start -n " REQUESTOR "/" REQUESTOR_PREFIX ".RequestActivity"
75 #define ACTION_NOTIFY "start -n " REQUESTOR "/" REQUESTOR_PREFIX ".NotifyActivity"
76 #define ACTION_RESULT "broadcast -n " REQUESTOR "/" REQUESTOR_PREFIX ".SuReceiver"
78 #define DEFAULT_SHELL "/system/bin/sh"
80 #define xstr(a) str(a)
84 #define VERSION_CODE 9
86 #define VERSION xstr(VERSION_CODE) " " REQUESTOR
88 #define PROTO_VERSION 1
111 struct su_user_info {
112 // the user in android userspace (multiuser)
113 // that invoked this action.
114 unsigned android_user_id;
115 // how su behaves with multiuser. see enum below.
117 // path to superuser directory. this is populated according
118 // to the multiuser mode.
119 // this is used to check uid/gid for protecting socket.
120 // this is used instead of database, as it is more likely
121 // to exist. db will not exist if su has never launched.
122 char base_path[PATH_MAX];
123 // path to su database. this is populated according
124 // to the multiuser mode.
125 char database_path[PATH_MAX];
129 struct su_initiator from;
130 struct su_request to;
131 struct su_user_info user;
133 char sock_path[PATH_MAX];
136 // multiuser su behavior
139 MULTIUSER_MODE_OWNER_ONLY = 0,
140 // owner gets a su prompt
141 MULTIUSER_MODE_OWNER_MANAGED = 1,
142 // user gets a su prompt
143 MULTIUSER_MODE_USER = 2,
144 MULTIUSER_MODE_NONE = 3,
147 #define MULTIUSER_VALUE_OWNER_ONLY "owner"
148 #define MULTIUSER_VALUE_OWNER_MANAGED "managed"
149 #define MULTIUSER_VALUE_USER "user"
150 #define MULTIUSER_VALUE_NONE "none"
158 extern policy_t database_check(struct su_context *ctx);
159 extern void set_identity(unsigned int uid);
160 extern int send_request(struct su_context *ctx);
161 extern int send_result(struct su_context *ctx, policy_t policy);
162 extern int silent_run(char* command);
164 static inline char *get_command(const struct su_request *to)
170 char* ret = to->argv[to->optind];
173 return DEFAULT_SHELL;
176 void exec_loge(const char* fmt, ...);
177 void exec_logw(const char* fmt, ...);
178 void exec_logd(const char* fmt, ...);
180 // fallback to using /system/bin/log.
181 // can't use liblog.so because this is a static binary.
183 #define LOGE exec_loge
186 #define LOGD exec_logd
189 #define LOGW exec_logw
194 #define LOGE(fmt,args...) fprintf(stderr, fmt, ##args)
196 #define LOGD(fmt,args...) fprintf(stderr, fmt, ##args)
198 #define LOGW(fmt,args...) fprintf(stderr, fmt, ##args)
203 #define PLOGE(fmt,args...) LOGE(fmt " failed with %d: %s", ##args, errno, strerror(errno))
204 #define PLOGEV(fmt,err,args...) LOGE(fmt " failed with %d: %s", ##args, err, strerror(err))