summaryrefslogtreecommitdiff
path: root/security/PAM/patches/patch-ak
blob: 3c2b40bb254eecb1a639ff55bf8a6104aa5bf979 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
$NetBSD: patch-ak,v 1.3 2002/12/23 21:23:59 jlam Exp $

--- modules/pam_filter/pam_filter.c.orig	Sun Nov 11 02:43:54 2001
+++ modules/pam_filter/pam_filter.c
@@ -21,7 +21,17 @@
 #include <sys/stat.h>
 #include <sys/socket.h>
 #include <sys/ioctl.h>
+#ifdef HAVE_TERMIOS_H
+#include <termios.h>
+#define STRUCT_TERMIO		struct termios
+#define TCGETATTR(fd, p_termio)	tcgetattr(fd, p_termio)
+#define TCSETATTR(fd, p_termio)	tcsetattr(fd, TCSANOW, p_termio)
+#else
 #include <termio.h>
+#define STRUCT_TERMIO		struct termio
+#define TCGETATTR(fd, p_termio)	ioctl(fd, TCGETA, (char *) p_termio)
+#define TCSETATTR(fd, p_termio)	ioctl(fd, TCSETA, (char *) p_termio)
+#endif
 
 #include <signal.h>
 
@@ -278,7 +288,7 @@ static int set_filter(pam_handle_t *pamh
 {
     int status=-1;
     char terminal[TERMINAL_LEN];
-    struct termio stored_mode;           /* initial terminal mode settings */
+    STRUCT_TERMIO stored_mode;           /* initial terminal mode settings */
     int fd[2], child=0, child2=0, aterminal;
 
     if (filtername == NULL || *filtername != '/') {
@@ -307,17 +317,20 @@ static int set_filter(pam_handle_t *pamh
 
 	/* this is termio terminal handling... */
 
-	if (ioctl(STDIN_FILENO, TCGETA, (char *) &stored_mode ) < 0) {
+	if (TCGETATTR(STDIN_FILENO, &stored_mode ) < 0) {
 	    /* in trouble, so close down */
 	    close(fd[0]);
 	    _pam_log(LOG_CRIT, "couldn't copy terminal mode");
 	    return PAM_ABORT;
 	} else {
-	    struct termio t_mode = stored_mode;
+	    STRUCT_TERMIO t_mode = stored_mode;
 
 	    t_mode.c_iflag = 0;            /* no input control */
 	    t_mode.c_oflag &= ~OPOST;      /* no ouput post processing */
 
+#ifndef XCASE
+#define XCASE 0
+#endif
 	    /* no signals, canonical input, echoing, upper/lower output */
 	    t_mode.c_lflag &= ~(ISIG|ICANON|ECHO|XCASE);
 	    t_mode.c_cflag &= ~(CSIZE|PARENB);  /* no parity */
@@ -326,7 +339,7 @@ static int set_filter(pam_handle_t *pamh
 	    t_mode.c_cc[VMIN] = 1; /* number of chars to satisfy a read */
 	    t_mode.c_cc[VTIME] = 0;          /* 0/10th second for chars */
 
-	    if (ioctl(STDIN_FILENO, TCSETA, (char *) &t_mode) < 0) {
+	    if (TCSETATTR(STDIN_FILENO, &t_mode) < 0) {
 		close(fd[0]);
 		_pam_log(LOG_WARNING, "couldn't put terminal in RAW mode");
 		return PAM_ABORT;
@@ -356,7 +369,7 @@ static int set_filter(pam_handle_t *pamh
 
 	_pam_log(LOG_WARNING,"first fork failed");
 	if (aterminal) {
-	    (void) ioctl(STDIN_FILENO, TCSETA, (char *) &stored_mode);
+	    (void) TCSETATTR(STDIN_FILENO, &stored_mode);
 	}
 
 	return PAM_AUTH_ERR;
@@ -398,7 +411,7 @@ static int set_filter(pam_handle_t *pamh
 	    /* initialize the child's terminal to be the way the
 	       parent's was before we set it into RAW mode */
 
-	    if (ioctl(fd[1], TCSETA, (char *) &stored_mode) < 0) {
+	    if (TCSETATTR(fd[1], &stored_mode) < 0) {
 		_pam_log(LOG_WARNING,"cannot set slave terminal mode; %s"
 			 ,terminal);
 		close(fd[1]);
@@ -572,7 +585,7 @@ static int set_filter(pam_handle_t *pamh
 
     if (aterminal) {
 	/* reset to initial terminal mode */
-	(void) ioctl(STDIN_FILENO, TCSETA, (char *) &stored_mode);
+	(void) TCSETATTR(STDIN_FILENO, &stored_mode);
     }
 
     if (ctrl & FILTER_DEBUG) {