head	1.9;
access;
symbols
	RELENG_6_4_0_RELEASE:1.8.14.1
	RELENG_6_4:1.8.14.1.0.4
	RELENG_6_4_BP:1.8.14.1
	RELENG_6_3_0_RELEASE:1.8.14.1
	RELENG_6_3:1.8.14.1.0.2
	RELENG_6_3_BP:1.8.14.1
	RELENG_6_2_0_RELEASE:1.8
	RELENG_6_2:1.8.0.22
	RELENG_6_2_BP:1.8
	RELENG_5_5_0_RELEASE:1.8
	RELENG_5_5:1.8.0.20
	RELENG_5_5_BP:1.8
	RELENG_6_1_0_RELEASE:1.8
	RELENG_6_1:1.8.0.18
	RELENG_6_1_BP:1.8
	RELENG_6_0_0_RELEASE:1.8
	RELENG_6_0:1.8.0.16
	RELENG_6_0_BP:1.8
	RELENG_6:1.8.0.14
	RELENG_6_BP:1.8
	RELENG_5_4_0_RELEASE:1.8
	RELENG_5_4:1.8.0.12
	RELENG_5_4_BP:1.8
	RELENG_4_11_0_RELEASE:1.7.2.1
	RELENG_4_11:1.7.2.1.0.18
	RELENG_4_11_BP:1.7.2.1
	RELENG_5_3_0_RELEASE:1.8
	RELENG_5_3:1.8.0.10
	RELENG_5_3_BP:1.8
	RELENG_5:1.8.0.8
	RELENG_5_BP:1.8
	RELENG_4_10_0_RELEASE:1.7.2.1
	RELENG_4_10:1.7.2.1.0.16
	RELENG_4_10_BP:1.7.2.1
	RELENG_5_2_1_RELEASE:1.8
	RELENG_5_2_0_RELEASE:1.8
	RELENG_5_2:1.8.0.6
	RELENG_5_2_BP:1.8
	RELENG_4_9_0_RELEASE:1.7.2.1
	RELENG_4_9:1.7.2.1.0.14
	RELENG_4_9_BP:1.7.2.1
	RELENG_5_1_0_RELEASE:1.8
	RELENG_5_1:1.8.0.4
	RELENG_5_1_BP:1.8
	RELENG_4_8_0_RELEASE:1.7.2.1
	RELENG_4_8:1.7.2.1.0.12
	RELENG_4_8_BP:1.7.2.1
	RELENG_5_0_0_RELEASE:1.8
	RELENG_5_0:1.8.0.2
	RELENG_5_0_BP:1.8
	RELENG_4_7_0_RELEASE:1.7.2.1
	RELENG_4_7:1.7.2.1.0.10
	RELENG_4_7_BP:1.7.2.1
	RELENG_4_6_2_RELEASE:1.7.2.1
	RELENG_4_6_1_RELEASE:1.7.2.1
	RELENG_4_6_0_RELEASE:1.7.2.1
	RELENG_4_6:1.7.2.1.0.8
	RELENG_4_6_BP:1.7.2.1
	RELENG_4_5_0_RELEASE:1.7.2.1
	RELENG_4_5:1.7.2.1.0.6
	RELENG_4_5_BP:1.7.2.1
	RELENG_4_4_0_RELEASE:1.7.2.1
	RELENG_4_4:1.7.2.1.0.4
	RELENG_4_4_BP:1.7.2.1
	RELENG_4_3_0_RELEASE:1.7.2.1
	RELENG_4_3:1.7.2.1.0.2
	RELENG_4_3_BP:1.7.2.1
	RELENG_4_2_0_RELEASE:1.7
	RELENG_4_1_1_RELEASE:1.7
	PRE_SMPNG:1.7
	RELENG_4_1_0_RELEASE:1.7
	RELENG_3_5_0_RELEASE:1.5.2.2
	RELENG_4_0_0_RELEASE:1.7
	RELENG_4:1.7.0.2
	RELENG_4_BP:1.7
	RELENG_3_4_0_RELEASE:1.5.2.2
	RELENG_3_3_0_RELEASE:1.5.2.2
	RELENG_3_2_PAO:1.5.0.4
	RELENG_3_2_PAO_BP:1.5
	RELENG_3_2_0_RELEASE:1.5
	RELENG_3_1_0_RELEASE:1.5
	RELENG_3:1.5.0.2
	RELENG_3_BP:1.5
	RELENG_2_2_8_RELEASE:1.4.10.1
	RELENG_3_0_0_RELEASE:1.5
	RELENG_2_2_7_RELEASE:1.4.10.1
	RELENG_2_2_6_RELEASE:1.4.10.1
	RELENG_2_2_5_RELEASE:1.4
	RELENG_2_2_2_RELEASE:1.4
	RELENG_2_2_1_RELEASE:1.4
	RELENG_2_2_0_RELEASE:1.4
	RELENG_2_1_7_RELEASE:1.4
	RELENG_2_1_6_1_RELEASE:1.4
	RELENG_2_1_6_RELEASE:1.4
	RELENG_2_2:1.4.0.10
	RELENG_2_2_BP:1.4
	RELENG_2_1_5_RELEASE:1.4
	RELENG_2_1_0_RELEASE:1.4
	RELENG_2_1_0:1.4.0.8
	RELENG_2_1_0_BP:1.4
	RELENG_2_0_5_RELEASE:1.4
	RELENG_2_0_5:1.4.0.6
	RELENG_2_0_5_BP:1.4
	RELENG_2_0_5_ALPHA:1.4
	RELEASE_2_0:1.4
	BETA_2_0:1.4
	ALPHA_2_0:1.4.0.4
	MOVED_NEWCVS:1.4
	FINAL_1_1_5:1.4
	ALPHA_1_1_5:1.4
	FINAL_1_1:1.4
	GAMMA_1_1:1.4
	BETA_1_1:1.4.0.2
	BP_BETA_1_1:1.4
	FINAL_1_0:1.4
	EPSILON_1_0:1.3
	GAMMA_1_0:1.2
	BETA_1_0:1.2
	ALPHA_1_0:1.2
	GZIP_1_1:1.1.1.1
	GNU:1.1.1;
