Import Upstream version 1.8.5
[hcoop/debian/openafs.git] / src / libafscp / afscp_acl.c
1 /* AUTORIGHTS
2 Copyright (C) 2003 - 2010 Chaskiel Grundman
3 All rights reserved
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
7 are met:
8
9 1. Redistributions of source code must retain the above copyright
10 notice, this list of conditions and the following disclaimer.
11
12 2. Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
15
16 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27 #include <afsconfig.h>
28 #include <afs/param.h>
29
30 #include <roken.h>
31
32 #include <afs/vlserver.h>
33 #include <afs/vldbint.h>
34 #include <afs/dir.h>
35 #include "afscp.h"
36 #include "afscp_internal.h"
37
38 int
39 afscp_FetchACL(const struct afscp_venusfid *dir, struct AFSOpaque *acl)
40 {
41 int code, i, j;
42 struct AFSFid df = dir->fid;
43 struct afscp_volume *vol;
44 struct AFSFetchStatus dfst;
45 struct AFSVolSync vs;
46 struct afscp_server *server;
47
48 vol = afscp_VolumeById(dir->cell, dir->fid.Volume);
49 if (vol == NULL) {
50 afscp_errno = ENOENT;
51 return -1;
52 }
53 code = ENOENT;
54 for (i = 0; i < vol->nservers; i++) {
55 server = afscp_ServerByIndex(vol->servers[i]);
56 if (server && server->naddrs > 0) {
57 for (j = 0; j < server->naddrs; j++) {
58 code = RXAFS_FetchACL(server->conns[j], &df, acl, &dfst, &vs);
59 if (code >= 0)
60 break;
61 }
62 }
63 if (code >= 0)
64 break;
65 }
66 if (code != 0) {
67 _StatInvalidate(dir);
68 afscp_errno = code;
69 return -1;
70 }
71 _StatStuff(dir, &dfst);
72 return 0;
73 }
74
75
76 int
77 afscp_StoreACL(const struct afscp_venusfid *dir, struct AFSOpaque *acl)
78 {
79 int code, i, j;
80 struct AFSFid df = dir->fid;
81 struct afscp_volume *vol;
82 struct AFSFetchStatus dfst;
83 struct AFSVolSync vs;
84 struct afscp_server *server;
85
86 vol = afscp_VolumeById(dir->cell, dir->fid.Volume);
87 if (vol == NULL) {
88 afscp_errno = ENOENT;
89 return -1;
90 }
91 code = ENOENT;
92 for (i = 0; i < vol->nservers; i++) {
93 server = afscp_ServerByIndex(vol->servers[i]);
94 if (server && server->naddrs > 0) {
95 for (j = 0; j < server->naddrs; j++) {
96 code = RXAFS_StoreACL(server->conns[j], &df, acl, &dfst, &vs);
97 if (code >= 0)
98 break;
99 }
100 }
101 if (code >= 0)
102 break;
103 }
104 if (code != 0) {
105 _StatInvalidate(dir);
106 afscp_errno = code;
107 return -1;
108 }
109 _StatStuff(dir, &dfst);
110 return 0;
111 }