Integrate tizen-platform-wrapper
[platform/core/system/tizen-platform-config.git] / src / global-api.c
1 /*
2  * Copyright (C) 2013-2014 Intel Corporation.
3  * 
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
17  *
18  * Authors:
19  *   José Bollo <jose.bollo@open.eurogiciel.org>
20  *   Stéphane Desneux <stephane.desneux@open.eurogiciel.org>
21  *   Jean-Benoit Martin <jean-benoit.martin@open.eurogiciel.org>
22  *
23  */
24 #define _GNU_SOURCE
25
26 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
29
30 #include <unistd.h>
31 #include "tzplatform_variables.h"
32 #include "tzplatform_config.h"
33
34 #include "shared-api.h"
35 #include "isadmin.h"
36
37 int tzplatform_getcount()
38 {
39     return _TZPLATFORM_VARIABLES_COUNT_;
40 }
41
42 const char* tzplatform_getname(enum tzplatform_variable id)
43 {
44     return _getname_tzplatform_(id);
45 }
46
47 enum tzplatform_variable tzplatform_getid(const char *name)
48 {
49     return _getid_tzplatform_(name);
50 }
51
52 const char* tzplatform_getenv(enum tzplatform_variable id) 
53 {
54     return _getenv_tzplatform_(id);
55 }
56
57 const char* tzplatform_context_getenv(struct tzplatform_context *context, enum tzplatform_variable id)
58 {
59     return _context_getenv_tzplatform_(id, context);
60 }
61
62 int tzplatform_getenv_int(enum tzplatform_variable id)
63 {
64     return _getenv_int_tzplatform_(id);
65 }
66
67 int tzplatform_context_getenv_int(struct tzplatform_context *context, enum tzplatform_variable id)
68 {
69     return _context_getenv_int_tzplatform_(id, context);
70 }
71
72 const char* tzplatform_mkstr(enum tzplatform_variable id, const char * str)
73 {
74     return _mkstr_tzplatform_(id, str);
75 }
76
77 const char* tzplatform_context_mkstr(struct tzplatform_context *context, enum tzplatform_variable id, const char *str)
78 {
79     return _context_mkstr_tzplatform_(id, str, context);
80 }
81
82 const char* tzplatform_mkpath(enum tzplatform_variable id, const char * path)
83 {
84     return _mkpath_tzplatform_(id, path);
85 }
86
87 const char* tzplatform_context_mkpath(struct tzplatform_context *context, enum tzplatform_variable id, const char *path)
88 {
89     return _context_mkpath_tzplatform_(id, path, context);
90 }
91
92 const char* tzplatform_mkpath3(enum tzplatform_variable id, const char * path, const char* path2)
93 {
94     return _mkpath3_tzplatform_(id, path, path2);
95 }
96
97 const char* tzplatform_context_mkpath3(struct tzplatform_context *context, enum tzplatform_variable id, const char *path, const char *path2)
98 {
99     return _context_mkpath3_tzplatform_(id, path, path2, context);
100 }
101
102 const char* tzplatform_mkpath4(enum tzplatform_variable id, const char * path, const char* path2, const char *path3)
103 {
104     return _mkpath4_tzplatform_(id, path, path2, path3);
105 }
106
107 const char* tzplatform_context_mkpath4(struct tzplatform_context *context, enum tzplatform_variable id, const char *path, const char *path2, const char *path3)
108 {
109     return _context_mkpath4_tzplatform_(id, path, path2, path3, context);
110 }
111
112 uid_t tzplatform_getuid(enum tzplatform_variable id)
113 {
114     return _getuid_tzplatform_(id);
115 }
116
117 uid_t tzplatform_context_getuid(struct tzplatform_context *context, enum tzplatform_variable id)
118 {
119     return _context_getuid_tzplatform_(id, context);
120 }
121
122 gid_t tzplatform_getgid(enum tzplatform_variable id)
123 {
124     return _getgid_tzplatform_(id);
125 }
126
127 gid_t tzplatform_context_getgid(struct tzplatform_context *context, enum tzplatform_variable id)
128 {
129     return _context_getgid_tzplatform_(id, context);
130 }
131
132 int tzplatform_has_system_group(uid_t uid)
133 {
134         return _has_system_group_static_(uid);
135 }
136
137 #ifdef TEST
138 #include <stdlib.h>
139 #include <stdio.h>
140
141 int main() {
142     int i;
143     struct tzplatform_context *context;
144     enum tzplatform_variable id;
145     const char *name;
146     const char *value;
147     int xid;
148     uid_t uid;
149
150     i = 0;
151     while(i != tzplatform_getcount()) {
152         id = (enum tzplatform_variable)i;
153         name = tzplatform_getname(id);
154         value = tzplatform_getenv(id);
155         xid = (int)tzplatform_getid(name);
156         printf("%d=%d\t%s=%s\n",i,xid,name,value?value:"<null>");
157         i++;
158     }
159
160     printf("------------------------\n");
161     i = tzplatform_context_create(&context);
162     if (i) {
163         printf("error while creating context %d\n",i);
164         return 1;
165     }
166
167     uid = (uid_t)0;
168     i = tzplatform_context_set_user(context, uid);
169     if (i) {
170         printf("error %d while switching to user %d\n",i,(int)uid);
171         return 1;
172     }
173     i = 0;
174     while(i != tzplatform_getcount()) {
175         id = (enum tzplatform_variable)i;
176         name = tzplatform_getname(id);
177         value = tzplatform_context_getenv(context, id);
178         xid = (int)tzplatform_getid(name);
179         printf("%d=%d\t%s=%s\n",i,xid,name,value?value:"<null>");
180         i++;
181     }
182     tzplatform_context_destroy(context);
183
184     return 0;
185 }
186 #endif
187
188