Skip to content

Commit b7744e9

Browse files
author
git-core
committed
Merge branch 'gc' into gc-ics
2 parents e0329ce + 3352996 commit b7744e9

File tree

5 files changed

+384
-239
lines changed

5 files changed

+384
-239
lines changed

Android.mk

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,19 @@ include $(CLEAR_VARS)
44
LOCAL_MODULE := su
55
LOCAL_SRC_FILES := su.c db.c activity.cpp
66

7+
SU_SHARED_LIBRARIES := liblog libsqlite
8+
ifeq ($(PLATFORM_SDK_VERSION),4)
9+
LOCAL_CFLAGS += -DSU_LEGACY_BUILD
10+
SU_SHARED_LIBRARIES += libandroid_runtime
11+
else
12+
SU_SHARED_LIBRARIES += libcutils libbinder libutils
13+
LOCAL_MODULE_TAGS := debug,eng
14+
endif
715

816
LOCAL_C_INCLUDES += external/sqlite/dist
917

10-
LOCAL_SHARED_LIBRARIES := \
11-
liblog \
12-
libsqlite \
13-
libcutils \
14-
libbinder \
15-
libutils \
18+
LOCAL_SHARED_LIBRARIES := $(SU_SHARED_LIBRARIES)
1619

1720
LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES)
18-
LOCAL_MODULE_TAGS := debug,eng
1921

2022
include $(BUILD_EXECUTABLE)

activity.cpp

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,20 @@
1717

1818
#include <unistd.h>
1919
#include <android_runtime/ActivityManager.h>
20+
#ifdef SU_LEGACY_BUILD
21+
#include <utils/IBinder.h>
22+
#include <utils/IServiceManager.h>
23+
#include <utils/Parcel.h>
24+
#else
2025
#include <binder/IBinder.h>
2126
#include <binder/IServiceManager.h>
2227
#include <binder/Parcel.h>
28+
#endif
2329
#include <utils/String8.h>
2430
#include <assert.h>
2531

2632
extern "C" {
2733
#include "su.h"
28-
#include <private/android_filesystem_config.h>
29-
#include <cutils/properties.h>
3034
}
3135

3236
using namespace android;
@@ -40,13 +44,9 @@ static const int VAL_INTEGER = 1;
4044

4145
static const int START_SUCCESS = 0;
4246

