Index: stable/2.1/sbin/md5/md5.c =================================================================== --- stable/2.1/sbin/md5/md5.c (revision 10587) +++ stable/2.1/sbin/md5/md5.c (revision 10588) @@ -1,171 +1,174 @@ /* - * $Id: md5.c,v 1.4 1995/02/26 02:00:35 phk Exp $ + * $Id: md5.c,v 1.6 1995/07/12 09:14:46 phk Exp $ * * Derived from: */ /* * MDDRIVER.C - test driver for MD2, MD4 and MD5 */ /* * Copyright (C) 1990-2, RSA Data Security, Inc. Created 1990. All * rights reserved. * * RSA Data Security, Inc. makes no representations concerning either * the merchantability of this software or the suitability of this * software for any particular purpose. It is provided "as is" * without express or implied warranty of any kind. * * These notices must be retained in any copies of any part of this * documentation and/or software. */ #include #include #include #include "global.h" #include /* * Length of test block, number of test blocks. */ #define TEST_BLOCK_LEN 1000 #define TEST_BLOCK_COUNT 1000 static void MDString PROTO_LIST((char *)); static void MDTimeTrial PROTO_LIST((void)); static void MDTestSuite PROTO_LIST((void)); static void MDFilter PROTO_LIST((int)); /* Main driver. Arguments (may be any combination): -sstring - digests string -t - runs time trial -x - runs test script filename - digests file (none) - digests standard input */ int main(argc, argv) int argc; char *argv[]; { int i; char *p; + char buf[33]; if (argc > 1) for (i = 1; i < argc; i++) if (argv[i][0] == '-' && argv[i][1] == 's') MDString(argv[i] + 2); else if (strcmp(argv[i], "-t") == 0) MDTimeTrial(); else if (strcmp(argv[i], "-p") == 0) MDFilter(1); else if (strcmp(argv[i], "-x") == 0) MDTestSuite(); else { - p = MD5File(argv[i]); + p = MD5File(argv[i],buf); if (!p) perror(argv[i]); else printf("MD5 (%s) = %s\n", argv[i], p); } else MDFilter(0); return (0); } /* * Digests a string and prints the result. */ static void MDString(string) char *string; { unsigned int len = strlen(string); + char buf[33]; - printf("MD5 (\"%s\") = %s\n", string, MD5Data(string, len)); + printf("MD5 (\"%s\") = %s\n", string, MD5Data(string, len, buf)); } /* * Measures the time to digest TEST_BLOCK_COUNT TEST_BLOCK_LEN-byte blocks. */ static void MDTimeTrial() { MD5_CTX context; time_t endTime, startTime; unsigned char block[TEST_BLOCK_LEN]; unsigned int i; - char *p; + char *p, buf[33]; printf ("MD5 time trial. Digesting %d %d-byte blocks ...", TEST_BLOCK_LEN, TEST_BLOCK_COUNT); /* Initialize block */ for (i = 0; i < TEST_BLOCK_LEN; i++) block[i] = (unsigned char) (i & 0xff); /* Start timer */ time(&startTime); /* Digest blocks */ MD5Init(&context); for (i = 0; i < TEST_BLOCK_COUNT; i++) MD5Update(&context, block, TEST_BLOCK_LEN); - p = MD5End(&context); + p = MD5End(&context,buf); /* Stop timer */ time(&endTime); printf(" done\n"); printf("Digest = %s", p); printf("\nTime = %ld seconds\n", (long) (endTime - startTime)); /* Be careful that endTime-startTime is not zero. (Bug fix from Ric * Anderson, ric@Artisoft.COM.) */ printf ("Speed = %ld bytes/second\n", (long) TEST_BLOCK_LEN * (long) TEST_BLOCK_COUNT / ((endTime - startTime) != 0 ? (endTime - startTime) : 1)); } /* * Digests a reference suite of strings and prints the results. */ static void MDTestSuite() { printf("MD5 test suite:\n"); MDString(""); MDString("a"); MDString("abc"); MDString("message digest"); MDString("abcdefghijklmnopqrstuvwxyz"); MDString ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"); MDString ("1234567890123456789012345678901234567890\ 1234567890123456789012345678901234567890"); } /* * Digests the standard input and prints the result. */ static void MDFilter(int pipe) { MD5_CTX context; int len; unsigned char buffer[BUFSIZ], digest[16]; + char buf[33]; MD5Init(&context); while (len = fread(buffer, 1, BUFSIZ, stdin)) { if(pipe && (len != fwrite(buffer, 1, len, stdout))) { perror("stdout"); exit(1); } MD5Update(&context, buffer, len); } - printf("%s\n", MD5End(&context)); + printf("%s\n", MD5End(&context,buf)); } Index: stable/2.1/usr.sbin/ctm/ctm/Makefile =================================================================== --- stable/2.1/usr.sbin/ctm/ctm/Makefile (revision 10587) +++ stable/2.1/usr.sbin/ctm/ctm/Makefile (revision 10588) @@ -1,25 +1,25 @@ # # ---------------------------------------------------------------------------- # "THE BEER-WARE LICENSE" (Revision 42): # wrote this file. As long as you retain this notice you # can do whatever you want with this stuff. If we meet some day, and you think # this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp # ---------------------------------------------------------------------------- # -# $Id: Makefile,v 1.7 1995/03/04 20:36:44 phk Exp $ +# $Id: Makefile,v 1.9 1995/07/12 18:35:22 bde Exp $ # PROG= ctm NOTYET= ctm_ed.c SRCS= ctm.c ctm_input.c ctm_pass1.c ctm_pass2.c ctm_pass3.c \ ctm_syntax.c ctm_ed.c LDADD+= -lmd DPADD+= ${LIBMD} MAN1= ctm.1 MAN5= ctm.5 -CFLAGS+= -Wall -g +CFLAGS+= -Wall .if exists(${.CURDIR}/../../Makefile.inc) .include "${.CURDIR}/../../Makefile.inc" .endif .include Index: stable/2.1/usr.sbin/ctm/ctm/ctm_pass1.c =================================================================== --- stable/2.1/usr.sbin/ctm/ctm/ctm_pass1.c (revision 10587) +++ stable/2.1/usr.sbin/ctm/ctm/ctm_pass1.c (revision 10588) @@ -1,205 +1,206 @@ /* * ---------------------------------------------------------------------------- * "THE BEER-WARE LICENSE" (Revision 42): * wrote this file. As long as you retain this notice you * can do whatever you want with this stuff. If we meet some day, and you think * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp * ---------------------------------------------------------------------------- * - * $Id: ctm_pass1.c,v 1.9 1995/03/26 20:09:52 phk Exp $ + * $Id: ctm_pass1.c,v 1.11 1995/07/12 09:16:08 phk Exp $ * */ #include "ctm.h" #define BADREAD 1 /*---------------------------------------------------------------------------*/ /* Pass1 -- Validate the incoming CTM-file. */ int Pass1(FILE *fd, unsigned applied) { u_char *p,*q; MD5_CTX ctx; int i,j,sep,cnt; u_char *md5=0,*trash=0; struct CTM_Syntax *sp; int slashwarn=0; unsigned current; + char md5_1[33]; if(Verbose>3) printf("Pass1 -- Checking integrity of incoming CTM-patch\n"); MD5Init (&ctx); GETFIELD(p,' '); /* CTM_BEGIN */ if(strcmp(p,"CTM_BEGIN")) { Fatal("Probably not a CTM-patch at all."); if(Verbose>3) fprintf(stderr,"Expected \"CTM_BEGIN\" got \"%s\".\n",p); return 1; } GETFIELDCOPY(Version,' '); /* */ if(strcmp(Version,VERSION)) { Fatal("CTM-patch is wrong version."); if(Verbose>3) fprintf(stderr,"Expected \"%s\" got \"%s\".\n",VERSION,p); return 1; } GETFIELDCOPY(Name,' '); /* */ GETFIELDCOPY(Nbr,' '); /* */ GETFIELDCOPY(TimeStamp,' '); /* */ GETFIELDCOPY(Prefix,'\n'); /* */ sscanf(Nbr, "%u", ¤t); if(current && current <= applied) { if(Verbose) fprintf(stderr,"Delta number %u is already applied; ignoring.\n", current); return Exit_Version; } for(;;) { if(md5) {Free(md5), md5 = 0;} if(trash) {Free(trash), trash = 0;} cnt = -1; GETFIELD(p,' '); /* CTM_something */ if (p[0] != 'C' || p[1] != 'T' || p[2] != 'M') { Fatal("Expected CTM keyword."); fprintf(stderr,"Got [%s]\n",p); return 1; } if(!strcmp(p+3,"_END")) break; for(sp=Syntax;sp->Key;sp++) if(!strcmp(p+3,sp->Key)) goto found; Fatal("Expected CTM keyword."); fprintf(stderr,"Got [%s]\n",p); return 1; found: if(Verbose > 5) fprintf(stderr,"%s ",sp->Key); for(i=0;(j = sp->List[i]);i++) { if (sp->List[i+1] && (sp->List[i+1] & CTM_F_MASK) != CTM_F_Bytes) sep = ' '; else sep = '\n'; if(Verbose > 5) fprintf(stderr," %x(%d)",sp->List[i],sep); switch (j & CTM_F_MASK) { case CTM_F_Name: /* XXX check for garbage and .. */ GETFIELD(p,sep); j = strlen(p); if(p[j-1] == '/' && !slashwarn) { fprintf(stderr,"Warning: contains trailing slash\n"); slashwarn++; } if (p[0] == '/') { Fatal("Absolute paths are illegal."); return Exit_Mess; } for (;;) { if (p[0] == '.' && p[1] == '.') if (p[2] == '/' || p[2] == '\0') { Fatal("Paths containing '..' are illegal."); return Exit_Mess; } if ((p = strchr(p, '/')) == NULL) break; p++; } break; case CTM_F_Uid: GETFIELD(p,sep); while(*p) { if(!isdigit(*p)) { Fatal("Non-digit in uid."); return 32; } p++; } break; case CTM_F_Gid: GETFIELD(p,sep); while(*p) { if(!isdigit(*p)) { Fatal("Non-digit in gid."); return 32; } p++; } break; case CTM_F_Mode: GETFIELD(p,sep); while(*p) { if(!isdigit(*p)) { Fatal("Non-digit in mode."); return 32; } p++; } break; case CTM_F_MD5: if(j & CTM_Q_MD5_Chunk) { GETFIELDCOPY(md5,sep); /* XXX check for garbage */ } else if(j & CTM_Q_MD5_Before) { GETFIELD(p,sep); /* XXX check for garbage */ } else if(j & CTM_Q_MD5_After) { GETFIELD(p,sep); /* XXX check for garbage */ } else { fprintf(stderr,"List = 0x%x\n",j); Fatal("Unqualified MD5."); return 32; } break; case CTM_F_Count: GETBYTECNT(cnt,sep); break; case CTM_F_Bytes: if(cnt < 0) WRONG GETDATA(trash,cnt); - p = MD5Data(trash,cnt); + p = MD5Data(trash,cnt,md5_1); if(md5 && strcmp(md5,p)) { Fatal("Internal MD5 failed."); return 1; default: fprintf(stderr,"List = 0x%x\n",j); Fatal("List had garbage."); return 1; } } } if(Verbose > 5) putc('\n',stderr); continue; } - q = MD5End (&ctx); + q = MD5End (&ctx,md5_1); if(Verbose > 2) printf("Expecting Global MD5 <%s>\n",q); GETFIELD(p,'\n'); /* */ if(Verbose > 2) printf("Reference Global MD5 <%s>\n",p); if(strcmp(q,p)) { Fatal("MD5 sum doesn't match."); fprintf(stderr,"\tI have:<%s>\n",q); fprintf(stderr,"\tShould have been:<%s>\n",p); return 1; } if (-1 != getc(fd)) { if(!Force) { Fatal("Trailing junk in CTM-file. Can Force with -F."); return 16; } } return 0; } Index: stable/2.1/usr.sbin/ctm/ctm/ctm_pass2.c =================================================================== --- stable/2.1/usr.sbin/ctm/ctm/ctm_pass2.c (revision 10587) +++ stable/2.1/usr.sbin/ctm/ctm/ctm_pass2.c (revision 10588) @@ -1,176 +1,177 @@ /* * ---------------------------------------------------------------------------- * "THE BEER-WARE LICENSE" (Revision 42): * wrote this file. As long as you retain this notice you * can do whatever you want with this stuff. If we meet some day, and you think * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp * ---------------------------------------------------------------------------- * - * $Id: ctm_pass2.c,v 1.7 1995/03/19 12:01:23 roberto Exp $ + * $Id: ctm_pass2.c,v 1.9 1995/07/12 09:16:10 phk Exp $ * */ #include "ctm.h" #define BADREAD 32 /*---------------------------------------------------------------------------*/ /* Pass2 -- Validate the incoming CTM-file. */ int Pass2(FILE *fd) { u_char *p,*q,*md5=0; MD5_CTX ctx; int i,j,sep,cnt; u_char *trash=0,*name=0; struct CTM_Syntax *sp; struct stat st; int ret = 0; + char md5_1[33]; if(Verbose>3) printf("Pass2 -- Checking if CTM-patch will apply\n"); MD5Init (&ctx); GETFIELD(p,' '); if(strcmp("CTM_BEGIN",p)) WRONG GETFIELD(p,' '); if(strcmp(Version,p)) WRONG GETFIELD(p,' '); if(strcmp(Name,p)) WRONG /* XXX Lookup name in /etc/ctm,conf, read stuff */ GETFIELD(p,' '); if(strcmp(Nbr,p)) WRONG /* XXX Verify that this is the next patch to apply */ GETFIELD(p,' '); if(strcmp(TimeStamp,p)) WRONG GETFIELD(p,'\n'); if(strcmp(Prefix,p)) WRONG /* XXX drop or use ? */ for(;;) { if(trash) {Free(trash), trash = 0;} if(name) {Free(name), name = 0;} if(md5) {Free(md5), md5 = 0;} cnt = -1; GETFIELD(p,' '); if (p[0] != 'C' || p[1] != 'T' || p[2] != 'M') WRONG if(!strcmp(p+3,"_END")) break; for(sp=Syntax;sp->Key;sp++) if(!strcmp(p+3,sp->Key)) goto found; WRONG found: for(i=0;(j = sp->List[i]);i++) { if (sp->List[i+1] && (sp->List[i+1] & CTM_F_MASK) != CTM_F_Bytes) sep = ' '; else sep = '\n'; switch (j & CTM_F_MASK) { case CTM_F_Name: GETFIELDCOPY(name,sep); /* XXX Check DR DM rec's for parent-dir */ if(j & CTM_Q_Name_New) { /* XXX Check DR FR rec's for item */ if(-1 != stat(name,&st)) { fprintf(stderr," %s: %s exists.\n", sp->Key,name); ret |= Exit_Forcible; } break; } if(-1 == stat(name,&st)) { fprintf(stderr," %s: %s doesn't exist.\n", sp->Key,name); if (sp->Key[1] == 'R') ret |= Exit_Forcible; else ret |= Exit_NotOK; break; } if (j & CTM_Q_Name_Dir) { if((st.st_mode & S_IFMT) != S_IFDIR) { fprintf(stderr, " %s: %s exist, but isn't dir.\n", sp->Key,name); ret |= Exit_NotOK; } break; } if (j & CTM_Q_Name_File) { if((st.st_mode & S_IFMT) != S_IFREG) { fprintf(stderr, " %s: %s exist, but isn't file.\n", sp->Key,name); ret |= Exit_NotOK; } break; } break; case CTM_F_Uid: case CTM_F_Gid: case CTM_F_Mode: GETFIELD(p,sep); break; case CTM_F_MD5: if(!name) WRONG if(j & CTM_Q_MD5_Before) { GETFIELD(p,sep); if((st.st_mode & S_IFMT) == S_IFREG && - strcmp(MD5File(name),p)) { + strcmp(MD5File(name,md5_1),p)) { fprintf(stderr," %s: %s md5 mismatch.\n", sp->Key,name); 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; } if(j & CTM_Q_MD5_After) { GETFIELDCOPY(md5,sep); break; } /* Unqualified MD5 */ WRONG break; case CTM_F_Count: GETBYTECNT(cnt,sep); break; case CTM_F_Bytes: if(cnt < 0) WRONG GETDATA(trash,cnt); if(!strcmp(sp->Key,"FN")) { p = tempnam(TmpDir,"CTMclient"); j = ctm_edit(trash,cnt,name,p); if(j) { fprintf(stderr," %s: %s edit returned %d.\n", sp->Key,name,j); ret |= j; return ret; - } else if(strcmp(md5,MD5File(p))) { + } else if(strcmp(md5,MD5File(p,md5_1))) { fprintf(stderr," %s: %s edit fails.\n", sp->Key,name); ret |= Exit_Mess; return ret; } unlink(p); free(p); } break; default: WRONG } } } - q = MD5End (&ctx); + q = MD5End (&ctx,md5_1); GETFIELD(p,'\n'); /* */ if(strcmp(q,p)) WRONG if (-1 != getc(fd)) WRONG return ret; } Index: stable/2.1/usr.sbin/ctm/ctm/ctm_pass3.c =================================================================== --- stable/2.1/usr.sbin/ctm/ctm/ctm_pass3.c (revision 10587) +++ stable/2.1/usr.sbin/ctm/ctm/ctm_pass3.c (revision 10588) @@ -1,184 +1,185 @@ /* * ---------------------------------------------------------------------------- * "THE BEER-WARE LICENSE" (Revision 42): * wrote this file. As long as you retain this notice you * can do whatever you want with this stuff. If we meet some day, and you think * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp * ---------------------------------------------------------------------------- * - * $Id: ctm_pass3.c,v 1.9 1995/03/25 20:46:51 joerg Exp $ + * $Id: ctm_pass3.c,v 1.11 1995/07/12 09:16:13 phk Exp $ * */ #include "ctm.h" #define BADREAD 32 /*---------------------------------------------------------------------------*/ /* Pass3 -- Validate the incoming CTM-file. */ int Pass3(FILE *fd) { u_char *p,*q,buf[BUFSIZ]; MD5_CTX ctx; int i,j,sep,cnt; u_char *md5=0,*md5before=0,*trash=0,*name=0,*uid=0,*gid=0,*mode=0; struct CTM_Syntax *sp; FILE *ed=0; struct stat st; + char md5_1[33]; if(Verbose>3) printf("Pass3 -- Applying the CTM-patch\n"); MD5Init (&ctx); GETFIELD(p,' '); if(strcmp("CTM_BEGIN",p)) WRONG GETFIELD(p,' '); if(strcmp(Version,p)) WRONG GETFIELD(p,' '); if(strcmp(Name,p)) WRONG GETFIELD(p,' '); if(strcmp(Nbr,p)) WRONG GETFIELD(p,' '); if(strcmp(TimeStamp,p)) WRONG GETFIELD(p,'\n'); if(strcmp(Prefix,p)) WRONG for(;;) { if(md5) {Free(md5), md5 = 0;} if(uid) {Free(uid), uid = 0;} if(gid) {Free(gid), gid = 0;} if(mode) {Free(mode), mode = 0;} if(md5before) {Free(md5before), md5before = 0;} if(trash) {Free(trash), trash = 0;} if(name) {Free(name), name = 0;} cnt = -1; GETFIELD(p,' '); if (p[0] != 'C' || p[1] != 'T' || p[2] != 'M') WRONG if(!strcmp(p+3,"_END")) break; for(sp=Syntax;sp->Key;sp++) if(!strcmp(p+3,sp->Key)) goto found; WRONG found: for(i=0;(j = sp->List[i]);i++) { if (sp->List[i+1] && (sp->List[i+1] & CTM_F_MASK) != CTM_F_Bytes) sep = ' '; else sep = '\n'; switch (j & CTM_F_MASK) { case CTM_F_Name: GETFIELDCOPY(name,sep); break; case CTM_F_Uid: GETFIELDCOPY(uid,sep); break; case CTM_F_Gid: GETFIELDCOPY(gid,sep); break; case CTM_F_Mode: GETFIELDCOPY(mode,sep); break; case CTM_F_MD5: if(j & CTM_Q_MD5_Before) GETFIELDCOPY(md5before,sep); else GETFIELDCOPY(md5,sep); break; case CTM_F_Count: GETBYTECNT(cnt,sep); break; case CTM_F_Bytes: GETDATA(trash,cnt); break; default: WRONG } } /* XXX This should go away. Disallow trailing '/' */ j = strlen(name)-1; if(name[j] == '/') name[j] = '\0'; fprintf(stderr,"> %s %s\n",sp->Key,name); if(!strcmp(sp->Key,"FM") || !strcmp(sp->Key, "FS")) { i = open(name,O_WRONLY|O_CREAT|O_TRUNC,0666); if(i < 0) { perror(name); WRONG } if(cnt != write(i,trash,cnt)) { perror(name); WRONG } close(i); - if(strcmp(md5,MD5File(name))) { + if(strcmp(md5,MD5File(name,md5_1))) { fprintf(stderr," %s %s MD5 didn't come out right\n", sp->Key,name); WRONG } continue; } if(!strcmp(sp->Key,"FE")) { ed = popen("ed","w"); if(!ed) { WRONG } fprintf(ed,"e %s\n",name); if(cnt != fwrite(trash,1,cnt,ed)) { perror(name); pclose(ed); WRONG } fprintf(ed,"w %s\n",name); if(pclose(ed)) { perror("ed"); WRONG } - if(strcmp(md5,MD5File(name))) { + if(strcmp(md5,MD5File(name,md5_1))) { fprintf(stderr," %s %s MD5 didn't come out right\n", sp->Key,name); WRONG } continue; } if(!strcmp(sp->Key,"FN")) { strcpy(buf,name); strcat(buf,".ctm"); i = ctm_edit(trash,cnt,name,buf); if(i) { fprintf(stderr," %s %s Edit failed with code %d.\n", sp->Key,name,i); WRONG } rename(buf,name); - if(strcmp(md5,MD5File(name))) { + if(strcmp(md5,MD5File(name,md5_1))) { fprintf(stderr," %s %s Edit failed MD5 check.\n", sp->Key,name); WRONG } continue; } if(!strcmp(sp->Key,"DM")) { if(0 > mkdir(name,0777)) { sprintf(buf,"mkdir -p %s",name); system(buf); } if(0 > stat(name,&st) || ((st.st_mode & S_IFMT) != S_IFDIR)) { fprintf(stderr,"<%s> mkdir failed\n",name); WRONG } continue; } if(!strcmp(sp->Key,"FR")) { if (0 != unlink(name)) { fprintf(stderr,"<%s> unlink failed\n",name); if (!Force) WRONG } continue; } if(!strcmp(sp->Key,"DR")) { /* * We cannot use rmdir() because we do not get the directories * in '-depth' order (cvs-cur.0018.gz for examples) */ sprintf(buf,"rm -rf %s",name); system(buf); continue; } WRONG } - q = MD5End (&ctx); + q = MD5End (&ctx,md5_1); GETFIELD(p,'\n'); if(strcmp(q,p)) WRONG if (-1 != getc(fd)) WRONG return 0; } Index: stable/2.1/usr.sbin/ctm/ctm_rmail/Makefile =================================================================== --- stable/2.1/usr.sbin/ctm/ctm_rmail/Makefile (revision 10587) +++ stable/2.1/usr.sbin/ctm/ctm_rmail/Makefile (revision 10588) @@ -1,6 +1,6 @@ PROG= ctm_rmail SRCS= ctm_rmail.c error.c -CFLAGS+= -Wall -g +CFLAGS+= -Wall MLINKS+= ctm_rmail.1 ctm_smail.1 .include Index: stable/2.1/usr.sbin/ctm/ctm_scan/ctm_scan.c =================================================================== --- stable/2.1/usr.sbin/ctm/ctm_scan/ctm_scan.c (revision 10587) +++ stable/2.1/usr.sbin/ctm/ctm_scan/ctm_scan.c (revision 10588) @@ -1,187 +1,187 @@ /* * ---------------------------------------------------------------------------- * "THE BEER-WARE LICENSE" (Revision 42): * wrote this file. As long as you retain this notice you * can do whatever you want with this stuff. If we meet some day, and you think * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp * ---------------------------------------------------------------------------- * - * $Id: ctm_scan.c,v 1.10 1995/03/24 21:36:32 phk Exp $ + * $Id: ctm_scan.c,v 1.12 1995/07/13 15:33:42 phk Exp $ * */ #include #include #include #include #include #include #include #include #include int barf[256]; int CheckMode = 0; int pstrcmp(const void *pp, const void *qq) { return strcmp(*(char **)pp,*(char **)qq); } int Do(char *path) { DIR *d; struct dirent *de; struct stat st; int ret=0; u_char buf[BUFSIZ]; u_char data[BUFSIZ],*q; int bufp; MD5_CTX ctx; int fd,i,j,k,l,npde,nde=0; - char **pde; + char **pde, md5[33]; npde = 1; pde = malloc(sizeof *pde * (npde+1)); d = opendir(path); if(!d) { perror(path); return 2; } if(!strcmp(path,".")) { *buf = 0; } else { strcpy(buf,path); if(buf[strlen(buf)-1] != '/') strcat(buf,"/"); } bufp = strlen(buf); while((de=readdir(d))) { if(!strcmp(de->d_name,".")) continue; if(!strcmp(de->d_name,"..")) continue; if(nde >= npde) { npde *= 2; pde = realloc(pde,sizeof *pde * (npde+1)); } strcpy(buf+bufp,de->d_name); if(stat(buf,&st)) { ret |= 1; continue; } pde[nde] = malloc(strlen(buf+bufp)+1); strcpy(pde[nde++],buf+bufp); } closedir(d); if(!nde) return 0; qsort(pde,nde,sizeof *pde, pstrcmp); for(k=0;k 1 && !strcmp(argv[1],"-c")) { CheckMode=1; argc--; argv++; } /* * First argument, if any, is where to do the work. */ if (argc > 1) { if(chdir(argv[1])) { perror(argv[1]); return 2; } argc--; argv++; } /* * Scan the directories recursively. */ if (argc > 1) { while (argc > 1) { i = Do(argv[1]); argc--; argv++; if (i) return i; } return i; } else return Do("."); } Index: stable/2.1/usr.sbin/ctm/ctm_smail/Makefile =================================================================== --- stable/2.1/usr.sbin/ctm/ctm_smail/Makefile (revision 10587) +++ stable/2.1/usr.sbin/ctm/ctm_smail/Makefile (revision 10588) @@ -1,7 +1,7 @@ PROG= ctm_smail SRCS= ctm_smail.c error.c NOMAN= 1 -CFLAGS+= -Wall -g -I${.CURDIR}/../ctm_rmail +CFLAGS+= -Wall -I${.CURDIR}/../ctm_rmail +.PATH: ${.CURDIR}/../ctm_rmail .include -.PATH: ${.CURDIR}/../ctm_rmail Index: stable/2.1/usr.sbin/mtree/compare.c =================================================================== --- stable/2.1/usr.sbin/mtree/compare.c (revision 10587) +++ stable/2.1/usr.sbin/mtree/compare.c (revision 10588) @@ -1,292 +1,289 @@ /*- * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #ifndef lint static char sccsid[] = "@(#)compare.c 8.1 (Berkeley) 6/6/93"; #endif /* not lint */ #include #include #include #include #include #include #include #include #include #include "mtree.h" #include "extern.h" extern int uflag; static char *ftype __P((u_int)); #define INDENTNAMELEN 8 #define LABEL \ if (!label++) { \ len = printf("%s: ", RP(p)); \ if (len > INDENTNAMELEN) { \ tab = "\t"; \ (void)printf("\n"); \ } else { \ tab = ""; \ (void)printf("%*s", INDENTNAMELEN - (int)len, ""); \ } \ } int compare(name, s, p) char *name; register NODE *s; register FTSENT *p; { extern int uflag; u_long len, val; int fd, label; char *cp, *tab = ""; label = 0; switch(s->type) { case F_BLOCK: if (!S_ISBLK(p->fts_statp->st_mode)) goto typeerr; break; case F_CHAR: if (!S_ISCHR(p->fts_statp->st_mode)) goto typeerr; break; case F_DIR: if (!S_ISDIR(p->fts_statp->st_mode)) goto typeerr; break; case F_FIFO: if (!S_ISFIFO(p->fts_statp->st_mode)) goto typeerr; break; case F_FILE: if (!S_ISREG(p->fts_statp->st_mode)) goto typeerr; break; case F_LINK: if (!S_ISLNK(p->fts_statp->st_mode)) goto typeerr; break; case F_SOCK: if (!S_ISSOCK(p->fts_statp->st_mode)) { typeerr: LABEL; (void)printf("\ttype (%s, %s)\n", ftype(s->type), inotype(p->fts_statp->st_mode)); } break; } /* Set the uid/gid first, then set the mode. */ if (s->flags & (F_UID | F_UNAME) && s->st_uid != p->fts_statp->st_uid) { LABEL; (void)printf("%suser (%lu, %lu", tab, s->st_uid, p->fts_statp->st_uid); if (uflag) if (chown(p->fts_accpath, s->st_uid, -1)) (void)printf(", not modified: %s)\n", strerror(errno)); else (void)printf(", modified)\n"); else (void)printf(")\n"); tab = "\t"; } if (s->flags & (F_GID | F_GNAME) && s->st_gid != p->fts_statp->st_gid) { LABEL; (void)printf("%sgid (%lu, %lu", tab, s->st_gid, p->fts_statp->st_gid); if (uflag) if (chown(p->fts_accpath, -1, s->st_gid)) (void)printf(", not modified: %s)\n", strerror(errno)); else (void)printf(", modified)\n"); else (void)printf(")\n"); tab = "\t"; } if (s->flags & F_MODE && s->st_mode != (p->fts_statp->st_mode & MBITS)) { LABEL; (void)printf("%spermissions (%#o, %#o", tab, s->st_mode, p->fts_statp->st_mode & MBITS); if (uflag) if (chmod(p->fts_accpath, s->st_mode)) (void)printf(", not modified: %s)\n", strerror(errno)); else (void)printf(", modified)\n"); else (void)printf(")\n"); tab = "\t"; } if (s->flags & F_NLINK && s->type != F_DIR && s->st_nlink != p->fts_statp->st_nlink) { LABEL; (void)printf("%slink count (%u, %u)\n", tab, s->st_nlink, p->fts_statp->st_nlink); tab = "\t"; } if (s->flags & F_SIZE && s->st_size != p->fts_statp->st_size) { LABEL; (void)printf("%ssize (%qd, %qd)\n", tab, s->st_size, p->fts_statp->st_size); tab = "\t"; } /* * XXX * Catches nano-second differences, but doesn't display them. */ if ((s->flags & F_TIME) && ((s->st_mtimespec.ts_sec != p->fts_statp->st_mtimespec.ts_sec) || (s->st_mtimespec.ts_nsec != p->fts_statp->st_mtimespec.ts_nsec))) { LABEL; (void)printf("%smodification time (%.24s, ", tab, ctime(&s->st_mtimespec.ts_sec)); (void)printf("%.24s)\n", ctime(&p->fts_statp->st_mtimespec.ts_sec)); tab = "\t"; } if (s->flags & F_CKSUM) if ((fd = open(p->fts_accpath, O_RDONLY, 0)) < 0) { LABEL; (void)printf("%scksum: %s: %s\n", tab, p->fts_accpath, strerror(errno)); tab = "\t"; } else if (crc(fd, &val, &len)) { (void)close(fd); LABEL; (void)printf("%scksum: %s: %s\n", tab, p->fts_accpath, strerror(errno)); tab = "\t"; } else { (void)close(fd); if (s->cksum != val) { LABEL; (void)printf("%scksum (%lu, %lu)\n", tab, s->cksum, val); } tab = "\t"; } if (s->flags & F_MD5) { - char *new_digest; + char *new_digest, buf[33]; - new_digest = MD5File(p->fts_accpath); + new_digest = MD5File(p->fts_accpath,buf); if (!new_digest) { LABEL; printf("%sMD5File: %s: %s\n", tab, p->fts_accpath, strerror(errno)); tab = "\t"; } else if (strcmp(new_digest, s->md5digest)) { LABEL; printf("%sMD5 (%s, %s)\n", tab, s->md5digest, new_digest); tab = "\t"; - free(new_digest); - } else { - free(new_digest); } } if (s->flags & F_SLINK && strcmp(cp = rlink(name), s->slink)) { LABEL; (void)printf("%slink ref (%s, %s)\n", tab, cp, s->slink); } return (label); } char * inotype(type) u_int type; { switch(type & S_IFMT) { case S_IFBLK: return ("block"); case S_IFCHR: return ("char"); case S_IFDIR: return ("dir"); case S_IFIFO: return ("fifo"); case S_IFREG: return ("file"); case S_IFLNK: return ("link"); case S_IFSOCK: return ("socket"); default: return ("unknown"); } /* NOTREACHED */ } static char * ftype(type) u_int type; { switch(type) { case F_BLOCK: return ("block"); case F_CHAR: return ("char"); case F_DIR: return ("dir"); case F_FIFO: return ("fifo"); case F_FILE: return ("file"); case F_LINK: return ("link"); case F_SOCK: return ("socket"); default: return ("unknown"); } /* NOTREACHED */ } char * rlink(name) char *name; { static char lbuf[MAXPATHLEN]; register int len; if ((len = readlink(name, lbuf, sizeof(lbuf))) == -1) err("%s: %s", name, strerror(errno)); lbuf[len] = '\0'; return (lbuf); } Index: stable/2.1/usr.sbin/mtree/create.c =================================================================== --- stable/2.1/usr.sbin/mtree/create.c (revision 10587) +++ stable/2.1/usr.sbin/mtree/create.c (revision 10588) @@ -1,344 +1,344 @@ /*- * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #ifndef lint static char sccsid[] = "@(#)create.c 8.1 (Berkeley) 6/6/93"; #endif /* not lint */ #include #include #include #include #include #include #include #include #include #include #include #include #include "mtree.h" #include "extern.h" #define INDENTNAMELEN 15 #define MAXLINELEN 80 extern long int crc_total; extern int ftsoptions; extern int dflag, iflag, nflag, sflag; extern u_short keys; extern char fullpath[MAXPATHLEN]; static gid_t gid; static uid_t uid; static mode_t mode; static int dsort __P((const FTSENT **, const FTSENT **)); static void output __P((int, int *, const char *, ...)); static int statd __P((FTS *, FTSENT *, uid_t *, gid_t *, mode_t *)); static void statf __P((int, FTSENT *)); void cwalk() { register FTS *t; register FTSENT *p; time_t clock; char *argv[2], host[MAXHOSTNAMELEN]; int indent = 0; (void)time(&clock); (void)gethostname(host, sizeof(host)); (void)printf( "#\t user: %s\n#\tmachine: %s\n#\t tree: %s\n#\t date: %s", getlogin(), host, fullpath, ctime(&clock)); argv[0] = "."; argv[1] = NULL; if ((t = fts_open(argv, ftsoptions, dsort)) == NULL) err("fts_open: %s", strerror(errno)); while ((p = fts_read(t))) { if (iflag) indent = p->fts_level * 4; switch(p->fts_info) { case FTS_D: if (!dflag) (void)printf("\n"); if (!nflag) (void)printf("# %s\n", p->fts_path); statd(t, p, &uid, &gid, &mode); statf(indent, p); break; case FTS_DP: if (!nflag && (p->fts_level > 0)) (void)printf("%*s# %s\n", indent, "", p->fts_path); (void)printf("%*s..\n", indent, ""); if (!dflag) (void)printf("\n"); break; case FTS_DNR: case FTS_ERR: case FTS_NS: (void)fprintf(stderr, "mtree: %s: %s\n", p->fts_path, strerror(p->fts_errno)); break; default: if (!dflag) statf(indent, p); break; } } (void)fts_close(t); if (sflag && keys & F_CKSUM) (void)fprintf(stderr, "mtree: %s checksum: %lu\n", fullpath, crc_total); } static void statf(indent, p) int indent; FTSENT *p; { struct group *gr; struct passwd *pw; u_long len, val; int fd, offset; if (iflag || S_ISDIR(p->fts_statp->st_mode)) offset = printf("%*s%s", indent, "", p->fts_name); else offset = printf("%*s %s", indent, "", p->fts_name); if (offset > (INDENTNAMELEN + indent)) offset = MAXLINELEN; else offset += printf("%*s", (INDENTNAMELEN + indent) - offset, ""); if (!S_ISREG(p->fts_statp->st_mode) && !dflag) output(indent, &offset, "type=%s", inotype(p->fts_statp->st_mode)); if (p->fts_statp->st_uid != uid) { if (keys & F_UNAME) { if ((pw = getpwuid(p->fts_statp->st_uid)) != NULL) { output(indent, &offset, "uname=%s", pw->pw_name); } else { err("could not get uname for uid=%u", p->fts_statp->st_uid); } } if (keys & F_UID) output(indent, &offset, "uid=%u", p->fts_statp->st_uid); } if (p->fts_statp->st_gid != gid) { if (keys & F_GNAME) { if ((gr = getgrgid(p->fts_statp->st_gid)) != NULL) { output(indent, &offset, "gname=%s", gr->gr_name); } else { err("could not get gname for gid=%u", p->fts_statp->st_gid); } } if (keys & F_GID) output(indent, &offset, "gid=%u", p->fts_statp->st_gid); } if (keys & F_MODE && (p->fts_statp->st_mode & MBITS) != mode) output(indent, &offset, "mode=%#o", p->fts_statp->st_mode & MBITS); if (keys & F_NLINK && p->fts_statp->st_nlink != 1) output(indent, &offset, "nlink=%u", p->fts_statp->st_nlink); if (keys & F_SIZE) output(indent, &offset, "size=%qd", p->fts_statp->st_size); if (keys & F_TIME) output(indent, &offset, "time=%ld.%ld", p->fts_statp->st_mtimespec.ts_sec, p->fts_statp->st_mtimespec.ts_nsec); if (keys & F_CKSUM && S_ISREG(p->fts_statp->st_mode)) { if ((fd = open(p->fts_accpath, O_RDONLY, 0)) < 0 || crc(fd, &val, &len)) err("%s: %s", p->fts_accpath, strerror(errno)); (void)close(fd); output(indent, &offset, "cksum=%lu", val); } if (keys & F_MD5 && S_ISREG(p->fts_statp->st_mode)) { - char *md5digest = MD5File(p->fts_accpath); + char *md5digest, buf[33]; + md5digest = MD5File(p->fts_accpath,buf); if (!md5digest) { err("%s: %s", p->fts_accpath, strerror(errno)); } else { output(indent, &offset, "md5digest=%s", md5digest); - free(md5digest); } } if (keys & F_SLINK && (p->fts_info == FTS_SL || p->fts_info == FTS_SLNONE)) output(indent, &offset, "link=%s", rlink(p->fts_accpath)); (void)putchar('\n'); } #define MAXGID 5000 #define MAXUID 5000 #define MAXMODE MBITS + 1 static int statd(t, parent, puid, pgid, pmode) FTS *t; FTSENT *parent; uid_t *puid; gid_t *pgid; mode_t *pmode; { register FTSENT *p; register gid_t sgid; register uid_t suid; register mode_t smode; struct group *gr; struct passwd *pw; gid_t savegid = *pgid; uid_t saveuid = *puid; mode_t savemode = *pmode; u_short maxgid, maxuid, maxmode, g[MAXGID], u[MAXUID], m[MAXMODE]; static int first = 1; if ((p = fts_children(t, 0)) == NULL) { if (errno) err("%s: %s", RP(parent), strerror(errno)); return (1); } bzero(g, sizeof(g)); bzero(u, sizeof(u)); bzero(m, sizeof(m)); maxuid = maxgid = maxmode = 0; for (; p; p = p->fts_link) { if (!dflag || (dflag && S_ISDIR(p->fts_statp->st_mode))) { smode = p->fts_statp->st_mode & MBITS; if (smode < MAXMODE && ++m[smode] > maxmode) { savemode = smode; maxmode = m[smode]; } sgid = p->fts_statp->st_gid; if (sgid < MAXGID && ++g[sgid] > maxgid) { savegid = sgid; maxgid = g[sgid]; } suid = p->fts_statp->st_uid; if (suid < MAXUID && ++u[suid] > maxuid) { saveuid = suid; maxuid = u[suid]; } } } /* * If the /set record is the same as the last one we do not need to output * a new one. So first we check to see if anything changed. Note that we * always output a /set record for the first directory. */ if ((((keys & F_UNAME) | (keys & F_UID)) && (*puid != saveuid)) || (((keys & F_GNAME) | (keys & F_GID)) && (*pgid != savegid)) || ((keys & F_MODE) && (*pmode != savemode)) || (first)) { first = 0; if (dflag) (void)printf("/set type=dir"); else (void)printf("/set type=file"); if (keys & F_UNAME) if ((pw = getpwuid(saveuid)) != NULL) (void)printf(" uname=%s", pw->pw_name); else err("could not get uname for uid=%u", saveuid); if (keys & F_UID) (void)printf(" uid=%lu", saveuid); if (keys & F_GNAME) if ((gr = getgrgid(savegid)) != NULL) (void)printf(" gname=%s", gr->gr_name); else err("could not get gname for gid=%u", savegid); if (keys & F_GID) (void)printf(" gid=%lu", savegid); if (keys & F_MODE) (void)printf(" mode=%#o", savemode); if (keys & F_NLINK) (void)printf(" nlink=1"); (void)printf("\n"); *puid = saveuid; *pgid = savegid; *pmode = savemode; } return (0); } static int dsort(a, b) const FTSENT **a, **b; { if (S_ISDIR((*a)->fts_statp->st_mode)) { if (!S_ISDIR((*b)->fts_statp->st_mode)) return (1); } else if (S_ISDIR((*b)->fts_statp->st_mode)) return (-1); return (strcmp((*a)->fts_name, (*b)->fts_name)); } #if __STDC__ #include #else #include #endif void #if __STDC__ output(int indent, int *offset, const char *fmt, ...) #else output(indent, offset, fmt, va_alist) int indent; int *offset; char *fmt; va_dcl #endif { va_list ap; char buf[1024]; #if __STDC__ va_start(ap, fmt); #else va_start(ap); #endif (void)vsnprintf(buf, sizeof(buf), fmt, ap); va_end(ap); if (*offset + strlen(buf) > MAXLINELEN - 3) { (void)printf(" \\\n%*s", INDENTNAMELEN + indent, ""); *offset = INDENTNAMELEN + indent; } *offset += printf(" %s", buf) + 1; }