~ubuntu-branches/ubuntu/oneiric/nis/oneiric-proposed

« back to all changes in this revision

Viewing changes to ypserv-2.18/ypxfr/ypxfr_xdr.c

  • Committer: Bazaar Package Importer
  • Author(s): Scott James Remnant
  • Date: 2005-11-16 23:42:06 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20051116234206-p00omaw5ji5q0qhr
Tags: 3.15-3ubuntu1
Resynchronise with Debian.  (me)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (c) 1996, 1997, 1999, 2001, 2003  Thorsten Kukuk
 
2
   Author: Thorsten Kukuk <kukuk@suse.de>
 
3
 
 
4
   The YP Server is free software; you can redistribute it and/or
 
5
   modify it under the terms of the GNU General Public License
 
6
   version 2 as published by the Free Software Foundation.
 
7
 
 
8
   The YP Server is distributed in the hope that it will be useful,
 
9
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 
11
   General Public License for more details.
 
12
 
 
13
   You should have received a copy of the GNU General Public
 
14
   License along with the YP Server; see the file COPYING. If
 
15
   not, write to the Free Software Foundation, Inc., 675 Mass Ave,
 
16
   Cambridge, MA 02139, USA. */
 
17
 
 
18
#ifdef HAVE_CONFIG_H
 
19
#include "config.h"
 
20
#endif
 
21
 
 
22
#define _GNU_SOURCE
 
23
 
 
24
#include <stdio.h>
 
25
#include <string.h>
 
26
#include <memory.h>
 
27
#include <unistd.h>
 
28
#include <rpc/rpc.h>
 
29
#include "yp.h"
 
30
 
 
31
struct {
 
32
  union {
 
33
    ypstat (*encoder) (char *, int, char **, int *, char **, int *);
 
34
    int (*decoder) (int, char *, int, char *, int, char *);
 
35
  }
 
36
  foreach;
 
37
  char *data;
 
38
} *xdr_ypall_callback;
 
39
 
 
40
 
 
41
bool_t
 
42
xdr_keydat (XDR *xdrs, keydat *objp)
 
43
{
 
44
  if (!xdr_bytes (xdrs, (char **) &objp->keydat_val,
 
45
                  (u_int *) &objp->keydat_len, ~0))
 
46
    return FALSE;
 
47
  return TRUE;
 
48
}
 
49
 
 
50
bool_t
 
51
xdr_valdat (XDR *xdrs, valdat *objp)
 
52
{
 
53
  if (!xdr_bytes (xdrs, (char **) &objp->valdat_val,
 
54
                  (u_int *) &objp->valdat_len, ~0))
 
55
    return FALSE;
 
56
  return TRUE;
 
57
}
 
58
 
 
59
bool_t
 
60
xdr_ypresp_val (XDR *xdrs, ypresp_val *objp)
 
61
{
 
62
  if (!xdr_ypstat (xdrs, &objp->stat))
 
63
    return FALSE;
 
64
  if (!xdr_valdat (xdrs, &objp->val))
 
65
    return FALSE;
 
66
  return TRUE;
 
67
}
 
68
 
 
69
bool_t
 
70
xdr_ypresp_key_val (XDR *xdrs, ypresp_key_val *objp)
 
71
{
 
72
  if (!xdr_ypstat (xdrs, &objp->stat))
 
73
    return FALSE;
 
74
 
 
75
  if (!xdr_valdat (xdrs, &objp->val))
 
76
    return FALSE;
 
77
 
 
78
  if (!xdr_keydat (xdrs, &objp->key))
 
79
    return FALSE;
 
80
 
 
81
  return TRUE;
 
82
}
 
83
 
 
84
bool_t
 
85
xdr_ypresp_order (XDR *xdrs, ypresp_order *objp)
 
86
{
 
87
  if (!xdr_ypstat (xdrs, &objp->stat))
 
88
    return FALSE;
 
89
  if (!xdr_u_int (xdrs, &objp->ordernum))
 
90
    return FALSE;
 
91
  return TRUE;
 
92
}
 
93
 
 
94
bool_t
 
95
xdr_ypbind_setdom (XDR *xdrs, ypbind_setdom *objp)
 
96
{
 
97
  if (!xdr_domainname (xdrs, &objp->ypsetdom_domain))
 
98
    return FALSE;
 
99
 
 
100
  if (!xdr_ypbind_binding (xdrs, &objp->ypsetdom_binding))
 
101
    return FALSE;
 
102
 
 
103
  if (!xdr_u_int (xdrs, &objp->ypsetdom_vers))
 
104
    return FALSE;
 
105
 
 
106
  return TRUE;
 
107
}
 
