Skip to content

Commit

Permalink
Fix issue Yubico#205
Browse files Browse the repository at this point in the history
Adds support for a `prompt=` configuration flag with a custom prompt. If not specified, existing prompt/behavior is used.
  • Loading branch information
bored-engineer authored Dec 18, 2019
1 parent 6094967 commit 0513b40
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions pam_yubico.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ struct cfg
const char *capath;
const char *cainfo;
const char *proxy;
const char *prompt;
const char *url;
const char *urllist;
const char *ldapserver;
Expand Down Expand Up @@ -838,6 +839,8 @@ parse_cfg (int flags, int argc, const char **argv, struct cfg *cfg)
cfg->cainfo = argv[i] + 7;
if (strncmp (argv[i], "proxy=", 6) == 0)
cfg->proxy = argv[i] + 6;
if (strncmp (argv[i], "prompt=", 7) == 0)
cfg->prompt = argv[i] + 7;
if (strncmp (argv[i], "url=", 4) == 0)
cfg->url = argv[i] + 4;
if (strncmp (argv[i], "urllist=", 8) == 0)
Expand Down Expand Up @@ -935,6 +938,7 @@ parse_cfg (int flags, int argc, const char **argv, struct cfg *cfg)
DBG ("urllist=%s", cfg->urllist ? cfg->urllist : "(null)");
DBG ("capath=%s", cfg->capath ? cfg->capath : "(null)");
DBG ("cainfo=%s", cfg->cainfo ? cfg->cainfo : "(null)");
DBG ("prompt=%s", cfg->prompt ? cfg->prompt : "(null)");
DBG ("proxy=%s", cfg->proxy ? cfg->proxy : "(null)");
DBG ("token_id_length=%u", cfg->token_id_length);
DBG ("mode=%s", cfg->mode == CLIENT ? "client" : "chresp" );
Expand Down Expand Up @@ -1140,7 +1144,12 @@ pam_sm_authenticate (pam_handle_t * pamh,
pmsg[0] = &msg[0];
{
#define QUERY_TEMPLATE "YubiKey for `%s': "
size_t len = strlen (QUERY_TEMPLATE) + strlen (user);
size_t len = strlen (user);
if (cfg->prompt != NULL) {
len += strlen (cfg->prompt);
} else {
len += strlen (QUERY_TEMPLATE);
}
int wrote;

msg[0].msg = malloc (len);
Expand All @@ -1150,7 +1159,11 @@ pam_sm_authenticate (pam_handle_t * pamh,
goto done;
}

wrote = snprintf ((char *) msg[0].msg, len, QUERY_TEMPLATE, user);
if (cfg->prompt != NULL) {
wrote = snprintf ((char *) msg[0].msg, len, cfg->prompt, user);
} else {
wrote = snprintf ((char *) msg[0].msg, len, QUERY_TEMPLATE, user);
}
if (wrote < 0 || wrote >= len)
{
retval = PAM_BUF_ERR;
Expand Down

0 comments on commit 0513b40

Please sign in to comment.