Skip to content

Commit 0513b40

Browse files
Fix issue Yubico#205
Adds support for a `prompt=` configuration flag with a custom prompt. If not specified, existing prompt/behavior is used.
1 parent 6094967 commit 0513b40

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

pam_yubico.c

+15-2
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ struct cfg
120120
const char *capath;
121121
const char *cainfo;
122122
const char *proxy;
123+
const char *prompt;
123124
const char *url;
124125
const char *urllist;
125126
const char *ldapserver;
@@ -838,6 +839,8 @@ parse_cfg (int flags, int argc, const char **argv, struct cfg *cfg)
838839
cfg->cainfo = argv[i] + 7;
839840
if (strncmp (argv[i], "proxy=", 6) == 0)
840841
cfg->proxy = argv[i] + 6;
842+
if (strncmp (argv[i], "prompt=", 7) == 0)
843+
cfg->prompt = argv[i] + 7;
841844
if (strncmp (argv[i], "url=", 4) == 0)
842845
cfg->url = argv[i] + 4;
843846
if (strncmp (argv[i], "urllist=", 8) == 0)
@@ -935,6 +938,7 @@ parse_cfg (int flags, int argc, const char **argv, struct cfg *cfg)
935938
DBG ("urllist=%s", cfg->urllist ? cfg->urllist : "(null)");
936939
DBG ("capath=%s", cfg->capath ? cfg->capath : "(null)");
937940
DBG ("cainfo=%s", cfg->cainfo ? cfg->cainfo : "(null)");
941+
DBG ("prompt=%s", cfg->prompt ? cfg->prompt : "(null)");
938942
DBG ("proxy=%s", cfg->proxy ? cfg->proxy : "(null)");
939943
DBG ("token_id_length=%u", cfg->token_id_length);
940944
DBG ("mode=%s", cfg->mode == CLIENT ? "client" : "chresp" );
@@ -1140,7 +1144,12 @@ pam_sm_authenticate (pam_handle_t * pamh,
11401144
pmsg[0] = &msg[0];
11411145
{
11421146
#define QUERY_TEMPLATE "YubiKey for `%s': "
1143-
size_t len = strlen (QUERY_TEMPLATE) + strlen (user);
1147+
size_t len = strlen (user);
1148+
if (cfg->prompt != NULL) {
1149+
len += strlen (cfg->prompt);
1150+
} else {
1151+
len += strlen (QUERY_TEMPLATE);
1152+
}
11441153
int wrote;
11451154

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

1153-
wrote = snprintf ((char *) msg[0].msg, len, QUERY_TEMPLATE, user);
1162+
if (cfg->prompt != NULL) {
1163+
wrote = snprintf ((char *) msg[0].msg, len, cfg->prompt, user);
1164+
} else {
1165+
wrote = snprintf ((char *) msg[0].msg, len, QUERY_TEMPLATE, user);
1166+
}
11541167
if (wrote < 0 || wrote >= len)
11551168
{
11561169
retval = PAM_BUF_ERR;

0 commit comments

Comments
 (0)