Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

*------------------*

* Version    2.2.a *
*------------------*
 --------------------------------------------
 02/07/06 orc@india.pell.portland.or.us 1.32
 actions.c:
   Include stdlib for malloc
 fe.c:
   If run as root, attempt to setuid to someone else (either
   the caller or -1, if that's not possible) because otherwise
   there are a large number of really spiffy security holes
   that could be driven through.
 args.c:
   Check that argv[1] exists before trying to reference it
 configure.inc:
   Add support for generic --use-X and --use-X={yes|no}
   options, which create the environment variable USE_X
 configure.sh:
   Add --use-fifo option to enable or disable the
   ghostscript fifo
 --------------------------------------------
 02/07/09 root@omni.pell.portland.or.us 1.33
 configure.inc:
   Change ``grep -qs'' to ``grep -s >/dev/null''
   to support greps that don't have the -s flag
 --------------------------------------------
 02/07/09 orc@downbelow.pell.portland.or.us 1.34
 magicfilter.h.in:
   Check for the existance of malloc.h or sys/malloc.h;
   if they're found, #include them in magicfiler.h
 configure.sh:
   Check for the existance of malloc.h or sys/malloc.h;
   if they're found, #include them in magicfilter.h
 --------------------------------------------
 02/07/10 orc@downbelow.pell.portland.or.us 1.35
 configure.sh:
   Remove --path support, since that's now handled in
   configure.inc by --with-path
 configure.inc:
   Set AC_PATH to $WITH_PATH (--with-path) or $PATH
   if that's not defined.
   Have acLookFor only succeed when it finds a _file_
   that matches the name in the path.
 INSTALL:
   Describe the change of --path to --with-path
 --------------------------------------------
 02/07/10 orc@downbelow.pell.portland.or.us 1.36
 config:
   Add the autocheckout flag
 --------------------------------------------
 02/07/10 root@omni.pell.portland.or.us 1.37
 INSTALL:
   Explain why you'd want to use --use-local-magic
 --------------------------------------------
 02/07/11 root@australia.pell.portland.or.us 1.38
 Cleanup unprototyped functions and unused variables.
 --------------------------------------------
 02/07/11 orc@downbelow.pell.portland.or.us 1.39
 Add gratuitous { }'s to shut gcc -Wall up.
 --------------------------------------------
 02/07/11 root@australia.pell.portland.or.us 1.40
 Hunting SGI features!
 --------------------------------------------
 02/07/11 root@australia.pell.portland.or.us 1.41
 Merge configure.inc from the configure package.
 --------------------------------------------
 02/07/11 root@australia.pell.portland.or.us 1.42
 configure.inc:
   Merge configure.inc from the configure package
 --------------------------------------------
 02/07/12 root@egypt.pell.portland.or.us 1.43
 Redo @INSTALL_MAGIC@ to be either $PROG_INSTALL or ``:'' -- don't
 use it as a prefix to @INSTALL_DATA@ anymore.
 --------------------------------------------
 02/07/12 orc@downbelow.pell.portland.or.us 1.44
 VERSION:
   Bump up to 2.2 for the new works-on-Irix-for-me release
 --------------------------------------------
  • Loading branch information...
commit e5f9bc7ea498130006702898cced4b7c89e6bb5e 1 parent e0bcc1f
David Parsons authored
View
22 INSTALL
@@ -22,16 +22,17 @@
will look for it here as well.
--filterdir=DIR where to put printer filters ($prefix/sbin/printers)
- --path=PATH look for conversion programs in PATH
- (/sbin:/usr/sbin:/bin:/usr/bin:\
- /usr/local/bin:/usr/X11R6/bin)
+ --with-path=PATH look for conversion programs in PATH ($PATH)
If configure can't find a conversion program, it will build
magicfilter without support for that particular conversion.
- The default path is set up to (hopefully) get all the normal
- places for filters, but if you're on a bizarre system like
- Solaris, you may need to customise it to include /opt/LLOCL/bin
- and so on.
+
+ Normally, magicfilter uses your $PATH to (hopefully) get all
+ the normal places for filters, but you may need to customize
+ it if you're on a system that places filters in odd locations.
+
+ NOTE: This used to be --path in previous versions
+ of Magicfilter.
--use-local-magic install a private magic file
@@ -40,7 +41,12 @@
file does not appear to be modern enough (experimentally
determined by seeing if it recognises a H-P pjl file),
configure.sh will configure magicfilter to use a local
- magic file.
+ magic file. But there are cases where file(1) has been
+ modified so that it doesn't just use /etc/magic, but instead
+ has its magic files scattered randomly around, and thus
+ configure.sh will report that /etc/magic works when it
+ doesn't. If you use --use-local-magic, magicfilter won't
+ even bother to try and use the system /etc/magic.
--with-papersize=size
View
2  Makefile.in
@@ -44,7 +44,7 @@ commoninstall: textonly
@INSTALL@ -d $(prefix)/@mandir@/man8
@INSTALL@ -d $(prefix)/@mandir@/man5
@INSTALL@ -d $(prefix)/@filterdir@
- @INSTALL_MAGIC@@INSTALL_DATA@ -m 444 file/magic $(prefix)/@MAGIC@
+ @INSTALL_MAGIC@ -m 444 file/magic $(prefix)/@MAGIC@
@INSTALL_PROGRAM@ -m 511 textonly $(prefix)/@filterdir@
install: @DO_WHAT@
View
2  VERSION
@@ -1 +1 @@
-2.1.b
+2.2.a
View
27 actions.c
@@ -34,6 +34,7 @@
*/
#include <unistd.h>
+#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
@@ -206,19 +207,19 @@ pipe_it(char *blk, int size, struct rule *r)
pid_t spawn;
int status;
char *file = 0;
- pid_t sysproc;
if (pipe(io) == -1) {
perror("pipe::pipe");
exit(1);
}
- switch (spawn = fork()) {
- case -1:
+ spawn = fork();
+
+ if (spawn == -1) {
perror("pipe::fork");
exit(1);
-
- default:
+ }
+ else if (spawn != 0) {
/* parent -- run xyzzy against the output of the filter, then exit
*/
dup2(io[0], 0);
@@ -229,8 +230,8 @@ pipe_it(char *blk, int size, struct rule *r)
else
xyzzy();
exit(0); /* be paranoid */
-
- case 0:
+ }
+ else {
if (r->action == FPIPE) {
/* fpipe spools stdin to a file before processing, so it's easy
*/
@@ -258,15 +259,18 @@ pipe_it(char *blk, int size, struct rule *r)
* must refork again so we can shovel what we got plus
* what we didn't get into the filter.
*/
+ pid_t sysproc;
+
if (pipe(sio) == -1) {
perror("pipe::pipe");
exit(1);
}
- switch (sysproc = fork()) {
- case -1:
+
+ if ( (sysproc = fork()) == -1) {
perror("pipe::fork");
exit(1);
- case 0:
+ }
+ else if (sysproc == 0) {
/* child -- execvp() the process
*/
close(sio[1]);
@@ -277,7 +281,8 @@ pipe_it(char *blk, int size, struct rule *r)
execvp(r->argv[0], r->argv);
perror(r->argv[0]);
exit(1);
- default:
+ }
+ else {
/* parent -- copy blk + stdin -> stdout
*/
close(io[0]);
View
10 args.c
@@ -29,6 +29,8 @@
#include <sys/types.h>
#include <sys/stat.h>
+#include <stdlib.h>
+#include <unistd.h>
#include <fcntl.h>
#include <string.h>
@@ -61,6 +63,8 @@ struct x_option opts[] = {
} ;
#define NROPTS (sizeof opts/sizeof opts[0])
+extern void showopts(FILE*, int, struct x_option*);
+
#define GETOPT(argc,argv) x_getopt(argc, argv, NROPTS, opts)
#define OPTIND x_optind
#define OPTARG x_optarg
@@ -86,10 +90,6 @@ SET(char *x,char *y)
}
#endif
-#ifdef HAVE_BASENAME
-const char *basename(char*);
-#endif
-
int
getoptionsandscript(int argc, char **argv)
{
@@ -101,7 +101,7 @@ getoptionsandscript(int argc, char **argv)
* figured out
*/
- if (argv[1][0] != '-') { /* #! hack works. Goodie */
+ if (argv[1] && (argv[1][0] != '-')) { /* #! hack works. Goodie */
script = argv[1];
++argv, --argc;
}
View
3  basis/options.c
@@ -120,7 +120,7 @@ x_getopt(int argc, char **argv, int optcount, struct x_option *opts)
for (x=0; x<optcount; x++)
if (opts[x].name && strcmp(opts[x].name, longopts) == 0) {
- if (opts[x].has_argument)
+ if (opts[x].has_argument) {
if (x_optind < x_argc)
x_optarg = x_argv[x_optind++];
else {
@@ -130,6 +130,7 @@ x_getopt(int argc, char **argv, int optcount, struct x_option *opts)
x_argv[0], longopts);
return EOF;
}
+ }
return opts[x].optval;
}
View
156 configure.inc
@@ -1,4 +1,4 @@
-#
+# @(#) configure.inc 1.10@(#)
# Copyright (c) 1999 David Parsons. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -43,6 +43,7 @@ ac_standard="--src=DIR where the source lives (.)
__fail=exit
+ac_progname=$0
ac_configure_command="$*"
while [ $# -gt 0 ]; do
@@ -97,6 +98,29 @@ while [ $# -gt 0 ]; do
AC_MANDIR=`echo "$1" | sed -e 's/^[^=]*=//'`
shift 1;;
+ X--use-*=*)
+ _var=`echo "$1"| sed -n 's/^--use-\([A-Za-z][-A-Za-z0-9_]*\)=.*$/\1/p'`
+ if [ "$_var" ]; then
+ _val=`echo "$1" | sed -e 's/^--use-[^=]*=\(.*\)$/\1/'`
+ _v=`echo $_var | tr '[a-z]' '[A-Z]' | tr '-' '_'`
+ case X"$_val" in
+ X[Yy][Ee][Ss]|X[Tt][Rr][Uu][Ee]) eval USE_${_v}=T ;;
+ X[Nn][Oo]|X[Ff][Aa][Ll][Ss][Ee]) eval unset USE_${_v} ;;
+ *) echo "Bad value for --use-$_var ; must be yes or no"
+ exit 1 ;;
+ esac
+ else
+ echo "Bad option $1. Use --help to show options" 1>&2
+ exit 1
+ fi
+ shift 1 ;;
+
+ X--use-*)
+ _var=`echo "$1"|sed -n 's/^--use-\([A-Za-z][-A-Za-z0-9_]*\)$/\1/p'`
+ _v=`echo $_var | tr '[a-z]' '[A-Z]' | tr '-' '_'`
+ eval USE_${_v}=T
+ shift 1;;
+
X--with-*=*)
_var=`echo "$1"| sed -n 's/^--with-\([A-Za-z][-A-Za-z0-9_]*\)=.*$/\1/p'`
if [ "$_var" ]; then
@@ -104,7 +128,7 @@ while [ $# -gt 0 ]; do
_v=`echo $_var | tr '[a-z]' '[A-Z]' | tr '-' '_'`
eval WITH_${_v}=$_val
else
- LOG "Bad option $1. Use --help to show options"
+ echo "Bad option $1. Use --help to show options" 1>&2
exit 1
fi
shift 1 ;;
@@ -115,14 +139,14 @@ while [ $# -gt 0 ]; do
_v=`echo $_var | tr '[a-z]' '[A-Z]' | tr '-' '_'`
eval WITH_${_v}=1
else
- LOG "Bad option $1. Use --help to show options"
+ echo "Bad option $1. Use --help to show options" 1>&2
exit 1
fi
shift 1 ;;
X--help)
- LOG "$ac_standard"
- test "$ac_help" && LOG "$ac_help"
+ echo "$ac_standard"
+ test "$ac_help" && echo "$ac_help"
exit 0;;
*) if [ "$LOCAL_AC_OPTIONS" ]; then
@@ -131,7 +155,7 @@ while [ $# -gt 0 ]; do
ac_error=T
fi
if [ "$ac_error" ]; then
- LOG "Bad option $1. Use --help to show options"
+ echo "Bad option $1. Use --help to show options" 1>&2
exit 1
fi ;;
esac
@@ -139,6 +163,14 @@ done
#
+# echo w/o newline
+#
+echononl()
+{
+ ${ac_echo:-echo} "${@}$ac_echo_nonl"
+}
+
+#
# log something to the terminal and to a logfile.
#
LOG () {
@@ -151,7 +183,7 @@ LOG () {
# a newline
#
LOGN () {
- echo -n "$@" 1>&5
+ echononl "$@" 1>&5
echo "$@"
}
@@ -166,7 +198,7 @@ TLOG () {
# log something to the terminal, no newline
#
TLOGN () {
- echo -n "$@" 1>&5
+ echononl "$@" 1>&5
}
@@ -195,7 +227,7 @@ EOF
LOGN "checking for header $1"
if $AC_CC -o /tmp/ngc$$ /tmp/ngc$$.c; then
- echo '#define HAVE_'`echo $1 | tr 'a-z' 'A-Z' | tr './' '_'`' 1' >> $__cwd/config.h
+ AC_DEFINE 'HAVE_'`echo $1 | tr 'a-z' 'A-Z' | tr './' '_'` 1
TLOG " (found)"
rc=0
else
@@ -223,7 +255,7 @@ EOF
LOGN "checking for the $1 function"
if $AC_CC -o /tmp/ngc$$ /tmp/ngc$$.c $LIBS; then
- echo "#define `echo ${2:-HAVE_$1} | tr 'a-z' 'A-Z'` 1" >> $__cwd/config.h
+ AC_DEFINE `echo ${2:-HAVE_$1} | tr 'a-z' 'A-Z'` 1
TLOG " (found)"
rc=0
else
@@ -239,6 +271,48 @@ EOF
#
+# check to see if some structure contains a field
+#
+# usage: AC_CHECK_FIELD structure field {include ...}
+#
+AC_CHECK_FIELD () {
+ AC_PROG_CC
+
+ struct=$1
+ field=$2
+ shift 2
+
+ rm -f /tmp/ngc$$.c
+
+ for include in $*;do
+ echo "#include <$include>" >> /tmp/ngc$$.c
+ done
+
+ cat >> /tmp/ngc$$.c << EOF
+main()
+{
+ struct $struct foo;
+
+ foo.$field;
+}
+EOF
+
+ LOGN "checking that struct $struct has a $field field"
+
+ if $AC_CC -o /tmp/ngc$$ /tmp/ngc$$.c $AC_LIBS 2>>config.log; then
+ AC_DEFINE HAVE_`echo ${struct}_$field | tr 'a-z' 'A-Z'`
+ TLOG " (yes)"
+ rc=0
+ else
+ TLOG " (no)"
+ rc=1
+ fi
+ rm -f /tmp/ngc$$.c /tmp/ngc$$
+ return $rc
+}
+
+
+#
# check that the C compiler works
#
AC_PROG_CC () {
@@ -300,8 +374,7 @@ EOF
else
AC_SUB 'CFLAGS' ''
AC_SUB 'LDFLAGS' ''
- TLOG " does not compile code properly"
- $__fail 1
+ AC_FAIL " does not compile code properly"
fi
AC_SUB 'CC' "$AC_CC"
@@ -328,7 +401,7 @@ acLookFor () {
for program in $*; do
IFS=":"
for x in $path; do
- if [ $__mode $x/$program ]; then
+ if [ $__mode $x/$program -a -f $x/$program ]; then
echo $x/$program
break 2
fi
@@ -357,7 +430,7 @@ MF_PATH_INCLUDE () {
DEST=`acLookFor $__mode $*`
- __sym=`echo -n "$SYM" | tr '[a-z]' '[A-Z]'`
+ __sym=`echo "$SYM" | tr '[a-z]' '[A-Z]'`
if [ "$DEST" ]; then
TLOG " ($DEST)"
echo "$1 is $DEST"
@@ -386,6 +459,25 @@ AC_INIT () {
__cwd=`pwd`
exec 5>&1 1>$__cwd/config.log 2>&1
AC_CONFIGURE_FOR=__AC_`echo $1 | sed -e 's/\..$//' | tr 'a-z' 'A-Z' | tr ' ' '_'`_D
+
+ # check to see whether to use echo -n or echo ...\c
+ #
+ echo -n hello > $$
+ echo world >> $$
+ if grep "helloworld" $$ >/dev/null; then
+ ac_echo="echo -n"
+ echo "[echo -n] works"
+ else
+ ac_echo="echo"
+ echo 'hello\c' > $$
+ echo 'world' >> $$
+ if grep "helloworld" $$ >/dev/null; then
+ ac_echo_nonl='\c'
+ echo "[echo ...\\c] works"
+ fi
+ fi
+ rm -f $$
+
LOG "Configuring for [$1]"
ac_os=`uname -s`
@@ -401,12 +493,12 @@ AC_INIT () {
EOF
rm -f $__cwd/config.mak
-AC_PREFIX=${AC_PREFIX:-/usr/local}
-AC_EXECDIR=${AC_EXECDIR:-$AC_PREFIX/bin}
-AC_LIBDIR=${AC_LIBDIR:-$AC_PREFIX/lib}
-AC_MANDIR=${AC_MANDIR:-$AC_PREFIX/man}
-AC_CONFDIR=${AC_CONFDIR:-/etc}
-AC_SRCDIR=${AC_SRCDIR:-`pwd`}
+ AC_PREFIX=${AC_PREFIX:-/usr/local}
+ AC_EXECDIR=${AC_EXECDIR:-$AC_PREFIX/bin}
+ AC_LIBDIR=${AC_LIBDIR:-$AC_PREFIX/lib}
+ AC_MANDIR=${AC_MANDIR:-$AC_PREFIX/man}
+ AC_CONFDIR=${AC_CONFDIR:-/etc}
+ AC_SRCDIR=${AC_SRCDIR:-`pwd`}
AC_SUB 'srcdir' "$AC_SRCDIR"
AC_SUB 'prefix' "$AC_PREFIX"
@@ -415,6 +507,7 @@ AC_SRCDIR=${AC_SRCDIR:-`pwd`}
AC_SUB 'confdir' "$AC_CONFDIR"
AC_SUB 'mandir' "$AC_MANDIR"
+ AC_PATH=${WITH_PATH:-$PATH}
AC_PROG_CPP
AC_PROG_INSTALL
}
@@ -588,7 +681,7 @@ AC_OUTPUT () {
rm -f config.cmd
cat - > config.cmd << EOF
#! /bin/sh
-${CC:+CC=\"$CC\"} ${CFLAGS:+CFLAGS=\"$CFLAGS\"} $0 $ac_configure_command
+${CC:+CC=\"$CC\"} ${CFLAGS:+CFLAGS=\"$CFLAGS\"} $ac_progname $ac_configure_command
EOF
chmod +x config.cmd
@@ -658,7 +751,7 @@ FOO
EOF
if $1 $2 /tmp/ngc$$.c > /tmp/ngc$$.o; then
- if grep -v '#define' /tmp/ngc$$.o | grep -qs BAR; then
+ if grep -v '#define' /tmp/ngc$$.o | grep -s BAR >/dev/null; then
echo "CPP=[$1], CPPFLAGS=[$2]"
AC_SUB 'CPP' "$1"
AC_SUB 'CPPFLAGS' "$2"
@@ -676,7 +769,11 @@ EOF
# to run it as a filter.
#
AC_PROG_CPP () {
- DEST=${AC_CPP_PROG:-`AC_PATH=/lib:/usr/lib:$ac_default_path acLookFor cpp`}
+ if [ "$AC_CPP_PROG" ]; then
+ DEST=$AC_CPP_PROG
+ else
+ DEST=`AC_PATH=/lib:/usr/lib:${AC_PATH:-$ac_default_path} acLookFor cpp`
+ fi
unset fail
LOGN "Looking for cpp"
@@ -689,29 +786,28 @@ AC_PROG_CPP () {
acCheckCPP $DEST -pipe || fail=1
if [ "$fail" ]; then
- TLOG " (can't run cpp as a pipeline)"
- $__fail 1
+ AC_FAIL " (can't run cpp as a pipeline)"
else
TLOG " ok"
return 0
fi
fi
- TLOG " (not found)"
- $__fail 1
+ AC_FAIL " (not found)"
}
#
# AC_FAIL spits out an error message, then __fail's
AC_FAIL() {
- echo "$*"
+ LOG "$*"
$__fail 1
}
#
# AC_SUB writes a substitution into config.sub
AC_SUB() {
- ( echo -n "s;@$1@;"
- echo -n "$2" | sed -e 's/;/\\;/g'
+ ( echononl "s;@$1@;"
+ _subst=`echo $2 | sed -e 's/;/\\;/g'`
+ echononl "$_subst"
echo ';g' ) >> $__cwd/config.sub
}
View
36 configure.sh
@@ -5,24 +5,14 @@
# is a script that's processed with eval, so you need to be very careful to
# make certain that what you quote is what you want to quote.
-ac_help='--path=PATH look for conversion programs in PATH
---filterdir=DIR where to put printer filters (prefix/sbin/printers)
+ac_help='--filterdir=DIR where to put printer filters (prefix/sbin/printers)
--traditional build a more traditional sort of magicfilter
--use-local-magic install a private magic file
+--use-fifo pipe the output from gs through a fifo
--with-papersize=SIZE set the default paper size for gs/pstext'
LOCAL_AC_OPTIONS='
case X"$1" in
-X--path=*) AC_PATH=`echo "$1" | sed -e 's/^[^=]*=//'`
- shift 1
- ;;
-X--path) AC_PATH="$2"
- shift 2
- ;;
-X--use-local-magic|X--use-local)
- ac_local_magic=T
- shift 1
- ;;
X--filterdir=*)
AC_FILTER=`echo "$1" | sed -e 's/^[^=]*=//'`
shift 1
@@ -44,16 +34,23 @@ esac'
TARGET=magicfilter
. ./configure.inc
+
# and away we go
#
+USE_FIFO=T # default to piping ghostscript via a fifo
AC_INIT magicfilter
AC_PROG_CC
AC_SUB filterdir ${AC_FILTER:-$AC_PREFIX/sbin/printers}
-AC_SUB GSOUT '${FIFO}'
-if [ ! "$ac_local_magic" ]; then
+if [ "$USE_FIFO" = "T" ]; then
+ AC_SUB GSOUT '${FIFO}'
+else
+ AC_SUB GSOUT '-'
+fi
+
+if [ ! "$USE_LOCAL_MAGIC" ]; then
case $ac_os in
[Ff]ree[Bb][Ss][Dd])magicpath=/etc:/usr/etc:/usr/share/misc ;;
*) magicpath=/etc:/usr/etc: ;;
@@ -69,11 +66,11 @@ if [ ! "$ac_local_magic" ]; then
if [ "$F" -a "$G" ]; then
save_AC_PATH=$AC_PATH
- AC_PATH=$magicpath MF_PATH_INCLUDE MAGIC -r magic || ac_local_magic=T
+ AC_PATH=$magicpath MF_PATH_INCLUDE MAGIC -r magic || USE_LOCAL_MAGIC=T
AC_PATH=$save_AC_PATH
else
LOG "file(1) is too old -- using private magic file"
- ac_local_magic=T
+ USE_LOCAL_MAGIC=T
fi
else
LOG "Using private magic file $AC_CONFDIR/mf.magic"
@@ -81,13 +78,13 @@ fi
rm -f $$
trap 1 2 3 9 15
-if [ "$ac_local_magic" ]; then
+if [ "$USE_LOCAL_MAGIC" ]; then
# if we're using local magic, manually write the substitution
# information into the config files
AC_CONFIG MAGIC "$AC_CONFDIR"/mf.magic
- AC_SUB INSTALL_MAGIC ""
+ AC_SUB INSTALL_MAGIC "$PROG_INSTALL"
else
- AC_SUB INSTALL_MAGIC ": "
+ AC_SUB INSTALL_MAGIC ":"
fi
AC_SUB DO_WHAT install-$TARGET
@@ -104,6 +101,7 @@ if AC_CHECK_HEADERS basis/options.h; then
fi
test "$HAVE_XGETOPT" || AC_SUB XGETOPT options.o
+AC_CHECK_HEADERS malloc.h || AC_CHECK_HEADERS sys/malloc.h
AC_CHECK_FUNCS basename
View
35 fe.c
@@ -34,11 +34,16 @@
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
+#include <sys/stat.h>
+#include <pwd.h>
#include <sys/wait.h>
#include <fcntl.h>
+#include <stdlib.h>
+#include <string.h>
#include "rule.h"
#include "magicfilter.h"
+#include "file/file.h"
int debug = 0;
char *progname;
@@ -51,7 +56,7 @@ void
fe(int input, int output)
{
char blk[1024];
- int size, status, i;
+ int size, i;
int fd;
dup2(input, 0);
@@ -151,6 +156,7 @@ be(int input, int output)
break;
case FPIPE: r->action = FFILTER;
break;
+ default: break;
}
}
@@ -164,16 +170,18 @@ be(int input, int output)
/*
* magicfilter: transparently print a variety of file formats
*/
+int
main(int argc, char **argv)
{
- pid_t child;
#ifndef NOFE
+ int status;
+ pid_t child;
int input[2], output[2];
#endif
int script;
- int status;
- int x;
+ char *user;
+ struct passwd *pw;
script = getoptionsandscript(argc, argv);
@@ -187,6 +195,25 @@ main(int argc, char **argv)
exit(0);
}
+ /* don't run as root; run as the print job owner if at all possible,
+ * otherwise set gid and uid to -1 and go from there
+ */
+ if (getuid() == 0) {
+ if ( (user=getenv("LPUSER")) == 0)
+ user = "nobody";
+
+ if ( (pw = getpwnam(user)) != 0) {
+ setgid(pw->pw_gid);
+ setuid(pw->pw_uid);
+ }
+ else {
+ setgid(-1);
+ setuid(-1);
+ }
+ }
+
+
+
#ifndef NOFE
if (pipe(input) == -1 || pipe(output) == -1) {
perror("pipe");
View
2  file/apprentice.c
@@ -36,7 +36,7 @@
#endif
#include "file.private.h"
-#ifndef lint
+#if 0
static char *moduleid =
"@(#)apprentice.c,v 3.0.1.1 1997/08/01 00:38:22 orc Exp";
#endif /* lint */
View
4 file/ascmagic.c
@@ -35,7 +35,7 @@
#include "names.h"
#include "form.h"
-#ifndef lint
+#if 0
static char *moduleid =
"@(#)ascmagic.c,v 3.0.1.1 1997/08/01 00:38:22 orc Exp";
#endif /* lint */
@@ -48,7 +48,7 @@ __lf_ascmagic(buf, nbytes)
unsigned char *buf;
int nbytes; /* size actually read */
{
- int i, isblock, has_escapes = 0;
+ int i, has_escapes = 0;
unsigned char *s;
char nbuf[HOWMANY+1]; /* one extra for terminating '\0' */
char *token;
View
11 file/file.c
@@ -24,7 +24,7 @@
*
* 4. This notice may not be removed or altered.
*/
-#ifndef lint
+#if 0
static char *moduleid =
"@(#)$Id$";
#endif /* lint */
@@ -38,6 +38,15 @@ extern int getopt();
extern int optind;
extern char *optarg;
+#ifndef __P
+# if __STDC__ || __cplusplus
+# define __P(a) a
+# else
+# define __P(a) ()
+# define const
+# endif
+#endif
+
#include "file.h"
#ifdef S_IFLNK
View
1  file/file.private.h
@@ -96,6 +96,7 @@ extern int __lf_softmagic __P((unsigned char *, int));
extern void __lf_tryit __P((unsigned char *, int, int));
extern int __lf_zmagic __P((unsigned char *, int));
extern void __lf_ckfprintf __P((FILE *, const char *, ...));
+extern void __lf_form __P((char *, ...));
extern unsigned long __lf_signextend __P((struct magic *, unsigned long));
View
1  file/form.c
@@ -1,5 +1,6 @@
#include <stdlib.h>
#include <stdarg.h>
+#include <string.h>
#include "form.h"
static char *bfr = 0;
View
2  file/fsmagic.c
@@ -44,7 +44,7 @@
#include "file.private.h"
-#ifndef lint
+#if 0
static char *moduleid =
"@(#)$Id$";
#endif /* lint */
View
1  file/libe.c
@@ -12,6 +12,7 @@
*/
#include "file.private.h"
+#include "form.h"
int
magic_zflag(int x)
View
11 file/print.c
@@ -36,9 +36,10 @@
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
+#include <ctype.h>
#include "file.private.h"
-#ifndef lint
+#if 0
static char *moduleid =
"@(#)$Id$";
#endif /* lint */
@@ -88,18 +89,18 @@ struct magic *m;
m->offset);
if (m->flag & INDIR)
- (void) fprintf(stderr, "(%s,%d),",
+ (void) fprintf(stderr, "(%s,%ld),",
(m->in.type >= 0 && m->in.type < SZOF(typ)) ?
typ[(unsigned char) m->in.type] :
"*bad*",
- m->in.offset);
+ (long)(m->in.offset));
(void) fprintf(stderr, " %s%s", (m->flag & UNSIGNED) ? "u" : "",
(m->type >= 0 && m->type < SZOF(typ)) ?
typ[(unsigned char) m->type] :
"*bad*");
if (m->mask != ~0L)
- (void) fprintf(stderr, " & %.8x", m->mask);
+ (void) fprintf(stderr, " & %.8lx", (long)(m->mask));
(void) fprintf(stderr, ",%c", m->reln);
@@ -112,7 +113,7 @@ struct magic *m;
case LELONG:
case BESHORT:
case BELONG:
- (void) fprintf(stderr, "%d", m->value.l);
+ (void) fprintf(stderr, "%ld", m->value.l);
break;
case STRING:
__lf_showstr(stderr, m->value.s, -1);
View
2  file/process.c
@@ -24,7 +24,7 @@
*
* 4. This notice may not be removed or altered.
*/
-#ifndef lint
+#if 0
static char *moduleid =
"@(#)$Id$";
#endif /* lint */
View
4 file/softmagic.c
@@ -32,7 +32,7 @@
#include "file.private.h"
-#ifndef lint
+#if 0
static char *moduleid =
"@(#)$Id$";
#endif /* lint */
@@ -270,7 +270,7 @@ long offset;
char *str;
int len;
{
- (void) fprintf(stderr, "mget @%d: ", offset);
+ (void) fprintf(stderr, "mget @%ld: ", offset);
__lf_showstr(stderr, (char *) str, len);
(void) fputc('\n', stderr);
(void) fputc('\n', stderr);
View
5 getline.c
@@ -111,7 +111,6 @@ getarg(char **p)
else {
if (**p == '\\' && (*p)[1]) {
int ct;
- char c;
(*p)++;
switch (**p) {
@@ -152,7 +151,6 @@ getarg(char **p)
void
vis(FILE *output, unsigned char *s)
{
- char *pat;
for ( ; *s ; ++s) {
switch (*s) {
case '\r': fputs("\\r", output); continue;
@@ -182,7 +180,6 @@ getline(FILE *input)
int idx, err; /* current char in line, error return flag */
char *p, *q, *hint; /* pointers for disassembling the line */
- int c;
if (buflen == 0) {
/* initialize the line buffer the first time in
@@ -298,7 +295,7 @@ getline(FILE *input)
++p;
r->argv = malloc(1);
- while (q = getarg(&p)) {
+ while ( (q = getarg(&p)) != 0) {
r->argv = realloc(r->argv, (3 + r->argc) * sizeof r->argv[0]);
if (r->argv == 0) {
perror("getline::realloc");
View
14 magicfilter.h.in
@@ -33,6 +33,12 @@
#include "rule.h"
#include "config.h"
+#if HAS_MALLOC_H
+# include <malloc.h>
+#elif HAS_SYS_MALLOC_H
+# include <sys/malloc.h>
+#endif
+
extern void xyzzy();
extern void plugh(struct rule *, char *, int);
@@ -45,8 +51,14 @@ extern char *filetype; /* the file type of the input file */
extern int getaline(FILE*,char**,int*,int*);
extern void trace(char*,struct rule*);
-
extern int getoptionsandscript(int, char**);
+extern void reject(char*,...);
+
+extern void filter_it(char *, int, struct rule*);
+extern void pipe_it(char *, int, struct rule*);
+extern void cat_it(char *, int, struct rule*);
+
+extern void vis(FILE*, unsigned char*);
#define MAGICFILTER_CONF "@confdir@/magicfilter.cf"
View
1  reject.c
@@ -29,6 +29,7 @@
#include <stdio.h>
#include <stdarg.h>
+void
reject(char *fmt, ...)
{
va_list ptr;
View
1  rule.h
@@ -57,5 +57,6 @@ struct rule {
extern struct rule *getline(FILE *);
extern struct rule *rules;
+char * action_p(enum rule_action);
#endif/*__RULE_D*/
View
1  textonly.c
@@ -128,7 +128,6 @@ void hex_dump(unsigned char *stuff_to_dump, int size, int fake_offset) {
int line_loc, i, this_line_size;
int dumped = 0;
- int temp;
/* some header stuff */
View
2  xyzzy.c
@@ -33,6 +33,7 @@
#include "magicfilter.h"
#include <file.h>
#include <string.h>
+#include <unistd.h>
char *filetype = 0;
@@ -40,7 +41,6 @@ void
xyzzy()
{
struct rule *r;
- int x;
char *ftype;
char bfr[4096];
int size;
Please sign in to comment.
Something went wrong with that request. Please try again.