no-copy-libafs-builds-20021015
[openafs.git] / src / kauth / kaaux.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 #include <afsconfig.h>
11 #include <afs/param.h>
12
13 RCSID("$Header$");
14
15 #if defined(UKERNEL)
16 #include "rx/xdr.h"
17 #include "afs/kauth.h"
18 #else /* defined(UKERNEL) */
19 #include <rx/xdr.h>
20 #include "kauth.h"
21 #endif /* defined(UKERNEL) */
22
23 #define MAXBS   2048            /* try to avoid horrible allocs */
24
25 int xdr_ka_CBS(
26   XDR *x,
27   struct ka_CBS *abbs)
28 {
29     afs_int32 len;
30     if (x->x_op == XDR_FREE) {
31         free(abbs->SeqBody);
32         return TRUE;
33     }
34
35     if (x->x_op == XDR_ENCODE) {
36         xdr_afs_int32(x, &abbs->SeqLen);
37         xdr_opaque(x, abbs->SeqBody, abbs->SeqLen);
38         return TRUE;
39     }
40     else {
41         xdr_afs_int32(x, &len);
42         if (len < 0 || len > MAXBS) return FALSE;
43         if (!abbs->SeqBody) abbs->SeqBody = (char *) malloc(len);
44         abbs->SeqLen = len;
45         xdr_opaque(x, abbs->SeqBody, len);
46         return TRUE;
47     }
48 }
49
50 int xdr_ka_BBS(
51   XDR *x,
52   struct ka_BBS *abbs)
53 {
54     afs_int32 maxLen, len;
55     if (x->x_op == XDR_FREE) {
56         free(abbs->SeqBody);
57         return TRUE;
58     }
59
60     if (x->x_op == XDR_ENCODE) {
61         if (!xdr_afs_int32(x, &abbs->MaxSeqLen) ||
62             !xdr_afs_int32(x, &abbs->SeqLen) ||
63             !xdr_opaque(x, abbs->SeqBody, abbs->SeqLen))
64             return FALSE;
65         return TRUE;
66     }
67     else {
68         if (!xdr_afs_int32(x, &maxLen) ||
69             !xdr_afs_int32(x, &len) ||
70             (len < 0) || (len > MAXBS) || (len > maxLen))
71             return FALSE;
72         if (!abbs->SeqBody) abbs->SeqBody = (char *) malloc(maxLen);
73         abbs->MaxSeqLen = maxLen;
74         abbs->SeqLen = len;
75         if (!xdr_opaque(x, abbs->SeqBody, len)) return FALSE;
76         return TRUE;
77     }
78 }
79