2 * Copyright 2000, International Business Machines Corporation and others.
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
11 Information Technology Center
12 Carnegie-Mellon University
16 #include <afsconfig.h>
17 #include <afs/param.h>
23 #include <afs/ptclient.h>
28 * Sanity check the access list.
30 * \param acl pointer to the acl structure to be checked
32 * \returns 0 if acl list is valid
34 * \retval EINVAL invalid values in the acl header
37 CheckAccessList(struct acl_accessList
*acl
)
39 if (acl
->total
< 0 || acl
->total
> ACL_MAXENTRIES
) {
42 if (acl
->positive
< 0 || acl
->negative
< 0
43 || (acl
->positive
+ acl
->negative
) != acl
->total
) {
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
)) {
55 * Convert the access list to network byte order.
57 * \param acl pointer to the acl structure to be converted
59 * \returns zero on success
61 * \retval EINVAL invalid values in the acl header
64 acl_HtonACL(struct acl_accessList
*acl
)
69 code
= CheckAccessList(acl
);
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
);
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
);
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
);
91 * Convert the access list to host byte order.
93 * \param acl pointer to the acl structure to be converted
95 * \returns zero on success
97 * \retval EINVAL invalid values in the acl header
100 acl_NtohACL(struct acl_accessList
*acl
)
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
);
111 code
= CheckAccessList(acl
);
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
);
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
);