393c6cdbc723b268a13ca77f19c98ca397024dc8
[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 <afs/param.h>
28 #include <afs/afsint.h>
29 #include <afs/vlserver.h>
30 #include <afs/vldbint.h>
31 #include <afs/dir.h>
32 #include <stdlib.h>
33 #include <string.h>
34 #include <errno.h>
35 #include "afscp.h"
36 #include "afscp_internal.h"
37
38
39 int afs_FetchACL(const struct afs_venusfid *dir,
40                  struct AFSOpaque *acl) {
41   int code, i, j;
42   struct AFSFid df = dir->fid;
43   struct afs_volume *vol;
44   struct AFSFetchStatus dfst;
45   struct AFSVolSync vs;
46   struct afs_volume *volume;
47   struct afs_server *server;
48
49   vol=afs_volumebyid(dir->cell, dir->fid.Volume);
50   if (!vol) {
51     afs_errno=ENOENT;
52     return -1;
53   }
54   code=ENOENT;
55   for (i=0;i<vol->nservers;i++) {
56     server=afs_serverbyindex(vol->servers[i]);
57     if (server && server->naddrs > 0) {
58       for (j=0;j < server->naddrs;j++) {
59         code=RXAFS_FetchACL(server->conns[j], &df, acl, &dfst, &vs);
60         if (code >= 0)
61           break;
62       }
63     }
64     if (code >= 0)
65       break;
66   }
67   if (code) {
68     _StatInvalidate(dir);
69     afs_errno=code;
70     return -1;
71   }
72   _StatStuff(dir, &dfst);
73   return 0;
74 }
75
76
77 int afs_StoreACL(const struct afs_venusfid *dir,
78                  struct AFSOpaque *acl) {
79   int code, i, j;
80   struct AFSFid df = dir->fid;
81   struct afs_volume *vol;
82   struct AFSFetchStatus dfst;
83   struct AFSVolSync vs;
84   struct afs_volume *volume;
85   struct afs_server *server;
86
87   vol=afs_volumebyid(dir->cell, dir->fid.Volume);
88   if (!vol) {
89     afs_errno=ENOENT;
90     return -1;
91   }
92   code=ENOENT;
93   for (i=0;i<vol->nservers;i++) {
94     server=afs_serverbyindex(vol->servers[i]);
95     if (server && server->naddrs > 0) {
96       for (j=0;j < server->naddrs;j++) {
97         code=RXAFS_StoreACL(server->conns[j], &df, acl, &dfst, &vs);
98         if (code >= 0)
99           break;
100       }
101     }
102     if (code >= 0)
103       break;
104   }
105   if (code) {
106     _StatInvalidate(dir);
107     afs_errno=code;
108     return -1;
109   }
110   _StatStuff(dir, &dfst);
111   return 0;
112 }