From 7f8f9a59363c75271f22b7c812fc2f28d8083564 Mon Sep 17 00:00:00 2001 From: James Morris Date: Fri, 30 Jun 2023 21:01:29 -0400 Subject: [PATCH 1/6] Replace echo with printf for better shell compatibility --- mailsecchk.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/mailsecchk.sh b/mailsecchk.sh index bbc44e0..01871f3 100755 --- a/mailsecchk.sh +++ b/mailsecchk.sh @@ -21,7 +21,7 @@ usage() log() { - echo "$1" + printf '%b\n' "$1" if [ "$logfile" != "" ]; then echo "$1" >> "$logfile" @@ -30,7 +30,7 @@ log() print_good() { - echo "\e[1;32m[+]\e[0m $1" + printf '\033[1;32m[+]\033[0m %s\n' "$1" if [ "$logfile" != "" ]; then echo "[+] $1" >> "$logfile" @@ -40,7 +40,7 @@ print_good() print_bad() { - echo "\e[1;31m[-]\e[0m $1" + printf '\033[1;31m[-]\033[0m %s\n' "$1" if [ "$logfile" != "" ]; then echo "[-] $1" >> "$logfile" @@ -49,7 +49,7 @@ print_bad() print_medium() { - echo "\e[1;33m[~]\e[0m $1" + printf '\033[1;33m[~]\033[0m %s\n' "$1" if [ "$logfile" != "" ]; then echo "[~] $1" >> "$logfile" @@ -58,7 +58,7 @@ print_medium() print_info() { - echo "\e[1;34m[I]\e[0m $1" + printf '\033[1;34m[I]\033[0m %s\n' "$1" if [ "$logfile" != "" ]; then echo "[I] $1" >> "$logfile" @@ -665,7 +665,7 @@ if [ "$d" = "" ]; then exit 1 fi -log "Checking \e[1;32m$d\e[0m" +log "Checking \033[1;32m$d\033[0m" log # Preliminary checks From fc50d1f11315998428bf8c87480c20edb276e050 Mon Sep 17 00:00:00 2001 From: James Morris Date: Fri, 30 Jun 2023 21:33:38 -0400 Subject: [PATCH 2/6] Fix exit codes for usage --- mailsecchk.sh | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/mailsecchk.sh b/mailsecchk.sh index 01871f3..cb2c3bd 100755 --- a/mailsecchk.sh +++ b/mailsecchk.sh @@ -16,7 +16,6 @@ usage() echo " -l log file to output to" echo " -p extract DKIM public key if found" echo " -r SPF recursive tests" - exit 0 } log() @@ -81,9 +80,10 @@ while getopts "d:hl:pr" o; do d) d="${OPTARG}" ;; - h) - usage - ;; + h) + usage + exit 0 + ;; l) logfile="${OPTARG}" ;; @@ -93,8 +93,9 @@ while getopts "d:hl:pr" o; do r) spf_recursive=1 ;; - *) + *) usage + exit 1 ;; esac done From 7eabc2132411945e96ad3306010cc277b508d3d8 Mon Sep 17 00:00:00 2001 From: James Morris Date: Sun, 23 Jul 2023 12:30:17 -0400 Subject: [PATCH 3/6] Prevent `local` from masking return values --- mailsecchk.sh | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/mailsecchk.sh b/mailsecchk.sh index cb2c3bd..9f7437b 100755 --- a/mailsecchk.sh +++ b/mailsecchk.sh @@ -414,7 +414,8 @@ dkim_specific() fi for s in $selectors; do - local curr="$(dig +short txt "$s._domainkey.$d" | grep "v=DKIM")" + local curr + curr=$(dig +short txt "$s._domainkey.$d" | grep 'v=DKIM') if [ "$curr" != "" ]; then print_good "DKIM $full_name set ($s)" @@ -451,7 +452,8 @@ dkim_extract_key() return fi - local dkim_p="$(echo "$dkim" | grep -Eo 'p=[^;]+' | sed 's/p=//g' | sed 's/[ "]//g')" + local dkim_p + dkim_p=$(echo "$dkim" | grep -Eo 'p=[^;]+' | sed 's/p=//g' | sed 's/[ "]//g') print_info "Extracting DKIM public key..." @@ -470,7 +472,8 @@ dkim_crypto_keysize() return fi - local keysize="$(echo "$dkim_parsed_key" | grep -E 'Public-Key:[ ]+\([0-9]+[ ]+bit\)' | grep -Eo '[0-9]+')" + local keysize + keysize=$(echo "$dkim_parsed_key" | grep -E 'Public-Key:[ ]+\([0-9]+[ ]+bit\)' | grep -Eo '[0-9]+') if [ "$keysize" -lt $dkim_key_minsize ]; then print_medium "DKIM public key size is < $dkim_key_minsize bits ($keysize bits)" @@ -625,7 +628,8 @@ get_bimi() while read -r s; do print_info "$s" - local curr="$(dig +short txt "$s._bimi.$d" | grep "v=BIMI")" + local curr + curr="$(dig +short txt "$s._bimi.$d" | grep 'v=BIMI')" if [ "$curr" != "" ]; then print_good "BIMI found for selector $s: $curr" From d597abff7839f9e361df68f1ac9d5520aa185865 Mon Sep 17 00:00:00 2001 From: James Morris <6653392+J-M0@users.noreply.github.com> Date: Sun, 23 Jul 2023 11:39:15 -0400 Subject: [PATCH 4/6] Check script with shellcheck --- .github/workflows/ci.yml | 13 +++++++++++++ mailsecchk.sh | 2 ++ 2 files changed, 15 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..99f8c95 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,13 @@ +name: CI +on: + push: + pull_request: +jobs: + shellcheck: + runs-on: macos-latest + steps: + - uses: actions/checkout@v3 + - name: Install shellcheck + run: brew install shellcheck + - name: Run shellcheck + run: shellcheck --color=always mailsecchk.sh diff --git a/mailsecchk.sh b/mailsecchk.sh index 9f7437b..9ab90fd 100755 --- a/mailsecchk.sh +++ b/mailsecchk.sh @@ -5,6 +5,8 @@ # This source code is licensed under the GPLv3 license found in the # LICENSE file in the root directory of this source tree. +# shellcheck disable=SC3043 + usage() { echo "Usage: $0 [OPTIONS]..." From 69d3a27d1c9292e4e8cfa232881c360895256b5b Mon Sep 17 00:00:00 2001 From: Jeffrey Bencteux Date: Mon, 24 Jul 2023 08:53:23 +0200 Subject: [PATCH 5/6] fix opts indentation --- mailsecchk.sh | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/mailsecchk.sh b/mailsecchk.sh index 9ab90fd..383eedb 100755 --- a/mailsecchk.sh +++ b/mailsecchk.sh @@ -80,25 +80,25 @@ bimi_selectors_file="./bimi_selectors.txt" while getopts "d:hl:pr" o; do case "${o}" in d) - d="${OPTARG}" - ;; + d="${OPTARG}" + ;; h) usage exit 0 ;; l) - logfile="${OPTARG}" - ;; + logfile="${OPTARG}" + ;; p) - dkim_extract=1 - ;; + dkim_extract=1 + ;; r) - spf_recursive=1 - ;; + spf_recursive=1 + ;; *) - usage + usage exit 1 - ;; + ;; esac done shift $((OPTIND-1)) From 65d468cbac28f1b930fbaecc488c8a94f38a6097 Mon Sep 17 00:00:00 2001 From: Jeffrey Bencteux Date: Mon, 24 Jul 2023 08:58:49 +0200 Subject: [PATCH 6/6] change CI OS macOS -> Ubuntu --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 99f8c95..f24323c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,10 +4,10 @@ on: pull_request: jobs: shellcheck: - runs-on: macos-latest + runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: Install shellcheck - run: brew install shellcheck + run: sudo apt install shellcheck - name: Run shellcheck run: shellcheck --color=always mailsecchk.sh