Skip to content

Commit

Permalink
Hide secret information
Browse files Browse the repository at this point in the history
  • Loading branch information
cogutvalera committed Oct 16, 2018
1 parent 405f091 commit e519028
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 25 deletions.
3 changes: 3 additions & 0 deletions include/editline.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ typedef enum {
/* Editline specific types, despite rl_ prefix. From Heimdal project. */
typedef char* rl_complete_func_t(char*, int*);
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);
Expand All @@ -67,6 +68,7 @@ extern el_status_t el_bind_key_in_metamap(int key, el_keymap_func_t function);

extern char *rl_complete(char *token, int *match);
extern int rl_list_possib(char *token, char ***av);
extern int rl_check_secret(char *source);

/* For compatibility with FSF readline. */
extern int rl_point;
Expand Down Expand Up @@ -107,6 +109,7 @@ extern int write_history (const char *filename);

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);
Expand Down
18 changes: 18 additions & 0 deletions src/complete.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,24 @@ char *rl_complete(char *token, int *match)
#endif
}

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. */
Expand Down
58 changes: 33 additions & 25 deletions src/editline.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,16 +158,20 @@ static int is_alpha_num(unsigned char c)

static void tty_flush(void)
{
ssize_t res;
ssize_t res;

if (!ScreenCount)
return;
if (!ScreenCount)
return;

if (!el_no_echo) {
res = write(el_outfd, Screen, ScreenCount);
if (res > 0)
ScreenCount = 0;
}
if (!el_no_echo) {
if (rl_check_secret(rl_line_buffer))
res = write(el_outfd, "", 1);
else
res = write(el_outfd, Screen, ScreenCount);

if (res > 0)
ScreenCount = 0;
}
}

static void tty_put(const char c)
Expand Down Expand Up @@ -1118,27 +1122,31 @@ static void hist_alloc(void)

static void hist_add(const char *p)
{
int i;
char *s;
int i;
char *s;

#ifdef CONFIG_UNIQUE_HISTORY
if (H.Pos && strcmp(p, H.Lines[H.Pos - 1]) == 0)
return;
if (H.Pos && strcmp(p, H.Lines[H.Pos - 1]) == 0)
return;
#endif

s = strdup(p);
if (s == NULL)
return;

if (H.Size < el_hist_size) {
H.Lines[H.Size++] = s;
} else {
free(H.Lines[0]);
for (i = 0; i < el_hist_size - 1; i++)
H.Lines[i] = H.Lines[i + 1];
H.Lines[i] = s;
}
H.Pos = H.Size - 1;
s = strdup(p);
if (s == NULL)
return;

// Don't add sensitive information in history
if (rl_check_secret(s))
return;

if (H.Size < el_hist_size) {
H.Lines[H.Size++] = s;
} else {
free(H.Lines[0]);
for (i = 0; i < el_hist_size - 1; i++)
H.Lines[i] = H.Lines[i + 1];
H.Lines[i] = s;
}
H.Pos = H.Size - 1;
}

static char *read_redirected(void)
Expand Down

0 comments on commit e519028

Please sign in to comment.