108
 
 
109
bool_t
 
110
xdr_ypreq_key (XDR *xdrs, ypreq_key *objp)
 
111
{
 
112
  if (!xdr_domainname (xdrs, &objp->domain))
 
113
    return FALSE;
 
114
 
 
115
  if (!xdr_mapname (xdrs, &objp->map))
 
116
    return FALSE;
 
117
 
 
118
  if (!xdr_keydat (xdrs, &objp->key))
 
119
    return FALSE;
 
120
 
 
121
  return TRUE;
 
122
}
 
123
 
 
124
bool_t
 
125
ypxfr_xdr_ypresp_all (XDR *xdrs, ypresp_all *objp)
 
126
{
 
127
  int CallAgain = 0;
 
128
 
 
129
  if (xdrs->x_op == XDR_DECODE)
 
130
    {
 
131
      while (1)
 
132
        {
 
133
          int s = objp->ypresp_all_u.val.stat;
 
134
          memset (objp, '\0', sizeof (*objp));
 
135
          objp->ypresp_all_u.val.stat = s;
 
136
          if (!xdr_bool (xdrs, &objp->more))
 
137
            return FALSE;
 
138
 
 
139
          switch (objp->more)
 
140
            {
 
141
            case TRUE:
 
142
              if (!xdr_ypresp_key_val (xdrs, &objp->ypresp_all_u.val))
 
143
                {
 
144
                  printf ("xdr_ypresp_key_val failed\n");
 
145
                  return (FALSE);
 
146
                }
 
147
 
 
148
              if (CallAgain == 0)
 
149
                {
 
150
                  CallAgain = (*(xdr_ypall_callback->foreach.decoder))
 
151
                    (objp->ypresp_all_u.val.stat,
 
152
                     objp->ypresp_all_u.val.key.keydat_val,
 
153
                     objp->ypresp_all_u.val.key.keydat_len,
 
154
                     objp->ypresp_all_u.val.val.valdat_val,
 
155
                     objp->ypresp_all_u.val.val.valdat_len,
 
156
                     xdr_ypall_callback->data);
 
157
                }
 
158
              break;
 
159
            case FALSE:
 
160
              return TRUE;
 
161
            }
 
162
          xdr_free ((xdrproc_t) ypxfr_xdr_ypresp_all, (char *) objp);
 
163
        }
 
164
    }
 
165
  else if (xdrs->x_op == XDR_ENCODE)
 
166
    {
 
167
      while (1)
 
168
        {
 
169
          if (!xdr_bool (xdrs, &(objp->more)))
 
170
            return FALSE;
 
171
 
 
172
          if (!xdr_ypresp_key_val (xdrs, &objp->ypresp_all_u.val))
 
173
            {
 
174
              printf ("xdr_ypresp_key_val failed\n");
 
175
              return FALSE;
 
176
            }
 
177
          if (objp->ypresp_all_u.val.stat != YP_TRUE)
 
178
            {
 
179
              objp->more = FALSE;
 
180
              if (!xdr_bool (xdrs, &(objp->more)))
 
181
                return FALSE;
 
182
 
 
183
              return TRUE;
 
184
            }
 
185
          objp->ypresp_all_u.val.stat =
 
186
            (*(xdr_ypall_callback->foreach.encoder))
 
187
            (objp->ypresp_all_u.val.key.keydat_val,
 
188
             objp->ypresp_all_u.val.key.keydat_len,
 
189
             &(objp->ypresp_all_u.val.key.keydat_val),
 
190
             (int *) &(objp->ypresp_all_u.val.key.keydat_len),
 
191
             &(objp->ypresp_all_u.val.val.valdat_val),
 
192
             (int *) &(objp->ypresp_all_u.val.val.valdat_len));
 
193
        }
 
194
    }
 
195
  else
 
196
    return TRUE;
 
197
}
 
198
 
 
199
/* Default timeout can be changed using clnt_control() */
 
200
static struct timeval TIMEOUT = { 25, 0 };
 
201
 
 
202
enum clnt_stat
 
203
ypproc_all_2 (ypreq_nokey *argp, ypresp_all *clnt_res, CLIENT *clnt)
 
204
{
 
205
  memset(clnt_res, 0, sizeof(ypresp_all));
 
206
  return (clnt_call(clnt, YPPROC_ALL,
 
207
                    (xdrproc_t) xdr_ypreq_nokey, (caddr_t) argp,
 
208
                    (xdrproc_t) ypxfr_xdr_ypresp_all, (caddr_t) clnt_res,
 
209
                    TIMEOUT));
 
210
}