* sec_auth.cc (extract_nt_dom_user): Return domain and user name as

WCHAR.
	(cygwin_logon_user): Accommodate above change.  Convert password to
	WCHAR and call LogonUserW.
	* external.cc (cygwin_internal): Accommodate above change.
	* security.h (extract_nt_dom_user): Change prototype accordingly.
This commit is contained in:
Corinna Vinschen 2008-07-30 12:10:20 +00:00
parent 79ea8bbb10
commit b54881352d
4 changed files with 35 additions and 15 deletions

View File

@ -1,3 +1,12 @@
2008-07-30 Corinna Vinschen <corinna@vinschen.de>
* sec_auth.cc (extract_nt_dom_user): Return domain and user name as
WCHAR.
(cygwin_logon_user): Accommodate above change. Convert password to
WCHAR and call LogonUserW.
* external.cc (cygwin_internal): Accommodate above change.
* security.h (extract_nt_dom_user): Change prototype accordingly.
2008-07-30 Christopher Faylor <me+cygwin@cgf.cx> 2008-07-30 Christopher Faylor <me+cygwin@cgf.cx>
* cygwin.din (_getutline): Remove. * cygwin.din (_getutline): Remove.

View File

@ -28,6 +28,7 @@ details. */
#include <unistd.h> #include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
#include <wchar.h> #include <wchar.h>
#include <iptypes.h>
child_info *get_cygwin_startup_info (); child_info *get_cygwin_startup_info ();
@ -254,10 +255,17 @@ cygwin_internal (cygwin_getinfo_types t, ...)
} }
case CW_EXTRACT_DOMAIN_AND_USER: case CW_EXTRACT_DOMAIN_AND_USER:
{ {
WCHAR nt_domain[MAX_DOMAIN_NAME_LEN + 1];
WCHAR nt_user[UNLEN + 1];
struct passwd *pw = va_arg (arg, struct passwd *); struct passwd *pw = va_arg (arg, struct passwd *);
char *domain = va_arg (arg, char *); char *domain = va_arg (arg, char *);
char *user = va_arg (arg, char *); char *user = va_arg (arg, char *);
extract_nt_dom_user (pw, domain, user); extract_nt_dom_user (pw, nt_domain, nt_user);
if (domain)
sys_wcstombs (domain, MAX_DOMAIN_NAME_LEN + 1, nt_domain);
if (user)
sys_wcstombs (user, UNLEN + 1, nt_user);
return 0; return 0;
} }
case CW_CMDLINE: case CW_CMDLINE:

View File

