Hide secret information

This commit is contained in:
Valera Cogut 2018-10-18 11:15:35 +03:00
parent 4ec7d26a9d
commit 4784fe2491
3 changed files with 26 additions and 1 deletions

View File

@ -45,6 +45,7 @@ typedef enum {
/* Editline specific types, despite rl_ prefix. From Heimdal project. */
typedef int rl_list_possib_func_t(char*, char***);
typedef int rl_check_secret_func_t(const char*);
typedef el_status_t el_keymap_func_t(void);
typedef int rl_hook_func_t(void);
typedef int rl_getc_func_t(void);
@ -76,6 +77,7 @@ extern char *rl_complete(char *token, int *match);
extern int rl_list_possib(char *token, char ***av);
extern char **rl_completion_matches(const char *token, rl_compentry_func_t *generator);
extern char *rl_filename_completion_function(const char *text, int state);
extern int rl_check_secret(char *source);
/* For compatibility with FSF readline. */
extern int rl_point;
@ -117,6 +119,7 @@ extern int write_history (const char *filename);
extern rl_completion_func_t *rl_attempted_completion_function;
extern rl_complete_func_t *rl_set_complete_func (rl_complete_func_t *func);
extern rl_list_possib_func_t *rl_set_list_possib_func (rl_list_possib_func_t *func);
extern rl_check_secret_func_t *rl_set_check_secret_func (rl_check_secret_func_t *func);
/* Alternate interface to plain readline(), for event loops */
extern void rl_callback_handler_install (const char *prompt, rl_vcpfunc_t *lhandler);

View File

@ -397,6 +397,21 @@ char *rl_complete(char *token, int *match)
return el_filename_complete(token, match);
}
static rl_check_secret_func_t *el_check_secret_func = NULL;
/* For compatibility with the Heimdal project. */
rl_check_secret_func_t *rl_set_check_secret_func(rl_check_secret_func_t *func)
{
rl_check_secret_func_t *old = el_check_secret_func;
el_check_secret_func = func;
return old;
}
int rl_check_secret(char *source)
{
if (el_check_secret_func)
return el_check_secret_func(source);
return 0;
}
static rl_list_possib_func_t *el_list_possib_func = NULL;
/* For compatibility with the Heimdal project. */

View File

@ -162,7 +162,10 @@ static void tty_flush(void)
return;
if (!el_no_echo) {
res = write(el_outfd, Screen, ScreenCount);
if (rl_check_secret(rl_line_buffer))
res = write(el_outfd, "", 1);
else
res = write(el_outfd, Screen, ScreenCount);
if (res > 0)
ScreenCount = 0;
}
@ -1134,6 +1137,10 @@ static void hist_add(const char *p)
if (s == NULL)
return;
// Don't add secret information in history
if (rl_check_secret(s))
return;
if (H.Size < el_hist_size) {
H.Lines[H.Size++] = s;
} else {