No Description

006-fix_xdr.patch 5.3KB

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