locks; strict;
comment	@# @;


1.9
date	2007.01.31.03.44.42;	author delphij;	state dead;
branches;
next	1.8;

1.8
date	2000.11.19.13.10.11;	author kris;	state Exp;
branches
	1.8.14.1;
next	1.7;

1.7
date	99.08.27.23.35.50;	author peter;	state Exp;
branches
	1.7.2.1;
next	1.6;

1.6
date	99.05.28.13.23.14;	author kris;	state Exp;
branches;
next	1.5;

1.5
date	97.08.09.15.34.40;	author peter;	state Exp;
branches
	1.5.2.1;
next	1.4;

1.4
date	93.10.14.00.32.39;	author nate;	state Exp;
branches
	1.4.10.1;
next	1.3;

1.3
date	93.09.07.05.13.47;	author nate;	state Exp;
branches;
next	1.2;

1.2
date	93.06.19.00.22.26;	author nate;	state Exp;
branches;
next	1.1;

1.1
date	93.06.18.18.39.38;	author nate;	state Exp;
branches
	1.1.1.1;
next	;

1.8.14.1
date	2007.02.20.08.33.29;	author delphij;	state dead;
branches;
next	;

1.7.2.1
date	2001.02.18.02.19.22;	author kris;	state Exp;
branches;
next	1.7.2.2;

1.7.2.2
date	2012.11.17.07.23.05;	author svnexp;	state Exp;
branches;
next	;

1.5.2.1
date	99.06.07.14.07.26;	author kris;	state Exp;
branches;
next	1.5.2.2;

1.5.2.2
date	99.08.29.14.33.25;	author peter;	state Exp;
branches;
next	;

1.4.10.1
date	98.02.15.15.34.17;	author jkh;	state Exp;
branches;
next	;

1.1.1.1
date	93.06.18.18.39.39;	author nate;	state Exp;
branches;
next	;


desc
@@


1.9
log
@Remove GNU gzip left-offs, they are no longer necessary.
@
text
@#!/bin/sh
# gzexe: compressor for Unix executables.
# Use this only for binaries that you do not use frequently.
#
# The compressed version is a shell script which decompresses itself after
# skipping $skip lines of shell commands.  We try invoking the compressed
# executable with the original name (for programs looking at their name).
# We also try to retain the original file permissions on the compressed file.
# For safety reasons, gzexe will not create setuid or setgid shell scripts.

# WARNING: the first line of this file must be either : or #!/bin/sh
# The : is required for some old versions of csh.
# On Ultrix, /bin/sh is too buggy, change the first line to: #!/bin/sh5
#
# $FreeBSD: src/gnu/usr.bin/gzip/gzexe,v 1.8 2000/11/19 13:10:11 kris Exp $

x=`basename $0`
if test $# = 0; then
  echo compress executables. original file foo is renamed to foo~
  echo usage: ${x} [-d] files...
  echo   "   -d  decompress the executables"
  exit 1
fi

