Update license description
[platform/core/api/notification.git] / src / notification_init.c
1 /*
2  * Copyright (c) 2016 - 2017 Samsung Electronics Co., Ltd. All rights reserved.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 #define _GNU_SOURCE
19
20 #include <string.h>
21 #include <stdlib.h>
22 #include <stdio.h>
23 #include <dirent.h>
24 #include <unistd.h>
25 #include <sys/stat.h>
26 #include <sys/types.h>
27 #include <sys/wait.h>
28 #include <errno.h>
29
30 #include <notification_setting.h>
31
32 /* For multi-user support */
33 #include <tzplatform_config.h>
34
35 #define OWNER_ROOT 0
36
37 #ifdef _E
38 #undef _E
39 #endif
40 #define _E(fmt, arg...) fprintf(stderr, "[NOTIFICATION_INIT][E][%s,%d] "fmt"\n", \
41                 __FUNCTION__, __LINE__, ##arg);
42
43 static int _is_authorized()
44 {
45         /* pkg_init db should be called by as root privilege. */
46         uid_t uid = getuid();
47
48         if ((uid_t) OWNER_ROOT == uid)
49                 return 1;
50         else
51                 return 0;
52 }
53
54 int main(int argc, char *argv[])
55 {
56         int ret;
57         uid_t uid = 0;
58
59         if (!_is_authorized()) {
60                 _E("You are not an authorized user!");
61                 return -1;
62         }
63
64         if (argc > 2)
65                 uid = (uid_t)atoi(argv[2]);
66         ret = notification_setting_refresh_setting_table(uid);
67         if (ret != NOTIFICATION_ERROR_NONE) {
68                 _E("notification setting table refresh fail.");
69                 return ret;
70         }
71
72         ret = notification_system_setting_init_system_setting_table(uid);
73         if (ret != NOTIFICATION_ERROR_NONE) {
74                 _E("notification system setting table init fail.");
75                 return ret;
76         }
77
78         return ret;
79 }