summaryrefslogtreecommitdiff
path: root/net/oidentd/patches/patch-ac
blob: 84b7f7c34f5ddf5b8e2abdd242ea35b8704c9ebe (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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
$NetBSD: patch-ac,v 1.5 2005/08/07 12:51:32 tron Exp $

--- src/kernel/netbsd.c.orig	2003-02-12 02:15:59.000000000 +0000
+++ src/kernel/netbsd.c	2005-08-07 13:48:57.000000000 +0100
@@ -29,6 +29,7 @@
 #include <errno.h>
 #include <string.h>
 #include <sys/types.h>
+#include <sys/param.h>
 #include <sys/socket.h>
 #include <sys/socketvar.h>
 #include <netinet/in.h>
@@ -41,6 +42,16 @@
 #include <netinet/tcp.h>
 #include <netinet/ip_compat.h>
 
+#if __NetBSD_Version__ >= 399000300	/* 3.99.3 */
+#define	SO_UIDINFO	/* "struct socket" contains so_uidinfo" */
+
+#include <sys/proc.h>
+#include <sys/resource.h>
+#define	_KERNEL	42
+#include <sys/resourcevar.h>
+#undef _KERNEL
+#endif
+
 #ifdef WANT_IPV6
 #	include <sys/sysctl.h>
 #	include <netinet/ip_var.h>
@@ -99,7 +110,11 @@
 	kinfo->nl[N_TCB].n_name = "_tcbtable";
 
 #ifdef WANT_IPV6
+#if __NetBSD_Version__ >= 106250000	/* 1.6Y */
+	kinfo->nl[N_TCB6].n_name = "_tcbtable";
+#else
 	kinfo->nl[N_TCB6].n_name = "_tcb6";
+#endif
 #else
 	kinfo->nl[N_TCB6].n_name = "_oidentd_nonexistent";
 #endif
@@ -162,7 +177,7 @@
 	if (tcbtablep == NULL)
 		return (NULL);
 
-	kpcbp = tcbtablep->inpt_queue.cqh_first;
+	kpcbp = (struct inpcb *) tcbtablep->inpt_queue.cqh_first;
 	while (kpcbp != (struct inpcb *) ktcbtablep) {
 		if (getbuf((u_long) kpcbp, &pcb, sizeof(struct inpcb)) == -1)
 			break;
@@ -185,7 +200,7 @@
 			return (pcb.inp_socket);
 		}
 
-		kpcbp = pcb.inp_queue.cqe_next;
+		kpcbp = (struct inpcb *) pcb.inp_queue.cqe_next;
 	}
 
 	return (NULL);
@@ -203,6 +218,9 @@
 	struct socket *sockp, sock;
 	struct inpcbtable tcbtable;
 	int ret;
+#ifdef SO_UIDINFO
+	struct uidinfo uidinfo;
+#endif
 
 	ret = getbuf(kinfo->nl[N_TCB].n_value, &tcbtable, sizeof(tcbtable));
 	if (ret == -1)
@@ -218,7 +236,17 @@
 	if (getbuf((u_long) sockp, &sock, sizeof(sock)) == -1)
 		return (-1);
 
+#ifdef SO_UIDINFO
+	if (sock.so_uidinfo == NULL)
+		return (-1);
+
+	if (getbuf((u_long) sock.so_uidinfo, &uidinfo, sizeof(uidinfo)) == -1)
+		return (-1);
+
+	return (uidinfo.ui_uid);
+#else
 	return (sock.so_uid);
+#endif
 }
 
 #ifdef MASQ_SUPPORT
@@ -327,12 +355,38 @@
 ** Returns NULL if no match.
 */
 
+#if __NetBSD_Version__ >= 106250000
+static struct socket *getlist6(	struct inpcbtable *tcbtablep,
+								struct inpcbtable *ktcbtablep,
+#else
 static struct socket *getlist6(	struct in6pcb *tcb6,
+#endif
 								in_port_t lport,
 								in_port_t fport,
 								const struct in6_addr *laddr,
 								const struct in6_addr *faddr)
 {
+#if __NetBSD_Version__ >= 106250000
+	struct in6pcb *kpcbp, pcb;
+
+	if (tcbtablep == NULL)
+		return (NULL);
+
+	kpcbp = (struct in6pcb *) tcbtablep->inpt_queue.cqh_first;
+	while (kpcbp != (struct in6pcb *) ktcbtablep) {
+		if (getbuf((u_long) kpcbp, &pcb, sizeof(struct in6pcb)) == -1)
+			break;
+		if (pcb.in6p_fport == fport &&
+			pcb.in6p_lport == lport &&
+			IN6_ARE_ADDR_EQUAL(&pcb.in6p_laddr, laddr) &&
+			IN6_ARE_ADDR_EQUAL(&pcb.in6p_faddr, faddr))
+		{
+			return (pcb.in6p_socket);
+		}
+
+		kpcbp = (struct in6pcb *) pcb.in6p_queue.cqe_next;
+	}
+#else
 	struct in6pcb *tcb6_cur, tcb6_temp;
 
 	if (tcb6 == NULL)
@@ -355,7 +409,7 @@
 		if (getbuf((u_long) tcb6_cur, &tcb6_temp, sizeof(tcb6_temp)) == -1)
 			break;
 	} while ((u_long) tcb6_cur != kinfo->nl[N_TCB6].n_value);
-
+#endif
 	return (NULL);
 }
 
@@ -368,6 +422,22 @@
 				struct sockaddr_storage *laddr,
 				struct sockaddr_storage *faddr)
 {
+#if __NetBSD_Version__ >= 106250000	/* 1.6Y */
+	struct socket *sockp, sock;
+	struct inpcbtable tcbtable;
+	int ret;
+#ifdef SO_UIDINFO
+	struct uidinfo uidinfo;
+#endif
+
+	ret = getbuf(kinfo->nl[N_TCB6].n_value, &tcbtable, sizeof(tcbtable));
+	if (ret == -1)
+		return (-1);
+
+	sockp = getlist6(&tcbtable,
+				(struct inpcbtable *) kinfo->nl[N_TCB6].n_value,
+				lport, fport, &SIN6(laddr)->sin6_addr, &SIN6(faddr)->sin6_addr);
+#else
 	struct socket *sockp, sock;
 	struct in6pcb tcb6;
 	int ret;
@@ -378,6 +448,7 @@
 
 	sockp = getlist6(&tcb6, lport, fport,
 				&SIN6(laddr)->sin6_addr, &SIN6(faddr)->sin6_addr);
+#endif
 
 	if (sockp == NULL)
 		return (-1);
@@ -385,7 +456,17 @@
 	if (getbuf((u_long) sockp, &sock, sizeof(sock)) == -1)
 		return (-1);
 
+#ifdef SO_UIDINFO
+	if (sock.so_uidinfo == NULL)
+		return (-1);
+
+	if (getbuf((u_long) sock.so_uidinfo, &uidinfo, sizeof(uidinfo)) == -1)
+		return (-1);
+
+	return (uidinfo.ui_uid);
+#else
 	return (sock.so_uid);
+#endif
 }
 
 #endif