1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
|
/*
* The author of this software is Matt Blaze.
* Copyright (c) 1992, 1994 by AT&T.
* Permission to use, copy, and modify this software without fee
* is hereby granted, provided that this entire notice is included in
* all copies of any software which is or includes a copy or
* modification of this software and in all copies of the supporting
* documentation for such software.
*
* This software is subject to United States export controls.
*
* THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR AT&T MAKE ANY
* REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
* OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
*/
/*
* cfs ccat - 1.3
*/
#include <stdio.h>
#include <rpc/rpc.h>
#include <sys/time.h>
#include <sys/file.h>
#include <sys/stat.h>
#ifdef SOLARIS2X
#include <string.h>
#define rindex strrchr
#else
#include <strings.h>
#endif
#include "nfsproto.h"
#include "admproto.h"
#include "cfs.h"
/* following are never used - just so i can re-use the library */
int validhost;
char zerovect[]={0,0,0,0,0,0,0,0,0};
int cursecs=0;
main(argc,argv)
int argc;
char **argv;
{
char *pw;
char pword[256];
char *getpassword();
cfs_admkey k;
cfskey kt;
char *flg;
char *p;
char ivfile[1024];
char base[1024];
char iv[16];
int fd;
int len;
int siz;
int offset;
int i;
char *buf[8192];
int ciph=CFS_THREE_DES;
fprintf(stderr,"WARNING: ccat works only on old format CFS files\n");
while (--argc && (**++argv == '-')) {
for (flg= ++*argv; *flg; ++flg)
switch (*flg) {
case '1':
ciph=CFS_STD_DES;
break;
case '3':
ciph=CFS_THREE_DES;
break;
case 'b':
ciph=CFS_BLOWFISH;
break;
case 'm':
ciph=CFS_MACGUFFIN;
break;
case 's':
ciph=CFS_SAFER_SK128;
break;
default:
fprintf(stderr,"usage: ccat [-13bms] file...\n");
exit(1);
}
}
if (argc<1) {
fprintf(stderr,"Usage: ccat [-3bms] file...\n");
exit(1);
}
if ((pw=getpassword("Key:"))==NULL) {
fprintf(stderr,"Can't get key\n");
exit(1);
}
strcpy(pword,pw);
k.cipher=ciph;
if (old_pwcrunch(pw,&k)!=0) {
fprintf(stderr,"Invalid key\n");
exit(1);
}
copykey(&k,&kt);
kt.smsize=LARGESMSIZE;
if (((kt.primask=(char*) malloc(kt.smsize)) == NULL)
|| ((kt.secmask=(char*) malloc(kt.smsize)) == NULL)) {
fprintf(stderr,"No memory\n");
exit(2);
}
genmasks(&kt);
for (i=0; i<argc; i++) {
int l;
strncpy(ivfile, argv[i], 1023); ivfile[1023] =0;
if ((p=rindex(ivfile,'/'))==NULL) {
l =snprintf(ivfile, 1024, ".pvect_%s", argv[i]);
if (l < 0 || l >= 1024) {
fprintf(stderr, "File name too long\n");
continue;
}
}
else {
*p='\0';
strcpy(base,++p);
snprintf(ivfile, 1024, "%s/.pvect_%s", ivfile, base);
if (l < 0 || l >= 1024) {
fprintf(stderr, "File name too long\n");
continue;
}
}
if (readlink(ivfile,iv,8) != 8)
bcopy(zerovect,iv,8);
fprintf(stderr,"%s %s\n",ivfile,iv);
if ((fd=open(argv[i],O_RDONLY,0))<0) {
perror(argv[i]);
continue;
}
len=flen(fd);
fprintf(stderr,"%s %d\n",argv[i],len);
for (offset=0; offset<len;){
siz=len-offset;
if (siz>8192)
siz=8192;
siz=readblock(buf,fd,offset,siz,&kt,iv);
write(1,buf,siz);
offset+=siz;
}
}
}
flen(fd)
int fd;
{
struct stat sb;
if (fstat(fd,&sb)<0)
return -1;
return dtov(sb.st_size);
}
|