void main(int argc, char *argv[]) { Dir *d; char *p, *file; int fd, len; ARGBEGIN{ case 'p': usepass = 1; break; case 'v': verb = 1; break; case 'a': convaes = 1; break; default: usage(); } ARGEND if(argc != 1) usage(); file = argv[0]; /* get original key */ if(usepass) { print("enter password file is encoded with\n"); getpass(&okey, nil, 0, 1); } else { getauthkey(&okey); } if(!verb) { print("enter password to reencode with\n"); getpass(&nkey, nil, 0, 1); } fd = open(file, ORDWR); if(fd < 0) error("can't open %s: %r\n", file); d = dirfstat(fd); if(d == nil) error("can't stat %s: %r\n", file); len = d->length; p = malloc(len); if(p == nil) error("out of memory"); if(read(fd, p, len) != len) error("can't read key file: %r\n"); len = convert(&p, len); if(pwrite(fd, p, len, 0) != len) error("can't write key file: %r\n"); close(fd); exits(nil); }
void main(int argc, char *argv[]) { Dir *d; char *p, *np, *file, key[DESKEYLEN]; int fd, len; ARGBEGIN{ case 'v': verb = 1; break; case 'p': usepass = 1; break; default: usage(); }ARGEND if(argc != 1) usage(); file = argv[0]; /* get original key */ if(usepass){ print("enter password file is encoded with\n"); getpass(authkey, nil, 0, 1); } else getauthkey(authkey); print("enter password to reencode with\n"); getpass(key, nil, 0, 1); fd = open(file, ORDWR); if(fd < 0) error("can't open %s: %r\n", file); d = dirfstat(fd); if(d == nil) error("can't stat %s: %r\n", file); len = d->length; p = malloc(len); if(!p) error("out of memory"); np = malloc((len/OKEYDBLEN)*KEYDBLEN + KEYDBOFF); if(!np) error("out of memory"); if(read(fd, p, len) != len) error("can't read key file: %r\n"); len = convert(p, np, key, len); if(verb) exits(0); if(pwrite(fd, np, len, 0) != len) error("can't write key file: %r\n"); close(fd); exits(0); }