Skip to content

Commit d81a983

Browse files
committed
Merge branch 'L1-Prod' into console-updates-integration
2 parents c3b785a + 6b7d17d commit d81a983

File tree

15 files changed

+397
-337
lines changed

15 files changed

+397
-337
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,3 +278,4 @@ d2utmpa*
278278
configure
279279
contrib/win32/openssh/Win32-OpenSSH.VC.opendb
280280
*.opendb
281+
*.db

auth-passwd.c

Lines changed: 40 additions & 180 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@
4141
#include "xmalloc.h"
4242
#endif
4343

44-
/*
45-
* We support only client side kerberos on Windows.
46-
*/
44+
/*
45+
* We support only client side kerberos on Windows.
46+
*/
4747

4848
#ifdef WIN32_FIXME
49-
#undef GSSAPI
50-
#undef KRB5
49+
#undef GSSAPI
50+
#undef KRB5
5151
#endif
5252

5353
#include <sys/types.h>
@@ -202,183 +202,43 @@ sys_auth_passwd(Authctxt *authctxt, const char *password)
202202
}
203203

204204
#elif defined(WIN32_FIXME)
205+
extern int auth_sock;
205206
int sys_auth_passwd(Authctxt *authctxt, const char *password)
206207
{
207-
/*
208-
* Authenticate on Windows
209-
*/
210-
211-
struct passwd *pw = authctxt -> pw;
212-
213-
HANDLE hToken = INVALID_HANDLE_VALUE;
214-
215-
BOOL worked = FALSE;
216-
217-
LPWSTR user_UTF16 = NULL;
218-
LPWSTR password_UTF16 = NULL;
219-
LPWSTR domain_UTF16 = NULL;
220-
221-
int buffer_size = 0;
222-
223-
/*
224-
* Identify domain or local login.
225-
*/
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-
}
285-
286-
authctxt -> methoddata = hToken;
287-
288-
if (domain_UTF16 == NULL)
289-
{
290-
debug3("Using domain logon...");
291-
}
292-
293-
/*
294-
* Convert username from UTF-8 to UTF-16
295-
*/
296-
297-
buffer_size = MultiByteToWideChar(CP_UTF8, 0, username, -1, NULL, 0);
298-
299-
if (buffer_size > 0)
300-
{
301-
user_UTF16 = xmalloc(4 * buffer_size);
302-
}
303-
else
304-
{
305-
return 0;
306-
}
307-
308-
if (0 == MultiByteToWideChar(CP_UTF8, 0, username,
309-
-1, user_UTF16, buffer_size))
310-
{
311-
free(user_UTF16);
312-
313-
return 0;
314-
}
315-
316-
/*
317-
* Convert password from UTF-8 to UTF-16
318-
*/
319-
320-
buffer_size = MultiByteToWideChar(CP_UTF8, 0, password, -1, NULL, 0);
321-
322-
if (buffer_size > 0)
323-
{
324-
password_UTF16 = xmalloc(4 * buffer_size);
325-
}
326-
else
327-
{
328-
return 0;
329-
}
330-
331-
if (0 == MultiByteToWideChar(CP_UTF8, 0, password, -1,
332-
password_UTF16 , buffer_size))
333-
{
334-
free(password_UTF16 );
335-
336-
return 0;
337-
}
338-
339-
worked = LogonUserW(user_UTF16, domain_UTF16, password_UTF16,
340-
LOGON32_LOGON_NETWORK,
341-
LOGON32_PROVIDER_DEFAULT, &hToken);
342-
343-
344-
free(user_UTF16);
345-
free(password_UTF16);
346-
if (domainslash) free(domain_UTF16);
347-
348-
/*
349-
* If login still fails, go out.
350-
*/
351-
352-
if (!worked || hToken == INVALID_HANDLE_VALUE)
353-
{
354-
return 0;
355-
}
356-
357-
/*
358-
* Make sure this can be inherited for when
359-
* we start shells or commands.
360-
*/
361-
362-
worked = SetHandleInformation(hToken, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT);
363-
364-
if (!worked)
365-
{
366-
CloseHandle(hToken);
367-
368-
hToken = INVALID_HANDLE_VALUE;
369-
370-
authctxt -> methoddata = hToken;
371-
372-
return 0;
373-
}
374-
375-
/*
376-
* Save the handle (or invalid handle) as method-specific data.
377-
*/
378-
379-
authctxt -> methoddata = hToken;
380-
381-
return 1;
208+
/*
209+
* Authenticate on Windows
210+
*/
211+
212+
{
213+
u_char *blob = NULL;
214+
size_t blen = 0;
215+
DWORD token = 0;
216+
struct sshbuf *msg = NULL;
217+
218+
msg = sshbuf_new();
219+
if (!msg)
220+
return 0;
221+
if (sshbuf_put_u8(msg, 100) != 0 ||
222+
sshbuf_put_cstring(msg, "password") != 0 ||
223+
sshbuf_put_cstring(msg, authctxt->user) != 0 ||
224+
sshbuf_put_cstring(msg, password) != 0 ||
225+
ssh_request_reply(auth_sock, msg, msg) != 0 ||
226+
sshbuf_get_u32(msg, &token) != 0) {
227+
debug("auth agent did not authorize client %s", authctxt->pw->pw_name);
228+
return 0;
229+
}
230+
231+
232+
if (blob)
233+
free(blob);
234+
if (msg)
235+
sshbuf_free(msg);
236+
237+
authctxt->methoddata = token;
238+
239+
}
240+
241+
return 1;
382242
}
383243

