mirror of
https://github.com/sheumann/hush.git
synced 2025-01-13 21:31:51 +00:00
lineedit: create history files with mode 0600
Signed-off-by: Wolfram Sang <w.sang@pengutronix.de> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
6696eac274
commit
2e9aeae4db
@ -1336,7 +1336,7 @@ static void save_history(char *str)
|
|||||||
int fd;
|
int fd;
|
||||||
int len, len2;
|
int len, len2;
|
||||||
|
|
||||||
fd = open(state->hist_file, O_WRONLY | O_CREAT | O_APPEND, 0666);
|
fd = open(state->hist_file, O_WRONLY | O_CREAT | O_APPEND, 0600);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
return;
|
return;
|
||||||
xlseek(fd, 0, SEEK_END); /* paranoia */
|
xlseek(fd, 0, SEEK_END); /* paranoia */
|
||||||
@ -1351,10 +1351,8 @@ static void save_history(char *str)
|
|||||||
/* did we write so much that history file needs trimming? */
|
/* did we write so much that history file needs trimming? */
|
||||||
state->cnt_history_in_file++;
|
state->cnt_history_in_file++;
|
||||||
if (state->cnt_history_in_file > MAX_HISTORY * 4) {
|
if (state->cnt_history_in_file > MAX_HISTORY * 4) {
|
||||||
FILE *fp;
|
|
||||||
char *new_name;
|
char *new_name;
|
||||||
line_input_t *st_temp;
|
line_input_t *st_temp;
|
||||||
int i;
|
|
||||||
|
|
||||||
/* we may have concurrently written entries from others.
|
/* we may have concurrently written entries from others.
|
||||||
* load them */
|
* load them */
|
||||||
@ -1364,8 +1362,12 @@ static void save_history(char *str)
|
|||||||
|
|
||||||
/* write out temp file and replace hist_file atomically */
|
/* write out temp file and replace hist_file atomically */
|
||||||
new_name = xasprintf("%s.%u.new", state->hist_file, (int) getpid());
|
new_name = xasprintf("%s.%u.new", state->hist_file, (int) getpid());
|
||||||
fp = fopen_for_write(new_name);
|
fd = open(state->hist_file, O_WRONLY | O_CREAT | O_TRUNC, 0600);
|
||||||
if (fp) {
|
if (fd >= 0) {
|
||||||
|
FILE *fp;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
fp = xfdopen_for_write(fd);
|
||||||
for (i = 0; i < st_temp->cnt_history; i++)
|
for (i = 0; i < st_temp->cnt_history; i++)
|
||||||
fprintf(fp, "%s\n", st_temp->history[i]);
|
fprintf(fp, "%s\n", st_temp->history[i]);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user