xref: /plan9/sys/src/cmd/auth/readnvram.c (revision b1c161c21052bbfab8430c267211155c26021160)
1 /* readnvram */
2 #include <u.h>
3 #include <libc.h>
4 #include <auth.h>
5 #include <authsrv.h>
6 
7 void
main(int,char **)8 main(int, char **)
9 {
10 	int i;
11 	Nvrsafe safe;
12 
13 	quotefmtinstall();
14 
15 	memset(&safe, 0, sizeof safe);
16 	/*
17 	 * readnvram can return -1 meaning nvram wasn't written,
18 	 * but safe still holds good data.
19 	 */
20 	if(readnvram(&safe, 0) < 0 && safe.authid[0] == '\0')
21 		sysfatal("readnvram: %r");
22 
23 	/*
24 	 *  only use nvram key if it is non-zero
25 	 */
26 	for(i = 0; i < DESKEYLEN; i++)
27 		if(safe.machkey[i] != 0)
28 			break;
29 	if(i == DESKEYLEN)
30 		sysfatal("bad key");
31 
32 	fmtinstall('H', encodefmt);
33 	print("key proto=p9sk1 user=%q dom=%q !hex=%.*H !password=______\n",
34 		safe.authid, safe.authdom, DESKEYLEN, safe.machkey);
35 	exits(0);
36 }
37