/usr/lib/news/bin/nntpsend is in inn 1:1.7.2q-45build2.
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 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 | #! /bin/sh
## $Revision: 1.17 $
## Send news via NNTP by running several innxmit processes in the background.
## Usage:
## nntpsend [-n][-p][-r][-s size][-S][-t timeout][-T limit][host fqdn]...
## -a Always have innxmit rewrite the batchfile
## -d debug mode, run ixxmmits with debug as well
## -D same as -d except innxmits are not debugged
## -p Run innxmit with -p to prune batch files
## -r innxmit, don't requeue on unexpected error code
## -s size limit the =n file to size bytes
## -S send via xreplic protocol (send to a slave site)
## -c disable message-ID checking in streaming mode
## -t timeout innxmit timeout to make connection (def: 180)
## -T limit innxmit connection transmit time limit (def: forever)
## -P portnum port number to use
## -n do not lock for nntpsend, do not sleep between sets
## host fqdn send to host and qualified domain (def: nntpsend.ctl)
## If no "host fqdn" pairs appear on the command line, then ${CTLFILE}
## file is read.
## =()<. @<_PATH_SHELLVARS>@>()=
. /usr/lib/news/innshellvars
PROGNAME=`basename $0`
LOCK=${LOCKS}/LOCK.${PROGNAME}
CTLFILE=/etc/news/${PROGNAME}.ctl
LOG=${MOST_LOGS}/${PROGNAME}.log
## Set defaults.
A_FLAG=
D_FLAG=
NO_LOG_FLAG=
P_FLAG=
R_FLAG=
S_FLAG=
C_FLAG=
TRUNC_SIZE=
T_FLAG=
TIMELIMIT=
PP_FLAG=
NOLOCK=
## Parse JCL.
MORETODO=true
while ${MORETODO} ; do
case X"$1" in
X-a)
A_FLAG="-a"
;;
X-d)
D_FLAG="-d"
NO_LOG_FLAG="true"
;;
X-D)
NO_LOG_FLAG="true"
;;
X-p)
P_FLAG="-p"
;;
X-r)
R_FLAG="-r"
;;
X-S)
S_FLAG="-S"
;;
X-c)
C_FLAG="-c"
;;
X-s)
if [ -z "$2" ] ; then
echo "${PROGNAME}: option requires an argument -- s" 1>&2
exit 1
fi
TRUNC_SIZE="$2"
shift
;;
X-s*)
TRUNC_SIZE="`echo $2 | ${SED} -e 's/-s//'`"
;;
X-t)
if [ -z "$2" ] ; then
echo "${PROGNAME}: option requires an argument -- t" 1>&2
exit 1
fi
T_FLAG="-t$2"
shift
;;
X-t*)
T_FLAG="$1"
;;
X-P)
if [ -z "$2" ] ; then
echo "${PROGNAME}: option requires an argument -- P" 1>&2
exit 1
fi
PP_FLAG="-P$2"
shift
;;
X-P*)
PP_FLAG="$1"
;;
X-T)
if [ -z "$2" ] ; then
echo "${PROGNAME}: option requires an argument -- T" 1>&2
exit 1
fi
TIMELIMIT="-T$2"
shift
;;
X-T*)
TIMELIMIT="$1"
;;
X-n)
NOLOCK=true
;;
X--)
shift
MORETODO=false
;;
X-*)
echo "${PROGNAME}: illegal option -- $1" 1>&2
exit 1
;;
*)
MORETODO=false
;;
esac
${MORETODO} && shift
done
## grab the lock if not -n
NNTPLOCK=${LOCKS}/LOCK.nntpsend
if [ -z "${NOLOCK}" ]; then
shlock -p $$ -f ${NNTPLOCK} || {
# nothing to do
exit 0
}
fi
## Parse arguments; host/fqdn pairs.
INPUT=${TMPDIR}/nntpsend$$
cp /dev/null ${INPUT}
while [ $# -gt 0 ]; do
if [ $# -lt 2 ]; then
echo "${PROGNAME}: Bad host/fqdn pair" 1>&2
rm -f ${NNTPLOCK}
exit 1
fi
echo "$1 $2" >>${INPUT}
shift
shift
done
## If nothing specified on the command line, read the control file.
if [ ! -s ${INPUT} ] ; then
if [ ! -r ${CTLFILE} ]; then
echo "${PROGNAME}: cannot read ${CTLFILE}"
rm -f ${NNTPLOCK}
exit 1
fi
${SED} -e 's/#.*//' -e '/^$/d' -e 's/::\([^:]*\)$/:max:\1/' \
-e 's/:/ /g' <${CTLFILE} >${INPUT}
fi
## Go to where the action is.
if [ ! -d ${BATCH} ]; then
echo "${PROGNAME}: directory ${BATCH} not found" 1>&2
rm -f ${NNTPLOCK}
exit 1
fi
cd ${BATCH}
## Set up log file.
umask 002
if [ -z "${NO_LOG_FLAG}" ]; then
test ! -f ${LOG} && touch ${LOG}
chmod 0660 ${LOG}
exec >>${LOG} 2>&1
fi
PARENTPID=$$
echo "${PROGNAME}: [${PARENTPID}] start"
## Set up environment.
export BATCH PROGNAME PARENTPID INNFLAGS
## Loop over all sites.
cat ${INPUT} | while read SITE HOST SIZE_ARG FLAGS; do
## Parse the input parameters.
if [ -z "${SITE}" -o -z "${HOST}" ] ; then
echo "Ignoring bad line: ${SITE} ${HOST} ${SIZE_ARG} ${FLAGS}" 1>&2
continue
fi
## give up early if we cannot even lock it
##
## NOTE: This lock is not nntpsend's lock but rather the
## lock that the parent shell of innxmit will use.
## Later on the child will take the lock from us.
##
LOCK="${LOCKS}/LOCK.${SITE}"
shlock -p $$ -f "${LOCK}" || continue
## Compute the specific parameters for this site.
test "${SIZE_ARG}" = "max" && SIZE_ARG=
if [ -n "${TRUNC_SIZE}" ]; then
SIZE_ARG="${TRUNC_SIZE}"
fi
## Parse the SIZE_ARG for either MaxSize-TruncSize or TruncSize
case "${SIZE_ARG}" in
*-*) MAXSIZE="`echo ${SIZE_ARG} | ${SED} -e 's/-.*//'`";
SIZE="`echo ${SIZE_ARG} | ${SED} -e 's/^.*-//'`" ;;
*) MAXSIZE="${SIZE_ARG}";
SIZE="${SIZE_ARG}" ;;
esac
D_PARAM=
R_PARAM=
S_PARAM=
S2_PARAM=
C_PARAM=
PP_PARAM=
TIMEOUT_PARAM=
TIMELIMIT_PARAM=
if [ -z "${FLAGS}" ]; then
MORETODO=false
else
MORETODO=true
set -- ${FLAGS}
fi
while ${MORETODO} ; do
case "X$1" in
X-a)
;;
X-d)
D_PARAM="-d"
;;
X-c)
C_PARAM="-c"
;;
X-p)
P_PARAM="-p"
;;
X-r)
R_PARAM="-r"
;;
X-S)
S_PARAM="-S"
;;
X-s)
S2_PARAM="-s"
;;
X-t)
if [ -z "$2" ] ; then
echo "${PROGNAME}: option requires an argument -- t" 1>&2
rm -f "${NNTPLOCK}" "${LOCK}"
exit 1
fi
TIMEOUT_PARAM="-t$2"
shift
;;
X-t*)
TIMEOUT_PARAM="$1"
;;
X-P)
if [ -z "$2" ] ; then
echo "${PROGNAME}: option requires an argument -- P" 1>&2
rm -f "${NNTPLOCK}" "${LOCK}"
exit 1
fi
PP_PARAM="-P$2"
shift
;;
X-P*)
PP_PARAM="$1"
;;
X-T)
if [ -z "$2" ] ; then
echo "${PROGNAME}: option requires an argument -- T" 1>&2
rm -f "${NNTPLOCK}" "${LOCK}"
exit 1
fi
TIMELIMIT_PARAM="-T$2"
shift
;;
X-T*)
TIMELIMIT_PARAM="$1"
;;
*)
MORETODO=false
;;
esac
${MORETODO} && shift
done
if [ -z "${SIZE}" -o -n "${A_FLAG}" ]; then
# rewrite batch file if we do not have a size limit
INNFLAGS="-a"
else
# we have a size limit, let shrinkfile rewrite the file
INNFLAGS=
fi
if [ -n "${D_FLAG}" ]; then
INNFLAGS="${INNFLAGS} ${D_FLAG}"
else
test -n "${D_PARAM}" && INNFLAGS="${INNFLAGS} ${D_PARAM}"
fi
if [ -n "${C_FLAG}" ]; then
INNFLAGS="${INNFLAGS} ${C_FLAG}"
else
test -n "${C_PARAM}" && INNFLAGS="${INNFLAGS} ${C_PARAM}"
fi
if [ -n "${P_FLAG}" ]; then
INNFLAGS="${INNFLAGS} ${P_FLAG}"
else
test -n "${P_PARAM}" && INNFLAGS="${INNFLAGS} ${P_PARAM}"
fi
if [ -n "${R_FLAG}" ]; then
INNFLAGS="${INNFLAGS} ${R_FLAG}"
else
test -n "${R_PARAM}" && INNFLAGS="${INNFLAGS} ${R_PARAM}"
fi
if [ -n "${S_FLAG}" ]; then
INNFLAGS="${INNFLAGS} ${S_FLAG}"
else
test -n "${S_PARAM}" && INNFLAGS="${INNFLAGS} ${S_PARAM}"
fi
if [ -n "${S2_FLAG}" ]; then
INNFLAGS="${INNFLAGS} ${S2_FLAG}"
else
test -n "${S2_PARAM}" && INNFLAGS="${INNFLAGS} ${S2_PARAM}"
fi
if [ -n "${T_FLAG}" ]; then
INNFLAGS="${INNFLAGS} ${T_FLAG}"
else
test -n "${TIMEOUT_PARAM}" && INNFLAGS="${INNFLAGS} ${TIMEOUT_PARAM}"
fi
if [ -n "${PP_FLAG}" ]; then
INNFLAGS="${INNFLAGS} ${PP_FLAG}"
else
test -n "${PP_PARAM}" && INNFLAGS="${INNFLAGS} ${PP_PARAM}"
fi
if [ -n "${TIMELIMIT}" ]; then
INNFLAGS="${INNFLAGS} ${TIMELIMIT}"
else
test -n "${TIMELIMIT_PARAM}" \
&& INNFLAGS="${INNFLAGS} ${TIMELIMIT_PARAM}"
fi
## Flush the buffers for the site now, rather than in the child.
## This helps pace the number of ctlinnd commands because the
## nntpsend process does not proceed until the site flush has
## been completed.
##
# carry old unfinished work over to this task
BATCHFILE="${SITE}=n"
if [ -f "${SITE}.work" ] ; then
sort "${SITE}.work" >>"${BATCHFILE}"
rm -f "${SITE}.work"
fi
# form BATCHFILE to hold the work for this site
if [ -f "${SITE}" ]; then
mv "${SITE}" "${SITE}.work"
if ctlinnd -s -t30 flush ${SITE} ; then
sort ${SITE}.work >>"${BATCHFILE}"
rm -f ${SITE}.work
else
# flush failed, continue if we have any batchfile to work on
echo "${PROGNAME}: bad flush for ${HOST} via ${SITE}"
if [ -f "${BATCHFILE}" ]; then
echo "${PROGNAME}: trying ${HOST} via ${SITE} anyway"
else
echo "${PROGNAME}: skipping ${HOST} via ${SITE}"
rm -f ${LOCK}
continue
fi
fi
else
# nothing to work on, so flush and move on
ctlinnd -s -t30 flush ${SITE}
echo "${PROGNAME}: file ${BATCH}/${SITE} for ${HOST} not found"
if [ -f "${BATCHFILE}" ]; then
echo "${PROGNAME}: trying ${HOST} via ${SITE} anyway"
else
echo "${PROGNAME}: skipping ${HOST} via ${SITE}"
rm -f ${LOCK}
continue
fi
fi
## Start sending this site in the background.
export MAXSIZE SITE HOST PROGNAME PARENTPID SIZE TMPDIR LOCK BATCHFILE
sh -c '
# grab the lock from the parent
#
# This is safe because only the parent will have locked
# the site. We break the lock and reclaim it.
rm -f ${LOCK}
trap "rm -f ${LOCK} ; exit 1" 1 2 3 15
shlock -p $$ -f ${LOCK} || {
WHY="`cat ${LOCK}`"
echo "${PROGNAME}: [${PARENTPID}:$$] ${SITE} locked ${WHY} `date`"
exit
}
# process the site BATCHFILE
if [ -f "${BATCHFILE}" ]; then
test -n "${SIZE}" && shrinkfile -m${MAXSIZE} -s${SIZE} -v ${BATCHFILE}
if [ -s ${BATCHFILE} ] ; then
echo "${PROGNAME}: [${PARENTPID}:$$] begin ${SITE} `date`"
echo "${PROGNAME}: [${PARENTPID}:$$] innxmit ${INNFLAGS} ${HOST} ..."
eval innxmit ${INNFLAGS} ${HOST} ${BATCH}/${BATCHFILE}
echo "${PROGNAME}: [${PARENTPID}:$$] end ${SITE} `date`"
else
rm -f ${BATCHFILE}
fi
else
echo "${PROGNAME}: file ${BATCH}/${BATCHFILE} for ${HOST} not found"
fi
rm -f ${LOCK}
' &
done
## release the nntpsend lock and clean up before we wait on child processes
if [ -z "${NOLOCK}" ]; then
rm -f ${NNTPLOCK}
fi
rm -f ${INPUT}
## wait for child processes to finish
wait
## all done
echo "${PROGNAME}: [${PARENTPID}] stop"
exit 0
|