Skip to content

Commit 779707b

Browse files
committed
Fix for apps that use multiple commands not being remembered properly
1 parent fa0b93d commit 779707b

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

db.c

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,23 @@ int database_check(const struct su_context *ctx)
3232
if ((fp = fopen(filename, "r"))) {
3333
LOGD("Found file %s", filename);
3434

35-
fgets(allow, sizeof(allow), fp);
36-
last = strlen(allow) - 1;
37-
if (last >= 0)
38-
allow[last] = 0;
35+
while (fgets(allow, sizeof(allow), fp)) {
36+
last = strlen(allow) - 1;
37+
if (last >= 0)
38+
allow[last] = 0;
3939

40-
char cmd[ARG_MAX];
41-
fgets(cmd, sizeof(cmd), fp);
42-
/* skip trailing '\n' */
43-
last = strlen(cmd) - 1;
44-
if (last >= 0)
45-
cmd[last] = 0;
40+
char cmd[ARG_MAX];
41+
fgets(cmd, sizeof(cmd), fp);
42+
/* skip trailing '\n' */
43+
last = strlen(cmd) - 1;
44+
if (last >= 0)
45+
cmd[last] = 0;
4646

47-
LOGD("Comparing '%s' to '%s'", cmd, get_command(&ctx->to));
48-
if (strcmp(cmd, get_command(&ctx->to)) != 0) {
49-
strcpy(allow, "prompt");
47+
LOGD("Comparing '%s' to '%s'", cmd, get_command(&ctx->to));
48+
if (strcmp(cmd, get_command(&ctx->to)) == 0)
49+
break;
50+
else
51+
strcpy(allow, "prompt");
5052
}
5153
fclose(fp);
5254
} else if ((fp = fopen(REQUESTOR_STORED_DEFAULT, "r"))) {

0 commit comments

Comments
 (0)