384244
#elif !defined(CUSTOM_SYS_AUTH_PASSWD)

auth2-pubkey.c

Lines changed: 5 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ extern u_int session_id2_len;
8686
#ifdef WIN32_FIXME
8787

8888
extern char HomeDirLsaW[MAX_PATH];
89+
extern int auth_sock;
8990

9091
#endif
9192

@@ -192,52 +193,24 @@ userauth_pubkey(Authctxt *authctxt)
192193
#ifdef WIN32_FIXME
193194
{
194195
#define SSH_AGENT_ROOT "SOFTWARE\\SSH\\Agent"
195-
HKEY agent_root = 0;
196-
DWORD agent_pid = 0, tmp_size = 4, pipe_server_pid = 0xff;
197-
int sock = -1, r;
196+
int r;
198197
u_char *blob = NULL;
199198
size_t blen = 0;
200199
DWORD token = 0;
201-
HANDLE h = INVALID_HANDLE_VALUE;
202200
struct sshbuf *msg = NULL;
203201

204202
while (1) {
205-
RegOpenKeyEx(HKEY_LOCAL_MACHINE, SSH_AGENT_ROOT, 0, KEY_QUERY_VALUE, &agent_root);
206-
if (agent_root)
207-
RegQueryValueEx(agent_root, "ProcessId", 0, NULL, &agent_pid, &tmp_size);
208-
209-
210-
h = CreateFile(
211-
"\\\\.\\pipe\\ssh-authagent", // pipe name
212-
GENERIC_READ | // read and write access
213-
GENERIC_WRITE,
214-
0, // no sharing
215-
NULL, // default security attributes
216-
OPEN_EXISTING, // opens existing pipe
217-
FILE_FLAG_OVERLAPPED, // attributes
218-
NULL); // no template file
219-
if (h == INVALID_HANDLE_VALUE) {
220-
debug("cannot connect to auth agent");
221-
break;
222-
}
223-
224-
if (!GetNamedPipeServerProcessId(h, &pipe_server_pid) || (agent_pid != pipe_server_pid)) {
225-
debug("auth agent pid mismatch");
226-
break;
227-
}
228-
229-
if ((sock = w32_allocate_fd_for_handle(h, FALSE)) < 0)
230-
break;
231203
msg = sshbuf_new();
232204
if (!msg)
233205
break;
234-
if ((r = sshbuf_put_cstring(msg, "keyauthenticate")) != 0 ||
206+
if ((r = sshbuf_put_u8(msg, 100)) != 0 ||
207+
(r = sshbuf_put_cstring(msg, "pubkey")) != 0 ||
235208
(r = sshkey_to_blob(key, &blob, &blen)) != 0 ||
236209
(r = sshbuf_put_string(msg, blob, blen)) != 0 ||
237210
(r = sshbuf_put_cstring(msg, authctxt->pw->pw_name)) != 0 ||
238211
(r = sshbuf_put_string(msg, sig, slen)) != 0 ||
239212
(r = sshbuf_put_string(msg, buffer_ptr(&b), buffer_len(&b))) != 0 ||
240-
(r = ssh_request_reply(sock, msg, msg)) != 0 ||
213+
(r = ssh_request_reply(auth_sock, msg, msg)) != 0 ||
241214
(r = sshbuf_get_u32(msg, &token)) != 0) {
242215
debug("auth agent did not authorize client %s", authctxt->pw->pw_name);
243216
break;
@@ -246,12 +219,8 @@ userauth_pubkey(Authctxt *authctxt)
246219
break;
247220

248221
}
249-
if (agent_root)
250-
RegCloseKey(agent_root);
251222
if (blob)
252223
free(blob);
253-
if (sock != -1)
254-
close(sock);
255224
if (msg)
256225
sshbuf_free(msg);
257226

authfd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ ssh_get_authentication_socket(int *fdp)
107107
}
108108

109109
h = CreateFile(
110-
"\\\\.\\pipe\\ssh-keyagent", // pipe name
110+
"\\\\.\\pipe\\ssh-agent", // pipe name
111111
GENERIC_READ | // read and write access
112112
GENERIC_WRITE,
113113
0, // no sharing

contrib/win32/openssh/scp.vcxproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
<ItemGroup>
2323
<ClCompile Include="$(OpenSSH-Src-Path)scp.c" />
2424
</ItemGroup>
25+
<ItemGroup>
26+
<ResourceCompile Include="version.rc" />
27+
</ItemGroup>
2528
<PropertyGroup Label="Globals">
2629
<ProjectGuid>{29B98ADF-1285-49CE-BF6C-AA92C5D2FB24}</ProjectGuid>
2730
<Keyword>Win32Proj</Keyword>

contrib/win32/openssh/version.rc

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)