[sqm-scripts/luci-app-sqm] Document how to disable shaping on a per direction basis
[feed/packages.git] / libs / libpam / patches / 006-fix_xdr.patch
1 --- a/modules/pam_unix/yppasswd_xdr.c
2 +++ b/modules/pam_unix/yppasswd_xdr.c
3 @@ -21,6 +21,268 @@
4 #endif
5 #include "yppasswd.h"
6
7 +#ifdef __UCLIBC__
8 +
9 +static const char xdr_zero[BYTES_PER_XDR_UNIT] = {0, 0, 0, 0};
10 +
11 +/*
12 + * XDR integers
13 + */
14 +bool_t
15 +xdr_int (XDR *xdrs, int *ip)
16 +{
17 +
18 +#if INT_MAX < LONG_MAX
19 + long l;
20 +
21 + switch (xdrs->x_op)
22 + {
23 + case XDR_ENCODE:
24 + l = (long) *ip;
25 + return XDR_PUTLONG (xdrs, &l);
26 +
27 + case XDR_DECODE:
28 + if (!XDR_GETLONG (xdrs, &l))
29 + {
30 + return FALSE;
31 + }
32 + *ip = (int) l;
33 + case XDR_FREE:
34 + return TRUE;
35 + }
36 + return FALSE;
37 +#elif INT_MAX == LONG_MAX
38 + return xdr_long (xdrs, (long *) ip);
39 +#elif INT_MAX == SHRT_MAX
40 + return xdr_short (xdrs, (short *) ip);
41 +#else
42 +#error unexpected integer sizes in xdr_int()
43 +#endif
44 +}
45 +
46 +/*
47 + * XDR null terminated ASCII strings
48 + * xdr_string deals with "C strings" - arrays of bytes that are
49 + * terminated by a NULL character. The parameter cpp references a
50 + * pointer to storage; If the pointer is null, then the necessary
51 + * storage is allocated. The last parameter is the max allowed length
52 + * of the string as specified by a protocol.
53 + */
54 +bool_t
55 +xdr_string (XDR *xdrs, char **cpp, u_int maxsize)
56 +{
57 + char *sp = *cpp; /* sp is the actual string pointer */
58 + u_int size;
59 + u_int nodesize;
60 +
61 + /*
62 + * first deal with the length since xdr strings are counted-strings
63 + */
64 + switch (xdrs->x_op)
65 + {
66 + case XDR_FREE:
67 + if (sp == NULL)
68 + {
69 + return TRUE; /* already free */
70 + }
71 + /* fall through... */
72 + case XDR_ENCODE:
73 + if (sp == NULL)
74 + return FALSE;
75 + size = strlen (sp);
76 + break;
77 + case XDR_DECODE:
78 + break;
79 + }
80 + if (!xdr_u_int (xdrs, &size))
81 + {
82 + return FALSE;
83 + }
84 + if (size > maxsize)
85 + {
86 + return FALSE;
87 + }
88 + nodesize = size + 1;
89 +
90 + /*
91 + * now deal with the actual bytes
92 + */
93 + switch (xdrs->x_op)
94 + {
95 + case XDR_DECODE:
96 + if (nodesize == 0)
97 + {
98 + return TRUE;
99 + }
100 + if (sp == NULL)
101 + *cpp = sp = (char *) mem_alloc (nodesize);
102 + if (sp == NULL)
103 + {
104 +#ifdef USE_IN_LIBIO
105 + if (_IO_fwide (stderr, 0) > 0)
106 + (void) fwprintf (stderr, L"%s",
107 + _("xdr_string: out of memory\n"));
108 + else
109 +#endif
110 + (void) fputs (_("xdr_string: out of memory\n"), stderr);
111 + return FALSE;
112 + }
113 + sp[size] = 0;
114 + /* fall into ... */
115 +
116 + case XDR_ENCODE:
117 + return xdr_opaque (xdrs, sp, size);
118 +
119 + case XDR_FREE:
120 + mem_free (sp, nodesize);
121 + *cpp = NULL;
122 + return TRUE;
123 + }
124 + return FALSE;
125 +}
126 +
127 +/*
128 + * XDR long integers
129 + * The definition of xdr_long() is kept for backward
130 + * compatibility. Instead xdr_int() should be used.
131 + */
132 +bool_t
133 +xdr_long (XDR *xdrs, long *lp)
134 +{
135 + if (xdrs->x_op == XDR_ENCODE
136 + && (sizeof (int32_t) == sizeof (long)
137 + || (int32_t) *lp == *lp))
138 + return XDR_PUTLONG (xdrs, lp);
139 +
140 + if (xdrs->x_op == XDR_DECODE)
141 + return XDR_GETLONG (xdrs, lp);
142 +
143 + if (xdrs->x_op == XDR_FREE)
144 + return TRUE;
145 +
146 + return FALSE;
147 +}
148 +
149 +/*
150 + * XDR unsigned integers
151 + */
152 +bool_t
153 +xdr_u_int (XDR *xdrs, u_int *up)
154 +{
155 +#if UINT_MAX < ULONG_MAX
156 + u_long l;
157 +
158 + switch (xdrs->x_op)
159 + {
160 + case XDR_ENCODE:
161 + l = (u_long) * up;
162 + return XDR_PUTLONG (xdrs, (long *) &l);
163 +
164 + case XDR_DECODE:
165 + if (!XDR_GETLONG (xdrs, (long *) &l))
166 + {
167 + return FALSE;
168 + }
169 + *up = (u_int) l;
170 + case XDR_FREE:
171 + return TRUE;
172 + }
173 + return FALSE;
174 +#elif UINT_MAX == ULONG_MAX
175 + return xdr_u_long (xdrs, (u_long *) up);
176 +#elif UINT_MAX == USHRT_MAX
177 + return xdr_short (xdrs, (short *) up);
178 +#else
179 +#error unexpected integer sizes in xdr_u_int()
180 +#endif
181 +}
182 +
183 +/*
184 + * XDR opaque data
185 + * Allows the specification of a fixed size sequence of opaque bytes.
186 + * cp points to the opaque object and cnt gives the byte length.
187 + */
188 +bool_t
189 +xdr_opaque (XDR *xdrs, caddr_t cp, u_int cnt)
190 +{
191 + u_int rndup;
192 + static char crud[BYTES_PER_XDR_UNIT];
193 +
194 + /*
195 + * if no data we are done
196 + */
197 + if (cnt == 0)
198 + return TRUE;
199 +
200 + /*
201 + * round byte count to full xdr units
202 + */
203 + rndup = cnt % BYTES_PER_XDR_UNIT;
204 + if (rndup > 0)
205 + rndup = BYTES_PER_XDR_UNIT - rndup;
206 +
207 + switch (xdrs->x_op)
208 + {
209 + case XDR_DECODE:
210 + if (!XDR_GETBYTES (xdrs, cp, cnt))
211 + {
212 + return FALSE;
213 + }
214 + if (rndup == 0)
215 + return TRUE;
216 + return XDR_GETBYTES (xdrs, (caddr_t)crud, rndup);
217 +
218 + case XDR_ENCODE:
219 + if (!XDR_PUTBYTES (xdrs, cp, cnt))
220 + {
221 + return FALSE;
222 + }
223 + if (rndup == 0)
224 + return TRUE;
225 + return XDR_PUTBYTES (xdrs, xdr_zero, rndup);
226 +
227 + case XDR_FREE:
228 + return TRUE;
229 + }
230 + return FALSE;
231 +}
232 +
233 +/*
234 + * XDR unsigned long integers
235 + * The definition of xdr_u_long() is kept for backward
236 + * compatibility. Instead xdr_u_int() should be used.
237 + */
238 +bool_t
239 +xdr_u_long (XDR *xdrs, u_long *ulp)
240 +{
241 + switch (xdrs->x_op)
242 + {
243 + case XDR_DECODE:
244 + {
245 + long int tmp;
246 +
247 + if (XDR_GETLONG (xdrs, &tmp) == FALSE)
248 + return FALSE;
249 +
250 + *ulp = (uint32_t) tmp;
251 + return TRUE;
252 + }
253 +
254 + case XDR_ENCODE:
255 + if (sizeof (uint32_t) != sizeof (u_long)
256 + && (uint32_t) *ulp != *ulp)
257 + return FALSE;
258 +
259 + return XDR_PUTLONG (xdrs, (long *) ulp);
260 +
261 + case XDR_FREE:
262 + return TRUE;
263 + }
264 + return FALSE;
265 +}
266 +
267 +#endif /* UCLIBC */
268 +
269 bool_t
270 xdr_xpasswd(XDR * xdrs, xpasswd * objp)
271 {