4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5 * Copyright (C) 2013-2014 Intel Corporation.
7 * Contact: Sabera Djelti <sabera.djelti@open.eurogiciel.org>,
8 * Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>, Jaeho Lee <jaeho81.lee@samsung.com>
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
31 #include <sys/smack.h>
35 #include "ail_private.h"
41 #define _E(fmt, arg...) fprintf(stderr, "[AIL_INITDB][E][%s,%d] "fmt"\n", __FUNCTION__, __LINE__, ##arg);
47 #define _D(fmt, arg...) fprintf(stderr, "[AIL_INITDB][D][%s,%d] "fmt"\n", __FUNCTION__, __LINE__, ##arg);
49 #define SET_DEFAULT_LABEL(x) \
51 if (smack_setlabel((x), "*", SMACK_LABEL_ACCESS)) \
52 _E("failed chsmack -a \"*\" %s", x); \
54 _D("chsmack -a \"*\" %s", x); \
57 static int __is_authorized(void)
59 /* ail_init db should be called by an user. */
61 if ((uid_t)OWNER_ROOT != uid)
67 int main(int argc, char *argv[])
72 if (!__is_authorized()) {
73 fprintf(stderr, "You are not an authorized user!\n");
74 _E("You are root user! Please switch to a regular user");
78 db = ail_get_app_DB(getuid());
81 _E("%s is not removed", db);
86 db = ail_get_app_DB_journal(getuid());
89 _E("%s is not removed", db);
94 ret = setenv("AIL_INITDB", "1", 1);
95 _D("AIL_INITDB : %d", ret);
97 if (db_open(DB_OPEN_RW, getuid()) != AIL_ERROR_OK) {
98 _E("Fail to create system databases");
99 return AIL_ERROR_DB_FAILED;