Add files from parent branch HEAD:
[pkgsrc.git] / net / oidentd / patches / patch-ac
1 $NetBSD$
2
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
5 @@ -29,6 +29,7 @@
6  #include <errno.h>
7  #include <string.h>
8  #include <sys/types.h>
9 +#include <sys/param.h>
10  #include <sys/socket.h>
11  #include <sys/socketvar.h>
12  #include <netinet/in.h>
13 @@ -41,6 +42,16 @@
14  #include <netinet/tcp.h>
15  #include <netinet/ip_compat.h>
16  
17 +#if __NetBSD_Version__ >= 399000300    /* 3.99.3 */
18 +#define        SO_UIDINFO      /* "struct socket" contains so_uidinfo" */
19 +
20 +#include <sys/proc.h>
21 +#include <sys/resource.h>
22 +#define        _KERNEL 42
23 +#include <sys/resourcevar.h>
24 +#undef _KERNEL
25 +#endif
26 +
27  #ifdef WANT_IPV6
28  #      include <sys/sysctl.h>
29  #      include <netinet/ip_var.h>
30 @@ -99,7 +110,11 @@
31         kinfo->nl[N_TCB].n_name = "_tcbtable";
32  
33  #ifdef WANT_IPV6
34 +#if __NetBSD_Version__ >= 106250000    /* 1.6Y */
35 +       kinfo->nl[N_TCB6].n_name = "_tcbtable";
36 +#else
37         kinfo->nl[N_TCB6].n_name = "_tcb6";
38 +#endif
39  #else
40         kinfo->nl[N_TCB6].n_name = "_oidentd_nonexistent";
41  #endif
42 @@ -162,7 +177,7 @@
43         if (tcbtablep == NULL)
44                 return (NULL);
45  
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)
50                         break;
51 @@ -185,7 +200,7 @@
52                         return (pcb.inp_socket);
53                 }
54  
55 -               kpcbp = pcb.inp_queue.cqe_next;
56 +               kpcbp = (struct inpcb *) pcb.inp_queue.cqe_next;
57         }
58  
59         return (NULL);
60 @@ -203,6 +218,9 @@
61         struct socket *sockp, sock;
62         struct inpcbtable tcbtable;
63         int ret;
64 +#ifdef SO_UIDINFO
65 +       struct uidinfo uidinfo;
66 +#endif
67  
68         ret = getbuf(kinfo->nl[N_TCB].n_value, &tcbtable, sizeof(tcbtable));
69         if (ret == -1)
70 @@ -218,7 +236,17 @@
71         if (getbuf((u_long) sockp, &sock, sizeof(sock)) == -1)
72                 return (-1);
73  
74 +#ifdef SO_UIDINFO
75 +       if (sock.so_uidinfo == NULL)
76 +               return (-1);
77 +
78 +       if (getbuf((u_long) sock.so_uidinfo, &uidinfo, sizeof(uidinfo)) == -1)
79 +               return (-1);
80 +
81 +       return (uidinfo.ui_uid);
82 +#else
83         return (sock.so_uid);
84 +#endif
85  }
86  
87  #ifdef MASQ_SUPPORT
88 @@ -327,12 +355,38 @@
89  ** Returns NULL if no match.
90  */
91  
92 +#if __NetBSD_Version__ >= 106250000
93 +static struct socket *getlist6(        struct inpcbtable *tcbtablep,
94 +                                                               struct inpcbtable *ktcbtablep,
95 +#else
96  static struct socket *getlist6(        struct in6pcb *tcb6,
97 +#endif
98                                                                 in_port_t lport,
99                                                                 in_port_t fport,
100                                                                 const struct in6_addr *laddr,
101                                                                 const struct in6_addr *faddr)
102  {
103 +#if __NetBSD_Version__ >= 106250000
104 +       struct in6pcb *kpcbp, pcb;
105 +
106 +       if (tcbtablep == NULL)
107 +               return (NULL);
108 +
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)
112 +                       break;
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))
117 +               {
118 +                       return (pcb.in6p_socket);
119 +               }
120 +
121 +               kpcbp = (struct in6pcb *) pcb.in6p_queue.cqe_next;
122 +       }
123 +#else
124         struct in6pcb *tcb6_cur, tcb6_temp;
125  
126         if (tcb6 == NULL)
127 @@ -355,7 +409,7 @@
128                 if (getbuf((u_long) tcb6_cur, &tcb6_temp, sizeof(tcb6_temp)) == -1)
129                         break;
130         } while ((u_long) tcb6_cur != kinfo->nl[N_TCB6].n_value);
131 -
132 +#endif
133         return (NULL);
134  }
135  
136 @@ -368,6 +422,22 @@
137                                 struct sockaddr_storage *laddr,
138                                 struct sockaddr_storage *faddr)
139  {
140 +#if __NetBSD_Version__ >= 106250000    /* 1.6Y */
141 +       struct socket *sockp, sock;
142 +       struct inpcbtable tcbtable;
143 +       int ret;
144 +#ifdef SO_UIDINFO
145 +       struct uidinfo uidinfo;
146 +#endif
147 +
148 +       ret = getbuf(kinfo->nl[N_TCB6].n_value, &tcbtable, sizeof(tcbtable));
149 +       if (ret == -1)
150 +               return (-1);
151 +
152 +       sockp = getlist6(&tcbtable,
153 +                               (struct inpcbtable *) kinfo->nl[N_TCB6].n_value,
154 +                               lport, fport, &SIN6(laddr)->sin6_addr, &SIN6(faddr)->sin6_addr);
155 +#else
156         struct socket *sockp, sock;
157         struct in6pcb tcb6;
158         int ret;
159 @@ -378,6 +448,7 @@
160  
161         sockp = getlist6(&tcb6, lport, fport,
162                                 &SIN6(laddr)->sin6_addr, &SIN6(faddr)->sin6_addr);
163 +#endif
164  
165         if (sockp == NULL)
166                 return (-1);
167 @@ -385,7 +456,17 @@
168         if (getbuf((u_long) sockp, &sock, sizeof(sock)) == -1)
169                 return (-1);
170  
171 +#ifdef SO_UIDINFO
172 +       if (sock.so_uidinfo == NULL)
173 +               return (-1);
174 +
175 +       if (getbuf((u_long) sock.so_uidinfo, &uidinfo, sizeof(uidinfo)) == -1)
176 +               return (-1);
177 +
178 +       return (uidinfo.ui_uid);
179 +#else
180         return (sock.so_uid);
181 +#endif
182  }
183  
184  #endif