Fix building and minor improvements 75/28175/1
authorJosé Bollo <jose.bollo@open.eurogiciel.org>
Mon, 29 Sep 2014 14:22:53 +0000 (16:22 +0200)
committerJosé Bollo <jose.bollo@open.eurogiciel.org>
Mon, 29 Sep 2014 14:22:53 +0000 (16:22 +0200)
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 <jose.bollo@open.eurogiciel.org>
src/build.sh
src/isadmin.c
src/isadmin.h
src/static-api.c
src/tzplatform_config.h

index 2ccaa48..8f76b08 100755 (executable)
@@ -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
 
 
index c17a4c9..903ebe2 100644 (file)
 #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;
@@ -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;
 }
 
index 3e5fe0f..835f913 100644 (file)
@@ -35,7 +35,6 @@ extern "C" {
  * 
  */
 
-#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.
@@ -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
 }
index ed5007d..f259a8e 100644 (file)
@@ -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
index 6055bee..c58b468 100644 (file)
@@ -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
 }