xref: /plan9/sys/src/cmd/auth/lib/getauthkey.c (revision 4727cc49fce24ba84abe29b3bce2810b82f17507)
1 #include <u.h>
2 #include <libc.h>
3 #include <authsrv.h>
4 #include <bio.h>
5 #include "authcmdlib.h"
6 
7 static int
getkey(char * authkey)8 getkey(char *authkey)
9 {
10 	Nvrsafe safe;
11 
12 	if(readnvram(&safe, 0) < 0)
13 		return -1;
14 	memmove(authkey, safe.machkey, DESKEYLEN);
15 	memset(&safe, 0, sizeof safe);
16 	return 0;
17 }
18 
19 int
getauthkey(char * authkey)20 getauthkey(char *authkey)
21 {
22 	if(getkey(authkey) == 0)
23 		return 1;
24 	print("can't read NVRAM, please enter machine key\n");
25 	getpass(authkey, nil, 0, 1);
26 	return 1;
27 }
28