2000-02-17 20:38:33 +01:00
|
|
|
/* passwd.cc: getpwnam () and friends
|
|
|
|
|
2003-01-10 13:32:49 +01:00
|
|
|
Copyright 1996, 1997, 1998, 2001, 2002, 2003 Red Hat, Inc.
|
2000-02-17 20:38:33 +01: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-02 18:28:18 +02:00
|
|
|
#include "winsup.h"
|
2000-02-17 20:38:33 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <pwd.h>
|
|
|
|
#include <stdio.h>
|
2000-08-22 07:10:20 +02:00
|
|
|
#include "cygerrno.h"
|
2001-07-26 21:22:24 +02:00
|
|
|
#include "security.h"
|
2001-08-07 10:56:22 +02: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 02:37:18 +02:00
|
|
|
#include "fhandler.h"
|
2001-10-01 06:10:07 +02:00
|
|
|
#include "dtable.h"
|
2000-08-12 07:35:42 +02:00
|
|
|
#include "pinfo.h"
|
2000-11-15 01:13:09 +01:00
|
|
|
#include "cygheap.h"
|
2000-09-07 18:23:51 +02:00
|
|
|
#include <sys/termios.h>
|
2001-09-09 18:52:37 +02:00
|
|
|
#include "pwdgrp.h"
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
/* Read /etc/passwd only once for better performance. This is done
|
|
|
|
on the first call that needs information from it. */
|
|
|
|
|
2003-01-20 03:57:54 +01:00
|
|
|
passwd *passwd_buf;
|
2003-01-21 07:58:11 +01:00
|
|
|
static pwdgrp pr (passwd_buf);
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
/* Parse /etc/passwd line into passwd structure. */
|
2003-01-20 03:57:54 +01:00
|
|
|
bool
|
2003-01-24 04:53:46 +01:00
|
|
|
pwdgrp::parse_passwd ()
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2003-01-20 03:57:54 +01:00
|
|
|
# define res (*passwd_buf)[curr_lines]
|
2003-01-27 01:16:01 +01:00
|
|
|
res.pw_name = next_str (':');
|
|
|
|
res.pw_passwd = next_str (':');
|
2003-01-27 18:00:17 +01:00
|
|
|
if (!next_num (res.pw_uid))
|
|
|
|
return false;
|
|
|
|
if (!next_num (res.pw_gid))
|
|
|
|
return false;
|
2003-01-26 06:38:38 +01:00
|
|
|
res.pw_comment = NULL;
|
2003-01-27 01:16:01 +01:00
|
|
|
res.pw_gecos = next_str (':');
|
|
|
|
res.pw_dir = next_str (':');
|
|
|
|
res.pw_shell = next_str (':');
|
2003-01-20 03:57:54 +01:00
|
|
|
return true;
|
|
|
|
# undef res
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Read in /etc/passwd and save contents in the password cache.
|
2003-01-17 06:18:30 +01:00
|
|
|
This sets pr to loaded or emulated so functions in this file can
|
2000-07-26 13:48:38 +02:00
|
|
|
tell that /etc/passwd has been read in or will be emulated. */
|
2003-01-21 07:58:11 +01:00
|
|
|
void
|
|
|
|
pwdgrp::read_passwd ()
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2003-01-26 06:38:38 +01:00
|
|
|
load ("/etc/passwd");
|
2003-01-21 07:58:11 +01:00
|
|
|
|
|
|
|
char strbuf[128] = "";
|
|
|
|
bool searchentry = true;
|
|
|
|
struct passwd *pw;
|
|
|
|
|
|
|
|
if (wincap.has_security ())
|
|
|
|
{
|
2003-01-31 18:00:42 +01:00
|
|
|
/* must be static */
|
2003-01-21 07:58:11 +01:00
|
|
|
static char NO_COPY pretty_ls[] = "????????:*:-1:-1:";
|
2003-01-26 06:38:38 +01:00
|
|
|
add_line (pretty_ls);
|
2003-01-21 07:58:11 +01:00
|
|
|
cygsid tu = cygheap->user.sid ();
|
|
|
|
tu.string (strbuf);
|
|
|
|
if (myself->uid == ILLEGAL_UID)
|
|
|
|
searchentry = !internal_getpwsid (tu);
|
|
|
|
}
|
|
|
|
else if (myself->uid == ILLEGAL_UID)
|
|
|
|
searchentry = !internal_getpwuid (DEFAULT_UID);
|
|
|
|
if (searchentry &&
|
|
|
|
(!(pw = internal_getpwnam (cygheap->user.name ())) ||
|
|
|
|
(myself->uid != ILLEGAL_UID &&
|
|
|
|
myself->uid != (__uid32_t) pw->pw_uid &&
|
|
|
|
!internal_getpwuid (myself->uid))))
|
2002-06-05 13:10:15 +02:00
|
|
|
{
|
2003-02-01 19:41:29 +01:00
|
|
|
static char linebuf[1024]; // must be static and
|
2004-05-28 21:50:07 +02:00
|
|
|
// should not be NO_COPY
|
2005-07-06 22:05:03 +02:00
|
|
|
cygheap->user.ontherange (CH_HOME, NULL);
|
2003-01-21 07:58:11 +01:00
|
|
|
snprintf (linebuf, sizeof (linebuf), "%s:*:%lu:%lu:,%s:%s:/bin/sh",
|
|
|
|
cygheap->user.name (),
|
2003-02-06 15:01:54 +01:00
|
|
|
myself->uid == ILLEGAL_UID ? UNKNOWN_UID : myself->uid,
|
2003-01-21 07:58:11 +01:00
|
|
|
myself->gid,
|
|
|
|
strbuf, getenv ("HOME") ?: "");
|
|
|
|
debug_printf ("Completing /etc/passwd: %s", linebuf);
|
2003-01-26 06:38:38 +01:00
|
|
|
add_line (linebuf);
|
2002-06-05 13:10:15 +02:00
|
|
|
}
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
2002-11-20 18:10:05 +01:00
|
|
|
struct passwd *
|
2003-02-04 15:58:04 +01:00
|
|
|
internal_getpwsid (cygpsid &sid)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2002-11-20 18:10:05 +01:00
|
|
|
struct passwd *pw;
|
|
|
|
char *ptr1, *ptr2, *endptr;
|
|
|
|
char sid_string[128] = {0,','};
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2003-02-01 19:41:29 +01:00
|
|
|
pr.refresh (false);
|
2002-11-20 18:10:05 +01:00
|
|
|
|
|
|
|
if (sid.string (sid_string + 2))
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2002-11-20 18:10:05 +01:00
|
|
|
endptr = strchr (sid_string + 2, 0) - 1;
|
2003-01-20 03:57:54 +01:00
|
|
|
for (int i = 0; i < pr.curr_lines; i++)
|
2002-11-20 18:10:05 +01:00
|
|
|
if ((pw = passwd_buf + i)->pw_dir > pw->pw_gecos + 8)
|
|
|
|
for (ptr1 = endptr, ptr2 = pw->pw_dir - 2;
|
|
|
|
*ptr1 == *ptr2; ptr2--)
|
|
|
|
if (!*--ptr1)
|
|
|
|
return pw;
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
2000-07-26 13:48:38 +02:00
|
|
|
return NULL;
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
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 13:43:49 +01:00
|
|
|
struct passwd *
|
2003-01-17 19:05:32 +01:00
|
|
|
internal_getpwuid (__uid32_t uid, bool check)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2003-01-21 07:58:11 +01:00
|
|
|
pr.refresh (check);
|
2001-06-26 16:47:48 +02:00
|
|
|
|
2003-01-20 03:57:54 +01:00
|
|
|
for (int i = 0; i < pr.curr_lines; i++)
|
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 13:43:49 +01:00
|
|
|
if (uid == (__uid32_t) passwd_buf[i].pw_uid)
|
|
|
|
return passwd_buf + i;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct passwd *
|
2003-01-17 19:05:32 +01:00
|
|
|
internal_getpwnam (const char *name, bool check)
|
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 13:43:49 +01:00
|
|
|
{
|
2003-01-21 07:58:11 +01:00
|
|
|
pr.refresh (check);
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2003-01-20 03:57:54 +01:00
|
|
|
for (int i = 0; i < pr.curr_lines; i++)
|
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 13:43:49 +01:00
|
|
|
/* on Windows NT user names are case-insensitive */
|
|
|
|
if (strcasematch (name, passwd_buf[i].pw_name))
|
|
|
|
return passwd_buf + i;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
extern "C" struct passwd *
|
|
|
|
getpwuid32 (__uid32_t uid)
|
|
|
|
{
|
2003-12-07 23:37:12 +01:00
|
|
|
struct passwd *temppw = internal_getpwuid (uid, true);
|
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 13:43:49 +01:00
|
|
|
pthread_testcancel ();
|
|
|
|
return temppw;
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
2002-05-29 17:04:29 +02:00
|
|
|
extern "C" struct passwd *
|
|
|
|
getpwuid (__uid16_t uid)
|
|
|
|
{
|
|
|
|
return getpwuid32 (uid16touid32 (uid));
|
|
|
|
}
|
|
|
|
|
2001-06-26 16:47:48 +02:00
|
|
|
extern "C" int
|
2002-05-29 17:04:29 +02:00
|
|
|
getpwuid_r32 (__uid32_t uid, struct passwd *pwd, char *buffer, size_t bufsize, struct passwd **result)
|
2001-04-18 23:10:15 +02:00
|
|
|
{
|
|
|
|
*result = NULL;
|
|
|
|
|
|
|
|
if (!pwd || !buffer)
|
|
|
|
return ERANGE;
|
|
|
|
|
2003-12-07 23:37:12 +01:00
|
|
|
struct passwd *temppw = internal_getpwuid (uid, true);
|
2002-09-22 05:38:57 +02:00
|
|
|
pthread_testcancel ();
|
2001-04-18 23:10:15 +02:00
|
|
|
if (!temppw)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* check needed buffer size. */
|
2001-04-24 23:45:20 +02:00
|
|
|
size_t needsize = strlen (temppw->pw_name) + strlen (temppw->pw_dir) +
|
2001-06-26 16:47:48 +02:00
|
|
|
strlen (temppw->pw_shell) + strlen (temppw->pw_gecos) +
|
2003-01-02 01:03:23 +01:00
|
|
|
strlen (temppw->pw_passwd) + 5;
|
2001-04-18 23:10:15 +02: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;
|
|
|
|
pwd->pw_name = buffer;
|
2001-04-24 23:45:20 +02:00
|
|
|
pwd->pw_dir = pwd->pw_name + strlen (temppw->pw_name) + 1;
|
|
|
|
pwd->pw_shell = pwd->pw_dir + strlen (temppw->pw_dir) + 1;
|
|
|
|
pwd->pw_gecos = pwd->pw_shell + strlen (temppw->pw_shell) + 1;
|
2003-09-08 23:44:53 +02:00
|
|
|
pwd->pw_comment = NULL;
|
2001-04-24 23:52:57 +02:00
|
|
|
pwd->pw_passwd = pwd->pw_gecos + strlen (temppw->pw_gecos) + 1;
|
2001-04-18 23:10:15 +02:00
|
|
|
strcpy (pwd->pw_name, temppw->pw_name);
|
|
|
|
strcpy (pwd->pw_dir, temppw->pw_dir);
|
|
|
|
strcpy (pwd->pw_shell, temppw->pw_shell);
|
2001-04-24 23:45:20 +02:00
|
|
|
strcpy (pwd->pw_gecos, temppw->pw_gecos);
|
2001-04-24 23:52:57 +02:00
|
|
|
strcpy (pwd->pw_passwd, temppw->pw_passwd);
|
2001-04-18 23:10:15 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-05-29 17:04:29 +02: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);
|
|
|
|
}
|
|
|
|
|
2000-02-21 06:20:38 +01:00
|
|
|
extern "C" struct passwd *
|
2000-02-17 20:38:33 +01:00
|
|
|
getpwnam (const char *name)
|
|
|
|
{
|
2003-12-07 23:37:12 +01:00
|
|
|
struct passwd *temppw = internal_getpwnam (name, true);
|
2002-09-22 05:38:57 +02:00
|
|
|
pthread_testcancel ();
|
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 13:43:49 +01:00
|
|
|
return temppw;
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
2001-04-18 23:10:15 +02:00
|
|
|
|
2001-06-26 16:47:48 +02:00
|
|
|
/* the max size buffer we can expect to
|
2001-04-18 23:10:15 +02: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;
|
|
|
|
|
2003-12-07 23:37:12 +01:00
|
|
|
struct passwd *temppw = internal_getpwnam (nam, true);
|
2002-09-22 05:38:57 +02:00
|
|
|
pthread_testcancel ();
|
2001-04-21 16:23:47 +02:00
|
|
|
|
2001-04-18 23:10:15 +02:00
|
|
|
if (!temppw)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* check needed buffer size. */
|
2001-04-24 23:45:20 +02:00
|
|
|
size_t needsize = strlen (temppw->pw_name) + strlen (temppw->pw_dir) +
|
2001-06-26 16:47:48 +02:00
|
|
|
strlen (temppw->pw_shell) + strlen (temppw->pw_gecos) +
|
2001-04-24 23:52:57 +02:00
|
|
|
strlen (temppw->pw_passwd) + 5;
|
2001-04-18 23:10:15 +02:00
|
|
|
if (needsize > bufsize)
|
|
|
|
return ERANGE;
|
2001-06-26 16:47:48 +02:00
|
|
|
|
2001-04-18 23:10:15 +02:00
|
|
|
/* make a copy of temppw */
|
|
|
|
*result = pwd;
|
|
|
|
pwd->pw_uid = temppw->pw_uid;
|
|
|
|
pwd->pw_gid = temppw->pw_gid;
|
|
|
|
pwd->pw_name = buffer;
|
2001-04-24 23:45:20 +02:00
|
|
|
pwd->pw_dir = pwd->pw_name + strlen (temppw->pw_name) + 1;
|
|
|
|
pwd->pw_shell = pwd->pw_dir + strlen (temppw->pw_dir) + 1;
|
|
|
|
pwd->pw_gecos = pwd->pw_shell + strlen (temppw->pw_shell) + 1;
|
2003-09-09 00:03:20 +02:00
|
|
|
pwd->pw_comment = NULL;
|
2001-04-24 23:52:57 +02:00
|
|
|
pwd->pw_passwd = pwd->pw_gecos + strlen (temppw->pw_gecos) + 1;
|
2001-04-18 23:10:15 +02:00
|
|
|
strcpy (pwd->pw_name, temppw->pw_name);
|
|
|
|
strcpy (pwd->pw_dir, temppw->pw_dir);
|
|
|
|
strcpy (pwd->pw_shell, temppw->pw_shell);
|
2001-04-24 23:45:20 +02:00
|
|
|
strcpy (pwd->pw_gecos, temppw->pw_gecos);
|
2001-04-24 23:52:57 +02:00
|
|
|
strcpy (pwd->pw_passwd, temppw->pw_passwd);
|
2001-04-18 23:10:15 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-02-21 06:20:38 +01:00
|
|
|
extern "C" struct passwd *
|
2000-02-17 20:38:33 +01:00
|
|
|
getpwent (void)
|
|
|
|
{
|
2003-12-23 17:26:31 +01:00
|
|
|
if (_my_tls.locals.pw_pos == 0)
|
2003-02-01 19:41:29 +01:00
|
|
|
pr.refresh (true);
|
2003-12-23 17:26:31 +01:00
|
|
|
if (_my_tls.locals.pw_pos < pr.curr_lines)
|
|
|
|
return passwd_buf + _my_tls.locals.pw_pos++;
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2000-02-21 06:20:38 +01:00
|
|
|
extern "C" struct passwd *
|
* (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 14:38:51 +01:00
|
|
|
getpwduid (__uid16_t)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2000-02-21 06:20:38 +01:00
|
|
|
extern "C" void
|
2000-02-17 20:38:33 +01:00
|
|
|
setpwent (void)
|
|
|
|
{
|
2003-12-23 17:26:31 +01:00
|
|
|
_my_tls.locals.pw_pos = 0;
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
2000-02-21 06:20:38 +01:00
|
|
|
extern "C" void
|
2000-02-17 20:38:33 +01:00
|
|
|
endpwent (void)
|
|
|
|
{
|
2003-12-23 17:26:31 +01:00
|
|
|
_my_tls.locals.pw_pos = 0;
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
2000-02-21 06:20:38 +01:00
|
|
|
extern "C" int
|
2000-02-17 20:38:33 +01:00
|
|
|
setpassent ()
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-02-21 06:20:38 +01:00
|
|
|
extern "C" char *
|
2000-02-17 20:38:33 +01:00
|
|
|
getpass (const char * prompt)
|
|
|
|
{
|
2003-12-23 17:26:31 +01:00
|
|
|
char *pass = _my_tls.locals.pass;
|
2000-02-17 20:38:33 +01:00
|
|
|
struct termios ti, newti;
|
|
|
|
|
2001-10-16 01:39:33 +02:00
|
|
|
cygheap_fdget fhstdin (0);
|
|
|
|
|
|
|
|
if (fhstdin < 0)
|
|
|
|
pass[0] = '\0';
|
2000-02-17 20:38:33 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
fhstdin->tcgetattr (&ti);
|
|
|
|
newti = ti;
|
|
|
|
newti.c_lflag &= ~ECHO;
|
|
|
|
fhstdin->tcsetattr (TCSANOW, &newti);
|
|
|
|
fputs (prompt, stderr);
|
|
|
|
fgets (pass, _PASSWORD_LEN, stdin);
|
|
|
|
fprintf (stderr, "\n");
|
|
|
|
for (int i=0; pass[i]; i++)
|
|
|
|
if (pass[i] == '\r' || pass[i] == '\n')
|
|
|
|
pass[i] = '\0';
|
|
|
|
fhstdin->tcsetattr (TCSANOW, &ti);
|
|
|
|
}
|
|
|
|
return pass;
|
|
|
|
}
|