1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2004 Cluster File Systems, Inc.
6 * This file is part of Lustre, http://www.lustre.org.
8 * Lustre is free software; you can redistribute it and/or
9 * modify it under the terms of version 2 of the GNU General Public
10 * License as published by the Free Software Foundation.
12 * Lustre is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Lustre; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
35 * 0: fail to insert (found identical)
38 int insert_sort(gid_t *groups, int size, gid_t grp)
43 for (i = 0; i < size; i++) {
50 for (; i <= size; i++) {
58 int get_groups_local(uid_t uid, int *ngroups, gid_t **groups)
67 maxgroups = sysconf(_SC_NGROUPS_MAX);
68 *groups = malloc(maxgroups * sizeof(gid_t));
76 while ((gr = getgrent())) {
79 for (i = 0; gr->gr_mem[i]; i++) {
80 if (strcmp(gr->gr_mem[i], pw->pw_name))
82 size += insert_sort(*groups, size, gr->gr_gid);
85 if (size == maxgroups)
93 int main (int argc, char **argv)
102 char *pathname = "/proc/fs/lustre/mds/group_info";
105 printf("bad parameter\n");
109 ioc_data.uid = atoi(argv[1]);
111 fd = open(pathname, O_WRONLY);
114 printf("can't open device %s\n", pathname);
118 ioc_data.err = get_groups_local(ioc_data.uid, &ioc_data.ngroups, &ioc_data.groups);
120 rc = write(fd, &ioc_data, sizeof(ioc_data));
121 return (rc != sizeof(ioc_data));