Skip to content

Commit 74f2c00

Browse files
committed
sshd fixed to now take ___domain\user format for ___domain user login
___domain\user form now works. user@___domain format already worked but now fixd to allow local machine name as the ___domain name also. So all these formats now work: For a ___domain acct: user OR ___domain\user OR user@___domain For a local acct: user OR localmachinename\user OR user@localmachinename Note: public key logon still only works for a local user acct and the localmachinename must not be given and only the username specified for public key logon to work.
1 parent b1fb747 commit 74f2c00

File tree

1 file changed

+63
-5
lines changed

1 file changed

+63
-5
lines changed

auth-passwd.c

Lines changed: 63 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,65 @@ int sys_auth_passwd(Authctxt *authctxt, const char *password)
223223
/*
224224
* Identify ___domain or local login.
225225
*/
226-
227-
domain_UTF16 = strchr(authctxt -> user, '@') ? NULL : L".";
226+
227+
char *username = authctxt->user;
228+
229+
char *domainslash = strchr(authctxt->user, '\\');
230+
if (domainslash) {
231+
// ___domain\username format
232+
char *domainname = authctxt->user;
233+
*domainslash = '\0';
234+
username = ++domainslash; // username is past the ___domain \ is the username
235+
236+
// Convert domainname from UTF-8 to UTF-16
237+
buffer_size = MultiByteToWideChar(CP_UTF8, 0, domainname, -1, NULL, 0);
238+
239+
if (buffer_size > 0)
240+
{
241+
domain_UTF16 = xmalloc(4 * buffer_size);
242+
}
243+
else
244+
{
245+
return 0;
246+
}
247+
248+
if (0 == MultiByteToWideChar(CP_UTF8, 0, domainname,
249+
-1, domain_UTF16, buffer_size))
250+
{
251+
free(domain_UTF16);
252+
253+
return 0;
254+
}
255+
}
256+
else if (domainslash = strchr(authctxt->user, '@')) {
257+
// username@___domain format
258+
username = authctxt->user;
259+
*domainslash = '\0';
260+
char *domainname = ++domainslash; // domainname is past the user@
261+
262+
// Convert domainname from UTF-8 to UTF-16
263+
buffer_size = MultiByteToWideChar(CP_UTF8, 0, domainname, -1, NULL, 0);
264+
265+
if (buffer_size > 0)
266+
{
267+
domain_UTF16 = xmalloc(4 * buffer_size);
268+
}
269+
else
270+
{
271+
return 0;
272+
}
273+
274+
if (0 == MultiByteToWideChar(CP_UTF8, 0, domainname,
275+
-1, domain_UTF16, buffer_size))
276+
{
277+
free(domain_UTF16);
278+
279+
return 0;
280+
}
281+
}
282+
else {
283+
domain_UTF16 = strchr(authctxt->user, '@') ? NULL : L".";
284+
}
228285

229286
authctxt -> methoddata = hToken;
230287

@@ -237,7 +294,7 @@ int sys_auth_passwd(Authctxt *authctxt, const char *password)
237294
* Convert username from UTF-8 to UTF-16
238295
*/
239296

240-
buffer_size = MultiByteToWideChar(CP_UTF8, 0, authctxt -> user, -1, NULL, 0);
297+
buffer_size = MultiByteToWideChar(CP_UTF8, 0, username, -1, NULL, 0);
241298

242299
if (buffer_size > 0)
243300
{
@@ -248,7 +305,7 @@ int sys_auth_passwd(Authctxt *authctxt, const char *password)
248305
return 0;
249306
}
250307

251-
if (0 == MultiByteToWideChar(CP_UTF8, 0, authctxt -> user,
308+
if (0 == MultiByteToWideChar(CP_UTF8, 0, username,
252309
-1, user_UTF16, buffer_size))
253310
{
254311
free(user_UTF16);
@@ -296,7 +353,7 @@ int sys_auth_passwd(Authctxt *authctxt, const char *password)
296353
HANDLE weakToken = INVALID_HANDLE_VALUE;
297354

298355
debug3("Netork login attemp [%s][%ls]...",
299-
authctxt -> user, domain_UTF16);
356+
username, domain_UTF16);
300357

301358
worked = LogonUserW(user_UTF16, domain_UTF16, password_UTF16,
302359
LOGON32_LOGON_NETWORK,
@@ -314,6 +371,7 @@ int sys_auth_passwd(Authctxt *authctxt, const char *password)
314371

315372
free(user_UTF16);
316373
free(password_UTF16);
374+
if (domainslash) free(domain_UTF16);
317375

318376
/*
319377
* If login still fails, go out.

0 commit comments

Comments
 (0)