diff options
Diffstat (limited to 'appl/cmd/auth/secstore.b')
| -rw-r--r-- | appl/cmd/auth/secstore.b | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/appl/cmd/auth/secstore.b b/appl/cmd/auth/secstore.b index e26e132d..3bebd29b 100644 --- a/appl/cmd/auth/secstore.b +++ b/appl/cmd/auth/secstore.b @@ -199,7 +199,25 @@ Auth: secstore->erasekey(file); file = nil; verb('x', fname); - 'r' or * => + 'r' => + checkname(fname, 1); + fd := sys->open(fname, sys->OREAD); + if(fd == nil) + error(sys->sprint("open %q: %r", fname)); + (ok, dir) := sys->fstat(fd); + if(ok != 0) + error(sys->sprint("stat %q: %r", fname)); + if(int dir.length > Maxfilesize) + error(sys->sprint("length %bd > Maxfilesize %d", dir.length, Maxfilesize)); + file = array[int dir.length] of byte; + if(sys->readn(fd, file, len file) != len file) + error(sys->sprint("short read: %r")); + if(putfile(conn, fname, file, filekey) < 0) + error(sys->sprint("putfile: %r")); + secstore->erasekey(file); + file = nil; + verb('r', fname); + * => error(sys->sprint("op %c not implemented", op)); } } @@ -242,6 +260,14 @@ getfile(conn: ref Dial->Connection, fname: string, key: array of byte): array of return f; } +putfile(conn: ref Dial->Connection, fname: string, data, key: array of byte): int +{ + data = secstore->encrypt(data, key); + if(data == nil) + return -1; + return secstore->putfile(conn, fname, data); +} + erase() { if(secstore != nil){ |
