From: Bradley Nicholes Date: Wed, 2 Jan 2002 22:47:13 +0000 (+0000) Subject: Fixed the problem on NetWare when accessing an empty directory which X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ec24d5fe988138df8b69257bdfd4af0960ea95cc;p=thirdparty%2Fapache%2Fhttpd.git Fixed the problem on NetWare when accessing an empty directory which has option indexes specified produces an access forbidden message. Submitted by: Charles Goldman, Guenter Knauf git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/1.3.x@92708 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/os/netware/ApacheCore.imp b/src/os/netware/ApacheCore.imp index 4be4ced5f04..9fbbb9b01bc 100644 --- a/src/os/netware/ApacheCore.imp +++ b/src/os/netware/ApacheCore.imp @@ -363,6 +363,7 @@ ap_os_http_method, os_readdir, os_opendir, + os_closedir, ap_update_vhost_from_headers, ap_update_vhost_given_ip, ap_set_name_virtual_host, diff --git a/src/os/netware/os.c b/src/os/netware/os.c index 54043fa8051..d5d8ed7b7fc 100644 --- a/src/os/netware/os.c +++ b/src/os/netware/os.c @@ -180,7 +180,8 @@ char *ap_os_canonical_filename(pool *pPool, const char *szFile) _splitpath (ap_server_root, vol, NULL, NULL, NULL); pNewName = ap_pstrcat (pPool, vol, pNewName, NULL); } - if ((slash_test = strchr(pNewName, ':')) && (*(slash_test+1) != '/')) + if ((slash_test = strchr(pNewName, ':')) && (*(slash_test+1) != '/') + && (*(slash_test+1) != '\0')) { char vol[_MAX_VOLUME+1]; @@ -261,7 +262,8 @@ int ap_os_is_filename_valid(const char *file) pos = ++colonpos; if (!*pos) { /* No path information */ - return 0; + /* Same as specifying volume:\ */ + return 1; } while (*pos) { @@ -292,6 +294,14 @@ int ap_os_is_filename_valid(const char *file) } } + /* Test 2.5 */ + if (seglength == 2) { + if ( (segstart[0] == '.') && (segstart[1] == '.') ) { + return 1; + } + + } + /* Test 3 */ if (segstart[seglength-1] == '.') { return 0; @@ -323,18 +333,66 @@ int ap_os_is_filename_valid(const char *file) #undef opendir_411 DIR *os_opendir (const char *pathname) { - DIR *d = opendir_411 (pathname); + struct stat s; + DIR *d = opendir_411 (pathname); if (d) { strcpy (d->d_name, "<<**"); } + + if (!d) { + /* Let's check if this is an empty directory */ + if (stat(pathname, &s) != 0) + return NULL; + if (!(S_ISDIR(s.st_mode))) + return NULL; + + /* If we are here, then this appears to be a directory */ + /* We allocate a name */ + d = NULL; + d = (DIR *)malloc(sizeof(DIR)); + if (d) { + memset(d, 0, sizeof(DIR)); + strcpy(d->d_name, "**<<"); + d->d_cdatetime = 50; + + } + + } + return d; + } #undef readdir_411 DIR *os_readdir (DIR *dirP) { - if ((dirP->d_name[0] == '<') && (dirP->d_name[2] == '*')) { + +/* + * First three if statements added for empty directory support. + * + */ + if ( (dirP->d_cdatetime == 50) && (dirP->d_name[0] == '*') && + (dirP->d_name[2] == '<') ) + { + strcpy (dirP->d_name, "."); + strcpy (dirP->d_nameDOS, "."); + return (dirP); + } + else if ((dirP->d_cdatetime == 50) && + (dirP->d_name[0] == '.') && + (dirP->d_name[1] == '\0')) { + strcpy (dirP->d_name, ".."); + strcpy (dirP->d_nameDOS, ".."); + return (dirP); + } + else if ( (dirP->d_cdatetime == 50) && + (dirP->d_name[0] == '.') && + (dirP->d_name[1] == '.') && + (dirP->d_name[2] == '\0') ) { + return (NULL); + } + else if ((dirP->d_name[0] == '<') && (dirP->d_name[2] == '*')) { strcpy (dirP->d_name, "."); strcpy (dirP->d_nameDOS, "."); return (dirP); @@ -348,6 +406,42 @@ DIR *os_readdir (DIR *dirP) return readdir_411 (dirP); } + +#undef closedir_510 +int os_closedir (DIR *dirP) +{ +/* + * Modified to handle empty directories. + * + */ + + if (dirP == NULL) { + return 0; + } + + if ( ( (dirP->d_cdatetime == 50) && (dirP->d_name[0] == '*') && + (dirP->d_name[2] == '<') + ) || + ( (dirP->d_cdatetime == 50) && (dirP->d_name[0] == '.') && + (dirP->d_name[1] == '\0') + ) || + ( (dirP->d_cdatetime == 50) && (dirP->d_name[0] == '.') && + (dirP->d_name[1] == '.') && (dirP->d_name[2] == '\0') + ) + ) + { + + free(dirP); + dirP = NULL; + return 0; + } + else { + return closedir_510(dirP); + } + + +} + char *ap_os_http_method(void *r) { int s = ((request_rec*)r)->connection->client->fd; diff --git a/src/os/netware/os.h b/src/os/netware/os.h index 39ab02f95bb..85021a9f4f6 100644 --- a/src/os/netware/os.h +++ b/src/os/netware/os.h @@ -134,6 +134,10 @@ DIR *os_opendir (const char *pathname); #define readdir(p) os_readdir(p) DIR *os_readdir (DIR *dirP); +#define closedir_510(p) os_closedir(p) +#define closedir(p) os_closedir(p) +int os_closedir (DIR *dirP); + /* Prototypes */ void AMCSocketCleanup(void); void clean_parent_exit(int code);