-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathccat.c
129 lines (123 loc) · 2.86 KB
/
ccat.c
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
/*
* 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>
#include <strings.h>
#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_SAFER_SK128;;
fprintf(stderr,"WARNING: ccat works only on old format CFS files\n");
while (--argc && (**++argv == '-')) {
for (flg= ++*argv; *flg; ++flg)
switch (*flg) {
case 's':
ciph=CFS_SAFER_SK128;
break;
default:
fprintf(stderr,"usage: ccat file...\n");
exit(1);
}
}
if (argc<1) {
fprintf(stderr,"Usage: ccat 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++) {
strcpy(ivfile,argv[i]);
if ((p=rindex(ivfile,'/'))==NULL)
sprintf(ivfile,".pvect_%s",argv[i]);
else {
*p='\0';
strcpy(base,++p);
sprintf(ivfile,"%s/.pvect_%s",ivfile,base);
}
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);
}