Skip to content

Commit ead199c

Browse files
committed
5-14 C4
1 parent 03c8d96 commit ead199c

File tree

3 files changed

+45
-62
lines changed

3 files changed

+45
-62
lines changed

auth2-pubkey.c

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -93,21 +93,7 @@ extern u_int session_id2_len;
9393

9494
static int
9595
userauth_pubkey(Authctxt *authctxt)
96-
{
97-
#ifdef WIN32_FIXME
98-
99-
int loginStat = 1;
100-
101-
char currentUser[MAX_PATH] = {0};
102-
103-
DWORD currentUserSize = sizeof(currentUser);
104-
105-
int targetIsCurrent = 0;
106-
107-
int doOpenSSHVerify = 0;
108-
109-
#endif
110-
96+
{
11197
Buffer b;
11298
Key *key = NULL;
11399
char *pkalg, *userstyle;
@@ -203,9 +189,6 @@ userauth_pubkey(Authctxt *authctxt)
203189

204190
/* test for correct signature */
205191
authenticated = 0;
206-
/*
207-
* On pure win32 try to logon using lsa first.
208-
*/
209192

210193
#ifdef WIN32_FIXME
211194
{
@@ -234,13 +217,18 @@ userauth_pubkey(Authctxt *authctxt)
234217
OPEN_EXISTING, // opens existing pipe
235218
FILE_FLAG_OVERLAPPED, // attributes
236219
NULL); // no template file
237-
if (h == INVALID_HANDLE_VALUE)
220+
if (h == INVALID_HANDLE_VALUE) {
221+
debug("cannot connect to auth agent");
238222
break;
223+
}
239224

240-
if (!GetNamedPipeServerProcessId(h, &pipe_server_pid) || (agent_pid != pipe_server_pid))
225+
if (!GetNamedPipeServerProcessId(h, &pipe_server_pid) || (agent_pid != pipe_server_pid)) {
226+
debug("auth agent pid mismatch");
241227
break;
228+
}
242229

243-
sock = w32_allocate_fd_for_handle(h, FALSE);
230+
if ((sock = w32_allocate_fd_for_handle(h, FALSE)) < 0)
231+
break;
244232
msg = sshbuf_new();
245233
if (!msg)
246234
break;
@@ -251,8 +239,10 @@ userauth_pubkey(Authctxt *authctxt)
251239
(r = sshbuf_put_string(msg, sig, slen)) != 0 ||
252240
(r = sshbuf_put_string(msg, buffer_ptr(&b), buffer_len(&b))) != 0 ||
253241
(r = ssh_request_reply(sock, msg, msg)) != 0 ||
254-
(r = sshbuf_get_u32(msg, &token)) != 0 )
242+
(r = sshbuf_get_u32(msg, &token)) != 0) {
243+
debug("auth agent did not authorize client %s", authctxt->pw->pw_name);
255244
break;
245+
}
256246

257247
break;
258248

authfd.c

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -95,35 +95,42 @@ ssh_get_authentication_socket(int *fdp)
9595
*fdp = -1;
9696

9797
#ifdef WIN32_FIXME
98+
{
9899
#define SSH_AGENT_ROOT "SOFTWARE\\SSH\\Agent"
99-
HKEY agent_root = 0;
100-
DWORD agent_pid = 0, tmp_size = 4, pipe_server_pid = 0xff;
101-
RegOpenKeyEx(HKEY_LOCAL_MACHINE, SSH_AGENT_ROOT, 0, KEY_QUERY_VALUE, &agent_root);
102-
if (agent_root) {
103-
RegQueryValueEx(agent_root, "ProcessId", 0, NULL, &agent_pid, &tmp_size);
104-
RegCloseKey(agent_root);
105-
}
106-
107-
HANDLE h = CreateFile(
108-
"\\\\.\\pipe\\ssh-keyagent", // pipe name
109-
GENERIC_READ | // read and write access
110-
GENERIC_WRITE,
111-
0, // no sharing
112-
NULL, // default security attributes
113-
OPEN_EXISTING, // opens existing pipe
114-
FILE_FLAG_OVERLAPPED, // attributes
115-
NULL); // no template file
116-
if (h == INVALID_HANDLE_VALUE) {
117-
return SSH_ERR_AGENT_NOT_PRESENT;
118-
}
100+
HKEY agent_root = 0;
101+
DWORD agent_pid = 0, tmp_size = 4, pipe_server_pid = 0xff;
102+
HANDLE h;
103+
RegOpenKeyEx(HKEY_LOCAL_MACHINE, SSH_AGENT_ROOT, 0, KEY_QUERY_VALUE, &agent_root);
104+
if (agent_root) {
105+
RegQueryValueEx(agent_root, "ProcessId", 0, NULL, &agent_pid, &tmp_size);
106+
RegCloseKey(agent_root);
107+
}
119108

120-
if (!GetNamedPipeServerProcessId(h, &pipe_server_pid) || (agent_pid != pipe_server_pid)) {
121-
return SSH_ERR_AGENT_COMMUNICATION;
122-
123-
}
109+
h = CreateFile(
110+
"\\\\.\\pipe\\ssh-keyagent", // pipe name
111+
GENERIC_READ | // read and write access
112+
GENERIC_WRITE,
113+
0, // no sharing
114+
NULL, // default security attributes
115+
OPEN_EXISTING, // opens existing pipe
116+
FILE_FLAG_OVERLAPPED, // attributes
117+
NULL); // no template file
118+
if (h == INVALID_HANDLE_VALUE) {
119+
return SSH_ERR_AGENT_NOT_PRESENT;
120+
}
121+
122+
if (!GetNamedPipeServerProcessId(h, &pipe_server_pid) || (agent_pid != pipe_server_pid)) {
123+
debug("agent pid mismatch");
124+
CloseHandle(h);
125+
return SSH_ERR_AGENT_COMMUNICATION;
124126

125-
sock = w32_allocate_fd_for_handle(h, FALSE);
127+
}
126128

129+
if ((sock = w32_allocate_fd_for_handle(h, FALSE)) < 0) {
130+
CloseHandle(h);
131+
return SSH_ERR_SYSTEM_ERROR;
132+
}
133+
}
127134
#else
128135
authsocket = getenv(SSH_AUTHSOCKET_ENV_NAME);
129136
if (!authsocket)

contrib/win32/win32compat/ssh-agent/pubkeyagent-request.c

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,7 @@ process_add_request(struct sshbuf* request, struct sshbuf* response, struct agen
4242

4343

4444
int process_pubkeyagent_request(struct sshbuf* request, struct sshbuf* response, struct agent_connection* con) {
45-
int r = 0;
46-
const u_char *op;
47-
size_t op_len;
48-
49-
if ((r = sshbuf_get_string_direct(request, &op, &op_len)) != 0)
50-
goto done;
51-
52-
if (op_len > 10) {
53-
r = EINVAL;
54-
goto done;
55-
}
56-
57-
if ((op_len == 3) && (strncmp(op, PK_REQUEST_ADD, 3) == 0))
58-
r = 0;
59-
45+
int r = -1;
6046

6147
done:
6248
return r;

0 commit comments

Comments
 (0)