This file is indexed.

/usr/share/cron-apt/functions is in cron-apt 0.9.2.

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

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
# DocumentId: $Id: cron-apt 2438 2007-08-02 15:25:04Z ola $
#
# Copyright (C) 2002-2011 Ola Lundqvist <ola@inguza.com>
# Copyright (C) 2009      Edward Malone <edward.malone88@gmail.com>
# Copyright (C)      2007 Bob Proulx <bob@proulx.com>
# Copyright (C) 2004,2005,2007 Marc Haber <mh+debian-bugs@zugschlus.de>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301 USA.
#
# Changes:
#       2011-11-05 Ola Lundqvist <ola@inguza.com>
#               No warning message will be printed to tell that there is no
#               mail command available when MAILON is set to 'never' or empty
#               string.
#       2009-05-12 Ola Lundqvist <ola@inguza.com>
#               Add support for mail headers using suggested code from
#               Edward Malone <edward.malone88@gmail.com>
#       2007-08-09 Ola Lundqvist <ola@inguza.com>
#               Avoid overflow in directory size calculation when using dash.
#               Also remove directory if the size is too low.
#       2007-08-02 Ola Lundqvist <ola@inguza.com>
#		Broke out the common functions from the cron-apt command so it
#               can be tested separately.
#               The changes done in the project has been analyzed to give
#               correct copyright statements in this file.
#


# Check the tmpdir size and exit if the space is too small.
checktmpsize() {
    # Sector size
    SSIZE=$(stat --file-system --format=%S $TMPDIR)
    # Number of free sectors
    FSCOUNT=$(stat --file-system --format=%a $TMPDIR)
    # Check to avoid overflow in calculations when using dash 2^(32-1-6)
    # The number size above is got from 32768/512=2^6
    if [ "$FSCOUNT" -lt 33554432 ] ; then
	if [ "$(($SSIZE / 512 * $FSCOUNT / 2))" -lt "$MINTMPDIRSIZE" ]; then
	    echo >&2 "Error: Not enough free space in $TMPDIR."
	    rmdir --ignore-fail-on-non-empty $TMPDIR
	    exit 1
        fi
    fi
}

# Send the mail to the system administrator. Will only be sent if there is
# something to send. No arguments needed.
onexit() {
    if [ -f "$INITLOG" ] ; then
	rm -f "$INITLOG"
    fi
    if [ -f "$TEMP" ] ; then
	rm -f "$TEMP"
    fi
    if [ -f "$ACTIONLOG" ] ; then
	rm -f "$ACTIONLOG"
    fi
    if [ -f "$ACTIONSYSLOG" ] ; then
	rm -f "$ACTIONSYSLOG"
    fi
    if [ -f "$ACTIONMAIL" ] ; then
	rm -f "$ACTIONMAIL"
    fi
    if [ -f "$ACTIONERROR" ] ; then
	rm -f "$ACTIONERROR"
    fi
    if [ -f "$RUNLOG" ] ; then
	rm -f "$RUNLOG"
    fi
    if [ -f "$ERROR" ] ; then
	rm -f "$ERROR"
    fi
    if [ -f "$RUNSYSLOG" ] ; then
	rm -f "$RUNSYSLOG"
    fi
    if [ -f "$RUNERROR" ] ; then
	rm -f "$RUNERROR"
    fi
    if [ -f "$RUNMAIL" ] ; then
	rm -f "$RUNMAIL"
    fi
    if [ -f "$MAIL" ] && [ "$MAILON" != "never" ] && [ -n "$MAILON" ] ; then
	if command -v mail >/dev/null; then
	    if [ -z "$HOSTNAME" ]; then
		HOSTNAME="$(uname -n)"
	    fi
	    SUBJECT="CRON-APT completed on $HOSTNAME [$CONFIG]"
	    if [ -f "$ERROR" ] ; then
		SUBJECT="CRON-APT error on $HOSTNAME [$CONFIG]"
	    fi
	    # Support for XHEADERS
	    IFSOLD=$IFS
	    IFS=`printf '\t'`
            i=1
	    eval "VAL=\${XHEADER$i}"
	    while [ ! -z $VAL ] ; do
		XHEADERS="$XHEADERS  <TAB> -a  <TAB>   $VAL"
		i=$(( $i + 1 ))
		eval "VAL=\${XHEADER$i}"
	    done
	    #
            mail $XHEADERS -s "$SUBJECT" "$MAILTO" < "$MAIL"
	    IFS=$IFSOLD
	else
	    echo >&2 "cron-apt was configured to send e-mail, but no mail binary found in path."
	    echo >&2 "Either set MAILON=never in configuration or install the mailx package."
	fi
	rm -f "$MAIL"
    fi
    if [ -f "$DIFF" ] ; then
	rm -f "$DIFF"
    fi
    if [ -d "$TMPDIR" ] ; then
	rmdir "$TMPDIR"
    fi
    if [ -x "/usr/bin/dotlockfile" ]; then
        dotlockfile -u $LOCKFILE
    fi
}

