This file is indexed.

/usr/bin/faxrunq is in mgetty-fax 1.1.36-1.6.

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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
#!/bin/bash
#
# faxrunq
#
# look for outgoing fax jobs, send them via sendfax, if succesful, remove
# them from the outgoing queue (and send a mail to the originator of the
# job)
#
# For details about configuration etc. see "man faxrunq".
#
# For heavy-duty usage (multiple lines, many 100 faxes per day), check
# out faxrunqd.
#
# RCS: $Id: faxrunq.in,v 4.20 2006/04/09 16:48:21 gert Exp $ Copyright (C) 1994 Gert Doering
#
# $Log: faxrunq.in,v $
# Revision 4.20  2006/04/09 16:48:21  gert
# fix quoting bug in `date` command (for acct.log) - Klaus Weglehner
#
# Revision 4.19  2006/01/19 14:44:23  gert
# new acct.log format (see faxrunqd: 1.70->1.71 for details)
#
# Revision 4.18  2005/02/27 11:57:31  gert
# get "trap off" handling from mksed/sedscript
#
# Revision 4.17  2005/01/03 16:46:28  gert
# workaround for needless bash3 incompatibility ("trap 0 1 2 3" doesn't work
# anymore, need to use "trap - 0 1 2 3", which doesn't work on old /bin/sh)
#
# Revision 4.16  2004/11/24 13:30:38  gert
# implement update-call-program (status update callback)
#
# Revision 4.15  2002/11/23 15:35:46  gert
# test for existance of config file (not for readability) and thus produce
# error message if it exists but is not readable (mode 600/wrong owner)
#
# Revision 4.14  2002/11/23 15:13:51  gert
# revert 4.10->4.11 change: faxqueue_done is back in fax queue dir (which
# is now owned by "fax" and no longer world-writeable, while /var/run is
# likely not writeable by "fax")
#
#

FAX_SPOOL=/var/spool/fax
FAX_SPOOL_OUT=/var/spool/fax/outgoing
FAX_SENDER="/usr/sbin/sendfax"
FAX_ACCT=$FAX_SPOOL/acct.log
LAST_RUN=/var/spool/fax/outgoing/faxqueue_done

MAILER="/usr/sbin/sendmail"

CONF_FILE="/etc/mgetty/faxrunq.config"

#
# echo program that will accept escapes (bash: "echo -e", sun: /usr/5bin/echo)
#
echo="echo -e"

#
# awk program that is not stone-old-brain-dead (that is, not oawk...)
#
AWK=awk

#
# make sure we'll find "newslock" and other good stuff when run from "cron"...
#
PATH=/usr/bin:$PATH

#
# set defaults, then process configuration file (if it exists)
#
do_mail_s="TRUE"
do_mail_f="TRUE"
exec_pgm_s=""
exec_pgm_f=""
exec_pgm_u=""
max_fail_costly=5
max_fail_total=10
delete_sent=""

if [ -f $CONF_FILE ] ; then
    eval `$AWK '/^ *#/ { next }
	     $1 == "success-send-mail" \
		{ printf "do_mail_s=\"%s\";", ($2 ~ /^[yYjJtT1]/)? "T":"" }
	     $1 == "failure-send-mail" \
		{ printf "do_mail_f=\"%s\";", ($2 ~ /^[yYjJtT1]/)? "T":"" }
	     $1 == "success-call-program" \
		{ printf "exec_pgm_s=\"%s\";", $2 }
	     $1 == "failure-call-program" \
		{ printf "exec_pgm_f=\"%s\";", $2 }
	     $1 == "update-call-program" \
		{ printf "exec_pgm_u=\"%s\";", $2 }
	     $1 == "maxfail-costly" && $2 ~ /^[0-9]/ \
		{ printf "max_fail_costly=\"%s\";", $2 }
	     $1 == "maxfail-total" && $2 ~ /^[0-9]/ \
		{ printf "max_fail_total=\"%s\";", $2 }
	     $1 == "delete-sent-jobs" \
		{ printf "delete_sent=\"%s\";", ($2 ~ /^[yYjJtT1]/)? "T":"" }
	     $1 == "acct-log" \
		{ printf "FAX_ACCT=\"%s\";", $2 }
	     END { printf "\n" }' - <$CONF_FILE`
fi

#
# command line arguments
#
usage="usage: $0 [-s] [-q]"

while :
do
    case "$1" in
# sleep 30 seconds after each job, give modem time to settle
	-s) sleepwait=30;shift;;
# quiet operation
	-q) exec >/dev/null ; shift ;;
# invalid option
	-*) $echo "$0: unknown option: $1" >&2
            $echo "$usage" >&2
	    exit 1
	    ;;
	*) break
    esac
