Skip to content

Commit

Permalink
Responder: set hardcoded strings for prompts
Browse files Browse the repository at this point in the history
Due to the difficulty of having a single source for the prompts strings
for both CLI and GUI, it has been decided to leave them fixed and use
the strings proposed by Allan in the mockups design.

Signed-off-by: Iker Pedrosa <[email protected]>
  • Loading branch information
ikerexxe committed Sep 17, 2024
1 parent 270dc3c commit a808f15
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 103 deletions.
95 changes: 4 additions & 91 deletions src/responder/pam/pamsrv_json.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,104 +202,17 @@ obtain_prompts(struct confdb_ctx *cdb, TALLOC_CTX *mem_ctx,
char *passkey_init_prompt = NULL;
char *passkey_pin_prompt = NULL;
char *passkey_touch_prompt = NULL;
const char *tmp = NULL;
int prompt_type;
size_t c;
errno_t ret;

tmp_ctx = talloc_new(NULL);
if (tmp_ctx == NULL) {
return ENOMEM;
}

if (pc_list != NULL) {
for (c = 0; pc_list[c] != NULL; c++) {
prompt_type = pc_get_type(pc_list[c]);
switch(prompt_type) {
case PC_TYPE_PASSWORD:
tmp = pc_get_password_prompt(pc_list[c]);
if (tmp == NULL) {
ret = ENOENT;
}
password_prompt = talloc_strdup(tmp_ctx, tmp);
if (password_prompt == NULL) {
ret = ENOMEM;
}
break;
case PC_TYPE_EIDP:
tmp = pc_get_eidp_init_prompt(pc_list[c]);
if (tmp == NULL) {
ret = ENOENT;
}
oauth2_init_prompt = talloc_strdup(tmp_ctx, tmp);
if (oauth2_init_prompt == NULL) {
ret = ENOMEM;
}
tmp = pc_get_eidp_link_prompt(pc_list[c]);
if (tmp == NULL) {
ret = ENOENT;
}
oauth2_link_prompt = talloc_strdup(tmp_ctx, tmp);
if (oauth2_link_prompt == NULL) {
ret = ENOMEM;
}
break;
case PC_TYPE_SMARTCARD:
tmp = pc_get_smartcard_init_prompt(pc_list[c]);
if (tmp == NULL) {
ret = ENOENT;
}
sc_init_prompt = talloc_strdup(tmp_ctx, tmp);
if (sc_init_prompt == NULL) {
ret = ENOMEM;
}
tmp = pc_get_smartcard_pin_prompt(pc_list[c]);
if (tmp == NULL) {
ret = ENOENT;
}
sc_pin_prompt = talloc_strdup(tmp_ctx, tmp);
if (sc_pin_prompt == NULL) {
ret = ENOMEM;
}
break;
case PC_TYPE_PASSKEY:
tmp = pc_get_passkey_inter_prompt(pc_list[c]);
if (tmp == NULL) {
ret = ENOENT;
}
passkey_init_prompt = talloc_strdup(tmp_ctx, tmp);
if (passkey_init_prompt == NULL) {
ret = ENOMEM;
}
tmp = pc_get_passkey_pin_prompt(pc_list[c]);
if (tmp == NULL) {
ret = ENOENT;
}
passkey_pin_prompt = talloc_strdup(tmp_ctx, tmp);
if (passkey_pin_prompt == NULL) {
ret = ENOMEM;
}
tmp = pc_get_passkey_touch_prompt(pc_list[c]);
if (tmp == NULL) {
ret = ENOENT;
}
passkey_touch_prompt = talloc_strdup(tmp_ctx, tmp);
if (passkey_touch_prompt == NULL) {
ret = ENOMEM;
}
break;
default:
ret = EPERM;
goto done;
}
}
}

if (password_prompt == NULL) {
ret = confdb_get_string(cdb, tmp_ctx, CONFDB_PC_CONF_ENTRY,
CONFDB_PC_PASSWORD_PROMPT, "",
&password_prompt);
if (ret != EOK) {
password_prompt = talloc_strdup(tmp_ctx, "Password");
if (password_prompt == NULL) {
ret = ENOMEM;
goto done;
}
}
Expand Down Expand Up @@ -330,7 +243,7 @@ obtain_prompts(struct confdb_ctx *cdb, TALLOC_CTX *mem_ctx,
}

if (sc_pin_prompt == NULL) {
sc_pin_prompt = talloc_strdup(tmp_ctx, "PIN");
sc_pin_prompt = talloc_strdup(tmp_ctx, "Smartcard PIN");
if (sc_pin_prompt == NULL) {
ret = ENOMEM;
goto done;
Expand Down
24 changes: 12 additions & 12 deletions src/tests/cmocka/test_pamsrv_json.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@
#include "src/responder/pam/pamsrv_json.h"

#define PASSWORD_PROMPT "Password"
#define OAUTH2_INIT_PROMPT "Init"
#define OAUTH2_LINK_PROMPT "Link"
#define OAUTH2_INIT_PROMPT "Log In"
#define OAUTH2_LINK_PROMPT "Log in online with another device"
#define OAUTH2_URI "short.url.com/tmp\0"
#define OAUTH2_URI_COMP "\0"
#define OAUTH2_CODE "1234-5678"
#define OAUTH2_STR OAUTH2_URI OAUTH2_URI_COMP OAUTH2_CODE
#define SC_INIT_PROMPT "Insert smartcard"
#define SC_PIN_PROMPT "PIN"
#define PASSKEY_INIT_PROMPT "Insert key"
#define PASSKEY_PIN_PROMPT "Key PIN"
#define PASSKEY_TOUCH_PROMPT "Touch key"
#define SC_PIN_PROMPT "Smartcard PIN"
#define PASSKEY_INIT_PROMPT "Insert security key"
#define PASSKEY_PIN_PROMPT "Security key PIN"
#define PASSKEY_TOUCH_PROMPT "Touch security key"

#define SC1_CERT_USER "cert_user1\0"
#define SC1_TOKEN_NAME "token_name1\0"
Expand Down Expand Up @@ -75,18 +75,18 @@
#define BASIC_SC "\"smartcard:1\": {" \
"\"name\": \"prompt1\", \"role\": \"smartcard\", " \
"\"selectable\": true, " \
"\"init_instruction\": \"Insert smartcard\", " \
"\"pin_prompt\": \"PIN\"}"
"\"init_instruction\": \"" SC_INIT_PROMPT "\", " \
"\"pin_prompt\": \"" SC_PIN_PROMPT "\"}"
#define MULTIPLE_SC "\"smartcard:1\": {" \
"\"name\": \"prompt1\", \"role\": \"smartcard\", " \
"\"selectable\": true, " \
"\"init_instruction\": \"Insert smartcard\", " \
"\"pin_prompt\": \"PIN\"}, " \
"\"init_instruction\": \"" SC_INIT_PROMPT "\", " \
"\"pin_prompt\": \"" SC_PIN_PROMPT "\"}, " \
"\"smartcard:2\": {" \
"\"name\": \"prompt2\", \"role\": \"smartcard\", " \
"\"selectable\": true, " \
"\"init_instruction\": \"Insert smartcard\", " \
"\"pin_prompt\": \"PIN\"}"
"\"init_instruction\": \"" SC_INIT_PROMPT "\", " \
"\"pin_prompt\": \"" SC_PIN_PROMPT "\"}"
#define BASIC_PASSKEY "\"passkey\": {" \
"\"name\": \"passkey\", \"role\": \"passkey\", " \
"\"selectable\": true, " \
Expand Down

0 comments on commit a808f15

Please sign in to comment.