2 * Copyright (C) 2013 Intel Corporation.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 * Stephen Clymans <stephen.clymans@open.eurogiciel.org>
24 * This source file and its associated header are present to maintain a
25 * temporary solution. We need to know if an user have the privilege for
26 * a particular action.
28 * At the end, this feature will be managed by Cynara
34 #include <sys/types.h>
40 #include "tzplatform_variables.h"
41 #include "tzplatform_config.h"
43 int _has_system_group_static_(uid_t uid) {
45 struct passwd pwd, *userinfo = NULL;
46 struct group grp, *systemgroupinfo = NULL;
47 const char *sysgrpname = NULL;
61 /* Get the gid of the group named "system" */
62 sysgrpname = tzplatform_getname(TZ_SYS_ADMIN_GROUP);
63 if(sysgrpname == NULL) {
64 fprintf( stderr, "isadmin ERROR: variable TZ_SYS_ADMIN_GROUP is NULL");
67 getgrnam_r(sysgrpname, &grp, buf, sizeof(buf), &systemgroupinfo);
68 if(systemgroupinfo == NULL) {
69 fprintf( stderr, "isadmin ERROR: cannot find group named \"%s\"\n", sysgrpname);
73 system_gid = systemgroupinfo->gr_gid;
75 /* Get all the gid of the given uid */
77 getpwuid_r(myuid, &pwd, buf, sizeof(buf), &userinfo);
79 /* Need to call this function now to get the number of group to make the
80 malloc correctly sized */
81 if (getgrouplist(userinfo->pw_name, userinfo->pw_gid, groups, &nbgroups) != -1) {
82 fprintf( stderr, "isadmin ERROR: cannot get number of groups\n");
86 groups = malloc(nbgroups * sizeof (gid_t));
88 fprintf( stderr, "isadmin ERROR: malloc cannot allocate memory\n");
92 if (getgrouplist(userinfo->pw_name, userinfo->pw_gid, groups, &nbgroups) == -1) {
94 fprintf( stderr, "isadmin ERROR: cannot get groups\n");
98 /* Check if the given uid is in the system group */
100 for(i = 0 ; i < nbgroups ; i++) {
101 if(groups[i] == system_gid) {