43-
int send_intent(struct su_initiator *from, struct su_request *to, const char *socket_path, int allow, int type)
47+
int send_intent(const struct su_context *ctx,
48+
const char *socket_path, int allow, const char *action)
4449
{
45-
char sdk_version_prop[PROPERTY_VALUE_MAX] = "0";
46-
property_get("ro.build.version.sdk", sdk_version_prop, "0");
47-
48-
int sdk_version = atoi(sdk_version_prop);
49-
5050
sp<IServiceManager> sm = defaultServiceManager();
5151
sp<IBinder> am = sm->checkService(String16("activity"));
5252
assert(am != NULL);
@@ -57,54 +57,50 @@ int send_intent(struct su_initiator *from, struct su_request *to, const char *so
5757
data.writeStrongBinder(NULL); /* caller */
5858

5959
/* intent */
60-
if (type == 0) {
61-
data.writeString16(String16("com.noshufou.android.su.REQUEST")); /* action */
62-
} else {
63-
data.writeString16(String16("com.noshufou.android.su.RESULT")); /* action */
64-
}
60+
data.writeString16(String16(action)); /* action */
6561
data.writeInt32(NULL_TYPE_ID); /* Uri - data */
6662
data.writeString16(NULL, 0); /* type */
6763
data.writeInt32(0); /* flags */
68-
if (sdk_version >= 4) {
64+
if (ctx->sdk_version >= 4) {
6965
// added in donut
7066
data.writeString16(NULL, 0); /* package name - DONUT ONLY, NOT IN CUPCAKE. */
7167
}
7268
data.writeString16(NULL, 0); /* ComponentName - package */
73-
data.writeInt32(0); /* Categories - size */
74-
if (sdk_version >= 7) {
69+
if (ctx->sdk_version >= 7) {
7570
// added in eclair rev 7
76-
data.writeInt32(0);
71+
data.writeInt32(0); /* Rect - the bounds of the sender */
7772
}
78-
if (sdk_version >= 15) {
73+
data.writeInt32(0); /* Categories - size */
74+
if (ctx->sdk_version >= 15) {
7975
// added in IceCreamSandwich 4.0.3
8076
data.writeInt32(0); /* Selector */
8177
}
8278
{ /* Extras */
8379
data.writeInt32(-1); /* dummy, will hold length */
84-
int oldPos = data.dataPosition();
8580
data.writeInt32(0x4C444E42); // 'B' 'N' 'D' 'L'
81+
int oldPos = data.dataPosition();
8682
{ /* writeMapInternal */
8783
data.writeInt32(7); /* writeMapInternal - size */
8884

8985
data.writeInt32(VAL_STRING);
9086
data.writeString16(String16("caller_uid"));
9187
data.writeInt32(VAL_INTEGER);
92-
data.writeInt32(from->uid);
88+
data.writeInt32(ctx->from.uid);
9389

9490
data.writeInt32(VAL_STRING);
9591
data.writeString16(String16("caller_bin"));
9692
data.writeInt32(VAL_STRING);
97-
data.writeString16(String16(from->bin));
93+
data.writeString16(String16(ctx->from.bin));
9894

9995
data.writeInt32(VAL_STRING);
10096
data.writeString16(String16("desired_uid"));
10197
data.writeInt32(VAL_INTEGER);
102-
data.writeInt32(to->uid);
98+
data.writeInt32(ctx->to.uid);
10399

104100
data.writeInt32(VAL_STRING);
105101
data.writeString16(String16("desired_cmd"));
106102
data.writeInt32(VAL_STRING);
107-
data.writeString16(String16(to->command));
103+
data.writeString16(String16(get_command(&ctx->to)));
108104

109105
data.writeInt32(VAL_STRING);
110106
data.writeString16(String16("socket"));
@@ -122,15 +118,13 @@ int send_intent(struct su_initiator *from, struct su_request *to, const char *so
122118
data.writeInt32(VERSION_CODE);
123119
}
124120
int newPos = data.dataPosition();
125-
data.setDataPosition(oldPos - 4);
121+
data.setDataPosition(oldPos - 8);
126122
data.writeInt32(newPos - oldPos); /* length */
127123
data.setDataPosition(newPos);
128124
}
129125

130126
data.writeString16(NULL, 0); /* resolvedType */
131127

132-
data.writeInt32(-1); /* Not sure what this is for, but it prevents a warning */
133-
134128
data.writeStrongBinder(NULL); /* resultTo */
135129
data.writeInt32(-1); /* resultCode */
136130
data.writeString16(NULL, 0); /* resultData */
@@ -140,7 +134,6 @@ int send_intent(struct su_initiator *from, struct su_request *to, const char *so
140134
data.writeString16(String16("com.noshufou.android.su.RESPOND")); /* perm */
141135
data.writeInt32(0); /* serialized */
142136
data.writeInt32(0); /* sticky */
143-
data.writeInt32(-1);
144137

145138
status_t ret = am->transact(BROADCAST_INTENT_TRANSACTION, data, &reply);
146139
if (ret < START_SUCCESS) return -1;

db.c

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@
2323

2424
#include "su.h"
2525

26-
// { int* pint; pint=(int*)data; ++(*pint); }
27-
28-
sqlite3 *database_init()
26+
static sqlite3 *db_init(void)
2927
{
3028
sqlite3 *db;
3129
int rc;
@@ -41,7 +39,7 @@ sqlite3 *database_init()
4139
return db;
4240
}
4341

44-
int database_check(sqlite3 *db, struct su_initiator *from, struct su_request *to)
42+
static int db_check(sqlite3 *db, const struct su_context *ctx)
4543
{
4644
char sql[4096];
4745
char *zErrmsg;
@@ -52,7 +50,7 @@ int database_check(sqlite3 *db, struct su_initiator *from, struct su_request *to
5250
sqlite3_snprintf(
5351
sizeof(sql), sql,
5452
"SELECT _id,name,allow FROM apps WHERE uid=%u AND exec_uid=%u AND exec_cmd='%q';",
55-
(unsigned)from->uid, to->uid, to->command
53+
ctx->from.uid, ctx->to.uid, get_command(&ctx->to)
5654
);
5755

5856
if (strlen(sql) >= sizeof(sql)-1)
@@ -85,3 +83,25 @@ int database_check(sqlite3 *db, struct su_initiator *from, struct su_request *to
8583

8684
return allow;
8785
}
86+
87+
int database_check(const struct su_context *ctx)
88+
{
89+
sqlite3 *db;
90+
int dballow;
91+
92+
LOGE("sudb - Opening database");
93+
db = db_init();
94+
if (!db) {
95+
LOGE("sudb - Could not open database, prompt user");
96+
// if the database could not be opened, we can assume we need to
97+
// prompt the user
98+
return DB_INTERACTIVE;
99+
}
100+
101+
LOGE("sudb - Database opened");
102+
dballow = db_check(db, ctx);
103+
// Close the database, we're done with it. If it stays open, it will cause problems
104+
sqlite3_close(db);
105+
LOGE("sudb - Database closed");
106+
return dballow;
107+
}

0 commit comments

Comments
 (0)