1
/* Copyright (c) 1993, 1994 Washington University in Saint Louis
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions are
6
* met: 1. Redistributions of source code must retain the above copyright
7
* notice, this list of conditions and the following disclaimer. 2.
8
* Redistributions in binary form must reproduce the above copyright notice,
9
* this list of conditions and the following disclaimer in the documentation
10
* and/or other materials provided with the distribution. 3. All advertising
11
* materials mentioning features or use of this software must display the
12
* following acknowledgement: This product includes software developed by the
13
* Washington University in Saint Louis and its contributors. 4. Neither the
14
* name of the University nor the names of its contributors may be used to
15
* endorse or promote products derived from this software without specific
16
* prior written permission.
18
* THIS SOFTWARE IS PROVIDED BY WASHINGTON UNIVERSITY AND CONTRIBUTORS
19
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASHINGTON
22
* UNIVERSITY OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
28
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
* POSSIBILITY OF SUCH DAMAGE.
33
char * rcsid = "$Id: acl.c,v 1.2 1999/10/05 21:23:23 he Exp $";
41
#include <sys/syslog.h>
46
#include <sys/types.h>
50
#include "pathnames.h"
51
#include "extensions.h"
54
static struct aclmember *aclmembers;
56
/*************************************************************************/
57
/* FUNCTION : getaclentry */
58
/* PURPOSE : Retrieve a named entry from the ACL */
59
/* ARGUMENTS : pointer to the keyword and a handle to the acl members */
60
/* RETURNS : pointer to the acl member containing the keyword or NULL */
61
/*************************************************************************/
65
getaclentry(char *keyword, struct aclmember **next)
67
getaclentry(keyword,next)
69
struct aclmember **next;
76
*next = (*next)->next;
77
} while (*next && strcmp((*next)->keyword, keyword));
82
/*************************************************************************/
83
/* FUNCTION : parseacl */
84
/* PURPOSE : Parse the acl buffer into its components */
85
/* ARGUMENTS : A pointer to the acl file */
86
/* RETURNS : != 0 if error is detected */
87
/*************************************************************************/
100
struct aclmember *member,
103
if (!aclbuf || !(*aclbuf))
106
aclmembers = (struct aclmember *) NULL;
107
acltail = (struct aclmember *) NULL;
109
while (*aclptr != '\0') {
111
while (*aclptr && *aclptr != '\n')
113
*aclptr++ = (char) NULL;
115
/* deal with comments */
116
if ((ptr = strchr(line, '#')) != NULL)
117
/* allowed escaped '#' chars for path-filter (DiB) */
118
if (*(ptr-1) != '\\')
121
ptr = strtok(line, " \t");
123
member = (struct aclmember *) calloc(1, sizeof(struct aclmember));
125
(void) strcpy(member->keyword, ptr);
127
while ((ptr = strtok(NULL, " \t")) != NULL) {
128
if (cnt >= MAXARGS) {
130
"Too many args (>%d) in ftpaccess: %s %s %s %s %s ...",
131
MAXARGS - 1, member->keyword, member->arg[0],
132
member->arg[1], member->arg[2], member->arg[3]);
135
member->arg[cnt++] = ptr;
138
acltail->next = member;
147
/*************************************************************************/
148
/* FUNCTION : readacl */
149
/* PURPOSE : Read the acl into memory */
150
/* ARGUMENTS : The pathname of the acl */
151
/* RETURNS : 0 if error, 1 if no error */
152
/*************************************************************************/
156
readacl(char *aclpath)
164
extern int use_accessfile;
169
if ((aclfile = fopen(aclpath, "r")) == NULL) {
170
syslog(LOG_ERR, "cannot open access file %s: %s", aclpath,
174
if (fstat(fileno(aclfile), &finfo) != 0) {
175
syslog(LOG_ERR, "cannot fstat access file %s: %s", aclpath,
177
(void) fclose(aclfile);
180
if (finfo.st_size == 0) {
181
aclbuf = (char *) calloc(1, 1);
183
if (!(aclbuf = (char *)malloc((unsigned) finfo.st_size + 1))) {
184
syslog(LOG_ERR, "could not malloc aclbuf (%d bytes)", finfo.st_size + 1);
185
(void) fclose(aclfile);
188
if (!fread(aclbuf, (size_t) finfo.st_size, 1, aclfile)) {
189
syslog(LOG_ERR, "error reading acl file %s: %s", aclpath,
192
(void) fclose(aclfile);
195
*(aclbuf + finfo.st_size) = '\0';
197
(void) fclose(aclfile);