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