readnvram.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. /* readnvram */
  10. #include <u.h>
  11. #include <libc.h>
  12. #include <auth.h>
  13. #include <authsrv.h>
  14. void
  15. main(int n, char **g)
  16. {
  17. int i;
  18. Nvrsafe safe;
  19. quotefmtinstall();
  20. memset(&safe, 0, sizeof safe);
  21. /*
  22. * readnvram can return -1 meaning nvram wasn't written,
  23. * but safe still holds good data.
  24. */
  25. if(readnvram(&safe, 0) < 0 && safe.authid[0] == '\0')
  26. sysfatal("readnvram: %r");
  27. /*
  28. * only use nvram key if it is non-zero
  29. */
  30. for(i = 0; i < DESKEYLEN; i++)
  31. if(safe.machkey[i] != 0)
  32. break;
  33. if(i == DESKEYLEN)
  34. sysfatal("bad key");
  35. fmtinstall('H', encodefmt);
  36. print("key proto=p9sk1 user=%q dom=%q !hex=%.*H !password=______\n",
  37. safe.authid, safe.authdom, DESKEYLEN, safe.machkey);
  38. exits(0);
  39. }