2 * Copyright (C) 2013-2014 Intel Corporation.
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.
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.
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
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>
24 #ifndef LIBTIZEN_PLATFORM_WRAPPER
25 #define LIBTIZEN_PLATFORM_WRAPPER
31 #include <sys/types.h>
32 #include <tzplatform_variables.h>
34 //=================================================================================
35 //======================== COMMON APIs (No context) ===============================
36 //=================================================================================
39 Return the count of variables.
42 int tzplatform_getcount();
45 Return the name of the variable 'id' as a string.
46 Return NULL if 'id' is invalid.
49 const char* tzplatform_getname(enum tzplatform_variable id);
52 Return the id of the variable of 'name'.
53 Return _TZPLATFORM_VARIABLES_INVALID_ if 'name' doesn't match a
57 enum tzplatform_variable tzplatform_getid(const char *name);
59 //=================================================================================
60 //====================== GLOBAL APIs (default global context) =====================
61 //=================================================================================
64 Enforces the removal of the previously evaluated tizen platform variables.
66 Call this function in case of changing of user inside the application.
69 void tzplatform_reset();
72 Set the user used for UID/EUID/USER/EUSER computations.
73 Using uid==(uid_t)-1 reset the context as if tzplatform_reset_user
76 Returns 0 if uid is valid or -1 if not valid.
79 int tzplatform_set_user(uid_t uid);
84 uid_t tzplatform_get_user();
87 Reset the user context to use the values returned by
91 void tzplatform_reset_user();
94 Return the read-only string value of the tizen plaform variable 'id'.
96 The returned value is an allocated unique string that MUST not be freed.
98 Can return NULL in case of internal error or when 'id' isn't defined.
101 const char* tzplatform_getenv(enum tzplatform_variable id);
104 Return the integer value of the tizen plaform variable 'id'.
107 int tzplatform_getenv_int(enum tzplatform_variable id);
110 Return the string resulting of the concatenation of string value of the
111 tizen plaform variable 'id' and the given string 'str'.
113 The returned value is an allocated unique string that MUST not be freed.
115 Can return NULL in case of internal error.
118 if TZ_SYS_HOME == "/opt/home" then calling
120 tzplatform_mkstr(TZ_SYS_HOME,"-yes")
122 will return "/opt/home-yes"
125 const char* tzplatform_mkstr(enum tzplatform_variable id, const char *str);
128 Return the string resulting of the path-concatenation of string value of the
129 tizen plaform variable 'id' and the given string 'path'.
131 path-concatenation is the concatenation taking care of / characters.
133 The returned value is an allocated unique string that MUST not be freed.
135 Can return NULL in case of internal error.
138 if TZ_SYS_HOME == "/opt/home" then calling
140 tzplatform_mkpath(TZ_SYS_HOME,"yes")
142 will return "/opt/home/yes"
145 const char* tzplatform_mkpath(enum tzplatform_variable id, const char *path);
148 Return the string resulting of the path-concatenation of string value of the
149 tizen plaform variable 'id' and the given strings 'path' and 'path2'.
151 path-concatenation is the concatenation taking care of / characters.
153 The returned value is an allocated unique string that MUST not be freed.
155 Can return NULL in case of internal error.
158 if TZ_SYS_HOME == "/opt/home" then calling
160 tzplatform_mkpath3(TZ_SYS_HOME,"yes","no")
162 will return "/opt/home/yes/no"
165 const char* tzplatform_mkpath3(enum tzplatform_variable id, const char *path,
169 Return the string resulting of the path-concatenation of string value of the
170 tizen plaform variable 'id' and the given strings 'path', 'path2' and 'path3'.
172 path-concatenation is the concatenation taking care of / characters.
174 The returned value is an allocated unique string that MUST not be freed.
176 Can return NULL in case of internal error.
179 if TZ_SYS_HOME == "/opt/home" then calling
181 tzplatform_mkpath4(TZ_SYS_HOME,"yes","no","/maybe")
183 will return "/opt/home/yes/no/maybe"
186 const char* tzplatform_mkpath4(enum tzplatform_variable id, const char *path,
187 const char *path2, const char *path3);
190 Return the uid for a given user name, stored in variable <id>
191 Retun -1 in case of error.
194 if TZ_USER_NAME=="app" then calling:
196 tzplatform_getuid(TZ_USER_NAME)
198 will return the uid of the user 'app'
201 uid_t tzplatform_getuid(enum tzplatform_variable id);
204 Return the gid for a given user name, stored in variable <id>
205 Retun -1 in case of error.
208 if TZ_USER_NAME=="app" then calling:
210 tzplatform_getuid(TZ_USER_NAME)
212 will return the gid of the user 'app'
215 gid_t tzplatform_getgid(enum tzplatform_variable id);
217 //=================================================================================
218 //============================ UID-based APIs =====================================
219 //=================================================================================
222 In the following APIs, a 'uid' parameter is added to the form of GLOBAL APIs.
224 How-to-use is the same with GLOBAL APIs, but contexts are internally created and set for each uid.
226 uid should be one of root(0), owner(5001), and so on.
230 const char* tzplatform_uid_getenv(uid_t uid, enum tzplatform_variable id);
233 const char* tzplatform_uid_mkpath(uid_t uid, enum tzplatform_variable id, const char *path);
236 const char* tzplatform_uid_mkpath3(uid_t uid, enum tzplatform_variable id, const char *path,
240 const char* tzplatform_uid_mkpath4(uid_t uid, enum tzplatform_variable id, const char *path,
241 const char *path2, const char *path3);
243 //=================================================================================
244 //============================ CONTEXTUAL APIs ====================================
245 //=================================================================================
247 struct tzplatform_context;
250 Creates a new platform 'context'.
251 Return 0 in case of success or a negative value in case of error.
254 int tzplatform_context_create(struct tzplatform_context **context);
257 Destroys the platform 'context' previously created with 'tzplatform_context_create'.
258 The destroyed context must not be used after calling this function.
261 void tzplatform_context_destroy(struct tzplatform_context *context);
264 Enforces the removal of the previously evaluated tizen platform variables.
267 void tzplatform_context_reset(struct tzplatform_context *context);
270 Set the user used for UID/EUID/USER/EUSER computations.
271 Using uid==(uid_t)-1 reset the context as if tzplatform_context_reset_user
274 Returns 0 if uid is valid or -1 if not valid.
277 int tzplatform_context_set_user(struct tzplatform_context *context, uid_t uid);
280 Get the user set to the context.
283 uid_t tzplatform_context_get_user(struct tzplatform_context *context);
286 Reset the user context to use the values returned by
290 void tzplatform_context_reset_user(struct tzplatform_context *context);
293 Return the read-only string value of the tizen plaform variable 'id'.
295 The returned value is an allocated unique string that MUST not be freed.
297 Can return NULL in case of internal error or when 'id' isn't defined.
300 const char* tzplatform_context_getenv(struct tzplatform_context *context,
301 enum tzplatform_variable id);
304 Return the integer value of the tizen plaform variable 'id'.
307 int tzplatform_context_getenv_int(struct tzplatform_context *context,
308 enum tzplatform_variable id);
311 Return the string resulting of the concatenation of string value of the
312 tizen plaform variable 'id' and the given string 'str'.
314 The returned value is an allocated unique string that MUST not be freed.
316 Can return NULL in case of internal error.
319 if TZ_SYS_HOME == "/opt/home" then calling
321 tzplatform_context_mkstr(context, TZ_SYS_HOME,"-yes")
323 will return "/opt/home-yes"
326 const char* tzplatform_context_mkstr(struct tzplatform_context *context,
327 enum tzplatform_variable id, const char *str);
330 Return the string resulting of the path-concatenation of string value of the
331 tizen plaform variable 'id' and the given string 'path'.
333 path-concatenation is the concatenation taking care of / characters.
335 The returned value is an allocated unique string that MUST not be freed.
337 Can return NULL in case of internal error.
340 if TZ_SYS_HOME == "/opt/home" then calling
342 tzplatform_context_mkpath(context, TZ_SYS_HOME,"yes")
344 will return "/opt/home/yes"
347 const char* tzplatform_context_mkpath(struct tzplatform_context *context,
348 enum tzplatform_variable id, const char *path);
351 Return the string resulting of the path-concatenation of string value of the
352 tizen plaform variable 'id' and the given strings 'path' and 'path2'.
354 path-concatenation is the concatenation taking care of / characters.
356 The returned value is an allocated unique string that MUST not be freed.
358 Can return NULL in case of internal error.
361 if TZ_SYS_HOME == "/opt/home" then calling
363 tzplatform_context_mkpath3(context, TZ_SYS_HOME,"yes","no")
365 will return "/opt/home/yes/no"
368 const char* tzplatform_context_mkpath3(struct tzplatform_context *context,
369 enum tzplatform_variable id, const char *path,
373 Return the string resulting of the path-concatenation of string value of the
374 tizen plaform variable 'id' and the given strings 'path', 'path2' and 'path3'.
376 path-concatenation is the concatenation taking care of / characters.
378 The returned value is an allocated unique string that MUST not be freed.
380 Can return NULL in case of internal error.
383 if TZ_SYS_HOME == "/opt/home" then calling
385 tzplatform_context_mkpath4(context, TZ_SYS_HOME,"yes","no","/maybe")
387 will return "/opt/home/yes/no/maybe"
390 const char* tzplatform_context_mkpath4(struct tzplatform_context *context,
391 enum tzplatform_variable id, const char *path,
392 const char *path2, const char *path3);
395 Return the uid for a given user name, stored in variable <id>
396 Retun -1 in case of error.
399 if TZ_USER_NAME=="app" then calling:
401 tzplatform_context_getuid(context, TZ_USER_NAME)
403 will return the uid of the user 'app'
406 uid_t tzplatform_context_getuid(struct tzplatform_context *context, enum tzplatform_variable id);
409 Return the gid for a given user name, stored in variable <id>
410 Retun -1 in case of error.
413 if TZ_USER_NAME=="app" then calling:
415 tzplatform_context_getuid(context, TZ_USER_NAME)
417 will return the gid of the user 'app'
420 gid_t tzplatform_context_getgid(struct tzplatform_context *context, enum tzplatform_variable id);
424 Return 1 if given uid is in the system admin group (named "system")
426 Return -1 in case of error.
429 tzplatform_has_system_group(1000)
431 will return 0 or 1 depends on right of given uid.
434 * If you pass the -1 value to this function it will take the current uid given
435 * by the POSIX function getuid();
438 * This is a temporary feature
439 * This will be managed by Cynara
443 int tzplatform_has_system_group(uid_t uid);
449 #endif /* LIBTIZEN_PLATFORM_WRAPPER */