# Do the actual msg transfer. This reduce some duplications.
# 1 CATFILE
# 2 TOFILE (if = syslog log to syslog)
# 3 TOSTDOUT ()
tomsg() {
    TCAT="$1"
    TFILE="$2"
    TSTD="$3"
    if [ -n "$TCAT" ] && [ -r "$TCAT" ] ; then
	if [ -n "$TSTD" ] ; then
	    cat "$TCAT"
	fi
	if [ "$TFILE" != "syslog" ] ; then
	    cat "$TCAT" >> "$TFILE"
	else
	    logger -p user.notice -t cron-apt -f "$TCAT"
	fi
    fi
}

# Create file with RUN information. Line data should be added later.
# Arguments:
# 1: File to create (if = "syslog" we should log to syslog instead)
# 2: File to cat e.g. $TEMP
# 3: Optional file to cat (like errormsg.d/action or so)
# 4: Optional runinformation file (will be removed)
# 5: Optional actioninformation file (will be removed)
# 6: If not empty data will be printed to stdout too.
createdivinfo() {
    FILE="$1"
    CAT="$2"
    OPTCAT="$3"
    OPTRUNCAT="$4"
    OPTACTIONCAT="$5"
    TMPSTDOUT="$6"
    if [ "$FILE" != "syslog" ] ; then
	touch "$FILE"
    fi
    if [ -n "$OPTCAT" ] && [ -f "$OPTCAT" ] ; then
	tomsg "$OPTCAT" "$FILE" "$TMPSTDOUT"
    fi
    if [ -n "$OPTRUNCAT" ] && [ -f "$OPTRUNCAT" ] ; then
	tomsg "$OPTRUNCAT" "$FILE" "$TMPSTDOUT"
	rm -f "$OPTRUNCAT"
    fi
    if [ -n "$OPTACTIONCAT" ] && [ -f "$OPTACTIONCAT" ] ; then
	tomsg "$OPTACTIONCAT" "$FILE" "$TMPSTDOUT"
	rm -f "$OPTACTIONCAT"
    fi
    tomsg "$CAT" "$FILE" "$TMPSTDOUT"
}

# ACTIONF as first argument
createmailinfo() {
    touch "$MAIL"
    if [ -n "$MAILON" ] && [ -f "$MAILONMSGSDIR/$MAILON" ] ; then
	cat "$MAILONMSGSDIR/$MAILON" >> "$MAIL"
    fi
    createdivinfo "$MAIL" "$TEMP" "$MAILMSGDIR/$1" "$RUNMAIL" "$ACTIONMAIL"
}

# ACTIONF as first argument
createsysloginfo() {
    if [ -n "$SYSLOGON" ] && [ -f "$SYSLOGONMSGSDIR/$SYSLOGON" ] ; then
	logger -p user.notice -t cron-apt -f "$SYSLOGONMSGSDIR/$SYSLOGON" 
    fi
    createdivinfo "syslog" "$TEMP" "$SYSLOGMSGDIR/$1" "$RUNSYSLOG" "$ACTIONSYSLOG"
}

# ACTIONF as first argument
createloginfo() {
    createdivinfo "$LOG" "$TEMP" "$LOGMSGDIR/$1" "$RUNLOG" "$ACTIONLOG" "$STDOUT"
}

# ACTIONF as first argument
createerrorinfo() {
    createdivinfo "$ERROR" "$TEMP" "$ERRORMSGDIR/$1" "$RUNERROR" "$ACTIONERROR"
}

# run-parts emulation, stolen from Branden's /etc/X11/Xsession
run_parts () {
	# reset LC_COLLATE
	unset LANG LC_COLLATE LC_ALL

	if [ -z "$1" ]; then
		echo >&2 "$0: internal run_parts called without an argument"
	fi
	if [ ! -d "$1" ]; then
		echo >&2 "$0: internal run_parts called, but $1 does not exist or is not a directory."
	fi
	for F in $(ls $1); do
		if expr "$F" : '[[:alnum:]_-]\+$' > /dev/null 2>&1; then
			if [ -f "$1/$F" ] ; then
				echo "$1/$F"
			fi
		fi
	done;
}

general_varmove() {
    PREFIX=$1
    STORE=$2
    SIFS=$IFS
    LIST=$(set | grep "^[a-zA-Z][a-zA-Z0-9_]*_$PREFIX=" | sed -e "s|=.*||;")
    for PVAR in $LIST ; do
        # Var name
        VVAR=$(echo $PVAR | sed -e "s|_$PREFIX$||g;")
        if [ -n "$STORE" ] ; then
            # Stored var name
            eval "SVAR=${VVAR}_$STORE"
            # Store the value
            eval "$SVAR=\$$VVAR"
        fi
        # Set variable to here variable
	eval "$VVAR=\$$PVAR"
        eval "unset $PVAR"
    done
}

herevariables_store() {
    general_varmove HERE STORED
}

herevariables_restore() {
    general_varmove STORED ""
}