Home | History | Annotate | Line # | Download | only in postconf
      1 #!/bin/sh
      2 
      3 # To view the formatted manual page of this file, type:
      4 #	POSTFIXSOURCE/mantools/srctoman - extract_cfg.sh | nroff -man
      5 
      6 #++
      7 # NAME
      8 #	extract_cfg 1
      9 # SUMMARY
     10 #	extract database parameter names from cfg_get_xxx() calls
     11 # SYNOPSIS
     12 #	\fBextract_cfg [-d|-s] [\fIfile...\fB]\fR
     13 # DESCRIPTION
     14 #	The \fBextract_cfg\fR command extracts the parameter names
     15 #	from cfg_get_{str,int,bool}() calls in dict_xxx.c files. The
     16 #	output is one parameter name per line, formatted as a C string
     17 #	followed by comma.
     18 #
     19 #	Options:
     20 # .IP \fB-d\fR
     21 #	Add the "domain" parameter to the output. This is used by
     22 #	the LDAP, memcache, and *SQL* tables.
     23 # .IP \fB-s\fR
     24 #	Add the legacy SQL query parameters: "select_field", "table",
     25 #	"where_field", and "additional_conditions".
     26 # LICENSE
     27 # .ad
     28 # .fi
     29 #	The Secure Mailer license must be distributed with this software.
     30 # HISTORY
     31 # .ad
     32 # .fi
     33 #	This command was introduced with Postfix 3.3.
     34 # AUTHOR(S)
     35 #	Wietse Venema
     36 #	Google, Inc.
     37 #	111 8th Avenue
     38 #	New York, NY 10011, USA
     39 #--
     40 
     41 # In case not installed.
     42 m4 </dev/null || exit 1
     43 
     44 # Flags to add db_common parameter names.
     45 add_legacy_sql_query_params=
     46 add_domain_param=
     47 
     48 # Parse JCL.
     49 
     50 while :
     51 do
     52     case "$1" in
     53     -d) add_domain_param=1;;
     54     -s) add_legacy_sql_query_params=1;;
     55     -*) echo Bad option: $1 1>&2; exit 1;;
     56      *) break;;
     57     esac
     58     shift
     59 done
     60 
     61 # We use m4 macros to extract arguments from cfg_get_xxx() calls that
     62 # may span multiple lines. We sandwich information of interest between
     63 # control-A characters. Multiple cfg_get_xxx() calls on the same line
     64 # should be OK, as long as the calls don't nest.
     65 
     66 (
     67 cat <<'EOF'
     68 define(`cfg_get_str',`$2
     69 ')dnl
     70 define(`cfg_get_int',`$2
     71 ')dnl
     72 define(`cfg_get_bool',`$2
     73 ')dnl
     74 EOF
     75 # Convert selected C macro definitions into m4 macro definitions.
     76 sed 's/^#define[ 	]*\([DICT_MC_NAME_A-Za-z0-9_]*\)[ 	]*\("[^"]*"\)/define(`\1'"'"',`\2'"'"')/' "$@"
     77 ) | m4 | awk -F '// { print $2 }' | (
     78 test -n "$add_domain_param" && {
     79 cat <<EOF
     80 "domain"
     81 EOF
     82 }
     83 test -n "$add_legacy_sql_query_params" && {
     84 cat <<EOF
     85 "table"
     86 "select_field"
     87 "where_field"
     88 "additional_conditions"
     89 EOF
     90 }
     91 cat -
     92 ) | sort -u | sed 's/$/,/'
     93