~ubuntu-branches/ubuntu/jaunty/isdnutils/jaunty-proposed

« back to all changes in this revision

Viewing changes to ipppd/readpw.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2004-09-04 08:20:20 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040904082020-g641px056lshw203
Tags: 1:3.3.0.20040728-2
* Put libcapi20 development files into new libcapi20-dev package,
  change libcapi20 soname to libcapi20-3, conflict with existing
  versions of packages depending on libcapi20-3 (closes: #268767).
* Update debconf translation strings (closes: #268716).
* Update french debconf translation (closes: #269666).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <termios.h>
 
2
#include <stdio.h>
 
3
#include <unistd.h>
 
4
#include <errno.h>
 
5
 
 
6
static int              tc_modified = 0;
 
7
static struct termios   oldset;
 
8
 
 
9
static void
 
10
echo_disable(void)
 
11
{
 
12
        struct termios newset;
 
13
 
 
14
        if (tcgetattr(STDIN_FILENO, &oldset) == 0 && (oldset.c_lflag & ECHO)) {
 
15
                tc_modified = 1;
 
16
                newset = oldset;
 
17
                newset.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL);
 
18
                (void) tcsetattr(STDIN_FILENO, TCSANOW, &newset);
 
19
        }
 
20
        return;
 
21
}
 
22
 
 
23
static void
 
24
echo_restore(void)
 
25
{
 
26
        if (tc_modified != 0) {
 
27
                tcsetattr(STDIN_FILENO, TCSANOW, &oldset);
 
28
                tc_modified = 0;
 
29
        }
 
30
}
 
31
 
 
32
static int
 
33
readnoecho(char* buf, int maxl)
 
34
{
 
35
        char c = 0;
 
36
        int n, i = 0;
 
37
 
 
38
        echo_disable();
 
39
        while (c != '\n') {
 
40
                n = read(STDIN_FILENO, &c, 1);
 
41
                if (n == -1 && (errno == EAGAIN || errno == EINTR))
 
42
                        continue;
 
43
                if (n != 1)
 
44
                        break;
 
45
                if (c == '\r')
 
46
                        break;
 
47
                if (c == '\n')
 
48
                        break;
 
49
                if (i < maxl)
 
50
                        buf[i++] = c;
 
51
        }
 
52
        buf[i] = '\0';
 
53
        echo_restore();
 
54
        fprintf(stderr, "\n");
 
55
        fflush(stderr);
 
56
        return i;
 
57
}
 
58
 
 
59
int
 
60
readpassw(char *buf, int maxlen)
 
61
{
 
62
        fflush(stdout);
 
63
        fflush(stderr);
 
64
        fprintf(stderr, "password:");
 
65
        fflush(stderr);
 
66
        return(readnoecho(buf, maxlen));
 
67
}
 
68