166a022a3SMichal Scigocki#- 266a022a3SMichal Scigocki# SPDX-License-Identifier: BSD-2-Clause 366a022a3SMichal Scigocki# 466a022a3SMichal Scigocki# Copyright (c) 2024 Michal Scigocki <michal.os@hotmail.com> 566a022a3SMichal Scigocki# 666a022a3SMichal Scigocki 7*ee75c991SMichal Scigocki. $(atf_get_srcdir)/syslogd_test_common.sh 8*ee75c991SMichal Scigocki 966a022a3SMichal Scigocki# REGEX Components 1066a022a3SMichal Scigockireadonly PRI="<15>" 1166a022a3SMichal Scigockireadonly VERSION="1" 1266a022a3SMichal Scigockireadonly DATE_RFC3164="[A-Z][a-z]{2} [ 1-3][0-9]" 1366a022a3SMichal Scigockireadonly TIMESPEC_RFC5424="([:TZ0-9\.\+\-]{20,32}|\-)" # Simplified TIMESPEC 1466a022a3SMichal Scigockireadonly TIME_RFC3164="([0-9]{2}:){2}[0-9]{2}" 1566a022a3SMichal Scigockireadonly HOSTNAME="example.test" 1666a022a3SMichal Scigockireadonly HOSTNAME_REGEX="example\.test" 1766a022a3SMichal Scigockireadonly TAG="test_tag" 1866a022a3SMichal Scigockireadonly MSG="test_log_message" 1966a022a3SMichal Scigocki 2066a022a3SMichal Scigocki# Test REGEX 2166a022a3SMichal Scigocki# Dec 2 15:55:00 example.test test_tag: test_log_message 2266a022a3SMichal Scigockireadonly REGEX_RFC3164="${DATE_RFC3164} ${TIME_RFC3164} ${HOSTNAME_REGEX} ${TAG}: ${MSG}" 2366a022a3SMichal Scigockireadonly REGEX_RFC3164_LOGFILE="^${REGEX_RFC3164}$" 2466a022a3SMichal Scigockireadonly REGEX_RFC3164_PAYLOAD="${PRI}${REGEX_RFC3164}$" 2566a022a3SMichal Scigocki 2666a022a3SMichal Scigocki# Dec 2 15:55:00 Forwarded from example.test: test_tag: test_log_message 2766a022a3SMichal Scigockireadonly REGEX_RFC3164_LEGACY="${DATE_RFC3164} ${TIME_RFC3164} Forwarded from ${HOSTNAME_REGEX}: ${TAG}: ${MSG}" 2866a022a3SMichal Scigockireadonly REGEX_RFC3164_LEGACY_LOGFILE="^${REGEX_RFC3164_LEGACY}$" 2966a022a3SMichal Scigockireadonly REGEX_RFC3164_LEGACY_PAYLOAD="${PRI}${REGEX_RFC3164_LEGACY}$" 3066a022a3SMichal Scigocki 3166a022a3SMichal Scigocki# <15>1 2024-12-02T15:55:00.000000+00:00 example.test test_tag - - - test_log_message 3266a022a3SMichal Scigockireadonly REGEX_RFC5424="${PRI}${VERSION} ${TIMESPEC_RFC5424} ${HOSTNAME_REGEX} ${TAG} - - - ${MSG}" 3366a022a3SMichal Scigockireadonly REGEX_RFC5424_LOGFILE="^${REGEX_RFC5424}$" 3466a022a3SMichal Scigockireadonly REGEX_RFC5424_PAYLOAD="${REGEX_RFC5424}$" 35*ee75c991SMichal Scigocki 36*ee75c991SMichal Scigocki# Filename helper functions 37*ee75c991SMichal Scigockiconfig_filename() 38*ee75c991SMichal Scigocki{ local ref="$1"; echo "${PWD}/syslog_${ref}.conf"; } 39*ee75c991SMichal Scigocki 40*ee75c991SMichal Scigockilocal_socket_filename() 41*ee75c991SMichal Scigocki{ local ref="$1"; echo "${PWD}/log_${ref}.sock"; } 42*ee75c991SMichal Scigocki 43*ee75c991SMichal Scigockipid_filename() 44*ee75c991SMichal Scigocki{ local ref="$1"; echo "${PWD}/syslogd_${ref}.pid"; } 45*ee75c991SMichal Scigocki 46*ee75c991SMichal Scigockilocal_privsocket_filename() 47*ee75c991SMichal Scigocki{ local ref="$1"; echo "${PWD}/logpriv_${ref}.sock"; } 48*ee75c991SMichal Scigocki 49*ee75c991SMichal Scigockiconfirm_INET_support_or_skip() 50*ee75c991SMichal Scigocki{ 51*ee75c991SMichal Scigocki if ! sysctl kern.conftxt | grep -qw INET; then 52*ee75c991SMichal Scigocki atf_skip "Running kernel does not support INET" 53*ee75c991SMichal Scigocki fi 54*ee75c991SMichal Scigocki} 55*ee75c991SMichal Scigocki 56*ee75c991SMichal Scigockiset_common_atf_metadata() 57*ee75c991SMichal Scigocki{ 58*ee75c991SMichal Scigocki atf_set timeout 5 59*ee75c991SMichal Scigocki atf_set require.user root 60*ee75c991SMichal Scigocki} 61*ee75c991SMichal Scigocki 62*ee75c991SMichal Scigocki# Wrapper with better semantic name for networking context 63*ee75c991SMichal Scigockisyslogd_start_on_port() 64*ee75c991SMichal Scigocki{ 65*ee75c991SMichal Scigocki local port="$1" 66*ee75c991SMichal Scigocki shift 1 67*ee75c991SMichal Scigocki 68*ee75c991SMichal Scigocki syslogd_start \ 69*ee75c991SMichal Scigocki -b ":${port}" \ 70*ee75c991SMichal Scigocki -f "$(config_filename ${port})" \ 71*ee75c991SMichal Scigocki -p "$(local_socket_filename ${port})" \ 72*ee75c991SMichal Scigocki -P "$(pid_filename ${port})" \ 73*ee75c991SMichal Scigocki -S "$(local_privsocket_filename ${port})" \ 74*ee75c991SMichal Scigocki $@ 75*ee75c991SMichal Scigocki} 76*ee75c991SMichal Scigocki 77*ee75c991SMichal Scigocki# Wrapper with better semantic name for networking context 78*ee75c991SMichal Scigockisyslogd_stop_on_ports() 79*ee75c991SMichal Scigocki{ 80*ee75c991SMichal Scigocki local ports="$@" 81*ee75c991SMichal Scigocki 82*ee75c991SMichal Scigocki for port in "${ports}"; do 83*ee75c991SMichal Scigocki syslogd_stop \ 84*ee75c991SMichal Scigocki "$(pid_filename ${port})" \ 85*ee75c991SMichal Scigocki "$(local_socket_filename ${port})" \ 86*ee75c991SMichal Scigocki "$(local_privsocket_filename ${port})" 87*ee75c991SMichal Scigocki done 88*ee75c991SMichal Scigocki} 89