server: Add vty command file-permission-mask

Related: SYS#5792
Change-Id: I78e0b56b38de438ee5fb679ae41c65b02ea2e722
This commit is contained in:
Pau Espin 2022-01-12 17:26:17 +01:00
parent 235eba3e9b
commit b9be6767ab
6 changed files with 47 additions and 1 deletions

View File

@ -16,6 +16,7 @@ line vty
!
server
base-path /tmp
file-permission-mask 0440
server ip 127.0.0.1
server port 6001
max-file-size 262144000

View File

@ -16,6 +16,7 @@ line vty
!
server
base-path /tmp
file-permission-mask 0440
server ip 127.0.0.1
server port 6001
max-file-size 262144000

View File

@ -129,6 +129,7 @@ struct osmo_pcap_server {
bool dh_params_allocated;
char *base_path;
mode_t permission_mask;
off_t max_size;
int max_snaplen;

View File

@ -284,6 +284,7 @@ int main(int argc, char **argv)
INIT_LLIST_HEAD(&pcap_server->conn);
pcap_server->base_path = talloc_strdup(pcap_server, "./");
pcap_server->permission_mask = 0440;
pcap_server->max_size = 1073741824;
pcap_server->max_snaplen = DEFAULT_SNAPLEN;

View File

@ -171,7 +171,7 @@ static void restart_pcap(struct osmo_pcap_conn *conn)
return;
}
conn->local_fd = creat(conn->curr_filename, 0440);
conn->local_fd = creat(conn->curr_filename, conn->server->permission_mask);
if (conn->local_fd < 0) {
LOGP(DSERVER, LOGL_ERROR, "Failed to file: '%s'\n", conn->curr_filename);
return;

View File

@ -88,6 +88,7 @@ static int config_write_server(struct vty *vty)
if (pcap_server->base_path)
vty_out(vty, " base-path %s%s", pcap_server->base_path, VTY_NEWLINE);
vty_out(vty, " file-permission-mask 0%o%s", pcap_server->permission_mask, VTY_NEWLINE);
if (pcap_server->addr)
vty_out(vty, " server ip %s%s", pcap_server->addr, VTY_NEWLINE);
if (pcap_server->port > 0)
@ -132,6 +133,46 @@ DEFUN(cfg_server_base,
return CMD_SUCCESS;
}
DEFUN(cfg_server_file_permission_mask,
cfg_server_file_permission_mask_cmd,
"file-permission-mask MODE",
"Permission mask to use when creating pcap files\n"
"The file permission mask, in octal format (default: 0440)\n")
{
unsigned long long val;
char *endptr;
errno = 0;
val = strtoul(argv[0], &endptr, 8);
switch (errno) {
case 0:
break;
case ERANGE:
case EINVAL:
default:
goto ret_invalid;
}
if (!endptr || *endptr) {
/* No chars were converted */
if (endptr == argv[0])
goto ret_invalid;
/* Or there are surplus chars after the converted number */
goto ret_invalid;
}
/* 'man mode_t': "According to POSIX, it shall be an integer type." */
if (val > INT_MAX)
goto ret_invalid;
pcap_server->permission_mask = val;
return CMD_SUCCESS;
ret_invalid:
vty_out(vty, "%% File permission mask out of range: '%s'%s", argv[0], VTY_NEWLINE);
return CMD_WARNING;
}
DEFUN(cfg_server_ip,
cfg_server_ip_cmd,
"server ip A.B.C.D",
@ -519,6 +560,7 @@ void vty_server_init(void)
install_node(&server_node, config_write_server);
install_element(SERVER_NODE, &cfg_server_base_cmd);
install_element(SERVER_NODE, &cfg_server_file_permission_mask_cmd);
install_element(SERVER_NODE, &cfg_server_ip_cmd);
install_element(SERVER_NODE, &cfg_server_port_cmd);
install_element(SERVER_NODE, &cfg_server_max_size_cmd);