Avoid echoing stdin when output is piped to doas.

Fix asprintf() compile warning when building on Linux.
This commit is contained in:
Jesse Smith 2019-03-10 19:11:40 -03:00
parent fe6d3a342b
commit c8cb4d999e
3 changed files with 10 additions and 9 deletions

View file

@ -3,12 +3,13 @@ YACC?=yacc
BIN=doas BIN=doas
PREFIX?=/usr/local PREFIX?=/usr/local
OBJECTS=doas.o env.o execvpe.o reallocarray.o y.tab.o OBJECTS=doas.o env.o execvpe.o reallocarray.o y.tab.o
CFLAGS+=-DUSE_PAM -DDOAS_CONF=\"${PREFIX}/etc/doas.conf\" CFLAGS+=-DUSE_PAM -DDOAS_CONF=\"${PREFIX}/etc/doas.conf\"
LDFLAGS+=-lpam LDFLAGS+=-lpam
UNAME_S := $(shell uname -s) UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux) ifeq ($(UNAME_S),Linux)
LDFLAGS+=-lpam_misc LDFLAGS+=-lpam_misc
OBJECTS+=strlcat.o strlcpy.o OBJECTS+=strlcat.o strlcpy.o
CFLAGS+=-D_GNU_SOURCE
endif endif
ifeq ($(UNAME_S),FreeBSD) ifeq ($(UNAME_S),FreeBSD)
CFLAGS+=-DHAVE_LOGIN_CAP_H CFLAGS+=-DHAVE_LOGIN_CAP_H

12
doas.c
View file

@ -433,7 +433,7 @@ main(int argc, char **argv)
pam_handle_t *pamh = NULL; pam_handle_t *pamh = NULL;
int pam_err; int pam_err;
#ifndef linux /* #ifndef linux */
int temp_stdin; int temp_stdin;
/* openpam_ttyconv checks if stdin is a terminal and /* openpam_ttyconv checks if stdin is a terminal and
@ -450,7 +450,7 @@ main(int argc, char **argv)
if (temp_stdin == -1) if (temp_stdin == -1)
err(1, "dup"); err(1, "dup");
close(STDIN_FILENO); close(STDIN_FILENO);
#else /* #else */
/* force password prompt to display on stderr, not stdout */ /* force password prompt to display on stderr, not stdout */
int temp_stdout = dup(1); int temp_stdout = dup(1);
if (temp_stdout == -1) if (temp_stdout == -1)
@ -458,7 +458,7 @@ main(int argc, char **argv)
close(1); close(1);
if (dup2(2, 1) == -1) if (dup2(2, 1) == -1)
err(1, "dup2"); err(1, "dup2");
#endif /* #endif */
pam_err = pam_start("doas", myname, &pamc, &pamh); pam_err = pam_start("doas", myname, &pamc, &pamh);
if (pam_err != PAM_SUCCESS) { if (pam_err != PAM_SUCCESS) {
@ -510,17 +510,17 @@ main(int argc, char **argv)
} }
pam_end(pamh, pam_err); pam_end(pamh, pam_err);
#ifndef linux /* #ifndef linux */
/* Re-establish stdin */ /* Re-establish stdin */
if (dup2(temp_stdin, STDIN_FILENO) == -1) if (dup2(temp_stdin, STDIN_FILENO) == -1)
err(1, "dup2"); err(1, "dup2");
close(temp_stdin); close(temp_stdin);
#else /* #else */
/* Re-establish stdout */ /* Re-establish stdout */
close(1); close(1);
if (dup2(temp_stdout, 1) == -1) if (dup2(temp_stdout, 1) == -1)
err(1, "dup2"); err(1, "dup2");
#endif /* #endif */
#else #else
#error No auth module! #error No auth module!
#endif #endif

4
env.c
View file

@ -20,9 +20,9 @@
#include <sys/tree.h> #include <sys/tree.h>
#endif #endif
#include <string.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include <err.h> #include <err.h>
#include <unistd.h> #include <unistd.h>
#include <errno.h> #include <errno.h>
@ -90,7 +90,7 @@ createenv(struct rule *rule)
env->count = 0; env->count = 0;
if (rule->options & KEEPENV) { if (rule->options & KEEPENV) {
extern const char **environ; /* extern const char **environ; */
for (i = 0; environ[i] != NULL; i++) { for (i = 0; environ[i] != NULL; i++) {
struct envnode *node; struct envnode *node;