2000-02-18 03:38:33 +08:00
|
|
|
/* grp.cc
|
|
|
|
|
* child_info.h, cygheap.h, fhandler_clipboard.cc, fhandler_dsp.cc,
fhandler_floppy.cc, fhandler_mem.cc, fhandler_random.cc,
fhandler_tape.cc, fhandler_zero.cc, grp.cc, mmap.cc, passwd.cc,
pinfo.cc, pinfo.h, pipe.cc, sec_acl.cc, sec_helper.cc, security.cc,
security.h, thread.h, uinfo.cc, include/cygwin/acl.h: Fix copyright.
2002-02-10 21:50:13 +08:00
|
|
|
Copyright 1996, 1997, 1998, 2000, 2001, 2002 Red Hat, Inc.
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
Original stubs by Jason Molenda of Cygnus Support, crash@cygnus.com
|
|
|
|
First implementation by Gunther Ebert, gunther.ebert@ixos-leipzig.de
|
|
|
|
|
|
|
|
This file is part of Cygwin.
|
|
|
|
|
|
|
|
This software is a copyrighted work licensed under the terms of the
|
|
|
|
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
|
|
|
|
details. */
|
|
|
|
|
2000-08-03 00:28:18 +08:00
|
|
|
#include "winsup.h"
|
2000-02-18 03:38:33 +08:00
|
|
|
#include <grp.h>
|
2001-05-01 02:21:48 +08:00
|
|
|
#include <wininet.h>
|
2000-02-18 03:38:33 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2000-08-30 02:59:26 +08:00
|
|
|
#include <errno.h>
|
2000-08-12 13:35:42 +08:00
|
|
|
#include "pinfo.h"
|
2001-07-27 03:22:24 +08:00
|
|
|
#include "security.h"
|
2001-04-19 05:10:15 +08:00
|
|
|
#include "fhandler.h"
|
2001-08-07 16:56:22 +08:00
|
|
|
#include "path.h"
|
2001-10-01 12:10:07 +08:00
|
|
|
#include "dtable.h"
|
2000-08-30 02:59:26 +08:00
|
|
|
#include "cygerrno.h"
|
2001-10-16 07:39:33 +08:00
|
|
|
#include "cygheap.h"
|
2001-09-10 00:52:37 +08:00
|
|
|
#include "pwdgrp.h"
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
/* Read /etc/group only once for better performance. This is done
|
|
|
|
on the first call that needs information from it. */
|
|
|
|
|
Change internal gid datatype from __gid16_t to __gid32_t
throughout.
* cygwin.din: Export new symbols chown32, fchown32, getegid32,
getgid32, getgrgid32, getgrnam32, getgroups32, initgroups32, lchown32,
setgid32, setegid32, getgrent32.
* grp.cc (grp32togrp16): New static function.
(getgrgid32): New function.
(getgrnam32): Ditto.
(getgrent32): Ditto.
(getgroups32): Change name of internal function from getgroups.
(getgroups32): New function.
(initgroups32): Ditto.
* syscalls.cc (chown32): Ditto.
(lchown32): Ditto.
(fchown32): Ditto.
(setegid32): Ditto.
(setgid32): Ditto.
* uinfo.cc (getgid32): Ditto.
(getegid32): Ditto.
* include/cygwin/grp.h: Remove declaration of getgrgid() and getgrnam().
Declare getgrgid32() and getgrnam32() instead. Declare getgid32().
2002-05-28 22:10:55 +08:00
|
|
|
static struct __group32 *group_buf; /* group contents in memory */
|
2001-09-06 12:41:59 +08:00
|
|
|
static int curr_lines;
|
|
|
|
static int max_lines;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
/* Position in the group cache */
|
|
|
|
#ifdef _MT_SAFE
|
2002-09-22 11:38:57 +08:00
|
|
|
#define grp_pos _reent_winsup ()->_grp_pos
|
2000-02-18 03:38:33 +08:00
|
|
|
#else
|
|
|
|
static int grp_pos = 0;
|
|
|
|
#endif
|
|
|
|
|
2001-09-10 00:52:37 +08:00
|
|
|
static pwdgrp_check group_state;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
static int
|
2002-06-05 19:10:15 +08:00
|
|
|
parse_grp (struct __group32 &grp, char *line)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2002-09-22 11:38:57 +08:00
|
|
|
int len = strlen (line);
|
2002-06-05 19:10:15 +08:00
|
|
|
if (line[--len] == '\r')
|
|
|
|
line[len] = '\0';
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2002-06-05 19:10:15 +08:00
|
|
|
char *dp = strchr (line, ':');
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
if (!dp)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
*dp++ = '\0';
|
2002-06-05 19:10:15 +08:00
|
|
|
grp.gr_name = line;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
grp.gr_passwd = dp;
|
|
|
|
dp = strchr (grp.gr_passwd, ':');
|
|
|
|
if (dp)
|
|
|
|
{
|
|
|
|
*dp++ = '\0';
|
|
|
|
if (!strlen (grp.gr_passwd))
|
2001-09-08 05:32:07 +08:00
|
|
|
grp.gr_passwd = NULL;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2000-07-02 01:30:35 +08:00
|
|
|
grp.gr_gid = strtol (dp, NULL, 10);
|
2000-02-18 03:38:33 +08:00
|
|
|
dp = strchr (dp, ':');
|
|
|
|
if (dp)
|
2001-09-08 05:32:07 +08:00
|
|
|
{
|
|
|
|
if (*++dp)
|
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
char *cp;
|
|
|
|
|
|
|
|
for (cp = dp; (cp = strchr (cp, ',')) != NULL; ++cp)
|
|
|
|
++i;
|
|
|
|
char **namearray = (char **) calloc (i + 2, sizeof (char *));
|
|
|
|
if (namearray)
|
|
|
|
{
|
|
|
|
i = 0;
|
|
|
|
for (cp = dp; (cp = strchr (dp, ',')) != NULL; dp = cp + 1)
|
|
|
|
{
|
|
|
|
*cp = '\0';
|
|
|
|
namearray[i++] = dp;
|
|
|
|
}
|
|
|
|
namearray[i++] = dp;
|
|
|
|
namearray[i] = NULL;
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
grp.gr_mem = namearray;
|
2001-09-08 05:32:07 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
grp.gr_mem = (char **) calloc (1, sizeof (char *));
|
|
|
|
return 1;
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read one line from /etc/group into the group cache */
|
|
|
|
static void
|
2002-06-05 19:10:15 +08:00
|
|
|
add_grp_line (char *line)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
if (curr_lines == max_lines)
|
|
|
|
{
|
|
|
|
max_lines += 10;
|
Change internal gid datatype from __gid16_t to __gid32_t
throughout.
* cygwin.din: Export new symbols chown32, fchown32, getegid32,
getgid32, getgrgid32, getgrnam32, getgroups32, initgroups32, lchown32,
setgid32, setegid32, getgrent32.
* grp.cc (grp32togrp16): New static function.
(getgrgid32): New function.
(getgrnam32): Ditto.
(getgrent32): Ditto.
(getgroups32): Change name of internal function from getgroups.
(getgroups32): New function.
(initgroups32): Ditto.
* syscalls.cc (chown32): Ditto.
(lchown32): Ditto.
(fchown32): Ditto.
(setegid32): Ditto.
(setgid32): Ditto.
* uinfo.cc (getgid32): Ditto.
(getegid32): Ditto.
* include/cygwin/grp.h: Remove declaration of getgrgid() and getgrnam().
Declare getgrgid32() and getgrnam32() instead. Declare getgid32().
2002-05-28 22:10:55 +08:00
|
|
|
group_buf = (struct __group32 *) realloc (group_buf, max_lines * sizeof (struct __group32));
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
if (parse_grp (group_buf[curr_lines], line))
|
|
|
|
curr_lines++;
|
|
|
|
}
|
|
|
|
|
2001-09-28 15:01:22 +08:00
|
|
|
class group_lock
|
|
|
|
{
|
2002-02-17 12:59:55 +08:00
|
|
|
bool armed;
|
|
|
|
static NO_COPY pthread_mutex_t mutex;
|
2001-09-28 15:01:22 +08:00
|
|
|
public:
|
2002-02-17 12:59:55 +08:00
|
|
|
group_lock (bool doit)
|
|
|
|
{
|
|
|
|
if (armed = doit)
|
|
|
|
pthread_mutex_lock (&mutex);
|
|
|
|
}
|
2001-09-28 15:23:18 +08:00
|
|
|
~group_lock ()
|
|
|
|
{
|
2002-02-17 12:59:55 +08:00
|
|
|
if (armed)
|
2001-09-28 15:23:18 +08:00
|
|
|
pthread_mutex_unlock (&mutex);
|
|
|
|
}
|
2001-09-28 15:01:22 +08:00
|
|
|
};
|
|
|
|
|
2002-02-17 12:59:55 +08:00
|
|
|
pthread_mutex_t NO_COPY group_lock::mutex = (pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER;
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
/* Cygwin internal */
|
|
|
|
/* Read in /etc/group and save contents in the group cache */
|
|
|
|
/* This sets group_in_memory_p to 1 so functions in this file can
|
|
|
|
tell that /etc/group has been read in */
|
|
|
|
/* FIXME: should be static but this is called in uinfo_init outside this
|
|
|
|
file */
|
|
|
|
void
|
|
|
|
read_etc_group ()
|
|
|
|
{
|
2002-06-05 19:10:15 +08:00
|
|
|
static pwdgrp_read gr;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2002-02-17 12:59:55 +08:00
|
|
|
group_lock here (cygwin_finished_initializing);
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2001-04-20 21:02:32 +08:00
|
|
|
/* if we got blocked by the mutex, then etc_group may have been processed */
|
|
|
|
if (group_state != uninitialized)
|
2001-09-28 15:01:22 +08:00
|
|
|
return;
|
2001-04-20 21:02:32 +08:00
|
|
|
|
|
|
|
if (group_state != initializing)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2001-04-20 21:02:32 +08:00
|
|
|
group_state = initializing;
|
2002-06-05 19:10:15 +08:00
|
|
|
if (gr.open ("/etc/group"))
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2002-06-05 19:10:15 +08:00
|
|
|
char *line;
|
|
|
|
while ((line = gr.gets ()) != NULL)
|
|
|
|
if (strlen (line))
|
|
|
|
add_grp_line (line);
|
2001-04-20 21:02:32 +08:00
|
|
|
|
2002-09-22 11:38:57 +08:00
|
|
|
group_state.set_last_modified (gr.get_fhandle (), gr.get_fname ());
|
2001-04-20 21:02:32 +08:00
|
|
|
group_state = loaded;
|
2002-06-05 19:10:15 +08:00
|
|
|
gr.close ();
|
|
|
|
debug_printf ("Read /etc/group, %d lines", curr_lines);
|
2001-04-20 21:02:32 +08:00
|
|
|
}
|
|
|
|
else /* /etc/group doesn't exist -- create default one in memory */
|
|
|
|
{
|
2002-06-05 19:10:15 +08:00
|
|
|
char group_name [UNLEN + 1];
|
|
|
|
DWORD group_name_len = UNLEN + 1;
|
2001-05-01 02:21:48 +08:00
|
|
|
char domain_name [INTERNET_MAX_HOST_NAME_LENGTH + 1];
|
|
|
|
DWORD domain_name_len = INTERNET_MAX_HOST_NAME_LENGTH + 1;
|
2001-04-20 21:02:32 +08:00
|
|
|
SID_NAME_USE acType;
|
2002-06-05 19:10:15 +08:00
|
|
|
static char linebuf [200];
|
|
|
|
|
2002-06-05 19:56:56 +08:00
|
|
|
if (wincap.has_security ())
|
2001-04-20 21:02:32 +08:00
|
|
|
{
|
2002-06-05 19:56:56 +08:00
|
|
|
HANDLE ptok;
|
|
|
|
cygsid tg;
|
|
|
|
DWORD siz;
|
|
|
|
|
2002-06-19 23:27:27 +08:00
|
|
|
if (OpenProcessToken (hMainProc, TOKEN_QUERY, &ptok))
|
2002-09-30 23:17:44 +08:00
|
|
|
{
|
2002-06-05 19:56:56 +08:00
|
|
|
if (GetTokenInformation (ptok, TokenPrimaryGroup, &tg,
|
|
|
|
sizeof tg, &siz)
|
|
|
|
&& LookupAccountSidA (NULL, tg, group_name,
|
|
|
|
&group_name_len, domain_name,
|
2002-09-30 23:17:44 +08:00
|
|
|
&domain_name_len, &acType))
|
2002-06-05 19:56:56 +08:00
|
|
|
{
|
|
|
|
char strbuf[100];
|
2002-06-05 23:43:49 +08:00
|
|
|
snprintf (linebuf, sizeof (linebuf), "%s:%s:%lu:",
|
2002-09-19 11:30:20 +08:00
|
|
|
group_name,
|
2002-06-05 19:56:56 +08:00
|
|
|
tg.string (strbuf),
|
2002-09-22 11:38:57 +08:00
|
|
|
*GetSidSubAuthority (tg,
|
|
|
|
*GetSidSubAuthorityCount (tg) - 1));
|
2002-06-05 19:56:56 +08:00
|
|
|
debug_printf ("Emulating /etc/group: %s", linebuf);
|
|
|
|
add_grp_line (linebuf);
|
|
|
|
group_state = emulated;
|
|
|
|
}
|
|
|
|
CloseHandle (ptok);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (group_state != emulated)
|
|
|
|
{
|
|
|
|
strncpy (group_name, "Administrators", sizeof (group_name));
|
|
|
|
if (!LookupAccountSidA (NULL, well_known_admins_sid, group_name,
|
|
|
|
&group_name_len, domain_name,
|
|
|
|
&domain_name_len, &acType))
|
|
|
|
{
|
|
|
|
strcpy (group_name, "unknown");
|
|
|
|
debug_printf ("Failed to get local admins group name. %E");
|
|
|
|
}
|
|
|
|
snprintf (linebuf, sizeof (linebuf), "%s::%u:", group_name,
|
|
|
|
(unsigned) DEFAULT_GID);
|
|
|
|
debug_printf ("Emulating /etc/group: %s", linebuf);
|
|
|
|
add_grp_line (linebuf);
|
|
|
|
group_state = emulated;
|
2001-04-20 21:02:32 +08:00
|
|
|
}
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2001-09-28 15:01:22 +08:00
|
|
|
return;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
Change internal gid datatype from __gid16_t to __gid32_t
throughout.
* cygwin.din: Export new symbols chown32, fchown32, getegid32,
getgid32, getgrgid32, getgrnam32, getgroups32, initgroups32, lchown32,
setgid32, setegid32, getgrent32.
* grp.cc (grp32togrp16): New static function.
(getgrgid32): New function.
(getgrnam32): Ditto.
(getgrent32): Ditto.
(getgroups32): Change name of internal function from getgroups.
(getgroups32): New function.
(initgroups32): Ditto.
* syscalls.cc (chown32): Ditto.
(lchown32): Ditto.
(fchown32): Ditto.
(setegid32): Ditto.
(setgid32): Ditto.
* uinfo.cc (getgid32): Ditto.
(getegid32): Ditto.
* include/cygwin/grp.h: Remove declaration of getgrgid() and getgrnam().
Declare getgrgid32() and getgrnam32() instead. Declare getgid32().
2002-05-28 22:10:55 +08:00
|
|
|
static
|
* (child_info.h, cygheap.h, dcrt0.cc, dir.cc, fhandler.cc, fhandler.h,
fhandler_clipboard.cc, fhandler_disk_file.cc, fhandler_dsp.cc,
fhandler_floppy.cc, fhandler_mem.cc, fhandler_random.cc,
fhandler_tape.cc, fhandler_zero.cc, grp.cc, mmap.cc, passwd.cc,
pinfo.cc, pinfo.h, pipe.cc, sec_acl.cc, sec_helper.cc, security.cc,
security.h, spawn.cc, syscalls.cc, thread.h, uinfo.cc, winsup.h):
Change usage of uid_t to __uid16_t, gid_t to __gid16_t and
off_t to __off32_t throughout. Use INVALID_UID, INVALID_GID and
INVALID_SEEK instead casting -1 to the appropriate type.
* winsup.h: Define INVALID_UID, INVALID_GID and INVALID_SEEK.
* include/cygwin/acl.h: Define internal __aclent16_t and __aclent32_t
types. Don't declare acl functions when compiling Cygwin.
* include/cygwin/grp.h: Declare getgrgid() and getgrnam() with
correct types for internal usage.
2002-02-10 21:38:51 +08:00
|
|
|
struct __group16 *
|
Change internal gid datatype from __gid16_t to __gid32_t
throughout.
* cygwin.din: Export new symbols chown32, fchown32, getegid32,
getgid32, getgrgid32, getgrnam32, getgroups32, initgroups32, lchown32,
setgid32, setegid32, getgrent32.
* grp.cc (grp32togrp16): New static function.
(getgrgid32): New function.
(getgrnam32): Ditto.
(getgrent32): Ditto.
(getgroups32): Change name of internal function from getgroups.
(getgroups32): New function.
(initgroups32): Ditto.
* syscalls.cc (chown32): Ditto.
(lchown32): Ditto.
(fchown32): Ditto.
(setegid32): Ditto.
(setgid32): Ditto.
* uinfo.cc (getgid32): Ditto.
(getegid32): Ditto.
* include/cygwin/grp.h: Remove declaration of getgrgid() and getgrnam().
Declare getgrgid32() and getgrnam32() instead. Declare getgid32().
2002-05-28 22:10:55 +08:00
|
|
|
grp32togrp16 (struct __group16 *gp16, struct __group32 *gp32)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
Change internal gid datatype from __gid16_t to __gid32_t
throughout.
* cygwin.din: Export new symbols chown32, fchown32, getegid32,
getgid32, getgrgid32, getgrnam32, getgroups32, initgroups32, lchown32,
setgid32, setegid32, getgrent32.
* grp.cc (grp32togrp16): New static function.
(getgrgid32): New function.
(getgrnam32): Ditto.
(getgrent32): Ditto.
(getgroups32): Change name of internal function from getgroups.
(getgroups32): New function.
(initgroups32): Ditto.
* syscalls.cc (chown32): Ditto.
(lchown32): Ditto.
(fchown32): Ditto.
(setegid32): Ditto.
(setgid32): Ditto.
* uinfo.cc (getgid32): Ditto.
(getegid32): Ditto.
* include/cygwin/grp.h: Remove declaration of getgrgid() and getgrnam().
Declare getgrgid32() and getgrnam32() instead. Declare getgid32().
2002-05-28 22:10:55 +08:00
|
|
|
if (!gp16 || !gp32)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* Copying the pointers is actually unnecessary. Just having the correct
|
|
|
|
return type is important. */
|
|
|
|
gp16->gr_name = gp32->gr_name;
|
|
|
|
gp16->gr_passwd = gp32->gr_passwd;
|
|
|
|
gp16->gr_gid = (__gid16_t) gp32->gr_gid; /* Not loss-free */
|
|
|
|
gp16->gr_mem = gp32->gr_mem;
|
|
|
|
|
|
|
|
return gp16;
|
|
|
|
}
|
|
|
|
|
2002-09-25 20:24:23 +08:00
|
|
|
extern "C" struct __group32 *
|
Change internal gid datatype from __gid16_t to __gid32_t
throughout.
* cygwin.din: Export new symbols chown32, fchown32, getegid32,
getgid32, getgrgid32, getgrnam32, getgroups32, initgroups32, lchown32,
setgid32, setegid32, getgrent32.
* grp.cc (grp32togrp16): New static function.
(getgrgid32): New function.
(getgrnam32): Ditto.
(getgrent32): Ditto.
(getgroups32): Change name of internal function from getgroups.
(getgroups32): New function.
(initgroups32): Ditto.
* syscalls.cc (chown32): Ditto.
(lchown32): Ditto.
(fchown32): Ditto.
(setegid32): Ditto.
(setgid32): Ditto.
* uinfo.cc (getgid32): Ditto.
(getegid32): Ditto.
* include/cygwin/grp.h: Remove declaration of getgrgid() and getgrnam().
Declare getgrgid32() and getgrnam32() instead. Declare getgid32().
2002-05-28 22:10:55 +08:00
|
|
|
getgrgid32 (__gid32_t gid)
|
|
|
|
{
|
|
|
|
struct __group32 * default_grp = NULL;
|
2001-04-20 21:02:32 +08:00
|
|
|
if (group_state <= initializing)
|
2002-09-22 11:38:57 +08:00
|
|
|
read_etc_group ();
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
for (int i = 0; i < curr_lines; i++)
|
|
|
|
{
|
|
|
|
if (group_buf[i].gr_gid == DEFAULT_GID)
|
2001-09-08 05:32:07 +08:00
|
|
|
default_grp = group_buf + i;
|
2000-02-18 03:38:33 +08:00
|
|
|
if (group_buf[i].gr_gid == gid)
|
2001-09-08 05:32:07 +08:00
|
|
|
return group_buf + i;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2002-01-22 04:51:30 +08:00
|
|
|
return allow_ntsec ? NULL : default_grp;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2002-09-25 20:24:23 +08:00
|
|
|
extern "C" struct __group16 *
|
Change internal gid datatype from __gid16_t to __gid32_t
throughout.
* cygwin.din: Export new symbols chown32, fchown32, getegid32,
getgid32, getgrgid32, getgrnam32, getgroups32, initgroups32, lchown32,
setgid32, setegid32, getgrent32.
* grp.cc (grp32togrp16): New static function.
(getgrgid32): New function.
(getgrnam32): Ditto.
(getgrent32): Ditto.
(getgroups32): Change name of internal function from getgroups.
(getgroups32): New function.
(initgroups32): Ditto.
* syscalls.cc (chown32): Ditto.
(lchown32): Ditto.
(fchown32): Ditto.
(setegid32): Ditto.
(setgid32): Ditto.
* uinfo.cc (getgid32): Ditto.
(getegid32): Ditto.
* include/cygwin/grp.h: Remove declaration of getgrgid() and getgrnam().
Declare getgrgid32() and getgrnam32() instead. Declare getgid32().
2002-05-28 22:10:55 +08:00
|
|
|
getgrgid (__gid16_t gid)
|
|
|
|
{
|
|
|
|
static struct __group16 g16;
|
|
|
|
|
|
|
|
return grp32togrp16 (&g16, getgrgid32 ((__gid32_t) gid));
|
|
|
|
}
|
|
|
|
|
2002-09-25 20:24:23 +08:00
|
|
|
extern "C" struct __group32 *
|
Change internal gid datatype from __gid16_t to __gid32_t
throughout.
* cygwin.din: Export new symbols chown32, fchown32, getegid32,
getgid32, getgrgid32, getgrnam32, getgroups32, initgroups32, lchown32,
setgid32, setegid32, getgrent32.
* grp.cc (grp32togrp16): New static function.
(getgrgid32): New function.
(getgrnam32): Ditto.
(getgrent32): Ditto.
(getgroups32): Change name of internal function from getgroups.
(getgroups32): New function.
(initgroups32): Ditto.
* syscalls.cc (chown32): Ditto.
(lchown32): Ditto.
(fchown32): Ditto.
(setegid32): Ditto.
(setgid32): Ditto.
* uinfo.cc (getgid32): Ditto.
(getegid32): Ditto.
* include/cygwin/grp.h: Remove declaration of getgrgid() and getgrnam().
Declare getgrgid32() and getgrnam32() instead. Declare getgid32().
2002-05-28 22:10:55 +08:00
|
|
|
getgrnam32 (const char *name)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2001-04-20 21:02:32 +08:00
|
|
|
if (group_state <= initializing)
|
2002-09-22 11:38:57 +08:00
|
|
|
read_etc_group ();
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
for (int i = 0; i < curr_lines; i++)
|
|
|
|
if (strcasematch (group_buf[i].gr_name, name))
|
|
|
|
return group_buf + i;
|
|
|
|
|
|
|
|
/* Didn't find requested group */
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2002-09-25 20:24:23 +08:00
|
|
|
extern "C" struct __group16 *
|
Change internal gid datatype from __gid16_t to __gid32_t
throughout.
* cygwin.din: Export new symbols chown32, fchown32, getegid32,
getgid32, getgrgid32, getgrnam32, getgroups32, initgroups32, lchown32,
setgid32, setegid32, getgrent32.
* grp.cc (grp32togrp16): New static function.
(getgrgid32): New function.
(getgrnam32): Ditto.
(getgrent32): Ditto.
(getgroups32): Change name of internal function from getgroups.
(getgroups32): New function.
(initgroups32): Ditto.
* syscalls.cc (chown32): Ditto.
(lchown32): Ditto.
(fchown32): Ditto.
(setegid32): Ditto.
(setgid32): Ditto.
* uinfo.cc (getgid32): Ditto.
(getegid32): Ditto.
* include/cygwin/grp.h: Remove declaration of getgrgid() and getgrnam().
Declare getgrgid32() and getgrnam32() instead. Declare getgid32().
2002-05-28 22:10:55 +08:00
|
|
|
getgrnam (const char *name)
|
|
|
|
{
|
|
|
|
static struct __group16 g16;
|
|
|
|
|
|
|
|
return grp32togrp16 (&g16, getgrnam32 (name));
|
|
|
|
}
|
|
|
|
|
2002-09-25 20:24:23 +08:00
|
|
|
extern "C" void
|
2002-09-22 11:38:57 +08:00
|
|
|
endgrent ()
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
grp_pos = 0;
|
|
|
|
}
|
|
|
|
|
2002-09-25 20:24:23 +08:00
|
|
|
extern "C" struct __group32 *
|
2002-09-22 11:38:57 +08:00
|
|
|
getgrent32 ()
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2001-04-20 21:02:32 +08:00
|
|
|
if (group_state <= initializing)
|
2002-09-22 11:38:57 +08:00
|
|
|
read_etc_group ();
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
if (grp_pos < curr_lines)
|
|
|
|
return group_buf + grp_pos++;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2002-09-25 20:24:23 +08:00
|
|
|
extern "C" struct __group16 *
|
2002-09-22 11:38:57 +08:00
|
|
|
getgrent ()
|
Change internal gid datatype from __gid16_t to __gid32_t
throughout.
* cygwin.din: Export new symbols chown32, fchown32, getegid32,
getgid32, getgrgid32, getgrnam32, getgroups32, initgroups32, lchown32,
setgid32, setegid32, getgrent32.
* grp.cc (grp32togrp16): New static function.
(getgrgid32): New function.
(getgrnam32): Ditto.
(getgrent32): Ditto.
(getgroups32): Change name of internal function from getgroups.
(getgroups32): New function.
(initgroups32): Ditto.
* syscalls.cc (chown32): Ditto.
(lchown32): Ditto.
(fchown32): Ditto.
(setegid32): Ditto.
(setgid32): Ditto.
* uinfo.cc (getgid32): Ditto.
(getegid32): Ditto.
* include/cygwin/grp.h: Remove declaration of getgrgid() and getgrnam().
Declare getgrgid32() and getgrnam32() instead. Declare getgid32().
2002-05-28 22:10:55 +08:00
|
|
|
{
|
|
|
|
static struct __group16 g16;
|
|
|
|
|
|
|
|
return grp32togrp16 (&g16, getgrent32 ());
|
|
|
|
}
|
|
|
|
|
2002-09-25 20:24:23 +08:00
|
|
|
extern "C" void
|
2000-02-18 03:38:33 +08:00
|
|
|
setgrent ()
|
|
|
|
{
|
|
|
|
grp_pos = 0;
|
|
|
|
}
|
|
|
|
|
2001-04-25 17:43:25 +08:00
|
|
|
/* Internal function. ONLY USE THIS INTERNALLY, NEVER `getgrent'!!! */
|
Change internal gid datatype from __gid16_t to __gid32_t
throughout.
* cygwin.din: Export new symbols chown32, fchown32, getegid32,
getgid32, getgrgid32, getgrnam32, getgroups32, initgroups32, lchown32,
setgid32, setegid32, getgrent32.
* grp.cc (grp32togrp16): New static function.
(getgrgid32): New function.
(getgrnam32): Ditto.
(getgrent32): Ditto.
(getgroups32): Change name of internal function from getgroups.
(getgroups32): New function.
(initgroups32): Ditto.
* syscalls.cc (chown32): Ditto.
(lchown32): Ditto.
(fchown32): Ditto.
(setegid32): Ditto.
(setgid32): Ditto.
* uinfo.cc (getgid32): Ditto.
(getegid32): Ditto.
* include/cygwin/grp.h: Remove declaration of getgrgid() and getgrnam().
Declare getgrgid32() and getgrnam32() instead. Declare getgid32().
2002-05-28 22:10:55 +08:00
|
|
|
struct __group32 *
|
2001-04-25 17:43:25 +08:00
|
|
|
internal_getgrent (int pos)
|
|
|
|
{
|
|
|
|
if (group_state <= initializing)
|
2002-09-22 11:38:57 +08:00
|
|
|
read_etc_group ();
|
2001-04-25 17:43:25 +08:00
|
|
|
|
|
|
|
if (pos < curr_lines)
|
|
|
|
return group_buf + pos;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
int
|
Change internal gid datatype from __gid16_t to __gid32_t
throughout.
* cygwin.din: Export new symbols chown32, fchown32, getegid32,
getgid32, getgrgid32, getgrnam32, getgroups32, initgroups32, lchown32,
setgid32, setegid32, getgrent32.
* grp.cc (grp32togrp16): New static function.
(getgrgid32): New function.
(getgrnam32): Ditto.
(getgrent32): Ditto.
(getgroups32): Change name of internal function from getgroups.
(getgroups32): New function.
(initgroups32): Ditto.
* syscalls.cc (chown32): Ditto.
(lchown32): Ditto.
(fchown32): Ditto.
(setegid32): Ditto.
(setgid32): Ditto.
* uinfo.cc (getgid32): Ditto.
(getegid32): Ditto.
* include/cygwin/grp.h: Remove declaration of getgrgid() and getgrnam().
Declare getgrgid32() and getgrnam32() instead. Declare getgid32().
2002-05-28 22:10:55 +08:00
|
|
|
getgroups32 (int gidsetsize, __gid32_t *grouplist, __gid32_t gid,
|
|
|
|
const char *username)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2001-04-16 22:02:42 +08:00
|
|
|
HANDLE hToken = NULL;
|
|
|
|
DWORD size;
|
|
|
|
int cnt = 0;
|
Change internal gid datatype from __gid16_t to __gid32_t
throughout.
* cygwin.din: Export new symbols chown32, fchown32, getegid32,
getgid32, getgrgid32, getgrnam32, getgroups32, initgroups32, lchown32,
setgid32, setegid32, getgrent32.
* grp.cc (grp32togrp16): New static function.
(getgrgid32): New function.
(getgrnam32): Ditto.
(getgrent32): Ditto.
(getgroups32): Change name of internal function from getgroups.
(getgroups32): New function.
(initgroups32): Ditto.
* syscalls.cc (chown32): Ditto.
(lchown32): Ditto.
(fchown32): Ditto.
(setegid32): Ditto.
(setgid32): Ditto.
* uinfo.cc (getgid32): Ditto.
(getegid32): Ditto.
* include/cygwin/grp.h: Remove declaration of getgrgid() and getgrnam().
Declare getgrgid32() and getgrnam32() instead. Declare getgid32().
2002-05-28 22:10:55 +08:00
|
|
|
struct __group32 *gr;
|
2001-04-16 22:02:42 +08:00
|
|
|
|
2001-04-20 21:02:32 +08:00
|
|
|
if (group_state <= initializing)
|
2002-09-22 11:38:57 +08:00
|
|
|
read_etc_group ();
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2002-11-15 03:19:39 +08:00
|
|
|
if (allow_ntsec)
|
|
|
|
{
|
|
|
|
/* If impersonated, use impersonation token. */
|
|
|
|
if (cygheap->user.issetuid ())
|
|
|
|
hToken = cygheap->user.token;
|
|
|
|
else if (!OpenProcessToken (hMainProc, TOKEN_QUERY, &hToken))
|
|
|
|
hToken = NULL;
|
|
|
|
}
|
|
|
|
if (hToken)
|
2001-04-16 22:02:42 +08:00
|
|
|
{
|
2001-04-25 17:43:25 +08:00
|
|
|
if (GetTokenInformation (hToken, TokenGroups, NULL, 0, &size)
|
2001-09-08 05:32:07 +08:00
|
|
|
|| GetLastError () == ERROR_INSUFFICIENT_BUFFER)
|
|
|
|
{
|
2001-04-25 17:43:25 +08:00
|
|
|
char buf[size];
|
|
|
|
TOKEN_GROUPS *groups = (TOKEN_GROUPS *) buf;
|
|
|
|
|
|
|
|
if (GetTokenInformation (hToken, TokenGroups, buf, size, &size))
|
2001-04-16 22:02:42 +08:00
|
|
|
{
|
2001-04-25 17:43:25 +08:00
|
|
|
cygsid sid;
|
|
|
|
|
|
|
|
for (int gidx = 0; (gr = internal_getgrent (gidx)); ++gidx)
|
* fork.cc (fork): Eliminate superfluous call to getuid().
* security.h: New define `NO_SID'. Remove declarations of functions
moved to methods into class cygsid.
(class cygsid): Declare new methods `getfromstr', `get_sid',
`getfrompw', `getfromgr', `get_rid', `get_uid', `get_gid', `string'
and new constructors and operators =, == and !=.
Declare new global cygsids `well_known_XXX_sid' substituting the
corresponding `get_XXX_sid' functions. Remove declarations of
these functions.
* sec_helper.cc (well_known_admin_sid): New global variable.
(well_known_system_sid): Ditto
(well_known_creator_owner_sid): Ditto
(well_known_world_sid): Ditto
(cygsid::string): New method, substituting `convert_sid_to_string_sid'.
(cygsid::get_sid): New method, substituting `get_sid'.
(cygsid::getfromstr): New method, substituting
`convert_string_sid_to_sid'.
(cygsid::getfrompw): New method, substituting `get_pw_sid'.
(cygsid::getfromgr): New method, substituting `get_gr_sid'.
(cygsid::get_id): New method, substituting `get_id_from_sid'.
(get_admin_sid): Eliminated.
(get_system_sid): Ditto.
(get_creator_owner_sid): Ditto.
(get_world_sid): Ditto.
* grp.cc: Use new cygsid methods and well known sids throughout.
* registry.cc: Ditto.
* sec_acl.cc: Ditto.
* security.cc: Ditto.
* shared.cc: Ditto.
* syscalls.cc (seteuid): Ditto. Eliminate redundant conditional.
* uinfo.cc (internal_getlogin): Ditto.
* spawn.cc (spawn_guts) Revert previous patch.
2001-05-16 03:23:31 +08:00
|
|
|
if (sid.getfromgr (gr))
|
2001-04-25 17:43:25 +08:00
|
|
|
for (DWORD pg = 0; pg < groups->GroupCount; ++pg)
|
2002-09-19 11:30:20 +08:00
|
|
|
if (sid == groups->Groups[pg].Sid &&
|
2002-08-02 19:00:18 +08:00
|
|
|
sid != well_known_world_sid)
|
2001-04-25 17:43:25 +08:00
|
|
|
{
|
|
|
|
if (cnt < gidsetsize)
|
|
|
|
grouplist[cnt] = gr->gr_gid;
|
|
|
|
++cnt;
|
|
|
|
if (gidsetsize && cnt > gidsetsize)
|
|
|
|
{
|
|
|
|
CloseHandle (hToken);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2001-04-16 22:02:42 +08:00
|
|
|
}
|
2001-09-08 05:32:07 +08:00
|
|
|
}
|
2001-04-25 17:43:25 +08:00
|
|
|
else
|
2001-09-08 05:32:07 +08:00
|
|
|
debug_printf ("%d = GetTokenInformation(NULL) %E", size);
|
2002-11-15 03:19:39 +08:00
|
|
|
if (hToken != cygheap->user.token)
|
|
|
|
CloseHandle (hToken);
|
2001-04-25 17:43:25 +08:00
|
|
|
if (cnt)
|
2001-09-08 05:32:07 +08:00
|
|
|
return cnt;
|
2001-04-16 22:02:42 +08:00
|
|
|
}
|
2001-04-25 17:43:25 +08:00
|
|
|
|
|
|
|
for (int gidx = 0; (gr = internal_getgrent (gidx)); ++gidx)
|
|
|
|
if (gid == gr->gr_gid)
|
|
|
|
{
|
|
|
|
if (cnt < gidsetsize)
|
|
|
|
grouplist[cnt] = gr->gr_gid;
|
|
|
|
++cnt;
|
|
|
|
if (gidsetsize && cnt > gidsetsize)
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
else if (gr->gr_mem)
|
|
|
|
for (int gi = 0; gr->gr_mem[gi]; ++gi)
|
|
|
|
if (strcasematch (username, gr->gr_mem[gi]))
|
2001-04-16 22:02:42 +08:00
|
|
|
{
|
|
|
|
if (cnt < gidsetsize)
|
2001-04-25 17:43:25 +08:00
|
|
|
grouplist[cnt] = gr->gr_gid;
|
2001-04-16 22:02:42 +08:00
|
|
|
++cnt;
|
|
|
|
if (gidsetsize && cnt > gidsetsize)
|
|
|
|
goto error;
|
|
|
|
}
|
2001-04-25 17:43:25 +08:00
|
|
|
return cnt;
|
2000-08-30 02:59:26 +08:00
|
|
|
|
|
|
|
error:
|
2000-09-05 01:52:42 +08:00
|
|
|
set_errno (EINVAL);
|
2000-08-30 02:59:26 +08:00
|
|
|
return -1;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2002-09-25 20:24:23 +08:00
|
|
|
extern "C" int
|
Change internal gid datatype from __gid16_t to __gid32_t
throughout.
* cygwin.din: Export new symbols chown32, fchown32, getegid32,
getgid32, getgrgid32, getgrnam32, getgroups32, initgroups32, lchown32,
setgid32, setegid32, getgrent32.
* grp.cc (grp32togrp16): New static function.
(getgrgid32): New function.
(getgrnam32): Ditto.
(getgrent32): Ditto.
(getgroups32): Change name of internal function from getgroups.
(getgroups32): New function.
(initgroups32): Ditto.
* syscalls.cc (chown32): Ditto.
(lchown32): Ditto.
(fchown32): Ditto.
(setegid32): Ditto.
(setgid32): Ditto.
* uinfo.cc (getgid32): Ditto.
(getegid32): Ditto.
* include/cygwin/grp.h: Remove declaration of getgrgid() and getgrnam().
Declare getgrgid32() and getgrnam32() instead. Declare getgid32().
2002-05-28 22:10:55 +08:00
|
|
|
getgroups32 (int gidsetsize, __gid32_t *grouplist)
|
|
|
|
{
|
|
|
|
return getgroups32 (gidsetsize, grouplist, myself->gid,
|
|
|
|
cygheap->user.name ());
|
|
|
|
}
|
|
|
|
|
2002-09-25 20:24:23 +08:00
|
|
|
extern "C" int
|
* (child_info.h, cygheap.h, dcrt0.cc, dir.cc, fhandler.cc, fhandler.h,
fhandler_clipboard.cc, fhandler_disk_file.cc, fhandler_dsp.cc,
fhandler_floppy.cc, fhandler_mem.cc, fhandler_random.cc,
fhandler_tape.cc, fhandler_zero.cc, grp.cc, mmap.cc, passwd.cc,
pinfo.cc, pinfo.h, pipe.cc, sec_acl.cc, sec_helper.cc, security.cc,
security.h, spawn.cc, syscalls.cc, thread.h, uinfo.cc, winsup.h):
Change usage of uid_t to __uid16_t, gid_t to __gid16_t and
off_t to __off32_t throughout. Use INVALID_UID, INVALID_GID and
INVALID_SEEK instead casting -1 to the appropriate type.
* winsup.h: Define INVALID_UID, INVALID_GID and INVALID_SEEK.
* include/cygwin/acl.h: Define internal __aclent16_t and __aclent32_t
types. Don't declare acl functions when compiling Cygwin.
* include/cygwin/grp.h: Declare getgrgid() and getgrnam() with
correct types for internal usage.
2002-02-10 21:38:51 +08:00
|
|
|
getgroups (int gidsetsize, __gid16_t *grouplist)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
Change internal gid datatype from __gid16_t to __gid32_t
throughout.
* cygwin.din: Export new symbols chown32, fchown32, getegid32,
getgid32, getgrgid32, getgrnam32, getgroups32, initgroups32, lchown32,
setgid32, setegid32, getgrent32.
* grp.cc (grp32togrp16): New static function.
(getgrgid32): New function.
(getgrnam32): Ditto.
(getgrent32): Ditto.
(getgroups32): Change name of internal function from getgroups.
(getgroups32): New function.
(initgroups32): Ditto.
* syscalls.cc (chown32): Ditto.
(lchown32): Ditto.
(fchown32): Ditto.
(setegid32): Ditto.
(setgid32): Ditto.
* uinfo.cc (getgid32): Ditto.
(getegid32): Ditto.
* include/cygwin/grp.h: Remove declaration of getgrgid() and getgrnam().
Declare getgrgid32() and getgrnam32() instead. Declare getgid32().
2002-05-28 22:10:55 +08:00
|
|
|
__gid32_t *grouplist32 = NULL;
|
|
|
|
|
|
|
|
if (gidsetsize < 0)
|
|
|
|
{
|
|
|
|
set_errno (EINVAL);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (gidsetsize > 0 && grouplist)
|
|
|
|
grouplist32 = (__gid32_t *) alloca (gidsetsize * sizeof (__gid32_t));
|
|
|
|
|
|
|
|
int ret = getgroups32 (gidsetsize, grouplist32, myself->gid,
|
|
|
|
cygheap->user.name ());
|
|
|
|
|
|
|
|
if (gidsetsize > 0 && grouplist)
|
|
|
|
for (int i = 0; i < ret; ++ i)
|
|
|
|
grouplist[i] = grouplist32[i];
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2002-09-25 20:24:23 +08:00
|
|
|
extern "C" int
|
Change internal gid datatype from __gid16_t to __gid32_t
throughout.
* cygwin.din: Export new symbols chown32, fchown32, getegid32,
getgid32, getgrgid32, getgrnam32, getgroups32, initgroups32, lchown32,
setgid32, setegid32, getgrent32.
* grp.cc (grp32togrp16): New static function.
(getgrgid32): New function.
(getgrnam32): Ditto.
(getgrent32): Ditto.
(getgroups32): Change name of internal function from getgroups.
(getgroups32): New function.
(initgroups32): Ditto.
* syscalls.cc (chown32): Ditto.
(lchown32): Ditto.
(fchown32): Ditto.
(setegid32): Ditto.
(setgid32): Ditto.
* uinfo.cc (getgid32): Ditto.
(getegid32): Ditto.
* include/cygwin/grp.h: Remove declaration of getgrgid() and getgrnam().
Declare getgrgid32() and getgrnam32() instead. Declare getgid32().
2002-05-28 22:10:55 +08:00
|
|
|
initgroups32 (const char *, __gid32_t)
|
|
|
|
{
|
2002-09-11 18:37:11 +08:00
|
|
|
if (wincap.has_security ())
|
|
|
|
cygheap->user.groups.clear_supp ();
|
Change internal gid datatype from __gid16_t to __gid32_t
throughout.
* cygwin.din: Export new symbols chown32, fchown32, getegid32,
getgid32, getgrgid32, getgrnam32, getgroups32, initgroups32, lchown32,
setgid32, setegid32, getgrent32.
* grp.cc (grp32togrp16): New static function.
(getgrgid32): New function.
(getgrnam32): Ditto.
(getgrent32): Ditto.
(getgroups32): Change name of internal function from getgroups.
(getgroups32): New function.
(initgroups32): Ditto.
* syscalls.cc (chown32): Ditto.
(lchown32): Ditto.
(fchown32): Ditto.
(setegid32): Ditto.
(setgid32): Ditto.
* uinfo.cc (getgid32): Ditto.
(getegid32): Ditto.
* include/cygwin/grp.h: Remove declaration of getgrgid() and getgrnam().
Declare getgrgid32() and getgrnam32() instead. Declare getgid32().
2002-05-28 22:10:55 +08:00
|
|
|
return 0;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2002-09-25 20:24:23 +08:00
|
|
|
extern "C" int
|
2002-09-11 18:37:11 +08:00
|
|
|
initgroups (const char * name, __gid16_t gid)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2002-09-11 18:37:11 +08:00
|
|
|
return initgroups32 (name, gid16togid32(gid));
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
2002-07-29 20:51:52 +08:00
|
|
|
|
|
|
|
/* setgroups32: standards? */
|
2002-09-25 20:24:23 +08:00
|
|
|
extern "C" int
|
2002-07-29 20:51:52 +08:00
|
|
|
setgroups32 (int ngroups, const __gid32_t *grouplist)
|
|
|
|
{
|
|
|
|
if (ngroups < 0 || (ngroups > 0 && !grouplist))
|
|
|
|
{
|
|
|
|
set_errno (EINVAL);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!wincap.has_security ())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
cygsidlist gsids (cygsidlist_alloc, ngroups);
|
|
|
|
struct __group32 *gr;
|
|
|
|
|
|
|
|
if (ngroups && !gsids.sids)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
for (int gidx = 0; gidx < ngroups; ++gidx)
|
|
|
|
{
|
|
|
|
for (int gidy = 0; gidy < gidx; gidy++)
|
|
|
|
if (grouplist[gidy] == grouplist[gidx])
|
|
|
|
goto found; /* Duplicate */
|
|
|
|
for (int gidy = 0; (gr = internal_getgrent (gidy)); ++gidy)
|
|
|
|
if (gr->gr_gid == (__gid32_t) grouplist[gidx])
|
|
|
|
{
|
|
|
|
if (gsids.addfromgr (gr))
|
|
|
|
goto found;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
debug_printf ("No sid found for gid %d", grouplist[gidx]);
|
|
|
|
gsids.free_sids ();
|
|
|
|
set_errno (EINVAL);
|
|
|
|
return -1;
|
|
|
|
found:
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
cygheap->user.groups.update_supp (gsids);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-09-25 20:24:23 +08:00
|
|
|
extern "C" int
|
2002-07-29 20:51:52 +08:00
|
|
|
setgroups (int ngroups, const __gid16_t *grouplist)
|
|
|
|
{
|
|
|
|
__gid32_t *grouplist32 = NULL;
|
|
|
|
|
|
|
|
if (ngroups > 0 && grouplist)
|
|
|
|
{
|
|
|
|
grouplist32 = (__gid32_t *) alloca (ngroups * sizeof (__gid32_t));
|
|
|
|
if (grouplist32 == NULL)
|
|
|
|
return -1;
|
|
|
|
for (int i = 0; i < ngroups; i++)
|
2002-09-19 11:30:20 +08:00
|
|
|
grouplist32[i] = grouplist[i];
|
2002-07-29 20:51:52 +08:00
|
|
|
}
|
|
|
|
return setgroups32 (ngroups, grouplist32);
|
|
|
|
}
|