2 ** Copyright 2010, Adam Shanks (@ChainsDD)
4 ** Licensed under the Apache License, Version 2.0 (the "License");
5 ** you may not use this file except in compliance with the License.
6 ** You may obtain a copy of the License at
8 ** http://www.apache.org/licenses/LICENSE-2.0
10 ** Unless required by applicable law or agreed to in writing, software
11 ** distributed under the License is distributed on an "AS IS" BASIS,
12 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 ** See the License for the specific language governing permissions and
14 ** limitations under the License.
23 int database_check(struct su_context *ctx)
26 char filename[PATH_MAX];
29 int from_uid = ctx->from.uid;
31 if (ctx->user.owner_mode) {
32 from_uid = from_uid % 100000;
35 snprintf(filename, sizeof(filename),
36 "%s/%u-%u", ctx->user.store_path, from_uid, ctx->to.uid);
37 if ((fp = fopen(filename, "r"))) {
38 LOGD("Found file %s", filename);
40 while (fgets(allow, sizeof(allow), fp)) {
41 last = strlen(allow) - 1;
46 fgets(cmd, sizeof(cmd), fp);
47 /* skip trailing '\n' */
48 last = strlen(cmd) - 1;
52 LOGD("Comparing '%s' to '%s'", cmd, get_command(&ctx->to));
53 if (strcmp(cmd, get_command(&ctx->to)) == 0)
55 else if (strcmp(cmd, "any") == 0) {
60 strcpy(allow, "prompt");
63 } else if ((fp = fopen(ctx->user.store_default, "r"))) {
64 LOGD("Using default file %s", ctx->user.store_default);
65 fgets(allow, sizeof(allow), fp);
66 last = strlen(allow) - 1;
73 if (strcmp(allow, "allow") == 0) {
75 } else if (strcmp(allow, "deny") == 0) {
78 if (ctx->user.userid != 0 && ctx->user.owner_mode) {