d ./toolbox c > hash.inc
d ./toolbox signup > signup.inc
d gcc $f -c *.c
-d ld -shared --version-script=tzplatform_config.sym -o libtzplatform-config.so buffer.o foreign.o heap.o parser.o scratch.o context.o hashing.o init.o passwd.o shared-api.o
-d gcc -o get tzplatform_get.o static-api.o -L. -ltzplatform-config
+d ld -shared --version-script=tzplatform_config.sym -o libtzplatform-shared.so buffer.o foreign.o heap.o parser.o scratch.o context.o hashing.o init.o passwd.o shared-api.o
+d ar cr libtzplatform-static.a static-api.o isadmin.o
+d gcc -o get tzplatform_get.o static-api.o -L. -ltzplatform-static -ltzplatform-shared
#include <sys/types.h>
#include <unistd.h>
#include <grp.h>
+#include <pwd.h>
#include "isadmin.h"
#include "tzplatform_variables.h"
-
-char is_admin(int uid) {
+#include "tzplatform_config.h"
+
+int _is_admin_static_(uid_t uid) {
struct passwd *userinfo = NULL;
struct group *systemgroupinfo = NULL;
+ const char *sysgrpname = NULL;
uid_t myuid = 0;
gid_t system_gid = 0;
gid_t *groups = NULL;
myuid = uid;
/* Get the gid of the group named "system" */
- systemgroupinfo = getgrnam(TZ_SYS_ADMIN_GROUP);
+ sysgrpname = tzplatform_getname(TZ_SYS_ADMIN_GROUP);
+ if(sysgrpname == NULL) {
+ fprintf( stderr, "isadmin ERROR: variable TZ_SYS_ADMIN_GROUP is NULL");
+ return -1;
+ }
+ systemgroupinfo = getgrnam(sysgrpname);
if(systemgroupinfo == NULL) {
- fprintf( stderr, "isadmin ERROR: cannot find group named \"sudo\" \n");
+ fprintf( stderr, "isadmin ERROR: cannot find group named \"%s\"\n", sysgrpname);
return -1;
}
- system_gid = admingroupinfo->gr_gid;
+ system_gid = systemgroupinfo->gr_gid;
/* Get all the gid of the given uid */
}
if (getgrouplist(userinfo->pw_name, userinfo->pw_gid, groups, &nbgroups) == -1) {
+ free(groups);
fprintf( stderr, "isadmin ERROR: cannot get groups\n");
return -1;
}
/* Check if the given uid is in the system group */
for(i = 0 ; i < nbgroups ; i++) {
- if(groups[i] == system_gid)
+ if(groups[i] == system_gid) {
+ free(groups);
return 1;
+ }
}
-
+ free(groups);
return 0;
}
*
*/
-#include <pwd.h>
/*
* Return 0 if the given uid is not in the admin group.
* Return 1 if the given uid is in the admin group.
* If you pass the -1 value to this function it will take the current uid given
* by the POSIX function getuid();
*/
-char is_admin(int uid);
+int _is_admin_static_(uid_t uid);
#ifdef __cplusplus
}
return _context_getgid_tzplatform_(id, tizen_platform_config_signup, context);
}
-char tzplatform_isadmin(uid_t uid)
+int tzplatform_isadmin(uid_t uid)
{
- return is_admin(uid);
+ return _is_admin_static_(uid);
}
#ifdef TEST