f9aec80afa430c77dbe5ac8b6ff1bb923f611910
[openafs.git] / src / libacl / netprocs.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         Information Technology Center
12         Carnegie-Mellon University
13 */
14
15
16 #include <afsconfig.h>
17 #include <afs/param.h>
18
19
20 #include <sys/types.h>
21 #ifdef AFS_NT40_ENV
22 #include <winsock2.h>
23 #else
24 #include <netinet/in.h>
25 #endif
26 #include <rx/xdr.h>
27 #include <rx/rx.h>
28 #include <afs/ptclient.h>
29 #include "acl.h"
30
31 int
32 acl_HtonACL(struct acl_accessList *acl)
33 {
34     /* Converts the access list defined by acl to network order.  Returns 0 always. */
35
36     int i;
37     if (htonl(1) == 1)
38         return (0);             /* no swapping needed */
39     for (i = 0; i < acl->positive; i++) {
40         acl->entries[i].id = htonl(acl->entries[i].id);
41         acl->entries[i].rights = htonl(acl->entries[i].rights);
42     }
43     for (i = acl->total - 1; i >= acl->total - acl->negative; i--) {
44         acl->entries[i].id = htonl(acl->entries[i].id);
45         acl->entries[i].rights = htonl(acl->entries[i].rights);
46     }
47     acl->size = htonl(acl->size);
48     acl->version = htonl(acl->version);
49     acl->total = htonl(acl->total);
50     acl->positive = htonl(acl->positive);
51     acl->negative = htonl(acl->negative);
52     return (0);
53 }
54
55 int
56 acl_NtohACL(struct acl_accessList *acl)
57 {
58     /* Converts the access list defined by acl to network order. Returns 0 always. */
59
60     int i;
61     if (ntohl(1) == 1)
62         return (0);             /* no swapping needed */
63     acl->size = ntohl(acl->size);
64     acl->version = ntohl(acl->version);
65     acl->total = ntohl(acl->total);
66     acl->positive = ntohl(acl->positive);
67     acl->negative = ntohl(acl->negative);
68     for (i = 0; i < acl->positive; i++) {
69         acl->entries[i].id = ntohl(acl->entries[i].id);
70         acl->entries[i].rights = ntohl(acl->entries[i].rights);
71     }
72     for (i = acl->total - 1; i >= acl->total - acl->negative; i--) {
73         acl->entries[i].id = ntohl(acl->entries[i].id);
74         acl->entries[i].rights = ntohl(acl->entries[i].rights);
75     }
76     return (0);
77 }