2000-02-18 03:38:33 +08:00
|
|
|
/* grp.cc
|
|
|
|
|
|
|
|
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"
|
2014-02-17 23:36:33 +08:00
|
|
|
#include <lm.h>
|
2015-02-24 04:51:12 +08:00
|
|
|
#include <ntsecapi.h>
|
2011-10-28 17:26:42 +08:00
|
|
|
#include <assert.h>
|
2000-02-18 03:38:33 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2005-01-13 06:40:46 +08:00
|
|
|
#include "cygerrno.h"
|
2000-08-12 13:35:42 +08:00
|
|
|
#include "pinfo.h"
|
2001-08-07 16:56:22 +08:00
|
|
|
#include "path.h"
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 08:37:18 +08:00
|
|
|
#include "fhandler.h"
|
2001-10-01 12:10:07 +08:00
|
|
|
#include "dtable.h"
|
2001-10-16 07:39:33 +08:00
|
|
|
#include "cygheap.h"
|
2011-04-29 15:34:05 +08:00
|
|
|
#include "ntdll.h"
|
2014-02-17 23:36:33 +08:00
|
|
|
#include "miscfuncs.h"
|
|
|
|
#include "ldap.h"
|
|
|
|
#include "tls_pbuf.h"
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2013-04-23 17:44:36 +08:00
|
|
|
static char * NO_COPY_RO null_ptr;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2003-01-20 10:57:54 +08:00
|
|
|
bool
|
2003-01-24 11:53:46 +08:00
|
|
|
pwdgrp::parse_group ()
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2014-02-10 03:44:56 +08:00
|
|
|
pg_grp &grp = group ()[curr_lines];
|
|
|
|
grp.g.gr_name = next_str (':');
|
|
|
|
if (!*grp.g.gr_name)
|
2003-01-24 11:53:46 +08:00
|
|
|
return false;
|
2014-02-10 03:44:56 +08:00
|
|
|
grp.g.gr_passwd = next_str (':');
|
2014-05-07 19:00:00 +08:00
|
|
|
/* Note that lptr points to the first byte of the gr_gid field.
|
|
|
|
We deliberately ignore the gr_gid and gr_mem entries when copying
|
|
|
|
the buffer content since they are not referenced anymore. */
|
|
|
|
grp.len = lptr - grp.g.gr_name;
|
2014-02-10 03:44:56 +08:00
|
|
|
if (!next_num (grp.g.gr_gid))
|
2003-01-26 13:38:38 +08:00
|
|
|
return false;
|
2014-05-07 19:00:00 +08:00
|
|
|
/* Don't generate gr_mem entries. */
|
2014-02-10 03:44:56 +08:00
|
|
|
grp.g.gr_mem = &null_ptr;
|
2015-04-17 17:56:15 +08:00
|
|
|
cygsid csid;
|
2015-12-16 19:25:27 +08:00
|
|
|
if (csid.getfromgr_passwd (&grp.g))
|
|
|
|
RtlCopySid (SECURITY_MAX_SID_SIZE, grp.sid, csid);
|
2003-01-26 13:38:38 +08:00
|
|
|
return true;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2014-02-10 03:44:56 +08:00
|
|
|
muto NO_COPY pwdgrp::pglock;
|
|
|
|
|
2003-01-21 14:58:11 +08:00
|
|
|
void
|
2014-02-10 03:44:56 +08:00
|
|
|
pwdgrp::init_grp ()
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2014-02-10 03:44:56 +08:00
|
|
|
pwdgrp_buf_elem_size = sizeof (pg_grp);
|
|
|
|
parse = &pwdgrp::parse_group;
|
|
|
|
}
|
2003-01-21 14:58:11 +08:00
|
|
|
|
2014-02-10 03:44:56 +08:00
|
|
|
struct group *
|
|
|
|
pwdgrp::find_group (cygpsid &sid)
|
|
|
|
{
|
|
|
|
for (ULONG i = 0; i < curr_lines; i++)
|
|
|
|
if (sid == group ()[i].sid)
|
|
|
|
return &group ()[i].g;
|
|
|
|
return NULL;
|
|
|
|
}
|
2005-04-05 14:04:57 +08:00
|
|
|
|
2014-02-10 03:44:56 +08:00
|
|
|
struct group *
|
|
|
|
pwdgrp::find_group (const char *name)
|
2003-04-18 04:05:15 +08:00
|
|
|
{
|
2014-02-10 03:44:56 +08:00
|
|
|
for (ULONG i = 0; i < curr_lines; i++)
|
|
|
|
if (strcasematch (group ()[i].g.gr_name, name))
|
|
|
|
return &group ()[i].g;
|
|
|
|
return NULL;
|
2003-04-18 04:05:15 +08:00
|
|
|
}
|
|
|
|
|
2014-02-10 03:44:56 +08:00
|
|
|
struct group *
|
|
|
|
pwdgrp::find_group (gid_t gid)
|
2003-04-18 04:05:15 +08:00
|
|
|
{
|
2014-02-10 03:44:56 +08:00
|
|
|
for (ULONG i = 0; i < curr_lines; i++)
|
|
|
|
if (gid == group ()[i].g.gr_gid)
|
|
|
|
return &group ()[i].g;
|
|
|
|
return NULL;
|
2003-04-18 04:05:15 +08:00
|
|
|
}
|
|
|
|
|
2013-04-23 17:44:36 +08:00
|
|
|
struct group *
|
2014-02-27 20:57:27 +08:00
|
|
|
internal_getgrsid (cygpsid &sid, cyg_ldap *pldap)
|
2002-11-21 01:10:05 +08:00
|
|
|
{
|
2014-02-10 03:44:56 +08:00
|
|
|
struct group *ret;
|
2002-11-21 01:10:05 +08:00
|
|
|
|
2014-02-10 03:44:56 +08:00
|
|
|
cygheap->pg.nss_init ();
|
2014-03-13 01:36:56 +08:00
|
|
|
/* Check caches first. */
|
|
|
|
if (cygheap->pg.nss_cygserver_caching ()
|
|
|
|
&& (ret = cygheap->pg.grp_cache.cygserver.find_group (sid)))
|
|
|
|
return ret;
|
|
|
|
if (cygheap->pg.nss_grp_files ()
|
|
|
|
&& (ret = cygheap->pg.grp_cache.file.find_group (sid)))
|
|
|
|
return ret;
|
|
|
|
if (cygheap->pg.nss_grp_db ()
|
|
|
|
&& (ret = cygheap->pg.grp_cache.win.find_group (sid)))
|
|
|
|
return ret;
|
|
|
|
/* Ask sources afterwards. */
|
|
|
|
if (cygheap->pg.nss_cygserver_caching ()
|
|
|
|
&& (ret = cygheap->pg.grp_cache.cygserver.add_group_from_cygserver (sid)))
|
|
|
|
return ret;
|
2014-02-10 03:44:56 +08:00
|
|
|
if (cygheap->pg.nss_grp_files ())
|
|
|
|
{
|
2014-03-08 04:38:48 +08:00
|
|
|
cygheap->pg.grp_cache.file.check_file ();
|
2014-02-10 03:44:56 +08:00
|
|
|
if ((ret = cygheap->pg.grp_cache.file.add_group_from_file (sid)))
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
if (cygheap->pg.nss_grp_db ())
|
2014-03-13 01:36:56 +08:00
|
|
|
return cygheap->pg.grp_cache.win.add_group_from_windows (sid, pldap);
|
2002-11-21 01:10:05 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-02-24 04:51:12 +08:00
|
|
|
/* Like internal_getgrsid but return only already cached data,
|
|
|
|
NULL otherwise. */
|
|
|
|
static struct group *
|
|
|
|
internal_getgrsid_cachedonly (cygpsid &sid)
|
|
|
|
{
|
|
|
|
struct group *ret;
|
|
|
|
|
|
|
|
/* Check caches only. */
|
|
|
|
if (cygheap->pg.nss_cygserver_caching ()
|
|
|
|
&& (ret = cygheap->pg.grp_cache.cygserver.find_group (sid)))
|
|
|
|
return ret;
|
|
|
|
if (cygheap->pg.nss_grp_files ()
|
|
|
|
&& (ret = cygheap->pg.grp_cache.file.find_group (sid)))
|
|
|
|
return ret;
|
|
|
|
if (cygheap->pg.nss_grp_db ()
|
|
|
|
&& (ret = cygheap->pg.grp_cache.win.find_group (sid)))
|
|
|
|
return ret;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Called from internal_getgroups. The full information required to create
|
|
|
|
a group account entry is already available from the LookupAccountSids
|
|
|
|
call. internal_getgrfull passes all available info into
|
|
|
|
pwdgrp::fetch_account_from_line, thus avoiding a LookupAccountSid call
|
|
|
|
for each group. This is quite a bit faster, especially in slower
|
|
|
|
environments. */
|
|
|
|
static struct group * __attribute__((used))
|
2015-02-25 04:52:57 +08:00
|
|
|
internal_getgrfull (fetch_acc_t &full_acc, cyg_ldap *pldap)
|
2015-02-24 04:51:12 +08:00
|
|
|
{
|
|
|
|
struct group *ret;
|
|
|
|
|
|
|
|
cygheap->pg.nss_init ();
|
2015-08-18 04:45:02 +08:00
|
|
|
/* Skip local caches, internal_getgroups already called
|
|
|
|
internal_getgrsid_cachedonly. */
|
2015-02-24 04:51:12 +08:00
|
|
|
if (cygheap->pg.nss_cygserver_caching ()
|
|
|
|
&& (ret = cygheap->pg.grp_cache.cygserver.add_group_from_cygserver
|
2015-02-25 04:52:57 +08:00
|
|
|
(full_acc.sid)))
|
2015-02-24 04:51:12 +08:00
|
|
|
return ret;
|
|
|
|
if (cygheap->pg.nss_grp_files ())
|
|
|
|
{
|
|
|
|
cygheap->pg.grp_cache.file.check_file ();
|
|
|
|
if ((ret = cygheap->pg.grp_cache.file.add_group_from_file
|
2015-02-25 04:52:57 +08:00
|
|
|
(full_acc.sid)))
|
2015-02-24 04:51:12 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
if (cygheap->pg.nss_grp_db ())
|
2015-02-25 04:52:57 +08:00
|
|
|
return cygheap->pg.grp_cache.win.add_group_from_windows (full_acc, pldap);
|
2015-02-24 04:51:12 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-02-23 03:38:12 +08:00
|
|
|
/* This function gets only called from mkgroup via cygwin_internal. */
|
|
|
|
struct group *
|
|
|
|
internal_getgrsid_from_db (cygpsid &sid)
|
|
|
|
{
|
|
|
|
cygheap->pg.nss_init ();
|
|
|
|
return cygheap->pg.grp_cache.win.add_group_from_windows (sid);
|
|
|
|
}
|
|
|
|
|
2013-04-23 17:44:36 +08:00
|
|
|
struct group *
|
2014-02-27 20:57:27 +08:00
|
|
|
internal_getgrnam (const char *name, cyg_ldap *pldap)
|
2002-12-10 Pierre Humblet <pierre.humblet@ieee.org>
* pwdgrp.h (pwdgrp_check::pwdgrp_state): Replace by
pwdgrp_check::isinitializing ().
(pwdgrp_check::isinitializing): Create.
* passwd.cc (grab_int): Change type to unsigned, use strtoul and
set the pointer content to 0 if the field is invalid.
(parse_pwd): Move validity test after getting pw_gid.
(read_etc_passwd): Replace "passwd_state <= " by
passwd_state::isinitializing ().
(internal_getpwuid): Ditto.
(internal_getpwnam): Ditto.
(getpwent): Ditto.
(getpass): Ditto.
* grp.cc (parse_grp): Use strtoul for gr_gid and verify the validity.
(read_etc_group): Replace "group_state <= " by
group_state::isinitializing ().
(internal_getgrgid): Ditto.
(getgrent32): Ditto.
(internal_getgrent): Ditto.
2002-12-10 Pierre Humblet <pierre.humblet@ieee.org>
* security.h: Move declarations of internal_getgrent,
internal_getpwsid and internal_getgrsid to pwdgrp.h.
* pwdgrp.h: Declare internal_getpwsid, internal_getpwnam,
internal_getpwuid, internal_getgrsid, internal_getgrgid,
internal_getgrnam, internal_getgrent and internal_getgroups.
Delete "emulated" from enum pwdgrp_state.
(pwdgrp_check::isuninitialized): Create.
(pwdgrp_check::pwdgrp_state): Change state to initializing
rather than to uninitialized.
(pwdgrp_read::gets): Remove trailing CRs.
* passwd.cc (grab_string): Don't look for NLs.
(grab_int): Ditto.
(parse_pwd): Don't look for CRs. Return 0 if entry is too short.
(search_for): Delete.
(read_etc_passwd): Simplify tests to actually read the file.
Set state to loaded before making internal_getpwXX calls.
Replace search_for calls by equivalent internal_pwgetXX calls.
(internal_getpwsid): Use passwd_state.isuninitialized to decide
to call read_etc_passwd.
(internal_getpwuid): Create.
(internal_getpwnam): Create.
(getpwuid32): Simply call internal_getpwuid.
(getpwuid_r32): Call internal_getpwuid.
(getpwnam): Simply call internal_getpwnam.
(getpwnam_r): Call internal_getpwnam.
* grp.cc (parse_grp): Don't look for CRs. Adjust blank space.
(add_grp_line): Adjust blank space.
(class group_lock): Ditto.
(read_etc_group): Simplify tests to actually read the file.
Set state to loaded before making internal_getgrXX calls.
Replace getgrXX calls by equivalent internal calls.
(internal_getgrsid): Use group_state.isuninitialized to decide
to call read_etc_group.
(internal_getgrgid): Create.
(internal_getgrnam): Create.
(getgroups32): Simply call internal_getgrgid.
(getgrnam32): Simply call internal_getgrnam.
(internal_getgrent): Call group_state.isuninitialized.
(internal_getgroups): Create from the former getgroups32, using
two of the four arguments. Set gid to myself->gid and username
to cygheap->user.name ().
(getgroups32): Simply call internal_getgroup.
(getgroups): Call internal_getgroup instead of getgroups32.
(setgroups32): Call internal versions of get{pw,gr}XX.
* sec_helper.cc: Include pwdgrp.h.
(is_grp_member): Call internal versions of get{pw,gr}XX.
* security.cc: Include pwdgrp.h.
(alloc_sd): Call internal versions of get{pw,gr}XX.
* syscalls.cc: Include pwdgrp.h.
(seteuid32): Call internal versions of get{pw,gr}XX.
(setegid32): Ditto.
* uinfo.cc: Include pwdgrp.h.
(internal_getlogin): Call internal versions of get{pw,gr}XX.
(cygheap_user::ontherange): Ditto.
* sec_acl.cc: Include pwdgrp.h.
(setacl): Call internal versions of get{pw,gr}XX.
(acl_access): Ditto and simplify logic.
(aclfromtext): Ditto.
2002-12-10 20:43:49 +08:00
|
|
|
{
|
2014-02-10 03:44:56 +08:00
|
|
|
struct group *ret;
|
2002-12-10 Pierre Humblet <pierre.humblet@ieee.org>
* pwdgrp.h (pwdgrp_check::pwdgrp_state): Replace by
pwdgrp_check::isinitializing ().
(pwdgrp_check::isinitializing): Create.
* passwd.cc (grab_int): Change type to unsigned, use strtoul and
set the pointer content to 0 if the field is invalid.
(parse_pwd): Move validity test after getting pw_gid.
(read_etc_passwd): Replace "passwd_state <= " by
passwd_state::isinitializing ().
(internal_getpwuid): Ditto.
(internal_getpwnam): Ditto.
(getpwent): Ditto.
(getpass): Ditto.
* grp.cc (parse_grp): Use strtoul for gr_gid and verify the validity.
(read_etc_group): Replace "group_state <= " by
group_state::isinitializing ().
(internal_getgrgid): Ditto.
(getgrent32): Ditto.
(internal_getgrent): Ditto.
2002-12-10 Pierre Humblet <pierre.humblet@ieee.org>
* security.h: Move declarations of internal_getgrent,
internal_getpwsid and internal_getgrsid to pwdgrp.h.
* pwdgrp.h: Declare internal_getpwsid, internal_getpwnam,
internal_getpwuid, internal_getgrsid, internal_getgrgid,
internal_getgrnam, internal_getgrent and internal_getgroups.
Delete "emulated" from enum pwdgrp_state.
(pwdgrp_check::isuninitialized): Create.
(pwdgrp_check::pwdgrp_state): Change state to initializing
rather than to uninitialized.
(pwdgrp_read::gets): Remove trailing CRs.
* passwd.cc (grab_string): Don't look for NLs.
(grab_int): Ditto.
(parse_pwd): Don't look for CRs. Return 0 if entry is too short.
(search_for): Delete.
(read_etc_passwd): Simplify tests to actually read the file.
Set state to loaded before making internal_getpwXX calls.
Replace search_for calls by equivalent internal_pwgetXX calls.
(internal_getpwsid): Use passwd_state.isuninitialized to decide
to call read_etc_passwd.
(internal_getpwuid): Create.
(internal_getpwnam): Create.
(getpwuid32): Simply call internal_getpwuid.
(getpwuid_r32): Call internal_getpwuid.
(getpwnam): Simply call internal_getpwnam.
(getpwnam_r): Call internal_getpwnam.
* grp.cc (parse_grp): Don't look for CRs. Adjust blank space.
(add_grp_line): Adjust blank space.
(class group_lock): Ditto.
(read_etc_group): Simplify tests to actually read the file.
Set state to loaded before making internal_getgrXX calls.
Replace getgrXX calls by equivalent internal calls.
(internal_getgrsid): Use group_state.isuninitialized to decide
to call read_etc_group.
(internal_getgrgid): Create.
(internal_getgrnam): Create.
(getgroups32): Simply call internal_getgrgid.
(getgrnam32): Simply call internal_getgrnam.
(internal_getgrent): Call group_state.isuninitialized.
(internal_getgroups): Create from the former getgroups32, using
two of the four arguments. Set gid to myself->gid and username
to cygheap->user.name ().
(getgroups32): Simply call internal_getgroup.
(getgroups): Call internal_getgroup instead of getgroups32.
(setgroups32): Call internal versions of get{pw,gr}XX.
* sec_helper.cc: Include pwdgrp.h.
(is_grp_member): Call internal versions of get{pw,gr}XX.
* security.cc: Include pwdgrp.h.
(alloc_sd): Call internal versions of get{pw,gr}XX.
* syscalls.cc: Include pwdgrp.h.
(seteuid32): Call internal versions of get{pw,gr}XX.
(setegid32): Ditto.
* uinfo.cc: Include pwdgrp.h.
(internal_getlogin): Call internal versions of get{pw,gr}XX.
(cygheap_user::ontherange): Ditto.
* sec_acl.cc: Include pwdgrp.h.
(setacl): Call internal versions of get{pw,gr}XX.
(acl_access): Ditto and simplify logic.
(aclfromtext): Ditto.
2002-12-10 20:43:49 +08:00
|
|
|
|
2014-02-10 03:44:56 +08:00
|
|
|
cygheap->pg.nss_init ();
|
2014-03-13 01:36:56 +08:00
|
|
|
/* Check caches first. */
|
|
|
|
if (cygheap->pg.nss_cygserver_caching ()
|
|
|
|
&& (ret = cygheap->pg.grp_cache.cygserver.find_group (name)))
|
|
|
|
return ret;
|
|
|
|
if (cygheap->pg.nss_grp_files ()
|
|
|
|
&& (ret = cygheap->pg.grp_cache.file.find_group (name)))
|
|
|
|
return ret;
|
|
|
|
if (cygheap->pg.nss_grp_db ()
|
|
|
|
&& (ret = cygheap->pg.grp_cache.win.find_group (name)))
|
|
|
|
return ret;
|
|
|
|
/* Ask sources afterwards. */
|
|
|
|
if (cygheap->pg.nss_cygserver_caching ()
|
|
|
|
&& (ret = cygheap->pg.grp_cache.cygserver.add_group_from_cygserver (name)))
|
|
|
|
return ret;
|
2014-02-10 03:44:56 +08:00
|
|
|
if (cygheap->pg.nss_grp_files ())
|
|
|
|
{
|
2014-03-08 04:38:48 +08:00
|
|
|
cygheap->pg.grp_cache.file.check_file ();
|
2014-02-10 03:44:56 +08:00
|
|
|
if ((ret = cygheap->pg.grp_cache.file.add_group_from_file (name)))
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
if (cygheap->pg.nss_grp_db ())
|
2014-03-13 01:36:56 +08:00
|
|
|
return cygheap->pg.grp_cache.win.add_group_from_windows (name, pldap);
|
2003-01-17 13:18:30 +08:00
|
|
|
return NULL;
|
2002-12-10 Pierre Humblet <pierre.humblet@ieee.org>
* pwdgrp.h (pwdgrp_check::pwdgrp_state): Replace by
pwdgrp_check::isinitializing ().
(pwdgrp_check::isinitializing): Create.
* passwd.cc (grab_int): Change type to unsigned, use strtoul and
set the pointer content to 0 if the field is invalid.
(parse_pwd): Move validity test after getting pw_gid.
(read_etc_passwd): Replace "passwd_state <= " by
passwd_state::isinitializing ().
(internal_getpwuid): Ditto.
(internal_getpwnam): Ditto.
(getpwent): Ditto.
(getpass): Ditto.
* grp.cc (parse_grp): Use strtoul for gr_gid and verify the validity.
(read_etc_group): Replace "group_state <= " by
group_state::isinitializing ().
(internal_getgrgid): Ditto.
(getgrent32): Ditto.
(internal_getgrent): Ditto.
2002-12-10 Pierre Humblet <pierre.humblet@ieee.org>
* security.h: Move declarations of internal_getgrent,
internal_getpwsid and internal_getgrsid to pwdgrp.h.
* pwdgrp.h: Declare internal_getpwsid, internal_getpwnam,
internal_getpwuid, internal_getgrsid, internal_getgrgid,
internal_getgrnam, internal_getgrent and internal_getgroups.
Delete "emulated" from enum pwdgrp_state.
(pwdgrp_check::isuninitialized): Create.
(pwdgrp_check::pwdgrp_state): Change state to initializing
rather than to uninitialized.
(pwdgrp_read::gets): Remove trailing CRs.
* passwd.cc (grab_string): Don't look for NLs.
(grab_int): Ditto.
(parse_pwd): Don't look for CRs. Return 0 if entry is too short.
(search_for): Delete.
(read_etc_passwd): Simplify tests to actually read the file.
Set state to loaded before making internal_getpwXX calls.
Replace search_for calls by equivalent internal_pwgetXX calls.
(internal_getpwsid): Use passwd_state.isuninitialized to decide
to call read_etc_passwd.
(internal_getpwuid): Create.
(internal_getpwnam): Create.
(getpwuid32): Simply call internal_getpwuid.
(getpwuid_r32): Call internal_getpwuid.
(getpwnam): Simply call internal_getpwnam.
(getpwnam_r): Call internal_getpwnam.
* grp.cc (parse_grp): Don't look for CRs. Adjust blank space.
(add_grp_line): Adjust blank space.
(class group_lock): Ditto.
(read_etc_group): Simplify tests to actually read the file.
Set state to loaded before making internal_getgrXX calls.
Replace getgrXX calls by equivalent internal calls.
(internal_getgrsid): Use group_state.isuninitialized to decide
to call read_etc_group.
(internal_getgrgid): Create.
(internal_getgrnam): Create.
(getgroups32): Simply call internal_getgrgid.
(getgrnam32): Simply call internal_getgrnam.
(internal_getgrent): Call group_state.isuninitialized.
(internal_getgroups): Create from the former getgroups32, using
two of the four arguments. Set gid to myself->gid and username
to cygheap->user.name ().
(getgroups32): Simply call internal_getgroup.
(getgroups): Call internal_getgroup instead of getgroups32.
(setgroups32): Call internal versions of get{pw,gr}XX.
* sec_helper.cc: Include pwdgrp.h.
(is_grp_member): Call internal versions of get{pw,gr}XX.
* security.cc: Include pwdgrp.h.
(alloc_sd): Call internal versions of get{pw,gr}XX.
* syscalls.cc: Include pwdgrp.h.
(seteuid32): Call internal versions of get{pw,gr}XX.
(setegid32): Ditto.
* uinfo.cc: Include pwdgrp.h.
(internal_getlogin): Call internal versions of get{pw,gr}XX.
(cygheap_user::ontherange): Ditto.
* sec_acl.cc: Include pwdgrp.h.
(setacl): Call internal versions of get{pw,gr}XX.
(acl_access): Ditto and simplify logic.
(aclfromtext): Ditto.
2002-12-10 20:43:49 +08:00
|
|
|
}
|
|
|
|
|
2013-04-23 17:44:36 +08:00
|
|
|
struct group *
|
2014-02-27 20:57:27 +08:00
|
|
|
internal_getgrgid (gid_t gid, cyg_ldap *pldap)
|
2002-12-10 Pierre Humblet <pierre.humblet@ieee.org>
* pwdgrp.h (pwdgrp_check::pwdgrp_state): Replace by
pwdgrp_check::isinitializing ().
(pwdgrp_check::isinitializing): Create.
* passwd.cc (grab_int): Change type to unsigned, use strtoul and
set the pointer content to 0 if the field is invalid.
(parse_pwd): Move validity test after getting pw_gid.
(read_etc_passwd): Replace "passwd_state <= " by
passwd_state::isinitializing ().
(internal_getpwuid): Ditto.
(internal_getpwnam): Ditto.
(getpwent): Ditto.
(getpass): Ditto.
* grp.cc (parse_grp): Use strtoul for gr_gid and verify the validity.
(read_etc_group): Replace "group_state <= " by
group_state::isinitializing ().
(internal_getgrgid): Ditto.
(getgrent32): Ditto.
(internal_getgrent): Ditto.
2002-12-10 Pierre Humblet <pierre.humblet@ieee.org>
* security.h: Move declarations of internal_getgrent,
internal_getpwsid and internal_getgrsid to pwdgrp.h.
* pwdgrp.h: Declare internal_getpwsid, internal_getpwnam,
internal_getpwuid, internal_getgrsid, internal_getgrgid,
internal_getgrnam, internal_getgrent and internal_getgroups.
Delete "emulated" from enum pwdgrp_state.
(pwdgrp_check::isuninitialized): Create.
(pwdgrp_check::pwdgrp_state): Change state to initializing
rather than to uninitialized.
(pwdgrp_read::gets): Remove trailing CRs.
* passwd.cc (grab_string): Don't look for NLs.
(grab_int): Ditto.
(parse_pwd): Don't look for CRs. Return 0 if entry is too short.
(search_for): Delete.
(read_etc_passwd): Simplify tests to actually read the file.
Set state to loaded before making internal_getpwXX calls.
Replace search_for calls by equivalent internal_pwgetXX calls.
(internal_getpwsid): Use passwd_state.isuninitialized to decide
to call read_etc_passwd.
(internal_getpwuid): Create.
(internal_getpwnam): Create.
(getpwuid32): Simply call internal_getpwuid.
(getpwuid_r32): Call internal_getpwuid.
(getpwnam): Simply call internal_getpwnam.
(getpwnam_r): Call internal_getpwnam.
* grp.cc (parse_grp): Don't look for CRs. Adjust blank space.
(add_grp_line): Adjust blank space.
(class group_lock): Ditto.
(read_etc_group): Simplify tests to actually read the file.
Set state to loaded before making internal_getgrXX calls.
Replace getgrXX calls by equivalent internal calls.
(internal_getgrsid): Use group_state.isuninitialized to decide
to call read_etc_group.
(internal_getgrgid): Create.
(internal_getgrnam): Create.
(getgroups32): Simply call internal_getgrgid.
(getgrnam32): Simply call internal_getgrnam.
(internal_getgrent): Call group_state.isuninitialized.
(internal_getgroups): Create from the former getgroups32, using
two of the four arguments. Set gid to myself->gid and username
to cygheap->user.name ().
(getgroups32): Simply call internal_getgroup.
(getgroups): Call internal_getgroup instead of getgroups32.
(setgroups32): Call internal versions of get{pw,gr}XX.
* sec_helper.cc: Include pwdgrp.h.
(is_grp_member): Call internal versions of get{pw,gr}XX.
* security.cc: Include pwdgrp.h.
(alloc_sd): Call internal versions of get{pw,gr}XX.
* syscalls.cc: Include pwdgrp.h.
(seteuid32): Call internal versions of get{pw,gr}XX.
(setegid32): Ditto.
* uinfo.cc: Include pwdgrp.h.
(internal_getlogin): Call internal versions of get{pw,gr}XX.
(cygheap_user::ontherange): Ditto.
* sec_acl.cc: Include pwdgrp.h.
(setacl): Call internal versions of get{pw,gr}XX.
(acl_access): Ditto and simplify logic.
(aclfromtext): Ditto.
2002-12-10 20:43:49 +08:00
|
|
|
{
|
2014-02-10 03:44:56 +08:00
|
|
|
struct group *ret;
|
2002-12-10 Pierre Humblet <pierre.humblet@ieee.org>
* pwdgrp.h (pwdgrp_check::pwdgrp_state): Replace by
pwdgrp_check::isinitializing ().
(pwdgrp_check::isinitializing): Create.
* passwd.cc (grab_int): Change type to unsigned, use strtoul and
set the pointer content to 0 if the field is invalid.
(parse_pwd): Move validity test after getting pw_gid.
(read_etc_passwd): Replace "passwd_state <= " by
passwd_state::isinitializing ().
(internal_getpwuid): Ditto.
(internal_getpwnam): Ditto.
(getpwent): Ditto.
(getpass): Ditto.
* grp.cc (parse_grp): Use strtoul for gr_gid and verify the validity.
(read_etc_group): Replace "group_state <= " by
group_state::isinitializing ().
(internal_getgrgid): Ditto.
(getgrent32): Ditto.
(internal_getgrent): Ditto.
2002-12-10 Pierre Humblet <pierre.humblet@ieee.org>
* security.h: Move declarations of internal_getgrent,
internal_getpwsid and internal_getgrsid to pwdgrp.h.
* pwdgrp.h: Declare internal_getpwsid, internal_getpwnam,
internal_getpwuid, internal_getgrsid, internal_getgrgid,
internal_getgrnam, internal_getgrent and internal_getgroups.
Delete "emulated" from enum pwdgrp_state.
(pwdgrp_check::isuninitialized): Create.
(pwdgrp_check::pwdgrp_state): Change state to initializing
rather than to uninitialized.
(pwdgrp_read::gets): Remove trailing CRs.
* passwd.cc (grab_string): Don't look for NLs.
(grab_int): Ditto.
(parse_pwd): Don't look for CRs. Return 0 if entry is too short.
(search_for): Delete.
(read_etc_passwd): Simplify tests to actually read the file.
Set state to loaded before making internal_getpwXX calls.
Replace search_for calls by equivalent internal_pwgetXX calls.
(internal_getpwsid): Use passwd_state.isuninitialized to decide
to call read_etc_passwd.
(internal_getpwuid): Create.
(internal_getpwnam): Create.
(getpwuid32): Simply call internal_getpwuid.
(getpwuid_r32): Call internal_getpwuid.
(getpwnam): Simply call internal_getpwnam.
(getpwnam_r): Call internal_getpwnam.
* grp.cc (parse_grp): Don't look for CRs. Adjust blank space.
(add_grp_line): Adjust blank space.
(class group_lock): Ditto.
(read_etc_group): Simplify tests to actually read the file.
Set state to loaded before making internal_getgrXX calls.
Replace getgrXX calls by equivalent internal calls.
(internal_getgrsid): Use group_state.isuninitialized to decide
to call read_etc_group.
(internal_getgrgid): Create.
(internal_getgrnam): Create.
(getgroups32): Simply call internal_getgrgid.
(getgrnam32): Simply call internal_getgrnam.
(internal_getgrent): Call group_state.isuninitialized.
(internal_getgroups): Create from the former getgroups32, using
two of the four arguments. Set gid to myself->gid and username
to cygheap->user.name ().
(getgroups32): Simply call internal_getgroup.
(getgroups): Call internal_getgroup instead of getgroups32.
(setgroups32): Call internal versions of get{pw,gr}XX.
* sec_helper.cc: Include pwdgrp.h.
(is_grp_member): Call internal versions of get{pw,gr}XX.
* security.cc: Include pwdgrp.h.
(alloc_sd): Call internal versions of get{pw,gr}XX.
* syscalls.cc: Include pwdgrp.h.
(seteuid32): Call internal versions of get{pw,gr}XX.
(setegid32): Ditto.
* uinfo.cc: Include pwdgrp.h.
(internal_getlogin): Call internal versions of get{pw,gr}XX.
(cygheap_user::ontherange): Ditto.
* sec_acl.cc: Include pwdgrp.h.
(setacl): Call internal versions of get{pw,gr}XX.
(acl_access): Ditto and simplify logic.
(aclfromtext): Ditto.
2002-12-10 20:43:49 +08:00
|
|
|
|
2014-02-10 03:44:56 +08:00
|
|
|
cygheap->pg.nss_init ();
|
2014-03-13 01:36:56 +08:00
|
|
|
/* Check caches first. */
|
|
|
|
if (cygheap->pg.nss_cygserver_caching ()
|
|
|
|
&& (ret = cygheap->pg.grp_cache.cygserver.find_group (gid)))
|
|
|
|
return ret;
|
|
|
|
if (cygheap->pg.nss_grp_files ()
|
|
|
|
&& (ret = cygheap->pg.grp_cache.file.find_group (gid)))
|
|
|
|
return ret;
|
|
|
|
if (cygheap->pg.nss_grp_db ()
|
|
|
|
&& (ret = cygheap->pg.grp_cache.win.find_group (gid)))
|
|
|
|
return ret;
|
|
|
|
/* Ask sources afterwards. */
|
|
|
|
if (cygheap->pg.nss_cygserver_caching ()
|
|
|
|
&& (ret = cygheap->pg.grp_cache.cygserver.add_group_from_cygserver (gid)))
|
|
|
|
return ret;
|
2014-02-10 03:44:56 +08:00
|
|
|
if (cygheap->pg.nss_grp_files ())
|
|
|
|
{
|
2014-03-08 04:38:48 +08:00
|
|
|
cygheap->pg.grp_cache.file.check_file ();
|
2014-02-10 03:44:56 +08:00
|
|
|
if ((ret = cygheap->pg.grp_cache.file.add_group_from_file (gid)))
|
|
|
|
return ret;
|
|
|
|
}
|
2014-03-13 01:36:56 +08:00
|
|
|
if (cygheap->pg.nss_grp_db () || gid == ILLEGAL_GID)
|
2014-02-27 20:57:27 +08:00
|
|
|
return cygheap->pg.grp_cache.win.add_group_from_windows (gid, pldap);
|
2002-12-10 Pierre Humblet <pierre.humblet@ieee.org>
* pwdgrp.h (pwdgrp_check::pwdgrp_state): Replace by
pwdgrp_check::isinitializing ().
(pwdgrp_check::isinitializing): Create.
* passwd.cc (grab_int): Change type to unsigned, use strtoul and
set the pointer content to 0 if the field is invalid.
(parse_pwd): Move validity test after getting pw_gid.
(read_etc_passwd): Replace "passwd_state <= " by
passwd_state::isinitializing ().
(internal_getpwuid): Ditto.
(internal_getpwnam): Ditto.
(getpwent): Ditto.
(getpass): Ditto.
* grp.cc (parse_grp): Use strtoul for gr_gid and verify the validity.
(read_etc_group): Replace "group_state <= " by
group_state::isinitializing ().
(internal_getgrgid): Ditto.
(getgrent32): Ditto.
(internal_getgrent): Ditto.
2002-12-10 Pierre Humblet <pierre.humblet@ieee.org>
* security.h: Move declarations of internal_getgrent,
internal_getpwsid and internal_getgrsid to pwdgrp.h.
* pwdgrp.h: Declare internal_getpwsid, internal_getpwnam,
internal_getpwuid, internal_getgrsid, internal_getgrgid,
internal_getgrnam, internal_getgrent and internal_getgroups.
Delete "emulated" from enum pwdgrp_state.
(pwdgrp_check::isuninitialized): Create.
(pwdgrp_check::pwdgrp_state): Change state to initializing
rather than to uninitialized.
(pwdgrp_read::gets): Remove trailing CRs.
* passwd.cc (grab_string): Don't look for NLs.
(grab_int): Ditto.
(parse_pwd): Don't look for CRs. Return 0 if entry is too short.
(search_for): Delete.
(read_etc_passwd): Simplify tests to actually read the file.
Set state to loaded before making internal_getpwXX calls.
Replace search_for calls by equivalent internal_pwgetXX calls.
(internal_getpwsid): Use passwd_state.isuninitialized to decide
to call read_etc_passwd.
(internal_getpwuid): Create.
(internal_getpwnam): Create.
(getpwuid32): Simply call internal_getpwuid.
(getpwuid_r32): Call internal_getpwuid.
(getpwnam): Simply call internal_getpwnam.
(getpwnam_r): Call internal_getpwnam.
* grp.cc (parse_grp): Don't look for CRs. Adjust blank space.
(add_grp_line): Adjust blank space.
(class group_lock): Ditto.
(read_etc_group): Simplify tests to actually read the file.
Set state to loaded before making internal_getgrXX calls.
Replace getgrXX calls by equivalent internal calls.
(internal_getgrsid): Use group_state.isuninitialized to decide
to call read_etc_group.
(internal_getgrgid): Create.
(internal_getgrnam): Create.
(getgroups32): Simply call internal_getgrgid.
(getgrnam32): Simply call internal_getgrnam.
(internal_getgrent): Call group_state.isuninitialized.
(internal_getgroups): Create from the former getgroups32, using
two of the four arguments. Set gid to myself->gid and username
to cygheap->user.name ().
(getgroups32): Simply call internal_getgroup.
(getgroups): Call internal_getgroup instead of getgroups32.
(setgroups32): Call internal versions of get{pw,gr}XX.
* sec_helper.cc: Include pwdgrp.h.
(is_grp_member): Call internal versions of get{pw,gr}XX.
* security.cc: Include pwdgrp.h.
(alloc_sd): Call internal versions of get{pw,gr}XX.
* syscalls.cc: Include pwdgrp.h.
(seteuid32): Call internal versions of get{pw,gr}XX.
(setegid32): Ditto.
* uinfo.cc: Include pwdgrp.h.
(internal_getlogin): Call internal versions of get{pw,gr}XX.
(cygheap_user::ontherange): Ditto.
* sec_acl.cc: Include pwdgrp.h.
(setacl): Call internal versions of get{pw,gr}XX.
(acl_access): Ditto and simplify logic.
(aclfromtext): Ditto.
2002-12-10 20:43:49 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-04-23 17:44:36 +08:00
|
|
|
#ifndef __x86_64__
|
2003-01-20 10:57:54 +08:00
|
|
|
static struct __group16 *
|
2013-04-23 17:44:36 +08:00
|
|
|
grp32togrp16 (struct __group16 *gp16, struct group *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;
|
|
|
|
}
|
2013-04-23 17:44:36 +08:00
|
|
|
#endif
|
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
|
|
|
|
2004-05-18 00:06:02 +08:00
|
|
|
extern "C" int
|
2013-04-23 17:44:36 +08:00
|
|
|
getgrgid_r (gid_t gid, struct group *grp, char *buffer, size_t bufsize,
|
|
|
|
struct group **result)
|
2004-05-18 00:06:02 +08:00
|
|
|
{
|
|
|
|
*result = NULL;
|
|
|
|
|
|
|
|
if (!grp || !buffer)
|
|
|
|
return ERANGE;
|
|
|
|
|
2014-02-10 03:44:56 +08:00
|
|
|
struct group *tempgr = internal_getgrgid (gid);
|
2004-05-29 03:50:07 +08:00
|
|
|
pthread_testcancel ();
|
2004-05-18 00:06:02 +08:00
|
|
|
if (!tempgr)
|
|
|
|
return 0;
|
|
|
|
|
2014-05-07 19:00:00 +08:00
|
|
|
/* Check needed buffer size. Deliberately ignore gr_mem. */
|
2004-05-18 00:06:02 +08:00
|
|
|
size_t needsize = strlen (tempgr->gr_name) + strlen (tempgr->gr_passwd)
|
|
|
|
+ 2 + sizeof (char *);
|
|
|
|
if (needsize > bufsize)
|
|
|
|
return ERANGE;
|
|
|
|
|
2014-05-07 19:00:00 +08:00
|
|
|
/* Make a copy of tempgr. Deliberately ignore gr_mem. */
|
2004-05-18 00:06:02 +08:00
|
|
|
*result = grp;
|
|
|
|
grp->gr_gid = tempgr->gr_gid;
|
2009-01-26 21:20:46 +08:00
|
|
|
buffer = stpcpy (grp->gr_name = buffer, tempgr->gr_name);
|
|
|
|
buffer = stpcpy (grp->gr_passwd = buffer + 1, tempgr->gr_passwd);
|
|
|
|
grp->gr_mem = (char **) (buffer + 1);
|
2014-05-07 19:00:00 +08:00
|
|
|
grp->gr_mem[0] = NULL;
|
2004-05-18 00:06:02 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-05-07 19:00:00 +08:00
|
|
|
/* getgrgid/getgrnam are not reentrant. */
|
|
|
|
static struct {
|
|
|
|
struct group g;
|
|
|
|
char *buf;
|
|
|
|
size_t bufsiz;
|
|
|
|
} app_gr;
|
|
|
|
|
|
|
|
static struct group *
|
|
|
|
getgr_cp (struct group *tempgr)
|
|
|
|
{
|
|
|
|
if (!tempgr)
|
|
|
|
return NULL;
|
|
|
|
pg_grp *gr = (pg_grp *) tempgr;
|
|
|
|
if (app_gr.bufsiz < gr->len)
|
|
|
|
{
|
|
|
|
char *newbuf = (char *) realloc (app_gr.buf, gr->len);
|
|
|
|
if (!newbuf)
|
|
|
|
{
|
|
|
|
set_errno (ENOMEM);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
app_gr.buf = newbuf;
|
|
|
|
app_gr.bufsiz = gr->len;
|
|
|
|
}
|
|
|
|
memcpy (app_gr.buf, gr->g.gr_name, gr->len);
|
|
|
|
memcpy (&app_gr.g, &gr->g, sizeof gr->g);
|
|
|
|
ptrdiff_t diff = app_gr.buf - gr->g.gr_name;
|
|
|
|
app_gr.g.gr_name += diff;
|
|
|
|
app_gr.g.gr_passwd += diff;
|
|
|
|
return &app_gr.g;
|
|
|
|
}
|
|
|
|
|
2013-04-23 17:44:36 +08:00
|
|
|
extern "C" struct group *
|
|
|
|
getgrgid32 (gid_t gid)
|
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
|
|
|
{
|
2014-05-07 19:00:00 +08:00
|
|
|
struct group *tempgr = internal_getgrgid (gid);
|
|
|
|
pthread_testcancel ();
|
|
|
|
return getgr_cp (tempgr);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2013-04-23 17:44:36 +08:00
|
|
|
#ifdef __x86_64__
|
|
|
|
EXPORT_ALIAS (getgrgid32, getgrgid)
|
|
|
|
#else
|
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)
|
|
|
|
{
|
2003-01-18 02:05:32 +08:00
|
|
|
static struct __group16 g16; /* FIXME: thread-safe? */
|
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
|
|
|
|
2003-02-06 22:01:54 +08:00
|
|
|
return grp32togrp16 (&g16, getgrgid32 (gid16togid32 (gid)));
|
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
|
|
|
}
|
2013-04-23 17:44:36 +08:00
|
|
|
#endif
|
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
|
|
|
|
2004-05-18 00:06:02 +08:00
|
|
|
extern "C" int
|
2013-04-23 17:44:36 +08:00
|
|
|
getgrnam_r (const char *nam, struct group *grp, char *buffer,
|
|
|
|
size_t bufsize, struct group **result)
|
2004-05-18 00:06:02 +08:00
|
|
|
{
|
|
|
|
*result = NULL;
|
|
|
|
|
|
|
|
if (!grp || !buffer)
|
|
|
|
return ERANGE;
|
|
|
|
|
2014-02-10 03:44:56 +08:00
|
|
|
struct group *tempgr = internal_getgrnam (nam);
|
2004-05-29 03:50:07 +08:00
|
|
|
pthread_testcancel ();
|
2004-05-18 00:06:02 +08:00
|
|
|
if (!tempgr)
|
|
|
|
return 0;
|
|
|
|
|
2014-05-07 19:00:00 +08:00
|
|
|
/* Check needed buffer size. Deliberately ignore gr_mem. */
|
2004-05-18 00:06:02 +08:00
|
|
|
size_t needsize = strlen (tempgr->gr_name) + strlen (tempgr->gr_passwd)
|
|
|
|
+ 2 + sizeof (char *);
|
|
|
|
if (needsize > bufsize)
|
|
|
|
return ERANGE;
|
|
|
|
|
2014-05-07 19:00:00 +08:00
|
|
|
/* Make a copy of tempgr. Deliberately ignore gr_mem. */
|
2004-05-18 00:06:02 +08:00
|
|
|
*result = grp;
|
|
|
|
grp->gr_gid = tempgr->gr_gid;
|
2009-01-26 21:20:46 +08:00
|
|
|
buffer = stpcpy (grp->gr_name = buffer, tempgr->gr_name);
|
|
|
|
buffer = stpcpy (grp->gr_passwd = buffer + 1, tempgr->gr_passwd);
|
|
|
|
grp->gr_mem = (char **) (buffer + 1);
|
2014-05-07 19:00:00 +08:00
|
|
|
grp->gr_mem[0] = NULL;
|
2004-05-18 00:06:02 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-04-23 17:44:36 +08:00
|
|
|
extern "C" struct group *
|
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
|
|
|
{
|
2014-05-07 19:00:00 +08:00
|
|
|
struct group *tempgr = internal_getgrnam (name);
|
|
|
|
pthread_testcancel ();
|
|
|
|
return getgr_cp (tempgr);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2013-04-23 17:44:36 +08:00
|
|
|
#ifdef __x86_64__
|
|
|
|
EXPORT_ALIAS (getgrnam32, getgrnam)
|
|
|
|
#else
|
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)
|
|
|
|
{
|
2003-01-18 02:05:32 +08:00
|
|
|
static struct __group16 g16; /* FIXME: thread-safe? */
|
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 grp32togrp16 (&g16, getgrnam32 (name));
|
|
|
|
}
|
2013-04-23 17:44:36 +08:00
|
|
|
#endif
|
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
|
|
|
|
2014-02-17 23:36:33 +08:00
|
|
|
/* getgrent functions are not reentrant. */
|
|
|
|
static gr_ent grent;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2014-02-17 23:36:33 +08:00
|
|
|
void *
|
|
|
|
gr_ent::enumerate_caches ()
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2014-03-13 01:36:56 +08:00
|
|
|
switch (max)
|
2014-02-10 03:44:56 +08:00
|
|
|
{
|
2014-03-13 01:36:56 +08:00
|
|
|
case 0:
|
|
|
|
if (cygheap->pg.nss_cygserver_caching ())
|
|
|
|
{
|
|
|
|
pwdgrp &grc = cygheap->pg.grp_cache.cygserver;
|
|
|
|
if (cnt < grc.cached_groups ())
|
|
|
|
return &grc.group ()[cnt++].g;
|
|
|
|
}
|
2014-02-17 23:36:33 +08:00
|
|
|
cnt = 0;
|
|
|
|
max = 1;
|
2014-03-13 01:36:56 +08:00
|
|
|
/*FALLTHRU*/
|
|
|
|
case 1:
|
|
|
|
if (from_files)
|
|
|
|
{
|
|
|
|
pwdgrp &grf = cygheap->pg.grp_cache.file;
|
|
|
|
grf.check_file ();
|
|
|
|
if (cnt < grf.cached_groups ())
|
|
|
|
return &grf.group ()[cnt++].g;
|
|
|
|
}
|
|
|
|
cnt = 0;
|
2014-05-08 16:44:07 +08:00
|
|
|
max = 2;
|
2014-03-13 01:36:56 +08:00
|
|
|
/*FALLTHRU*/
|
|
|
|
case 2:
|
|
|
|
if (from_db)
|
|
|
|
{
|
|
|
|
pwdgrp &grw = cygheap->pg.grp_cache.win;
|
|
|
|
if (cnt < grw.cached_groups ())
|
|
|
|
return &grw.group ()[cnt++].g;
|
|
|
|
}
|
|
|
|
break;
|
2014-02-10 03:44:56 +08:00
|
|
|
}
|
2014-02-17 23:36:33 +08:00
|
|
|
cnt = max = 0;
|
2000-02-18 03:38:33 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-02-17 23:36:33 +08:00
|
|
|
void *
|
|
|
|
gr_ent::enumerate_local ()
|
|
|
|
{
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
if (!cnt)
|
|
|
|
{
|
|
|
|
DWORD total;
|
|
|
|
NET_API_STATUS ret;
|
|
|
|
|
|
|
|
if (buf)
|
|
|
|
{
|
|
|
|
NetApiBufferFree (buf);
|
|
|
|
buf = NULL;
|
|
|
|
}
|
|
|
|
if (resume == ULONG_MAX)
|
|
|
|
ret = ERROR_NO_MORE_ITEMS;
|
|
|
|
else
|
|
|
|
ret = NetLocalGroupEnum (NULL, 0, (PBYTE *) &buf,
|
|
|
|
MAX_PREFERRED_LENGTH,
|
|
|
|
&max, &total, &resume);
|
|
|
|
if (ret == NERR_Success)
|
|
|
|
resume = ULONG_MAX;
|
|
|
|
else if (ret != ERROR_MORE_DATA)
|
|
|
|
{
|
|
|
|
cnt = max = resume = 0;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (cnt < max)
|
|
|
|
{
|
|
|
|
cygsid sid;
|
2014-05-06 20:28:33 +08:00
|
|
|
DWORD slen = SECURITY_MAX_SID_SIZE;
|
2014-02-17 23:36:33 +08:00
|
|
|
WCHAR dom[DNLEN + 1];
|
|
|
|
DWORD dlen = DNLEN + 1;
|
|
|
|
SID_NAME_USE acc_type;
|
|
|
|
|
|
|
|
LookupAccountNameW (NULL,
|
|
|
|
((PLOCALGROUP_INFO_0) buf)[cnt++].lgrpi0_name,
|
|
|
|
sid, &slen, dom, &dlen, &acc_type);
|
|
|
|
fetch_user_arg_t arg;
|
|
|
|
arg.type = SID_arg;
|
|
|
|
arg.sid = &sid;
|
2014-03-08 04:38:48 +08:00
|
|
|
char *line = pg.fetch_account_from_windows (arg);
|
2014-02-17 23:36:33 +08:00
|
|
|
if (line)
|
|
|
|
return pg.add_account_post_fetch (line, false);
|
|
|
|
}
|
|
|
|
cnt = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct group *
|
|
|
|
gr_ent::getgrent (void)
|
|
|
|
{
|
|
|
|
if (state == rewound)
|
|
|
|
setent (true);
|
|
|
|
else
|
|
|
|
clear_cache ();
|
|
|
|
return (struct group *) getent ();
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" void
|
|
|
|
setgrent ()
|
|
|
|
{
|
|
|
|
grent.setgrent ();
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" struct group *
|
|
|
|
getgrent32 (void)
|
|
|
|
{
|
|
|
|
return grent.getgrent ();
|
|
|
|
}
|
|
|
|
|
2013-04-23 17:44:36 +08:00
|
|
|
#ifdef __x86_64__
|
|
|
|
EXPORT_ALIAS (getgrent32, getgrent)
|
|
|
|
#else
|
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
|
|
|
{
|
2003-01-18 02:05:32 +08:00
|
|
|
static struct __group16 g16; /* FIXME: thread-safe? */
|
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 grp32togrp16 (&g16, getgrent32 ());
|
|
|
|
}
|
2013-04-23 17:44:36 +08:00
|
|
|
#endif
|
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
|
|
|
|
2002-09-25 20:24:23 +08:00
|
|
|
extern "C" void
|
2014-02-17 23:36:33 +08:00
|
|
|
endgrent (void)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2014-02-17 23:36:33 +08:00
|
|
|
grent.endgrent ();
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2014-02-19 03:39:48 +08:00
|
|
|
/* *_filtered functions are called from mkgroup */
|
|
|
|
void *
|
|
|
|
setgrent_filtered (int enums, PCWSTR enum_tdoms)
|
|
|
|
{
|
|
|
|
gr_ent *gr = new gr_ent;
|
|
|
|
if (gr)
|
|
|
|
gr->setgrent (enums, enum_tdoms);
|
|
|
|
return (void *) gr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
getgrent_filtered (void *gr)
|
|
|
|
{
|
|
|
|
return (void *) ((gr_ent *) gr)->getgrent ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
endgrent_filtered (void *gr)
|
|
|
|
{
|
|
|
|
((gr_ent *) gr)->endgrent ();
|
|
|
|
}
|
|
|
|
|
2014-02-28 19:37:02 +08:00
|
|
|
int
|
2015-03-17 22:42:59 +08:00
|
|
|
internal_getgroups (int gidsetsize, gid_t *grouplist, cyg_ldap *pldap)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2011-04-29 15:34:05 +08:00
|
|
|
NTSTATUS status;
|
2014-02-27 20:57:27 +08:00
|
|
|
HANDLE tok;
|
2011-04-29 15:34:05 +08:00
|
|
|
ULONG size;
|
2015-02-24 04:51:12 +08:00
|
|
|
PTOKEN_GROUPS groups;
|
|
|
|
PSID *sidp_buf;
|
|
|
|
ULONG scnt;
|
|
|
|
PLSA_REFERENCED_DOMAIN_LIST dlst = NULL;
|
|
|
|
PLSA_TRANSLATED_NAME nlst = NULL;
|
|
|
|
|
|
|
|
tmp_pathbuf tp;
|
2014-02-10 03:44:56 +08:00
|
|
|
struct group *grp;
|
2015-02-24 04:51:12 +08:00
|
|
|
int cnt = 0;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2014-02-27 20:57:27 +08:00
|
|
|
if (cygheap->user.groups.issetgroups ())
|
2002-11-15 03:19:39 +08:00
|
|
|
{
|
2014-02-10 03:44:56 +08:00
|
|
|
for (int pg = 0; pg < cygheap->user.groups.sgsids.count (); ++pg)
|
2014-02-27 20:57:27 +08:00
|
|
|
if ((grp = internal_getgrsid (cygheap->user.groups.sgsids.sids[pg],
|
2014-02-28 19:37:02 +08:00
|
|
|
pldap)))
|
2014-02-10 03:44:56 +08:00
|
|
|
{
|
|
|
|
if (cnt < gidsetsize)
|
|
|
|
grouplist[cnt] = grp->gr_gid;
|
|
|
|
++cnt;
|
|
|
|
if (gidsetsize && cnt > gidsetsize)
|
2015-02-24 04:51:12 +08:00
|
|
|
{
|
|
|
|
cnt = -1;
|
|
|
|
break;
|
|
|
|
}
|
2014-02-10 03:44:56 +08:00
|
|
|
}
|
2015-02-24 04:51:12 +08:00
|
|
|
goto out;
|
2002-11-15 03:19:39 +08:00
|
|
|
}
|
2005-04-16 23:21:47 +08:00
|
|
|
|
|
|
|
/* If impersonated, use impersonation token. */
|
2015-02-24 04:51:12 +08:00
|
|
|
tok = cygheap->user.issetuid () ? cygheap->user.primary_token ()
|
|
|
|
: hProcToken;
|
|
|
|
|
|
|
|
/* Fetch groups from user token. */
|
|
|
|
groups = (PTOKEN_GROUPS) tp.w_get ();
|
|
|
|
status = NtQueryInformationToken (tok, TokenGroups, groups, 2 * NT_MAX_PATH,
|
|
|
|
&size);
|
|
|
|
if (!NT_SUCCESS (status))
|
2001-04-16 22:02:42 +08:00
|
|
|
{
|
2015-08-18 04:45:02 +08:00
|
|
|
debug_printf ("NtQueryInformationToken(TokenGroups) %y", status);
|
2015-02-24 04:51:12 +08:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
/* Iterate over the group list and check which of them are already cached.
|
|
|
|
Those are simply copied to grouplist. The non-cached ones are collected
|
|
|
|
in sidp_buf for a later call to LsaLookupSids. */
|
|
|
|
sidp_buf = (PSID *) tp.w_get ();
|
|
|
|
scnt = 0;
|
|
|
|
for (DWORD pg = 0; pg < groups->GroupCount; ++pg)
|
|
|
|
{
|
|
|
|
cygpsid sid = groups->Groups[pg].Sid;
|
|
|
|
if ((groups->Groups[pg].Attributes
|
|
|
|
& (SE_GROUP_ENABLED | SE_GROUP_INTEGRITY_ENABLED)) == 0
|
|
|
|
|| sid == well_known_world_sid)
|
|
|
|
continue;
|
|
|
|
if ((grp = internal_getgrsid_cachedonly (sid)))
|
|
|
|
{
|
|
|
|
if (cnt < gidsetsize)
|
|
|
|
grouplist[cnt] = grp->gr_gid;
|
|
|
|
++cnt;
|
|
|
|
if (gidsetsize && cnt > gidsetsize)
|
|
|
|
{
|
|
|
|
cnt = -1;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
sidp_buf[scnt++] = sid;
|
|
|
|
}
|
2015-08-18 04:45:02 +08:00
|
|
|
/* If there are non-cached groups left, try to fetch them. */
|
2015-02-24 04:51:12 +08:00
|
|
|
if (scnt > 0)
|
|
|
|
{
|
2015-08-18 04:45:02 +08:00
|
|
|
/* Don't call LsaLookupSids if we're not utilizing the Windows account
|
|
|
|
DBs. If we don't have access to the AD, which is one good reason to
|
|
|
|
disable passwd/group: db in nsswitch.conf, then the subsequent call
|
|
|
|
to LsaLookupSids will take 5 - 10 seconds in some environments. */
|
|
|
|
if (!cygheap->pg.nss_grp_db ())
|
|
|
|
{
|
|
|
|
for (DWORD pg = 0; pg < scnt; ++pg)
|
|
|
|
{
|
|
|
|
cygpsid sid = sidp_buf[pg];
|
|
|
|
if ((grp = internal_getgrsid (sid, NULL)))
|
|
|
|
{
|
|
|
|
if (cnt < gidsetsize)
|
|
|
|
grouplist[cnt] = grp->gr_gid;
|
|
|
|
++cnt;
|
|
|
|
if (gidsetsize && cnt > gidsetsize)
|
|
|
|
{
|
|
|
|
cnt = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
/* Otherwise call LsaLookupSids and call internal_getgrfull on the
|
|
|
|
returned groups. This performs a lot better than calling
|
|
|
|
internal_getgrsid on each group. */
|
2015-02-24 04:51:12 +08:00
|
|
|
status = STATUS_ACCESS_DENIED;
|
|
|
|
HANDLE lsa = lsa_open_policy (NULL, POLICY_LOOKUP_NAMES);
|
|
|
|
if (!lsa)
|
|
|
|
{
|
2015-08-18 04:45:02 +08:00
|
|
|
debug_printf ("POLICY_LOOKUP_NAMES right not given?");
|
2015-02-24 04:51:12 +08:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
status = LsaLookupSids (lsa, scnt, sidp_buf, &dlst, &nlst);
|
|
|
|
lsa_close_policy (lsa);
|
2011-04-29 15:34:05 +08:00
|
|
|
if (NT_SUCCESS (status))
|
2001-09-08 05:32:07 +08:00
|
|
|
{
|
2015-02-24 04:51:12 +08:00
|
|
|
for (ULONG ncnt = 0; ncnt < scnt; ++ncnt)
|
2014-02-10 03:44:56 +08:00
|
|
|
{
|
2015-04-01 19:15:18 +08:00
|
|
|
static UNICODE_STRING empty = { 0, 0, (PWSTR) L"" };
|
2015-02-25 04:52:57 +08:00
|
|
|
fetch_acc_t full_acc =
|
2015-02-24 04:51:12 +08:00
|
|
|
{
|
|
|
|
.sid = sidp_buf[ncnt],
|
|
|
|
.name = &nlst[ncnt].Name,
|
2015-04-01 19:15:18 +08:00
|
|
|
.dom = &empty,
|
2015-02-24 04:51:12 +08:00
|
|
|
.acc_type = nlst[ncnt].Use
|
|
|
|
};
|
2015-04-01 19:15:18 +08:00
|
|
|
|
|
|
|
if (nlst[ncnt].DomainIndex >= 0)
|
|
|
|
full_acc.dom = &dlst->Domains[nlst[ncnt].DomainIndex].Name;
|
2015-02-25 04:52:57 +08:00
|
|
|
if ((grp = internal_getgrfull (full_acc, pldap)))
|
2014-02-10 03:44:56 +08:00
|
|
|
{
|
2015-02-23 23:46:10 +08:00
|
|
|
if (cnt < gidsetsize)
|
|
|
|
grouplist[cnt] = grp->gr_gid;
|
|
|
|
++cnt;
|
|
|
|
if (gidsetsize && cnt > gidsetsize)
|
2015-02-24 04:51:12 +08:00
|
|
|
{
|
|
|
|
cnt = -1;
|
2015-08-18 04:45:02 +08:00
|
|
|
break;
|
2015-02-24 04:51:12 +08:00
|
|
|
}
|
2014-02-10 03:44:56 +08:00
|
|
|
}
|
|
|
|
}
|
2001-09-08 05:32:07 +08:00
|
|
|
}
|
2001-04-16 22:02:42 +08:00
|
|
|
}
|
2000-08-30 02:59:26 +08:00
|
|
|
|
2015-02-24 04:51:12 +08:00
|
|
|
out:
|
|
|
|
if (dlst)
|
|
|
|
LsaFreeMemory (dlst);
|
|
|
|
if (nlst)
|
|
|
|
LsaFreeMemory (nlst);
|
|
|
|
if (cnt == -1)
|
|
|
|
set_errno (EINVAL);
|
|
|
|
return cnt;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2014-02-28 19:37:02 +08:00
|
|
|
extern "C" int
|
|
|
|
getgroups32 (int gidsetsize, gid_t *grouplist)
|
|
|
|
{
|
|
|
|
cyg_ldap cldap;
|
|
|
|
|
|
|
|
return internal_getgroups (gidsetsize, grouplist, &cldap);
|
|
|
|
}
|
|
|
|
|
2013-04-23 17:44:36 +08:00
|
|
|
#ifdef __x86_64__
|
|
|
|
EXPORT_ALIAS (getgroups32, getgroups)
|
|
|
|
#else
|
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
|
|
|
{
|
2013-04-23 17:44:36 +08:00
|
|
|
gid_t *grouplist32 = NULL;
|
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 (gidsetsize < 0)
|
|
|
|
{
|
|
|
|
set_errno (EINVAL);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (gidsetsize > 0 && grouplist)
|
2013-04-23 17:44:36 +08:00
|
|
|
grouplist32 = (gid_t *) alloca (gidsetsize * sizeof (gid_t));
|
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
|
|
|
|
2014-02-27 20:57:27 +08:00
|
|
|
int ret = getgroups32 (gidsetsize, grouplist32);
|
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 (gidsetsize > 0 && grouplist)
|
|
|
|
for (int i = 0; i < ret; ++ i)
|
|
|
|
grouplist[i] = grouplist32[i];
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2013-04-23 17:44:36 +08:00
|
|
|
#endif
|
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
|
|
|
|
2011-10-28 17:26:42 +08:00
|
|
|
/* Core functionality of initgroups and getgrouplist. */
|
2013-05-14 17:07:30 +08:00
|
|
|
static void
|
2011-10-28 17:26:42 +08:00
|
|
|
get_groups (const char *user, gid_t gid, cygsidlist &gsids)
|
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
|
|
|
{
|
2014-02-27 20:57:27 +08:00
|
|
|
cyg_ldap cldap;
|
|
|
|
|
2007-02-23 23:15:50 +08:00
|
|
|
cygheap->user.deimpersonate ();
|
2014-02-27 20:57:27 +08:00
|
|
|
struct passwd *pw = internal_getpwnam (user, &cldap);
|
|
|
|
struct group *grp = internal_getgrgid (gid, &cldap);
|
2007-02-23 23:15:50 +08:00
|
|
|
cygsid usersid, grpsid;
|
2013-05-14 16:50:37 +08:00
|
|
|
if (usersid.getfrompw (pw))
|
2015-03-18 23:54:19 +08:00
|
|
|
get_server_groups (gsids, usersid);
|
2014-02-20 21:55:57 +08:00
|
|
|
if (gid != ILLEGAL_GID && grpsid.getfromgr (grp))
|
2013-05-14 16:50:37 +08:00
|
|
|
gsids += grpsid;
|
2007-02-23 23:15:50 +08:00
|
|
|
cygheap->user.reimpersonate ();
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2002-09-25 20:24:23 +08:00
|
|
|
extern "C" int
|
2013-04-23 17:44:36 +08:00
|
|
|
initgroups32 (const char *user, gid_t gid)
|
2011-10-28 17:26:42 +08:00
|
|
|
{
|
|
|
|
assert (user != NULL);
|
|
|
|
cygsidlist tmp_gsids (cygsidlist_auto, 12);
|
2013-05-14 17:07:30 +08:00
|
|
|
get_groups (user, gid, tmp_gsids);
|
|
|
|
cygsidlist new_gsids (cygsidlist_alloc, tmp_gsids.count ());
|
|
|
|
for (int i = 0; i < tmp_gsids.count (); i++)
|
|
|
|
new_gsids.sids[i] = tmp_gsids.sids[i];
|
|
|
|
new_gsids.count (tmp_gsids.count ());
|
|
|
|
cygheap->user.groups.update_supp (new_gsids);
|
|
|
|
syscall_printf ( "0 = initgroups(%s, %u)", user, gid);
|
|
|
|
return 0;
|
2011-10-28 17:26:42 +08:00
|
|
|
}
|
|
|
|
|
2013-04-23 17:44:36 +08:00
|
|
|
#ifdef __x86_64__
|
|
|
|
EXPORT_ALIAS (initgroups32, initgroups)
|
|
|
|
#else
|
2011-10-28 17:26:42 +08:00
|
|
|
extern "C" int
|
|
|
|
initgroups (const char *user, __gid16_t gid)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2011-10-28 17:26:42 +08:00
|
|
|
return initgroups32 (user, gid16togid32(gid));
|
|
|
|
}
|
2013-04-23 17:44:36 +08:00
|
|
|
#endif
|
2011-10-28 17:26:42 +08:00
|
|
|
|
|
|
|
extern "C" int
|
|
|
|
getgrouplist (const char *user, gid_t gid, gid_t *groups, int *ngroups)
|
|
|
|
{
|
2013-05-14 17:07:30 +08:00
|
|
|
int ret = 0;
|
|
|
|
int cnt = 0;
|
2014-02-10 03:44:56 +08:00
|
|
|
struct group *grp;
|
2014-02-27 20:57:27 +08:00
|
|
|
cyg_ldap cldap;
|
2011-10-28 17:26:42 +08:00
|
|
|
|
|
|
|
/* Note that it's not defined if groups or ngroups may be NULL!
|
|
|
|
GLibc does not check the pointers on entry and just uses them.
|
|
|
|
FreeBSD calls assert for ngroups and allows a NULL groups if
|
|
|
|
*ngroups is 0. We follow FreeBSD's lead here, but always allow
|
|
|
|
a NULL groups pointer. */
|
|
|
|
assert (user != NULL);
|
|
|
|
assert (ngroups != NULL);
|
|
|
|
|
|
|
|
cygsidlist tmp_gsids (cygsidlist_auto, 12);
|
2013-05-14 17:07:30 +08:00
|
|
|
get_groups (user, gid, tmp_gsids);
|
|
|
|
for (int i = 0; i < tmp_gsids.count (); i++)
|
2014-02-27 20:57:27 +08:00
|
|
|
if ((grp = internal_getgrsid (tmp_gsids.sids[i], &cldap)) != NULL)
|
2013-05-14 17:07:30 +08:00
|
|
|
{
|
|
|
|
if (groups && cnt < *ngroups)
|
2014-02-10 03:44:56 +08:00
|
|
|
groups[cnt] = grp->gr_gid;
|
2013-05-14 17:07:30 +08:00
|
|
|
++cnt;
|
|
|
|
}
|
|
|
|
if (cnt > *ngroups)
|
|
|
|
ret = -1;
|
2014-02-20 23:46:48 +08:00
|
|
|
else
|
|
|
|
ret = cnt;
|
2014-06-16 17:12:29 +08:00
|
|
|
*ngroups = cnt;
|
2013-05-14 17:07:30 +08:00
|
|
|
|
2011-12-04 05:43:27 +08:00
|
|
|
syscall_printf ( "%d = getgrouplist(%s, %u, %p, %d)",
|
2011-10-28 17:26:42 +08:00
|
|
|
ret, user, gid, groups, *ngroups);
|
|
|
|
return ret;
|
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
|
2013-04-23 17:44:36 +08:00
|
|
|
setgroups32 (int ngroups, const gid_t *grouplist)
|
2002-07-29 20:51:52 +08:00
|
|
|
{
|
2005-04-06 20:35:52 +08:00
|
|
|
syscall_printf ("setgroups32 (%d)", ngroups);
|
2002-07-29 20:51:52 +08:00
|
|
|
if (ngroups < 0 || (ngroups > 0 && !grouplist))
|
|
|
|
{
|
|
|
|
set_errno (EINVAL);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
cygsidlist gsids (cygsidlist_alloc, ngroups);
|
2014-02-10 03:44:56 +08:00
|
|
|
struct group *grp;
|
2014-02-27 20:57:27 +08:00
|
|
|
cyg_ldap cldap;
|
2002-07-29 20:51:52 +08:00
|
|
|
|
|
|
|
if (ngroups && !gsids.sids)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
for (int gidx = 0; gidx < ngroups; ++gidx)
|
|
|
|
{
|
2014-02-27 20:57:27 +08:00
|
|
|
if ((grp = internal_getgrgid (grouplist[gidx], &cldap))
|
2014-02-10 03:44:56 +08:00
|
|
|
&& gsids.addfromgr (grp))
|
2005-04-06 20:35:52 +08:00
|
|
|
continue;
|
2013-04-23 17:44:36 +08:00
|
|
|
debug_printf ("No sid found for gid %u", grouplist[gidx]);
|
2002-07-29 20:51:52 +08:00
|
|
|
gsids.free_sids ();
|
|
|
|
set_errno (EINVAL);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
cygheap->user.groups.update_supp (gsids);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-04-23 17:44:36 +08:00
|
|
|
#ifdef __x86_64__
|
|
|
|
EXPORT_ALIAS (setgroups32, setgroups)
|
|
|
|
#else
|
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)
|
|
|
|
{
|
2013-04-23 17:44:36 +08:00
|
|
|
gid_t *grouplist32 = NULL;
|
2002-07-29 20:51:52 +08:00
|
|
|
|
|
|
|
if (ngroups > 0 && grouplist)
|
|
|
|
{
|
2013-04-23 17:44:36 +08:00
|
|
|
grouplist32 = (gid_t *) alloca (ngroups * sizeof (gid_t));
|
2002-07-29 20:51:52 +08:00
|
|
|
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);
|
|
|
|
}
|
2013-04-23 17:44:36 +08:00
|
|
|
#endif
|