source: grub-pc/trunk/fuentes/grub-core/osdep/unix/password.c @ 22

Last change on this file since 22 was 22, checked in by mabarracus, 4 years ago

updated version and apply net.ifnames=0 into debian/rules

File size: 1.8 KB
Line 
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
20#include <grub/crypto.h>
21#include <grub/mm.h>
22#include <grub/term.h>
23
24#include <termios.h>
25#include <stdlib.h>
26#include <string.h>
27#include <stdio.h>
28
29int
30grub_password_get (char buf[], unsigned buf_size)
31{
32  FILE *in;
33  struct termios s, t;
34  int tty_changed = 0;
35  char *ptr;
36
37  grub_refresh ();
38
39  /* Disable echoing. Based on glibc.  */
40  in = fopen ("/dev/tty", "w+c");
41  if (in == NULL)
42    in = stdin;
43
44  if (tcgetattr (fileno (in), &t) == 0)
45    {
46      /* Save the old one. */
47      s = t;
48      /* Tricky, tricky. */
49      t.c_lflag &= ~(ECHO|ISIG);
50      tty_changed = (tcsetattr (fileno (in), TCSAFLUSH, &t) == 0);
51    }
52  else
53    tty_changed = 0;
54  grub_memset (buf, 0, buf_size);
55  if (!fgets (buf, buf_size, stdin))
56    return 0;
57  ptr = buf + strlen (buf) - 1;
58  while (buf <= ptr && (*ptr == '\n' || *ptr == '\r'))
59    *ptr-- = 0;
60  /* Restore the original setting.  */
61  if (tty_changed)
62    (void) tcsetattr (fileno (in), TCSAFLUSH, &s);
63
64  grub_xputs ("\n");
65  grub_refresh ();
66
67  return 1;
68}
Note: See TracBrowser for help on using the repository browser.