diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2008-07-30 16:10:20 +0400 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2008-07-30 16:10:20 +0400 |
commit | b54881352d5c4d1c179726e52d00cc50f35a2080 (patch) | |
tree | 992ebd43e672facc72c850c995e713f31523d301 | |
parent | 79ea8bbb10421f19c016e44916124d9bb8efbeda (diff) |
* 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.
-rw-r--r-- | winsup/cygwin/ChangeLog | 9 | ||||
-rw-r--r-- | winsup/cygwin/external.cc | 10 | ||||
-rw-r--r-- | winsup/cygwin/sec_auth.cc | 29 | ||||
-rw-r--r-- | winsup/cygwin/security.h | 2 |
4 files changed, 35 insertions, 15 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index cde34cf6d..8a84c10c0 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -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> * cygwin.din (_getutline): Remove. diff --git a/winsup/cygwin/external.cc b/winsup/cygwin/external.cc index 429a2875a..d9ab4d578 100644 --- a/winsup/cygwin/external.cc +++ b/winsup/cygwin/external.cc @@ -28,6 +28,7 @@ details. */ #include <unistd.h> #include <stdlib.h> #include <wchar.h> +#include <iptypes.h> child_info *get_cygwin_startup_info (); @@ -254,10 +255,17 @@ cygwin_internal (cygwin_getinfo_types t, ...) } 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 *); char *domain = 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; } case CW_CMDLINE: diff --git a/winsup/cygwin/sec_auth.cc b/winsup/cygwin/sec_auth.cc index 0a334c001..504345573 100644 --- a/winsup/cygwin/sec_auth.cc +++ b/winsup/cygwin/sec_auth.cc @@ -22,6 +22,7 @@ details. */ #include "dtable.h" #include "cygheap.h" #include "ntdll.h" +#include "tls_pbuf.h" #include <lm.h> #include <iptypes.h> #include "pwdgrp.h" @@ -36,7 +37,7 @@ cygwin_set_impersonation_token (const HANDLE hToken) } 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; @@ -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); if (psid.getfrompw (pw) - && LookupAccountSid (NULL, psid, user, &ulen, domain, &dlen, &use)) + && LookupAccountSidW (NULL, psid, user, &ulen, domain, &dlen, &use)) return; char *d, *u, *c; - domain[0] = '\0'; - strlcpy (user, pw->pw_name, UNLEN + 1); + domain[0] = L'\0'; + sys_mbstowcs (user, UNLEN + 1, pw->pw_name); if ((d = strstr (pw->pw_gecos, "U-")) != NULL && (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) u = d + 1; 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) - strlcpy (user, u + 1, c - u); + sys_mbstowcs (user, UNLEN + 1, u + 1, c - u); } } extern "C" HANDLE cygwin_logon_user (const struct passwd *pw, const char *password) { - if (!pw) + if (!pw || !password) { set_errno (EINVAL); return INVALID_HANDLE_VALUE; } - char nt_domain[MAX_DOMAIN_NAME_LEN + 1]; - char nt_user[UNLEN + 1]; + WCHAR nt_domain[MAX_DOMAIN_NAME_LEN + 1]; + WCHAR nt_user[UNLEN + 1]; + PWCHAR passwd; HANDLE hToken; + tmp_pathbuf tp; 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, otherwise it returns with ERROR_ACCESS_DENIED. */ cygheap->user.deimpersonate (); - if (!LogonUserA (nt_user, *nt_domain ? nt_domain : NULL, (char *) password, - LOGON32_LOGON_INTERACTIVE, - LOGON32_PROVIDER_DEFAULT, + if (!LogonUserW (nt_user, *nt_domain ? nt_domain : NULL, passwd, + LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, &hToken)) { __seterrno (); diff --git a/winsup/cygwin/security.h b/winsup/cygwin/security.h index 42e75e755..9be7a28e2 100644 --- a/winsup/cygwin/security.h +++ b/winsup/cygwin/security.h @@ -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); /* 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. */ bool get_logon_server (PWCHAR domain, PWCHAR wserver, bool rediscovery); |