tmp=`/usr/bin/mktemp -t gz` || exit 1
trap "rm -f $tmp; exit 1" 1 2 3 5 10 13 15

decomp=0
res=0
test "$x" = "ungzexe" && decomp=1
if test "x$1" = "x-d"; then
  decomp=1
  shift
fi

zfoo1=`/usr/bin/mktemp -t zfoo1` || exit 1
zfoo2=`/usr/bin/mktemp -t zfoo2` || exit 1
echo hi > $zfoo1
echo hi > $zfoo2
if test -z "`(${CPMOD-cpmod} $zfoo1 $zfoo2) 2>&1`"; then
  cpmod=${CPMOD-cpmod}
fi
rm -f $zfoo1 $zfoo2

tail=""
IFS="${IFS= 	}"; saveifs="$IFS"; IFS="${IFS}:"
for dir in $PATH; do
  test -z "$dir" && dir=.
  if test -f $dir/tail; then
    tail="$dir/tail"
    break
  fi
done
IFS="$saveifs"
if test -z "$tail"; then
  echo cannot find tail
  exit 1
fi

for i do
  if test ! -f "$i" ; then
    echo ${x}: $i not a file
    res=1
    continue
  fi
  if test $decomp -eq 0; then
    if sed -e 1d -e 2q "$i" | grep "^skip=[0-9]*$" >/dev/null; then
      echo "${x}: $i is already gzexe'd"
      continue
    fi
  fi
  if ls -l "$i" | grep '^...[sS]' > /dev/null; then
    echo "${x}: $i has setuid permission, unchanged"
    continue
  fi
  if ls -l "$i" | grep '^......[sS]' > /dev/null; then
    echo "${x}: $i has setgid permission, unchanged"
    continue
  fi
  case "`basename $i`" in
  sh | gzip | tail | chmod | ln | sleep | rm | mktemp)
	echo "${x}: $i would depend on itself"; continue ;;
  esac
  if test -z "$cpmod"; then
    cp -p "$i" $tmp 2>/dev/null || cp "$i" $tmp
    if test -w $tmp 2>/dev/null; then
      writable=1
    else
      writable=0
      chmod u+w $tmp 2>/dev/null
    fi
  fi
  if test $decomp -eq 0; then
    sed 1q $0 > $tmp
    sed "s|^if tail|if $tail|" >> $tmp <<'EOF'
skip=22
gztmp=`/usr/bin/mktemp -t gztmp` || exit 1
if tail +$skip $0 | gzip -cd > $gztmp; then
  chmod 700 $gztmp
  prog="`echo $0 | sed 's|^.*/||'`"
  progtmp=`/usr/bin/mktemp -t ${prog}` || exit 1
  if /bin/ln $gztmp $progtmp 2>/dev/null; then
    trap '/bin/rm -f $gztmp $progtmp; exit $res' 0
    (/bin/sleep 5; /bin/rm -f $gztmp $progtmp) 2>/dev/null &
    /tmp/"$prog" ${1+"$@@"}; res=$?
  else
    trap '/bin/rm -f $progtmp $gztmp exit $res' 0
    (/bin/sleep 5; /bin/rm -f $progtmp $gztmp) 2>/dev/null &
    $gztmp ${1+"$@@"}; res=$?
  fi
else
  echo Cannot decompress $0
  rm -f $gztmp
  exit 1
fi; exit $res
EOF
    gzip -cv9 "$i" >> $tmp || {
      /bin/rm -f $tmp
      echo ${x}: compression not possible for $i, file unchanged.
      res=1
      continue
    }

  else
    # decompression
    skip=18
    if sed -e 1d -e 2q "$i" | grep "^skip=[0-9]*$" >/dev/null; then
      eval `sed -e 1d -e 2q "$i"`
    fi
    if tail +$skip "$i" | gzip -cd > $tmp; then
      :
    else
      echo ${x}: $i probably not in gzexe format, file unchanged.
      res=1
      continue
    fi
  fi
  rm -f "$i~"
  mv "$i" "$i~" || {
    echo ${x}: cannot backup $i as $i~
    rm -f $tmp
    res=1
    continue
  }
  mv $tmp "$i" || cp -p $tmp "$i" 2>/dev/null || cp $tmp "$i" || {
    echo ${x}: cannot create $i
    rm -f $tmp
    res=1
    continue
  }
  rm -f $tmp
  if test -n "$cpmod"; then
    $cpmod "$i~" "$i" 2>/dev/null
  elif test $writable -eq 0; then
    chmod u-w $i 2>/dev/null
  fi
done
exit $res
@


