2000-02-18 03:38:33 +08:00
|
|
|
/* uinfo.cc: user info (uid, gid, etc...)
|
|
|
|
|
|
|
|
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. */
|
|
|
|
|
|
|
|
#include "winsup.h"
|
2014-02-10 03:44:56 +08:00
|
|
|
#include <iptypes.h>
|
|
|
|
#include <lm.h>
|
|
|
|
#include <ntsecapi.h>
|
2001-05-01 02:21:48 +08:00
|
|
|
#include <wininet.h>
|
2014-02-10 03:44:56 +08:00
|
|
|
#include <unistd.h>
|
2000-02-18 03:38:33 +08:00
|
|
|
#include <stdlib.h>
|
2014-02-10 03:44:56 +08:00
|
|
|
#include <stdio.h>
|
2008-07-25 02:25:52 +08:00
|
|
|
#include <wchar.h>
|
2000-11-16 17:53:26 +08:00
|
|
|
#include <sys/cygwin.h>
|
2005-01-13 06:40:46 +08:00
|
|
|
#include "cygerrno.h"
|
2000-08-12 13:35:42 +08:00
|
|
|
#include "pinfo.h"
|
2001-10-01 12:10:07 +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-04-19 05:10:15 +08:00
|
|
|
#include "dtable.h"
|
2000-11-15 08:13:09 +08:00
|
|
|
#include "cygheap.h"
|
2008-07-25 02:25:52 +08:00
|
|
|
#include "shared_info.h"
|
2000-09-08 10:56:55 +08:00
|
|
|
#include "registry.h"
|
2002-06-15 02:01:21 +08:00
|
|
|
#include "child_info.h"
|
2002-06-29 10:36:08 +08:00
|
|
|
#include "environ.h"
|
2008-03-12 20:41:50 +08:00
|
|
|
#include "tls_pbuf.h"
|
2014-02-10 03:44:56 +08:00
|
|
|
#include "miscfuncs.h"
|
2007-07-19 16:36:32 +08:00
|
|
|
#include "ntdll.h"
|
2014-02-10 03:44:56 +08:00
|
|
|
#include "ldap.h"
|
2014-03-13 01:36:56 +08:00
|
|
|
#include "cygserver_pwdgrp.h"
|
2014-02-10 03:44:56 +08:00
|
|
|
|
2003-09-11 05:01:40 +08:00
|
|
|
/* Initialize the part of cygheap_user that does not depend on files.
|
2016-06-16 00:04:00 +08:00
|
|
|
The information is used in shared.cc to create the shared user_info
|
|
|
|
region. Final initialization occurs in uinfo_init */
|
2002-06-15 02:01:21 +08:00
|
|
|
void
|
2003-11-29 04:55:59 +08:00
|
|
|
cygheap_user::init ()
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2010-09-26 23:45:10 +08:00
|
|
|
WCHAR user_name[UNLEN + 1];
|
2010-09-28 22:49:31 +08:00
|
|
|
DWORD user_name_len = UNLEN + 1;
|
2003-09-11 05:01:40 +08:00
|
|
|
|
2016-06-16 01:48:43 +08:00
|
|
|
/* This method is only called if a Cygwin process gets started by a
|
|
|
|
native Win32 process. Try to get the username from the environment,
|
2011-03-31 23:33:53 +08:00
|
|
|
first USERNAME (Win32), then USER (POSIX). If that fails (which is
|
|
|
|
very unlikely), it only has an impact if we don't have an entry in
|
|
|
|
/etc/passwd for this user either. In that case the username sticks
|
|
|
|
to "unknown". Since this is called early in initialization, and
|
2016-06-16 01:48:43 +08:00
|
|
|
since we don't want to pull in a dependency to any other DLL except
|
2011-03-31 23:33:53 +08:00
|
|
|
ntdll and kernel32 at this early stage, don't call GetUserName,
|
|
|
|
GetUserNameEx, NetWkstaUserGetInfo, etc. */
|
|
|
|
if (GetEnvironmentVariableW (L"USERNAME", user_name, user_name_len)
|
|
|
|
|| GetEnvironmentVariableW (L"USER", user_name, user_name_len))
|
|
|
|
{
|
2015-10-22 20:22:07 +08:00
|
|
|
char mb_user_name[user_name_len = sys_wcstombs (NULL, 0, user_name) + 1];
|
2011-03-31 23:33:53 +08:00
|
|
|
sys_wcstombs (mb_user_name, user_name_len, user_name);
|
|
|
|
set_name (mb_user_name);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
set_name ("unknown");
|
2000-11-15 08:13:09 +08:00
|
|
|
|
2011-04-29 15:34:05 +08:00
|
|
|
NTSTATUS status;
|
|
|
|
ULONG size;
|
2004-02-06 18:37:37 +08:00
|
|
|
PSECURITY_DESCRIPTOR psd;
|
2003-09-27 09:56:36 +08:00
|
|
|
|
2011-04-29 15:34:05 +08:00
|
|
|
status = NtQueryInformationToken (hProcToken, TokenPrimaryGroup,
|
|
|
|
&groups.pgsid, sizeof (cygsid), &size);
|
|
|
|
if (!NT_SUCCESS (status))
|
2013-04-23 17:44:36 +08:00
|
|
|
system_printf ("NtQueryInformationToken (TokenPrimaryGroup), %y", status);
|
2003-09-27 09:56:36 +08:00
|
|
|
|
|
|
|
/* Get the SID from current process and store it in effec_cygsid */
|
2011-04-29 15:34:05 +08:00
|
|
|
status = NtQueryInformationToken (hProcToken, TokenUser, &effec_cygsid,
|
|
|
|
sizeof (cygsid), &size);
|
|
|
|
if (!NT_SUCCESS (status))
|
2003-09-27 09:56:36 +08:00
|
|
|
{
|
2013-04-23 17:44:36 +08:00
|
|
|
system_printf ("NtQueryInformationToken (TokenUser), %y", status);
|
2005-04-03 21:06:43 +08:00
|
|
|
return;
|
2003-09-27 09:56:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set token owner to the same value as token user */
|
2011-04-29 15:34:05 +08:00
|
|
|
status = NtSetInformationToken (hProcToken, TokenOwner, &effec_cygsid,
|
|
|
|
sizeof (cygsid));
|
|
|
|
if (!NT_SUCCESS (status))
|
2014-05-09 03:33:07 +08:00
|
|
|
debug_printf ("NtSetInformationToken (TokenOwner), %y", status);
|
2003-09-27 09:56:36 +08:00
|
|
|
|
2004-02-06 18:37:37 +08:00
|
|
|
/* Standard way to build a security descriptor with the usual DACL */
|
2005-06-08 03:31:42 +08:00
|
|
|
PSECURITY_ATTRIBUTES sa_buf = (PSECURITY_ATTRIBUTES) alloca (1024);
|
2005-04-03 21:06:43 +08:00
|
|
|
psd = (PSECURITY_DESCRIPTOR)
|
2011-06-06 13:02:13 +08:00
|
|
|
(sec_user_nih (sa_buf, sid()))->lpSecurityDescriptor;
|
2003-09-27 09:56:36 +08:00
|
|
|
|
2011-04-28 17:53:11 +08:00
|
|
|
BOOLEAN acl_exists, dummy;
|
2004-02-06 18:37:37 +08:00
|
|
|
TOKEN_DEFAULT_DACL dacl;
|
2011-04-28 17:53:11 +08:00
|
|
|
|
|
|
|
status = RtlGetDaclSecurityDescriptor (psd, &acl_exists, &dacl.DefaultDacl,
|
|
|
|
&dummy);
|
|
|
|
if (NT_SUCCESS (status) && acl_exists && dacl.DefaultDacl)
|
2004-02-06 18:37:37 +08:00
|
|
|
{
|
2007-07-19 16:36:32 +08:00
|
|
|
|
2004-02-06 18:37:37 +08:00
|
|
|
/* Set the default DACL and the process DACL */
|
2011-04-29 15:34:05 +08:00
|
|
|
status = NtSetInformationToken (hProcToken, TokenDefaultDacl, &dacl,
|
|
|
|
sizeof (dacl));
|
|
|
|
if (!NT_SUCCESS (status))
|
2013-04-23 17:44:36 +08:00
|
|
|
system_printf ("NtSetInformationToken (TokenDefaultDacl), %y", status);
|
2009-12-19 04:32:04 +08:00
|
|
|
if ((status = NtSetSecurityObject (NtCurrentProcess (),
|
|
|
|
DACL_SECURITY_INFORMATION, psd)))
|
2013-04-23 17:44:36 +08:00
|
|
|
system_printf ("NtSetSecurityObject, %y", status);
|
2003-09-11 05:01:40 +08:00
|
|
|
}
|
2004-02-06 18:37:37 +08:00
|
|
|
else
|
2004-09-03 09:53:12 +08:00
|
|
|
system_printf("Cannot get dacl, %E");
|
2003-09-11 05:01:40 +08:00
|
|
|
}
|
|
|
|
|
2016-03-24 00:51:03 +08:00
|
|
|
/* Check if sid is an enabled SID in the token group list of the current
|
|
|
|
effective token. Note that we only check for ENABLED groups, not for
|
|
|
|
INTEGRITY_ENABLED. The latter just doesn't make sense in our scenario
|
|
|
|
of using the group as primary group.
|
|
|
|
|
|
|
|
This needs careful checking should we use check_token_membership in other
|
|
|
|
circumstances. */
|
2018-02-22 04:40:01 +08:00
|
|
|
bool
|
2019-01-30 19:18:03 +08:00
|
|
|
check_token_membership (PSID sid)
|
2016-03-24 00:51:03 +08:00
|
|
|
{
|
|
|
|
NTSTATUS status;
|
|
|
|
ULONG size;
|
|
|
|
tmp_pathbuf tp;
|
|
|
|
PTOKEN_GROUPS groups = (PTOKEN_GROUPS) tp.w_get ();
|
|
|
|
|
2019-01-30 19:18:03 +08:00
|
|
|
/* If impersonated, use impersonation token. */
|
|
|
|
HANDLE tok = cygheap->user.issetuid () ? cygheap->user.primary_token ()
|
|
|
|
: hProcToken;
|
2016-03-24 00:51:03 +08:00
|
|
|
status = NtQueryInformationToken (tok, TokenGroups, groups, 2 * NT_MAX_PATH,
|
|
|
|
&size);
|
|
|
|
if (!NT_SUCCESS (status))
|
|
|
|
debug_printf ("NtQueryInformationToken (TokenGroups) %y", status);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (DWORD pg = 0; pg < groups->GroupCount; ++pg)
|
|
|
|
if (RtlEqualSid (sid, groups->Groups[pg].Sid)
|
|
|
|
&& (groups->Groups[pg].Attributes & SE_GROUP_ENABLED))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-02-22 04:40:01 +08:00
|
|
|
static void
|
2003-09-11 05:01:40 +08:00
|
|
|
internal_getlogin (cygheap_user &user)
|
|
|
|
{
|
2014-02-28 19:37:02 +08:00
|
|
|
struct passwd *pwd;
|
|
|
|
struct group *pgrp, *grp, *grp2;
|
2014-02-27 20:57:27 +08:00
|
|
|
cyg_ldap cldap;
|
2003-09-11 05:01:40 +08:00
|
|
|
|
2014-02-28 19:37:02 +08:00
|
|
|
/* Fetch (and potentially generate) passwd and group entries for the user
|
|
|
|
and the primary group in the token. */
|
|
|
|
pwd = internal_getpwsid (user.sid (), &cldap);
|
|
|
|
pgrp = internal_getgrsid (user.groups.pgsid, &cldap);
|
2014-03-13 01:36:56 +08:00
|
|
|
if (!cygheap->pg.nss_cygserver_caching ())
|
2015-03-17 22:42:59 +08:00
|
|
|
internal_getgroups (0, NULL, &cldap);
|
2014-02-28 19:37:02 +08:00
|
|
|
if (!pwd)
|
|
|
|
debug_printf ("user not found in passwd DB");
|
2002-11-21 01:10:05 +08:00
|
|
|
else
|
2002-06-15 02:01:21 +08:00
|
|
|
{
|
2007-02-23 23:15:50 +08:00
|
|
|
cygsid gsid;
|
|
|
|
|
2014-02-28 19:37:02 +08:00
|
|
|
user.set_name (pwd->pw_name);
|
|
|
|
myself->uid = pwd->pw_uid;
|
2022-12-02 23:37:33 +08:00
|
|
|
myself->gid = pgrp ? pgrp->gr_gid : pwd->pw_gid;
|
|
|
|
|
2014-05-07 22:49:54 +08:00
|
|
|
/* If the primary group in the passwd DB is different from the primary
|
2022-12-02 23:37:33 +08:00
|
|
|
group in the user token, and if the primary group is the default
|
|
|
|
group of a local user ("None", localized), we have to find the SID
|
|
|
|
of that group and try to override the token primary group. Also
|
|
|
|
makes sure we're not on a domain controller, where account_sid ()
|
|
|
|
== primary_sid (). */
|
|
|
|
gsid = cygheap->dom.account_sid ();
|
|
|
|
gsid.append (DOMAIN_GROUP_RID_USERS);
|
|
|
|
if (!pgrp
|
|
|
|
|| (myself->gid != pgrp->gr_gid
|
|
|
|
&& cygheap->dom.account_sid () != cygheap->dom.primary_sid ()
|
|
|
|
&& RtlEqualSid (gsid, user.groups.pgsid)))
|
2002-11-27 10:26:44 +08:00
|
|
|
{
|
2014-02-28 19:37:02 +08:00
|
|
|
if (gsid.getfromgr (grp = internal_getgrgid (pwd->pw_gid, &cldap)))
|
2002-11-21 01:10:05 +08:00
|
|
|
{
|
2014-02-28 19:37:02 +08:00
|
|
|
/* We might have a group file with a group entry for the current
|
|
|
|
user's primary group, but the current user has no entry in
|
|
|
|
passwd. If so, pw_gid is taken from windows and might
|
|
|
|
disagree with gr_gid from the group file. Overwrite it. */
|
|
|
|
if ((grp2 = internal_getgrsid (gsid, &cldap)) && grp2 != grp)
|
|
|
|
myself->gid = pwd->pw_gid = grp2->gr_gid;
|
2016-03-24 00:51:03 +08:00
|
|
|
/* Set primary group to the group in /etc/passwd, *iff*
|
|
|
|
the group in /etc/passwd is in the token *and* enabled. */
|
2014-02-28 19:37:02 +08:00
|
|
|
if (gsid != user.groups.pgsid)
|
|
|
|
{
|
2016-03-24 00:51:03 +08:00
|
|
|
NTSTATUS status = STATUS_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
if (check_token_membership (gsid))
|
|
|
|
{
|
|
|
|
status = NtSetInformationToken (hProcToken,
|
|
|
|
TokenPrimaryGroup,
|
|
|
|
&gsid, sizeof gsid);
|
|
|
|
if (!NT_SUCCESS (status))
|
|
|
|
debug_printf ("NtSetInformationToken "
|
|
|
|
"(TokenPrimaryGroup), %y", status);
|
|
|
|
}
|
2014-02-28 19:37:02 +08:00
|
|
|
if (!NT_SUCCESS (status))
|
|
|
|
{
|
|
|
|
/* Revert the primary group setting and override the
|
|
|
|
setting in the passwd entry. */
|
|
|
|
if (pgrp)
|
|
|
|
myself->gid = pwd->pw_gid = pgrp->gr_gid;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
user.groups.pgsid = gsid;
|
|
|
|
clear_procimptoken ();
|
|
|
|
}
|
2002-11-21 01:10:05 +08:00
|
|
|
}
|
2014-02-28 19:37:02 +08:00
|
|
|
else
|
|
|
|
debug_printf ("group not found in group DB");
|
2002-11-21 01:10:05 +08:00
|
|
|
}
|
2002-06-15 02:01:21 +08:00
|
|
|
}
|
2014-02-28 19:37:02 +08:00
|
|
|
cygheap->user.ontherange (CH_HOME, pwd);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
uinfo_init ()
|
|
|
|
{
|
2003-06-30 21:07:36 +08:00
|
|
|
if (child_proc_info && !cygheap->user.has_impersonation_tokens ())
|
2003-06-09 21:29:12 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (!child_proc_info)
|
2016-06-16 01:48:43 +08:00
|
|
|
internal_getlogin (cygheap->user); /* Set cygheap->user. */
|
2003-06-09 21:29:12 +08:00
|
|
|
/* Conditions must match those in spawn to allow starting child
|
|
|
|
processes with ruid != euid and rgid != egid. */
|
|
|
|
else if (cygheap->user.issetuid ()
|
2004-05-29 03:50:07 +08:00
|
|
|
&& cygheap->user.saved_uid == cygheap->user.real_uid
|
2003-09-16 17:24:52 +08:00
|
|
|
&& cygheap->user.saved_gid == cygheap->user.real_gid
|
2009-10-13 18:23:31 +08:00
|
|
|
&& !cygheap->user.groups.issetgroups ()
|
|
|
|
&& !cygheap->user.setuid_to_restricted)
|
2003-01-25 18:36:46 +08:00
|
|
|
{
|
2003-06-30 21:07:36 +08:00
|
|
|
cygheap->user.reimpersonate ();
|
2003-06-09 21:29:12 +08:00
|
|
|
return;
|
2003-01-25 18:36:46 +08:00
|
|
|
}
|
2003-06-09 21:29:12 +08:00
|
|
|
else
|
2003-06-30 21:07:36 +08:00
|
|
|
cygheap->user.close_impersonation_tokens ();
|
2003-06-09 21:29:12 +08:00
|
|
|
|
2003-09-16 17:24:52 +08:00
|
|
|
cygheap->user.saved_uid = cygheap->user.real_uid = myself->uid;
|
|
|
|
cygheap->user.saved_gid = cygheap->user.real_gid = myself->gid;
|
2004-10-28 09:46:01 +08:00
|
|
|
cygheap->user.external_token = NO_IMPERSONATION;
|
|
|
|
cygheap->user.internal_token = NO_IMPERSONATION;
|
2005-04-03 21:06:43 +08:00
|
|
|
cygheap->user.curr_primary_token = NO_IMPERSONATION;
|
2007-07-17 04:01:15 +08:00
|
|
|
cygheap->user.curr_imp_token = NO_IMPERSONATION;
|
2009-10-13 18:23:31 +08:00
|
|
|
cygheap->user.ext_token_is_restricted = false;
|
|
|
|
cygheap->user.curr_token_is_restricted = false;
|
|
|
|
cygheap->user.setuid_to_restricted = false;
|
2003-09-16 17:24:52 +08:00
|
|
|
cygheap->user.set_saved_sid (); /* Update the original sid */
|
2009-10-18 17:07:13 +08:00
|
|
|
cygheap->user.deimpersonate ();
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2004-05-18 00:06:02 +08:00
|
|
|
extern "C" int
|
|
|
|
getlogin_r (char *name, size_t namesize)
|
|
|
|
{
|
2011-05-17 01:58:21 +08:00
|
|
|
const char *login = cygheap->user.name ();
|
2004-05-18 00:06:02 +08:00
|
|
|
size_t len = strlen (login) + 1;
|
|
|
|
if (len > namesize)
|
|
|
|
return ERANGE;
|
2014-08-22 17:21:33 +08:00
|
|
|
__try
|
|
|
|
{
|
|
|
|
strncpy (name, login, len);
|
|
|
|
}
|
|
|
|
__except (NO_ERROR)
|
|
|
|
{
|
|
|
|
return EFAULT;
|
|
|
|
}
|
|
|
|
__endtry
|
2004-05-18 00:06:02 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
extern "C" char *
|
|
|
|
getlogin (void)
|
|
|
|
{
|
2011-05-17 01:58:21 +08:00
|
|
|
static char username[UNLEN];
|
|
|
|
int ret = getlogin_r (username, UNLEN);
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
set_errno (ret);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return username;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2013-04-23 17:44:36 +08:00
|
|
|
extern "C" uid_t
|
Cygwin: simplify some function names
Remove "32" or "64" from each of the following names: acl32,
aclcheck32, aclfrommode32, aclfrompbits32, aclfromtext32, aclsort32,
acltomode32, acltopbits32, acltotext32, facl32, fchown32, fcntl64,
fstat64, _fstat64, _fstat64_r, ftruncate64, getgid32, getgrent32,
getgrgid32, getgrnam32, getgroups32, getpwuid32, getpwuid_r32,
getuid32, getuid32, initgroups32, lseek64, lstat64, mknod32, mmap64,
setegid32, seteuid32, setgid32, setgroups32, setregid32, setreuid32,
setuid32, stat64, _stat64_r, truncate64.
Remove prototypes and macro definitions of these names.
Remove "#ifndef __INSIDE_CYGWIN__" from some headers so that the new
names will be available when compiling Cygwin.
Remove aliases that are no longer needed.
Include <unistd.h> in fhandler_clipboard.cc for the declarations of
geteuid and getegid.
2022-05-23 03:18:48 +08:00
|
|
|
getuid (void)
|
2002-05-29 23:04:29 +08:00
|
|
|
{
|
|
|
|
return cygheap->user.real_uid;
|
|
|
|
}
|
|
|
|
|
2013-04-23 17:44:36 +08:00
|
|
|
extern "C" gid_t
|
Cygwin: simplify some function names
Remove "32" or "64" from each of the following names: acl32,
aclcheck32, aclfrommode32, aclfrompbits32, aclfromtext32, aclsort32,
acltomode32, acltopbits32, acltotext32, facl32, fchown32, fcntl64,
fstat64, _fstat64, _fstat64_r, ftruncate64, getgid32, getgrent32,
getgrgid32, getgrnam32, getgroups32, getpwuid32, getpwuid_r32,
getuid32, getuid32, initgroups32, lseek64, lstat64, mknod32, mmap64,
setegid32, seteuid32, setgid32, setgroups32, setregid32, setreuid32,
setuid32, stat64, _stat64_r, truncate64.
Remove prototypes and macro definitions of these names.
Remove "#ifndef __INSIDE_CYGWIN__" from some headers so that the new
names will be available when compiling Cygwin.
Remove aliases that are no longer needed.
Include <unistd.h> in fhandler_clipboard.cc for the declarations of
geteuid and getegid.
2022-05-23 03:18:48 +08:00
|
|
|
getgid (void)
|
Change internal gid datatype from __gid16_t to __gid32_t
throughout.
* cygwin.din: Export new symbols chown32, fchown32, getegid32,
getgid32, getgrgid32, getgrnam32, getgroups32, initgroups32, lchown32,
setgid32, setegid32, getgrent32.
* grp.cc (grp32togrp16): New static function.
(getgrgid32): New function.
(getgrnam32): Ditto.
(getgrent32): Ditto.
(getgroups32): Change name of internal function from getgroups.
(getgroups32): New function.
(initgroups32): Ditto.
* syscalls.cc (chown32): Ditto.
(lchown32): Ditto.
(fchown32): Ditto.
(setegid32): Ditto.
(setgid32): Ditto.
* uinfo.cc (getgid32): Ditto.
(getegid32): Ditto.
* include/cygwin/grp.h: Remove declaration of getgrgid() and getgrnam().
Declare getgrgid32() and getgrnam32() instead. Declare getgid32().
2002-05-28 22:10:55 +08:00
|
|
|
{
|
|
|
|
return cygheap->user.real_gid;
|
|
|
|
}
|
|
|
|
|
2013-04-23 17:44:36 +08:00
|
|
|
extern "C" uid_t
|
Cygwin: simplify some function names
Remove "32" or "64" from each of the following names: acl32,
aclcheck32, aclfrommode32, aclfrompbits32, aclfromtext32, aclsort32,
acltomode32, acltopbits32, acltotext32, facl32, fchown32, fcntl64,
fstat64, _fstat64, _fstat64_r, ftruncate64, getgid32, getgrent32,
getgrgid32, getgrnam32, getgroups32, getpwuid32, getpwuid_r32,
getuid32, getuid32, initgroups32, lseek64, lstat64, mknod32, mmap64,
setegid32, seteuid32, setgid32, setgroups32, setregid32, setreuid32,
setuid32, stat64, _stat64_r, truncate64.
Remove prototypes and macro definitions of these names.
Remove "#ifndef __INSIDE_CYGWIN__" from some headers so that the new
names will be available when compiling Cygwin.
Remove aliases that are no longer needed.
Include <unistd.h> in fhandler_clipboard.cc for the declarations of
geteuid and getegid.
2022-05-23 03:18:48 +08:00
|
|
|
geteuid (void)
|
2002-05-29 23:04:29 +08:00
|
|
|
{
|
|
|
|
return myself->uid;
|
|
|
|
}
|
|
|
|
|
2013-04-23 17:44:36 +08:00
|
|
|
extern "C" gid_t
|
Cygwin: simplify some function names
Remove "32" or "64" from each of the following names: acl32,
aclcheck32, aclfrommode32, aclfrompbits32, aclfromtext32, aclsort32,
acltomode32, acltopbits32, acltotext32, facl32, fchown32, fcntl64,
fstat64, _fstat64, _fstat64_r, ftruncate64, getgid32, getgrent32,
getgrgid32, getgrnam32, getgroups32, getpwuid32, getpwuid_r32,
getuid32, getuid32, initgroups32, lseek64, lstat64, mknod32, mmap64,
setegid32, seteuid32, setgid32, setgroups32, setregid32, setreuid32,
setuid32, stat64, _stat64_r, truncate64.
Remove prototypes and macro definitions of these names.
Remove "#ifndef __INSIDE_CYGWIN__" from some headers so that the new
names will be available when compiling Cygwin.
Remove aliases that are no longer needed.
Include <unistd.h> in fhandler_clipboard.cc for the declarations of
geteuid and getegid.
2022-05-23 03:18:48 +08:00
|
|
|
getegid (void)
|
Change internal gid datatype from __gid16_t to __gid32_t
throughout.
* cygwin.din: Export new symbols chown32, fchown32, getegid32,
getgid32, getgrgid32, getgrnam32, getgroups32, initgroups32, lchown32,
setgid32, setegid32, getgrent32.
* grp.cc (grp32togrp16): New static function.
(getgrgid32): New function.
(getgrnam32): Ditto.
(getgrent32): Ditto.
(getgroups32): Change name of internal function from getgroups.
(getgroups32): New function.
(initgroups32): Ditto.
* syscalls.cc (chown32): Ditto.
(lchown32): Ditto.
(fchown32): Ditto.
(setegid32): Ditto.
(setgid32): Ditto.
* uinfo.cc (getgid32): Ditto.
(getegid32): Ditto.
* include/cygwin/grp.h: Remove declaration of getgrgid() and getgrnam().
Declare getgrgid32() and getgrnam32() instead. Declare getgid32().
2002-05-28 22:10:55 +08:00
|
|
|
{
|
|
|
|
return myself->gid;
|
|
|
|
}
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
/* Not quite right - cuserid can change, getlogin can't */
|
|
|
|
extern "C" char *
|
|
|
|
cuserid (char *src)
|
|
|
|
{
|
2002-06-12 13:13:54 +08:00
|
|
|
if (!src)
|
|
|
|
return getlogin ();
|
|
|
|
|
|
|
|
strcpy (src, getlogin ());
|
|
|
|
return src;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
cygheap_user::ontherange (homebodies what, struct passwd *pw)
|
|
|
|
{
|
2002-06-28 04:44:27 +08:00
|
|
|
char homedrive_env_buf[3];
|
|
|
|
char *newhomedrive = NULL;
|
|
|
|
char *newhomepath = NULL;
|
2008-03-12 20:41:50 +08:00
|
|
|
tmp_pathbuf tp;
|
2002-06-12 13:13:54 +08:00
|
|
|
|
2002-06-29 10:36:08 +08:00
|
|
|
debug_printf ("what %d, pw %p", what, pw);
|
2002-06-12 13:13:54 +08:00
|
|
|
if (what == CH_HOME)
|
|
|
|
{
|
|
|
|
char *p;
|
2002-06-16 13:26:14 +08:00
|
|
|
|
2002-06-12 13:13:54 +08:00
|
|
|
if ((p = getenv ("HOME")))
|
2015-08-10 18:00:12 +08:00
|
|
|
debug_printf ("HOME is already in the environment %s", p);
|
2015-07-23 23:42:07 +08:00
|
|
|
if (!p)
|
2002-06-12 13:13:54 +08:00
|
|
|
{
|
|
|
|
if (pw && pw->pw_dir && *pw->pw_dir)
|
|
|
|
{
|
2014-10-31 00:07:04 +08:00
|
|
|
debug_printf ("Set HOME (from account db) to %s", pw->pw_dir);
|
2002-07-01 11:57:17 +08:00
|
|
|
setenv ("HOME", pw->pw_dir, 1);
|
2002-06-12 13:13:54 +08:00
|
|
|
}
|
2002-07-01 11:57:17 +08:00
|
|
|
else
|
2002-06-12 13:13:54 +08:00
|
|
|
{
|
2009-05-06 19:52:20 +08:00
|
|
|
char home[strlen (name ()) + 8];
|
|
|
|
|
|
|
|
debug_printf ("Set HOME to default /home/USER");
|
|
|
|
__small_sprintf (home, "/home/%s", name ());
|
2002-07-01 11:57:17 +08:00
|
|
|
setenv ("HOME", home, 1);
|
2002-06-12 13:13:54 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-02 19:26:22 +08:00
|
|
|
if (what != CH_HOME && homepath == NULL)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2014-12-02 19:26:22 +08:00
|
|
|
WCHAR wuser[UNLEN + 1];
|
|
|
|
WCHAR wlogsrv[INTERNET_MAX_HOST_NAME_LENGTH + 3];
|
|
|
|
PUSER_INFO_3 ui = NULL;
|
2008-03-12 20:41:50 +08:00
|
|
|
char *homepath_env_buf = tp.c_get ();
|
2014-12-02 19:26:22 +08:00
|
|
|
WCHAR profile[MAX_PATH];
|
|
|
|
WCHAR win_id[UNLEN + 1]; /* Large enough for SID */
|
|
|
|
|
|
|
|
homepath_env_buf[0] = homepath_env_buf[1] = '\0';
|
|
|
|
/* Use Cygwin home as HOMEDRIVE/HOMEPATH in the first place. This
|
|
|
|
should cover it completely, in theory. Still, it might be the
|
|
|
|
wrong choice in the long run, which might demand to set HOMEDRIVE/
|
|
|
|
HOMEPATH to the correct values per Windows. Keep the entire rest
|
|
|
|
of the code mainly for this reason, so switching is easy. */
|
|
|
|
pw = internal_getpwsid (sid ());
|
2002-06-12 13:13:54 +08:00
|
|
|
if (pw && pw->pw_dir && *pw->pw_dir)
|
2008-03-12 20:41:50 +08:00
|
|
|
cygwin_conv_path (CCP_POSIX_TO_WIN_A, pw->pw_dir, homepath_env_buf,
|
|
|
|
NT_MAX_PATH);
|
2014-12-02 19:26:22 +08:00
|
|
|
/* First fallback: Windows path per Windows user DB. */
|
|
|
|
else if (logsrv ())
|
2002-06-12 13:13:54 +08:00
|
|
|
{
|
2014-12-02 19:26:22 +08:00
|
|
|
sys_mbstowcs (wlogsrv, sizeof (wlogsrv) / sizeof (*wlogsrv),
|
|
|
|
logsrv ());
|
|
|
|
sys_mbstowcs (wuser, sizeof wuser / sizeof *wuser, winname ());
|
|
|
|
if (NetUserGetInfo (wlogsrv, wuser, 3, (LPBYTE *) &ui)
|
|
|
|
== NERR_Success)
|
2002-06-12 13:13:54 +08:00
|
|
|
{
|
2014-12-02 19:26:22 +08:00
|
|
|
if (ui->usri3_home_dir_drive && *ui->usri3_home_dir_drive)
|
2002-06-12 13:13:54 +08:00
|
|
|
{
|
2008-03-12 20:41:50 +08:00
|
|
|
sys_wcstombs (homepath_env_buf, NT_MAX_PATH,
|
2014-12-02 19:26:22 +08:00
|
|
|
ui->usri3_home_dir_drive);
|
|
|
|
strcat (homepath_env_buf, "\\");
|
2002-06-12 13:13:54 +08:00
|
|
|
}
|
2014-12-02 19:26:22 +08:00
|
|
|
else if (ui->usri3_home_dir && *ui->usri3_home_dir)
|
|
|
|
sys_wcstombs (homepath_env_buf, NT_MAX_PATH,
|
|
|
|
ui->usri3_home_dir);
|
2002-06-12 13:13:54 +08:00
|
|
|
}
|
|
|
|
if (ui)
|
|
|
|
NetApiBufferFree (ui);
|
|
|
|
}
|
2014-12-02 19:26:22 +08:00
|
|
|
/* Second fallback: Windows profile dir. */
|
|
|
|
if (!homepath_env_buf[0]
|
|
|
|
&& get_user_profile_directory (get_windows_id (win_id),
|
|
|
|
profile, MAX_PATH))
|
|
|
|
sys_wcstombs (homepath_env_buf, NT_MAX_PATH, profile);
|
|
|
|
/* Last fallback: Cygwin root dir. */
|
|
|
|
if (!homepath_env_buf[0])
|
|
|
|
cygwin_conv_path (CCP_POSIX_TO_WIN_A | CCP_ABSOLUTE,
|
|
|
|
"/", homepath_env_buf, NT_MAX_PATH);
|
2002-06-12 13:13:54 +08:00
|
|
|
|
2002-06-15 04:36:42 +08:00
|
|
|
if (homepath_env_buf[1] != ':')
|
2002-06-12 13:13:54 +08:00
|
|
|
{
|
2002-06-28 04:44:27 +08:00
|
|
|
newhomedrive = almost_null;
|
|
|
|
newhomepath = homepath_env_buf;
|
2002-06-12 13:13:54 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-06-15 04:36:42 +08:00
|
|
|
homedrive_env_buf[0] = homepath_env_buf[0];
|
|
|
|
homedrive_env_buf[1] = homepath_env_buf[1];
|
2002-06-28 04:44:27 +08:00
|
|
|
homedrive_env_buf[2] = '\0';
|
|
|
|
newhomedrive = homedrive_env_buf;
|
|
|
|
newhomepath = homepath_env_buf + 2;
|
2002-06-12 13:13:54 +08:00
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
2002-06-12 13:13:54 +08:00
|
|
|
|
2002-07-01 11:57:17 +08:00
|
|
|
if (newhomedrive && newhomedrive != homedrive)
|
2002-06-28 04:44:27 +08:00
|
|
|
cfree_and_set (homedrive, (newhomedrive == almost_null)
|
2002-09-19 11:30:20 +08:00
|
|
|
? almost_null : cstrdup (newhomedrive));
|
2002-06-28 04:44:27 +08:00
|
|
|
|
2002-07-01 11:57:17 +08:00
|
|
|
if (newhomepath && newhomepath != homepath)
|
2002-06-28 04:44:27 +08:00
|
|
|
cfree_and_set (homepath, cstrdup (newhomepath));
|
|
|
|
|
2002-06-12 13:13:54 +08:00
|
|
|
switch (what)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2002-06-12 13:13:54 +08:00
|
|
|
case CH_HOMEDRIVE:
|
|
|
|
return homedrive;
|
|
|
|
case CH_HOMEPATH:
|
|
|
|
return homepath;
|
|
|
|
default:
|
|
|
|
return homepath;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
}
|
2002-06-12 13:13:54 +08:00
|
|
|
|
|
|
|
const char *
|
2002-06-29 10:36:08 +08:00
|
|
|
cygheap_user::test_uid (char *&what, const char *name, size_t namelen)
|
2002-06-12 13:13:54 +08:00
|
|
|
{
|
2002-07-01 11:57:17 +08:00
|
|
|
if (!what && !issetuid ())
|
2002-06-29 14:50:17 +08:00
|
|
|
what = getwinenveq (name, namelen, HEAP_STR);
|
2002-06-29 10:36:08 +08:00
|
|
|
return what;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
cygheap_user::env_logsrv (const char *name, size_t namelen)
|
|
|
|
{
|
|
|
|
if (test_uid (plogsrv, name, namelen))
|
2002-06-15 02:01:21 +08:00
|
|
|
return plogsrv;
|
2002-06-12 13:13:54 +08:00
|
|
|
|
2002-06-30 06:05:30 +08:00
|
|
|
const char *mydomain = domain ();
|
|
|
|
const char *myname = winname ();
|
2008-02-01 20:37:51 +08:00
|
|
|
if (!mydomain || ascii_strcasematch (myname, "SYSTEM"))
|
2002-06-29 11:14:12 +08:00
|
|
|
return almost_null;
|
2002-06-16 13:26:14 +08:00
|
|
|
|
2008-07-11 18:00:36 +08:00
|
|
|
WCHAR wdomain[MAX_DOMAIN_NAME_LEN + 1];
|
2008-07-09 19:58:38 +08:00
|
|
|
WCHAR wlogsrv[INTERNET_MAX_HOST_NAME_LENGTH + 3];
|
2008-07-11 18:00:36 +08:00
|
|
|
sys_mbstowcs (wdomain, MAX_DOMAIN_NAME_LEN + 1, mydomain);
|
2002-06-28 04:44:27 +08:00
|
|
|
cfree_and_set (plogsrv, almost_null);
|
2014-02-10 03:44:56 +08:00
|
|
|
if (get_logon_server (wdomain, wlogsrv, DS_IS_FLAT_NAME))
|
2008-07-09 19:58:38 +08:00
|
|
|
sys_wcstombs_alloc (&plogsrv, HEAP_STR, wlogsrv);
|
2002-06-28 04:44:27 +08:00
|
|
|
return plogsrv;
|
2002-06-15 02:01:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
2002-06-29 10:36:08 +08:00
|
|
|
cygheap_user::env_domain (const char *name, size_t namelen)
|
2002-06-15 02:01:21 +08:00
|
|
|
{
|
2002-06-29 14:50:17 +08:00
|
|
|
if (pwinname && test_uid (pdomain, name, namelen))
|
2002-06-15 02:01:21 +08:00
|
|
|
return pdomain;
|
|
|
|
|
2011-03-29 18:46:04 +08:00
|
|
|
DWORD ulen = UNLEN + 1;
|
|
|
|
WCHAR username[ulen];
|
2011-03-31 23:33:53 +08:00
|
|
|
DWORD dlen = MAX_DOMAIN_NAME_LEN + 1;
|
2011-03-29 18:46:04 +08:00
|
|
|
WCHAR userdomain[dlen];
|
2002-06-15 02:01:21 +08:00
|
|
|
SID_NAME_USE use;
|
|
|
|
|
2002-06-29 10:36:08 +08:00
|
|
|
cfree_and_set (pwinname, almost_null);
|
2002-06-28 04:44:27 +08:00
|
|
|
cfree_and_set (pdomain, almost_null);
|
2011-03-29 18:46:04 +08:00
|
|
|
if (!LookupAccountSidW (NULL, sid (), username, &ulen,
|
|
|
|
userdomain, &dlen, &use))
|
2002-06-28 04:44:27 +08:00
|
|
|
__seterrno ();
|
|
|
|
else
|
2002-06-15 02:01:21 +08:00
|
|
|
{
|
2011-03-29 18:46:04 +08:00
|
|
|
sys_wcstombs_alloc (&pwinname, HEAP_STR, username);
|
|
|
|
sys_wcstombs_alloc (&pdomain, HEAP_STR, userdomain);
|
2002-06-15 02:01:21 +08:00
|
|
|
}
|
2002-06-28 04:44:27 +08:00
|
|
|
return pdomain;
|
2002-06-12 13:13:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
2002-06-29 10:36:08 +08:00
|
|
|
cygheap_user::env_userprofile (const char *name, size_t namelen)
|
2002-06-12 13:13:54 +08:00
|
|
|
{
|
2002-06-29 10:36:08 +08:00
|
|
|
if (test_uid (puserprof, name, namelen))
|
|
|
|
return puserprof;
|
|
|
|
|
2014-12-02 18:49:47 +08:00
|
|
|
/* User profile path is never longer than MAX_PATH. */
|
|
|
|
WCHAR profile[MAX_PATH];
|
2008-02-15 00:47:11 +08:00
|
|
|
WCHAR win_id[UNLEN + 1]; /* Large enough for SID */
|
2004-11-21 03:09:19 +08:00
|
|
|
|
2002-06-28 04:44:27 +08:00
|
|
|
cfree_and_set (puserprof, almost_null);
|
2014-12-02 18:49:47 +08:00
|
|
|
if (get_user_profile_directory (get_windows_id (win_id), profile, MAX_PATH))
|
|
|
|
sys_wcstombs_alloc (&puserprof, HEAP_STR, profile);
|
2002-06-16 13:26:14 +08:00
|
|
|
|
2002-06-28 04:44:27 +08:00
|
|
|
return puserprof;
|
2002-06-12 13:13:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
2002-06-29 10:36:08 +08:00
|
|
|
cygheap_user::env_homepath (const char *name, size_t namelen)
|
2002-06-12 13:13:54 +08:00
|
|
|
{
|
|
|
|
return ontherange (CH_HOMEPATH);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
2002-06-29 10:36:08 +08:00
|
|
|
cygheap_user::env_homedrive (const char *name, size_t namelen)
|
2002-06-12 13:13:54 +08:00
|
|
|
{
|
|
|
|
return ontherange (CH_HOMEDRIVE);
|
|
|
|
}
|
2002-06-15 02:01:21 +08:00
|
|
|
|
|
|
|
const char *
|
2002-06-29 10:36:08 +08:00
|
|
|
cygheap_user::env_name (const char *name, size_t namelen)
|
2002-06-15 02:01:21 +08:00
|
|
|
{
|
2002-06-29 10:36:08 +08:00
|
|
|
if (!test_uid (pwinname, name, namelen))
|
2005-07-07 04:05:03 +08:00
|
|
|
domain ();
|
2002-06-29 10:36:08 +08:00
|
|
|
return pwinname;
|
2002-06-15 02:01:21 +08:00
|
|
|
}
|
2003-01-17 13:18:30 +08:00
|
|
|
|
2004-10-08 05:28:57 +08:00
|
|
|
const char *
|
|
|
|
cygheap_user::env_systemroot (const char *name, size_t namelen)
|
|
|
|
{
|
|
|
|
if (!psystemroot)
|
2021-05-08 05:05:24 +08:00
|
|
|
sys_wcstombs_alloc (&psystemroot, HEAP_STR, windows_directory);
|
2004-10-08 05:28:57 +08:00
|
|
|
return psystemroot;
|
|
|
|
}
|
|
|
|
|
2003-01-20 10:57:54 +08:00
|
|
|
char *
|
2003-01-24 11:53:46 +08:00
|
|
|
pwdgrp::next_str (char c)
|
2003-01-17 13:18:30 +08:00
|
|
|
{
|
2003-01-24 11:53:46 +08:00
|
|
|
char *res = lptr;
|
2012-10-27 20:09:38 +08:00
|
|
|
lptr = strchrnul (lptr, c);
|
2003-01-27 08:16:01 +08:00
|
|
|
if (*lptr)
|
|
|
|
*lptr++ = '\0';
|
2003-01-24 11:53:46 +08:00
|
|
|
return res;
|
2003-01-20 10:57:54 +08:00
|
|
|
}
|
2003-01-17 13:18:30 +08:00
|
|
|
|
2003-01-26 13:38:38 +08:00
|
|
|
bool
|
|
|
|
pwdgrp::next_num (unsigned long& n)
|
2003-01-24 11:53:46 +08:00
|
|
|
{
|
2003-01-27 08:16:01 +08:00
|
|
|
char *p = next_str (':');
|
2003-01-24 11:53:46 +08:00
|
|
|
char *cp;
|
2003-01-26 13:38:38 +08:00
|
|
|
n = strtoul (p, &cp, 10);
|
|
|
|
return p != cp && !*cp;
|
2003-01-24 11:53:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
|
|
|
pwdgrp::add_line (char *eptr)
|
2003-01-20 10:57:54 +08:00
|
|
|
{
|
2003-01-24 11:53:46 +08:00
|
|
|
if (eptr)
|
2003-01-20 10:57:54 +08:00
|
|
|
{
|
2003-01-24 11:53:46 +08:00
|
|
|
if (curr_lines >= max_lines)
|
|
|
|
{
|
|
|
|
max_lines += 10;
|
2014-02-10 03:44:56 +08:00
|
|
|
pwdgrp_buf = crealloc_abort (pwdgrp_buf,
|
|
|
|
max_lines * pwdgrp_buf_elem_size);
|
2003-01-24 11:53:46 +08:00
|
|
|
}
|
2014-02-10 03:44:56 +08:00
|
|
|
lptr = eptr;
|
2015-02-28 20:12:34 +08:00
|
|
|
if (!(this->*parse) ())
|
|
|
|
return NULL;
|
|
|
|
curr_lines++;
|
2003-01-20 10:57:54 +08:00
|
|
|
}
|
2003-01-24 11:53:46 +08:00
|
|
|
return eptr;
|
2003-01-17 13:18:30 +08:00
|
|
|
}
|
|
|
|
|
2003-01-26 13:38:38 +08:00
|
|
|
void
|
2014-02-10 03:44:56 +08:00
|
|
|
cygheap_pwdgrp::init ()
|
2003-01-17 13:18:30 +08:00
|
|
|
{
|
2014-03-13 01:36:56 +08:00
|
|
|
pwd_cache.cygserver.init_pwd ();
|
2014-02-10 03:44:56 +08:00
|
|
|
pwd_cache.file.init_pwd ();
|
|
|
|
pwd_cache.win.init_pwd ();
|
2014-03-13 01:36:56 +08:00
|
|
|
grp_cache.cygserver.init_grp ();
|
2014-02-10 03:44:56 +08:00
|
|
|
grp_cache.file.init_grp ();
|
|
|
|
grp_cache.win.init_grp ();
|
2020-04-22 02:31:09 +08:00
|
|
|
/* Default settings (excluding fallbacks):
|
2014-02-10 03:44:56 +08:00
|
|
|
|
|
|
|
passwd: files db
|
|
|
|
group: files db
|
2014-02-17 23:36:33 +08:00
|
|
|
db_enum: cache builtin
|
2014-02-10 03:44:56 +08:00
|
|
|
*/
|
2014-11-12 19:19:08 +08:00
|
|
|
pwd_src = (NSS_SRC_FILES | NSS_SRC_DB);
|
|
|
|
grp_src = (NSS_SRC_FILES | NSS_SRC_DB);
|
2014-02-17 23:36:33 +08:00
|
|
|
enums = (ENUM_CACHE | ENUM_BUILTIN);
|
|
|
|
enum_tdoms = NULL;
|
2014-09-01 02:18:49 +08:00
|
|
|
caching = true; /* INTERNAL ONLY */
|
2014-02-10 03:44:56 +08:00
|
|
|
}
|
2007-08-22 01:38:27 +08:00
|
|
|
|
2014-11-27 03:46:59 +08:00
|
|
|
#define NSS_NCMP(s) (!strncmp(c, (s), sizeof(s)-1))
|
|
|
|
#define NSS_CMP(s) (!strncmp(c, (s), sizeof(s)-1) \
|
|
|
|
&& strchr (" \t", c[sizeof(s)-1]))
|
|
|
|
|
2014-02-17 23:36:33 +08:00
|
|
|
/* The /etc/nsswitch.conf file is read exactly once by the root process of a
|
2019-02-13 18:10:41 +08:00
|
|
|
process tree. We can't afford methodical changes during the lifetime of a
|
2014-02-10 03:44:56 +08:00
|
|
|
process tree. */
|
|
|
|
void
|
|
|
|
cygheap_pwdgrp::nss_init_line (const char *line)
|
|
|
|
{
|
|
|
|
const char *c = line + strspn (line, " \t");
|
2014-11-27 03:46:59 +08:00
|
|
|
char *comment = strchr (c, '#');
|
|
|
|
if (comment)
|
|
|
|
*comment = '\0';
|
2014-02-10 03:44:56 +08:00
|
|
|
switch (*c)
|
|
|
|
{
|
|
|
|
case 'p':
|
|
|
|
case 'g':
|
|
|
|
{
|
2014-11-27 03:46:59 +08:00
|
|
|
uint32_t *src = NULL;
|
|
|
|
if (NSS_NCMP ("passwd:"))
|
|
|
|
src = &pwd_src;
|
|
|
|
else if (NSS_NCMP ("group:"))
|
|
|
|
src = &grp_src;
|
|
|
|
c = strchr (c, ':') + 1;
|
2014-02-10 03:44:56 +08:00
|
|
|
if (src)
|
|
|
|
{
|
|
|
|
*src = 0;
|
2014-11-27 03:46:59 +08:00
|
|
|
while (*(c += strspn (c, " \t")))
|
2014-02-10 03:44:56 +08:00
|
|
|
{
|
2014-11-27 03:46:59 +08:00
|
|
|
if (NSS_CMP ("files"))
|
2014-02-10 03:44:56 +08:00
|
|
|
{
|
2014-11-12 19:19:08 +08:00
|
|
|
*src |= NSS_SRC_FILES;
|
2014-02-10 03:44:56 +08:00
|
|
|
c += 5;
|
|
|
|
}
|
2014-11-27 03:46:59 +08:00
|
|
|
else if (NSS_CMP ("db"))
|
2014-02-10 03:44:56 +08:00
|
|
|
{
|
2014-11-12 19:19:08 +08:00
|
|
|
*src |= NSS_SRC_DB;
|
2014-02-10 03:44:56 +08:00
|
|
|
c += 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
c += strcspn (c, " \t");
|
|
|
|
debug_printf ("Invalid nsswitch.conf content: %s", line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (*src == 0)
|
2014-11-12 19:19:08 +08:00
|
|
|
*src = (NSS_SRC_FILES | NSS_SRC_DB);
|
2014-02-10 03:44:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'd':
|
2014-11-27 03:46:59 +08:00
|
|
|
if (!NSS_NCMP ("db_"))
|
2014-02-10 03:44:56 +08:00
|
|
|
{
|
|
|
|
debug_printf ("Invalid nsswitch.conf content: %s", line);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
c += 3;
|
2014-11-27 03:46:59 +08:00
|
|
|
if (NSS_NCMP ("enum:"))
|
2014-02-17 23:36:33 +08:00
|
|
|
{
|
|
|
|
tmp_pathbuf tp;
|
|
|
|
char *tdoms = tp.c_get ();
|
|
|
|
char *td = tdoms;
|
|
|
|
int new_enums = ENUM_NONE;
|
|
|
|
|
|
|
|
td[0] = '\0';
|
2014-11-27 03:46:59 +08:00
|
|
|
c = strchr (c, ':') + 1;
|
2014-02-17 23:36:33 +08:00
|
|
|
c += strspn (c, " \t");
|
|
|
|
while (!strchr (" \t", *c))
|
|
|
|
{
|
|
|
|
const char *e = c + strcspn (c, " \t");
|
2014-11-27 03:46:59 +08:00
|
|
|
if (NSS_CMP ("none"))
|
2014-02-17 23:36:33 +08:00
|
|
|
new_enums = ENUM_NONE;
|
2014-11-27 03:46:59 +08:00
|
|
|
else if (NSS_CMP ("builtin"))
|
2014-02-17 23:36:33 +08:00
|
|
|
new_enums |= ENUM_BUILTIN;
|
2014-11-27 03:46:59 +08:00
|
|
|
else if (NSS_CMP ("cache"))
|
2014-02-17 23:36:33 +08:00
|
|
|
new_enums |= ENUM_CACHE;
|
2014-11-27 03:46:59 +08:00
|
|
|
else if (NSS_CMP ("files"))
|
2014-02-17 23:36:33 +08:00
|
|
|
new_enums |= ENUM_FILES;
|
2014-11-27 03:46:59 +08:00
|
|
|
else if (NSS_CMP ("local"))
|
2014-02-17 23:36:33 +08:00
|
|
|
new_enums |= ENUM_LOCAL;
|
2014-11-27 03:46:59 +08:00
|
|
|
else if (NSS_CMP ("primary"))
|
2014-02-17 23:36:33 +08:00
|
|
|
new_enums |= ENUM_PRIMARY;
|
2014-11-27 03:46:59 +08:00
|
|
|
else if (NSS_CMP ("alltrusted"))
|
2014-02-17 23:36:33 +08:00
|
|
|
new_enums |= ENUM_TDOMS | ENUM_TDOMS_ALL;
|
2014-11-27 03:46:59 +08:00
|
|
|
else if (NSS_CMP ("all"))
|
2014-02-17 23:36:33 +08:00
|
|
|
new_enums |= ENUM_ALL;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
td = stpcpy (stpncpy (td, c, e - c), " ");
|
|
|
|
new_enums |= ENUM_TDOMS;
|
|
|
|
}
|
|
|
|
c = e;
|
|
|
|
c += strspn (c, " \t");
|
|
|
|
}
|
|
|
|
if ((new_enums & (ENUM_TDOMS | ENUM_TDOMS_ALL)) == ENUM_TDOMS)
|
|
|
|
{
|
|
|
|
if (td > tdoms)
|
|
|
|
{
|
|
|
|
PWCHAR spc;
|
|
|
|
sys_mbstowcs_alloc (&enum_tdoms, HEAP_BUF, tdoms);
|
|
|
|
/* Convert string to REG_MULTI_SZ-style. */
|
|
|
|
while ((spc = wcsrchr (enum_tdoms, L' ')))
|
|
|
|
*spc = L'\0';
|
|
|
|
}
|
|
|
|
else
|
2019-02-13 18:10:41 +08:00
|
|
|
new_enums &= ~(ENUM_TDOMS | ENUM_TDOMS_ALL);
|
2014-02-17 23:36:33 +08:00
|
|
|
}
|
|
|
|
enums = new_enums;
|
|
|
|
}
|
2014-11-27 03:46:59 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
nss_scheme_t *scheme = NULL;
|
|
|
|
if (NSS_NCMP ("home:"))
|
|
|
|
scheme = home_scheme;
|
|
|
|
else if (NSS_NCMP ("shell:"))
|
|
|
|
scheme = shell_scheme;
|
|
|
|
else if (NSS_NCMP ("gecos:"))
|
|
|
|
scheme = gecos_scheme;
|
|
|
|
if (scheme)
|
|
|
|
{
|
2020-04-21 01:21:00 +08:00
|
|
|
for (uint16_t idx = 0; idx < NSS_SCHEME_MAX; ++idx)
|
|
|
|
scheme[idx].method = NSS_SCHEME_FALLBACK;
|
2014-11-27 03:46:59 +08:00
|
|
|
|
|
|
|
c = strchr (c, ':') + 1;
|
|
|
|
c += strspn (c, " \t");
|
2020-04-21 01:21:00 +08:00
|
|
|
for (uint16_t idx = 0; *c && idx < NSS_SCHEME_MAX; ++idx)
|
2014-11-27 03:46:59 +08:00
|
|
|
{
|
|
|
|
if (NSS_CMP ("windows"))
|
|
|
|
scheme[idx].method = NSS_SCHEME_WINDOWS;
|
|
|
|
else if (NSS_CMP ("cygwin"))
|
|
|
|
scheme[idx].method = NSS_SCHEME_CYGWIN;
|
|
|
|
else if (NSS_CMP ("unix"))
|
|
|
|
scheme[idx].method = NSS_SCHEME_UNIX;
|
|
|
|
else if (NSS_CMP ("desc"))
|
|
|
|
scheme[idx].method = NSS_SCHEME_DESC;
|
2023-03-28 16:17:14 +08:00
|
|
|
else if (NSS_CMP ("env"))
|
|
|
|
scheme[idx].method = NSS_SCHEME_ENV;
|
2014-11-27 03:46:59 +08:00
|
|
|
else if (NSS_NCMP ("/"))
|
|
|
|
{
|
|
|
|
const char *e = c + strcspn (c, " \t");
|
|
|
|
scheme[idx].method = NSS_SCHEME_PATH;
|
|
|
|
sys_mbstowcs_alloc (&scheme[idx].attrib, HEAP_STR,
|
|
|
|
c, e - c);
|
|
|
|
}
|
|
|
|
else if (NSS_NCMP ("@") && isalnum ((unsigned) *++c))
|
|
|
|
{
|
|
|
|
const char *e = c + strcspn (c, " \t");
|
|
|
|
scheme[idx].method = NSS_SCHEME_FREEATTR;
|
|
|
|
sys_mbstowcs_alloc (&scheme[idx].attrib, HEAP_STR,
|
|
|
|
c, e - c);
|
|
|
|
}
|
|
|
|
else
|
2020-04-17 05:09:07 +08:00
|
|
|
{
|
|
|
|
debug_printf ("Invalid nsswitch.conf content: %s", line);
|
|
|
|
--idx;
|
|
|
|
}
|
2014-11-27 03:46:59 +08:00
|
|
|
c += strcspn (c, " \t");
|
|
|
|
c += strspn (c, " \t");
|
|
|
|
}
|
|
|
|
}
|
2020-04-21 01:21:15 +08:00
|
|
|
else
|
|
|
|
debug_printf ("Invalid nsswitch.conf content: %s", line);
|
2014-11-27 03:46:59 +08:00
|
|
|
}
|
2014-02-10 03:44:56 +08:00
|
|
|
break;
|
|
|
|
case '\0':
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
debug_printf ("Invalid nsswitch.conf content: %s", line);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-02 19:30:04 +08:00
|
|
|
static char *
|
2015-02-13 00:55:38 +08:00
|
|
|
fetch_windows_home (cyg_ldap *pldap, PUSER_INFO_3 ui, cygpsid &sid,
|
|
|
|
PCWSTR dnsdomain)
|
2014-12-02 19:30:04 +08:00
|
|
|
{
|
2015-01-09 01:08:47 +08:00
|
|
|
PCWSTR home_from_db = NULL;
|
2014-12-02 19:30:04 +08:00
|
|
|
char *home = NULL;
|
|
|
|
|
2015-01-09 01:08:47 +08:00
|
|
|
if (pldap)
|
|
|
|
{
|
2015-02-13 00:55:38 +08:00
|
|
|
if (pldap->fetch_ad_account (sid, false, dnsdomain))
|
|
|
|
{
|
2015-01-14 19:13:23 +08:00
|
|
|
#if 0
|
2015-02-13 00:55:38 +08:00
|
|
|
/* Disable preferring homeDrive for now. The drive letter may not
|
|
|
|
be available when it's needed. */
|
|
|
|
home_from_db = pldap->get_string_attribute (L"homeDrive");
|
|
|
|
if (!home_from_db || !*home_from_db)
|
2015-01-14 19:13:23 +08:00
|
|
|
#endif
|
2015-02-13 00:55:38 +08:00
|
|
|
home_from_db = pldap->get_string_attribute (L"homeDirectory");
|
|
|
|
}
|
2015-01-09 01:08:47 +08:00
|
|
|
}
|
|
|
|
else if (ui)
|
|
|
|
{
|
2015-01-14 19:13:23 +08:00
|
|
|
#if 0
|
|
|
|
/* Ditto. */
|
2015-01-09 01:08:47 +08:00
|
|
|
if (ui->usri3_home_dir_drive && *ui->usri3_home_dir_drive)
|
|
|
|
home_from_db = ui->usri3_home_dir_drive;
|
2015-01-14 19:13:23 +08:00
|
|
|
else
|
|
|
|
#endif
|
|
|
|
if (ui->usri3_home_dir && *ui->usri3_home_dir)
|
2015-01-09 01:08:47 +08:00
|
|
|
home_from_db = ui->usri3_home_dir;
|
|
|
|
}
|
2014-12-02 19:30:04 +08:00
|
|
|
if (home_from_db && *home_from_db)
|
|
|
|
home = (char *) cygwin_create_path (CCP_WIN_W_TO_POSIX, home_from_db);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* The db fields are empty, so we have to evaluate the local profile
|
|
|
|
path, which is the same thing as the default home directory on
|
|
|
|
Windows. So what we do here is to try to find out if the user
|
|
|
|
already has a profile on this machine.
|
|
|
|
Note that we don't try to generate the profile if it doesn't exist.
|
|
|
|
Think what would happen if we actually have the permissions to do
|
|
|
|
so and call getpwent... in a domain environment. The problem is,
|
|
|
|
of course, that we can't know the profile path, unless the OS
|
|
|
|
created it.
|
|
|
|
The only reason this could occur is if a user account, which never
|
|
|
|
logged on to the machine before, tries to logon via a Cygwin service
|
|
|
|
like sshd. */
|
|
|
|
WCHAR profile[MAX_PATH];
|
|
|
|
WCHAR sidstr[128];
|
|
|
|
|
|
|
|
if (get_user_profile_directory (sid.string (sidstr), profile, MAX_PATH))
|
2019-02-13 18:10:41 +08:00
|
|
|
home = (char *) cygwin_create_path (CCP_WIN_W_TO_POSIX, profile);
|
2014-12-02 19:30:04 +08:00
|
|
|
}
|
|
|
|
return home;
|
|
|
|
}
|
|
|
|
|
2014-11-27 03:46:59 +08:00
|
|
|
/* Local SAM accounts have only a handful attributes available to home users.
|
|
|
|
Therefore, allow to fetch additional passwd/group attributes from the
|
|
|
|
"Comment" field in XML short style. For symmetry, this is also allowed
|
|
|
|
from the equivalent "description" AD attribute. */
|
2014-12-02 18:28:42 +08:00
|
|
|
static char *
|
2014-11-27 03:46:59 +08:00
|
|
|
fetch_from_description (PCWSTR desc, PCWSTR search, size_t len)
|
|
|
|
{
|
|
|
|
PWCHAR s, e;
|
|
|
|
char *ret = NULL;
|
|
|
|
|
|
|
|
if ((s = wcsstr (desc, L"<cygwin ")) && (e = wcsstr (s + 8, L"/>")))
|
|
|
|
{
|
|
|
|
s += 8;
|
|
|
|
while (s && s < e)
|
|
|
|
{
|
|
|
|
while (*s == L' ')
|
|
|
|
++s;
|
|
|
|
if (!wcsncmp (s, search, len)) /* Found what we're searching? */
|
|
|
|
{
|
|
|
|
s += len;
|
|
|
|
if ((e = wcschr (s, L'"')))
|
|
|
|
{
|
|
|
|
sys_wcstombs_alloc (&ret, HEAP_NOTHEAP, s, e - s);
|
|
|
|
s = e + 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else /* Skip the current foo="bar" string. */
|
|
|
|
if ((s = wcschr (s, L'"')) && (s = wcschr (s + 1, L'"')))
|
|
|
|
++s;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-12-02 18:28:42 +08:00
|
|
|
static char *
|
2015-02-13 00:55:38 +08:00
|
|
|
fetch_from_path (cyg_ldap *pldap, PUSER_INFO_3 ui, cygpsid &sid, PCWSTR str,
|
|
|
|
PCWSTR dom, PCWSTR dnsdomain, PCWSTR name, bool full_qualified)
|
2014-11-27 03:46:59 +08:00
|
|
|
{
|
|
|
|
tmp_pathbuf tp;
|
|
|
|
PWCHAR wpath = tp.w_get ();
|
|
|
|
PWCHAR w = wpath;
|
|
|
|
PWCHAR we = wpath + NT_MAX_PATH - 1;
|
2015-01-09 01:08:47 +08:00
|
|
|
char *home;
|
2014-11-27 03:46:59 +08:00
|
|
|
char *ret = NULL;
|
|
|
|
|
|
|
|
while (*str && w < we)
|
|
|
|
{
|
|
|
|
if (*str != L'%')
|
2019-02-13 18:10:41 +08:00
|
|
|
*w++ = *str++;
|
2014-11-27 03:46:59 +08:00
|
|
|
else
|
2019-02-13 18:10:41 +08:00
|
|
|
{
|
2014-11-27 03:46:59 +08:00
|
|
|
switch (*++str)
|
|
|
|
{
|
|
|
|
case L'u':
|
|
|
|
if (full_qualified)
|
|
|
|
{
|
|
|
|
w = wcpncpy (w, dom, we - w);
|
|
|
|
if (w < we)
|
2022-12-02 22:13:24 +08:00
|
|
|
*w++ = NSS_SEPARATOR_CHAR;
|
2014-11-27 03:46:59 +08:00
|
|
|
}
|
|
|
|
w = wcpncpy (w, name, we - w);
|
|
|
|
break;
|
|
|
|
case L'U':
|
|
|
|
w = wcpncpy (w, name, we - w);
|
|
|
|
break;
|
|
|
|
case L'D':
|
|
|
|
w = wcpncpy (w, dom, we - w);
|
|
|
|
break;
|
2015-01-09 01:08:47 +08:00
|
|
|
case L'H':
|
2015-02-13 00:55:38 +08:00
|
|
|
home = fetch_windows_home (pldap, ui, sid, dnsdomain);
|
2015-01-09 01:08:47 +08:00
|
|
|
if (home)
|
|
|
|
{
|
|
|
|
/* Drop one leading slash to accommodate home being an
|
|
|
|
absolute path. We don't check for broken usage of
|
|
|
|
%H here, of course. */
|
|
|
|
if (w > wpath && w[-1] == L'/')
|
|
|
|
--w;
|
|
|
|
w += sys_mbstowcs (w, we - w, home) - 1;
|
|
|
|
free (home);
|
|
|
|
}
|
|
|
|
break;
|
2014-11-27 03:46:59 +08:00
|
|
|
case L'_':
|
|
|
|
*w++ = L' ';
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
*w++ = *str;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
++str;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*w = L'\0';
|
|
|
|
sys_wcstombs_alloc (&ret, HEAP_NOTHEAP, wpath);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2023-03-28 16:17:14 +08:00
|
|
|
static char *
|
|
|
|
fetch_home_env (void)
|
|
|
|
{
|
|
|
|
/* If `HOME` is set, prefer it */
|
|
|
|
const char *home = getenv ("HOME");
|
|
|
|
if (home)
|
|
|
|
return strdup (home);
|
|
|
|
|
|
|
|
/* If `HOME` is unset, fall back to `HOMEDRIVE``HOMEPATH`
|
|
|
|
(without a directory separator, as `HOMEPATH` starts with one). */
|
|
|
|
const char *home_drive = getenv ("HOMEDRIVE");
|
|
|
|
if (home_drive)
|
|
|
|
{
|
|
|
|
const char *home_path = getenv ("HOMEPATH");
|
|
|
|
if (home_path)
|
|
|
|
{
|
|
|
|
tmp_pathbuf tp;
|
|
|
|
char *p = tp.c_get (), *q;
|
|
|
|
|
|
|
|
// concatenate HOMEDRIVE and HOMEPATH
|
|
|
|
q = stpncpy (p, home_drive, NT_MAX_PATH);
|
|
|
|
strlcpy (q, home_path, NT_MAX_PATH - (q - p));
|
|
|
|
return (char *) cygwin_create_path (CCP_WIN_A_TO_POSIX, p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If neither `HOME` nor `HOMEDRIVE``HOMEPATH` are set, fall back
|
|
|
|
to `USERPROFILE`; In corporate setups, this might point to a
|
|
|
|
disconnected network share, hence this is the last fall back. */
|
|
|
|
home = getenv ("USERPROFILE");
|
|
|
|
if (home)
|
|
|
|
return (char *) cygwin_create_path (CCP_WIN_A_TO_POSIX, home);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-11-27 03:46:59 +08:00
|
|
|
char *
|
2014-12-02 19:30:04 +08:00
|
|
|
cygheap_pwdgrp::get_home (cyg_ldap *pldap, cygpsid &sid, PCWSTR dom,
|
2015-02-13 00:55:38 +08:00
|
|
|
PCWSTR dnsdomain, PCWSTR name, bool full_qualified)
|
2014-11-27 03:46:59 +08:00
|
|
|
{
|
|
|
|
PWCHAR val;
|
|
|
|
char *home = NULL;
|
|
|
|
|
|
|
|
for (uint16_t idx = 0; !home && idx < NSS_SCHEME_MAX; ++idx)
|
|
|
|
{
|
|
|
|
switch (home_scheme[idx].method)
|
|
|
|
{
|
|
|
|
case NSS_SCHEME_FALLBACK:
|
|
|
|
return NULL;
|
|
|
|
case NSS_SCHEME_WINDOWS:
|
2015-02-13 00:55:38 +08:00
|
|
|
if (pldap->fetch_ad_account (sid, false, dnsdomain))
|
|
|
|
home = fetch_windows_home (pldap, NULL, sid, dnsdomain);
|
2014-11-27 03:46:59 +08:00
|
|
|
break;
|
|
|
|
case NSS_SCHEME_CYGWIN:
|
2015-02-13 00:55:38 +08:00
|
|
|
if (pldap->fetch_ad_account (sid, false, dnsdomain))
|
|
|
|
{
|
|
|
|
val = pldap->get_string_attribute (L"cygwinHome");
|
|
|
|
if (val && *val)
|
|
|
|
sys_wcstombs_alloc (&home, HEAP_NOTHEAP, val);
|
|
|
|
}
|
2014-11-27 03:46:59 +08:00
|
|
|
break;
|
|
|
|
case NSS_SCHEME_UNIX:
|
2015-02-13 00:55:38 +08:00
|
|
|
if (pldap->fetch_ad_account (sid, false, dnsdomain))
|
|
|
|
{
|
|
|
|
val = pldap->get_string_attribute (L"unixHomeDirectory");
|
|
|
|
if (val && *val)
|
|
|
|
sys_wcstombs_alloc (&home, HEAP_NOTHEAP, val);
|
|
|
|
}
|
2014-11-27 03:46:59 +08:00
|
|
|
break;
|
|
|
|
case NSS_SCHEME_DESC:
|
2015-02-13 00:55:38 +08:00
|
|
|
if (pldap->fetch_ad_account (sid, false, dnsdomain))
|
|
|
|
{
|
|
|
|
val = pldap->get_string_attribute (L"description");
|
|
|
|
if (val && *val)
|
|
|
|
home = fetch_from_description (val, L"home=\"", 6);
|
|
|
|
}
|
2014-11-27 03:46:59 +08:00
|
|
|
break;
|
|
|
|
case NSS_SCHEME_PATH:
|
2015-01-09 01:08:47 +08:00
|
|
|
home = fetch_from_path (pldap, NULL, sid, home_scheme[idx].attrib,
|
2015-02-13 00:55:38 +08:00
|
|
|
dom, dnsdomain, name, full_qualified);
|
2014-11-27 03:46:59 +08:00
|
|
|
break;
|
|
|
|
case NSS_SCHEME_FREEATTR:
|
2015-02-13 00:55:38 +08:00
|
|
|
if (pldap->fetch_ad_account (sid, false, dnsdomain))
|
2014-11-28 00:49:41 +08:00
|
|
|
{
|
2015-02-13 00:55:38 +08:00
|
|
|
val = pldap->get_string_attribute (home_scheme[idx].attrib);
|
|
|
|
if (val && *val)
|
|
|
|
{
|
|
|
|
if (isdrive (val) || *val == '\\')
|
|
|
|
home = (char *)
|
|
|
|
cygwin_create_path (CCP_WIN_W_TO_POSIX, val);
|
|
|
|
else
|
|
|
|
sys_wcstombs_alloc (&home, HEAP_NOTHEAP, val);
|
|
|
|
}
|
2014-11-28 00:49:41 +08:00
|
|
|
}
|
2014-11-27 03:46:59 +08:00
|
|
|
break;
|
2023-03-28 16:17:14 +08:00
|
|
|
case NSS_SCHEME_ENV:
|
|
|
|
if (RtlEqualSid (sid, cygheap->user.sid ()))
|
|
|
|
home = fetch_home_env ();
|
|
|
|
break;
|
2014-11-27 03:46:59 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return home;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
2014-12-02 19:30:04 +08:00
|
|
|
cygheap_pwdgrp::get_home (PUSER_INFO_3 ui, cygpsid &sid, PCWSTR dom,
|
|
|
|
PCWSTR name, bool full_qualified)
|
2014-11-27 03:46:59 +08:00
|
|
|
{
|
|
|
|
char *home = NULL;
|
|
|
|
|
|
|
|
for (uint16_t idx = 0; !home && idx < NSS_SCHEME_MAX; ++idx)
|
|
|
|
{
|
|
|
|
switch (home_scheme[idx].method)
|
|
|
|
{
|
|
|
|
case NSS_SCHEME_FALLBACK:
|
|
|
|
return NULL;
|
|
|
|
case NSS_SCHEME_WINDOWS:
|
2015-02-13 00:55:38 +08:00
|
|
|
home = fetch_windows_home (NULL, ui, sid, NULL);
|
2014-11-27 03:46:59 +08:00
|
|
|
break;
|
|
|
|
case NSS_SCHEME_CYGWIN:
|
|
|
|
case NSS_SCHEME_UNIX:
|
|
|
|
case NSS_SCHEME_FREEATTR:
|
|
|
|
break;
|
|
|
|
case NSS_SCHEME_DESC:
|
2016-08-08 15:45:34 +08:00
|
|
|
if (ui)
|
|
|
|
home = fetch_from_description (ui->usri3_comment, L"home=\"", 6);
|
2014-11-27 03:46:59 +08:00
|
|
|
break;
|
|
|
|
case NSS_SCHEME_PATH:
|
2015-01-09 01:08:47 +08:00
|
|
|
home = fetch_from_path (NULL, ui, sid, home_scheme[idx].attrib,
|
2015-02-13 00:55:38 +08:00
|
|
|
dom, NULL, name, full_qualified);
|
2014-11-27 03:46:59 +08:00
|
|
|
break;
|
2023-03-28 16:17:14 +08:00
|
|
|
case NSS_SCHEME_ENV:
|
|
|
|
if (RtlEqualSid (sid, cygheap->user.sid ()))
|
|
|
|
home = fetch_home_env ();
|
|
|
|
break;
|
2014-11-27 03:46:59 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return home;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
2015-01-09 01:08:47 +08:00
|
|
|
cygheap_pwdgrp::get_shell (cyg_ldap *pldap, cygpsid &sid, PCWSTR dom,
|
2015-02-13 00:55:38 +08:00
|
|
|
PCWSTR dnsdomain, PCWSTR name, bool full_qualified)
|
2014-11-27 03:46:59 +08:00
|
|
|
{
|
|
|
|
PWCHAR val;
|
|
|
|
char *shell = NULL;
|
|
|
|
|
|
|
|
for (uint16_t idx = 0; !shell && idx < NSS_SCHEME_MAX; ++idx)
|
|
|
|
{
|
|
|
|
switch (shell_scheme[idx].method)
|
|
|
|
{
|
|
|
|
case NSS_SCHEME_FALLBACK:
|
|
|
|
return NULL;
|
|
|
|
case NSS_SCHEME_WINDOWS:
|
2023-03-28 16:17:14 +08:00
|
|
|
case NSS_SCHEME_ENV:
|
2014-11-27 03:46:59 +08:00
|
|
|
break;
|
|
|
|
case NSS_SCHEME_CYGWIN:
|
2015-02-13 00:55:38 +08:00
|
|
|
if (pldap->fetch_ad_account (sid, false, dnsdomain))
|
|
|
|
{
|
|
|
|
val = pldap->get_string_attribute (L"cygwinShell");
|
|
|
|
if (val && *val)
|
|
|
|
sys_wcstombs_alloc (&shell, HEAP_NOTHEAP, val);
|
|
|
|
}
|
2014-11-27 03:46:59 +08:00
|
|
|
break;
|
|
|
|
case NSS_SCHEME_UNIX:
|
2015-02-13 00:55:38 +08:00
|
|
|
if (pldap->fetch_ad_account (sid, false, dnsdomain))
|
|
|
|
{
|
|
|
|
val = pldap->get_string_attribute (L"loginShell");
|
|
|
|
if (val && *val)
|
|
|
|
sys_wcstombs_alloc (&shell, HEAP_NOTHEAP, val);
|
|
|
|
}
|
2014-11-27 03:46:59 +08:00
|
|
|
break;
|
|
|
|
case NSS_SCHEME_DESC:
|
2015-02-13 00:55:38 +08:00
|
|
|
if (pldap->fetch_ad_account (sid, false, dnsdomain))
|
|
|
|
{
|
|
|
|
val = pldap->get_string_attribute (L"description");
|
|
|
|
if (val && *val)
|
|
|
|
shell = fetch_from_description (val, L"shell=\"", 7);
|
|
|
|
}
|
2014-11-27 03:46:59 +08:00
|
|
|
break;
|
|
|
|
case NSS_SCHEME_PATH:
|
2015-01-09 01:08:47 +08:00
|
|
|
shell = fetch_from_path (pldap, NULL, sid, shell_scheme[idx].attrib,
|
2019-02-13 18:10:41 +08:00
|
|
|
dom, dnsdomain, name, full_qualified);
|
2014-11-27 03:46:59 +08:00
|
|
|
break;
|
|
|
|
case NSS_SCHEME_FREEATTR:
|
2015-02-13 00:55:38 +08:00
|
|
|
if (pldap->fetch_ad_account (sid, false, dnsdomain))
|
2014-11-28 00:49:41 +08:00
|
|
|
{
|
2015-02-13 00:55:38 +08:00
|
|
|
val = pldap->get_string_attribute (shell_scheme[idx].attrib);
|
|
|
|
if (val && *val)
|
|
|
|
{
|
|
|
|
if (isdrive (val) || *val == '\\')
|
|
|
|
shell = (char *)
|
|
|
|
cygwin_create_path (CCP_WIN_W_TO_POSIX, val);
|
|
|
|
else
|
|
|
|
sys_wcstombs_alloc (&shell, HEAP_NOTHEAP, val);
|
|
|
|
}
|
2014-11-28 00:49:41 +08:00
|
|
|
}
|
2014-11-27 03:46:59 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return shell;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
2015-01-09 01:08:47 +08:00
|
|
|
cygheap_pwdgrp::get_shell (PUSER_INFO_3 ui, cygpsid &sid, PCWSTR dom,
|
|
|
|
PCWSTR name, bool full_qualified)
|
2014-11-27 03:46:59 +08:00
|
|
|
{
|
|
|
|
char *shell = NULL;
|
|
|
|
|
|
|
|
for (uint16_t idx = 0; !shell && idx < NSS_SCHEME_MAX; ++idx)
|
|
|
|
{
|
|
|
|
switch (shell_scheme[idx].method)
|
|
|
|
{
|
|
|
|
case NSS_SCHEME_FALLBACK:
|
|
|
|
return NULL;
|
|
|
|
case NSS_SCHEME_WINDOWS:
|
|
|
|
case NSS_SCHEME_CYGWIN:
|
|
|
|
case NSS_SCHEME_UNIX:
|
|
|
|
case NSS_SCHEME_FREEATTR:
|
2023-03-28 16:17:14 +08:00
|
|
|
case NSS_SCHEME_ENV:
|
2014-11-27 03:46:59 +08:00
|
|
|
break;
|
|
|
|
case NSS_SCHEME_DESC:
|
2016-08-08 15:45:34 +08:00
|
|
|
if (ui)
|
|
|
|
shell = fetch_from_description (ui->usri3_comment, L"shell=\"", 7);
|
2014-11-27 03:46:59 +08:00
|
|
|
break;
|
|
|
|
case NSS_SCHEME_PATH:
|
2015-01-09 01:08:47 +08:00
|
|
|
shell = fetch_from_path (NULL, ui, sid, shell_scheme[idx].attrib,
|
2015-02-13 00:55:38 +08:00
|
|
|
dom, NULL, name, full_qualified);
|
2014-11-27 03:46:59 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return shell;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Helper function to replace colons with semicolons in pw_gecos field. */
|
|
|
|
static inline void
|
|
|
|
colon_to_semicolon (char *str)
|
|
|
|
{
|
|
|
|
char *cp = str;
|
|
|
|
while ((cp = strchr (cp, L':')) != NULL)
|
|
|
|
*cp++ = L';';
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
2015-01-09 01:08:47 +08:00
|
|
|
cygheap_pwdgrp::get_gecos (cyg_ldap *pldap, cygpsid &sid, PCWSTR dom,
|
2015-02-13 00:55:38 +08:00
|
|
|
PCWSTR dnsdomain, PCWSTR name, bool full_qualified)
|
2014-11-27 03:46:59 +08:00
|
|
|
{
|
|
|
|
PWCHAR val;
|
|
|
|
char *gecos = NULL;
|
|
|
|
|
|
|
|
for (uint16_t idx = 0; !gecos && idx < NSS_SCHEME_MAX; ++idx)
|
|
|
|
{
|
|
|
|
switch (gecos_scheme[idx].method)
|
|
|
|
{
|
|
|
|
case NSS_SCHEME_FALLBACK:
|
|
|
|
return NULL;
|
|
|
|
case NSS_SCHEME_WINDOWS:
|
2015-02-13 00:55:38 +08:00
|
|
|
if (pldap->fetch_ad_account (sid, false, dnsdomain))
|
|
|
|
{
|
|
|
|
val = pldap->get_string_attribute (L"displayName");
|
|
|
|
if (val && *val)
|
|
|
|
sys_wcstombs_alloc (&gecos, HEAP_NOTHEAP, val);
|
|
|
|
}
|
2014-11-27 03:46:59 +08:00
|
|
|
break;
|
|
|
|
case NSS_SCHEME_CYGWIN:
|
2015-02-13 00:55:38 +08:00
|
|
|
if (pldap->fetch_ad_account (sid, false, dnsdomain))
|
|
|
|
{
|
|
|
|
val = pldap->get_string_attribute (L"cygwinGecos");
|
|
|
|
if (val && *val)
|
|
|
|
sys_wcstombs_alloc (&gecos, HEAP_NOTHEAP, val);
|
|
|
|
}
|
2014-11-27 03:46:59 +08:00
|
|
|
break;
|
|
|
|
case NSS_SCHEME_UNIX:
|
2015-02-13 00:55:38 +08:00
|
|
|
if (pldap->fetch_ad_account (sid, false, dnsdomain))
|
|
|
|
{
|
|
|
|
val = pldap->get_string_attribute (L"gecos");
|
|
|
|
if (val && *val)
|
|
|
|
sys_wcstombs_alloc (&gecos, HEAP_NOTHEAP, val);
|
|
|
|
}
|
2014-11-27 03:46:59 +08:00
|
|
|
break;
|
|
|
|
case NSS_SCHEME_DESC:
|
2015-02-13 00:55:38 +08:00
|
|
|
if (pldap->fetch_ad_account (sid, false, dnsdomain))
|
|
|
|
{
|
|
|
|
val = pldap->get_string_attribute (L"description");
|
|
|
|
if (val && *val)
|
|
|
|
gecos = fetch_from_description (val, L"gecos=\"", 7);
|
|
|
|
}
|
2014-11-27 03:46:59 +08:00
|
|
|
break;
|
|
|
|
case NSS_SCHEME_PATH:
|
2015-01-09 01:08:47 +08:00
|
|
|
gecos = fetch_from_path (pldap, NULL, sid,
|
|
|
|
gecos_scheme[idx].attrib + 1,
|
2015-02-13 00:55:38 +08:00
|
|
|
dom, dnsdomain, name, full_qualified);
|
2014-11-27 03:46:59 +08:00
|
|
|
break;
|
|
|
|
case NSS_SCHEME_FREEATTR:
|
2015-02-13 00:55:38 +08:00
|
|
|
if (pldap->fetch_ad_account (sid, false, dnsdomain))
|
|
|
|
{
|
|
|
|
val = pldap->get_string_attribute (gecos_scheme[idx].attrib);
|
|
|
|
if (val && *val)
|
|
|
|
sys_wcstombs_alloc (&gecos, HEAP_NOTHEAP, val);
|
|
|
|
}
|
2014-11-27 03:46:59 +08:00
|
|
|
break;
|
2023-03-28 16:17:14 +08:00
|
|
|
case NSS_SCHEME_ENV:
|
|
|
|
break;
|
2014-11-27 03:46:59 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (gecos)
|
|
|
|
colon_to_semicolon (gecos);
|
|
|
|
return gecos;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
2015-01-09 01:08:47 +08:00
|
|
|
cygheap_pwdgrp::get_gecos (PUSER_INFO_3 ui, cygpsid &sid, PCWSTR dom,
|
|
|
|
PCWSTR name, bool full_qualified)
|
2014-11-27 03:46:59 +08:00
|
|
|
{
|
|
|
|
char *gecos = NULL;
|
|
|
|
|
|
|
|
for (uint16_t idx = 0; !gecos && idx < NSS_SCHEME_MAX; ++idx)
|
|
|
|
{
|
|
|
|
switch (gecos_scheme[idx].method)
|
|
|
|
{
|
|
|
|
case NSS_SCHEME_FALLBACK:
|
|
|
|
return NULL;
|
|
|
|
case NSS_SCHEME_WINDOWS:
|
2016-08-08 15:45:34 +08:00
|
|
|
if (ui && ui->usri3_full_name && *ui->usri3_full_name)
|
2014-11-27 03:46:59 +08:00
|
|
|
sys_wcstombs_alloc (&gecos, HEAP_NOTHEAP, ui->usri3_full_name);
|
|
|
|
break;
|
|
|
|
case NSS_SCHEME_CYGWIN:
|
|
|
|
case NSS_SCHEME_UNIX:
|
|
|
|
case NSS_SCHEME_FREEATTR:
|
2023-03-28 16:17:14 +08:00
|
|
|
case NSS_SCHEME_ENV:
|
2014-11-27 03:46:59 +08:00
|
|
|
break;
|
|
|
|
case NSS_SCHEME_DESC:
|
2016-08-08 15:45:34 +08:00
|
|
|
if (ui)
|
|
|
|
gecos = fetch_from_description (ui->usri3_comment, L"gecos=\"", 7);
|
2014-11-27 03:46:59 +08:00
|
|
|
break;
|
|
|
|
case NSS_SCHEME_PATH:
|
2015-01-09 01:08:47 +08:00
|
|
|
gecos = fetch_from_path (NULL, ui, sid, gecos_scheme[idx].attrib + 1,
|
2015-02-13 00:55:38 +08:00
|
|
|
dom, NULL, name, full_qualified);
|
2014-11-27 03:46:59 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (gecos)
|
|
|
|
colon_to_semicolon (gecos);
|
|
|
|
return gecos;
|
|
|
|
}
|
|
|
|
|
2014-02-10 03:44:56 +08:00
|
|
|
void
|
|
|
|
cygheap_pwdgrp::_nss_init ()
|
|
|
|
{
|
|
|
|
UNICODE_STRING path;
|
2007-08-22 01:38:27 +08:00
|
|
|
OBJECT_ATTRIBUTES attr;
|
2014-02-10 03:44:56 +08:00
|
|
|
NT_readline rl;
|
|
|
|
tmp_pathbuf tp;
|
|
|
|
char *buf = tp.c_get ();
|
|
|
|
|
|
|
|
PCWSTR rel_path = L"\\etc\\nsswitch.conf";
|
2018-12-25 08:06:34 +08:00
|
|
|
path.Length = cygheap->installation_root.Length
|
|
|
|
+ wcslen (rel_path) * sizeof (WCHAR);
|
2014-10-27 19:33:53 +08:00
|
|
|
path.MaximumLength = path.Length + sizeof (WCHAR);
|
|
|
|
path.Buffer = (PWCHAR) alloca (path.MaximumLength);
|
2018-12-25 08:06:34 +08:00
|
|
|
wcpcpy (wcpcpy (path.Buffer, cygheap->installation_root.Buffer), rel_path);
|
2014-02-10 03:44:56 +08:00
|
|
|
InitializeObjectAttributes (&attr, &path, OBJ_CASE_INSENSITIVE,
|
|
|
|
NULL, NULL);
|
|
|
|
if (rl.init (&attr, buf, NT_MAX_PATH))
|
|
|
|
while ((buf = rl.gets ()))
|
|
|
|
nss_init_line (buf);
|
|
|
|
nss_inited = true;
|
|
|
|
}
|
2003-01-26 13:38:38 +08:00
|
|
|
|
2014-02-10 03:44:56 +08:00
|
|
|
/* Override the ParentIndex value of the PDS_DOMAIN_TRUSTSW entry with the
|
|
|
|
PosixOffset. */
|
|
|
|
#define PosixOffset ParentIndex
|
2003-01-20 10:57:54 +08:00
|
|
|
|
2014-02-10 03:44:56 +08:00
|
|
|
bool
|
|
|
|
cygheap_domain_info::init ()
|
|
|
|
{
|
|
|
|
HANDLE lsa;
|
|
|
|
NTSTATUS status;
|
|
|
|
ULONG ret;
|
|
|
|
/* We *have* to copy the information. Apart from our wish to have the
|
|
|
|
stuff in the cygheap, even when not calling LsaFreeMemory on the result,
|
|
|
|
the data will be overwritten later. From what I gather, the information
|
|
|
|
is, in fact, stored on the stack. */
|
|
|
|
PPOLICY_DNS_DOMAIN_INFO pdom;
|
|
|
|
PPOLICY_ACCOUNT_DOMAIN_INFO adom;
|
|
|
|
PDS_DOMAIN_TRUSTSW td;
|
|
|
|
ULONG tdom_cnt;
|
|
|
|
|
|
|
|
if (adom_name)
|
|
|
|
return true;
|
|
|
|
lsa = lsa_open_policy (NULL, POLICY_VIEW_LOCAL_INFORMATION);
|
|
|
|
if (!lsa)
|
|
|
|
{
|
|
|
|
system_printf ("lsa_open_policy(NULL) failed");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
/* Fetch primary domain information from local LSA. */
|
|
|
|
status = LsaQueryInformationPolicy (lsa, PolicyDnsDomainInformation,
|
|
|
|
(PVOID *) &pdom);
|
|
|
|
if (status != STATUS_SUCCESS)
|
2003-01-26 13:38:38 +08:00
|
|
|
{
|
2014-02-12 01:45:09 +08:00
|
|
|
system_printf ("LsaQueryInformationPolicy(Primary) %y", status);
|
2014-02-10 03:44:56 +08:00
|
|
|
return false;
|
2003-01-26 13:38:38 +08:00
|
|
|
}
|
2014-02-10 03:44:56 +08:00
|
|
|
/* Copy primary domain info to cygheap. */
|
|
|
|
pdom_name = cwcsdup (pdom->Name.Buffer);
|
|
|
|
pdom_dns_name = pdom->DnsDomainName.Length
|
|
|
|
? cwcsdup (pdom->DnsDomainName.Buffer) : NULL;
|
|
|
|
pdom_sid = pdom->Sid;
|
|
|
|
LsaFreeMemory (pdom);
|
|
|
|
/* Fetch account domain information from local LSA. */
|
|
|
|
status = LsaQueryInformationPolicy (lsa, PolicyAccountDomainInformation,
|
|
|
|
(PVOID *) &adom);
|
|
|
|
if (status != STATUS_SUCCESS)
|
|
|
|
{
|
2014-02-12 01:45:09 +08:00
|
|
|
system_printf ("LsaQueryInformationPolicy(Account) %y", status);
|
2014-02-10 03:44:56 +08:00
|
|
|
return false;
|
|
|
|
}
|
2014-02-11 04:16:55 +08:00
|
|
|
/* Copy account domain info to cygheap. If we're running on a DC the account
|
|
|
|
domain is identical to the primary domain. This leads to confusion when
|
|
|
|
trying to compute the uid/gid values. Therefore we invalidate the account
|
|
|
|
domain name if we're running on a DC. */
|
2014-02-10 03:44:56 +08:00
|
|
|
adom_sid = adom->DomainSid;
|
2014-02-11 04:28:32 +08:00
|
|
|
adom_name = cwcsdup (pdom_sid == adom_sid ? L"@" : adom->DomainName.Buffer);
|
2014-02-10 03:44:56 +08:00
|
|
|
LsaFreeMemory (adom);
|
|
|
|
lsa_close_policy (lsa);
|
|
|
|
if (cygheap->dom.member_machine ())
|
|
|
|
{
|
|
|
|
ret = DsEnumerateDomainTrustsW (NULL, DS_DOMAIN_DIRECT_INBOUND
|
|
|
|
| DS_DOMAIN_DIRECT_OUTBOUND
|
|
|
|
| DS_DOMAIN_IN_FOREST,
|
|
|
|
&td, &tdom_cnt);
|
|
|
|
if (ret != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
SetLastError (ret);
|
|
|
|
debug_printf ("DsEnumerateDomainTrusts: %E");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (tdom_cnt == 0)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
/* Copy trusted domain info to cygheap, setting PosixOffset on the fly. */
|
|
|
|
tdom = (PDS_DOMAIN_TRUSTSW)
|
|
|
|
cmalloc_abort (HEAP_BUF, tdom_cnt * sizeof (DS_DOMAIN_TRUSTSW));
|
|
|
|
memcpy (tdom, td, tdom_cnt * sizeof (DS_DOMAIN_TRUSTSW));
|
|
|
|
for (ULONG idx = 0; idx < tdom_cnt; ++idx)
|
|
|
|
{
|
|
|
|
/* Copy... */
|
|
|
|
tdom[idx].NetbiosDomainName = cwcsdup (td[idx].NetbiosDomainName);
|
2014-02-13 22:04:03 +08:00
|
|
|
/* DnsDomainName as well as DomainSid can be NULL. The reason is
|
|
|
|
usually a domain of type TRUST_TYPE_DOWNLEVEL. This can be an
|
|
|
|
old pre-AD domain, or a Netware domain, etc. If DnsDomainName
|
|
|
|
is NULL, just set it to NetbiosDomainName. This simplifies
|
|
|
|
subsequent code which doesn't have to check for a NULL pointer. */
|
|
|
|
tdom[idx].DnsDomainName = td[idx].DnsDomainName
|
|
|
|
? cwcsdup (td[idx].DnsDomainName)
|
|
|
|
: tdom[idx].NetbiosDomainName;
|
|
|
|
if (td[idx].DomainSid)
|
|
|
|
{
|
|
|
|
ULONG len = RtlLengthSid (td[idx].DomainSid);
|
|
|
|
tdom[idx].DomainSid = cmalloc_abort(HEAP_BUF, len);
|
|
|
|
RtlCopySid (len, tdom[idx].DomainSid, td[idx].DomainSid);
|
|
|
|
}
|
2014-02-10 03:44:56 +08:00
|
|
|
/* ...and set PosixOffset to 0. This */
|
|
|
|
tdom[idx].PosixOffset = 0;
|
|
|
|
}
|
|
|
|
NetApiBufferFree (td);
|
|
|
|
tdom_count = tdom_cnt;
|
|
|
|
}
|
2014-02-13 22:04:03 +08:00
|
|
|
/* If we have Microsoft Client for NFS installed, we make use of a name
|
|
|
|
mapping server. This can be either Active Directory to map uids/gids
|
|
|
|
directly to Windows SIDs, or an AD LDS or other RFC 2307 compatible
|
|
|
|
identity store. The name of the mapping domain can be fetched from the
|
|
|
|
registry key created by the NFS client installation and entered by the
|
|
|
|
user via nfsadmin or the "Services For NFS" MMC snap-in.
|
2014-02-10 03:44:56 +08:00
|
|
|
|
|
|
|
Reference:
|
|
|
|
http://blogs.technet.com/b/filecab/archive/2012/10/09/nfs-identity-mapping-in-windows-server-2012.aspx
|
|
|
|
Note that we neither support UNMP nor local passwd/group file mapping,
|
|
|
|
nor UUUA.
|
|
|
|
|
|
|
|
This function returns the mapping server from the aforementioned registry
|
|
|
|
key, or, if none is configured, NULL, which will be resolved to the
|
|
|
|
primary domain of the machine by the ldap_init function.
|
|
|
|
|
|
|
|
The latter is useful to get an RFC 2307 mapping for Samba UNIX accounts,
|
|
|
|
even if no NFS name mapping is configured on the machine. Fortunately,
|
|
|
|
the posixAccount and posixGroup schemas are already available in the
|
2015-12-16 02:54:35 +08:00
|
|
|
Active Directory default setup. */
|
2022-03-07 20:11:34 +08:00
|
|
|
reg_key reg (HKEY_LOCAL_MACHINE, KEY_READ,
|
2014-02-10 03:44:56 +08:00
|
|
|
L"SOFTWARE", L"Microsoft", L"ServicesForNFS", NULL);
|
|
|
|
if (!reg.error ())
|
|
|
|
{
|
|
|
|
DWORD rfc2307 = reg.get_dword (L"Rfc2307", 0);
|
|
|
|
if (rfc2307)
|
|
|
|
{
|
|
|
|
rfc2307_domain_buf = (PWCHAR) ccalloc_abort (HEAP_STR, 257,
|
|
|
|
sizeof (WCHAR));
|
|
|
|
reg.get_string (L"Rfc2307Domain", rfc2307_domain_buf, 257, L"");
|
|
|
|
if (!rfc2307_domain_buf[0])
|
|
|
|
{
|
|
|
|
cfree (rfc2307_domain_buf);
|
|
|
|
rfc2307_domain_buf = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2008-07-25 02:25:52 +08:00
|
|
|
|
2015-03-31 00:05:06 +08:00
|
|
|
PDS_DOMAIN_TRUSTSW
|
|
|
|
cygheap_domain_info::add_domain (PCWSTR domain, PSID sid)
|
|
|
|
{
|
|
|
|
PDS_DOMAIN_TRUSTSW new_tdom;
|
|
|
|
cygsid tsid (sid);
|
|
|
|
|
|
|
|
new_tdom = (PDS_DOMAIN_TRUSTSW) crealloc (tdom, (tdom_count + 1)
|
|
|
|
* sizeof (DS_DOMAIN_TRUSTSW));
|
|
|
|
if (!new_tdom)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
tdom = new_tdom;
|
|
|
|
new_tdom = &tdom[tdom_count];
|
|
|
|
new_tdom->DnsDomainName = new_tdom->NetbiosDomainName = cwcsdup (domain);
|
|
|
|
--*RtlSubAuthorityCountSid (tsid);
|
|
|
|
ULONG len = RtlLengthSid (tsid);
|
|
|
|
new_tdom->DomainSid = cmalloc_abort(HEAP_BUF, len);
|
|
|
|
RtlCopySid (len, new_tdom->DomainSid, tsid);
|
|
|
|
new_tdom->PosixOffset = 0;
|
|
|
|
++tdom_count;
|
|
|
|
return new_tdom;
|
|
|
|
}
|
|
|
|
|
2014-02-10 03:44:56 +08:00
|
|
|
/* Per session, so it changes potentially when switching the user context. */
|
|
|
|
static cygsid logon_sid ("");
|
2008-07-25 02:25:52 +08:00
|
|
|
|
2014-02-10 03:44:56 +08:00
|
|
|
static void
|
|
|
|
get_logon_sid ()
|
|
|
|
{
|
|
|
|
if (PSID (logon_sid) == NO_SID)
|
|
|
|
{
|
|
|
|
NTSTATUS status;
|
|
|
|
ULONG size;
|
|
|
|
tmp_pathbuf tp;
|
2016-03-24 00:42:04 +08:00
|
|
|
PTOKEN_GROUPS groups = (PTOKEN_GROUPS) tp.w_get ();
|
2008-07-25 02:25:52 +08:00
|
|
|
|
2014-02-10 03:44:56 +08:00
|
|
|
status = NtQueryInformationToken (hProcToken, TokenGroups, groups,
|
2016-03-24 00:42:04 +08:00
|
|
|
2 * NT_MAX_PATH, &size);
|
2014-02-10 03:44:56 +08:00
|
|
|
if (!NT_SUCCESS (status))
|
2016-03-24 00:42:04 +08:00
|
|
|
debug_printf ("NtQueryInformationToken (TokenGroups) %y", status);
|
2014-02-10 03:44:56 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
for (DWORD pg = 0; pg < groups->GroupCount; ++pg)
|
|
|
|
if (groups->Groups[pg].Attributes & SE_GROUP_LOGON_ID)
|
|
|
|
{
|
|
|
|
logon_sid = groups->Groups[pg].Sid;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-08 15:45:34 +08:00
|
|
|
/* Fetch special AzureAD group, which is part of the token group list but
|
|
|
|
*not* recognized by LookupAccountSid (ERROR_NONE_MAPPED). */
|
|
|
|
static cygsid azure_grp_sid ("");
|
|
|
|
|
|
|
|
static void
|
|
|
|
get_azure_grp_sid ()
|
|
|
|
{
|
|
|
|
if (PSID (azure_grp_sid) == NO_SID)
|
|
|
|
{
|
|
|
|
NTSTATUS status;
|
|
|
|
ULONG size;
|
|
|
|
tmp_pathbuf tp;
|
|
|
|
PTOKEN_GROUPS groups = (PTOKEN_GROUPS) tp.w_get ();
|
|
|
|
|
|
|
|
status = NtQueryInformationToken (hProcToken, TokenGroups, groups,
|
|
|
|
2 * NT_MAX_PATH, &size);
|
|
|
|
if (!NT_SUCCESS (status))
|
|
|
|
debug_printf ("NtQueryInformationToken (TokenGroups) %y", status);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (DWORD pg = 0; pg < groups->GroupCount; ++pg)
|
|
|
|
if (sid_id_auth (groups->Groups[pg].Sid) == 12)
|
|
|
|
{
|
|
|
|
azure_grp_sid = groups->Groups[pg].Sid;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-10 03:44:56 +08:00
|
|
|
void *
|
2014-02-17 23:36:33 +08:00
|
|
|
pwdgrp::add_account_post_fetch (char *line, bool lock)
|
2014-02-10 03:44:56 +08:00
|
|
|
{
|
2015-02-28 20:12:34 +08:00
|
|
|
void *ret = NULL;
|
|
|
|
|
2014-02-10 03:44:56 +08:00
|
|
|
if (line)
|
2019-02-13 18:10:41 +08:00
|
|
|
{
|
2014-02-17 23:36:33 +08:00
|
|
|
if (lock)
|
|
|
|
pglock.init ("pglock")->acquire ();
|
2015-02-28 20:12:34 +08:00
|
|
|
if (add_line (line))
|
|
|
|
ret = ((char *) pwdgrp_buf) + (curr_lines - 1) * pwdgrp_buf_elem_size;
|
2014-02-17 23:36:33 +08:00
|
|
|
if (lock)
|
|
|
|
pglock.release ();
|
2014-02-10 03:44:56 +08:00
|
|
|
}
|
2015-02-28 20:12:34 +08:00
|
|
|
return ret;
|
2014-02-10 03:44:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
pwdgrp::add_account_from_file (cygpsid &sid)
|
|
|
|
{
|
|
|
|
if (!path.MaximumLength)
|
|
|
|
return NULL;
|
|
|
|
fetch_user_arg_t arg;
|
|
|
|
arg.type = SID_arg;
|
|
|
|
arg.sid = &sid;
|
|
|
|
char *line = fetch_account_from_file (arg);
|
2014-02-17 23:36:33 +08:00
|
|
|
return (struct passwd *) add_account_post_fetch (line, true);
|
2014-02-10 03:44:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
pwdgrp::add_account_from_file (const char *name)
|
|
|
|
{
|
|
|
|
if (!path.MaximumLength)
|
|
|
|
return NULL;
|
|
|
|
fetch_user_arg_t arg;
|
|
|
|
arg.type = NAME_arg;
|
|
|
|
arg.name = name;
|
|
|
|
char *line = fetch_account_from_file (arg);
|
2014-02-17 23:36:33 +08:00
|
|
|
return (struct passwd *) add_account_post_fetch (line, true);
|
2014-02-10 03:44:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
pwdgrp::add_account_from_file (uint32_t id)
|
|
|
|
{
|
|
|
|
if (!path.MaximumLength)
|
|
|
|
return NULL;
|
|
|
|
fetch_user_arg_t arg;
|
|
|
|
arg.type = ID_arg;
|
|
|
|
arg.id = id;
|
|
|
|
char *line = fetch_account_from_file (arg);
|
2014-02-17 23:36:33 +08:00
|
|
|
return (struct passwd *) add_account_post_fetch (line, true);
|
2014-02-10 03:44:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
2014-03-08 04:38:48 +08:00
|
|
|
pwdgrp::add_account_from_windows (cygpsid &sid, cyg_ldap *pldap)
|
2014-02-10 03:44:56 +08:00
|
|
|
{
|
|
|
|
fetch_user_arg_t arg;
|
|
|
|
arg.type = SID_arg;
|
|
|
|
arg.sid = &sid;
|
2014-03-08 04:38:48 +08:00
|
|
|
char *line = fetch_account_from_windows (arg, pldap);
|
2014-02-10 03:44:56 +08:00
|
|
|
if (!line)
|
|
|
|
return NULL;
|
2014-03-13 01:36:56 +08:00
|
|
|
return add_account_post_fetch (line, true);
|
2014-02-10 03:44:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
2014-03-08 04:38:48 +08:00
|
|
|
pwdgrp::add_account_from_windows (const char *name, cyg_ldap *pldap)
|
2014-02-10 03:44:56 +08:00
|
|
|
{
|
|
|
|
fetch_user_arg_t arg;
|
|
|
|
arg.type = NAME_arg;
|
|
|
|
arg.name = name;
|
2014-03-08 04:38:48 +08:00
|
|
|
char *line = fetch_account_from_windows (arg, pldap);
|
2014-02-10 03:44:56 +08:00
|
|
|
if (!line)
|
|
|
|
return NULL;
|
2014-03-13 01:36:56 +08:00
|
|
|
return add_account_post_fetch (line, true);
|
2014-02-10 03:44:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
2014-03-08 04:38:48 +08:00
|
|
|
pwdgrp::add_account_from_windows (uint32_t id, cyg_ldap *pldap)
|
2014-02-10 03:44:56 +08:00
|
|
|
{
|
|
|
|
fetch_user_arg_t arg;
|
|
|
|
arg.type = ID_arg;
|
|
|
|
arg.id = id;
|
2014-03-08 04:38:48 +08:00
|
|
|
char *line = fetch_account_from_windows (arg, pldap);
|
2014-02-10 03:44:56 +08:00
|
|
|
if (!line)
|
|
|
|
return NULL;
|
2014-03-13 01:36:56 +08:00
|
|
|
return add_account_post_fetch (line, true);
|
2014-02-10 03:44:56 +08:00
|
|
|
}
|
|
|
|
|
2015-02-24 04:51:12 +08:00
|
|
|
/* Called from internal_getgrfull, in turn called from internal_getgroups. */
|
|
|
|
struct group *
|
2015-02-25 04:52:57 +08:00
|
|
|
pwdgrp::add_group_from_windows (fetch_acc_t &full_acc, cyg_ldap *pldap)
|
2015-02-24 04:51:12 +08:00
|
|
|
{
|
|
|
|
fetch_user_arg_t arg;
|
2015-02-25 04:52:57 +08:00
|
|
|
arg.type = FULL_acc_arg;
|
|
|
|
arg.full_acc = &full_acc;
|
2015-02-24 04:51:12 +08:00
|
|
|
char *line = fetch_account_from_windows (arg, pldap);
|
|
|
|
if (!line)
|
|
|
|
return NULL;
|
|
|
|
return (struct group *) add_account_post_fetch (line, true);
|
|
|
|
}
|
|
|
|
|
2014-02-10 03:44:56 +08:00
|
|
|
/* Check if file exists and if it has been written to since last checked.
|
|
|
|
If file has been changed, invalidate the current cache.
|
2019-02-13 18:10:41 +08:00
|
|
|
|
2014-02-10 03:44:56 +08:00
|
|
|
If the file doesn't exist when this function is called the first time,
|
|
|
|
by the first Cygwin process in a process tree, the file will never be
|
|
|
|
visited again by any process in this process tree. This is important,
|
|
|
|
because we cannot allow a change of UID/GID values for the lifetime
|
|
|
|
of a process tree.
|
2019-02-13 18:10:41 +08:00
|
|
|
|
2014-02-10 03:44:56 +08:00
|
|
|
If the file gets deleted or unreadable, the file cache will stay in
|
|
|
|
place, but we won't try to read new accounts from the file.
|
2019-02-13 18:10:41 +08:00
|
|
|
|
2014-02-10 03:44:56 +08:00
|
|
|
The return code indicates to the calling function if the file exists. */
|
|
|
|
bool
|
2014-03-08 04:38:48 +08:00
|
|
|
pwdgrp::check_file ()
|
2014-02-10 03:44:56 +08:00
|
|
|
{
|
|
|
|
FILE_BASIC_INFORMATION fbi;
|
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
if (!path.Buffer)
|
2003-01-20 10:57:54 +08:00
|
|
|
{
|
2014-03-08 04:38:48 +08:00
|
|
|
PCWSTR rel_path = is_group () ? L"\\etc\\group" : L"\\etc\\passwd";
|
2018-12-25 08:06:34 +08:00
|
|
|
path.Length = cygheap->installation_root.Length
|
|
|
|
+ wcslen (rel_path) * sizeof (WCHAR);
|
2014-10-27 19:33:53 +08:00
|
|
|
path.MaximumLength = path.Length + sizeof (WCHAR);
|
|
|
|
path.Buffer = (PWCHAR) cmalloc_abort (HEAP_BUF, path.MaximumLength);
|
2018-12-25 08:06:34 +08:00
|
|
|
wcpcpy (wcpcpy (path.Buffer, cygheap->installation_root.Buffer),
|
|
|
|
rel_path);
|
2014-02-10 03:44:56 +08:00
|
|
|
InitializeObjectAttributes (&attr, &path, OBJ_CASE_INSENSITIVE,
|
|
|
|
NULL, NULL);
|
2003-01-17 13:18:30 +08:00
|
|
|
}
|
2014-02-10 03:44:56 +08:00
|
|
|
else if (path.MaximumLength == 0) /* Indicates that the file doesn't exist. */
|
|
|
|
return false;
|
|
|
|
status = NtQueryAttributesFile (&attr, &fbi);
|
2007-08-22 01:38:27 +08:00
|
|
|
if (!NT_SUCCESS (status))
|
|
|
|
{
|
2014-02-10 03:44:56 +08:00
|
|
|
if (last_modified.QuadPart)
|
|
|
|
last_modified.QuadPart = 0LL;
|
|
|
|
else
|
|
|
|
path.MaximumLength = 0;
|
|
|
|
return false;
|
2007-08-22 01:38:27 +08:00
|
|
|
}
|
2014-02-10 03:44:56 +08:00
|
|
|
if (fbi.LastWriteTime.QuadPart > last_modified.QuadPart)
|
2007-08-22 01:38:27 +08:00
|
|
|
{
|
2014-02-10 03:44:56 +08:00
|
|
|
last_modified.QuadPart = fbi.LastWriteTime.QuadPart;
|
|
|
|
if (curr_lines > 0)
|
|
|
|
{
|
|
|
|
pglock.init ("pglock")->acquire ();
|
|
|
|
int curr = curr_lines;
|
|
|
|
curr_lines = 0;
|
|
|
|
for (int i = 0; i < curr; ++i)
|
2014-03-08 04:38:48 +08:00
|
|
|
cfree (is_group () ? this->group ()[i].g.gr_name
|
2014-02-10 03:44:56 +08:00
|
|
|
: this->passwd ()[i].p.pw_name);
|
|
|
|
pglock.release ();
|
|
|
|
}
|
2007-08-22 01:38:27 +08:00
|
|
|
}
|
2014-02-10 03:44:56 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
|
|
|
pwdgrp::fetch_account_from_line (fetch_user_arg_t &arg, const char *line)
|
|
|
|
{
|
|
|
|
char *p, *e;
|
|
|
|
|
|
|
|
switch (arg.type)
|
|
|
|
{
|
|
|
|
case SID_arg:
|
|
|
|
/* Ignore fields, just scan for SID string. */
|
|
|
|
if (!(p = strstr (line, arg.name)) || p[arg.len] != ':')
|
|
|
|
return NULL;
|
|
|
|
break;
|
|
|
|
case NAME_arg:
|
|
|
|
/* First field is always name. */
|
|
|
|
if (!strncasematch (line, arg.name, arg.len) || line[arg.len] != ':')
|
|
|
|
return NULL;
|
|
|
|
break;
|
|
|
|
case ID_arg:
|
|
|
|
/* Skip to third field. */
|
|
|
|
if (!(p = strchr (line, ':')) || !(p = strchr (p + 1, ':')))
|
|
|
|
return NULL;
|
|
|
|
if (strtoul (p + 1, &e, 10) != arg.id || !e || *e != ':')
|
|
|
|
return NULL;
|
|
|
|
break;
|
2015-02-24 04:51:12 +08:00
|
|
|
default:
|
|
|
|
return NULL;
|
2014-02-10 03:44:56 +08:00
|
|
|
}
|
|
|
|
return cstrdup (line);
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
|
|
|
pwdgrp::fetch_account_from_file (fetch_user_arg_t &arg)
|
|
|
|
{
|
|
|
|
NT_readline rl;
|
|
|
|
tmp_pathbuf tp;
|
|
|
|
char *buf = tp.c_get ();
|
2014-02-13 22:04:03 +08:00
|
|
|
char str[128];
|
2014-02-10 03:44:56 +08:00
|
|
|
char *ret = NULL;
|
|
|
|
|
|
|
|
/* Create search string. */
|
|
|
|
switch (arg.type)
|
|
|
|
{
|
|
|
|
case SID_arg:
|
|
|
|
/* Override SID with SID string. */
|
|
|
|
arg.sid->string (str);
|
|
|
|
arg.name = str;
|
2020-08-06 03:58:22 +08:00
|
|
|
fallthrough;
|
2014-02-10 03:44:56 +08:00
|
|
|
case NAME_arg:
|
|
|
|
arg.len = strlen (arg.name);
|
|
|
|
break;
|
|
|
|
case ID_arg:
|
|
|
|
break;
|
2015-02-24 04:51:12 +08:00
|
|
|
default:
|
|
|
|
return NULL;
|
2014-02-10 03:44:56 +08:00
|
|
|
}
|
|
|
|
if (rl.init (&attr, buf, NT_MAX_PATH))
|
|
|
|
while ((buf = rl.gets ()))
|
|
|
|
if ((ret = fetch_account_from_line (arg, buf)))
|
|
|
|
return ret;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-02-13 22:04:03 +08:00
|
|
|
static ULONG
|
2014-02-27 20:57:27 +08:00
|
|
|
fetch_posix_offset (PDS_DOMAIN_TRUSTSW td, cyg_ldap *cldap)
|
2014-02-13 22:04:03 +08:00
|
|
|
{
|
2014-07-29 16:53:13 +08:00
|
|
|
uint32_t id_val = UINT32_MAX;
|
2014-02-13 22:04:03 +08:00
|
|
|
|
|
|
|
if (!td->PosixOffset && !(td->Flags & DS_DOMAIN_PRIMARY) && td->DomainSid)
|
|
|
|
{
|
2014-07-14 21:33:20 +08:00
|
|
|
if (cldap->open (NULL) == NO_ERROR)
|
2014-02-27 20:57:27 +08:00
|
|
|
id_val = cldap->fetch_posix_offset_for_domain (td->DnsDomainName);
|
2014-07-29 16:53:13 +08:00
|
|
|
if (id_val < PRIMARY_POSIX_OFFSET)
|
|
|
|
{
|
|
|
|
/* If the offset is less than the primay domain offset, we're bound
|
|
|
|
to suffer collisions with system and local accounts. Move offset
|
|
|
|
to a fixed replacement fake offset. This may result in collisions
|
|
|
|
between other domains all of which were moved to this replacement
|
|
|
|
offset, but we can't fix all problems caused by careless admins. */
|
|
|
|
id_val = UNUSABLE_POSIX_OFFSET;
|
|
|
|
}
|
|
|
|
else if (id_val == UINT32_MAX)
|
2014-02-13 22:04:03 +08:00
|
|
|
{
|
2014-07-14 21:33:20 +08:00
|
|
|
/* We're probably running under a local account, so we're not allowed
|
2014-07-29 16:53:13 +08:00
|
|
|
to fetch any information from AD beyond the most obvious. Fake a
|
|
|
|
reasonable posix offset as above and hope for the best. */
|
|
|
|
id_val = NOACCESS_POSIX_OFFSET;
|
2014-02-13 22:04:03 +08:00
|
|
|
}
|
2014-07-14 21:33:20 +08:00
|
|
|
td->PosixOffset = id_val;
|
2014-02-13 22:04:03 +08:00
|
|
|
}
|
|
|
|
return td->PosixOffset;
|
|
|
|
}
|
|
|
|
|
2018-08-28 00:28:33 +08:00
|
|
|
/* If LookupAccountName fails, we check the name for a known constructed name
|
|
|
|
with this function. Return true if we could create a valid SID from name
|
|
|
|
in sid. sep is either a pointer to thr backslash in name, or NULL if name
|
|
|
|
is not a qualified DOMAIN\\name string. */
|
|
|
|
bool
|
|
|
|
pwdgrp::construct_sid_from_name (cygsid &sid, wchar_t *name, wchar_t *sep)
|
|
|
|
{
|
|
|
|
unsigned long rid;
|
|
|
|
wchar_t *endptr;
|
|
|
|
|
|
|
|
if (sep && wcscmp (name, L"no\\body") == 0)
|
|
|
|
{
|
|
|
|
/* Special case "nobody" for reproducible construction of a
|
|
|
|
nobody SID for WinFsp and similar services. We use the
|
|
|
|
value 65534 which is -2 with 16 bit uid/gids. */
|
|
|
|
sid.create (0, 1, 0xfffe);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (sep && wcscmp (name, L"AzureAD\\Group") == 0)
|
|
|
|
{
|
|
|
|
get_azure_grp_sid ();
|
|
|
|
if (PSID (logon_sid) != NO_SID)
|
|
|
|
{
|
|
|
|
sid = azure_grp_sid;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2018-08-28 17:26:52 +08:00
|
|
|
if (!sep && wcscmp (name, L"CurrentSession") == 0)
|
|
|
|
{
|
|
|
|
get_logon_sid ();
|
|
|
|
if (PSID (logon_sid) == NO_SID)
|
|
|
|
return false;
|
|
|
|
sid = logon_sid;
|
|
|
|
return true;
|
|
|
|
}
|
2018-08-28 00:28:33 +08:00
|
|
|
if (!sep && wcscmp (name, L"Authentication authority asserted identity") == 0)
|
|
|
|
{
|
|
|
|
sid.create (18, 1, 1);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (!sep && wcscmp (name, L"Service asserted identity") == 0)
|
|
|
|
{
|
|
|
|
sid.create (18, 1, 2);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (sep && wcsncmp (name, L"Unix_", 5) == 0)
|
|
|
|
{
|
|
|
|
int type;
|
|
|
|
|
|
|
|
if (wcsncmp (name + 5, L"User\\", 5) == 0)
|
|
|
|
type = 1;
|
|
|
|
else if (wcsncmp (name + 5, L"Group\\", 6) == 0)
|
|
|
|
type = 2;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
|
|
|
|
rid = wcstoul (sep + 1, &endptr, 10);
|
|
|
|
if (*endptr == L'\0')
|
|
|
|
{
|
|
|
|
sid.create (22, 2, type, rid);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
/* At this point we have to check if the domain name is one of the
|
|
|
|
known domains, and if the account name is one of "User(DWORD)"
|
|
|
|
or "Group(DWORD)". */
|
|
|
|
if (sep)
|
|
|
|
{
|
|
|
|
wchar_t *numstr = NULL;
|
|
|
|
bool have_domain = false;
|
|
|
|
|
|
|
|
if (wcsncmp (sep + 1, L"User(", 5) == 0)
|
|
|
|
numstr = sep + 1 + 5;
|
|
|
|
else if (wcsncmp (sep + 1, L"Group(", 6) == 0)
|
|
|
|
numstr = sep + 1 + 6;
|
|
|
|
if (!numstr)
|
|
|
|
return false;
|
|
|
|
rid = wcstoul (numstr, &endptr, 10);
|
|
|
|
if (wcscmp (endptr, L")") != 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (wcsncasecmp (name, cygheap->dom.account_flat_name (), sep - name)
|
|
|
|
== 0)
|
|
|
|
{
|
|
|
|
sid = cygheap->dom.account_sid ();
|
|
|
|
have_domain = true;
|
|
|
|
}
|
|
|
|
else if (wcsncasecmp (name, cygheap->dom.primary_flat_name (), sep - name)
|
|
|
|
== 0)
|
|
|
|
{
|
|
|
|
sid = cygheap->dom.primary_sid ();
|
|
|
|
have_domain = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PDS_DOMAIN_TRUSTSW td = NULL;
|
|
|
|
|
|
|
|
for (ULONG idx = 0; (td = cygheap->dom.trusted_domain (idx)); ++idx)
|
|
|
|
{
|
|
|
|
if (wcsncasecmp (name, td->NetbiosDomainName, sep - name) == 0)
|
|
|
|
{
|
|
|
|
sid = td->DomainSid;
|
|
|
|
have_domain = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (have_domain)
|
|
|
|
{
|
|
|
|
sid.append (rid);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-02-10 03:44:56 +08:00
|
|
|
char *
|
2014-03-08 04:38:48 +08:00
|
|
|
pwdgrp::fetch_account_from_windows (fetch_user_arg_t &arg, cyg_ldap *pldap)
|
2014-02-10 03:44:56 +08:00
|
|
|
{
|
|
|
|
/* Used in LookupAccount calls. */
|
2019-02-13 19:41:55 +08:00
|
|
|
WCHAR namebuf[DNLEN + 1 + UNLEN + 1], *name = namebuf;
|
2014-02-10 03:44:56 +08:00
|
|
|
WCHAR dom[DNLEN + 1] = L"";
|
|
|
|
cygsid csid;
|
|
|
|
DWORD nlen = UNLEN + 1;
|
|
|
|
DWORD dlen = DNLEN + 1;
|
2014-05-06 20:28:33 +08:00
|
|
|
DWORD slen = SECURITY_MAX_SID_SIZE;
|
2014-02-27 20:57:27 +08:00
|
|
|
cygpsid sid (NO_SID);
|
2014-02-10 03:44:56 +08:00
|
|
|
SID_NAME_USE acc_type;
|
|
|
|
BOOL ret = false;
|
|
|
|
/* Cygwin user name style. */
|
2014-08-04 23:50:42 +08:00
|
|
|
bool fully_qualified_name = false;
|
2014-02-10 03:44:56 +08:00
|
|
|
/* Computed stuff. */
|
|
|
|
uid_t uid = ILLEGAL_UID;
|
|
|
|
gid_t gid = ILLEGAL_GID;
|
|
|
|
bool is_domain_account = true;
|
|
|
|
PCWSTR domain = NULL;
|
2014-11-27 03:46:59 +08:00
|
|
|
char *shell = NULL;
|
|
|
|
char *home = NULL;
|
|
|
|
char *gecos = NULL;
|
2014-02-27 20:57:27 +08:00
|
|
|
/* Temporary stuff. */
|
2014-02-10 03:44:56 +08:00
|
|
|
PWCHAR p;
|
2019-02-13 20:16:15 +08:00
|
|
|
PWCHAR val;
|
2014-02-10 03:44:56 +08:00
|
|
|
WCHAR sidstr[128];
|
|
|
|
ULONG posix_offset = 0;
|
2014-02-11 19:51:29 +08:00
|
|
|
uint32_t id_val;
|
2014-02-27 20:57:27 +08:00
|
|
|
cyg_ldap loc_ldap;
|
|
|
|
cyg_ldap *cldap = pldap ?: &loc_ldap;
|
2014-02-10 03:44:56 +08:00
|
|
|
|
|
|
|
/* Initialize */
|
|
|
|
if (!cygheap->dom.init ())
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
switch (arg.type)
|
2007-08-22 01:38:27 +08:00
|
|
|
{
|
2015-02-25 04:52:57 +08:00
|
|
|
case FULL_acc_arg:
|
2015-02-24 04:51:12 +08:00
|
|
|
{
|
2015-02-25 04:52:57 +08:00
|
|
|
sid = arg.full_acc->sid;
|
|
|
|
*wcpncpy (name, arg.full_acc->name->Buffer,
|
|
|
|
arg.full_acc->name->Length / sizeof (WCHAR)) = L'\0';
|
|
|
|
*wcpncpy (dom, arg.full_acc->dom->Buffer,
|
|
|
|
arg.full_acc->dom->Length / sizeof (WCHAR)) = L'\0';
|
|
|
|
acc_type = arg.full_acc->acc_type;
|
2019-02-13 18:10:41 +08:00
|
|
|
ret = acc_type != SidTypeUnknown;
|
2015-02-24 04:51:12 +08:00
|
|
|
}
|
|
|
|
break;
|
2014-02-10 03:44:56 +08:00
|
|
|
case SID_arg:
|
|
|
|
sid = *arg.sid;
|
|
|
|
ret = LookupAccountSidW (NULL, sid, name, &nlen, dom, &dlen, &acc_type);
|
2014-02-17 23:36:33 +08:00
|
|
|
if (!ret
|
|
|
|
&& cygheap->dom.member_machine ()
|
|
|
|
&& sid_id_auth (sid) == 5 /* SECURITY_NT_AUTHORITY */
|
|
|
|
&& sid_sub_auth (sid, 0) == SECURITY_BUILTIN_DOMAIN_RID)
|
|
|
|
{
|
|
|
|
/* LookupAccountSid called on a non-DC cannot resolve aliases which
|
|
|
|
are not defined in the local SAM. If we encounter an alias which
|
|
|
|
can't be resolved, and if we're a domain member machine, ask a DC.
|
|
|
|
Do *not* use LookupAccountSidW. It can take ages when called on a
|
|
|
|
DC for some weird reason. Use LDAP instead. */
|
2015-02-13 00:55:38 +08:00
|
|
|
if (cldap->fetch_ad_account (sid, true)
|
2019-02-13 19:42:56 +08:00
|
|
|
&& (val = cldap->get_account_name ()))
|
2014-02-17 23:36:33 +08:00
|
|
|
{
|
|
|
|
wcpcpy (name, val);
|
|
|
|
wcpcpy (dom, L"BUILTIN");
|
|
|
|
acc_type = SidTypeAlias;
|
|
|
|
ret = true;
|
|
|
|
}
|
|
|
|
}
|
2014-02-13 22:04:03 +08:00
|
|
|
if (!ret)
|
|
|
|
debug_printf ("LookupAccountSid(%W), %E", sid.string (sidstr));
|
2014-02-10 03:44:56 +08:00
|
|
|
break;
|
|
|
|
case NAME_arg:
|
2014-08-04 23:50:42 +08:00
|
|
|
bool fq_name;
|
|
|
|
|
|
|
|
fq_name = false;
|
|
|
|
/* Copy over to wchar for search. */
|
|
|
|
sys_mbstowcs (name, UNLEN + 1, arg.name);
|
2015-03-31 17:54:34 +08:00
|
|
|
/* If the incoming name has a backslash or at sign, and neither backslash
|
|
|
|
nor at are the domain separator chars, the name is invalid. */
|
2022-12-02 22:13:24 +08:00
|
|
|
if ((p = wcspbrk (name, L"\\@")) && *p != NSS_SEPARATOR_CHAR)
|
2015-03-31 17:54:34 +08:00
|
|
|
{
|
|
|
|
debug_printf ("Invalid account name <%s> (backslash/at)", arg.name);
|
|
|
|
return NULL;
|
|
|
|
}
|
2014-02-10 03:44:56 +08:00
|
|
|
/* Replace domain separator char with backslash and make sure p is NULL
|
2014-09-01 02:18:49 +08:00
|
|
|
or points to the backslash. */
|
2022-12-02 22:13:24 +08:00
|
|
|
if ((p = wcschr (name, NSS_SEPARATOR_CHAR)))
|
2014-08-04 23:50:42 +08:00
|
|
|
{
|
|
|
|
fq_name = true;
|
2019-02-18 17:13:35 +08:00
|
|
|
*p = L'\\';
|
2014-08-04 23:50:42 +08:00
|
|
|
}
|
2014-02-10 03:44:56 +08:00
|
|
|
sid = csid;
|
|
|
|
ret = LookupAccountNameW (NULL, name, sid, &slen, dom, &dlen, &acc_type);
|
2014-08-04 23:50:42 +08:00
|
|
|
/* If this is a name-only S-1-5-21 account *and* it's a machine account
|
|
|
|
on a domain member machine, then we found the wrong one. Another
|
|
|
|
weird, but perfectly valid case is, if the group name is identical
|
|
|
|
to the domain name. Try again with domain name prepended. */
|
|
|
|
if (ret
|
|
|
|
&& !fq_name
|
|
|
|
&& sid_id_auth (sid) == 5 /* SECURITY_NT_AUTHORITY */
|
|
|
|
&& sid_sub_auth (sid, 0) == SECURITY_NT_NON_UNIQUE
|
|
|
|
&& cygheap->dom.member_machine ()
|
|
|
|
&& (wcscasecmp (dom, cygheap->dom.account_flat_name ()) == 0
|
|
|
|
|| acc_type == SidTypeDomain))
|
|
|
|
{
|
|
|
|
p = wcpcpy (name, cygheap->dom.primary_flat_name ());
|
|
|
|
*p = L'\\';
|
|
|
|
sys_mbstowcs (p + 1, UNLEN + 1, arg.name);
|
|
|
|
slen = SECURITY_MAX_SID_SIZE;
|
|
|
|
dlen = DNLEN + 1;
|
|
|
|
sid = csid;
|
|
|
|
ret = LookupAccountNameW (NULL, name, sid, &slen, dom, &dlen,
|
|
|
|
&acc_type);
|
|
|
|
}
|
2014-02-10 03:44:56 +08:00
|
|
|
if (!ret)
|
|
|
|
{
|
2018-08-28 00:28:33 +08:00
|
|
|
/* For accounts which can't be resolved by Windows, try if
|
|
|
|
it's one of the special names we use for special accounts. */
|
|
|
|
if (construct_sid_from_name (csid, name, p))
|
|
|
|
break;
|
2014-02-10 03:44:56 +08:00
|
|
|
debug_printf ("LookupAccountNameW (%W), %E", name);
|
|
|
|
return NULL;
|
|
|
|
}
|
2014-08-04 23:50:42 +08:00
|
|
|
/* We can skip the backslash in the rest of this function. */
|
2014-02-10 03:44:56 +08:00
|
|
|
if (p)
|
|
|
|
name = p + 1;
|
2014-05-14 19:27:47 +08:00
|
|
|
/* Last but not least, some validity checks on the name style. */
|
2014-08-04 23:50:42 +08:00
|
|
|
if (!fq_name)
|
2014-05-14 19:27:47 +08:00
|
|
|
{
|
2016-08-08 15:45:34 +08:00
|
|
|
/* AzureAD user must be prepended by "domain" name. */
|
|
|
|
if (sid_id_auth (sid) == 12)
|
|
|
|
return NULL;
|
2014-08-04 23:50:42 +08:00
|
|
|
/* name_only account is either builtin or primary domain, or
|
|
|
|
account domain on non-domain machines. */
|
2014-05-14 19:27:47 +08:00
|
|
|
if (sid_id_auth (sid) == 5 /* SECURITY_NT_AUTHORITY */
|
|
|
|
&& sid_sub_auth (sid, 0) == SECURITY_NT_NON_UNIQUE)
|
|
|
|
{
|
2014-08-04 23:50:42 +08:00
|
|
|
if (cygheap->dom.member_machine ())
|
|
|
|
{
|
|
|
|
if (wcscasecmp (dom, cygheap->dom.primary_flat_name ()) != 0)
|
|
|
|
{
|
|
|
|
debug_printf ("Invalid account name <%s> (name only/"
|
|
|
|
"non primary on domain machine)", arg.name);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (wcscasecmp (dom, cygheap->dom.account_flat_name ()) != 0)
|
|
|
|
{
|
|
|
|
debug_printf ("Invalid account name <%s> (name only/"
|
|
|
|
"non machine on non-domain machine)", arg.name);
|
|
|
|
return NULL;
|
|
|
|
}
|
2014-05-14 19:27:47 +08:00
|
|
|
}
|
2014-08-04 23:50:42 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-08-08 15:45:34 +08:00
|
|
|
/* AzureAD accounts should be fully qualifed either. */
|
|
|
|
if (sid_id_auth (sid) == 12)
|
|
|
|
break;
|
2015-01-13 17:06:53 +08:00
|
|
|
/* Otherwise, no fully_qualified for builtin accounts, except for
|
|
|
|
NT SERVICE, for which we require the prefix. Note that there's
|
|
|
|
no equivalent test in the `if (!fq_name)' branch above, because
|
|
|
|
LookupAccountName never returns NT SERVICE accounts if they are
|
|
|
|
not prependend with the domain anyway. */
|
2014-05-14 19:27:47 +08:00
|
|
|
if (sid_id_auth (sid) != 5 /* SECURITY_NT_AUTHORITY */
|
2015-01-13 17:06:53 +08:00
|
|
|
|| (sid_sub_auth (sid, 0) != SECURITY_NT_NON_UNIQUE
|
|
|
|
&& sid_sub_auth (sid, 0) != SECURITY_SERVICE_ID_BASE_RID))
|
2014-05-14 19:27:47 +08:00
|
|
|
{
|
|
|
|
debug_printf ("Invalid account name <%s> (fully qualified/"
|
2015-01-13 17:06:53 +08:00
|
|
|
"not NON_UNIQUE or NT_SERVICE)", arg.name);
|
2014-05-14 19:27:47 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
/* Domain member and domain == primary domain? */
|
|
|
|
if (cygheap->dom.member_machine ())
|
|
|
|
{
|
|
|
|
if (!wcscasecmp (dom, cygheap->dom.primary_flat_name ()))
|
|
|
|
{
|
|
|
|
debug_printf ("Invalid account name <%s> (fully qualified/"
|
|
|
|
"primary domain account)", arg.name);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Not domain member and domain == account domain? */
|
|
|
|
else if (!wcscasecmp (dom, cygheap->dom.account_flat_name ()))
|
|
|
|
{
|
|
|
|
debug_printf ("Invalid account name <%s> (fully qualified/"
|
|
|
|
"local account)", arg.name);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
2014-02-10 03:44:56 +08:00
|
|
|
break;
|
|
|
|
case ID_arg:
|
|
|
|
/* Construct SID from ID using the SFU rules, just like the code below
|
|
|
|
goes the opposite route. */
|
|
|
|
#ifndef INTERIX_COMPATIBLE
|
|
|
|
/* Except for Builtin and Alias groups in the SECURITY_NT_AUTHORITY.
|
|
|
|
We create uid/gid values compatible with the old values generated
|
|
|
|
by mkpasswd/mkgroup. */
|
|
|
|
if (arg.id < 0x200)
|
2016-03-12 23:39:19 +08:00
|
|
|
csid.create (5, 1, arg.id & 0x1ff);
|
2015-11-30 04:21:35 +08:00
|
|
|
else if (arg.id <= 0x3e7)
|
2016-03-12 23:39:19 +08:00
|
|
|
csid.create (5, 2, 32, arg.id & 0x3ff);
|
2014-05-07 20:07:12 +08:00
|
|
|
else if (arg.id == 0x3e8) /* Special case "Other Organization" */
|
2016-03-12 23:39:19 +08:00
|
|
|
csid.create (5, 1, 1000);
|
2014-02-10 03:44:56 +08:00
|
|
|
else
|
|
|
|
#endif
|
|
|
|
if (arg.id == 0xffe)
|
|
|
|
{
|
|
|
|
/* OtherSession != Logon SID. */
|
|
|
|
get_logon_sid ();
|
|
|
|
/* LookupAccountSidW will fail. */
|
|
|
|
sid = csid = logon_sid;
|
|
|
|
sid_sub_auth_rid (sid) = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (arg.id == 0xfff)
|
|
|
|
{
|
|
|
|
/* CurrentSession == Logon SID. */
|
|
|
|
get_logon_sid ();
|
|
|
|
/* LookupAccountSidW will fail. */
|
|
|
|
sid = logon_sid;
|
|
|
|
break;
|
|
|
|
}
|
2016-08-08 15:45:34 +08:00
|
|
|
else if (arg.id == 0x1000)
|
|
|
|
{
|
|
|
|
/* AzureAD S-1-12-1-W-X-Y-Z user */
|
|
|
|
csid = cygheap->user.saved_sid ();
|
|
|
|
}
|
|
|
|
else if (arg.id == 0x1001)
|
|
|
|
{
|
|
|
|
/* Special AzureAD group SID */
|
|
|
|
get_azure_grp_sid ();
|
|
|
|
/* LookupAccountSidW will fail. */
|
|
|
|
sid = csid = azure_grp_sid;
|
|
|
|
break;
|
|
|
|
}
|
2016-06-29 23:12:38 +08:00
|
|
|
else if (arg.id == 0xfffe)
|
|
|
|
{
|
|
|
|
/* Special case "nobody" for reproducible construction of a
|
|
|
|
nobody SID for WinFsp and similar services. We use the
|
|
|
|
value 65534 which is -2 with 16 bit uid/gids. */
|
|
|
|
csid.create (0, 1, 0xfffe);
|
|
|
|
sid = csid;
|
|
|
|
break;
|
|
|
|
}
|
2014-02-10 03:44:56 +08:00
|
|
|
else if (arg.id < 0x10000)
|
|
|
|
{
|
|
|
|
/* Nothing. */
|
|
|
|
debug_printf ("Invalid POSIX id %u", arg.id);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
else if (arg.id < 0x20000)
|
|
|
|
{
|
|
|
|
/* Well-Known Group */
|
|
|
|
arg.id -= 0x10000;
|
2014-09-05 17:46:26 +08:00
|
|
|
/* SECURITY_APP_PACKAGE_AUTHORITY */
|
|
|
|
if (arg.id >= 0xf20 && arg.id <= 0xf3f)
|
2016-03-12 23:39:19 +08:00
|
|
|
csid.create (15, 2, (arg.id >> 4) & 0xf, arg.id & 0xf);
|
2014-09-05 17:46:26 +08:00
|
|
|
else
|
2016-03-12 23:39:19 +08:00
|
|
|
csid.create (arg.id >> 8, 1, arg.id & 0xff);
|
2014-02-10 03:44:56 +08:00
|
|
|
}
|
|
|
|
else if (arg.id >= 0x30000 && arg.id < 0x40000)
|
|
|
|
{
|
|
|
|
/* Account domain user or group. */
|
2016-03-12 23:39:19 +08:00
|
|
|
csid = cygheap->dom.account_sid ();
|
|
|
|
csid.append (arg.id & 0xffff);
|
2014-02-10 03:44:56 +08:00
|
|
|
}
|
|
|
|
else if (arg.id < 0x60000)
|
|
|
|
{
|
|
|
|
/* Builtin Alias */
|
2016-03-12 23:39:19 +08:00
|
|
|
csid.create (5, 2, arg.id >> 12, arg.id & 0xffff);
|
2014-02-10 03:44:56 +08:00
|
|
|
}
|
|
|
|
else if (arg.id < 0x70000)
|
|
|
|
{
|
|
|
|
/* Mandatory Label. */
|
2016-03-12 23:39:19 +08:00
|
|
|
csid.create (16, 1, arg.id & 0xffff);
|
2014-02-10 03:44:56 +08:00
|
|
|
}
|
|
|
|
else if (arg.id < 0x80000)
|
|
|
|
{
|
|
|
|
/* Identity assertion SIDs. */
|
2016-03-12 23:39:19 +08:00
|
|
|
csid.create (18, 1, arg.id & 0xffff);
|
2014-02-10 03:44:56 +08:00
|
|
|
}
|
2014-07-29 16:53:13 +08:00
|
|
|
else if (arg.id < PRIMARY_POSIX_OFFSET)
|
2014-02-10 03:44:56 +08:00
|
|
|
{
|
|
|
|
/* Nothing. */
|
|
|
|
debug_printf ("Invalid POSIX id %u", arg.id);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
else if (arg.id == ILLEGAL_UID)
|
|
|
|
{
|
|
|
|
/* Just some fake. */
|
2016-03-12 23:39:19 +08:00
|
|
|
sid = csid.create (99, 1, 0);
|
2014-02-10 03:44:56 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (arg.id >= UNIX_POSIX_OFFSET)
|
|
|
|
{
|
|
|
|
/* UNIX (unknown NFS or Samba) user account. */
|
2016-03-12 23:39:19 +08:00
|
|
|
csid.create (22, 2, is_group () ? 2 : 1, arg.id & UNIX_POSIX_MASK);
|
2014-02-10 03:44:56 +08:00
|
|
|
/* LookupAccountSidW will fail. */
|
2016-03-12 23:39:19 +08:00
|
|
|
sid = csid;
|
2014-02-10 03:44:56 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Some trusted domain? */
|
2014-05-22 17:47:23 +08:00
|
|
|
PDS_DOMAIN_TRUSTSW td = NULL, this_td = NULL;
|
2014-02-10 03:44:56 +08:00
|
|
|
|
|
|
|
for (ULONG idx = 0; (td = cygheap->dom.trusted_domain (idx)); ++idx)
|
|
|
|
{
|
2014-05-22 22:50:24 +08:00
|
|
|
fetch_posix_offset (td, &loc_ldap);
|
2014-02-10 03:44:56 +08:00
|
|
|
if (td->PosixOffset > posix_offset && td->PosixOffset <= arg.id)
|
2014-05-22 17:47:23 +08:00
|
|
|
posix_offset = (this_td = td)->PosixOffset;
|
2014-02-10 03:44:56 +08:00
|
|
|
}
|
2014-05-22 17:47:23 +08:00
|
|
|
if (this_td)
|
2014-02-10 03:44:56 +08:00
|
|
|
{
|
2016-03-12 23:39:19 +08:00
|
|
|
csid = this_td->DomainSid;
|
|
|
|
csid.append (arg.id - posix_offset);
|
2014-02-10 03:44:56 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Primary domain */
|
2016-03-12 23:39:19 +08:00
|
|
|
csid = cygheap->dom.primary_sid ();
|
|
|
|
csid.append (arg.id - PRIMARY_POSIX_OFFSET);
|
2014-02-10 03:44:56 +08:00
|
|
|
}
|
|
|
|
posix_offset = 0;
|
|
|
|
}
|
2016-03-12 23:39:19 +08:00
|
|
|
sid = csid;
|
2014-02-10 03:44:56 +08:00
|
|
|
ret = LookupAccountSidW (NULL, sid, name, &nlen, dom, &dlen, &acc_type);
|
|
|
|
if (!ret)
|
|
|
|
{
|
2016-03-12 23:39:19 +08:00
|
|
|
debug_printf ("LookupAccountSidW (%W), %E", sid.string (sidstr));
|
2014-02-10 03:44:56 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
break;
|
2007-08-22 01:38:27 +08:00
|
|
|
}
|
2014-02-10 03:44:56 +08:00
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
/* Builtin account? SYSTEM, for instance, is returned as SidTypeUser,
|
2014-05-06 20:02:48 +08:00
|
|
|
if a process is running as LocalSystem service.
|
|
|
|
Microsoft Account? These show up in the user's group list, using the
|
|
|
|
undocumented security authority 11. Even though this is officially a
|
|
|
|
user account, it only matters as part of the group list, so we convert
|
|
|
|
it to a well-known group here. */
|
|
|
|
if (acc_type == SidTypeUser
|
|
|
|
&& (sid_sub_auth_count (sid) <= 3 || sid_id_auth (sid) == 11))
|
2023-04-03 22:45:03 +08:00
|
|
|
{
|
|
|
|
acc_type = SidTypeWellKnownGroup;
|
|
|
|
home = cygheap->pg.get_home ((PUSER_INFO_3) NULL, sid, dom, name,
|
|
|
|
fully_qualified_name);
|
|
|
|
}
|
2018-08-28 17:26:52 +08:00
|
|
|
switch ((int) acc_type)
|
2019-02-13 18:10:41 +08:00
|
|
|
{
|
2014-02-10 03:44:56 +08:00
|
|
|
case SidTypeUser:
|
2015-02-27 22:03:29 +08:00
|
|
|
if (is_group ())
|
2015-02-27 20:59:09 +08:00
|
|
|
{
|
|
|
|
/* Don't allow users as group. While this is technically
|
|
|
|
possible, it doesn't make sense in a POSIX scenario.
|
2019-02-13 18:10:41 +08:00
|
|
|
|
2016-08-08 15:45:34 +08:00
|
|
|
Microsoft Accounts as well as AzureAD accounts have the
|
|
|
|
primary group SID in their user token set to their own
|
|
|
|
user SID.
|
|
|
|
|
|
|
|
Those we let pass, but no others. */
|
2015-02-27 20:59:09 +08:00
|
|
|
bool its_ok = false;
|
2016-08-08 15:45:34 +08:00
|
|
|
if (sid_id_auth (sid) == 12)
|
|
|
|
its_ok = true;
|
2022-11-16 00:15:44 +08:00
|
|
|
else /* Microsoft Account */
|
2015-02-27 20:59:09 +08:00
|
|
|
{
|
2018-08-28 17:24:59 +08:00
|
|
|
USER_INFO_24 *ui24;
|
2015-02-27 20:59:09 +08:00
|
|
|
if (NetUserGetInfo (NULL, name, 24, (PBYTE *) &ui24)
|
|
|
|
== NERR_Success)
|
|
|
|
{
|
|
|
|
if (ui24->usri24_internet_identity)
|
|
|
|
its_ok = true;
|
|
|
|
NetApiBufferFree (ui24);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!its_ok)
|
|
|
|
return NULL;
|
|
|
|
}
|
2020-08-06 03:58:22 +08:00
|
|
|
fallthrough;
|
2014-02-10 03:44:56 +08:00
|
|
|
case SidTypeGroup:
|
2014-02-11 19:51:29 +08:00
|
|
|
case SidTypeAlias:
|
|
|
|
/* Predefined alias? */
|
|
|
|
if (acc_type == SidTypeAlias
|
|
|
|
&& sid_sub_auth (sid, 0) != SECURITY_NT_NON_UNIQUE)
|
|
|
|
{
|
|
|
|
#ifdef INTERIX_COMPATIBLE
|
|
|
|
posix_offset = 0x30000;
|
|
|
|
uid = 0x1000 * sid_sub_auth (sid, 0)
|
|
|
|
+ (sid_sub_auth_rid (sid) & 0xffff);
|
|
|
|
#else
|
|
|
|
posix_offset = 0;
|
|
|
|
#endif
|
|
|
|
is_domain_account = false;
|
|
|
|
}
|
2014-02-10 03:44:56 +08:00
|
|
|
/* Account domain account? */
|
2014-05-06 20:02:48 +08:00
|
|
|
else if (!wcscasecmp (dom, cygheap->dom.account_flat_name ()))
|
2014-02-10 03:44:56 +08:00
|
|
|
{
|
|
|
|
posix_offset = 0x30000;
|
2022-12-02 22:13:24 +08:00
|
|
|
if (cygheap->dom.member_machine ())
|
2014-08-04 23:50:42 +08:00
|
|
|
fully_qualified_name = true;
|
2014-02-10 03:44:56 +08:00
|
|
|
is_domain_account = false;
|
|
|
|
}
|
|
|
|
/* Domain member machine? */
|
|
|
|
else if (cygheap->dom.member_machine ())
|
|
|
|
{
|
|
|
|
/* Primary domain account? */
|
2014-05-06 20:02:48 +08:00
|
|
|
if (!wcscasecmp (dom, cygheap->dom.primary_flat_name ()))
|
2014-02-10 03:44:56 +08:00
|
|
|
{
|
2014-07-29 16:53:13 +08:00
|
|
|
posix_offset = PRIMARY_POSIX_OFFSET;
|
2014-02-10 03:44:56 +08:00
|
|
|
/* In theory domain should have been set to
|
2014-07-30 22:23:53 +08:00
|
|
|
cygheap->dom.primary_dns_name (), but it turns out that
|
|
|
|
not setting the domain here has advantages. We open the
|
|
|
|
ldap connection to NULL (== some DC of our primary domain)
|
|
|
|
anyway. So the domain is only used later on. So, don't
|
|
|
|
set domain here to non-NULL, unless you're sure you have
|
|
|
|
also changed subsequent assumptions that domain is NULL
|
|
|
|
if it's a primary domain account. */
|
2014-02-10 03:44:56 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* No, fetch POSIX offset. */
|
|
|
|
PDS_DOMAIN_TRUSTSW td = NULL;
|
|
|
|
|
2014-08-04 23:50:42 +08:00
|
|
|
fully_qualified_name = true;
|
2014-02-10 03:44:56 +08:00
|
|
|
for (ULONG idx = 0;
|
|
|
|
(td = cygheap->dom.trusted_domain (idx));
|
|
|
|
++idx)
|
2014-05-06 20:02:48 +08:00
|
|
|
if (!wcscasecmp (dom, td->NetbiosDomainName))
|
2014-02-13 22:04:03 +08:00
|
|
|
{
|
|
|
|
domain = td->DnsDomainName;
|
|
|
|
break;
|
|
|
|
}
|
2014-02-10 03:44:56 +08:00
|
|
|
if (!domain)
|
|
|
|
{
|
2015-03-31 00:05:06 +08:00
|
|
|
/* This shouldn't happen, in theory, but it does. There
|
|
|
|
are cases where the user's logon domain does not show
|
|
|
|
up in the list of trusted domains. We're desperately
|
2018-08-28 00:28:33 +08:00
|
|
|
trying to workaround that here by adding an entry for
|
2015-03-31 00:05:06 +08:00
|
|
|
this domain to the trusted domains and ask the DC for
|
|
|
|
a posix_offset. There's a good chance this doesn't
|
|
|
|
work either, but at least we tried, and the user can
|
|
|
|
work. */
|
2014-02-10 03:44:56 +08:00
|
|
|
debug_printf ("Unknown domain %W", dom);
|
2015-03-31 00:05:06 +08:00
|
|
|
td = cygheap->dom.add_domain (dom, sid);
|
|
|
|
if (td)
|
|
|
|
domain = td->DnsDomainName;
|
2014-02-10 03:44:56 +08:00
|
|
|
}
|
2015-03-31 00:05:06 +08:00
|
|
|
if (domain)
|
|
|
|
posix_offset = fetch_posix_offset (td, &loc_ldap);
|
2014-02-10 03:44:56 +08:00
|
|
|
}
|
|
|
|
}
|
2016-08-08 15:45:34 +08:00
|
|
|
/* AzureAD S-1-12-1-W-X-Y-Z user */
|
|
|
|
else if (sid_id_auth (sid) == 12)
|
|
|
|
{
|
|
|
|
uid = gid = 0x1000;
|
|
|
|
fully_qualified_name = true;
|
|
|
|
home = cygheap->pg.get_home ((PUSER_INFO_3) NULL, sid, dom, name,
|
|
|
|
fully_qualified_name);
|
|
|
|
shell = cygheap->pg.get_shell ((PUSER_INFO_3) NULL, sid, dom,
|
|
|
|
name, fully_qualified_name);
|
|
|
|
gecos = cygheap->pg.get_gecos ((PUSER_INFO_3) NULL, sid, dom,
|
|
|
|
name, fully_qualified_name);
|
|
|
|
break;
|
|
|
|
}
|
2014-02-10 03:44:56 +08:00
|
|
|
/* If the domain returned by LookupAccountSid is not our machine
|
|
|
|
name, and if our machine is no domain member, we lose. We have
|
|
|
|
nobody to ask for the POSIX offset. */
|
|
|
|
else
|
|
|
|
{
|
|
|
|
debug_printf ("Unknown domain %W", dom);
|
|
|
|
return NULL;
|
|
|
|
}
|
2014-11-27 03:46:59 +08:00
|
|
|
/* Generate uid/gid values. */
|
2014-02-11 19:51:29 +08:00
|
|
|
if (uid == ILLEGAL_UID)
|
|
|
|
uid = posix_offset + sid_sub_auth_rid (sid);
|
2014-11-27 03:46:59 +08:00
|
|
|
if (!is_group () && acc_type == SidTypeUser)
|
2014-04-12 19:10:13 +08:00
|
|
|
{
|
2022-12-02 23:49:47 +08:00
|
|
|
/* Default primary group. Make the educated guess that the user
|
|
|
|
is in group "Domain Users" or "None". */
|
|
|
|
gid = posix_offset + DOMAIN_GROUP_RID_USERS;
|
2014-04-12 19:10:13 +08:00
|
|
|
}
|
2014-02-28 19:37:02 +08:00
|
|
|
|
2014-04-12 19:10:13 +08:00
|
|
|
if (is_domain_account)
|
|
|
|
{
|
2019-02-22 18:04:34 +08:00
|
|
|
/* Skip this when creating group entries and for non-users. */
|
2015-02-13 00:55:38 +08:00
|
|
|
if (is_group() || acc_type != SidTypeUser)
|
|
|
|
break;
|
2015-01-22 04:40:33 +08:00
|
|
|
/* On AD machines, use LDAP to fetch domain account infos. */
|
|
|
|
if (cygheap->dom.primary_dns_name ())
|
2014-02-10 03:44:56 +08:00
|
|
|
{
|
2022-12-02 23:49:47 +08:00
|
|
|
/* Fetch primary group from AD and overwrite the one we
|
|
|
|
just guessed above. */
|
|
|
|
if (cldap->fetch_ad_account (sid, false, domain))
|
2019-02-13 20:16:15 +08:00
|
|
|
{
|
|
|
|
if ((val = cldap->get_account_name ()))
|
|
|
|
wcscpy (name, val);
|
|
|
|
if ((id_val = cldap->get_primary_gid ()) != ILLEGAL_GID)
|
|
|
|
gid = posix_offset + id_val;
|
|
|
|
}
|
2015-02-13 00:55:38 +08:00
|
|
|
home = cygheap->pg.get_home (cldap, sid, dom, domain,
|
|
|
|
name, fully_qualified_name);
|
|
|
|
shell = cygheap->pg.get_shell (cldap, sid, dom, domain,
|
|
|
|
name,
|
|
|
|
fully_qualified_name);
|
|
|
|
gecos = cygheap->pg.get_gecos (cldap, sid, dom, domain,
|
|
|
|
name, fully_qualified_name);
|
|
|
|
/* Check and, if necessary, add unix<->windows id mapping
|
|
|
|
on the fly, unless we're called from getpwent. */
|
|
|
|
if (!pldap && cldap->is_open ())
|
2014-11-27 03:46:59 +08:00
|
|
|
{
|
2015-02-13 00:55:38 +08:00
|
|
|
id_val = cldap->get_unix_uid ();
|
|
|
|
if (id_val != ILLEGAL_UID
|
|
|
|
&& cygheap->ugid_cache.get_uid (id_val)
|
|
|
|
== ILLEGAL_UID)
|
|
|
|
cygheap->ugid_cache.add_uid (id_val, uid);
|
2014-11-27 03:46:59 +08:00
|
|
|
}
|
2015-01-22 04:40:33 +08:00
|
|
|
}
|
|
|
|
/* If primary_dns_name() is empty, we're likely running under an
|
|
|
|
NT4 domain, so we can't use LDAP. For user accounts fall back
|
|
|
|
to NetUserGetInfo. This isn't overly fast, but keep in mind
|
|
|
|
that NT4 domains are mostly replaced by AD these days. */
|
2015-02-13 00:55:38 +08:00
|
|
|
else
|
2015-01-22 04:40:33 +08:00
|
|
|
{
|
|
|
|
WCHAR server[INTERNET_MAX_HOST_NAME_LENGTH + 3];
|
|
|
|
NET_API_STATUS nas;
|
|
|
|
PUSER_INFO_3 ui;
|
2019-02-13 18:10:41 +08:00
|
|
|
|
2015-01-22 04:40:33 +08:00
|
|
|
if (!get_logon_server (cygheap->dom.primary_flat_name (),
|
|
|
|
server, DS_IS_FLAT_NAME))
|
|
|
|
break;
|
|
|
|
nas = NetUserGetInfo (server, name, 3, (PBYTE *) &ui);
|
|
|
|
if (nas != NERR_Success)
|
2014-02-10 03:44:56 +08:00
|
|
|
{
|
2015-01-22 04:40:33 +08:00
|
|
|
debug_printf ("NetUserGetInfo(%W) %u", name, nas);
|
|
|
|
break;
|
2014-02-10 03:44:56 +08:00
|
|
|
}
|
2019-02-13 20:16:15 +08:00
|
|
|
/* Overwrite name to be sure case is same as in SAM */
|
|
|
|
wcscpy (name, ui->usri3_name);
|
2015-01-22 04:40:33 +08:00
|
|
|
gid = posix_offset + ui->usri3_primary_group_id;
|
|
|
|
home = cygheap->pg.get_home (ui, sid, dom, name,
|
|
|
|
fully_qualified_name);
|
|
|
|
shell = cygheap->pg.get_shell (ui, sid, dom, name,
|
|
|
|
fully_qualified_name);
|
|
|
|
gecos = cygheap->pg.get_gecos (ui, sid, dom, name,
|
|
|
|
fully_qualified_name);
|
2014-02-10 03:44:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Otherwise check account domain (local SAM).*/
|
2014-02-11 19:51:29 +08:00
|
|
|
else
|
2014-02-10 03:44:56 +08:00
|
|
|
{
|
|
|
|
NET_API_STATUS nas;
|
2014-11-27 03:46:59 +08:00
|
|
|
PUSER_INFO_3 ui;
|
2014-02-11 19:51:29 +08:00
|
|
|
PLOCALGROUP_INFO_1 gi;
|
2014-11-27 03:46:59 +08:00
|
|
|
char *pgrp = NULL;
|
|
|
|
char *uxid = NULL;
|
2014-02-11 19:51:29 +08:00
|
|
|
|
|
|
|
if (acc_type == SidTypeUser)
|
2014-02-10 03:44:56 +08:00
|
|
|
{
|
2014-11-27 03:46:59 +08:00
|
|
|
nas = NetUserGetInfo (NULL, name, 3, (PBYTE *) &ui);
|
2014-02-11 19:51:29 +08:00
|
|
|
if (nas != NERR_Success)
|
2014-02-10 03:44:56 +08:00
|
|
|
{
|
2014-02-11 19:51:29 +08:00
|
|
|
debug_printf ("NetUserGetInfo(%W) %u", name, nas);
|
|
|
|
break;
|
2014-02-10 03:44:56 +08:00
|
|
|
}
|
2019-02-13 20:16:15 +08:00
|
|
|
/* Overwrite name to be sure case is same as in SAM */
|
|
|
|
wcscpy (name, ui->usri3_name);
|
2014-11-27 03:46:59 +08:00
|
|
|
/* Fetch user attributes. */
|
2014-12-02 19:30:04 +08:00
|
|
|
home = cygheap->pg.get_home (ui, sid, dom, name,
|
2014-11-27 03:46:59 +08:00
|
|
|
fully_qualified_name);
|
2015-01-09 01:08:47 +08:00
|
|
|
shell = cygheap->pg.get_shell (ui, sid, dom, name,
|
2014-11-27 03:46:59 +08:00
|
|
|
fully_qualified_name);
|
2015-01-09 01:08:47 +08:00
|
|
|
gecos = cygheap->pg.get_gecos (ui, sid, dom, name,
|
2014-11-27 03:46:59 +08:00
|
|
|
fully_qualified_name);
|
|
|
|
uxid = fetch_from_description (ui->usri3_comment,
|
|
|
|
L"unix=\"", 6);
|
|
|
|
pgrp = fetch_from_description (ui->usri3_comment,
|
|
|
|
L"group=\"", 7);
|
2014-02-11 19:51:29 +08:00
|
|
|
}
|
2014-04-12 19:10:13 +08:00
|
|
|
else /* acc_type == SidTypeAlias */
|
2014-02-11 19:51:29 +08:00
|
|
|
{
|
|
|
|
nas = NetLocalGroupGetInfo (NULL, name, 1, (PBYTE *) &gi);
|
|
|
|
if (nas != NERR_Success)
|
2014-02-11 02:28:51 +08:00
|
|
|
{
|
2014-02-11 19:51:29 +08:00
|
|
|
debug_printf ("NetLocalGroupGetInfo(%W) %u", name, nas);
|
|
|
|
break;
|
2014-02-11 02:28:51 +08:00
|
|
|
}
|
2019-02-13 20:16:15 +08:00
|
|
|
/* Overwrite name to be sure case is same as in SAM */
|
|
|
|
wcscpy (name, gi->lgrpi1_name);
|
2014-11-27 03:46:59 +08:00
|
|
|
/* Fetch unix gid from comment field. */
|
|
|
|
uxid = fetch_from_description (gi->lgrpi1_comment,
|
|
|
|
L"unix=\"", 6);
|
2014-02-11 19:51:29 +08:00
|
|
|
}
|
2014-11-27 03:46:59 +08:00
|
|
|
|
2014-02-11 19:51:29 +08:00
|
|
|
if (acc_type == SidTypeUser)
|
|
|
|
NetApiBufferFree (ui);
|
2014-02-10 03:44:56 +08:00
|
|
|
else
|
2014-02-11 19:51:29 +08:00
|
|
|
NetApiBufferFree (gi);
|
|
|
|
if (pgrp)
|
2014-02-10 03:44:56 +08:00
|
|
|
{
|
2014-09-01 02:18:49 +08:00
|
|
|
/* Set primary group from the "Description" field. Prepend
|
2022-12-02 22:13:24 +08:00
|
|
|
account domain if this is a domain member machine. */
|
2014-11-27 03:46:59 +08:00
|
|
|
char gname[2 * DNLEN + strlen (pgrp) + 1], *gp = gname;
|
2014-02-11 19:51:29 +08:00
|
|
|
struct group *gr;
|
|
|
|
|
2022-12-02 22:13:24 +08:00
|
|
|
if (cygheap->dom.member_machine ())
|
2014-09-01 02:18:49 +08:00
|
|
|
{
|
|
|
|
gp = gname
|
|
|
|
+ sys_wcstombs (gname, sizeof gname,
|
|
|
|
cygheap->dom.account_flat_name ());
|
2022-12-02 22:13:24 +08:00
|
|
|
*gp++ = NSS_SEPARATOR_CHAR;
|
2014-09-01 02:18:49 +08:00
|
|
|
}
|
2014-11-27 03:46:59 +08:00
|
|
|
stpcpy (gp, pgrp);
|
2014-09-01 02:18:49 +08:00
|
|
|
if ((gr = internal_getgrnam (gname, cldap)))
|
2014-02-11 19:51:29 +08:00
|
|
|
gid = gr->gr_gid;
|
|
|
|
}
|
2014-11-27 03:46:59 +08:00
|
|
|
char *e;
|
|
|
|
if (!pldap && uxid && ((id_val = strtoul (uxid, &e, 10)), !*e))
|
2014-02-11 19:51:29 +08:00
|
|
|
{
|
|
|
|
if (acc_type == SidTypeUser)
|
2014-02-10 03:44:56 +08:00
|
|
|
{
|
2014-02-11 19:51:29 +08:00
|
|
|
if (cygheap->ugid_cache.get_uid (id_val) == ILLEGAL_UID)
|
|
|
|
cygheap->ugid_cache.add_uid (id_val, uid);
|
2014-02-10 03:44:56 +08:00
|
|
|
}
|
2014-02-11 19:51:29 +08:00
|
|
|
else if (cygheap->ugid_cache.get_gid (id_val) == ILLEGAL_GID)
|
|
|
|
cygheap->ugid_cache.add_gid (id_val, uid);
|
2014-02-10 03:44:56 +08:00
|
|
|
}
|
2014-11-27 03:46:59 +08:00
|
|
|
if (pgrp)
|
|
|
|
free (pgrp);
|
|
|
|
if (uxid)
|
|
|
|
free (uxid);
|
2014-02-10 03:44:56 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SidTypeWellKnownGroup:
|
2022-12-02 22:13:24 +08:00
|
|
|
fully_qualified_name = (
|
2014-11-17 18:09:01 +08:00
|
|
|
/* NT SERVICE Account */
|
2022-12-02 22:13:24 +08:00
|
|
|
(sid_id_auth (sid) == 5 /* SECURITY_NT_AUTHORITY */
|
2014-11-17 18:09:01 +08:00
|
|
|
&& sid_sub_auth (sid, 0) == SECURITY_SERVICE_ID_BASE_RID)
|
|
|
|
/* Microsoft Account */
|
|
|
|
|| sid_id_auth (sid) == 11);
|
2014-02-10 03:44:56 +08:00
|
|
|
#ifdef INTERIX_COMPATIBLE
|
|
|
|
if (sid_id_auth (sid) == 5 /* SECURITY_NT_AUTHORITY */
|
|
|
|
&& sid_sub_auth_count (sid) > 1)
|
|
|
|
{
|
|
|
|
uid = 0x1000 * sid_sub_auth (sid, 0)
|
|
|
|
+ (sid_sub_auth_rid (sid) & 0xffff);
|
2014-08-04 23:50:42 +08:00
|
|
|
fully_qualified_name = true;
|
2014-02-10 03:44:56 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
uid = 0x10000 + 0x100 * sid_id_auth (sid)
|
|
|
|
+ (sid_sub_auth_rid (sid) & 0xff);
|
|
|
|
#else
|
2014-09-05 17:46:26 +08:00
|
|
|
if (sid_id_auth (sid) == 15 /* SECURITY_APP_PACKAGE_AUTHORITY */)
|
|
|
|
uid = 0x10000 + 0x100 * sid_id_auth (sid)
|
|
|
|
+ 0x10 * sid_sub_auth (sid, 0)
|
|
|
|
+ (sid_sub_auth_rid (sid) & 0xf);
|
|
|
|
else if (sid_id_auth (sid) != 5 /* SECURITY_NT_AUTHORITY */)
|
2014-02-10 03:44:56 +08:00
|
|
|
uid = 0x10000 + 0x100 * sid_id_auth (sid)
|
|
|
|
+ (sid_sub_auth_rid (sid) & 0xff);
|
2014-05-07 20:07:12 +08:00
|
|
|
else if (sid_sub_auth (sid, 0) < SECURITY_PACKAGE_BASE_RID
|
|
|
|
|| sid_sub_auth (sid, 0) > SECURITY_MAX_BASE_RID)
|
2014-02-10 03:44:56 +08:00
|
|
|
uid = sid_sub_auth_rid (sid) & 0x7ff;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
uid = 0x1000 * sid_sub_auth (sid, 0)
|
|
|
|
+ (sid_sub_auth_rid (sid) & 0xffff);
|
|
|
|
}
|
|
|
|
#endif
|
2014-08-31 22:16:04 +08:00
|
|
|
/* Special case for "NULL SID", S-1-0-0 and "Everyone", S-1-1-0.
|
|
|
|
Never return "NULL SID" or Everyone as user or group. */
|
|
|
|
if (uid == 0x10000 || uid == 0x10100)
|
2014-02-10 03:44:56 +08:00
|
|
|
return NULL;
|
|
|
|
break;
|
2018-08-28 17:26:52 +08:00
|
|
|
case SidTypeLogonSession:
|
|
|
|
/* Starting with Windows 10, LookupAccountSid/Name return valid
|
|
|
|
info for the login session with new SID_NAME_USE value
|
|
|
|
SidTypeLogonSession. To return the same info as on
|
|
|
|
pre-Windows 10, we have to handle this type explicitely here
|
|
|
|
now and convert the name to "CurrentSession". */
|
|
|
|
get_logon_sid ();
|
|
|
|
if (PSID (logon_sid) == NO_SID)
|
|
|
|
return NULL;
|
|
|
|
if (RtlEqualSid (sid, logon_sid))
|
|
|
|
{
|
|
|
|
uid = 0xfff;
|
|
|
|
wcpcpy (name = namebuf, L"CurrentSession");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
uid = 0xffe;
|
|
|
|
wcpcpy (name = namebuf, L"OtherSession");
|
|
|
|
}
|
|
|
|
break;
|
2014-02-10 03:44:56 +08:00
|
|
|
case SidTypeLabel:
|
|
|
|
uid = 0x60000 + sid_sub_auth_rid (sid);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
2019-02-13 18:10:41 +08:00
|
|
|
}
|
2016-06-29 23:12:38 +08:00
|
|
|
else if (sid_id_auth (sid) == 0 && sid_sub_auth (sid, 0) == 0xfffe)
|
|
|
|
{
|
|
|
|
/* Special case "nobody" for reproducible construction of a
|
|
|
|
nobody SID for WinFsp and similar services. We use the
|
|
|
|
value 65534 which is -2 with 16 bit uid/gids. */
|
|
|
|
uid = gid = 0xfffe;
|
2016-07-22 15:41:23 +08:00
|
|
|
wcpcpy (dom, L"no");
|
|
|
|
wcpcpy (name = namebuf, L"body");
|
2016-06-29 23:12:38 +08:00
|
|
|
fully_qualified_name = true;
|
|
|
|
acc_type = SidTypeUnknown;
|
|
|
|
}
|
2016-08-08 15:45:34 +08:00
|
|
|
else if (sid_id_auth (sid) == 12 && sid_sub_auth (sid, 0) == 1)
|
|
|
|
{
|
|
|
|
/* Special AzureAD group SID which can't be resolved by
|
|
|
|
LookupAccountSid (ERROR_NONE_MAPPED). This is only allowed
|
|
|
|
as group entry, not as passwd entry. */
|
|
|
|
if (is_passwd ())
|
|
|
|
return NULL;
|
|
|
|
uid = gid = 0x1001;
|
|
|
|
wcpcpy (dom, L"AzureAD");
|
|
|
|
wcpcpy (name = namebuf, L"Group");
|
|
|
|
fully_qualified_name = true;
|
|
|
|
acc_type = SidTypeUnknown;
|
|
|
|
}
|
2014-02-10 03:44:56 +08:00
|
|
|
else if (sid_id_auth (sid) == 5 /* SECURITY_NT_AUTHORITY */
|
|
|
|
&& sid_sub_auth (sid, 0) == SECURITY_LOGON_IDS_RID)
|
|
|
|
{
|
|
|
|
/* Logon ID. Mine or other? */
|
|
|
|
get_logon_sid ();
|
|
|
|
if (PSID (logon_sid) == NO_SID)
|
|
|
|
return NULL;
|
|
|
|
if (RtlEqualSid (sid, logon_sid))
|
|
|
|
{
|
|
|
|
uid = 0xfff;
|
|
|
|
wcpcpy (name = namebuf, L"CurrentSession");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
uid = 0xffe;
|
|
|
|
wcpcpy (name = namebuf, L"OtherSession");
|
|
|
|
}
|
2014-03-07 02:54:08 +08:00
|
|
|
acc_type = SidTypeUnknown;
|
2014-02-10 03:44:56 +08:00
|
|
|
}
|
|
|
|
else if (sid_id_auth (sid) == 22)
|
|
|
|
{
|
|
|
|
/* Samba UNIX Users/Groups
|
|
|
|
|
2014-02-23 03:38:12 +08:00
|
|
|
This *might* collide with a posix_offset of some trusted domain.
|
2014-02-10 03:44:56 +08:00
|
|
|
It's just very unlikely. */
|
|
|
|
uid = MAP_UNIX_TO_CYGWIN_ID (sid_sub_auth_rid (sid));
|
|
|
|
/* Unfortunately we have no access to the file server from here,
|
|
|
|
so we can't generate correct user names. */
|
2014-02-23 03:38:12 +08:00
|
|
|
p = wcpcpy (dom, L"Unix_");
|
2014-02-10 03:44:56 +08:00
|
|
|
wcpcpy (p, sid_sub_auth (sid, 0) == 1 ? L"User" : L"Group");
|
|
|
|
__small_swprintf (name = namebuf, L"%d", uid & UNIX_POSIX_MASK);
|
2014-08-04 23:50:42 +08:00
|
|
|
fully_qualified_name = true;
|
2014-03-07 02:54:08 +08:00
|
|
|
acc_type = SidTypeUnknown;
|
2014-02-10 03:44:56 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-03-12 23:46:07 +08:00
|
|
|
if (cygheap->dom.member_machine ()
|
|
|
|
&& sid_id_auth (sid) == 5 /* SECURITY_NT_AUTHORITY */
|
2014-02-13 22:04:03 +08:00
|
|
|
&& sid_sub_auth (sid, 0) == SECURITY_NT_NON_UNIQUE)
|
|
|
|
{
|
|
|
|
/* Check if we know the domain. If so, create a passwd/group
|
|
|
|
entry with domain prefix and RID as username. */
|
|
|
|
PDS_DOMAIN_TRUSTSW td = NULL;
|
|
|
|
|
|
|
|
sid_sub_auth_count (sid) = sid_sub_auth_count (sid) - 1;
|
2014-02-28 19:37:02 +08:00
|
|
|
if (RtlEqualSid (sid, cygheap->dom.primary_sid ()))
|
|
|
|
{
|
|
|
|
domain = cygheap->dom.primary_flat_name ();
|
2014-07-29 16:53:13 +08:00
|
|
|
posix_offset = PRIMARY_POSIX_OFFSET;
|
2014-02-28 19:37:02 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
for (ULONG idx = 0; (td = cygheap->dom.trusted_domain (idx)); ++idx)
|
|
|
|
if (td->DomainSid && RtlEqualSid (sid, td->DomainSid))
|
|
|
|
{
|
|
|
|
domain = td->NetbiosDomainName;
|
2014-05-22 22:50:24 +08:00
|
|
|
posix_offset = fetch_posix_offset (td, &loc_ldap);
|
2014-02-28 19:37:02 +08:00
|
|
|
break;
|
|
|
|
}
|
2015-04-17 17:57:57 +08:00
|
|
|
sid_sub_auth_count (sid) = sid_sub_auth_count (sid) + 1;
|
2014-02-13 22:04:03 +08:00
|
|
|
}
|
|
|
|
if (domain)
|
|
|
|
{
|
|
|
|
wcscpy (dom, domain);
|
|
|
|
__small_swprintf (name = namebuf, L"%W(%u)",
|
2014-03-08 04:38:48 +08:00
|
|
|
is_group () ? L"Group" : L"User",
|
2014-02-13 22:04:03 +08:00
|
|
|
sid_sub_auth_rid (sid));
|
|
|
|
uid = posix_offset + sid_sub_auth_rid (sid);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wcpcpy (dom, L"Unknown");
|
2014-03-08 04:38:48 +08:00
|
|
|
wcpcpy (name = namebuf, is_group () ? L"Group" : L"User");
|
2014-02-13 22:04:03 +08:00
|
|
|
}
|
2014-08-04 23:50:42 +08:00
|
|
|
fully_qualified_name = true;
|
2014-03-07 02:54:08 +08:00
|
|
|
acc_type = SidTypeUnknown;
|
2014-02-10 03:44:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
tmp_pathbuf tp;
|
2014-11-27 03:46:59 +08:00
|
|
|
char *linebuf = tp.c_get ();
|
2014-02-10 03:44:56 +08:00
|
|
|
char *line = NULL;
|
|
|
|
|
|
|
|
WCHAR posix_name[UNLEN + 1 + DNLEN + 1];
|
|
|
|
p = posix_name;
|
|
|
|
if (gid == ILLEGAL_GID)
|
|
|
|
gid = uid;
|
2014-08-04 23:50:42 +08:00
|
|
|
if (fully_qualified_name)
|
2022-12-02 22:13:24 +08:00
|
|
|
p = wcpcpy (wcpcpy (p, dom), NSS_SEPARATOR_STRING);
|
2014-04-22 18:36:35 +08:00
|
|
|
wcpcpy (p, name);
|
2014-02-10 03:44:56 +08:00
|
|
|
|
2014-03-08 04:38:48 +08:00
|
|
|
if (is_group ())
|
2014-11-27 03:46:59 +08:00
|
|
|
__small_sprintf (linebuf, "%W:%s:%u:",
|
|
|
|
posix_name, sid.string ((char *) sidstr), uid);
|
2014-03-07 02:54:08 +08:00
|
|
|
/* For non-users, create a passwd entry which doesn't allow interactive
|
|
|
|
logon. Unless it's the SYSTEM account. This conveniently allows to
|
2014-05-14 00:07:50 +08:00
|
|
|
logon interactively as SYSTEM for debugging purposes. */
|
2014-03-07 02:54:08 +08:00
|
|
|
else if (acc_type != SidTypeUser && sid != well_known_system_sid)
|
2014-11-27 03:46:59 +08:00
|
|
|
__small_sprintf (linebuf, "%W:*:%u:%u:U-%W\\%W,%s:/:/sbin/nologin",
|
|
|
|
posix_name, uid, gid,
|
|
|
|
dom, name,
|
|
|
|
sid.string ((char *) sidstr));
|
2014-02-10 03:44:56 +08:00
|
|
|
else
|
2014-11-27 03:46:59 +08:00
|
|
|
__small_sprintf (linebuf, "%W:*:%u:%u:%s%sU-%W\\%W,%s:%s%W:%s",
|
|
|
|
posix_name, uid, gid,
|
|
|
|
gecos ?: "", gecos ? "," : "",
|
|
|
|
dom, name,
|
|
|
|
sid.string ((char *) sidstr),
|
|
|
|
home ?: "/home/", home ? L"" : name,
|
|
|
|
shell ?: "/bin/bash");
|
|
|
|
if (gecos)
|
|
|
|
free (gecos);
|
|
|
|
if (home)
|
|
|
|
free (home);
|
|
|
|
if (shell)
|
|
|
|
free (shell);
|
|
|
|
line = cstrdup (linebuf);
|
2014-02-10 03:44:56 +08:00
|
|
|
debug_printf ("line: <%s>", line);
|
|
|
|
return line;
|
2003-01-17 13:18:30 +08:00
|
|
|
}
|
2014-03-13 01:36:56 +08:00
|
|
|
|
|
|
|
client_request_pwdgrp::client_request_pwdgrp (fetch_user_arg_t &arg, bool group)
|
|
|
|
: client_request (CYGSERVER_REQUEST_PWDGRP, &_parameters, sizeof (_parameters))
|
|
|
|
{
|
|
|
|
size_t len = 0;
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
_parameters.in.group = group;
|
|
|
|
_parameters.in.type = arg.type;
|
|
|
|
switch (arg.type)
|
|
|
|
{
|
|
|
|
case SID_arg:
|
|
|
|
RtlCopySid (sizeof (DBGSID), (PSID) &_parameters.in.arg.sid, *arg.sid);
|
|
|
|
len = RtlLengthSid (*arg.sid);
|
|
|
|
break;
|
|
|
|
case NAME_arg:
|
|
|
|
p = stpcpy (_parameters.in.arg.name, arg.name);
|
2014-09-05 19:47:33 +08:00
|
|
|
len = p - _parameters.in.arg.name + 1;
|
2014-03-13 01:36:56 +08:00
|
|
|
break;
|
|
|
|
case ID_arg:
|
|
|
|
_parameters.in.arg.id = arg.id;
|
|
|
|
len = sizeof (uint32_t);
|
2015-02-25 16:44:54 +08:00
|
|
|
break;
|
2015-02-24 04:51:12 +08:00
|
|
|
default:
|
|
|
|
api_fatal ("Fetching account info from cygserver with wrong arg.type "
|
|
|
|
"%d", arg.type);
|
2014-03-13 01:36:56 +08:00
|
|
|
}
|
|
|
|
msglen (__builtin_offsetof (struct _pwdgrp_param_t::_pwdgrp_in_t, arg) + len);
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
|
|
|
pwdgrp::fetch_account_from_cygserver (fetch_user_arg_t &arg)
|
|
|
|
{
|
|
|
|
client_request_pwdgrp request (arg, is_group ());
|
|
|
|
if (request.make_request () == -1 || request.error_code ())
|
|
|
|
{
|
|
|
|
/* Cygserver not running? Don't try again. This will automatically
|
|
|
|
avoid an endless loop in cygserver itself. */
|
|
|
|
if (request.error_code () == ENOSYS)
|
|
|
|
cygheap->pg.nss_disable_cygserver_caching ();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (!request.line ())
|
|
|
|
return NULL;
|
|
|
|
return cstrdup (request.line ());
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
pwdgrp::add_account_from_cygserver (cygpsid &sid)
|
|
|
|
{
|
|
|
|
/* No, Everyone is no group in terms of POSIX. */
|
|
|
|
if (sid_id_auth (sid) == 1 /* SECURITY_WORLD_SID_AUTHORITY */
|
|
|
|
&& sid_sub_auth (sid, 0) == SECURITY_WORLD_RID)
|
|
|
|
return NULL;
|
|
|
|
fetch_user_arg_t arg;
|
|
|
|
arg.type = SID_arg;
|
|
|
|
arg.sid = &sid;
|
|
|
|
char *line = fetch_account_from_cygserver (arg);
|
2014-04-22 18:36:35 +08:00
|
|
|
return add_account_post_fetch (line, true);
|
2014-03-13 01:36:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
pwdgrp::add_account_from_cygserver (const char *name)
|
|
|
|
{
|
|
|
|
fetch_user_arg_t arg;
|
|
|
|
arg.type = NAME_arg;
|
|
|
|
arg.name = name;
|
|
|
|
char *line = fetch_account_from_cygserver (arg);
|
2014-04-22 18:36:35 +08:00
|
|
|
return add_account_post_fetch (line, true);
|
2014-03-13 01:36:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
pwdgrp::add_account_from_cygserver (uint32_t id)
|
|
|
|
{
|
|
|
|
fetch_user_arg_t arg;
|
|
|
|
arg.type = ID_arg;
|
|
|
|
arg.id = id;
|
|
|
|
char *line = fetch_account_from_cygserver (arg);
|
2014-04-22 18:36:35 +08:00
|
|
|
return add_account_post_fetch (line, true);
|
2014-03-13 01:36:56 +08:00
|
|
|
}
|