OSDN Git Service

Switch to BoringSSL for crypto.
[android-x86/system-extras.git] / su / su.h
1 /*
2 ** Copyright 2010, Adam Shanks (@ChainsDD)
3 ** Copyright 2008, Zinx Verituse (@zinxv)
4 **
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
8 **
9 **     http://www.apache.org/licenses/LICENSE-2.0
10 **
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.
16 */
17
18 #ifndef SU_h 
19 #define SU_h 1
20
21 #ifdef LOG_TAG
22 #undef LOG_TAG
23 #endif
24 #define LOG_TAG "su"
25
26 // CyanogenMod-specific behavior
27 #define CM_ROOT_ACCESS_DISABLED      0
28 #define CM_ROOT_ACCESS_APPS_ONLY     1
29 #define CM_ROOT_ACCESS_ADB_ONLY      2
30 #define CM_ROOT_ACCESS_APPS_AND_ADB  3
31
32 #define DAEMON_SOCKET_PATH "/dev/socket/su-daemon/"
33
34 #define DEFAULT_SHELL "/system/bin/sh"
35
36 #define xstr(a) str(a)
37 #define str(a) #a
38
39 #ifndef VERSION_CODE
40 #define VERSION_CODE 16
41 #endif
42 #define VERSION xstr(VERSION_CODE) " cm-su"
43
44 #define PROTO_VERSION 1
45
46 struct su_initiator {
47     pid_t pid;
48     unsigned uid;
49     unsigned user;
50     char name[64];
51     char bin[PATH_MAX];
52     char args[4096];
53 };
54
55 struct su_request {
56     unsigned uid;
57     char name[64];
58     int login;
59     int keepenv;
60     char *shell;
61     char *command;
62     char **argv;
63     int argc;
64     int optind;
65 };
66
67 struct su_context {
68     struct su_initiator from;
69     struct su_request to;
70     mode_t umask;
71     char sock_path[PATH_MAX];
72 };
73
74 typedef enum {
75     INTERACTIVE = 0,
76     DENY = 1,
77     ALLOW = 2,
78 } policy_t;
79
80 extern void set_identity(unsigned int uid);
81
82 static inline char *get_command(const struct su_request *to)
83 {
84   if (to->command)
85     return to->command;
86   if (to->shell)
87     return to->shell;
88   char* ret = to->argv[to->optind];
89   if (ret)
90     return ret;
91   return DEFAULT_SHELL;
92 }
93
94 int appops_start_op_su(int uid, const char *pkgName);
95 int appops_finish_op_su(int uid, const char *pkgName);
96
97 int run_daemon();
98 int connect_daemon(int argc, char *argv[], int ppid);
99 int su_main(int argc, char *argv[], int need_client);
100 // for when you give zero fucks about the state of the child process.
101 // this version of fork understands you don't care about the child.
102 // deadbeat dad fork.
103 int fork_zero_fucks();
104
105 #ifndef LOG_NDEBUG
106 #define LOG_NDEBUG 1
107 #endif
108
109 #include <errno.h>
110 #include <string.h>
111 #define PLOGE(fmt,args...) ALOGE(fmt " failed with %d: %s", ##args, errno, strerror(errno))
112 #define PLOGEV(fmt,err,args...) ALOGE(fmt " failed with %d: %s", ##args, err, strerror(err))
113
114 #endif