@@ -226,38 +226,45 @@ sys_auth_passwd(Authctxt *authctxt, const char *password)
226
226
227
227
#elif defined(WINDOWS )
228
228
/*
229
- * Authenticate on Windows - Pass credentials to ssh-agent and retrieve token
230
- * upon successful authentication
231
- * TODO - password is sent in plain text over IPC. Consider implications.
229
+ * Authenticate on Windows - Call LogonUser and retrieve user token
232
230
*/
233
231
int sys_auth_passwd (Authctxt * authctxt , const char * password )
234
232
{
235
- struct sshbuf * msg = NULL ;
236
- size_t blen = 0 ;
237
- DWORD token = 0 ;
238
- extern int auth_sock ;
233
+ wchar_t * user_utf16 = NULL , * udom_utf16 = NULL , * pwd_utf16 = NULL , * tmp ;
234
+ HANDLE token = NULL ;
239
235
int r = 0 ;
240
- int ssh_request_reply (int , struct sshbuf * , struct sshbuf * );
241
236
242
- msg = sshbuf_new ();
243
- if (!msg )
244
- fatal ("%s: out of memory" , __func__ );
237
+ if ((user_utf16 = utf8_to_utf16 (authctxt -> pw -> pw_name )) == NULL ||
238
+ (pwd_utf16 = utf8_to_utf16 (password )) == NULL ) {
239
+ fatal ("out of memory" );
240
+ goto done ;
241
+ }
245
242
246
- if (sshbuf_put_u8 (msg , SSH_AGENT_AUTHENTICATE ) != 0 ||
247
- sshbuf_put_cstring (msg , PASSWD_AUTH_REQUEST ) != 0 ||
248
- sshbuf_put_cstring (msg , authctxt -> pw -> pw_name ) != 0 ||
249
- sshbuf_put_cstring (msg , password ) != 0 ||
250
- ssh_request_reply (auth_sock , msg , msg ) != 0 ||
251
- sshbuf_get_u32 (msg , & token ) != 0 ) {
252
- debug ("auth agent did not authorize client %s" , authctxt -> user );
253
- r = 0 ;
243
+ if ((tmp = wcschr (user_utf16 , L'@' )) != NULL ) {
244
+ udom_utf16 = tmp + 1 ;
245
+ * tmp = L'\0' ;
246
+ }
247
+
248
+ if (LogonUserW (user_utf16 , udom_utf16 , pwd_utf16 , LOGON32_LOGON_NETWORK_CLEARTEXT ,
249
+ LOGON32_PROVIDER_DEFAULT , & token ) == FALSE) {
250
+ if (GetLastError () == ERROR_PASSWORD_MUST_CHANGE )
251
+ /*
252
+ * TODO - need to add support to force password change
253
+ * by sending back SSH_MSG_USERAUTH_PASSWD_CHANGEREQ
254
+ */
255
+ error ("password for user %s has expired" , authctxt -> pw -> pw_name );
256
+ else
257
+ debug ("failed to logon user: %ls domain: %ls error:%d" , user_utf16 , udom_utf16 , GetLastError ());
254
258
goto done ;
255
259
}
256
- authctxt -> methoddata = (void * )(INT_PTR )token ;
260
+
261
+ authctxt -> auth_token = (void * )(INT_PTR )token ;
257
262
r = 1 ;
258
263
done :
259
- if (msg )
260
- sshbuf_free (msg );
264
+ if (user_utf16 )
265
+ free (user_utf16 );
266
+ if (pwd_utf16 )
267
+ SecureZeroMemory (pwd_utf16 , sizeof (wchar_t ) * wcslen (pwd_utf16 ));
261
268
return r ;
262
269
}
263
270
#endif /* WINDOWS */
0 commit comments