#!/bin/sh

# Reports parameters that exist in postconf(1) output, but that are not
# documented in the postconf(5) manpage.

LANG=C; export LANG
LC_ALL=C; export LC_ALL

bin/postconf mail_version >/dev/null || exit 1

trap 'rm -f want.tmp have.tmp stoplist.tmp 2>/dev/null' 0 1 2 3 15

# Extract parameters from the postconf(5) manpage.

awk '/^%PARAM/ { print $2 }' proto/postconf.proto | sort > have.tmp || exit 1

# Build a stoplist for postconf(1) output.

# Eliminate unwanted dynamic parameter names for delivery agents. These
# names are prefixed by their master.cf service name (they must instead
# be documented with fake names that have the "transport_" prefix; that
# is implemented later in this script).

for xport in error lmtp local relay retry smtp virtual
do
   cat <<EOF
${xport}_delivery_slot_cost
${xport}_delivery_slot_discount
${xport}_delivery_slot_loan
${xport}_destination_concurrency_failed_cohort_limit
${xport}_destination_concurrency_limit
${xport}_destination_concurrency_negative_feedback
${xport}_destination_concurrency_positive_feedback
${xport}_destination_rate_delay
${xport}_destination_recipient_limit
${xport}_extra_recipient_limit
${xport}_initial_destination_concurrency
${xport}_minimum_delivery_slots
${xport}_recipient_limit
${xport}_recipient_refill_delay
${xport}_recipient_refill_limit
${xport}_transport_rate_delay
EOF
done >stoplist.tmp

# Eliminate other unwanted per-service parameters.

#cat >>stoplist.tmp <<EOF
#EOF

# Eliminate unwanted auto-generated parameters that make no sense.

cat >>stoplist.tmp <<'EOF'
lmtp_tlsrpt_enable
lmtp_tlsrpt_skip_reused_handshakes
lmtp_tlsrpt_socket_name
EOF

# Build the list of parameter names that must have an entry in the
# postconf(5) manpage.

(
# First, extract parameters from postconf(1) output, using the stock
# configurations.

bin/postconf -dHc conf | grep -F -vx -f stoplist.tmp

# Next, require that all dynamically-generated parameter names for delivery
# agents are documented as transport_mumble.

cat <<EOF
transport_delivery_slot_cost
transport_delivery_slot_discount
transport_delivery_slot_loan
transport_destination_concurrency_failed_cohort_limit
transport_destination_concurrency_limit
transport_destination_concurrency_negative_feedback
transport_destination_concurrency_positive_feedback
transport_destination_rate_delay
transport_destination_recipient_limit
transport_extra_recipient_limit
transport_initial_destination_concurrency
transport_minimum_delivery_slots
transport_recipient_limit
transport_recipient_refill_delay
transport_recipient_refill_limit
transport_transport_rate_delay
EOF

# Require that other per-service parameters are documented.

cat <<EOF
transport_time_limit
EOF
) | sort >want.tmp || exit 1

# Report parameter names that have an implementation but no documentation.

comm -23 want.tmp have.tmp