safecat-1.11-mdfn-struct.patch

I have written a patch to update safecat's behavior to use enhanced uniqueness of the revised Maildir protocol. This patch does not currently modify the hostname in the event of instances of '/' and ':'.

The patch is not exactly simple. With the way safecat currently works, I would need to perform two nearly duplicate queries in order to get the same tempfile information in two different parts of the program: once for the temporary filename, and again when creating the destination filename.

I attempted to avoid this by storing the information from the first query in a new data structure called maildirfn. Its declaration is like this:

typedef struct maildirfn {
 char secbuf[11];
 char inode[FMT_ULONG];
 char device[FMT_ULONG];
 char atto[TAIA_FMTFRAC];
 char pidbuf[6];
 char host[256];
} maildirfn;

In order to keep from creating a new mk_dstfile() twin to the existing mk_tempfile() function just to end up with the all of the same answers, I modified mk_tempfile() to store its answers in a maildirfn that could be used to create both filenames.

Questions may be directed to Toby Betts.

The following is a typescript of the procedure I used in applying my safecat-1.11-mdfn-struct.patch patch.

Script started on Thu Oct 23 15:59:40 2003
bismuth# tar xzf safecat-1.11.tar.gz -C /usr/local/src
bismuth# cp safecat-1.11-mdfn-struct.patch /usr/local/src/safecat-1.11/
bismuth# cd /usr/local/src/safecat-1.11/
bismuth# patch < ./safecat-1.11-mdfn-struct.patch
Hmm...  Looks like a unified diff to me...
The text leading up to this was:
--------------------------
|diff safecat-1.11/Makefile safecat-1.11-mdfn/Makefile
|--- safecat-1.11/Makefile	Tue Jun  3 23:42:17 2003
|+++ safecat-1.11-mdfn/Makefile	Thu Oct 23 13:51:03 2003
--------------------------
Patching file Makefile using Plan A...
Hunk #1 succeeded at 98.
Hunk #2 succeeded at 223.
Hunk #3 succeeded at 239.
Hmm...  The next patch looks like a unified diff to me...
The text leading up to this was:
--------------------------
|diff safecat-1.11/TARGETS safecat-1.11-mdfn/TARGETS
|--- safecat-1.11/TARGETS	Tue Jun  3 23:42:17 2003
|+++ safecat-1.11-mdfn/TARGETS	Thu Oct 23 13:51:03 2003
--------------------------
Patching file TARGETS using Plan A...
Hunk #1 succeeded at 17.
Hmm...  The next patch looks like a unified diff to me...
The text leading up to this was:
--------------------------
|diff safecat-1.11/fmt_xlong.c safecat-1.11-mdfn/fmt_xlong.c
|--- safecat-1.11/fmt_xlong.c	Wed Dec 31 19:00:00 1969
|+++ safecat-1.11-mdfn/fmt_xlong.c	Thu Oct 23 13:51:03 2003
--------------------------
(Creating file fmt_xlong.c...)
Patching file fmt_xlong.c using Plan A...
Empty context always matches.
Detection of previously applied patch not possible.
Hunk #1 succeeded at 1.
Hmm...  The next patch looks like a unified diff to me...
The text leading up to this was:
--------------------------
|diff safecat-1.11/maildirfn.h safecat-1.11-mdfn/maildirfn.h
|--- safecat-1.11/maildirfn.h	Wed Dec 31 19:00:00 1969
|+++ safecat-1.11-mdfn/maildirfn.h	Thu Oct 23 13:51:03 2003
--------------------------
(Creating file maildirfn.h...)
Patching file maildirfn.h using Plan A...
Empty context always matches.
Detection of previously applied patch not possible.
Hunk #1 succeeded at 1.
Hmm...  The next patch looks like a unified diff to me...
The text leading up to this was:
--------------------------
|diff safecat-1.11/safecat.c safecat-1.11-mdfn/safecat.c
|--- safecat-1.11/safecat.c	Tue Jun  3 23:42:17 2003
|+++ safecat-1.11-mdfn/safecat.c	Thu Oct 23 13:51:03 2003
--------------------------
Patching file safecat.c using Plan A...
Hunk #1 succeeded at 10.
Hunk #2 succeeded at 31.
Hunk #3 succeeded at 65.
Hunk #4 succeeded at 94.
Hunk #5 succeeded at 116.
Hunk #6 succeeded at 146.
Hmm...  The next patch looks like a unified diff to me...
The text leading up to this was:
--------------------------
|diff safecat-1.11/tempfile.c safecat-1.11-mdfn/tempfile.c
|--- safecat-1.11/tempfile.c	Tue Jul  1 10:01:34 2003
|+++ safecat-1.11-mdfn/tempfile.c	Thu Oct 23 13:51:03 2003
--------------------------
Patching file tempfile.c using Plan A...
Hunk #1 succeeded at 1.
Hunk #2 succeeded at 13.
Hunk #3 succeeded at 23.
Hmm...  The next patch looks like a unified diff to me...
The text leading up to this was:
--------------------------
|diff safecat-1.11/tempfile.h safecat-1.11-mdfn/tempfile.h
|--- safecat-1.11/tempfile.h	Mon Feb 28 23:09:50 2000
|+++ safecat-1.11-mdfn/tempfile.h	Thu Oct 23 13:51:03 2003
--------------------------
Patching file tempfile.h using Plan A...
Hunk #1 succeeded at 1.
done
bismuth# rm ./*.orig
bismuth# make
cat warn-auto.sh maildir.sh  | sed s}HOME}"`head -1 conf-root`"}g  > maildir
chmod 755 maildir
( cat warn-auto.sh;  echo CC=\'`head -1 conf-cc`\';  echo LD=\'`head -1 conf-ld`\';  ) > auto-ccld.sh
cat auto-ccld.sh make-load.sh > make-load
chmod 755 make-load
cat auto-ccld.sh find-systype.sh > find-systype
chmod 755 find-systype
./find-systype > systype
( cat warn-auto.sh; ./make-load "`cat systype`" ) > load
chmod 755 load
cat auto-ccld.sh make-compile.sh > make-compile
chmod 755 make-compile
( cat warn-auto.sh; ./make-compile "`cat systype`" ) >  compile
chmod 755 compile
( ( ./compile tryulong32.c && ./load tryulong32 &&  ./tryulong32 ) >/dev/null 2>&1  && cat uint32.h2 || cat uint32.h1 ) > uint32.h
rm -f tryulong32.o tryulong32
( ( ./compile tryulong64.c && ./load tryulong64 &&  ./tryulong64 ) >/dev/null 2>&1  && cat uint64.h2 || cat uint64.h1 ) > uint64.h
rm -f tryulong64.o tryulong64
./compile fmt_xlong.c
./compile safecat.c
( cat warn-auto.sh;  echo 'main="$1"; shift';  echo 'rm -f "$main"';  echo 'ar cr "$main" ${1+"$@"}';  case "`cat systype`" in  sunos-5.*) ;;  unix_sv*) ;;  irix64-*) ;;  irix-*) ;;  dgux-*) ;;  hp-ux-*) ;;  sco*) ;;  *) echo 'ranlib "$main"' ;;  esac  ) > makelib
chmod 755 makelib
./compile getln.c
./compile getln2.c
./makelib getln.a getln.o getln2.o
./compile str_len.c
./compile byte_chr.c
./compile byte_diff.c
./compile byte_copy.c
./compile byte_cr.c
./compile byte_zero.c
./makelib str.a str_len.o byte_chr.o byte_diff.o  byte_copy.o byte_cr.o byte_zero.o
./compile stralloc_eady.c
./compile stralloc_pend.c
./compile stralloc_copy.c
./compile stralloc_opys.c
./compile stralloc_opyb.c
./compile stralloc_cat.c
./compile stralloc_cats.c
./compile stralloc_catb.c
./compile stralloc_arts.c
./compile stralloc_num.c
./makelib stralloc.a stralloc_eady.o stralloc_pend.o  stralloc_copy.o stralloc_opys.o stralloc_opyb.o  stralloc_cat.o stralloc_cats.o stralloc_catb.o  stralloc_arts.o stralloc_num.o
( ( ./compile tryerrno.c && ./load tryerrno &&  ./tryerrno ) >/dev/null 2>&1  && cat error.h1 || cat error.h2 ) > error.h
rm -f tryerrno.o tryerrno
./compile strerr_sys.c
./compile strerr_die.c
./makelib strerr.a strerr_sys.o strerr_die.o
./compile substdio.c
./compile substdi.c
./compile substdo.c
./compile subfderr.c
./compile subfdout.c
./compile subfdouts.c
./compile subfdin.c
./compile subfdins.c
./compile substdio_copy.c
./makelib substdio.a substdio.o substdi.o substdo.o  subfderr.o subfdout.o subfdouts.o subfdin.o subfdins.o  substdio_copy.o
./compile alloc.c
./compile alloc_re.c
./compile envread.c
./compile error.c
./compile error_str.c
./compile fmt_uint64.c
./compile hostname.c
( ( ./compile trysgact.c && ./load trysgact ) >/dev/null  2>&1  && echo \#define HASSIGACTION 1 || exit 0 ) > hassgact.h
rm -f trysgact.o trysgact
./compile sig.c
./compile stat_dir.c
./compile str_diffn.c
./compile taia_fmtfrac.c
./compile taia_now.c
./compile taia_tai.c
./compile tempfile.c
./compile writefile.c
./load safecat getln.a str.a stralloc.a strerr.a substdio.a  alloc.o alloc_re.o byte_copy.o byte_cr.o envread.o error.o  error_str.o fmt_uint64.o fmt_xlong.o hostname.o sig.o  stat_dir.o str_diffn.o str_len.o substdi.o substdio.o  substdio_copy.o taia_fmtfrac.o taia_now.o taia_tai.o  tempfile.o writefile.o
nroff -man safecat.1 > safecat.0
nroff -man maildir.1 > maildir.0
bismuth# mkdir a b
bismuth# echo "hello world" | ./safecat a b
1066939274.If313V0M992722P23362.bismuth.glsc.org
bismuth# ls -la ./b
total 8
drwxr-xr-x  2 root  wheel   512 Oct 23 16:00 .
drwxr-xr-x  4 root  wheel  4096 Oct 23 16:13 ..
-rw-r--r--  1 root  wheel    12 Oct 23 16:00 1066939274.If313V0M992722P23362.bismuth.glsc.org
bismuth# exit

Script done on Thu Oct 23 16:00:45 2003