3 --- src/kernel/netbsd.c.orig 2003-02-12 02:15:59.000000000 +0000
4 +++ src/kernel/netbsd.c 2005-08-07 13:48:57.000000000 +0100
9 +#include <sys/param.h>
10 #include <sys/socket.h>
11 #include <sys/socketvar.h>
12 #include <netinet/in.h>
14 #include <netinet/tcp.h>
15 #include <netinet/ip_compat.h>
17 +#if __NetBSD_Version__ >= 399000300 /* 3.99.3 */
18 +#define SO_UIDINFO /* "struct socket" contains so_uidinfo" */
20 +#include <sys/proc.h>
21 +#include <sys/resource.h>
23 +#include <sys/resourcevar.h>
28 # include <sys/sysctl.h>
29 # include <netinet/ip_var.h>
31 kinfo->nl[N_TCB].n_name = "_tcbtable";
34 +#if __NetBSD_Version__ >= 106250000 /* 1.6Y */
35 + kinfo->nl[N_TCB6].n_name = "_tcbtable";
37 kinfo->nl[N_TCB6].n_name = "_tcb6";
40 kinfo->nl[N_TCB6].n_name = "_oidentd_nonexistent";
43 if (tcbtablep == NULL)
46 - kpcbp = tcbtablep->inpt_queue.cqh_first;
47 + kpcbp = (struct inpcb *) tcbtablep->inpt_queue.cqh_first;
48 while (kpcbp != (struct inpcb *) ktcbtablep) {
49 if (getbuf((u_long) kpcbp, &pcb, sizeof(struct inpcb)) == -1)
52 return (pcb.inp_socket);
55 - kpcbp = pcb.inp_queue.cqe_next;
56 + kpcbp = (struct inpcb *) pcb.inp_queue.cqe_next;
61 struct socket *sockp, sock;
62 struct inpcbtable tcbtable;
65 + struct uidinfo uidinfo;
68 ret = getbuf(kinfo->nl[N_TCB].n_value, &tcbtable, sizeof(tcbtable));
71 if (getbuf((u_long) sockp, &sock, sizeof(sock)) == -1)
75 + if (sock.so_uidinfo == NULL)
78 + if (getbuf((u_long) sock.so_uidinfo, &uidinfo, sizeof(uidinfo)) == -1)
81 + return (uidinfo.ui_uid);
89 ** Returns NULL if no match.
92 +#if __NetBSD_Version__ >= 106250000
93 +static struct socket *getlist6( struct inpcbtable *tcbtablep,
94 + struct inpcbtable *ktcbtablep,
96 static struct socket *getlist6( struct in6pcb *tcb6,
100 const struct in6_addr *laddr,
101 const struct in6_addr *faddr)
103 +#if __NetBSD_Version__ >= 106250000
104 + struct in6pcb *kpcbp, pcb;
106 + if (tcbtablep == NULL)
109 + kpcbp = (struct in6pcb *) tcbtablep->inpt_queue.cqh_first;
110 + while (kpcbp != (struct in6pcb *) ktcbtablep) {
111 + if (getbuf((u_long) kpcbp, &pcb, sizeof(struct in6pcb)) == -1)
113 + if (pcb.in6p_fport == fport &&
114 + pcb.in6p_lport == lport &&
115 + IN6_ARE_ADDR_EQUAL(&pcb.in6p_laddr, laddr) &&
116 + IN6_ARE_ADDR_EQUAL(&pcb.in6p_faddr, faddr))
118 + return (pcb.in6p_socket);
121 + kpcbp = (struct in6pcb *) pcb.in6p_queue.cqe_next;
124 struct in6pcb *tcb6_cur, tcb6_temp;
128 if (getbuf((u_long) tcb6_cur, &tcb6_temp, sizeof(tcb6_temp)) == -1)
130 } while ((u_long) tcb6_cur != kinfo->nl[N_TCB6].n_value);
137 struct sockaddr_storage *laddr,
138 struct sockaddr_storage *faddr)
140 +#if __NetBSD_Version__ >= 106250000 /* 1.6Y */
141 + struct socket *sockp, sock;
142 + struct inpcbtable tcbtable;
145 + struct uidinfo uidinfo;
148 + ret = getbuf(kinfo->nl[N_TCB6].n_value, &tcbtable, sizeof(tcbtable));
152 + sockp = getlist6(&tcbtable,
153 + (struct inpcbtable *) kinfo->nl[N_TCB6].n_value,
154 + lport, fport, &SIN6(laddr)->sin6_addr, &SIN6(faddr)->sin6_addr);
156 struct socket *sockp, sock;
161 sockp = getlist6(&tcb6, lport, fport,
162 &SIN6(laddr)->sin6_addr, &SIN6(faddr)->sin6_addr);
168 if (getbuf((u_long) sockp, &sock, sizeof(sock)) == -1)
172 + if (sock.so_uidinfo == NULL)
175 + if (getbuf((u_long) sock.so_uidinfo, &uidinfo, sizeof(uidinfo)) == -1)
178 + return (uidinfo.ui_uid);
180 return (sock.so_uid);