summaryrefslogtreecommitdiff
path: root/sys/src/cmd/auth/lib/getauthkey.c
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2016-07-31 20:16:25 +0200
committercinap_lenrek <cinap_lenrek@felloff.net>2016-07-31 20:16:25 +0200
commit261e3190929acd3e8e00507894789a5575fb815f (patch)
tree8d877d68090967ed4231c457dabed6d64d8bc002 /sys/src/cmd/auth/lib/getauthkey.c
parenta75f4de5c9f1782b3a7e0a9648e24b360031a0d5 (diff)
auth: various cleanups, use common readcons() from libauthsrv, zero keys after use
Diffstat (limited to 'sys/src/cmd/auth/lib/getauthkey.c')
-rw-r--r--sys/src/cmd/auth/lib/getauthkey.c29
1 files changed, 11 insertions, 18 deletions
diff --git a/sys/src/cmd/auth/lib/getauthkey.c b/sys/src/cmd/auth/lib/getauthkey.c
index 48437e808..45e1b3b27 100644
--- a/sys/src/cmd/auth/lib/getauthkey.c
+++ b/sys/src/cmd/auth/lib/getauthkey.c
@@ -1,29 +1,22 @@
#include <u.h>
#include <libc.h>
-#include <authsrv.h>
#include <bio.h>
+#include <authsrv.h>
#include "authcmdlib.h"
-static int
-getkey(Authkey *authkey)
-{
- Nvrsafe safe;
-
- if(readnvram(&safe, 0) < 0)
- return -1;
- memmove(authkey->des, safe.machkey, DESKEYLEN);
- memmove(authkey->aes, safe.aesmachkey, AESKEYLEN);
- memset(&safe, 0, sizeof safe);
- return 0;
-}
-
int
getauthkey(Authkey *authkey)
{
+ Nvrsafe safe;
+
memset(authkey, 0, sizeof(Authkey));
- if(getkey(authkey) == 0)
- return 1;
- print("can't read NVRAM, please enter machine key\n");
- getpass(authkey, nil, 0, 1);
+ if(readnvram(&safe, 0) < 0){
+ print("can't read NVRAM, please enter machine key\n");
+ getpass(authkey, nil, 0, 1);
+ } else {
+ memmove(authkey->des, safe.machkey, DESKEYLEN);
+ memmove(authkey->aes, safe.aesmachkey, AESKEYLEN);
+ memset(&safe, 0, sizeof safe);
+ }
return 1;
}