Use thread-safe function 80/62280/1 submit/tizen/20160323.090119
authorMyungki Lee <mk5004.lee@samsung.com>
Tue, 15 Mar 2016 07:35:59 +0000 (16:35 +0900)
committerMyungki Lee <mk5004.lee@samsung.com>
Tue, 15 Mar 2016 07:35:59 +0000 (16:35 +0900)
Change-Id: I7e2c45a0aee9d0933b0997d5db850a1192d655c1
Signed-off-by: Myungki Lee <mk5004.lee@samsung.com>
src/isadmin.c
src/tzplatform_get.c

index 1d1d699..130f43e 100644 (file)
 
 int _has_system_group_static_(uid_t uid) {
        
-       struct passwd *userinfo = NULL;
-       struct group *systemgroupinfo = NULL;
+       struct passwd pwd, *userinfo = NULL;
+       struct group grp, *systemgroupinfo = NULL;
        const char *sysgrpname = NULL;
+       char buf[1024];
        uid_t myuid = 0;
        gid_t system_gid = 0;
        gid_t *groups = NULL;
@@ -63,7 +64,7 @@ int _has_system_group_static_(uid_t uid) {
                fprintf( stderr, "isadmin ERROR: variable TZ_SYS_ADMIN_GROUP is NULL");
                return -1;
        }
-       systemgroupinfo = getgrnam(sysgrpname);
+       getgrnam_r(sysgrpname, &grp, buf, sizeof(buf), &systemgroupinfo);
        if(systemgroupinfo == NULL) {
                fprintf( stderr, "isadmin ERROR: cannot find group named \"%s\"\n", sysgrpname);
                return -1;
@@ -73,7 +74,7 @@ int _has_system_group_static_(uid_t uid) {
        
        /* Get all the gid of the given uid */
        
-       userinfo = getpwuid(myuid);
+       getpwuid(myuid, &pwd, buf, sizeof(buf), &userinfo);
        
        /* Need to call this function now to get the number of group to make the
           malloc correctly sized */
index 4273460..b190c34 100644 (file)
@@ -57,7 +57,8 @@ int main(int argc, char **argv)
        int all = 0, not = 0, query = 0, export = 0, space = 0, list = 0, cont = 0;
        int i, n, *sel, p;
        enum tzplatform_variable id;
-       struct passwd *spw;
+       struct passwd pwd, *spw;
+       char buf[1024];
 
        /* parse args */
        while(*argv && **argv=='-') {
@@ -178,9 +179,9 @@ int main(int argc, char **argv)
        if (user) {
                for (i=0 ; '0' <= user[i] && user[i] <= '9' ; i++);
                if (user[i])
-                       spw = getpwnam(user);
+                       getpwnam_r(user, &pwd, buf, sizeof(buf), &spw);
                else
-                       spw = getpwuid((uid_t)atoi(user));
+                       getpwuid_r(user, &pwd, buf, sizeof(buf), &spw);
                if (!spw) {
                        fprintf( stderr, "error! %s isn't standing for a valid user.\n", user);
                        if (!cont)