void dirlist(char *name, FILE * client, char verbose) { DIR *directory; char *cwd = NULL; int i; glob_t globbuf; if ((strstr(name, "/.")) && strchr(name, '*')) return; /* DoS protection */ if ((directory = opendir(name))) { closedir(directory); cwd = bftpd_cwd_getcwd(); chdir(name); glob("*", 0, NULL, &globbuf); } else glob(name, 0, NULL, &globbuf); for (i = 0; i < globbuf.gl_pathc; i++) dirlist_one_file(globbuf.gl_pathv[i], client, verbose); globfree(&globbuf); if (cwd) { chdir(cwd); free(cwd); } }
void dirlist(char *name, FILE * client, char verbose,int bshow_hiden_files) { DIR *directory; FILE *can_see_file; int show_nonreadable_files = FALSE; char *local_cwd = NULL; int i; int show_hidden_files = FALSE; glob_t globbuf; // 0.不支持配置文件配置,直接设置成显示所有文件包括隐藏文件 #if 0 if (! strcasecmp( config_getoption("SHOW_HIDDEN_FILES"), "yes") ) #endif show_hidden_files = bshow_hiden_files; if (! strcasecmp( config_getoption("SHOW_NONREADABLE_FILES"), "yes") ) show_nonreadable_files = TRUE; if ((strstr(name, "/.")) && strchr(name, '*')) return; /* DoS protection */ if ((directory = opendir(name))) { closedir(directory); local_cwd = bftpd_cwd_getcwd(); chdir(name); glob("*", 0, NULL, &globbuf); if (show_hidden_files) glob(".*", GLOB_APPEND, NULL, &globbuf); } else { if ( (name[0] == '*') && (show_hidden_files) ) { glob(name, 0, NULL, &globbuf); glob(".*", GLOB_APPEND, NULL, &globbuf); } else glob(name, 0, NULL, &globbuf); } for (i = 0; i < globbuf.gl_pathc; i++) { if (! show_nonreadable_files) { if ( (can_see_file = fopen(globbuf.gl_pathv[i], "r") ) == NULL) continue; else fclose(can_see_file); } dirlist_one_file(globbuf.gl_pathv[i], client, verbose); } globfree(&globbuf); if (local_cwd) { chdir(local_cwd); free(local_cwd); } }