tzplatform_get.c \
passwd.h \
passwd.c \
- groups.h \
- groups.c
+ isadmin.h \
+ isadmin.c
d ./toolbox signup > signup.inc
d gcc $f -c *.c
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 groups.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
+++ /dev/null
-/*
- * Copyright (C) 2013 Intel Corporation.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * Authors:
- * Stephen Clymans <stephen.clymans@open.eurogiciel.org>
- */
-
- /*
- * DISCLAIMER :
- * This source file and its associated header are present to maintain a
- * temporary solution. We need to know if an user have the privilege for
- * a particular action.
- *
- * At the end, this feature will be managed by Cynara
- *
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <grp.h>
-#include <pwd.h>
-
-#include "groups.h"
-#include "tzplatform_config.h"
-
-int _has_specified_group_static_(uid_t uid, enum tzplatform_variable group) {
-
- struct passwd *userinfo = NULL;
- struct group *groupinfo = NULL;
- const char *grpname = NULL;
- uid_t myuid = 0;
- gid_t gid = 0;
- gid_t *groups = NULL;
- int i, nbgroups = 0;
-
- if (group != TZ_SYS_USER_GROUP || group != TZ_SYS_ADMIN_GROUP) {
- fprintf( stderr, "groups ERROR: group is not valid \n");
- return -1;
- }
-
- if(uid == -1)
- /* Get current uid */
- myuid = getuid();
- else
- myuid = uid;
-
- /* Get the gid of the group */
- grpname = tzplatform_getname(group);
- if(grpname == NULL) {
- fprintf( stderr, "groups ERROR: variable TZ_SYS_ADMIN_GROUP is NULL");
- return -1;
- }
- groupinfo = getgrnam(grpname);
- if(groupinfo == NULL) {
- fprintf( stderr, "groups ERROR: cannot find group named \"%s\"\n", grpname);
- return -1;
- }
-
- gid = groupinfo->gr_gid;
-
- /* Get all the gid of the given uid */
-
- userinfo = getpwuid(myuid);
-
- /* Need to call this function now to get the number of group to make the
- malloc correctly sized */
- if (getgrouplist(userinfo->pw_name, userinfo->pw_gid, groups, &nbgroups) != -1) {
- fprintf( stderr, "groups ERROR: cannot get number of groups\n");
- return -1;
- }
-
- groups = malloc(nbgroups * sizeof (gid_t));
- if (groups == NULL) {
- fprintf( stderr, "groups ERROR: malloc cannot allocate memory\n");
- return -1;
- }
-
- if (getgrouplist(userinfo->pw_name, userinfo->pw_gid, groups, &nbgroups) == -1) {
- free(groups);
- fprintf( stderr, "groups ERROR: cannot get groups\n");
- return -1;
- }
-
- /* Check if the given uid is in the specified group */
-
- for(i = 0 ; i < nbgroups ; i++) {
- if(groups[i] == gid) {
- free(groups);
- return 1;
- }
- }
- free(groups);
- return 0;
-}
-
+++ /dev/null
-/*
- * Copyright (C) 2013 Intel Corporation.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * Authors:
- * Stephen Clymans <stephen.clymans@open.eurogiciel.org>
- */
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#ifndef TIZEN_PLATFORM_WRAPPER_GROUPS_H
-#define TIZEN_PLATFORM_WRAPPER_GROUPS_H
-
-#include "tzplatform_variables.h"
-
-/*
- * This feature aims to know if a user belongs to a specified group
- */
-
-/*
- * Return 0 if the given uid is not in the specified group.
- * Return 1 if the given uid is in the specified group.
- *
- * If you pass the -1 value to this function it will take the current uid given
- * by the POSIX function getuid();
-*/
-int _has_specified_group_static_(uid_t uid, enum tzplatform_variable group);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* TIZEN_PLATFORM_WRAPPER_GROUPS_H */
-
--- /dev/null
+/*
+ * Copyright (C) 2013 Intel Corporation.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Authors:
+ * Stephen Clymans <stephen.clymans@open.eurogiciel.org>
+ */
+
+ /*
+ * DISCLAIMER :
+ * This source file and its associated header are present to maintain a
+ * temporary solution. We need to know if an user have the privilege for
+ * a particular action.
+ *
+ * At the end, this feature will be managed by Cynara
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <grp.h>
+#include <pwd.h>
+
+#include "isadmin.h"
+#include "tzplatform_variables.h"
+#include "tzplatform_config.h"
+
+int _has_system_group_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;
+ int i, nbgroups = 0;
+
+
+ if(uid == -1)
+ /* Get current uid */
+ myuid = getuid();
+ else
+ myuid = uid;
+
+ /* Get the gid of the group named "system" */
+ 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 \"%s\"\n", sysgrpname);
+ return -1;
+ }
+
+ system_gid = systemgroupinfo->gr_gid;
+
+ /* Get all the gid of the given uid */
+
+ userinfo = getpwuid(myuid);
+
+ /* Need to call this function now to get the number of group to make the
+ malloc correctly sized */
+ if (getgrouplist(userinfo->pw_name, userinfo->pw_gid, groups, &nbgroups) != -1) {
+ fprintf( stderr, "isadmin ERROR: cannot get number of groups\n");
+ return -1;
+ }
+
+ groups = malloc(nbgroups * sizeof (gid_t));
+ if (groups == NULL) {
+ fprintf( stderr, "isadmin ERROR: malloc cannot allocate memory\n");
+ return -1;
+ }
+
+ 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) {
+ free(groups);
+ return 1;
+ }
+ }
+ free(groups);
+ return 0;
+}
+
--- /dev/null
+/*
+ * Copyright (C) 2013 Intel Corporation.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Authors:
+ * Stephen Clymans <stephen.clymans@open.eurogiciel.org>
+ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef TIZEN_PLATFORM_WRAPPER_ISADMIN_H
+#define TIZEN_PLATFORM_WRAPPER_ISADMIN_H
+
+/*
+ * DISCLAIMER :
+ * This header and its associated source file are present to maintain a
+ * temporary solution. We need to know if an user have the privilege for
+ * a particular action.
+ *
+ * At the end, this feature will be managed by Cynara
+ *
+ */
+
+/*
+ * 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();
+*/
+int _has_system_group_static_(uid_t uid);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* TIZEN_PLATFORM_WRAPPER_ISADMIN_H */
+
#include "tzplatform_config.h"
#include "shared-api.h"
-#include "groups.h"
+#include "isadmin.h"
#include "signup.inc"
int tzplatform_has_system_group(uid_t uid)
{
- return _has_specified_group_static_(uid, TZ_SYS_ADMIN_GROUP);
-}
-
-int tzplatform_has_users_group(uid_t uid)
-{
- return _has_specified_group_static_(uid, TZ_SYS_USER_GROUP);
+ return _has_system_group_static_(uid);
}
#ifdef TEST
extern
int tzplatform_has_system_group(uid_t uid);
-/*
- Return 1 if given uid is in the regular users group (named "users")
- Return 0 if not
- Return -1 in case of error.
-
- Example:
- tzplatform_has_users_group(1000)
-
- will return 0 or 1 depends on right of given uid.
-
- NOTE :
- * If you pass the -1 value to this function it will take the current uid given
- * by the POSIX function getuid();
-*/
-extern
-int tzplatform_has_users_group(uid_t uid);
-
#ifdef __cplusplus
}
#endif