1.8
log
@Use mktemp -t to respect TMPDIR
Clean up temporary file at runtime
@
text
@d15 1
a15 1
# $FreeBSD: src/gnu/usr.bin/gzip/gzexe,v 1.7 1999/08/27 23:35:50 peter Exp $
@


1.8.14.1
log
@MFC: Replace gzip(1) with the BSD licensed version found in -HEAD.

Discussed with:	re, so, portmgr (kris)

All bugs are mine.
@
text
@d15 1
a15 1
# $FreeBSD: src/gnu/usr.bin/gzip/gzexe,v 1.8 2000/11/19 13:10:11 kris Exp $
@


1.7
log
@$Id$ -> $FreeBSD$
@
text
@d15 1
a15 1
# $FreeBSD$
d25 1
a25 1
tmp=`/usr/bin/mktemp gzXXXXXXXXXX` || exit 1
d36 2
a37 2
zfoo1=`/usr/bin/mktemp zfoo1XXXXXXXXXX` || exit 1
zfoo2=`/usr/bin/mktemp zfoo2XXXXXXXXXX` || exit 1
d97 1
a97 1
gztmp=`/usr/bin/mktemp /tmp/gztmpXXXXXXXXXX` || exit 1
d101 1
a101 1
  progtmp=`/usr/bin/mktemp /tmp/${prog}XXXXXXXXXX` || exit 1
d107 2
a108 2
    trap '/bin/rm -f $gztmp exit $res' 0
    (/bin/sleep 5; /bin/rm -f $gztmp) 2>/dev/null &
@


1.7.2.1
log
@MFC: Better handling of tempfiles
@
text
@d15 1
a15 1
# $FreeBSD: src/gnu/usr.bin/gzip/gzexe,v 1.7 1999/08/27 23:35:50 peter Exp $
d25 1
a25 1
tmp=`/usr/bin/mktemp -t gz` || exit 1
d36 2
a37 2
zfoo1=`/usr/bin/mktemp -t zfoo1` || exit 1
zfoo2=`/usr/bin/mktemp -t zfoo2` || exit 1
d97 1
a97 1
gztmp=`/usr/bin/mktemp -t gztmp` || exit 1
d101 1
a101 1
  progtmp=`/usr/bin/mktemp -t ${prog}` || exit 1
d107 2
a108 2
    trap '/bin/rm -f $progtmp $gztmp exit $res' 0
    (/bin/sleep 5; /bin/rm -f $progtmp $gztmp) 2>/dev/null &
@


1.7.2.2
log
@Switch importer
@
text
@d15 1
a15 1
# $FreeBSD: stable/4/gnu/usr.bin/gzip/gzexe 72593 2001-02-18 02:19:22Z kris $
@


1.6
log
@Fixes from OpenBSD:

Add $Id$
Removes temp file exploits in gzexe (predictable filenames)
Fixes some typos
Fixes a buffer overrun in gzip -S
Don't prepend /usr/local/bin to path in scripts
Correct location of /usr/share/misc/termcap

Obtained from:	OpenBSD
@
text
@d15 1
a15 1
# $Id$
@


1.5
log
@Don't accidently compress "sh" or there are unfortunate consequences.

PR: 4220
Submitted-by: Dag-Erling Coidan Smrgrav <finrod@@pugwash.priv.no>
@
text
@d14 2
d25 1
a25 1
tmp=gz$$
d36 5
a40 3
echo hi > zfoo1$$
echo hi > zfoo2$$
if test -z "`(${CPMOD-cpmod} zfoo1$$ zfoo2$$) 2>&1`"; then
d43 1
a43 1
rm -f zfoo[12]$$
d81 1
a81 1
  sh | gzip | tail | chmod | ln | sleep | rm)
d96 4
a99 3
skip=18
if tail +$skip $0 | gzip -cd > /tmp/gztmp$$; then
  chmod 700 /tmp/gztmp$$
d101 4
a104 3
  if /bin/ln /tmp/gztmp$$ "/tmp/$prog" 2>/dev/null; then
    trap '/bin/rm -f /tmp/gztmp$$ "/tmp/$prog"; exit $res' 0
    (/bin/sleep 5; /bin/rm -f /tmp/gztmp$$ "/tmp/$prog") 2>/dev/null &
d107 3
a109 3
    trap '/bin/rm -f /tmp/gztmp$$; exit $res' 0
    (/bin/sleep 5; /bin/rm -f /tmp/gztmp$$) 2>/dev/null &
    /tmp/gztmp$$ ${1+"$@@"}; res=$?
