Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doas.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ char **prepenv(const struct rule *, const struct passwd *,
#define PERSIST 0x4
#define NOLOG 0x8

#define AUTH_RETRIES 3

#ifdef USE_PAM
void pamauth(const char *, const char *, int, int, int);
#endif
Expand Down
19 changes: 14 additions & 5 deletions pam.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,11 +286,20 @@ pamauth(const char *user, const char *myname, int interactive, int nopass, int p
"\rdoas (%.32s@%.32s) password: ", myname, host);

/* authenticate */
ret = pam_authenticate(pamh, 0);
if (ret != PAM_SUCCESS) {
pamcleanup(ret, sess, cred);
syslog(LOG_AUTHPRIV | LOG_NOTICE, "failed auth for %s", myname);
errx(1, "Authentication failed");
for (int i = 0; i < AUTH_RETRIES; i++) {
ret = pam_authenticate(pamh, 0);
if (ret != PAM_SUCCESS) {
syslog(LOG_AUTHPRIV | LOG_NOTICE, "failed auth for %s", myname);

if (i == AUTH_RETRIES - 1) {
pamcleanup(ret, sess, cred);
errx(1, "Authentication failed");
}
else
warnx("Authentication failed");
}
else
break;
}
}

Expand Down
39 changes: 22 additions & 17 deletions shadow.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,23 +80,28 @@ shadowauth(const char *myname, int persist)
snprintf(cbuf, sizeof(cbuf),
"\rdoas (%.32s@%.32s) password: ", myname, host);
challenge = cbuf;

response = readpassphrase(challenge, rbuf, sizeof(rbuf), RPP_REQUIRE_TTY);
if (response == NULL && errno == ENOTTY) {
syslog(LOG_AUTHPRIV | LOG_NOTICE,
"tty required for %s", myname);
errx(1, "a tty is required");
}
if (response == NULL)
err(1, "readpassphrase");
if ((encrypted = crypt(response, hash)) == NULL) {
explicit_bzero(rbuf, sizeof(rbuf));
errx(1, "Authentication failed");
}
explicit_bzero(rbuf, sizeof(rbuf));
if (strcmp(encrypted, hash) != 0) {
syslog(LOG_AUTHPRIV | LOG_NOTICE, "failed auth for %s", myname);
errx(1, "Authentication failed");
for (int i = 0; i < AUTH_RETRIES; i++) {
response = readpassphrase(challenge, rbuf, sizeof(rbuf), RPP_REQUIRE_TTY);
if (response == NULL && errno == ENOTTY) {
syslog(LOG_AUTHPRIV | LOG_NOTICE,
"tty required for %s", myname);
errx(1, "a tty is required");
}
if (response == NULL)
err(1, "readpassphrase");
if ((encrypted = crypt(response, hash)) == NULL) {
explicit_bzero(rbuf, sizeof(rbuf));
(i == AUTH_RETRIES - 1) ? errx(1, "Authentication failed") : warnx("Authentication failed");
}
else {
explicit_bzero(rbuf, sizeof(rbuf));
if (strcmp(encrypted, hash) != 0) {
syslog(LOG_AUTHPRIV | LOG_NOTICE, "failed auth for %s", myname);
(i == AUTH_RETRIES - 1) ? errx(1, "Authentication failed") : warnx("Authentication failed");
}
else
break;
}
}

#ifdef USE_TIMESTAMP
Expand Down