Commit | Line | Data |
---|---|---|
805e021f CE |
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 | Information Technology Center | |
12 | Carnegie-Mellon University | |
13 | */ | |
14 | ||
15 | ||
16 | #include <afsconfig.h> | |
17 | #include <afs/param.h> | |
18 | ||
19 | #include <roken.h> | |
20 | ||
21 | #include <rx/xdr.h> | |
22 | #include <rx/rx.h> | |
23 | #include <afs/ptclient.h> | |
24 | ||
25 | #include "acl.h" | |
26 | ||
27 | /*! | |
28 | * Sanity check the access list. | |
29 | * | |
30 | * \param acl pointer to the acl structure to be checked | |
31 | * | |
32 | * \returns 0 if acl list is valid | |
33 | * \retval 0 success | |
34 | * \retval EINVAL invalid values in the acl header | |
35 | */ | |
36 | static int | |
37 | CheckAccessList(struct acl_accessList *acl) | |
38 | { | |
39 | if (acl->total < 0 || acl->total > ACL_MAXENTRIES) { | |
40 | return EINVAL; | |
41 | } | |
42 | if (acl->positive < 0 || acl->negative < 0 | |
43 | || (acl->positive + acl->negative) != acl->total) { | |
44 | return EINVAL; | |
45 | } | |
46 | /* Note: size may exceed sizeof(struct acl_accessList). */ | |
47 | if (acl->size < sizeof(struct acl_accessList) | |
48 | + (acl->total - 1) * sizeof(struct acl_accessEntry)) { | |
49 | return EINVAL; | |
50 | } | |
51 | return 0; | |
52 | } | |
53 | ||
54 | /*! | |
55 | * Convert the access list to network byte order. | |
56 | * | |
57 | * \param acl pointer to the acl structure to be converted | |
58 | * | |
59 | * \returns zero on success | |
60 | * \retval 0 success | |
61 | * \retval EINVAL invalid values in the acl header | |
62 | */ | |
63 | int | |
64 | acl_HtonACL(struct acl_accessList *acl) | |
65 | { | |
66 | int i; | |
67 | int code; | |
68 | ||
69 | code = CheckAccessList(acl); | |
70 | if (code) { | |
71 | return code; | |
72 | } | |
73 | ||
74 | for (i = 0; i < acl->positive; i++) { | |
75 | acl->entries[i].id = htonl(acl->entries[i].id); | |
76 | acl->entries[i].rights = htonl(acl->entries[i].rights); | |
77 | } | |
78 | for (i = acl->total - 1; i >= acl->total - acl->negative; i--) { | |
79 | acl->entries[i].id = htonl(acl->entries[i].id); | |
80 | acl->entries[i].rights = htonl(acl->entries[i].rights); | |
81 | } | |
82 | acl->size = htonl(acl->size); | |
83 | acl->version = htonl(acl->version); | |
84 | acl->total = htonl(acl->total); | |
85 | acl->positive = htonl(acl->positive); | |
86 | acl->negative = htonl(acl->negative); | |
87 | return (0); | |
88 | } | |
89 | ||
90 | /*! | |
91 | * Convert the access list to host byte order. | |
92 | * | |
93 | * \param acl pointer to the acl structure to be converted | |
94 | * | |
95 | * \returns zero on success | |
96 | * \retval 0 success | |
97 | * \retval EINVAL invalid values in the acl header | |
98 | */ | |
99 | int | |
100 | acl_NtohACL(struct acl_accessList *acl) | |
101 | { | |
102 | int i; | |
103 | int code; | |
104 | ||
105 | acl->size = ntohl(acl->size); | |
106 | acl->version = ntohl(acl->version); | |
107 | acl->total = ntohl(acl->total); | |
108 | acl->positive = ntohl(acl->positive); | |
109 | acl->negative = ntohl(acl->negative); | |
110 | ||
111 | code = CheckAccessList(acl); | |
112 | if (code) { | |
113 | return code; | |
114 | } | |
115 | ||
116 | for (i = 0; i < acl->positive; i++) { | |
117 | acl->entries[i].id = ntohl(acl->entries[i].id); | |
118 | acl->entries[i].rights = ntohl(acl->entries[i].rights); | |
119 | } | |
120 | for (i = acl->total - 1; i >= acl->total - acl->negative; i--) { | |
121 | acl->entries[i].id = ntohl(acl->entries[i].id); | |
122 | acl->entries[i].rights = ntohl(acl->entries[i].rights); | |
123 | } | |
124 | return (0); | |
125 | } |