password.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * GRUB -- GRand Unified Bootloader
  3. * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2006
  4. * 2007, 2008, 2009, 2010, 2011, 2012, 2013 Free Software Foundation, Inc.
  5. *
  6. * GRUB is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * GRUB is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <grub/crypto.h>
  20. #include <grub/mm.h>
  21. #include <grub/term.h>
  22. #include <windows.h>
  23. #include <stdlib.h>
  24. #include <string.h>
  25. #include <stdio.h>
  26. int
  27. grub_password_get (char buf[], unsigned buf_size)
  28. {
  29. HANDLE hStdin = GetStdHandle (STD_INPUT_HANDLE);
  30. DWORD mode = 0;
  31. char *ptr;
  32. grub_refresh ();
  33. GetConsoleMode (hStdin, &mode);
  34. SetConsoleMode (hStdin, mode & (~ENABLE_ECHO_INPUT));
  35. fgets (buf, buf_size, stdin);
  36. ptr = buf + strlen (buf) - 1;
  37. while (buf <= ptr && (*ptr == '\n' || *ptr == '\r'))
  38. *ptr-- = 0;
  39. SetConsoleMode (hStdin, mode);
  40. grub_refresh ();
  41. return 1;
  42. }