@ -22,6 +22,7 @@ details. */
#include "dtable.h" #include "dtable.h"
#include "cygheap.h" #include "cygheap.h"
#include "ntdll.h" #include "ntdll.h"
#include "tls_pbuf.h"
#include <lm.h> #include <lm.h>
#include <iptypes.h> #include <iptypes.h>
#include "pwdgrp.h" #include "pwdgrp.h"
@ -36,7 +37,7 @@ cygwin_set_impersonation_token (const HANDLE hToken)
} }
void void
extract_nt_dom_user (const struct passwd *pw, char *domain, char *user) extract_nt_dom_user (const struct passwd *pw, PWCHAR domain, PWCHAR user)
{ {
cygsid psid; cygsid psid;
@ -47,12 +48,12 @@ extract_nt_dom_user (const struct passwd *pw, char *domain, char *user)
debug_printf ("pw_gecos %x (%s)", pw->pw_gecos, pw->pw_gecos); debug_printf ("pw_gecos %x (%s)", pw->pw_gecos, pw->pw_gecos);
if (psid.getfrompw (pw) if (psid.getfrompw (pw)
&& LookupAccountSid (NULL, psid, user, &ulen, domain, &dlen, &use)) && LookupAccountSidW (NULL, psid, user, &ulen, domain, &dlen, &use))
return; return;
char *d, *u, *c; char *d, *u, *c;
domain[0] = '\0'; domain[0] = L'\0';
strlcpy (user, pw->pw_name, UNLEN + 1); sys_mbstowcs (user, UNLEN + 1, pw->pw_name);
if ((d = strstr (pw->pw_gecos, "U-")) != NULL && if ((d = strstr (pw->pw_gecos, "U-")) != NULL &&
(d == pw->pw_gecos || d[-1] == ',')) (d == pw->pw_gecos || d[-1] == ','))
{ {
@ -60,33 +61,35 @@ extract_nt_dom_user (const struct passwd *pw, char *domain, char *user)
if ((u = strechr (d + 2, '\\')) >= c) if ((u = strechr (d + 2, '\\')) >= c)
u = d + 1; u = d + 1;
else if (u - d <= MAX_DOMAIN_NAME_LEN + 2) else if (u - d <= MAX_DOMAIN_NAME_LEN + 2)
strlcpy (domain, d + 2, u - d - 1); sys_mbstowcs (domain, MAX_DOMAIN_NAME_LEN + 1, d + 2, u - d - 1);
if (c - u <= UNLEN + 1) if (c - u <= UNLEN + 1)
strlcpy (user, u + 1, c - u); sys_mbstowcs (user, UNLEN + 1, u + 1, c - u);
} }
} }
extern "C" HANDLE extern "C" HANDLE
cygwin_logon_user (const struct passwd *pw, const char *password) cygwin_logon_user (const struct passwd *pw, const char *password)
{ {
if (!pw) if (!pw || !password)
{ {
set_errno (EINVAL); set_errno (EINVAL);
return INVALID_HANDLE_VALUE; return INVALID_HANDLE_VALUE;
} }
char nt_domain[MAX_DOMAIN_NAME_LEN + 1]; WCHAR nt_domain[MAX_DOMAIN_NAME_LEN + 1];
char nt_user[UNLEN + 1]; WCHAR nt_user[UNLEN + 1];
PWCHAR passwd;
HANDLE hToken; HANDLE hToken;
tmp_pathbuf tp;
extract_nt_dom_user (pw, nt_domain, nt_user); extract_nt_dom_user (pw, nt_domain, nt_user);
debug_printf ("LogonUserA (%s, %s, ...)", nt_user, nt_domain); debug_printf ("LogonUserW (%W, %W, ...)", nt_user, nt_domain);
sys_mbstowcs (passwd = tp.w_get (), NT_MAX_PATH, password);
/* CV 2005-06-08: LogonUser should run under the primary process token, /* CV 2005-06-08: LogonUser should run under the primary process token,
otherwise it returns with ERROR_ACCESS_DENIED. */ otherwise it returns with ERROR_ACCESS_DENIED. */
cygheap->user.deimpersonate (); cygheap->user.deimpersonate ();
if (!LogonUserA (nt_user, *nt_domain ? nt_domain : NULL, (char *) password, if (!LogonUserW (nt_user, *nt_domain ? nt_domain : NULL, passwd,
LOGON32_LOGON_INTERACTIVE, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT,
LOGON32_PROVIDER_DEFAULT,
&hToken)) &hToken))
{ {
__seterrno (); __seterrno ();

View File

@ -375,7 +375,7 @@ bool verify_token (HANDLE token, cygsid &usersid, user_groups &groups, bool *pin
bool get_server_groups (cygsidlist &grp_list, PSID usersid, struct passwd *pw); bool get_server_groups (cygsidlist &grp_list, PSID usersid, struct passwd *pw);
/* Extract U-domain\user field from passwd entry. */ /* Extract U-domain\user field from passwd entry. */
void extract_nt_dom_user (const struct passwd *pw, char *domain, char *user); void extract_nt_dom_user (const struct passwd *pw, PWCHAR domain, PWCHAR user);
/* Get default logonserver for a domain. */ /* Get default logonserver for a domain. */
bool get_logon_server (PWCHAR domain, PWCHAR wserver, bool rediscovery); bool get_logon_server (PWCHAR domain, PWCHAR wserver, bool rediscovery);