home *** CD-ROM | disk | FTP | other *** search
/ Serving the Web / ServingTheWeb1995.disc1of1.iso / linux / slacksrce / d / libc / libc-4.6 / libc-4 / libc-linux / yp / yp_xdr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-25  |  9.4 KB  |  458 lines

  1. /*
  2.  * Copyright (c) 1992/3 Theo de Raadt <deraadt@fsa.ca>
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  * 1. Redistributions of source code must retain the above copyright
  9.  *    notice, this list of conditions and the following disclaimer.
  10.  * 2. Redistributions in binary form must reproduce the above copyright
  11.  *    notice, this list of conditions and the following disclaimer in the
  12.  *    documentation and/or other materials provided with the distribution.
  13.  * 3. The name of the author may not be used to endorse or promote
  14.  *    products derived from this software without specific prior written
  15.  *    permission.
  16.  *
  17.  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
  18.  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  19.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  21.  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  22.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  23.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  24.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  25.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  26.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  27.  * SUCH DAMAGE.
  28.  */
  29.  
  30. /*
  31.  *  Modifications for linux by Swen Thuemmler <swen@uni-paderborn.de>
  32.  */
  33.  
  34. #include "yp.h"
  35. #include <rpcsvc/yp_prot.h>
  36. #include <string.h>
  37.  
  38. #if 0
  39. bool_t
  40. xdr_ypxfrstat(XDR *xdrs, enum ypxfrstat *objp)
  41. {
  42.   if (!xdr_enum(xdrs, (enum_t *)objp))
  43.     {
  44.       return (FALSE);
  45.     }
  46.   return (TRUE);
  47. }
  48. #endif
  49.  
  50. bool_t
  51. xdr_domainname(XDR *xdrs, char *objp)
  52. {
  53.   if (!xdr_string(xdrs, &objp, YPMAXDOMAIN))
  54.     {
  55.       return (FALSE);
  56.     }
  57.   return (TRUE);
  58. }
  59.  
  60. bool_t
  61. xdr_mapname(XDR *xdrs, mapname *objp)
  62. {
  63.   if (!xdr_string(xdrs, objp, YPMAXMAP))
  64.     {
  65.       return (FALSE);
  66.     }
  67.   return (TRUE);
  68. }
  69.  
  70. bool_t
  71. xdr_peername(XDR *xdrs, peername *objp)
  72. {
  73.   if (!xdr_string(xdrs, objp, YPMAXPEER))
  74.     {
  75.       return (FALSE);
  76.     }
  77.   return (TRUE);
  78. }
  79.  
  80. bool_t
  81. xdr_datum(XDR *xdrs, datum *objp)
  82. {
  83.   if (!xdr_bytes(xdrs,
  84.                  (char **)&objp->dptr,
  85.                  (u_int *)&objp->dsize,
  86.                  YPMAXRECORD))
  87.     {
  88.       return (FALSE);
  89.     }
  90.   return (TRUE);
  91. }
  92.  
  93. #if 0
  94. bool_t
  95. xdr_ypmap_parms(XDR *xdrs, struct ypmap_parms *objp)
  96. {
  97.   if (!xdr_domainname(xdrs, objp->domain))
  98.     {
  99.       return (FALSE);
  100.     }
  101.   if (!xdr_mapname(xdrs, &objp->map))
  102.     {
  103.       return (FALSE);
  104.     }
  105.   if (!xdr_u_long(xdrs, &objp->ordernum))
  106.     {
  107.       return (FALSE);
  108.     }
  109.   if (!xdr_peername(xdrs, &objp->owner))
  110.     {
  111.       return (FALSE);
  112.     }
  113.   return (TRUE);
  114. }
  115. #endif
  116.  
  117. bool_t
  118. xdr_ypreq_key(XDR *xdrs, struct ypreq_key *objp)
  119. {
  120.   if (!xdr_domainname(xdrs, objp->domain))
  121.     {
  122.       return (FALSE);
  123.     }
  124.   if (!xdr_mapname(xdrs, &objp->map))
  125.     {
  126.       return (FALSE);
  127.     }
  128.   if (!xdr_datum(xdrs, &objp->keydat))
  129.     {
  130.       return (FALSE);
  131.     }
  132.   return (TRUE);
  133. }
  134.  
  135. bool_t
  136. xdr_ypreq_nokey(XDR *xdrs, struct ypreq_nokey *objp)
  137. {
  138.   if (!xdr_domainname(xdrs, objp->domain))
  139.     {
  140.       return (FALSE);
  141.     }
  142.   if (!xdr_mapname(xdrs, &objp->map))
  143.     {
  144.       return (FALSE);
  145.     }
  146.   return (TRUE);
  147. }
  148.  
  149. #if 0
  150. bool_t
  151. xdr_ypreq_xfr(XDR *xdrs, struct ypreq_xfr *objp)
  152. {
  153.   if (!xdr_ypmap_parms(xdrs, &objp->map_parms))
  154.     {
  155.       return (FALSE);
  156.     }
  157.   if (!xdr_u_long(xdrs, &objp->transid))
  158.     {
  159.       return (FALSE);
  160.     }
  161.   if (!xdr_u_long(xdrs, &objp->proto))
  162.     {
  163.       return (FALSE);
  164.     }
  165.   if (!xdr_u_short(xdrs, &objp->port))
  166.     {
  167.       return (FALSE);
  168.     }
  169.   return (TRUE);
  170. }
  171. #endif
  172.  
  173. bool_t
  174. xdr_ypresp_val(XDR *xdrs, struct ypresp_val *objp)
  175. {
  176.   if (!xdr_u_long(xdrs, &objp->status))
  177.     {
  178.       return (FALSE);
  179.     }
  180.   if (!xdr_datum(xdrs, &objp->valdat))
  181.     {
  182.       return (FALSE);
  183.     }
  184.   return (TRUE);
  185. }
  186.  
  187. bool_t
  188. xdr_ypresp_key_val(XDR *xdrs, struct ypresp_key_val *objp)
  189. {
  190.   if (!xdr_u_long(xdrs, &objp->status))
  191.     {
  192.       return (FALSE);
  193.     }
  194. /* Silly. The server responds in wrong order !? */
  195.   if (!xdr_datum(xdrs, &objp->valdat))
  196.     {
  197.       return (FALSE);
  198.     }
  199.   if (!xdr_datum(xdrs, &objp->keydat))
  200.     {
  201.       return (FALSE);
  202.     }
  203.   return (TRUE);
  204. }
  205.  
  206. bool_t
  207. xdr_ypresp_master(XDR *xdrs, struct ypresp_master *objp)
  208. {
  209.   if (!xdr_u_long(xdrs, &objp->status))
  210.     {
  211.       return (FALSE);
  212.     }
  213.   if (!xdr_peername(xdrs, &objp->master))
  214.     {
  215.       return (FALSE);
  216.     }
  217.   return (TRUE);
  218. }
  219.  
  220. bool_t
  221. xdr_ypresp_order(XDR *xdrs, struct ypresp_order *objp)
  222. {
  223.   if (!xdr_u_long(xdrs, &objp->status))
  224.     {
  225.       return (FALSE);
  226.     }
  227.   if (!xdr_u_long(xdrs, &objp->ordernum))
  228.     {
  229.       return (FALSE);
  230.     }
  231.   return (TRUE);
  232. }
  233.  
  234. bool_t
  235. xdr_ypresp_all(XDR *xdrs, struct ypresp_all *objp)
  236. {
  237.   if (!xdr_bool(xdrs, &objp->more))
  238.     {
  239.       return (FALSE);
  240.     }
  241.   switch (objp->more) {
  242.   case TRUE:
  243.     if (!xdr_ypresp_key_val(xdrs, &objp->ypresp_all_u.val))
  244.       {
  245.         return (FALSE);
  246.       }
  247.     break;
  248.   case FALSE:
  249.     break;
  250.   default:
  251.     return (FALSE);
  252.   }
  253.   return (TRUE);
  254. }
  255.  
  256. bool_t
  257. xdr_ypmaplist_str (XDR *xdrs, char *objp)
  258. {
  259.   if (!xdr_mapname(xdrs, &objp))
  260.     {
  261.       return (FALSE);
  262.     }
  263.   return (TRUE);
  264. }
  265.  
  266. bool_t
  267. xdr_ypmaplist(XDR *xdrs, struct ypmaplist *objp)
  268. {
  269.   if (!xdr_ypmaplist_str(xdrs, objp->ypml_name))
  270.     {
  271.       return (FALSE);
  272.     }
  273.   if (!xdr_pointer(xdrs,
  274.                    (char **)&objp->ypml_next,
  275.                    sizeof(struct ypmaplist),
  276.                    (xdrproc_t)xdr_ypmaplist))
  277.     {
  278.       return (FALSE);
  279.     }
  280.   return (TRUE);
  281. }
  282.  
  283. bool_t
  284. xdr_ypresp_maplist(XDR *xdrs, struct ypresp_maplist *objp)
  285. {
  286.   if (!xdr_u_long(xdrs, &objp->status))
  287.     {
  288.       return (FALSE);
  289.     }
  290.   if (!xdr_pointer(xdrs, (char **)&objp->list,
  291.                    sizeof(struct ypmaplist), (xdrproc_t)xdr_ypmaplist))
  292.     {
  293.       return (FALSE);
  294.     }
  295.   return (TRUE);
  296. }
  297.  
  298. #if 0
  299. bool_t
  300. xdr_yppushresp_xfr(XDR *xdrs, struct yppushresp_xfr *objp)
  301. {
  302.   if (!xdr_u_long(xdrs, &objp->transid))
  303.     {
  304.       return (FALSE);
  305.     }
  306.   if (!xdr_u_long(xdrs, &objp->status))
  307.     {
  308.       return (FALSE);
  309.     }
  310.   return (TRUE);
  311. }
  312. #endif
  313.  
  314. bool_t
  315. xdr_ypbind_resptype(XDR *xdrs, enum ypbind_resptype *objp)
  316. {
  317.   if (!xdr_enum(xdrs, (enum_t *)objp))
  318.     {
  319.       return (FALSE);
  320.     }
  321.   return (TRUE);
  322. }
  323.  
  324. bool_t
  325. xdr_ypbind_binding(XDR *xdrs, struct ypbind_binding *objp)
  326. {
  327.   if (!xdr_opaque(xdrs, (caddr_t) &objp->ypbind_binding_addr, 4))
  328.     {
  329.       return (FALSE);
  330.     }
  331.   if (!xdr_opaque(xdrs, (caddr_t) &objp->ypbind_binding_port, 2))
  332.     {
  333.       return (FALSE);
  334.     }
  335.   return (TRUE);
  336. }
  337.  
  338. bool_t
  339. xdr_ypbind_resp(XDR *xdrs, struct ypbind_resp *objp)
  340. {
  341.   if (!xdr_ypbind_resptype(xdrs, &objp->ypbind_status))
  342.     {
  343.       return (FALSE);
  344.     }
  345.   switch (objp->ypbind_status) {
  346.   case YPBIND_FAIL_VAL:
  347.     if (!xdr_u_long(xdrs, &objp->ypbind_respbody.ypbind_error))
  348.       {
  349.         return (FALSE);
  350.       }
  351.     break;
  352.   case YPBIND_SUCC_VAL:
  353.     if (!xdr_ypbind_binding(xdrs, &objp->ypbind_respbody.ypbind_bindinfo))
  354.       {
  355.         return (FALSE);
  356.       }
  357.     break;
  358.   default:
  359.     return (FALSE);
  360.   }
  361.   return (TRUE);
  362. }
  363.  
  364. bool_t
  365. xdr_ypbind_setdom(XDR *xdrs, struct ypbind_setdom *objp)
  366. {
  367.   if (!xdr_domainname(xdrs, objp->ypsetdom_domain))
  368.     {
  369.       return (FALSE);
  370.     }
  371.   if (!xdr_ypbind_binding(xdrs, &objp->ypsetdom_binding))
  372.     {
  373.       return (FALSE);
  374.     }
  375.   if (!xdr_u_short(xdrs, &objp->ypsetdom_vers))
  376.     {
  377.       return (FALSE);
  378.     }
  379.   return (TRUE);
  380. }
  381.  
  382. bool_t
  383. xdr_ypresp_all_seq (XDR *xdrs, u_long *objp)
  384. {
  385.   struct ypresp_all out;
  386.   u_long status;
  387.   char *key, *val;
  388.   int r;
  389.   
  390.   bzero (&out, sizeof out);
  391.   while (1)
  392.     {
  393.       if (!xdr_ypresp_all (xdrs, &out))
  394.         {
  395.           xdr_free (xdr_ypresp_all, (char *) &out);
  396.           *objp = YP_YPERR;
  397.           return FALSE;
  398.         }
  399.       if (out.more == 0)
  400.         {
  401.           xdr_free (xdr_ypresp_all, (char *) &out);
  402.           return FALSE;
  403.         }
  404.       status = out.ypresp_all_u.val.status;
  405.       switch (status)
  406.         {
  407.         case YP_TRUE:
  408.           key = (char *) malloc (out.ypresp_all_u.val.keydat.dsize + 1);
  409.           bcopy (out.ypresp_all_u.val.keydat.dptr, key,
  410.                  out.ypresp_all_u.val.keydat.dsize);
  411.           key[out.ypresp_all_u.val.keydat.dsize] = '\0';
  412.           val = (char *) malloc (out.ypresp_all_u.val.valdat.dsize + 1);
  413.           bcopy (out.ypresp_all_u.val.valdat.dptr, val,
  414.                  out.ypresp_all_u.val.valdat.dsize);
  415.           val[out.ypresp_all_u.val.valdat.dsize] = '\0';
  416.           xdr_free (xdr_ypresp_all, (char *) &out);
  417.           
  418.           r = (*ypresp_allfn) (status,
  419.                                key, out.ypresp_all_u.val.keydat.dsize,
  420.                                val, out.ypresp_all_u.val.valdat.dsize,
  421.                                ypresp_data);
  422.           *objp = status;
  423.           free (key);
  424.           free (val);
  425.           if (r)
  426.             return TRUE;
  427.           break;
  428.         case YP_NOMORE:
  429.           xdr_free (xdr_ypresp_all, (char *) &out);
  430.           return TRUE;
  431.         default:
  432.           xdr_free (xdr_ypresp_all, (char *) &out);
  433.           *objp = status;
  434.           return TRUE;
  435.         }
  436.     }
  437. }
  438.  
  439. bool_t
  440. xdr_yp_inaddr (XDR *xdrs, struct in_addr *objp)
  441. {
  442.   if (!xdr_opaque (xdrs, (caddr_t) & objp->s_addr, sizeof objp->s_addr))
  443.     {
  444.       return (FALSE);
  445.     }
  446.   return (TRUE);
  447. }
  448.  
  449. bool_t
  450. xdr_ypstat (XDR *xdrs, enum ypbind_resptype *objp)
  451. {
  452.   if (!xdr_enum (xdrs, (enum_t *) objp))
  453.     {
  454.       return (FALSE);
  455.     }
  456.   return (TRUE);
  457. }
  458.