92a7f6c32e1de24f7a41e5001e01b96ed2837b2f
[packages.git] / utils / tmux / patches / 010-backport-b64_ntop-fix.patch
1 Index: tmux-1.5/configure.ac
2 ===================================================================
3 --- tmux-1.5.orig/configure.ac  2011-07-09 18:00:17.000000000 +0200
4 +++ tmux-1.5/configure.ac       2011-07-31 17:00:47.000000000 +0200
5 @@ -12,6 +12,7 @@
6  # autoconf will automatically use CFLAGS="-O2 -g". Prevent that by using an
7  # empty default.
8  : ${CFLAGS=""}
9 +
10  # Set up the compiler in two different ways and say yes we may want to install.
11  AC_PROG_CC
12  AM_PROG_CC_C_O
13 @@ -52,9 +53,8 @@
14  AC_ARG_ENABLE(
15         static,
16         AC_HELP_STRING(--enable-static, create a static build),
17 -       [found_static=$enable_static]
18 +       [LDFLAGS="$LDFLAGS -static"]
19  )
20 -AM_CONDITIONAL(IS_STATIC, test "x" = xyes)
21  
22  # Is this gcc?
23  AM_CONDITIONAL(IS_GCC, test "x$GCC" = xyes)
24 @@ -105,9 +105,14 @@
25  AC_CHECK_LIB(rt, clock_gettime)
26  
27  # Look for libevent.
28 -AC_SEARCH_LIBS(event_init, [event event-1.4 event2], found_libevent=yes, found_libevent=no)
29 +AC_SEARCH_LIBS(
30 +       event_init,
31 +       [event event-1.4 event2],
32 +       found_libevent=yes,
33 +       found_libevent=no
34 +)
35  if test "x$found_libevent" = xno; then
36 -    AC_MSG_ERROR("libevent not found")
37 +       AC_MSG_ERROR("libevent not found")
38  fi
39  
40  # Look for curses.
41 @@ -121,9 +126,44 @@
42      AC_MSG_ERROR("curses not found")
43  fi
44  
45 +# Check for b64_ntop.
46 +AC_MSG_CHECKING(for b64_ntop)
47 +AC_TRY_LINK(
48 +       [
49 +               #include <sys/types.h>
50 +               #include <netinet/in.h>
51 +               #include <resolv.h>
52 +       ],
53 +       [b64_ntop(NULL, 0, NULL, 0);],
54 +       found_b64_ntop=yes,
55 +       found_b64_ntop=no
56 +)
57 +if test "x$found_b64_ntop" = xno; then
58 +       AC_MSG_RESULT(no)
59 +
60 +       AC_MSG_CHECKING(for b64_ntop with -lresolv)
61 +       LIBS="$LIBS -lresolv"
62 +       AC_TRY_LINK(
63 +               [
64 +                       #include <sys/types.h>
65 +                       #include <netinet/in.h>
66 +                       #include <resolv.h>
67 +               ],
68 +               [b64_ntop(NULL, 0, NULL, 0);],
69 +               found_b64_ntop=yes,
70 +               found_b64_ntop=no
71 +       )
72 +       if test "x$found_b64_ntop" = xno; then
73 +               AC_MSG_RESULT(no)
74 +       fi
75 +fi
76 +if test "x$found_b64_ntop" = xyes; then
77 +       AC_DEFINE(HAVE_B64_NTOP)
78 +       AC_MSG_RESULT(yes)
79 +fi
80 +AM_CONDITIONAL(NO_B64_NTOP, [test "x$found_b64_ntop" = xno])
81 +
82  # Look for networking libraries.
83 -AC_SEARCH_LIBS(b64_ntop, resolv)
84 -AC_SEARCH_LIBS(__b64_ntop, resolv)
85  AC_SEARCH_LIBS(inet_ntoa, nsl)
86  AC_SEARCH_LIBS(socket, socket)
87  AC_CHECK_LIB(xnet, socket)
88 Index: tmux-1.5/compat.h
89 ===================================================================
90 --- tmux-1.5.orig/compat.h      2011-07-09 11:42:38.000000000 +0200
91 +++ tmux-1.5/compat.h   2011-07-31 17:00:24.000000000 +0200
92 @@ -196,6 +196,11 @@
93  int             daemon(int, int);
94  #endif
95  
96 +#ifndef HAVE_B64_NTOP
97 +/* b64_ntop.c */
98 +int             b64_ntop(const char *, size_t, char *, size_t);
99 +#endif
100 +
101  #ifndef HAVE_FORKPTY
102  /* forkpty.c */
103  #include <sys/ioctl.h>
104 Index: tmux-1.5/Makefile.am
105 ===================================================================
106 --- tmux-1.5.orig/Makefile.am   2011-07-09 15:45:24.000000000 +0200
107 +++ tmux-1.5/Makefile.am        2011-07-31 17:00:47.000000000 +0200
108 @@ -43,11 +43,6 @@
109  endif
110  endif
111  
112 -# Set flags for static.
113 -if IS_STATIC
114 -LDFLAGS += -static
115 -endif
116 -
117  # Set flags for Solaris.
118  if IS_SUNOS
119  CPPFLAGS += -D_XPG4_2 -D__EXTENSIONS__ -D_POSIX_PTHREAD_SEMANTICS
120 @@ -226,6 +221,9 @@
121  if NO_STRTONUM
122  nodist_tmux_SOURCES += compat/strtonum.c
123  endif
124 +if NO_B64_NTOP
125 +nodist_tmux_SOURCES += compat/b64_ntop.c
126 +endif
127  
128  # Update SF web site.
129  upload-index.html: update-index.html
130 Index: tmux-1.5/compat/b64_ntop.c
131 ===================================================================
132 --- /dev/null   1970-01-01 00:00:00.000000000 +0000
133 +++ tmux-1.5/compat/b64_ntop.c  2011-07-31 17:04:03.000000000 +0200
134 @@ -0,0 +1,182 @@
135 +/*
136 + * Copyright (c) 1996, 1998 by Internet Software Consortium.
137 + *
138 + * Permission to use, copy, modify, and distribute this software for any
139 + * purpose with or without fee is hereby granted, provided that the above
140 + * copyright notice and this permission notice appear in all copies.
141 + *
142 + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
143 + * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
144 + * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
145 + * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
146 + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
147 + * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
148 + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
149 + * SOFTWARE.
150 + */
151 +
152 +/*
153 + * Portions Copyright (c) 1995 by International Business Machines, Inc.
154 + *
155 + * International Business Machines, Inc. (hereinafter called IBM) grants
156 + * permission under its copyrights to use, copy, modify, and distribute this
157 + * Software with or without fee, provided that the above copyright notice and
158 + * all paragraphs of this notice appear in all copies, and that the name of IBM
159 + * not be used in connection with the marketing of any product incorporating
160 + * the Software or modifications thereof, without specific, written prior
161 + * permission.
162 + *
163 + * To the extent it has a right to do so, IBM grants an immunity from suit
164 + * under its patents, if any, for the use, sale or manufacture of products to
165 + * the extent that such products are used for performing Domain Name System
166 + * dynamic updates in TCP/IP networks by means of the Software.  No immunity is
167 + * granted for any product per se or for any other function of any product.
168 + *
169 + * THE SOFTWARE IS PROVIDED "AS IS", AND IBM DISCLAIMS ALL WARRANTIES,
170 + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
171 + * PARTICULAR PURPOSE.  IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL,
172 + * DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ARISING
173 + * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN
174 + * IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES.
175 + */
176 +
177 +#include <sys/types.h>
178 +#include <sys/param.h>
179 +#include <sys/socket.h>
180 +
181 +#include <netinet/in.h>
182 +#include <arpa/inet.h>
183 +
184 +#include <ctype.h>
185 +#include <stdio.h>
186 +#include <stdlib.h>
187 +#include <string.h>
188 +
189 +#define Assert(Cond) if (!(Cond)) abort()
190 +
191 +static const char Base64[] =
192 +       "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
193 +static const char Pad64 = '=';
194 +
195 +/* (From RFC1521 and draft-ietf-dnssec-secext-03.txt)
196 +   The following encoding technique is taken from RFC 1521 by Borenstein
197 +   and Freed.  It is reproduced here in a slightly edited form for
198 +   convenience.
199 +
200 +   A 65-character subset of US-ASCII is used, enabling 6 bits to be
201 +   represented per printable character. (The extra 65th character, "=",
202 +   is used to signify a special processing function.)
203 +
204 +   The encoding process represents 24-bit groups of input bits as output
205 +   strings of 4 encoded characters. Proceeding from left to right, a
206 +   24-bit input group is formed by concatenating 3 8-bit input groups.
207 +   These 24 bits are then treated as 4 concatenated 6-bit groups, each
208 +   of which is translated into a single digit in the base64 alphabet.
209 +
210 +   Each 6-bit group is used as an index into an array of 64 printable
211 +   characters. The character referenced by the index is placed in the
212 +   output string.
213 +
214 +                         Table 1: The Base64 Alphabet
215 +
216 +      Value Encoding  Value Encoding  Value Encoding  Value Encoding
217 +          0 A            17 R            34 i            51 z
218 +          1 B            18 S            35 j            52 0
219 +          2 C            19 T            36 k            53 1
220 +          3 D            20 U            37 l            54 2
221 +          4 E            21 V            38 m            55 3
222 +          5 F            22 W            39 n            56 4
223 +          6 G            23 X            40 o            57 5
224 +          7 H            24 Y            41 p            58 6
225 +          8 I            25 Z            42 q            59 7
226 +          9 J            26 a            43 r            60 8
227 +         10 K            27 b            44 s            61 9
228 +         11 L            28 c            45 t            62 +
229 +         12 M            29 d            46 u            63 /
230 +         13 N            30 e            47 v
231 +         14 O            31 f            48 w         (pad) =
232 +         15 P            32 g            49 x
233 +         16 Q            33 h            50 y
234 +
235 +   Special processing is performed if fewer than 24 bits are available
236 +   at the end of the data being encoded.  A full encoding quantum is
237 +   always completed at the end of a quantity.  When fewer than 24 input
238 +   bits are available in an input group, zero bits are added (on the
239 +   right) to form an integral number of 6-bit groups.  Padding at the
240 +   end of the data is performed using the '=' character.
241 +
242 +   Since all base64 input is an integral number of octets, only the
243 +         -------------------------------------------------
244 +   following cases can arise:
245 +
246 +       (1) the final quantum of encoding input is an integral
247 +           multiple of 24 bits; here, the final unit of encoded
248 +          output will be an integral multiple of 4 characters
249 +          with no "=" padding,
250 +       (2) the final quantum of encoding input is exactly 8 bits;
251 +           here, the final unit of encoded output will be two
252 +          characters followed by two "=" padding characters, or
253 +       (3) the final quantum of encoding input is exactly 16 bits;
254 +           here, the final unit of encoded output will be three
255 +          characters followed by one "=" padding character.
256 +   */
257 +
258 +int
259 +b64_ntop(uint8_t const *src, size_t srclength, char *target, size_t targsize) {
260 +       size_t datalength = 0;
261 +       uint8_t input[3];
262 +       uint8_t output[4];
263 +       size_t i;
264 +
265 +       while (2 < srclength) {
266 +               input[0] = *src++;
267 +               input[1] = *src++;
268 +               input[2] = *src++;
269 +               srclength -= 3;
270 +
271 +               output[0] = input[0] >> 2;
272 +               output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4);
273 +               output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6);
274 +               output[3] = input[2] & 0x3f;
275 +               Assert(output[0] < 64);
276 +               Assert(output[1] < 64);
277 +               Assert(output[2] < 64);
278 +               Assert(output[3] < 64);
279 +
280 +               if (datalength + 4 > targsize)
281 +                       return (-1);
282 +               target[datalength++] = Base64[output[0]];
283 +               target[datalength++] = Base64[output[1]];
284 +               target[datalength++] = Base64[output[2]];
285 +               target[datalength++] = Base64[output[3]];
286 +       }
287 +
288 +       /* Now we worry about padding. */
289 +       if (0 != srclength) {
290 +               /* Get what's left. */
291 +               input[0] = input[1] = input[2] = '\0';
292 +               for (i = 0; i < srclength; i++)
293 +                       input[i] = *src++;
294 +
295 +               output[0] = input[0] >> 2;
296 +               output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4);
297 +               output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6);
298 +               Assert(output[0] < 64);
299 +               Assert(output[1] < 64);
300 +               Assert(output[2] < 64);
301 +
302 +               if (datalength + 4 > targsize)
303 +                       return (-1);
304 +               target[datalength++] = Base64[output[0]];
305 +               target[datalength++] = Base64[output[1]];
306 +               if (srclength == 1)
307 +                       target[datalength++] = Pad64;
308 +               else
309 +                       target[datalength++] = Base64[output[2]];
310 +               target[datalength++] = Pad64;
311 +       }
312 +       if (datalength >= targsize)
313 +               return (-1);
314 +       target[datalength] = '\0';      /* Returned value doesn't count \0. */
315 +       return (datalength);
316 +}