Various cleanup and fixes.

This commit is contained in:
Poul-Henning Kamp 1994-09-22 02:49:24 +00:00
parent 5ba34297b9
commit b7e9accbaa
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=2971
8 changed files with 77 additions and 43 deletions

View File

@ -6,7 +6,7 @@
# this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
# ----------------------------------------------------------------------------
#
# $Id: Makefile,v 1.3 1994/09/21 04:38:26 phk Exp $
# $Id$
#
PROG= ctm
@ -15,6 +15,5 @@ SRCS= ctm.c ctm_input.c ctm_pass1.c ctm_pass2.c ctm_pass3.c \
ctm_syntax.c ctm_ed.c
LDADD+= -lmd
NOMAN= 1
CFLAGS+= -Wall
BINDIR= /usr/sbin
CFLAGS+= -Wall -g
.include <bsd.prog.mk>

View File

@ -16,17 +16,19 @@
* -a Attempt best effort.
* -b <dir> Base-dir
* -B <file> Backup to tar-file.
* -c Check it out, "ma non troppo"
* -d <int> Debug TBD.
* -F Force
* -m <mail-addr> Email me instead.
* -p Less paranoid.
* -P Paranoid.
* -q Be quiet.
* -r <name> Reconstruct file.
* -R <file> Read list of files to reconstruct.
*
* Options we have:
* -c Check it out, don't do anything.
* -F Force
* -p Less paranoid.
* -P Paranoid.
* -q Tell us less.
* -T <tmpdir>. Temporary files.
* -v Tell about each file.
* -v Tell us more.
*
*/
@ -73,7 +75,7 @@ main(int argc, char **argv)
if(stat) {
fprintf(stderr,"%d errors during option processing\n",stat);
exit(2);
return Exit_Pilot;
}
stat = 0;
argc -= optind;
@ -82,9 +84,15 @@ main(int argc, char **argv)
if(!argc)
stat |= Proc("-");
while(argc-- && !stat)
while(argc-- && !stat) {
stat |= Proc(*argv++);
}
if(stat == Exit_Done)
stat = Exit_OK;
if(Verbose)
fprintf(stderr,"Exit(%d)\n",stat);
return stat;
}
@ -103,13 +111,14 @@ Proc(char *filename)
strcpy(p,"gunzip < ");
strcat(p,filename);
f = popen(p,"r");
if(!f) { perror(p); return Exit_Garbage; }
} else {
p = 0;
f = fopen(filename,"r");
}
if(!f) {
perror(filename);
return 1;
return Exit_Garbage;
}
if(Verbose > 1)
@ -127,12 +136,15 @@ Proc(char *filename)
if(!f2) {
perror(fn);
fclose(f);
return 4;
return Exit_Broke;
}
unlink(fn);
fprintf(stderr,"Writing tmp-file \"%s\"\n",fn);
while(EOF != (i=getc(f)))
putc(i,f2);
if(EOF == putc(i,f2)) {
fclose(f2);
return Exit_Broke;
}
fclose(f);
f = f2;
}
@ -148,25 +160,30 @@ Proc(char *filename)
} else {
pclose(f);
f = popen(p,"r");
if(!f) { perror(p); return Exit_Broke; }
}
if((i=Pass2(f)))
return i;
i=Pass2(f);
if(!p) {
rewind(f);
} else {
pclose(f);
f = popen(p,"r");
if(!f) { perror(p); return Exit_Broke; }
}
if(i) {
if((!Force) || (i & ~Exit_Forcible))
return i;
}
if(CheckIt) {
fprintf(stderr,"All ok\n");
return 0;
fprintf(stderr,"All checks out ok.\n");
return Exit_Done;
}
if((i=Pass3(f)))
return i;
i=Pass3(f);
if(!p) {
fclose(f);
@ -174,7 +191,9 @@ Proc(char *filename)
pclose(f);
Free(p);
}
if(i)
return i;
fprintf(stderr,"All ok\n");
return 0;
fprintf(stderr,"All done ok\n");
return Exit_Done;
}

View File

