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())
34 // CyanogenMod-specific behavior
35 #define CM_ROOT_ACCESS_DISABLED 0
36 #define CM_ROOT_ACCESS_APPS_ONLY 1
37 #define CM_ROOT_ACCESS_ADB_ONLY 2
38 #define CM_ROOT_ACCESS_APPS_AND_ADB 3
40 #define REQUESTOR "com.koushikdutta.superuser"
41 #define REQUESTOR_DATA_PATH "/data/data/"
42 #define REQUESTOR_FILES_PATH REQUESTOR_DATA_PATH REQUESTOR "/files"
43 #define REQUESTOR_USER_PATH "/data/user/"
44 #define REQUESTOR_CACHE_PATH "/dev/" REQUESTOR
46 // there's no guarantee that the db or files are actually created named as such by
47 // SQLiteOpenHelper, etc. Though that is the behavior as of current.
48 // it is up to the Android application to symlink as appropriate.
49 #define REQUESTOR_DATABASE_PATH REQUESTOR "/databases/su.sqlite"
50 #define REQUESTOR_MULTIUSER_MODE REQUESTOR_FILES_PATH "/multiuser_mode"
53 #define ACTION_REQUEST "start -n " REQUESTOR "/.RequestActivity"
54 #define ACTION_NOTIFY "start -n " REQUESTOR "/.NotifyActivity"
55 #define ACTION_RESULT "broadcast -n " REQUESTOR "/.SuReceiver"
57 #define DEFAULT_SHELL "/system/bin/sh"
59 #define xstr(a) str(a)
62 #define VERSION_CODE 1
63 #define VERSION xstr(VERSION_CODE) " " REQUESTOR
65 #define PROTO_VERSION 1
89 // the user in android userspace (multiuser)
90 // that invoked this action.
91 unsigned android_user_id;
92 // how su behaves with multiuser. see enum below.
94 // path to superuser directory. this is populated according
95 // to the multiuser mode.
96 // this is used to check uid/gid for protecting socket.
97 // this is used instead of database, as it is more likely
98 // to exist. db will not exist if su has never launched.
99 char base_path[PATH_MAX];
100 // path to su database. this is populated according
101 // to the multiuser mode.
102 char database_path[PATH_MAX];
106 struct su_initiator from;
107 struct su_request to;
108 struct su_user_info user;
110 char sock_path[PATH_MAX];
113 // multiuser su behavior
116 MULTIUSER_MODE_OWNER_ONLY = 0,
117 // owner gets a su prompt
118 MULTIUSER_MODE_OWNER_MANAGED = 1,
119 // user gets a su prompt
120 MULTIUSER_MODE_USER = 2,
121 MULTIUSER_MODE_NONE = 3,
124 #define MULTIUSER_VALUE_OWNER_ONLY "owner"
125 #define MULTIUSER_VALUE_OWNER_MANAGED "managed"
126 #define MULTIUSER_VALUE_USER "user"
127 #define MULTIUSER_VALUE_NONE "none"
135 extern policy_t database_check(struct su_context *ctx);
136 extern void set_identity(unsigned int uid);
137 extern int send_request(struct su_context *ctx);
138 extern int send_result(struct su_context *ctx, policy_t policy);
139 extern void sigchld_handler(int sig);
141 static inline char *get_command(const struct su_request *to)
143 return (to->command) ? to->command : to->shell;
146 void exec_loge(const char* fmt, ...);
147 void exec_logw(const char* fmt, ...);
148 void exec_logd(const char* fmt, ...);
150 // fallback to using /system/bin/log.
151 // can't use liblog.so because this is a static binary.
153 #define LOGE exec_loge
156 #define LOGD exec_logd
159 #define LOGW exec_logw
164 #define LOGE(fmt,args...) fprintf(stderr, fmt, ##args)
166 #define LOGD(fmt,args...) fprintf(stderr, fmt, ##args)
168 #define LOGW(fmt,args...) fprintf(stderr, fmt, ##args)
173 #define PLOGE(fmt,args...) LOGE(fmt " failed with %d: %s", ##args, errno, strerror(errno))
174 #define PLOGEV(fmt,err,args...) LOGE(fmt " failed with %d: %s", ##args, err, strerror(err))