This file is indexed.

/usr/share/whereami/actions/setmailrelay is in whereami 0.3.34-0.3.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
#!/bin/bash 
# $Id: setmailrelay,v 1.12 2004/10/05 20:47:22 andrew Exp $
#
# This script was written originally by Jos Visser http://www.josv.com/~josv/
# and I have modified it a little to make it slightly more generic
#    - Andrew McMillan 10 August 1999
# Postfix support by Chris Halls, August 2001
# Exim support by Auke Jilderda, October 2002
# qmail support by Patrice Neff, October 2003
# exim4 support by Itay Ben-Yaacov, April 2004
#
# 2003-12-09 Chris Halls  Use postconf for postfix configuration
#
# Usage:
#   setmailrelay none   
#       - You have a permanent internet connection, do not use a mail relay
#   setmailrelay <relay>
#       - Relay to specified host
#   setmailrelay queue [<relay>]
#       - Do not send, place on the queue.  When the queue is flushed, mail
#         will be relayed to <relay>, or $DEFAULT_RELAY if not specified


# Where are the config files for your mailer?  Can override in mail-relay.conf
SENDMAIL_CONFFILE=/etc/mail/sendmail.cf
POSTFIX_CONFFILE=/etc/postfix/main.cf
EXIM_CONFFILE=/etc/exim/exim.conf
EXIM4_CONFFILE=/etc/exim4/update-exim4.conf.conf
QMAIL_CONFDIR=/etc/qmail/

# Where we get MAIL_SERVER and DEFAULT_RELAY from
. /etc/whereami/mail-relay.conf

RELAY="${1:-none}"
QUEUE_RELAY="${2:-${DEFAULT_RELAY}}"

# check for a "parameter=" line in a file, add it if it does not exist
#    check_for_line(file, parameter)
check_for_parameter()
{
    FILE="$1"
    PARAM="$2"

    if egrep -q "^$PARAM *=" "$FILE" ; then :
    else
        echo "$PARAM=" >> "$FILE"
    fi
}

if [ "$MAIL_SERVER" = "" ]; then
  # Go for some reasonable choices
  if [ -f $SENDMAIL_CONFFILE ] ; then
    MAIL_SERVER=sendmail
  elif [ -f $POSTFIX_CONFFILE ] ; then
    MAIL_SERVER=postfix
  elif [ -f $EXIM_CONFFILE ] ; then
    MAIL_SERVER=exim
  elif [ -f $EXIM4_CONFFILE ] ; then
    MAIL_SERVER=exim4
# Only supports split configuration
  elif [ -d $QMAIL_CONFDIR ] ; then
    MAIL_SERVER=qmail
  else
    echo "Unsupported mail server configuration check /etc/whereami/mail-relay.conf"
    echo "or advise awm@debian.org, hopefully including a patch!"
    exit 1
  fi
fi

echo "Setting mail relay host ($RELAY)" 