d112 3
a114 1
  echo Cannot decompress $0; exit 1
@


1.5.2.1
log
@MFC: Fixes from OpenBSD:

Add $Id$
Removes temp file exploits in gzexe (predictable filenames)
Fixes some typos
Fixes a buffer overrun in gzip -S
Don't prepend /usr/local/bin to path in scripts
Correct location of /usr/share/misc/termcap
@
text
@a13 2
#
# $Id: gzexe,v 1.6 1999/05/28 13:23:14 kris Exp $
d23 1
a23 1
tmp=`/usr/bin/mktemp gzXXXXXXXXXX` || exit 1
d34 3
a36 5
zfoo1=`/usr/bin/mktemp zfoo1XXXXXXXXXX` || exit 1
zfoo2=`/usr/bin/mktemp zfoo2XXXXXXXXXX` || exit 1
echo hi > $zfoo1
echo hi > $zfoo2
if test -z "`(${CPMOD-cpmod} $zfoo1 $zfoo2) 2>&1`"; then
d39 1
a39 1
rm -f $zfoo1 $zfoo2
d77 1
a77 1
  sh | gzip | tail | chmod | ln | sleep | rm | mktemp)
d92 3
a94 4
skip=22
gztmp=`/usr/bin/mktemp /tmp/gztmpXXXXXXXXXX` || exit 1
if tail +$skip $0 | gzip -cd > $gztmp; then
  chmod 700 $gztmp
d96 3
a98 4
  progtmp=`/usr/bin/mktemp /tmp/${prog}XXXXXXXXXX` || exit 1
  if /bin/ln $gztmp $progtmp 2>/dev/null; then
    trap '/bin/rm -f $gztmp $progtmp; exit $res' 0
    (/bin/sleep 5; /bin/rm -f $gztmp $progtmp) 2>/dev/null &
d101 3
a103 3
    trap '/bin/rm -f $gztmp exit $res' 0
    (/bin/sleep 5; /bin/rm -f $gztmp) 2>/dev/null &
    $gztmp ${1+"$@@"}; res=$?
d106 1
a106 3
  echo Cannot decompress $0
  rm -f $gztmp
  exit 1
@


1.5.2.2
log
@$Id$ -> $FreeBSD$
@
text
@d15 1
a15 1
# $FreeBSD$
@


1.4
log
@Updated gzip from version 1.2.2 to 1.2.4 due to popular demand
@
text
@d77 1
a77 1
  gzip | tail | chmod | ln | sleep | rm)
@


1.4.10.1
log
@MFC: selected security fixes.
@
text
@d77 1
a77 1
  sh | gzip | tail | chmod | ln | sleep | rm)
@


1.3
log
@Removed some hard-coded paths in gzexe so it works with the current
FreeBSD setup
@
text
@d95 1
a95 1
  prog="`echo $0 | sed 's|^.*/||`"
@


1.2
log
@Updated gzip from 1.1 to 1.2.2
@
text
@d93 3
a95 3
if tail +$skip $0 | "/usr/local/bin"/gzip -cd > /tmp/gztmp$$; then
  /bin/chmod 700 /tmp/gztmp$$
  prog="`echo $0 | /bin/sed 's|^.*/||`"
d109 1
a109 1
    "/usr/local/bin"/gzip -cv9 "$i" >> $tmp || {
d122 1
a122 1
    if tail +$skip "$i" | "/usr/local/bin"/gzip -cd > $tmp; then
@


1.1
log
@Initial revision
@
text
@d11 1
a11 1
# Warning: the first line of this file must be either : or #!/bin/sh
d13 1
d41 15
d76 4
a79 4
  if test "`basename $i`" = gzip; then
    echo "${x}: cannot compress gzip itself"
    continue
  fi
d91 1
a91 1
    cat >> $tmp <<'EOF'
d93 4
a96 4
if tail +$skip $0 | gzip -cd > /tmp/gztmp$$; then
  chmod 755 /tmp/gztmp$$
  prog="`basename $0`"
  if ln /tmp/gztmp$$ "/tmp/$prog" 2>/dev/null; then
d98 1
a98 1
    (sleep 5; /bin/rm -f /tmp/gztmp$$ "/tmp/$prog") 2>/dev/null &
d102 1
a102 1
    (sleep 5; /bin/rm -f /tmp/gztmp$$) 2>/dev/null &
d109 1
a109 1
    gzip -cv9 "$i" >> $tmp || {
d122 1
a122 1
    if tail +$skip "$i" | gzip -cd > $tmp; then
@


1.1.1.1
log
@Gzip 1.1
@
text
@@
