26 |
#include <assert.h> |
#include <assert.h> |
27 |
#include <unistd.h> |
#include <unistd.h> |
28 |
#include <sys/wait.h> |
#include <sys/wait.h> |
29 |
|
#include <sys/stat.h> |
30 |
|
#include <fcntl.h> |
31 |
|
|
32 |
/* Execute specified askpass program and fetch password from standard |
/* Execute specified askpass program and fetch password from standard |
33 |
output. Return NULL on failure, otherwise a pointer to the data |
output. Return NULL on failure, otherwise a pointer to the data |
41 |
char *pass; |
char *pass; |
42 |
int p[2], status, ret; |
int p[2], status, ret; |
43 |
char buf[1024]; |
char buf[1024]; |
44 |
|
int devnull; |
45 |
|
|
46 |
if (fflush(stdout) != 0) |
if (fflush(stdout) != 0) |
47 |
error("askpass: fflush: %s", strerror(errno)); |
error("askpass: fflush: %s", strerror(errno)); |
65 |
setuid(getuid()); |
setuid(getuid()); |
66 |
/* Close read end */ |
/* Close read end */ |
67 |
close(p[0]); |
close(p[0]); |
68 |
|
|
69 |
|
/* Setup stdin */ |
70 |
|
devnull = open("/dev/null", 0, O_RDONLY); |
71 |
|
if (dup2(devnull, STDIN_FILENO) < 0) |
72 |
|
{ |
73 |
|
error("askpass: dup2: %s", strerror(errno)); |
74 |
|
exit(1); |
75 |
|
} |
76 |
|
close(devnull); |
77 |
|
|
78 |
|
/* Setup stdout */ |
79 |
if (dup2(p[1], STDOUT_FILENO) < 0) |
if (dup2(p[1], STDOUT_FILENO) < 0) |
80 |
{ |
{ |
81 |
error("askpass: dup2: %s", strerror(errno)); |
error("askpass: dup2: %s", strerror(errno)); |
82 |
exit(1); |
exit(1); |
83 |
} |
} |
84 |
|
close(p[1]); |
85 |
|
|
86 |
|
/* By now, the following fds are open: |
87 |
|
0 -> /dev/null |
88 |
|
1 -> pipe write end |
89 |
|
2 -> users terminal */ |
90 |
execlp(askpass, askpass, msg, (char *) 0); |
execlp(askpass, askpass, msg, (char *) 0); |
91 |
error("askpass: exec(%s): %s", askpass, strerror(errno)); |
error("askpass: exec(%s): %s", askpass, strerror(errno)); |
92 |
exit(1); |
exit(1); |