Initial IBM OpenAFS 1.0 tree
[openafs.git] / src / kauth / kaaux.c
1 /*
2  * (C) COPYRIGHT IBM CORPORATION 1988
3  * LICENSED MATERIALS - PROPERTY OF IBM
4  */
5 /*
6  * Revision 1.5  89/03/14  13:19:57
7  * Rename CBS and BBS to ka_* to avoid collisions with afsint.h.
8  * 
9  * Revision 1.4  88/12/09  14:35:57
10  * Fixed a bug where BBS code didn't check error code which caused
11  *   problems when Ubik retransmitted packets after previous call
12  *   aborted and didn't return output parameters.
13  * 
14  * Revision 1.3  88/11/18  09:07:47
15  * Conversion to Rx.
16  * 
17  * Revision 1.2  88/09/20  11:38:13
18  * Added IBM Copyright
19  * 
20  * Revision 1.1  88/08/29  12:48:27
21  * Initial revision
22  *  */
23
24 #if defined(UKERNEL)
25 #include "../rx/xdr.h"
26 #include "../afsint/kauth.h"
27 #else /* defined(UKERNEL) */
28 #include <rx/xdr.h>
29 #include "kauth.h"
30 #endif /* defined(UKERNEL) */
31
32 #define MAXBS   2048            /* try to avoid horrible allocs */
33
34 int xdr_ka_CBS(
35   XDR *x,
36   struct ka_CBS *abbs)
37 {
38     afs_int32 len;
39     if (x->x_op == XDR_FREE) {
40         free(abbs->SeqBody);
41         return TRUE;
42     }
43
44     if (x->x_op == XDR_ENCODE) {
45         xdr_afs_int32(x, &abbs->SeqLen);
46         xdr_opaque(x, abbs->SeqBody, abbs->SeqLen);
47         return TRUE;
48     }
49     else {
50         xdr_afs_int32(x, &len);
51         if (len < 0 || len > MAXBS) return FALSE;
52         if (!abbs->SeqBody) abbs->SeqBody = (char *) malloc(len);
53         abbs->SeqLen = len;
54         xdr_opaque(x, abbs->SeqBody, len);
55         return TRUE;
56     }
57 }
58
59 int xdr_ka_BBS(
60   XDR *x,
61   struct ka_BBS *abbs)
62 {
63     afs_int32 maxLen, len;
64     if (x->x_op == XDR_FREE) {
65         free(abbs->SeqBody);
66         return TRUE;
67     }
68
69     if (x->x_op == XDR_ENCODE) {
70         if (!xdr_afs_int32(x, &abbs->MaxSeqLen) ||
71             !xdr_afs_int32(x, &abbs->SeqLen) ||
72             !xdr_opaque(x, abbs->SeqBody, abbs->SeqLen))
73             return FALSE;
74         return TRUE;
75     }
76     else {
77         if (!xdr_afs_int32(x, &maxLen) ||
78             !xdr_afs_int32(x, &len) ||
79             (len < 0) || (len > MAXBS) || (len > maxLen))
80             return FALSE;
81         if (!abbs->SeqBody) abbs->SeqBody = (char *) malloc(maxLen);
82         abbs->MaxSeqLen = maxLen;
83         abbs->SeqLen = len;
84         if (!xdr_opaque(x, abbs->SeqBody, len)) return FALSE;
85         return TRUE;
86     }
87 }
88