@ -22,10 +22,6 @@
#include <sys/stat.h>
#include <sys/file.h>
/*
* We redefine the names to make it look nice...
*/
#define VERSION "2.0"
#define MAXSIZE (1024*1024*10)
@ -47,6 +43,7 @@
#define CTM_Q_MD5_After 0x0100
#define CTM_Q_MD5_Before 0x0200
#define CTM_Q_MD5_Chunk 0x0400
#define CTM_Q_MD5_Force 0x0800
struct CTM_Syntax {
char *Key;
@ -102,12 +99,20 @@ EXTERN int Exit;
EXTERN int Force;
EXTERN int CheckIt;
#define Exit_OK 0
#define Exit_Garbage 1
#define Exit_Pilot 2
#define Exit_Broke 4
#define Exit_NotOK 8
#define Exit_Forcible 16
#define Exit_Mess 32
#define Exit_Done 64
char * String(char *s);
void Fatal_(int ln, char *fn, char *kind);
#define Fatal(foo) Fatal_(__LINE__,__FILE__,foo)
#define Assert() Fatal_(__LINE__,__FILE__,"Assert failed.")
#define WRONG {Assert(); return 32;}
#define WRONG {Assert(); return Exit_Mess;}
u_char * Ffield(FILE *fd, MD5_CTX *ctx,u_char term);

View File

@ -75,14 +75,14 @@ Pass2(FILE *fd)
if(-1 != stat(name,&st)) {
fprintf(stderr," %s: %s exists.\n",
sp->Key,name);
ret |= 8;
ret |= Exit_Forcible;
}
break;
}
if(-1 == stat(name,&st)) {
fprintf(stderr," %s: %s doesn't exists.\n",
sp->Key,name);
ret |= 8;
ret |= Exit_NotOK;
break;
}
if (j & CTM_Q_Name_Dir) {
@ -90,7 +90,7 @@ Pass2(FILE *fd)
fprintf(stderr,
" %s: %s exist, but isn't dir.\n",
sp->Key,name);
ret |= 8;
ret |= Exit_NotOK;
}
break;
}
@ -99,7 +99,7 @@ Pass2(FILE *fd)
fprintf(stderr,
" %s: %s exist, but isn't file.\n",
sp->Key,name);
ret |= 8;
ret |= Exit_NotOK;
}
break;
}
@ -117,8 +117,15 @@ Pass2(FILE *fd)
strcmp(MD5File(name),p)) {
fprintf(stderr," %s: %s md5 mismatch.\n",
sp->Key,name);
ret |= 8;
if(j & CTM_Q_MD5_Force) {
if(Force)
fprintf(stderr," Can and will force.\n");
else
fprintf(stderr," Could have forced.n");
ret |= Exit_Forcible;
} else {
ret |= Exit_NotOK;
}
}
break;
}
@ -127,7 +134,7 @@ Pass2(FILE *fd)
break;
}
/* Unqualified MD5 */
ret = 32;
WRONG
break;
case CTM_F_Count:
GETBYTECNT(cnt,sep);
@ -146,7 +153,7 @@ Pass2(FILE *fd)
} else if(strcmp(md5,MD5File(p))) {
fprintf(stderr," %s: %s edit fails.\n",
sp->Key,name);
ret |= 32;
ret |= Exit_Mess;
return ret;
}
unlink(p);

View File

@ -107,10 +107,11 @@ Pass3(FILE *fd)
continue;
}
if(!strcmp(sp->Key,"FE")) {
ed = popen("ed -s","w");
ed = popen("ed","w");
if(!ed) {
WRONG
}
fprintf(ed,"e %s\n",name);
if(cnt != fwrite(trash,1,cnt,ed)) {
perror(name);
pclose(ed);

View File

@ -28,15 +28,19 @@
#define After CTM_Q_MD5_After
#define Before CTM_Q_MD5_Before
#define Chunk CTM_Q_MD5_Chunk
#define Force CTM_Q_MD5_Force
static int ctmFM[] = /* File Make */
{ Name|File|New, Uid, Gid, Mode, MD5|After|Chunk, Count, Bytes,0 };
{ Name|File|New, Uid, Gid, Mode,
MD5|After|Chunk, Count, Bytes,0 };
static int ctmFS[] = /* File Substitute */
{ Name|File, Uid, Gid, Mode, MD5|Before, MD5|After|Chunk, Count, Bytes,0 };
{ Name|File, Uid, Gid, Mode,
MD5|Before|Force, MD5|After|Chunk, Count, Bytes,0 };
static int ctmFE[] = /* File Edit */
{ Name|File, Uid, Gid, Mode, MD5|Before, MD5|After, Count, Bytes,0 };
{ Name|File, Uid, Gid, Mode,
MD5|Before, MD5|After, Count, Bytes,0 };
static int ctmFR[] = /* File Remove */
{ Name|File, MD5|Before, 0 };

View File

@ -6,11 +6,10 @@
# this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
# ----------------------------------------------------------------------------
#
# $Id: Makefile,v 1.3 1994/09/21 04:38:46 phk Exp $
# $Id$
#
PROG= ctm_scan
LDADD+= -lmd
NOMAN= 1
CFLAGS+= -Wall
BINDIR= /usr/sbin
.include <bsd.prog.mk>

View File

@ -84,10 +84,10 @@ proc CTMchg {t1 n1 m1 u1 g1 b1 s1 h1 t2 n2 m2 u2 g2 b2 s2 h2} {
}
if {$b1 == "0" && $b2 == "0"} {
puts stderr "E $b1$b2 $t1$t2 $n1"
set i [catch "exec diff -e $d1/$n1 $d2/$n2 > tmp" j]
set i [catch "exec diff -n $d1/$n1 $d2/$n2 > tmp" j]
set s [file size tmp]
if {$s < $s2} {
puts $fo_files "CTMFE $n1 $u2 $g2 $m2 $h1 $h2 $s"
puts $fo_files "CTMFN $n1 $u2 $g2 $m2 $h1 $h2 $s"
flush $fo_files
exec cat tmp >@ $fo_files
puts $fo_files ""