done

if [ $# -gt 0 ]
then
    $echo "$usage" >&2
    exit 1
fi

#
# go to fax spool directory, process all JOB files
#

cd $FAX_SPOOL_OUT || exit 1

# stop flag?
if [ -r stop ] ; then
    $echo "faxrunq: $FAX_SPOOL_OUT/stop exists, not running queue."
    exit 0
fi

status="0"
jobs=`ls */JOB 2>/dev/null`
for job in $jobs
do
    if [ $status -eq 4 -a -n "$sleepwait" ]
    then
#     old stat :no connect; modem allows next redial in $sleepwait secs
      $echo "sleeping $sleepwait seconds"
      sleep $sleepwait
    fi
    cd $FAX_SPOOL_OUT/`dirname $job`
    $echo "processing $job..."
#
#   lock JOB file (by 'link(2)'ing it to JOB.locked)
#   'newslock' is a small C program that just calls link(argv[1], argv[2])
#
    # make sure Lock will be removed in case the shell aborts
    trap "rm -f JOB.locked 2>/dev/null" 0
    trap "rm -f JOB.locked 2>/dev/null ; exit 20" 1 2 3 15

    newslock JOB JOB.locked 2>/dev/null
    if [ $? -ne 0 ]
    then
	$echo "already locked"
	trap - 0 1 2 3 15
	continue
    fi
#
# get user to notify (->$MAIL_TO), phone number (->$PHONE) and
# earliest send time (->$TIME)
#
# read job using 'tr', remove all quote characters, dollar, and backslash
#
    eval `tr -d '\042\047\140\134\044\073' <JOB | \
	  $AWK 'BEGIN { user=""; mail=""; verbto=""; time=""; re=""; ah=""; }
		$1=="user" { user=$2 }
		$1=="mail" { mail=substr( $0, 6) }
		$1=="phone" { printf "PHONE=%s;", $2 }
		$1=="time" { time=$2 }
		$1=="verbose_to" { verbto=substr($0,12) }
		$1=="subject" { re=substr($0,9) }
		$1=="acct_handle" { ah=substr($0,13) }
		END { if ( mail != "" ) printf "MAIL_TO=\"%s\";", mail
				   else printf "MAIL_TO=\"%s\";", user
		      printf "TIME=\"%s\";", time
		      printf "VERBOSE_TO=\"%s\";", verbto
		      printf "RE=\"%s\"; AH=\"%s\"", re, ah }' - `

#
# check whether send time is reached
#
    if [ ! -z "$TIME" ]
    then
	if [ `date "+%H""%M"` -lt $TIME ]
	then
	    $echo "...send time not reached, postponing job"
	    rm JOB.locked
	    continue
	fi
    fi

#
# construct command line to execute
# read job using 'tr', remove all quote characters, dollar, and backslash
#
    command=`tr -d '\042\047\140\134\044\073' <JOB | \
             $AWK 'BEGIN { phone="-"; flags=""; pages="" }
		  $1=="phone" { phone=$2 }
		  $1=="header"     { flags=flags" -h "$2 }
		  $1=="poll"       { flags=flags" -p" }
		  $1=="normal_res" { flags=flags" -n" }
		  $1=="acct_handle" { flags=flags" -A \""substr($0,13)"\"" }
		  $1=="pages" { for( i=2; i<=NF; i++) pages=pages$i" " }
		  END { printf "'"$FAX_SENDER"' -v%s %s %s", \
			       flags, phone, pages }' -`

#
# execute faxsend command
#
    $echo "$command"
    eval $command
#
# handle return values
#
    status=$?
    $echo "command exited with status $status"

#
# string to include in subject line
#
    if [ -z "$VERBOSE_TO" ]
    then
        subject="your fax to $PHONE"
    else
        subject="your fax to $VERBOSE_TO ($PHONE)"
    fi

#
# evaluate return codes, if success, remove fax job from queue
#
    if [ $status -eq 0 ]
    then
	# transmission successful
	$echo "Status "`date`" successfully sent" >>JOB

	# update accounting log
	$echo `dirname $job`"|$MAIL_TO|| $PHONE |0|"`date '+%Y%m%d %H:%M:%S'`"|$AH|success" >>$FAX_ACCT

	# send mail, if requested
	if [ -n "$do_mail_s" ] ; then
	    $echo "    send mail to $MAIL_TO..."
	    ( 
	      trap - 0			# catch BASH bug
	      $echo "To: $MAIL_TO"
	      $echo "Subject: OK: $subject"
	      $echo "From: root (Fax Subsystem)\n"
	      $echo "Your fax has been sent successfully at: \c"
	      date
	      test -z "$RE" || \
		$echo "(Subject was: $RE)\n"
	      $echo "\n\nJob / Log file:"
	      cat JOB
	      tries=`grep Status JOB | sed -e '1d' | wc -l`
	      $echo "\nSending succeeded after" $tries "unsuccessful tries."
	    ) |
	    $MAILER "$MAIL_TO"
	fi

	# call "success" handler program (if requested)
	if [ -n "$exec_pgm_s" ] ; then
	    $echo "    calling program $exec_pgm_s..."
	    $exec_pgm_s $FAX_SPOOL_OUT/$job 0
	fi

	# job is done -> remove it from the queue
	mv JOB JOB.done

	# completely remove JOB directory (only if requested)
	# instead of this, the job could be archived by "$exec_pgm_s" or so
	if [ -n "$delete_sent" ] ; then
	    $echo "    deleting job files + directory..."
	    cd $FAX_SPOOL_OUT
	    rm -rf `dirname $job`
	fi

    else 
	# error codes < 10: error before starting to transmit (try again)
	# error codes >=10: error while transmitting, considered fatal
	comment="failed"
	why="unknown" ; case $status in
	    1) why="errors in command line" ;;
	    2) why="cannot open fax device (locked?)" ;;
	    3) why="modem initialization error" ;;
	    4) why="dial failed - BUSY" ;;
	    5) why="dial failed - NO DIALTONE" ;;
	    10) why="dial failed - NO CARRIER" ; comment="FATAL FAILURE";;
	    11) why="protocol failure, waiting for XON" ; comment="FATAL FAILURE";;
	    12) why="protocol failure sending page" ; comment="FATAL FAILURE";;
	    15) why="sendfax killed by signal(?)" ; comment="FATAL FAILURE";;
	esac
	$echo "Status "`date`" $comment, exit($status): $why" >>JOB

	# if failed <max_fail_costly> or <max_fail_total> times, suspend job
	suspend="";
	if [ `grep "FATAL FAILURE" JOB | wc -l` -ge $max_fail_costly ]
	then
	    $echo "Status "`date`" job suspended: too many FATAL errors" >>JOB
	    suspend=true
	elif [ `grep "Status " JOB | wc -l` -ge $max_fail_total ]
	then
	    $echo "Status "`date`" job suspended: too many tries" >>JOB
	    suspend=true
	fi

	if [ -n "$suspend" ]
	then
	    # update accounting log (final)
	    $echo `dirname $job`"|$MAIL_TO|| $PHONE |$status|"`date '+%Y%m%d %H:%M:%S'`"|$AH|fail $status: $why" >>$FAX_ACCT

	    # send mail, if requested
	    if [ -n "$do_mail_f" ] ; then
		echo "    send mail to $MAIL_TO..."
		( 
		  trap - 0			# catch BASH bug
		  $echo "To: $MAIL_TO"
		  $echo "Subject: FAIL: $subject failed"
		  $echo "From: root (Fax Subsystem)\n"
		  $echo "It was not possible to send your fax to $PHONE!\n"
		  test -z "$RE" || \
		    $echo "(Subject was: $RE)\n"
		  $echo "The fax job is suspended, you can requeue it with the command:"
		  $echo "    cd $FAX_SPOOL_OUT/"`dirname $job`
		  $echo "    mv JOB.suspended JOB\n"
		  $echo "log file follows:"
		  cat JOB ) |
		$MAILER "$MAIL_TO"
	    fi

	    # call error handler, if requested
	    if [ -n "$exec_pgm_f" ] ; then
		$echo "    calling program $exec_pgm_f ($status)..."
		$exec_pgm_f $FAX_SPOOL_OUT/$job $status
	    fi

	    #
	    # suspend job (but do not delete it)
	    #
	    mv JOB JOB.suspended 2>/dev/null
	else					# do not delete job yet...
	    # update accounting log (intermediate)
	    $echo `dirname $job`"|$MAIL_TO|| $PHONE |-$status|"`date '+%Y%m%d %H:%M:%S'`"|$AH|fail $status: $why" >>$FAX_ACCT

	    # call update handler, if requested
	    if [ -n "$exec_pgm_u" ] ; then
		$echo "    calling program $exec_pgm_u (-$status)..."
		$exec_pgm_u $FAX_SPOOL_OUT/$job -$status
	    fi
	fi
    fi
#
# unlock job (even if the JOB has been renamed to JOB.suspended or 
#             JOB.done, the link to JOB.locked still exists!)
#
    rm -f JOB.locked
done

trap - 0 1 2 3 15

#
# touch the time stamp, to make faxspool happy
#
rm -f $LAST_RUN
echo "`date` $0" >$LAST_RUN
chmod 644 $LAST_RUN