1#- 2# SPDX-License-Identifier: BSD-2-Clause 3# 4# Copyright (c) 2024 Michal Scigocki <michal.os@hotmail.com> 5# 6 7. $(atf_get_srcdir)/syslogd_test_common.sh 8 9# REGEX Components 10readonly PRI="<15>" 11readonly VERSION="1" 12readonly DATE_RFC3164="[A-Z][a-z]{2} [ 1-3][0-9]" 13readonly TIMESPEC_RFC5424="([:TZ0-9\.\+\-]{20,32}|\-)" # Simplified TIMESPEC 14readonly TIME_RFC3164="([0-9]{2}:){2}[0-9]{2}" 15readonly HOSTNAME="example.test" 16readonly HOSTNAME_REGEX="example\.test" 17readonly TAG="test_tag" 18readonly MSG="test_log_message" 19 20# Test REGEX 21# Dec 2 15:55:00 example.test test_tag: test_log_message 22readonly REGEX_RFC3164="${DATE_RFC3164} ${TIME_RFC3164} ${HOSTNAME_REGEX} ${TAG}: ${MSG}" 23readonly REGEX_RFC3164_LOGFILE="^${REGEX_RFC3164}$" 24readonly REGEX_RFC3164_PAYLOAD="${PRI}${REGEX_RFC3164}$" 25 26# Dec 2 15:55:00 Forwarded from example.test: test_tag: test_log_message 27readonly REGEX_RFC3164_LEGACY="${DATE_RFC3164} ${TIME_RFC3164} Forwarded from ${HOSTNAME_REGEX}: ${TAG}: ${MSG}" 28readonly REGEX_RFC3164_LEGACY_LOGFILE="^${REGEX_RFC3164_LEGACY}$" 29readonly REGEX_RFC3164_LEGACY_PAYLOAD="${PRI}${REGEX_RFC3164_LEGACY}$" 30 31# <15>1 2024-12-02T15:55:00.000000+00:00 example.test test_tag - - - test_log_message 32readonly REGEX_RFC5424="${PRI}${VERSION} ${TIMESPEC_RFC5424} ${HOSTNAME_REGEX} ${TAG} - - - ${MSG}" 33readonly REGEX_RFC5424_LOGFILE="^${REGEX_RFC5424}$" 34readonly REGEX_RFC5424_PAYLOAD="${REGEX_RFC5424}$" 35 36# Filename helper functions 37config_filename() 38{ local ref="$1"; echo "${PWD}/syslog_${ref}.conf"; } 39 40local_socket_filename() 41{ local ref="$1"; echo "${PWD}/log_${ref}.sock"; } 42 43pid_filename() 44{ local ref="$1"; echo "${PWD}/syslogd_${ref}.pid"; } 45 46local_privsocket_filename() 47{ local ref="$1"; echo "${PWD}/logpriv_${ref}.sock"; } 48 49confirm_INET_support_or_skip() 50{ 51 if ! sysctl kern.conftxt | grep -qw INET; then 52 atf_skip "Running kernel does not support INET" 53 fi 54} 55 56set_common_atf_metadata() 57{ 58 atf_set timeout 5 59 atf_set require.user root 60} 61 62# Wrapper with better semantic name for networking context 63syslogd_start_on_port() 64{ 65 local port="$1" 66 shift 1 67 68 syslogd_start \ 69 -b ":${port}" \ 70 -f "$(config_filename ${port})" \ 71 -p "$(local_socket_filename ${port})" \ 72 -P "$(pid_filename ${port})" \ 73 -S "$(local_privsocket_filename ${port})" \ 74 $@ 75} 76 77# Wrapper with better semantic name for networking context 78syslogd_stop_on_ports() 79{ 80 local ports="$@" 81 82 for port in "${ports}"; do 83 syslogd_stop \ 84 "$(pid_filename ${port})" \ 85 "$(local_socket_filename ${port})" \ 86 "$(local_privsocket_filename ${port})" 87 done 88} 89