|
23 | 23 | int database_check(const struct su_context *ctx)
|
24 | 24 | {
|
25 | 25 | FILE *fp;
|
26 |
| - int allow = '-'; |
27 | 26 | char filename[PATH_MAX];
|
| 27 | + char allow[7]; |
| 28 | + int last = 0; |
28 | 29 |
|
29 | 30 | snprintf(filename, sizeof(filename),
|
30 | 31 | REQUESTOR_STORED_PATH "/%u-%u", ctx->from.uid, ctx->to.uid);
|
31 | 32 | if ((fp = fopen(filename, "r"))) {
|
32 | 33 | LOGD("Found file %s", filename);
|
| 34 | + |
| 35 | + fgets(allow, sizeof(allow), fp); |
| 36 | + last = strlen(allow) - 1; |
| 37 | + if (last >= 0) |
| 38 | + allow[last] = 0; |
| 39 | + |
33 | 40 | char cmd[ARG_MAX];
|
34 | 41 | fgets(cmd, sizeof(cmd), fp);
|
35 | 42 | /* skip trailing '\n' */
|
36 |
| - int last = strlen(cmd) - 1; |
| 43 | + last = strlen(cmd) - 1; |
37 | 44 | if (last >= 0)
|
38 | 45 | cmd[last] = 0;
|
39 | 46 |
|
40 | 47 | LOGD("Comparing '%s' to '%s'", cmd, get_command(&ctx->to));
|
41 |
| - if (strcmp(cmd, get_command(&ctx->to)) == 0) { |
42 |
| - allow = fgetc(fp); |
| 48 | + if (strcmp(cmd, get_command(&ctx->to)) != 0) { |
| 49 | + strcpy(allow, "prompt"); |
43 | 50 | }
|
44 | 51 | fclose(fp);
|
45 | 52 | } else if ((fp = fopen(REQUESTOR_STORED_DEFAULT, "r"))) {
|
46 | 53 | LOGD("Using default file %s", REQUESTOR_STORED_DEFAULT);
|
47 |
| - char cmd[ARG_MAX]; |
48 |
| - fgets(cmd, sizeof(cmd), fp); |
49 |
| - int last = strlen(cmd) - 1; |
50 |
| - if (last >= 0) |
51 |
| - cmd[last] = 0; |
52 |
| - |
53 |
| - if (strcmp(cmd, "default") == 0) { |
54 |
| - allow = fgetc(fp); |
55 |
| - } |
| 54 | + fgets(allow, sizeof(allow), fp); |
| 55 | + last = strlen(allow) - 1; |
| 56 | + if (last >=0) |
| 57 | + allow[last] = 0; |
| 58 | + |
56 | 59 | fclose(fp);
|
57 | 60 | }
|
58 | 61 |
|
59 |
| - if (allow == '1') { |
| 62 | + if (strcmp(allow, "allow") == 0) { |
60 | 63 | return ALLOW;
|
61 |
| - } else if (allow == '0') { |
| 64 | + } else if (strcmp(allow, "deny") == 0) { |
62 | 65 | return DENY;
|
63 | 66 | } else {
|
64 | 67 | return INTERACTIVE;
|
|
0 commit comments