Changed checkaccess to make no file mean `allow'. Added shell matching

to names (if fnmatch is available).


git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@1676 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Johan Danielsson
1997-05-07 17:50:54 +00:00
parent ca0a5ed14c
commit e1f4d82f47

View File

@@ -682,15 +682,21 @@ checkuser(char *fname, char *name)
* If the user is not found in the file, but the pseudo-user `*' is, * If the user is not found in the file, but the pseudo-user `*' is,
* the permission is taken from that line. * the permission is taken from that line.
* *
* This is probably not the best way to do this, but it preserves * This preserves the old semantics where if a user was listed in the
* the old semantics where if a user was listed in the file he was * file he was denied, otherwise he was allowed.
* denied, otherwise he was allowed.
* *
* There is one change in the semantics, however; ftpd will now `fail * Return 1 if the user is denied, or 0 if he is allowed. */
* safe' and deny all access if there's no /etc/ftpusers file.
* static int
* Return 1 if the user is denied, or 0 if he is allowed. match(const char *pattern, const char *string)
*/ {
#ifdef HAVE_FNMATCH
return fnmatch(pattern, string, FNM_NOESCAPE);
#else
return strcmp(pattern, "*") != 0 && strcmp(pattern, string) != 0;
#endif
}
static int static int
checkaccess(char *name) checkaccess(char *name)
{ {
@@ -700,29 +706,26 @@ checkaccess(char *name)
int allowed = ALLOWED; int allowed = ALLOWED;
char *user, *perm, line[BUFSIZ]; char *user, *perm, line[BUFSIZ];
if ((fd = fopen(_PATH_FTPUSERS, "r")) == NULL) fd = fopen(_PATH_FTPUSERS, "r");
return NOT_ALLOWED;
if(fd == NULL)
return allowed;
while (fgets(line, sizeof(line), fd) != NULL) { while (fgets(line, sizeof(line), fd) != NULL) {
user = strtok(line, " \t\n"); user = strtok(line, " \t\n");
if (user[0] == '#') if (user[0] == '#')
continue; continue;
perm = strtok(NULL, " \t\n"); perm = strtok(NULL, " \t\n");
if (strcmp(user, "*") == 0) { if (match(user, name) == 0){
if (perm != NULL && strcmp(perm, "allow") == 0) if(perm && strcmp(perm, "allow") == 0)
allowed = ALLOWED; allowed = ALLOWED;
else else
allowed = NOT_ALLOWED; allowed = NOT_ALLOWED;
} break;
if (strcmp(user, name) == 0) {
if (perm != NULL && strcmp(perm, "allow") == 0)
return ALLOWED;
else
return NOT_ALLOWED;
} }
} }
fclose(fd); fclose(fd);
return (allowed); return allowed;
} }
#undef ALLOWED #undef ALLOWED
#undef NOT_ALLOWED #undef NOT_ALLOWED