make fetch_block_size uint64_t
[arla.git] / appl / fs / fs_la.c
blob8bfc7fc7e964cd021bf5f1d0ef15b7e8fa78fe22
1 /*
2 * Copyright (c) 1995 - 2001 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the Institute nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
34 #include "fs_local.h"
36 RCSID("$Id$");
38 static void
39 skipline(char **curptr)
41 while(**curptr!='\n') (*curptr)++;
42 (*curptr)++;
45 struct Acl *
46 afs_getacl(char *path)
48 struct Acl *oldacl;
49 struct ViceIoctl a_params;
50 struct AclEntry *pos=NULL;
51 struct AclEntry *neg=NULL;
52 char *curptr;
53 char tmpname[MAXNAME];
54 int tmprights;
55 int i;
57 oldacl=(struct Acl *) malloc(sizeof(struct Acl));
58 if(oldacl == NULL) {
59 printf("fs: Out of memory\n");
60 return NULL;
63 a_params.in_size=0;
64 a_params.out_size=MAXSIZE;
65 a_params.in=NULL;
66 a_params.out=malloc(MAXSIZE);
68 if(a_params.out == NULL) {
69 printf ("fs: Out of memory\n");
70 free (oldacl);
71 return NULL;
74 if(k_pioctl(path,ARLA_VIOCGETAL,&a_params,1)==-1) {
75 fserr(PROGNAME, errno, path);
76 free (oldacl);
77 free(a_params.out);
78 return NULL;
81 curptr=a_params.out;
83 /* Number of pos/neg entries parsing */
84 sscanf(curptr, "%d\n%d\n", &oldacl->NumPositiveEntries,
85 &oldacl->NumNegativeEntries);
86 skipline(&curptr);
87 skipline(&curptr);
89 if(oldacl->NumPositiveEntries)
90 for(i=0; i<oldacl->NumPositiveEntries; i++) {
91 sscanf(curptr, "%99s %d", tmpname, &tmprights);
92 skipline(&curptr);
93 if(!i) {
94 pos=malloc(sizeof(struct AclEntry));
95 oldacl->pos=pos;
97 else {
98 pos->next=malloc(sizeof(struct AclEntry));
99 pos=pos->next;
101 pos->RightsMask=tmprights;
102 strlcpy(pos->name, tmpname, sizeof(pos->name));
103 pos->next=NULL;
106 if(oldacl->NumNegativeEntries)
107 for(i=0; i<oldacl->NumNegativeEntries; i++) {
108 sscanf(curptr, "%99s %d", tmpname, &tmprights);
109 skipline(&curptr);
110 if(!i) {
111 neg=malloc(sizeof(struct AclEntry));
112 oldacl->neg=neg;
114 else {
115 neg->next=malloc(sizeof(struct AclEntry));
116 neg=neg->next;
118 neg->RightsMask=tmprights;
119 strlcpy(neg->name, tmpname, sizeof(neg->name));
120 neg->next=NULL;
123 free(a_params.out);
124 return oldacl;
127 static void
128 afs_listacl(char *path)
130 struct Acl *acl;
131 struct AclEntry *position;
132 int i;
134 acl = afs_getacl(path);
135 if (acl == NULL) {
136 if (errno == EACCES)
137 return;
138 else
139 exit(1);
142 printf("Access list for %s is\n", path);
143 if(acl->NumPositiveEntries) {
144 printf("Normal rights:\n");
146 position=acl->pos;
147 for(i=0;i<acl->NumPositiveEntries;i++) {
148 printf(" %s ", position->name);
149 if(position->RightsMask&PRSFS_READ)
150 printf("r");
151 if(position->RightsMask&PRSFS_LOOKUP)
152 printf("l");
153 if(position->RightsMask&PRSFS_INSERT)
154 printf("i");
155 if(position->RightsMask&PRSFS_DELETE)
156 printf("d");
157 if(position->RightsMask&PRSFS_WRITE)
158 printf("w");
159 if(position->RightsMask&PRSFS_LOCK)
160 printf("k");
161 if(position->RightsMask&PRSFS_ADMINISTER)
162 printf("a");
163 printf("\n");
164 position=position->next;
167 if(acl->NumNegativeEntries) {
168 printf("Negative rights:\n");
170 position=acl->neg;
171 for(i=0;i<acl->NumNegativeEntries;i++) {
172 printf(" %s ", position->name);
173 if(position->RightsMask&PRSFS_READ)
174 printf("r");
175 if(position->RightsMask&PRSFS_LOOKUP)
176 printf("l");
177 if(position->RightsMask&PRSFS_INSERT)
178 printf("i");
179 if(position->RightsMask&PRSFS_DELETE)
180 printf("d");
181 if(position->RightsMask&PRSFS_WRITE)
182 printf("w");
183 if(position->RightsMask&PRSFS_LOCK)
184 printf("k");
185 if(position->RightsMask&PRSFS_ADMINISTER)
186 printf("a");
187 printf("\n");
188 position=position->next;
194 listacl_cmd (int argc, char **argv)
196 unsigned int i;
198 argc--;
199 argv++;
201 if(!argc)
202 afs_listacl(".");
203 else
204 for(i=0;i<argc;i++) {
205 if(i)
206 printf("\n");
207 afs_listacl(argv[i]);
210 return 0;