Skip to content

Commit 73a4964

Browse files
author
git-core
committed
Move all code that deals with database in db.c
1 parent fb9f063 commit 73a4964

File tree

3 files changed

+27
-26
lines changed

3 files changed

+27
-26
lines changed

db.c

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
// { int* pint; pint=(int*)data; ++(*pint); }
2727

28-
sqlite3 *database_init()
28+
static sqlite3 *db_init()
2929
{
3030
sqlite3 *db;
3131
int rc;
@@ -41,7 +41,7 @@ sqlite3 *database_init()
4141
return db;
4242
}
4343

44-
int database_check(sqlite3 *db, struct su_initiator *from, struct su_request *to)
44+
static int db_check(sqlite3 *db, struct su_initiator *from, struct su_request *to)
4545
{
4646
char sql[4096];
4747
char *zErrmsg;
@@ -85,3 +85,25 @@ int database_check(sqlite3 *db, struct su_initiator *from, struct su_request *to
8585

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

su.c

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,12 @@
3939
#include <private/android_filesystem_config.h>
4040
#include <cutils/log.h>
4141

42-
#include <sqlite3.h>
43-
4442
#include "su.h"
4543

4644
//extern char* _mktemp(char*); /* mktemp doesn't link right. Don't ask me why. */
4745

48-
extern sqlite3 *database_init();
49-
extern int database_check(sqlite3*, struct su_initiator*, struct su_request*);
50-
5146
/* Still lazt, will fix this */
5247
static char *socket_path = NULL;
53-
static sqlite3 *db = NULL;
5448

5549
static struct su_initiator su_from = {
5650
.pid = -1,
@@ -137,7 +131,6 @@ static void socket_cleanup(void)
137131
static void cleanup(void)
138132
{
139133
socket_cleanup();
140-
if (db) sqlite3_close(db);
141134
}
142135

143136
static void cleanup_signal(int sig)
@@ -396,23 +389,7 @@ int main(int argc, char *argv[])
396389
setegid(st.st_gid);
397390
seteuid(st.st_uid);
398391

399-
LOGE("sudb - Opening database");
400-
db = database_init();
401-
if (!db) {
402-
LOGE("sudb - Could not open database, prompt user");
403-
// if the database could not be opened, we can assume we need to
404-
// prompt the user
405-
dballow = DB_INTERACTIVE;
406-
} else {
407-
LOGE("sudb - Database opened");
408-
dballow = database_check(db, &su_from, &su_to);
409-
// Close the database, we're done with it. If it stays open,
410-
// it will cause problems
411-
sqlite3_close(db);
412-
db = NULL;
413-
LOGE("sudb - Database closed");
414-
}
415-
392+
dballow = database_check(&su_from, &su_to);
416393
switch (dballow) {
417394
case DB_DENY: deny();
418395
case DB_ALLOW: allow(shell, orig_umask);

su.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ enum {
5353
DB_ALLOW
5454
};
5555

56+
extern int database_check(struct su_initiator*, struct su_request*);
57+
5658
extern int send_intent(struct su_initiator *from, struct su_request *to, const char *socket_path, int allow, int type);
5759

5860
#if 0

0 commit comments

Comments
 (0)