case "$MAIL_SERVER" in
  sendmail)
        /etc/init.d/sendmail stop

        if [ "$RELAY" = "none" ]; then 
                MODE=background 
                QUEUE_RUN="-q5m" 
                RELAY=""
        elif [ "$RELAY" = "queue" ]; then 
                MODE=deferred 
                QUEUE_RUN="" 
                RELAY="smtp:${DEFAULT_RELAY}"
        else 
                MODE=background 
                QUEUE_RUN="-q5m" 
                RELAY="smtp:$RELAY" 
        fi


        sed -e "s/^DS.*\$/DS$RELAY/" \
            -e "s/^O DeliveryMode=.*\$/O DeliveryMode=$MODE/" \
            <$SENDMAIL_CONFFILE >$SENDMAIL_CONFFILE.N

        # Preserve the ownership and permissions
        chmod --reference=$SENDMAIL_CONFFILE $SENDMAIL_CONFFILE.N
        chown --reference=$SENDMAIL_CONFFILE $SENDMAIL_CONFFILE.N

        # Make a backup copy
        mv -f $SENDMAIL_CONFFILE $SENDMAIL_CONFFILE.whereami

        mv $SENDMAIL_CONFFILE.N $SENDMAIL_CONFFILE

        /etc/init.d/sendmail start
        if [ "$QUEUE_RUN" = "-q5m"]; then
                /etc/init.d/sendmail runq
        fi
    ;;

  postfix)
        if [ "$RELAY" = "none" ]; then 
                DEFER=""
                DISABLE_LOOKUPS="no"
                RELAY=""
        elif [ "$RELAY" = "queue" ]; then 
                DEFER="smtp"
                DISABLE_LOOKUPS="yes"
                RELAY="$DEFAULT_RELAY"
        else 
                DEFER=""
                DISABLE_LOOKUPS="yes"
                MODE=background 
                RELAY="$RELAY"
        fi

        postconf -ev defer_transports=$DEFER disable_dns_lookups=$DISABLE_LOOKUPS \
	         "relayhost=$RELAY"

        # Need to reload after changing things
        /etc/init.d/postfix reload

        if [ "$RELAY" != "queue" ]; then
            # Run mail queue
            /etc/init.d/postfix flush
        fi
    ;;

  exim)
        if [ "$RELAY" = "none" ]; then 
                DEFER="# queue_remote_domains = *"
                RELAY="$DEFAULT_RELAY"
        elif [ "$RELAY" = "queue" ]; then 
                DEFER="queue_remote_domains = ! *"
                RELAY="$DEFAULT_RELAY"
        else 
                DEFER="# queue_remote_domains = *"
                RELAY="$RELAY"
        fi

        # add parameters to configuration file if they do not exist
        #check_for_parameter $EXIM_CONFFILE "queue_remote_domains"
        #check_for_parameter $EXIM_CONFFILE "route_list"

        sed -e "s/^.*queue_remote_domains *=.*\$/$DEFER/" \
            -e "s/route_list *=.*\$/route_list = \"* $RELAY bydns_a\"/" \
            < $EXIM_CONFFILE > $EXIM_CONFFILE.N

        # Preserve the ownership and permissions
        chmod --reference=$EXIM_CONFFILE $EXIM_CONFFILE.N
        chown --reference=$EXIM_CONFFILE $EXIM_CONFFILE.N

        # make a backup copy of configuration file
        mv -f $EXIM_CONFFILE $EXIM_CONFFILE.whereami
        mv $EXIM_CONFFILE.N $EXIM_CONFFILE

        # reload configuration
        /etc/init.d/exim reload

        if [ "$RELAY" != "queue" ]; then
            # flush queued mails
            exim -qff
        fi
    ;;

    exim4)
        if [ "$RELAY" = "none" ]; then
                DEFER="no"
                RELAY="$DEFAULT_RELAY"
        elif [ "$RELAY" = "queue" ]; then 
                DEFER="yes"
                RELAY=""
        else 
                DEFER="no"
        fi

        sed -e "s/dc_smarthost=.*/dc_smarthost=\'$RELAY\'/" \
            < $EXIM4_CONFFILE > $EXIM4_CONFFILE.N

        # Preserve the ownership and permissions
        chmod --reference=$EXIM4_CONFFILE $EXIM4_CONFFILE.N
        chown --reference=$EXIM4_CONFFILE $EXIM4_CONFFILE.N

        # make a backup copy of configuration file
#        mv -f $EXIM4_CONFFILE $EXIM4_CONFFILE.whereami
        mv $EXIM4_CONFFILE.N $EXIM4_CONFFILE

        # reload configuration
        /etc/init.d/exim4 reload

        if [ "$DEFER" = "no" ]; then
            # flush queued mails
            exim4 -qff
        fi
    ;;

  qmail)
        QMAIL_CONFFILE="${QMAIL_CONFDIR}smtproutes"
        QMAIL_CONFFILE_NEW="${QMAIL_CONFFILE}.setmailrelay"
	        
        if [ "$RELAY" = "none" ]; then 
                DELIVERIES="20"
                RELAY="$DEFAULT_RELAY"
        elif [ "$RELAY" = "queue" ]; then 
                DELIVERIES="0"
                RELAY="$DEFAULT_RELAY"
        else 
                DELIVERIES="20"
                RELAY="$RELAY"
        fi

        if [ -e $QMAIL_CONFFILE ]; then
          grep ':[^:]*' $QMAIL_CONFFILE >$QMAIL_CONFFILE_NEW
        else
	        >$QMAIL_CONFFILE_NEW
        fi
        [ -n "$RELAY" ] && echo "$RELAY" >>$QMAIL_CONFFILE_NEW

        # Preserve the ownership and permissions
        chmod --reference=$QMAIL_CONFFILE $QMAIL_CONFFILE_NEW
        chown --reference=$QMAIL_CONFFILE $QMAIL_CONFFILE_NEW

        mv $QMAIL_CONFFILE_NEW $QMAIL_CONFFILE
        echo $DELIVERIES >"${QMAIL_CONFDIR}concurrencyremote"
        /etc/init.d/qmail restart
    ;;

  *)
      echo "Unrecognised mail server type"
    ;;
esac