Skip to content

Commit 6b7d17d

Browse files
committed
Minor fixes to agent updates
1 parent d6d93e6 commit 6b7d17d

File tree

4 files changed

+25
-20
lines changed

4 files changed

+25
-20
lines changed

auth-passwd.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -155,23 +155,23 @@ warn_expiry(Authctxt *authctxt, auth_session_t *as)
155155
#ifdef HAVE_LOGIN_CAP
156156
if (authctxt->valid) {
157157
pwwarntime = login_getcaptime(lc, "password-warn", TWO_WEEKS,
158-
TWO_WEEKS);
158+
TWO_WEEKS);
159159
acwarntime = login_getcaptime(lc, "expire-warn", TWO_WEEKS,
160-
TWO_WEEKS);
160+
TWO_WEEKS);
161161
}
162162
#endif
163163
if (pwtimeleft != 0 && pwtimeleft < pwwarntime) {
164164
daysleft = pwtimeleft / DAY + 1;
165165
snprintf(buf, sizeof(buf),
166-
"Your password will expire in %lld day%s.\n",
167-
daysleft, daysleft == 1 ? "" : "s");
166+
"Your password will expire in %lld day%s.\n",
167+
daysleft, daysleft == 1 ? "" : "s");
168168
buffer_append(&loginmsg, buf, strlen(buf));
169169
}
170170
if (actimeleft != 0 && actimeleft < acwarntime) {
171171
daysleft = actimeleft / DAY + 1;
172172
snprintf(buf, sizeof(buf),
173-
"Your account will expire in %lld day%s.\n",
174-
daysleft, daysleft == 1 ? "" : "s");
173+
"Your account will expire in %lld day%s.\n",
174+
daysleft, daysleft == 1 ? "" : "s");
175175
buffer_append(&loginmsg, buf, strlen(buf));
176176
}
177177
}
@@ -184,16 +184,15 @@ sys_auth_passwd(Authctxt *authctxt, const char *password)
184184
static int expire_checked = 0;
185185

186186
as = auth_usercheck(pw->pw_name, authctxt->style, "auth-ssh",
187-
(char *)password);
187+
(char *)password);
188188
if (as == NULL)
189189
return (0);
190190
if (auth_getstate(as) & AUTH_PWEXPIRED) {
191191
auth_close(as);
192192
disable_forwarding();
193193
authctxt->force_pwchange = 1;
194194
return (1);
195-
}
196-
else {
195+
} else {
197196
if (!expire_checked) {
198197
expire_checked = 1;
199198
warn_expiry(authctxt, as);
@@ -258,13 +257,13 @@ sys_auth_passwd(Authctxt *authctxt, const char *password)
258257

259258
/* Encrypt the candidate password using the proper salt. */
260259
encrypted_password = xcrypt(password,
261-
(pw_password[0] && pw_password[1]) ? pw_password : "xx");
260+
(pw_password[0] && pw_password[1]) ? pw_password : "xx");
262261

263262
/*
264263
* Authentication is accepted if the encrypted passwords
265264
* are identical.
266265
*/
267266
return encrypted_password != NULL &&
268-
strcmp(encrypted_password, pw_password) == 0;
267+
strcmp(encrypted_password, pw_password) == 0;
269268
}
270269
#endif

contrib/win32/win32compat/pwd.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ char *GetHomeDirFromToken(char *userName, HANDLE token)
165165
RegCloseKey(reg_key);
166166

167167
{ /* retrieve and set env variables. */
168-
/* TODO - Get away with fixed limits and dynamically allocated required memory*/
168+
/* TODO - Get away with fixed limits and dynamically allocate required memory, cleanup this logic*/
169169
#define MAX_VALUE_LEN 1000
170170
#define MAX_DATA_LEN 2000
171171
#define MAX_EXPANDED_DATA_LEN 5000
@@ -176,7 +176,8 @@ char *GetHomeDirFromToken(char *userName, HANDLE token)
176176
int i;
177177
LONG ret;
178178

179-
ImpersonateLoggedOnUser(token);
179+
if (ImpersonateLoggedOnUser(token) == FALSE)
180+
debug("Failed to impersonate user token, %d", GetLastError());
180181
SET_USER_ENV(FOLDERID_LocalAppData, L"LOCALAPPDATA");
181182
SET_USER_ENV(FOLDERID_Profile, L"USERPROFILE");
182183
SET_USER_ENV(FOLDERID_RoamingAppData, L"APPDATA");

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ generate_user_token(wchar_t* user) {
201201
&token,
202202
&quotas,
203203
&subStatus) != STATUS_SUCCESS) {
204-
debug("LsaLogonUser failed");
204+
debug("LsaLogonUser failed %d", ret);
205205
goto done;
206206
}
207207

@@ -256,12 +256,16 @@ int process_passwordauth_request(struct sshbuf* request, struct sshbuf* response
256256
*tmp = L'\0';
257257
}
258258

259-
if (LogonUserW(userW, domW, pwdW, LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_DEFAULT, &token) == FALSE ||
260-
(FALSE == GetNamedPipeClientProcessId(con->connection, &client_pid)) ||
261-
((client_proc = OpenProcess(PROCESS_DUP_HANDLE, FALSE, client_pid)) == NULL) ||
262-
(FALSE == DuplicateHandle(GetCurrentProcess(), token, client_proc, &dup_token, TOKEN_QUERY | TOKEN_IMPERSONATE, FALSE, DUPLICATE_SAME_ACCESS)) ||
263-
(sshbuf_put_u32(response, dup_token) != 0)) {
264-
debug("failed to authenticate user");
259+
if (LogonUserW(userW, domW, pwdW, LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_DEFAULT, &token) == FALSE) {
260+
debug("failed to logon user");
261+
goto done;
262+
}
263+
264+
if ((FALSE == GetNamedPipeClientProcessId(con->connection, &client_pid)) ||
265+
((client_proc = OpenProcess(PROCESS_DUP_HANDLE, FALSE, client_pid)) == NULL) ||
266+
(FALSE == DuplicateHandle(GetCurrentProcess(), token, client_proc, &dup_token, TOKEN_QUERY | TOKEN_IMPERSONATE, FALSE, DUPLICATE_SAME_ACCESS)) ||
267+
(sshbuf_put_u32(response, dup_token) != 0)) {
268+
debug("failed to duplicate user token");
265269
goto done;
266270
}
267271

contrib/win32/win32compat/ssh-agent/connection.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ get_con_client_type(HANDLE pipe) {
167167
return r;
168168
}
169169

170+
/* TODO - move this to common header*/
170171
#define SSH_AGENT_AUTHENTICATE 100
171172

172173
static int

0 commit comments

Comments
 (0)