提交 d3dbc9b5 编写于 作者: D Dr. David von Oheimb

apps_ui.c: Correct password prompt for ui_method

Reviewed-by: NTomas Mraz <tmraz@fedoraproject.org>
(Merged from https://github.com/openssl/openssl/pull/12493)
上级 591ceedd
......@@ -99,6 +99,19 @@ static int ui_close(UI *ui)
return 1;
}
/* object_name defaults to prompt_info from ui user data if present */
static char *ui_prompt_construct(UI *ui, const char *phrase_desc,
const char *object_name)
{
PW_CB_DATA *cb_data = (PW_CB_DATA *)UI_get0_user_data(ui);
if (phrase_desc == NULL)
phrase_desc = "pass phrase";
if (object_name == NULL && cb_data != NULL)
object_name = cb_data->prompt_info;
return UI_construct_prompt(NULL, phrase_desc, object_name);
}
int setup_ui_method(void)
{
ui_fallback_method = UI_null();
......
......@@ -356,22 +356,22 @@ int UI_dup_error_string(UI *ui, const char *text)
0, 0, NULL);
}
char *UI_construct_prompt(UI *ui, const char *object_desc,
char *UI_construct_prompt(UI *ui, const char *phrase_desc,
const char *object_name)
{
char *prompt = NULL;
if (ui->meth->ui_construct_prompt != NULL)
prompt = ui->meth->ui_construct_prompt(ui, object_desc, object_name);
if (ui != NULL && ui->meth != NULL && ui->meth->ui_construct_prompt != NULL)
prompt = ui->meth->ui_construct_prompt(ui, phrase_desc, object_name);
else {
char prompt1[] = "Enter ";
char prompt2[] = " for ";
char prompt3[] = ":";
int len = 0;
if (object_desc == NULL)
if (phrase_desc == NULL)
return NULL;
len = sizeof(prompt1) - 1 + strlen(object_desc);
len = sizeof(prompt1) - 1 + strlen(phrase_desc);
if (object_name != NULL)
len += sizeof(prompt2) - 1 + strlen(object_name);
len += sizeof(prompt3) - 1;
......@@ -381,7 +381,7 @@ char *UI_construct_prompt(UI *ui, const char *object_desc,
return NULL;
}
OPENSSL_strlcpy(prompt, prompt1, len + 1);
OPENSSL_strlcat(prompt, object_desc, len + 1);
OPENSSL_strlcat(prompt, phrase_desc, len + 1);
if (object_name != NULL) {
OPENSSL_strlcat(prompt, prompt2, len + 1);
OPENSSL_strlcat(prompt, object_name, len + 1);
......@@ -690,10 +690,8 @@ int UI_method_set_data_duplicator(UI_METHOD *method,
int UI_method_set_prompt_constructor(UI_METHOD *method,
char *(*prompt_constructor) (UI *ui,
const char
*object_desc,
const char
*object_name))
const char *,
const char *))
{
if (method != NULL) {
method->ui_construct_prompt = prompt_constructor;
......
......@@ -44,7 +44,7 @@ UI_get_method, UI_set_method, UI_OpenSSL, UI_null - user interface
int UI_dup_error_string(UI *ui, const char *text);
char *UI_construct_prompt(UI *ui_method,
const char *object_desc, const char *object_name);
const char *phrase_desc, const char *object_name);
void *UI_add_user_data(UI *ui, void *user_data);
int UI_dup_user_data(UI *ui, void *user_data);
......@@ -149,10 +149,12 @@ as their UI_add counterparts, except that they make their own copies
of all strings.
UI_construct_prompt() is a helper function that can be used to create
a prompt from two pieces of information: an description and a name.
a prompt from two pieces of information: a phrase description I<phrase_desc>
and an object name I<object_name>, where the latter may be NULL.
The default constructor (if there is none provided by the method used)
creates a string "Enter I<description> for I<name>:". With the
description "pass phrase" and the filename "foo.key", that becomes
creates a string "Enter I<phrase_desc> for I<object_name>:"
where the " for I<object_name>" part is left out if I<object_name> is NULL.
With the description "pass phrase" and the filename "foo.key", that becomes
"Enter pass phrase for foo.key:". Other methods may create whatever
string and may include encodings that will be processed by the other
method functions.
......
......@@ -138,25 +138,26 @@ int UI_dup_error_string(UI *ui, const char *text);
# define UI_INPUT_FLAG_USER_BASE 16
/*-
* The following function helps construct a prompt. object_desc is a
* textual short description of the object, for example "pass phrase",
* and object_name is the name of the object (might be a card name or
* a file name.
* The following function helps construct a prompt.
* phrase_desc is a textual short description of the phrase to enter,
* for example "pass phrase", and
* object_name is the name of the object
* (which might be a card name or a file name) or NULL.
* The returned string shall always be allocated on the heap with
* OPENSSL_malloc(), and need to be free'd with OPENSSL_free().
*
* If the ui_method doesn't contain a pointer to a user-defined prompt
* constructor, a default string is built, looking like this:
*
* "Enter {object_desc} for {object_name}:"
* "Enter {phrase_desc} for {object_name}:"
*
* So, if object_desc has the value "pass phrase" and object_name has
* So, if phrase_desc has the value "pass phrase" and object_name has
* the value "foo.key", the resulting string is:
*
* "Enter pass phrase for foo.key:"
*/
char *UI_construct_prompt(UI *ui_method,
const char *object_desc, const char *object_name);
const char *phrase_desc, const char *object_name);
/*
* The following function is used to store a pointer to user-specific data.
......@@ -315,7 +316,7 @@ int UI_method_set_data_duplicator(UI_METHOD *method,
int UI_method_set_prompt_constructor(UI_METHOD *method,
char *(*prompt_constructor) (UI *ui,
const char
*object_desc,
*phrase_desc,
const char
*object_name));
int UI_method_set_ex_data(UI_METHOD *method, int idx, void *data);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册