2000-02-18 03:38:33 +08:00
|
|
|
/* passwd.cc: getpwnam () and friends
|
|
|
|
|
2013-01-21 12:38:31 +08:00
|
|
|
Copyright 1996, 1997, 1998, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008,
|
2014-01-28 04:04:35 +08:00
|
|
|
2009, 2010, 2011, 2012, 2013, 2014 Red Hat, Inc.
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
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>
|
2000-02-18 03:38:33 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
2000-08-22 13:10:20 +08:00
|
|
|
#include "cygerrno.h"
|
2001-07-27 03:22:24 +08:00
|
|
|
#include "security.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"
|
2000-08-12 13:35:42 +08:00
|
|
|
#include "pinfo.h"
|
2000-11-15 08:13:09 +08:00
|
|
|
#include "cygheap.h"
|
2008-10-22 00:47:28 +08:00
|
|
|
#include "shared_info.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
|
|
|
|
|
|
|
/* Parse /etc/passwd line into passwd structure. */
|
2003-01-20 10:57:54 +08:00
|
|
|
bool
|
2003-01-24 11:53:46 +08:00
|
|
|
pwdgrp::parse_passwd ()
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2014-02-10 03:44:56 +08:00
|
|
|
pg_pwd &res = passwd ()[curr_lines];
|
|
|
|
res.p.pw_name = next_str (':');
|
|
|
|
res.p.pw_passwd = next_str (':');
|
|
|
|
if (!next_num (res.p.pw_uid))
|
2003-01-28 01:00:17 +08:00
|
|
|
return false;
|
2014-02-10 03:44:56 +08:00
|
|
|
if (!next_num (res.p.pw_gid))
|
2003-01-28 01:00:17 +08:00
|
|
|
return false;
|
2014-02-10 03:44:56 +08:00
|
|
|
res.p.pw_comment = NULL;
|
|
|
|
res.p.pw_gecos = next_str (':');
|
|
|
|
res.p.pw_dir = next_str (':');
|
|
|
|
res.p.pw_shell = next_str (':');
|
|
|
|
res.sid.getfrompw (&res.p);
|
2014-05-07 22:49:54 +08:00
|
|
|
/* lptr points to the \0 after pw_shell. Increment by one to get the correct
|
|
|
|
required buffer len in getpw_cp. */
|
|
|
|
res.len = lptr - res.p.pw_name + 1;
|
2003-01-20 10:57:54 +08:00
|
|
|
return true;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2003-01-21 14:58:11 +08:00
|
|
|
void
|
2014-02-10 03:44:56 +08:00
|
|
|
pwdgrp::init_pwd ()
|
|
|
|
{
|
|
|
|
pwdgrp_buf_elem_size = sizeof (pg_pwd);
|
|
|
|
parse = &pwdgrp::parse_passwd;
|
|
|
|
}
|
|
|
|
|
2002-11-21 01:10:05 +08:00
|
|
|
struct passwd *
|
2014-02-10 03:44:56 +08:00
|
|
|
pwdgrp::find_user (cygpsid &sid)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2014-02-10 03:44:56 +08:00
|
|
|
for (ULONG i = 0; i < curr_lines; i++)
|
|
|
|
if (sid == passwd ()[i].sid)
|
|
|
|
return &passwd ()[i].p;
|
|
|
|
return NULL;
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2014-02-10 03:44:56 +08:00
|
|
|
struct passwd *
|
|
|
|
pwdgrp::find_user (const char *name)
|
|
|
|
{
|
|
|
|
for (ULONG i = 0; i < curr_lines; i++)
|
|
|
|
/* on Windows NT user names are case-insensitive */
|
|
|
|
if (strcasematch (name, passwd ()[i].p.pw_name))
|
|
|
|
return &passwd ()[i].p;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct passwd *
|
|
|
|
pwdgrp::find_user (uid_t uid)
|
|
|
|
{
|
|
|
|
for (ULONG i = 0; i < curr_lines; i++)
|
|
|
|
if (uid == passwd ()[i].p.pw_uid)
|
|
|
|
return &passwd ()[i].p;
|
|
|
|
return NULL;
|
|
|
|
}
|
2002-11-21 01:10:05 +08:00
|
|
|
|
2014-02-10 03:44:56 +08:00
|
|
|
struct passwd *
|
2014-02-27 20:57:27 +08:00
|
|
|
internal_getpwsid (cygpsid &sid, cyg_ldap *pldap)
|
2014-02-10 03:44:56 +08:00
|
|
|
{
|
|
|
|
struct passwd *ret;
|
|
|
|
|
|
|
|
cygheap->pg.nss_init ();
|
2014-03-13 01:36:56 +08:00
|
|
|
/* Check caches first. */
|
|
|
|
if (cygheap->pg.nss_cygserver_caching ()
|
|
|
|
&& (ret = cygheap->pg.pwd_cache.cygserver.find_user (sid)))
|
|
|
|
return ret;
|
|
|
|
if (cygheap->pg.nss_pwd_files ()
|
|
|
|
&& (ret = cygheap->pg.pwd_cache.file.find_user (sid)))
|
|
|
|
return ret;
|
|
|
|
if (cygheap->pg.nss_pwd_db ()
|
|
|
|
&& (ret = cygheap->pg.pwd_cache.win.find_user (sid)))
|
|
|
|
return ret;
|
|
|
|
/* Ask sources afterwards. */
|
|
|
|
if (cygheap->pg.nss_cygserver_caching ()
|
|
|
|
&& (ret = cygheap->pg.pwd_cache.cygserver.add_user_from_cygserver (sid)))
|
|
|
|
return ret;
|
2014-02-10 03:44:56 +08:00
|
|
|
if (cygheap->pg.nss_pwd_files ())
|
|
|
|
{
|
2014-03-08 04:38:48 +08:00
|
|
|
cygheap->pg.pwd_cache.file.check_file ();
|
2014-02-10 03:44:56 +08:00
|
|
|
if ((ret = cygheap->pg.pwd_cache.file.add_user_from_file (sid)))
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
if (cygheap->pg.nss_pwd_db ())
|
2014-03-13 01:36:56 +08:00
|
|
|
return cygheap->pg.pwd_cache.win.add_user_from_windows (sid, pldap);
|
2000-07-26 19:48:38 +08:00
|
|
|
return NULL;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2014-02-23 03:38:12 +08:00
|
|
|
/* This function gets only called from mkpasswd via cygwin_internal. */
|
|
|
|
struct passwd *
|
|
|
|
internal_getpwsid_from_db (cygpsid &sid)
|
|
|
|
{
|
|
|
|
cygheap->pg.nss_init ();
|
|
|
|
return cygheap->pg.pwd_cache.win.add_user_from_windows (sid);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
struct passwd *
|
2014-02-27 20:57:27 +08:00
|
|
|
internal_getpwnam (const char *name, cyg_ldap *pldap)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2014-02-10 03:44:56 +08:00
|
|
|
struct passwd *ret;
|
2001-06-26 22:47:48 +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.pwd_cache.cygserver.find_user (name)))
|
|
|
|
return ret;
|
|
|
|
if (cygheap->pg.nss_pwd_files ()
|
|
|
|
&& (ret = cygheap->pg.pwd_cache.file.find_user (name)))
|
|
|
|
return ret;
|
|
|
|
if (cygheap->pg.nss_pwd_db ()
|
|
|
|
&& (ret = cygheap->pg.pwd_cache.win.find_user (name)))
|
|
|
|
return ret;
|
|
|
|
/* Ask sources afterwards. */
|
|
|
|
if (cygheap->pg.nss_cygserver_caching ()
|
|
|
|
&& (ret = cygheap->pg.pwd_cache.cygserver.add_user_from_cygserver (name)))
|
|
|
|
return ret;
|
2014-02-10 03:44:56 +08:00
|
|
|
if (cygheap->pg.nss_pwd_files ())
|
|
|
|
{
|
2014-03-08 04:38:48 +08:00
|
|
|
cygheap->pg.pwd_cache.file.check_file ();
|
2014-02-10 03:44:56 +08:00
|
|
|
if ((ret = cygheap->pg.pwd_cache.file.add_user_from_file (name)))
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
if (cygheap->pg.nss_pwd_db ())
|
2014-03-13 01:36:56 +08:00
|
|
|
return cygheap->pg.pwd_cache.win.add_user_from_windows (name, 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct passwd *
|
2014-02-27 20:57:27 +08:00
|
|
|
internal_getpwuid (uid_t uid, 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 passwd *ret;
|
2000-02-18 03:38:33 +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.pwd_cache.cygserver.find_user (uid)))
|
|
|
|
return ret;
|
|
|
|
if (cygheap->pg.nss_pwd_files ()
|
|
|
|
&& (ret = cygheap->pg.pwd_cache.file.find_user (uid)))
|
|
|
|
return ret;
|
|
|
|
if (cygheap->pg.nss_pwd_db ()
|
|
|
|
&& (ret = cygheap->pg.pwd_cache.win.find_user (uid)))
|
|
|
|
return ret;
|
|
|
|
/* Ask sources afterwards. */
|
|
|
|
if (cygheap->pg.nss_cygserver_caching ()
|
|
|
|
&& (ret = cygheap->pg.pwd_cache.cygserver.add_user_from_cygserver (uid)))
|
|
|
|
return ret;
|
2014-02-10 03:44:56 +08:00
|
|
|
if (cygheap->pg.nss_pwd_files ())
|
|
|
|
{
|
2014-03-08 04:38:48 +08:00
|
|
|
cygheap->pg.pwd_cache.file.check_file ();
|
2014-02-10 03:44:56 +08:00
|
|
|
if ((ret = cygheap->pg.pwd_cache.file.add_user_from_file (uid)))
|
|
|
|
return ret;
|
|
|
|
}
|
2014-03-13 01:36:56 +08:00
|
|
|
if (cygheap->pg.nss_pwd_db () || uid == ILLEGAL_UID)
|
|
|
|
return cygheap->pg.pwd_cache.win.add_user_from_windows (uid, 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;
|
|
|
|
}
|
|
|
|
|
2014-05-07 19:00:00 +08:00
|
|
|
/* getpwuid/getpwnam are not reentrant. */
|
|
|
|
static struct {
|
|
|
|
struct passwd p;
|
|
|
|
char *buf;
|
|
|
|
size_t bufsiz;
|
|
|
|
} app_pw;
|
|
|
|
|
|
|
|
static struct passwd *
|
|
|
|
getpw_cp (struct passwd *temppw)
|
|
|
|
{
|
|
|
|
if (!temppw)
|
|
|
|
return NULL;
|
|
|
|
pg_pwd *pw = (pg_pwd *) temppw;
|
|
|
|
if (app_pw.bufsiz < pw->len)
|
|
|
|
{
|
|
|
|
char *newbuf = (char *) realloc (app_pw.buf, pw->len);
|
|
|
|
if (!newbuf)
|
|
|
|
{
|
|
|
|
set_errno (ENOMEM);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
app_pw.buf = newbuf;
|
|
|
|
app_pw.bufsiz = pw->len;
|
|
|
|
}
|
|
|
|
memcpy (app_pw.buf, pw->p.pw_name, pw->len);
|
|
|
|
memcpy (&app_pw.p, &pw->p, sizeof pw->p);
|
|
|
|
ptrdiff_t diff = app_pw.buf - pw->p.pw_name;
|
|
|
|
app_pw.p.pw_name += diff;
|
|
|
|
app_pw.p.pw_passwd += diff;
|
|
|
|
app_pw.p.pw_gecos += diff;
|
|
|
|
app_pw.p.pw_dir += diff;
|
|
|
|
app_pw.p.pw_shell += diff;
|
|
|
|
return &app_pw.p;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
extern "C" struct passwd *
|
2013-04-23 17:44:36 +08:00
|
|
|
getpwuid32 (uid_t uid)
|
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 passwd *temppw = internal_getpwuid (uid);
|
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
|
|
|
pthread_testcancel ();
|
2014-05-07 19:00:00 +08:00
|
|
|
return getpw_cp (temppw);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2013-04-23 17:44:36 +08:00
|
|
|
#ifdef __x86_64__
|
|
|
|
EXPORT_ALIAS (getpwuid32, getpwuid)
|
|
|
|
#else
|
2002-05-29 23:04:29 +08:00
|
|
|
extern "C" struct passwd *
|
|
|
|
getpwuid (__uid16_t uid)
|
|
|
|
{
|
|
|
|
return getpwuid32 (uid16touid32 (uid));
|
|
|
|
}
|
2013-04-23 17:44:36 +08:00
|
|
|
#endif
|
2002-05-29 23:04:29 +08:00
|
|
|
|
2001-06-26 22:47:48 +08:00
|
|
|
extern "C" int
|
2013-04-23 17:44:36 +08:00
|
|
|
getpwuid_r32 (uid_t uid, struct passwd *pwd, char *buffer, size_t bufsize, struct passwd **result)
|
2001-04-19 05:10:15 +08:00
|
|
|
{
|
|
|
|
*result = NULL;
|
|
|
|
|
|
|
|
if (!pwd || !buffer)
|
|
|
|
return ERANGE;
|
|
|
|
|
2014-02-10 03:44:56 +08:00
|
|
|
struct passwd *temppw = internal_getpwuid (uid);
|
2002-09-22 11:38:57 +08:00
|
|
|
pthread_testcancel ();
|
2001-04-19 05:10:15 +08:00
|
|
|
if (!temppw)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* check needed buffer size. */
|
2009-01-26 21:20:46 +08:00
|
|
|
size_t needsize = strlen (temppw->pw_name) + strlen (temppw->pw_passwd)
|
|
|
|
+ strlen (temppw->pw_gecos) + strlen (temppw->pw_dir)
|
|
|
|
+ strlen (temppw->pw_shell) + 5;
|
2001-04-19 05:10:15 +08:00
|
|
|
if (needsize > bufsize)
|
|
|
|
return ERANGE;
|
|
|
|
|
|
|
|
/* make a copy of temppw */
|
|
|
|
*result = pwd;
|
|
|
|
pwd->pw_uid = temppw->pw_uid;
|
|
|
|
pwd->pw_gid = temppw->pw_gid;
|
2009-01-26 21:20:46 +08:00
|
|
|
buffer = stpcpy (pwd->pw_name = buffer, temppw->pw_name);
|
|
|
|
buffer = stpcpy (pwd->pw_passwd = buffer + 1, temppw->pw_passwd);
|
|
|
|
buffer = stpcpy (pwd->pw_gecos = buffer + 1, temppw->pw_gecos);
|
|
|
|
buffer = stpcpy (pwd->pw_dir = buffer + 1, temppw->pw_dir);
|
|
|
|
stpcpy (pwd->pw_shell = buffer + 1, temppw->pw_shell);
|
2003-09-09 05:44:53 +08:00
|
|
|
pwd->pw_comment = NULL;
|
2001-04-19 05:10:15 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-04-23 17:44:36 +08:00
|
|
|
#ifdef __x86_64__
|
|
|
|
EXPORT_ALIAS (getpwuid_r32, getpwuid_r)
|
|
|
|
#else
|
2002-05-29 23:04:29 +08:00
|
|
|
extern "C" int
|
|
|
|
getpwuid_r (__uid16_t uid, struct passwd *pwd, char *buffer, size_t bufsize, struct passwd **result)
|
|
|
|
{
|
|
|
|
return getpwuid_r32 (uid16touid32 (uid), pwd, buffer, bufsize, result);
|
|
|
|
}
|
2013-04-23 17:44:36 +08:00
|
|
|
#endif
|
2002-05-29 23:04:29 +08:00
|
|
|
|
2000-02-21 13:20:38 +08:00
|
|
|
extern "C" struct passwd *
|
2000-02-18 03:38:33 +08:00
|
|
|
getpwnam (const char *name)
|
|
|
|
{
|
2014-02-10 03:44:56 +08:00
|
|
|
struct passwd *temppw = internal_getpwnam (name);
|
2002-09-22 11:38:57 +08:00
|
|
|
pthread_testcancel ();
|
2014-05-07 19:00:00 +08:00
|
|
|
return getpw_cp (temppw);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2001-04-19 05:10:15 +08:00
|
|
|
|
2001-06-26 22:47:48 +08:00
|
|
|
/* the max size buffer we can expect to
|
2001-04-19 05:10:15 +08:00
|
|
|
* use is returned via sysconf with _SC_GETPW_R_SIZE_MAX.
|
|
|
|
* This may need updating! - Rob Collins April 2001.
|
|
|
|
*/
|
|
|
|
extern "C" int
|
|
|
|
getpwnam_r (const char *nam, struct passwd *pwd, char *buffer, size_t bufsize, struct passwd **result)
|
|
|
|
{
|
|
|
|
*result = NULL;
|
|
|
|
|
|
|
|
if (!pwd || !buffer || !nam)
|
|
|
|
return ERANGE;
|
|
|
|
|
2014-02-10 03:44:56 +08:00
|
|
|
struct passwd *temppw = internal_getpwnam (nam);
|
2002-09-22 11:38:57 +08:00
|
|
|
pthread_testcancel ();
|
2001-04-21 22:23:47 +08:00
|
|
|
|
2001-04-19 05:10:15 +08:00
|
|
|
if (!temppw)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* check needed buffer size. */
|
2009-01-26 21:20:46 +08:00
|
|
|
size_t needsize = strlen (temppw->pw_name) + strlen (temppw->pw_passwd)
|
|
|
|
+ strlen (temppw->pw_gecos) + strlen (temppw->pw_dir)
|
|
|
|
+ strlen (temppw->pw_shell) + 5;
|
2001-04-19 05:10:15 +08:00
|
|
|
if (needsize > bufsize)
|
|
|
|
return ERANGE;
|
2001-06-26 22:47:48 +08:00
|
|
|
|
2001-04-19 05:10:15 +08:00
|
|
|
/* make a copy of temppw */
|
|
|
|
*result = pwd;
|
|
|
|
pwd->pw_uid = temppw->pw_uid;
|
|
|
|
pwd->pw_gid = temppw->pw_gid;
|
2009-01-26 21:20:46 +08:00
|
|
|
buffer = stpcpy (pwd->pw_name = buffer, temppw->pw_name);
|
|
|
|
buffer = stpcpy (pwd->pw_passwd = buffer + 1, temppw->pw_passwd);
|
|
|
|
buffer = stpcpy (pwd->pw_gecos = buffer + 1, temppw->pw_gecos);
|
|
|
|
buffer = stpcpy (pwd->pw_dir = buffer + 1, temppw->pw_dir);
|
|
|
|
stpcpy (pwd->pw_shell = buffer + 1, temppw->pw_shell);
|
2003-09-09 06:03:20 +08:00
|
|
|
pwd->pw_comment = NULL;
|
2001-04-19 05:10:15 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-02-17 23:36:33 +08:00
|
|
|
/* getpwent functions are not reentrant. */
|
|
|
|
static pw_ent pwent;
|
|
|
|
|
|
|
|
void
|
|
|
|
pg_ent::clear_cache ()
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2014-02-17 23:36:33 +08:00
|
|
|
if (pg.curr_lines)
|
2014-02-10 03:44:56 +08:00
|
|
|
{
|
2014-02-17 23:36:33 +08:00
|
|
|
if (state > from_file)
|
|
|
|
cfree (group ? grp.g.gr_name : pwd.p.pw_name);
|
|
|
|
pg.curr_lines = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
pg_ent::setent (bool _group, int _enums, PCWSTR _enum_tdoms)
|
|
|
|
{
|
2014-02-20 02:29:52 +08:00
|
|
|
cygheap->dom.init ();
|
2014-02-17 23:36:33 +08:00
|
|
|
endent (_group);
|
|
|
|
if (!_enums && !_enum_tdoms)
|
|
|
|
{
|
2014-02-23 03:38:12 +08:00
|
|
|
/* This is the default, when called from the usual setpwent/setgrent
|
|
|
|
functions. */
|
2014-02-17 23:36:33 +08:00
|
|
|
enums = cygheap->pg.nss_db_enums ();
|
|
|
|
enum_tdoms = cygheap->pg.nss_db_enum_tdoms ();
|
2014-02-23 03:38:12 +08:00
|
|
|
if (_group)
|
|
|
|
{
|
|
|
|
from_files = cygheap->pg.nss_grp_files ();
|
|
|
|
from_db = cygheap->pg.nss_grp_db ();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
from_files = cygheap->pg.nss_pwd_files ();
|
|
|
|
from_db = cygheap->pg.nss_pwd_db ();
|
|
|
|
}
|
2014-02-17 23:36:33 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-02-23 03:38:12 +08:00
|
|
|
/* This case is when called from mkpasswd/mkgroup via cygwin_internal. */
|
2014-02-17 23:36:33 +08:00
|
|
|
enums = _enums;
|
|
|
|
enum_tdoms = _enum_tdoms;
|
2014-02-23 03:38:12 +08:00
|
|
|
from_files = false;
|
|
|
|
from_db = true;
|
2014-02-17 23:36:33 +08:00
|
|
|
}
|
2014-02-19 03:39:48 +08:00
|
|
|
state = from_cache;
|
2014-02-17 23:36:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
pg_ent::getent (void)
|
|
|
|
{
|
|
|
|
void *entry;
|
|
|
|
|
|
|
|
switch (state)
|
|
|
|
{
|
|
|
|
case rewound:
|
|
|
|
state = from_cache;
|
|
|
|
/*FALLTHRU*/
|
|
|
|
case from_cache:
|
|
|
|
if (nss_db_enum_caches ()
|
|
|
|
&& (entry = enumerate_caches ()))
|
|
|
|
return entry;
|
|
|
|
state = from_file;
|
|
|
|
/*FALLTHRU*/
|
|
|
|
case from_file:
|
|
|
|
if (from_files
|
|
|
|
&& nss_db_enum_files ()
|
|
|
|
&& (entry = enumerate_file ()))
|
|
|
|
return entry;
|
|
|
|
state = from_builtin;
|
|
|
|
/*FALLTHRU*/
|
|
|
|
case from_builtin:
|
|
|
|
if (from_db
|
|
|
|
&& nss_db_enum_builtin ()
|
|
|
|
&& (entry = enumerate_builtin ()))
|
|
|
|
return entry;
|
|
|
|
state = from_local;
|
|
|
|
/*FALLTHRU*/
|
|
|
|
case from_local:
|
|
|
|
if (from_db
|
|
|
|
&& nss_db_enum_local ()
|
|
|
|
&& (!cygheap->dom.member_machine ()
|
|
|
|
|| !nss_db_enum_primary ())
|
|
|
|
&& (entry = enumerate_local ()))
|
|
|
|
return entry;
|
|
|
|
state = from_sam;
|
|
|
|
/*FALLTHRU*/
|
|
|
|
case from_sam:
|
|
|
|
if (from_db
|
|
|
|
&& nss_db_enum_local ()
|
2014-02-19 03:39:48 +08:00
|
|
|
/* Domain controller? If so, sam and ad are one and the same
|
|
|
|
and "local ad" would list all domain accounts twice without
|
|
|
|
this test. */
|
|
|
|
&& (cygheap->dom.account_flat_name ()[0] != L'@'
|
|
|
|
|| !nss_db_enum_primary ())
|
2014-02-17 23:36:33 +08:00
|
|
|
&& (entry = enumerate_sam ()))
|
|
|
|
return entry;
|
|
|
|
state = from_ad;
|
|
|
|
/*FALLTHRU*/
|
|
|
|
case from_ad:
|
|
|
|
if (cygheap->dom.member_machine ()
|
|
|
|
&& from_db
|
|
|
|
&& (entry = enumerate_ad ()))
|
|
|
|
return entry;
|
|
|
|
state = finished;
|
|
|
|
/*FALLTHRU*/
|
|
|
|
case finished:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
pg_ent::endent (bool _group)
|
|
|
|
{
|
|
|
|
if (buf)
|
|
|
|
{
|
|
|
|
if (state == from_file)
|
|
|
|
free (buf);
|
|
|
|
else if (state == from_local || state == from_sam)
|
|
|
|
NetApiBufferFree (buf);
|
|
|
|
buf = NULL;
|
|
|
|
}
|
|
|
|
if (!pg.curr_lines)
|
|
|
|
{
|
|
|
|
if ((group = _group))
|
|
|
|
{
|
|
|
|
pg.init_grp ();
|
|
|
|
pg.pwdgrp_buf = (void *) &grp;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pg.init_pwd ();
|
|
|
|
pg.pwdgrp_buf = (void *) &pwd;
|
|
|
|
}
|
|
|
|
pg.max_lines = 1;
|
2014-02-10 03:44:56 +08:00
|
|
|
}
|
2014-02-17 23:36:33 +08:00
|
|
|
else
|
|
|
|
clear_cache ();
|
|
|
|
cldap.close ();
|
|
|
|
rl.close ();
|
|
|
|
cnt = max = resume = 0;
|
|
|
|
enums = 0;
|
|
|
|
enum_tdoms = NULL;
|
|
|
|
state = rewound;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
pg_ent::enumerate_file ()
|
|
|
|
{
|
|
|
|
void *entry;
|
|
|
|
|
|
|
|
if (!cnt)
|
|
|
|
{
|
|
|
|
pwdgrp &prf = group ? cygheap->pg.grp_cache.file
|
|
|
|
: cygheap->pg.pwd_cache.file;
|
2014-03-08 04:38:48 +08:00
|
|
|
if (prf.check_file ())
|
2014-02-17 23:36:33 +08:00
|
|
|
{
|
|
|
|
if (!buf)
|
|
|
|
buf = (char *) malloc (NT_MAX_PATH);
|
|
|
|
if (buf
|
|
|
|
&& !rl.init (prf.file_attr (), buf, NT_MAX_PATH))
|
|
|
|
{
|
|
|
|
free (buf);
|
|
|
|
buf = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
++cnt;
|
|
|
|
if ((entry = pg.add_account_post_fetch (rl.gets (), false)))
|
|
|
|
return entry;
|
|
|
|
rl.close ();
|
|
|
|
free (buf);
|
|
|
|
buf = NULL;
|
|
|
|
cnt = max = resume = 0;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
pg_ent::enumerate_builtin ()
|
|
|
|
{
|
2014-03-07 02:54:08 +08:00
|
|
|
static cygpsid *pwd_builtins[] = {
|
|
|
|
&well_known_system_sid,
|
|
|
|
&well_known_local_service_sid,
|
|
|
|
&well_known_network_service_sid,
|
|
|
|
&well_known_admins_sid,
|
|
|
|
&trusted_installer_sid,
|
2014-02-17 23:36:33 +08:00
|
|
|
NULL
|
|
|
|
};
|
2014-03-07 02:54:08 +08:00
|
|
|
static cygpsid *grp_builtins[] = {
|
|
|
|
&well_known_system_sid,
|
|
|
|
&trusted_installer_sid,
|
2014-02-17 23:36:33 +08:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2014-03-07 02:54:08 +08:00
|
|
|
cygpsid **builtins = group ? grp_builtins : pwd_builtins;
|
2014-02-17 23:36:33 +08:00
|
|
|
if (!builtins[cnt])
|
|
|
|
{
|
|
|
|
cnt = max = resume = 0;
|
|
|
|
return NULL;
|
|
|
|
}
|
2014-03-07 02:54:08 +08:00
|
|
|
cygsid sid (*builtins[cnt++]);
|
2014-02-17 23:36:33 +08:00
|
|
|
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
|
|
|
return pg.add_account_post_fetch (line, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
pg_ent::enumerate_sam ()
|
|
|
|
{
|
|
|
|
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 if (group)
|
|
|
|
ret = NetGroupEnum (NULL, 2, (PBYTE *) &buf, MAX_PREFERRED_LENGTH,
|
|
|
|
&max, &total, &resume);
|
|
|
|
else
|
|
|
|
ret = NetUserEnum (NULL, 20, FILTER_NORMAL_ACCOUNT, (PBYTE *) &buf,
|
|
|
|
MAX_PREFERRED_LENGTH, &max, &total,
|
|
|
|
(PDWORD) &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 (cygheap->dom.account_sid ());
|
|
|
|
sid_sub_auth (sid, sid_sub_auth_count (sid)) =
|
|
|
|
group ? ((PGROUP_INFO_2) buf)[cnt].grpi2_group_id
|
|
|
|
: ((PUSER_INFO_20) buf)[cnt].usri20_user_id;
|
|
|
|
++cnt;
|
|
|
|
++sid_sub_auth_count (sid);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
pg_ent::enumerate_ad ()
|
|
|
|
{
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
if (!cnt)
|
|
|
|
{
|
|
|
|
PDS_DOMAIN_TRUSTSW td;
|
2014-06-25 17:10:50 +08:00
|
|
|
int ret;
|
2014-02-17 23:36:33 +08:00
|
|
|
|
|
|
|
if (!resume)
|
|
|
|
{
|
|
|
|
++resume;
|
2014-06-25 17:10:50 +08:00
|
|
|
if (!nss_db_enum_primary ())
|
2014-02-17 23:36:33 +08:00
|
|
|
continue;
|
2014-06-25 17:10:50 +08:00
|
|
|
if ((ret = cldap.enumerate_ad_accounts (NULL, group)) != NO_ERROR)
|
|
|
|
{
|
|
|
|
cldap.close ();
|
|
|
|
set_errno (ret);
|
|
|
|
return NULL;
|
|
|
|
}
|
2014-02-17 23:36:33 +08:00
|
|
|
}
|
|
|
|
else if ((td = cygheap->dom.trusted_domain (resume - 1)))
|
|
|
|
{
|
|
|
|
++resume;
|
2014-03-19 21:05:33 +08:00
|
|
|
/* Ignore primary domain in list of trusted domains only if all
|
|
|
|
trusted domains are enumerated anyway. This handles an
|
|
|
|
annoying backward compatibility problem in mkpasswd/mkgroup.
|
|
|
|
Without this test, `mkpasswd -d PRIMARY_DOMAIN' wouldn't
|
|
|
|
work as expected. */
|
|
|
|
if (((enums & ENUM_TDOMS_ALL) && td->Flags & DS_DOMAIN_PRIMARY)
|
2014-02-17 23:36:33 +08:00
|
|
|
|| !td->DomainSid
|
|
|
|
|| (!nss_db_enum_tdom (td->NetbiosDomainName)
|
2014-06-25 17:10:50 +08:00
|
|
|
&& !nss_db_enum_tdom (td->DnsDomainName)))
|
2014-02-17 23:36:33 +08:00
|
|
|
continue;
|
2014-06-25 17:10:50 +08:00
|
|
|
if ((ret = cldap.enumerate_ad_accounts (td->DnsDomainName, group))
|
|
|
|
!= NO_ERROR)
|
|
|
|
{
|
|
|
|
cldap.close ();
|
|
|
|
set_errno (ret);
|
|
|
|
return NULL;
|
|
|
|
}
|
2014-02-17 23:36:33 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cldap.close ();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
++cnt;
|
|
|
|
cygsid sid;
|
2014-06-25 17:10:50 +08:00
|
|
|
int ret = cldap.next_account (sid);
|
|
|
|
if (ret == NO_ERROR)
|
2014-02-17 23:36:33 +08:00
|
|
|
{
|
|
|
|
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, &cldap);
|
2014-02-17 23:36:33 +08:00
|
|
|
if (line)
|
|
|
|
return pg.add_account_post_fetch (line, false);
|
2014-06-25 17:10:50 +08:00
|
|
|
ret = EIO;
|
|
|
|
}
|
|
|
|
if (ret != ENMFILE)
|
|
|
|
{
|
|
|
|
cldap.close ();
|
|
|
|
set_errno (ret);
|
|
|
|
return NULL;
|
2014-02-17 23:36:33 +08:00
|
|
|
}
|
|
|
|
cnt = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
pw_ent::enumerate_caches ()
|
|
|
|
{
|
2014-03-13 01:36:56 +08:00
|
|
|
switch (max)
|
2014-02-17 23:36:33 +08:00
|
|
|
{
|
2014-03-13 01:36:56 +08:00
|
|
|
case 0:
|
|
|
|
if (cygheap->pg.nss_cygserver_caching ())
|
|
|
|
{
|
|
|
|
pwdgrp &prc = cygheap->pg.pwd_cache.cygserver;
|
|
|
|
if (cnt < prc.cached_users ())
|
|
|
|
return &prc.passwd ()[cnt++].p;
|
|
|
|
}
|
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 &prf = cygheap->pg.pwd_cache.file;
|
|
|
|
prf.check_file ();
|
|
|
|
if (cnt < prf.cached_users ())
|
|
|
|
return &prf.passwd ()[cnt++].p;
|
|
|
|
}
|
|
|
|
cnt = 0;
|
|
|
|
max = 2;
|
|
|
|
/*FALLTHRU*/
|
|
|
|
default:
|
|
|
|
if (from_db)
|
|
|
|
{
|
|
|
|
pwdgrp &prw = cygheap->pg.pwd_cache.win;
|
|
|
|
if (cnt < prw.cached_users ())
|
|
|
|
return &prw.passwd ()[cnt++].p;
|
|
|
|
}
|
|
|
|
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 *
|
|
|
|
pw_ent::enumerate_local ()
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
2014-02-17 23:36:33 +08:00
|
|
|
|
|
|
|
struct passwd *
|
|
|
|
pw_ent::getpwent (void)
|
|
|
|
{
|
|
|
|
if (state == rewound)
|
|
|
|
setent (false);
|
|
|
|
else
|
|
|
|
clear_cache ();
|
|
|
|
return (struct passwd *) getent ();
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2000-02-21 13:20:38 +08:00
|
|
|
extern "C" void
|
2014-02-17 23:36:33 +08:00
|
|
|
setpwent ()
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2014-02-17 23:36:33 +08:00
|
|
|
pwent.setpwent ();
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" struct passwd *
|
|
|
|
getpwent (void)
|
|
|
|
{
|
|
|
|
return pwent.getpwent ();
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2000-02-21 13:20:38 +08:00
|
|
|
extern "C" void
|
2000-02-18 03:38:33 +08:00
|
|
|
endpwent (void)
|
|
|
|
{
|
2014-02-17 23:36:33 +08:00
|
|
|
pwent.endpwent ();
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2014-02-19 03:39:48 +08:00
|
|
|
/* *_filtered functions are called from mkpasswd */
|
|
|
|
void *
|
|
|
|
setpwent_filtered (int enums, PCWSTR enum_tdoms)
|
|
|
|
{
|
|
|
|
pw_ent *pw = new pw_ent;
|
|
|
|
if (pw)
|
|
|
|
pw->setpwent (enums, enum_tdoms);
|
|
|
|
return (void *) pw;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
getpwent_filtered (void *pw)
|
|
|
|
{
|
|
|
|
return (void *) ((pw_ent *) pw)->getpwent ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
endpwent_filtered (void *pw)
|
|
|
|
{
|
|
|
|
((pw_ent *) pw)->endpwent ();
|
|
|
|
}
|
|
|
|
|
2014-02-17 23:36:33 +08:00
|
|
|
#ifndef __x86_64__
|
|
|
|
extern "C" struct passwd *
|
|
|
|
getpwduid (__uid16_t)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2000-02-21 13:20:38 +08:00
|
|
|
extern "C" int
|
2014-01-17 22:53:04 +08:00
|
|
|
setpassent (int)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-04-04 17:57:17 +08:00
|
|
|
static void
|
|
|
|
_getpass_close_fd (void *arg)
|
|
|
|
{
|
|
|
|
if (arg)
|
|
|
|
fclose ((FILE *) arg);
|
|
|
|
}
|
|
|
|
|
2000-02-21 13:20:38 +08:00
|
|
|
extern "C" char *
|
2000-02-18 03:38:33 +08:00
|
|
|
getpass (const char * prompt)
|
|
|
|
{
|
2003-12-24 00:26:31 +08:00
|
|
|
char *pass = _my_tls.locals.pass;
|
2000-02-18 03:38:33 +08:00
|
|
|
struct termios ti, newti;
|
2012-07-09 20:57:03 +08:00
|
|
|
bool tc_set = false;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2012-04-04 17:57:17 +08:00
|
|
|
/* Try to use controlling tty in the first place. Use stdin and stderr
|
|
|
|
only as fallback. */
|
|
|
|
FILE *in = stdin, *err = stderr;
|
|
|
|
FILE *tty = fopen ("/dev/tty", "w+b");
|
|
|
|
pthread_cleanup_push (_getpass_close_fd, tty);
|
|
|
|
if (tty)
|
|
|
|
{
|
|
|
|
/* Set close-on-exec for obvious reasons. */
|
|
|
|
fcntl (fileno (tty), F_SETFD, fcntl (fileno (tty), F_GETFD) | FD_CLOEXEC);
|
|
|
|
in = err = tty;
|
|
|
|
}
|
2001-10-16 07:39:33 +08:00
|
|
|
|
2012-04-04 17:57:17 +08:00
|
|
|
/* Make sure to notice if stdin is closed. */
|
2012-07-09 20:57:03 +08:00
|
|
|
if (fileno (in) >= 0)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2012-04-04 17:57:17 +08:00
|
|
|
flockfile (in);
|
2012-07-09 20:57:03 +08:00
|
|
|
/* Change tty attributes if possible. */
|
|
|
|
if (!tcgetattr (fileno (in), &ti))
|
|
|
|
{
|
|
|
|
newti = ti;
|
|
|
|
newti.c_lflag &= ~(ECHO | ISIG); /* No echo, no signal handling. */
|
|
|
|
if (!tcsetattr (fileno (in), TCSANOW, &newti))
|
|
|
|
tc_set = true;
|
|
|
|
}
|
2012-04-04 17:57:17 +08:00
|
|
|
fputs (prompt, err);
|
|
|
|
fflush (err);
|
|
|
|
fgets (pass, _PASSWORD_LEN, in);
|
|
|
|
fprintf (err, "\n");
|
2012-07-09 20:57:03 +08:00
|
|
|
if (tc_set)
|
|
|
|
tcsetattr (fileno (in), TCSANOW, &ti);
|
2012-04-04 17:57:17 +08:00
|
|
|
funlockfile (in);
|
|
|
|
char *crlf = strpbrk (pass, "\r\n");
|
|
|
|
if (crlf)
|
|
|
|
*crlf = '\0';
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
2012-04-04 17:57:17 +08:00
|
|
|
pthread_cleanup_pop (1);
|
2000-02-18 03:38:33 +08:00
|
|
|
return pass;
|
|
|
|
}
|