1
0
mirror of https://github.com/InfrastructureServices/vsftpd.git synced 2025-04-19 01:24:02 +03:00

Enable wide-character support in logs

This commit is contained in:
Artem Egorenkov 2021-03-29 18:33:46 +02:00
parent 63f0498a64
commit 8b82e73c93
7 changed files with 61 additions and 1 deletions

View File

@ -171,7 +171,14 @@ vsf_log_do_log_to_file(int fd, struct mystr* p_str)
return;
}
}
str_replace_unprintable_with_hex(p_str);
if (tunable_wc_logs_enable)
{
str_replace_unprintable_with_hex_wc(p_str);
}
else
{
str_replace_unprintable_with_hex(p_str);
}
str_append_char(p_str, '\n');
/* Ignore write failure; maybe the disk filled etc. */
(void) str_write_loop(p_str, fd);

View File

@ -113,6 +113,7 @@ parseconf_bool_array[] =
{ "allow_writeable_chroot", &tunable_allow_writeable_chroot },
{ "better_stou", &tunable_better_stou },
{ "log_die", &tunable_log_die },
{ "wc_logs_enable", &tunable_wc_logs_enable },
{ 0, 0 }
};

42
str.c
View File

@ -22,6 +22,8 @@
#include <stdio.h>
#include <string.h>
#include <wchar.h>
#include <wctype.h>
/* File local functions */
static void str_split_text_common(struct mystr* p_src, struct mystr* p_rhs,
@ -747,6 +749,46 @@ str_replace_unprintable_with_hex(struct mystr* p_str)
vsf_sysutil_free(ups);
}
void str_replace_unprintable_with_hex_wc(struct mystr* p_str)
{
unsigned int ups_size = sizeof(unsigned int) * (p_str->len);
if (ups_size < p_str->len)
{
bug("string is to long");
}
unsigned int* ups = vsf_sysutil_malloc(ups_size);
unsigned int up_count = 0;
size_t current = 0;
wchar_t pwc;
mbstate_t ps;
memset(&ps, 0, sizeof(ps));
ssize_t len = 0;
while ((len = mbrtowc(&pwc, p_str->p_buf, p_str->len - current, &ps)) > 0)
{
if (!iswprint(pwc))
{
for (unsigned int i = 0; i < len; i++)
{
ups[up_count++] = current++;
}
}
else
{
current += len;
}
}
if (len < 0)
{
while (current < p_str->len)
{
ups[up_count++] = current++;
}
}
str_replace_positions_with_hex(p_str, ups, up_count);
vsf_sysutil_free(ups);
}
void
str_replace_positions_with_hex(struct mystr* p_str, const unsigned int* poss, const unsigned int pos_count)
{

1
str.h
View File

@ -99,6 +99,7 @@ int str_all_space(const struct mystr* p_str);
int str_contains_unprintable(const struct mystr* p_str);
void str_replace_unprintable(struct mystr* p_str, char new_char);
void str_replace_unprintable_with_hex(struct mystr* p_str);
void str_replace_unprintable_with_hex_wc(struct mystr* p_str);
void str_replace_positions_with_hex(struct mystr* p_str, const unsigned int* poss,
const unsigned int pos_count);
int str_atoi(const struct mystr* p_str);

View File

@ -94,6 +94,7 @@ int tunable_seccomp_sandbox;
int tunable_allow_writeable_chroot;
int tunable_better_stou;
int tunable_log_die;
int tunable_wc_logs_enable;
unsigned int tunable_accept_timeout;
unsigned int tunable_connect_timeout;
@ -244,6 +245,7 @@ tunables_load_defaults()
tunable_allow_writeable_chroot = 0;
tunable_better_stou = 0;
tunable_log_die = 0;
tunable_wc_logs_enable = 0;
tunable_accept_timeout = 60;
tunable_connect_timeout = 60;

View File

@ -98,6 +98,7 @@ extern int tunable_better_stou; /* Use better file name generation
*/
extern int tunable_log_die; /* Log calls to die(), die2()
* and bug() */
extern int tunable_wc_logs_enable; /* Allow non ASCII characters in logs */
/* Integer/numeric defines */
extern unsigned int tunable_accept_timeout;

View File

@ -735,6 +735,12 @@ If enabled, use CLONE_NEWPID and CLONE_NEWIPC to isolate processes to their
ipc and pid namespaces. So separated processes can not interact with each other.
Default: YES
.TP
.B wc_logs_enable
If enabled, logs will be treated as wide-character strings and not just
ASCII strings when filtering out non-printable characters.
Default: NO
.SH NUMERIC OPTIONS
Below is a list of numeric options. A numeric option must be set to a non