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-22 13:10:20 +08:00
|
|
|
#include "sync.h"
|
|
|
|
#include "sigproc.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. */
|
|
|
|
|
2002-02-17 12:59:55 +08:00
|
|
|
static const char *etc_group NO_COPY = "/etc/group";
|
* (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
|
|
|
static struct __group16 *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
|
|
|
|
#define grp_pos _reent_winsup()->_grp_pos
|
|
|
|
#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
|
* (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
|
|
|
parse_grp (struct __group16 &grp, const char *line)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
int len = strlen(line);
|
|
|
|
char *newline = (char *) malloc (len + 1);
|
|
|
|
(void) memcpy (newline, line, len + 1);
|
|
|
|
|
|
|
|
if (newline[--len] == '\n')
|
|
|
|
newline[len] = '\0';
|
|
|
|
|
|
|
|
char *dp = strchr (newline, ':');
|
|
|
|
|
|
|
|
if (!dp)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
*dp++ = '\0';
|
|
|
|
grp.gr_name = newline;
|
|
|
|
|
|
|
|
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
|
|
|
|
add_grp_line (const char *line)
|
|
|
|
{
|
|
|
|
if (curr_lines == max_lines)
|
|
|
|
{
|
|
|
|
max_lines += 10;
|
* (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
|
|
|
group_buf = (struct __group16 *) realloc (group_buf, max_lines * sizeof (struct __group16));
|
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 ()
|
|
|
|
{
|
2001-01-28 13:51:15 +08:00
|
|
|
char linebuf [200];
|
2001-05-01 02:21:48 +08:00
|
|
|
char group_name [UNLEN + 1];
|
|
|
|
DWORD group_name_len = UNLEN + 1;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
strncpy (group_name, "Administrators", sizeof (group_name));
|
|
|
|
|
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;
|
2001-08-07 16:56:22 +08:00
|
|
|
if (max_lines) /* When rereading, free allocated memory first. */
|
2001-09-08 05:32:07 +08:00
|
|
|
{
|
2001-08-07 16:56:22 +08:00
|
|
|
for (int i = 0; i < curr_lines; ++i)
|
|
|
|
{
|
|
|
|
free (group_buf[i].gr_name);
|
|
|
|
free (group_buf[i].gr_mem);
|
|
|
|
}
|
2001-09-14 11:01:47 +08:00
|
|
|
curr_lines = 0;
|
2001-08-07 16:56:22 +08:00
|
|
|
}
|
2001-04-20 21:02:32 +08:00
|
|
|
|
|
|
|
FILE *f = fopen (etc_group, "rt");
|
|
|
|
|
|
|
|
if (f)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2001-04-20 21:02:32 +08:00
|
|
|
while (fgets (linebuf, sizeof (linebuf), f) != NULL)
|
|
|
|
{
|
|
|
|
if (strlen (linebuf))
|
|
|
|
add_grp_line (linebuf);
|
|
|
|
}
|
|
|
|
|
2001-09-10 00:52:37 +08:00
|
|
|
group_state.set_last_modified (f);
|
2001-04-20 21:02:32 +08:00
|
|
|
fclose (f);
|
|
|
|
group_state = loaded;
|
|
|
|
}
|
|
|
|
else /* /etc/group doesn't exist -- create default one in memory */
|
|
|
|
{
|
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;
|
|
|
|
debug_printf ("Emulating /etc/group");
|
|
|
|
if (! LookupAccountSidA (NULL ,
|
2001-07-16 06:40:07 +08:00
|
|
|
well_known_admins_sid,
|
2001-04-20 21:02:32 +08:00
|
|
|
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");
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2001-10-13 09:35:15 +08:00
|
|
|
snprintf (linebuf, sizeof (linebuf), "%s::%u:\n", group_name, (unsigned) DEFAULT_GID);
|
2001-04-20 21:02:32 +08:00
|
|
|
add_grp_line (linebuf);
|
|
|
|
group_state = emulated;
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
extern "C"
|
* (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 *
|
|
|
|
getgrgid (__gid16_t gid)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
* (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 * default_grp = NULL;
|
2001-04-20 21:02:32 +08:00
|
|
|
if (group_state <= initializing)
|
2000-02-18 03:38:33 +08:00
|
|
|
read_etc_group();
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
extern "C"
|
* (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 *
|
2000-02-18 03:38:33 +08:00
|
|
|
getgrnam (const char *name)
|
|
|
|
{
|
2001-04-20 21:02:32 +08:00
|
|
|
if (group_state <= initializing)
|
2000-02-18 03:38:33 +08:00
|
|
|
read_etc_group();
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C"
|
|
|
|
void
|
|
|
|
endgrent()
|
|
|
|
{
|
|
|
|
grp_pos = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C"
|
* (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 *
|
2000-02-18 03:38:33 +08:00
|
|
|
getgrent()
|
|
|
|
{
|
2001-04-20 21:02:32 +08:00
|
|
|
if (group_state <= initializing)
|
2000-02-18 03:38:33 +08:00
|
|
|
read_etc_group();
|
|
|
|
|
|
|
|
if (grp_pos < curr_lines)
|
|
|
|
return group_buf + grp_pos++;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C"
|
|
|
|
void
|
|
|
|
setgrent ()
|
|
|
|
{
|
|
|
|
grp_pos = 0;
|
|
|
|
}
|
|
|
|
|
2001-04-25 17:43:25 +08:00
|
|
|
/* Internal function. ONLY USE THIS INTERNALLY, NEVER `getgrent'!!! */
|
* (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 *
|
2001-04-25 17:43:25 +08:00
|
|
|
internal_getgrent (int pos)
|
|
|
|
{
|
|
|
|
if (group_state <= initializing)
|
|
|
|
read_etc_group();
|
|
|
|
|
|
|
|
if (pos < curr_lines)
|
|
|
|
return group_buf + pos;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
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, __gid16_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;
|
* (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 *gr;
|
2001-04-16 22:02:42 +08:00
|
|
|
|
2001-04-20 21:02:32 +08:00
|
|
|
if (group_state <= initializing)
|
2000-02-18 03:38:33 +08:00
|
|
|
read_etc_group();
|
|
|
|
|
2001-04-16 22:02:42 +08:00
|
|
|
if (allow_ntsec &&
|
2001-04-25 17:43:25 +08:00
|
|
|
OpenProcessToken (hMainProc, TOKEN_QUERY, &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)
|
|
|
|
if (sid == groups->Groups[pg].Sid)
|
|
|
|
{
|
|
|
|
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);
|
2001-04-16 22:02:42 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2000-11-15 08:13:09 +08:00
|
|
|
return getgroups (gidsetsize, grouplist, myself->gid, cygheap->user.name ());
|
2000-02-18 03:38:33 +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
|
|
|
initgroups (const char *, __gid16_t)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|