bf673a0003415dd3b143c5c1884d163c8978be9b
[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
14 #if defined(UKERNEL)
15 #include "rx/xdr.h"
16 #include "afs/kauth.h"
17 #else /* defined(UKERNEL) */
18 #include <rx/xdr.h>
19 #include <afs/kauth.h>
20 #endif /* defined(UKERNEL) */
21
22 #define MAXBS   2048            /* try to avoid horrible allocs */
23
24 int
25 xdr_ka_CBS(XDR * x, struct ka_CBS *abbs)
26 {
27     afs_int32 len;
28     if (x->x_op == XDR_FREE) {
29         free(abbs->SeqBody);
30         return TRUE;
31     }
32
33     if (x->x_op == XDR_ENCODE) {
34         xdr_afs_int32(x, &abbs->SeqLen);
35         xdr_opaque(x, abbs->SeqBody, abbs->SeqLen);
36         return TRUE;
37     } else {
38         xdr_afs_int32(x, &len);
39         if (len < 0 || len > MAXBS)
40             return FALSE;
41         if (!abbs->SeqBody)
42             abbs->SeqBody = (char *)malloc(len);
43         abbs->SeqLen = len;
44         xdr_opaque(x, abbs->SeqBody, len);
45         return TRUE;
46     }
47 }
48
49 int
50 xdr_ka_BBS(XDR * x, struct ka_BBS *abbs)
51 {
52     afs_int32 maxLen, len;
53     if (x->x_op == XDR_FREE) {
54         free(abbs->SeqBody);
55         return TRUE;
56     }
57
58     if (x->x_op == XDR_ENCODE) {
59         if (!xdr_afs_int32(x, &abbs->MaxSeqLen)
60             || !xdr_afs_int32(x, &abbs->SeqLen)
61             || !xdr_opaque(x, abbs->SeqBody, abbs->SeqLen))
62             return FALSE;
63         return TRUE;
64     } else {
65         if (!xdr_afs_int32(x, &maxLen) || !xdr_afs_int32(x, &len) || (len < 0)
66             || (len > MAXBS) || (len > maxLen))
67             return FALSE;
68         if (!abbs->SeqBody)
69             abbs->SeqBody = (char *)malloc(maxLen);
70         abbs->MaxSeqLen = maxLen;
71         abbs->SeqLen = len;
72         if (!xdr_opaque(x, abbs->SeqBody, len))
73             return FALSE;
74         return TRUE;
75     }
76 }