From 1c293b65be39845efaef0a4963b8e72c7cd29bd4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Bollo?= Date: Mon, 29 Sep 2014 16:22:53 +0200 Subject: [PATCH] Fix building and minor improvements MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Make the current project building and improves the name of the function to have less probability of collision with other names. Change-Id: I99d6079250404991a7022026b50262932aa7c5b1 Signed-off-by: José Bollo --- src/build.sh | 5 +++-- src/isadmin.c | 25 ++++++++++++++++++------- src/isadmin.h | 3 +-- src/static-api.c | 4 ++-- src/tzplatform_config.h | 2 +- 5 files changed, 25 insertions(+), 14 deletions(-) diff --git a/src/build.sh b/src/build.sh index 2ccaa48..8f76b08 100755 --- a/src/build.sh +++ b/src/build.sh @@ -14,7 +14,8 @@ d ./toolbox h > tzplatform_variables.h 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 diff --git a/src/isadmin.c b/src/isadmin.c index c17a4c9..903ebe2 100644 --- a/src/isadmin.c +++ b/src/isadmin.c @@ -34,14 +34,17 @@ #include #include #include +#include #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; @@ -55,13 +58,18 @@ char is_admin(int uid) { 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 */ @@ -81,6 +89,7 @@ char is_admin(int uid) { } if (getgrouplist(userinfo->pw_name, userinfo->pw_gid, groups, &nbgroups) == -1) { + free(groups); fprintf( stderr, "isadmin ERROR: cannot get groups\n"); return -1; } @@ -88,10 +97,12 @@ char is_admin(int uid) { /* 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; } diff --git a/src/isadmin.h b/src/isadmin.h index 3e5fe0f..835f913 100644 --- a/src/isadmin.h +++ b/src/isadmin.h @@ -35,7 +35,6 @@ extern "C" { * */ -#include /* * Return 0 if the given uid is not in the admin group. * Return 1 if the given uid is in the admin group. @@ -43,7 +42,7 @@ extern "C" { * 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 } diff --git a/src/static-api.c b/src/static-api.c index ed5007d..f259a8e 100644 --- a/src/static-api.c +++ b/src/static-api.c @@ -131,9 +131,9 @@ gid_t tzplatform_context_getgid(struct tzplatform_context *context, enum tzplatf 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 diff --git a/src/tzplatform_config.h b/src/tzplatform_config.h index 6055bee..c58b468 100644 --- a/src/tzplatform_config.h +++ b/src/tzplatform_config.h @@ -402,7 +402,7 @@ gid_t tzplatform_context_getgid(struct tzplatform_context *context, enum tzplatf */ extern -char tzplatform_isadmin(uid_t uid); +int tzplatform_isadmin(uid_t uid); #ifdef __cplusplus } -- 2.7.4