From 1e3115dbcbdd47cf514f5a25d6392affe336acb7 Mon Sep 17 00:00:00 2001 From: henri Date: Sat, 20 Oct 2012 15:00:10 +0000 Subject: [PATCH] Renamed nmap_fileexistsandisreadable() by file_is_readable(). Former was hardly readable and is not even a good candidate for longest method name (http://msdn.microsoft.com/en-us/library/system.windows.media.textformatting.textsource.gettexteffectcharacterindexfromtextsourcecharacterindex.aspx#Y0) --- nbase/nbase.h | 2 +- nbase/nbase_misc.c | 2 +- nmap.cc | 23 +++++++++-------------- nping/ArgParser.cc | 2 +- nping/utils_net.cc | 4 ++-- nse_main.cc | 6 +++--- 6 files changed, 17 insertions(+), 22 deletions(-) diff --git a/nbase/nbase.h b/nbase/nbase.h index 9e0e84866..a2b293f4c 100644 --- a/nbase/nbase.h +++ b/nbase/nbase.h @@ -427,7 +427,7 @@ void replacenonprintable(char *str, int strlength, char replchar); /* Returns one if the file pathname given exists, is not a directory and * is readable by the executing process. Returns two if it is readable * and is a directory. Otherwise returns 0. */ -int fileexistsandisreadable(const char *pathname); +int file_is_readable(const char *pathname); /* Portable, incompatible replacements for dirname and basename. */ char *path_get_dirname(const char *path); diff --git a/nbase/nbase_misc.c b/nbase/nbase_misc.c index 8bd2e137f..14c6a27d2 100644 --- a/nbase/nbase_misc.c +++ b/nbase/nbase_misc.c @@ -741,7 +741,7 @@ int optcmp(const char *a, const char *b) { /* Returns one if the file pathname given exists, is not a directory and * is readable by the executing process. Returns two if it is readable * and is a directory. Otherwise returns 0. */ -int fileexistsandisreadable(const char *pathname) { +int file_is_readable(const char *pathname) { char *pathname_buf = strdup(pathname); int status = 0; struct stat st; diff --git a/nmap.cc b/nmap.cc index 11a7bc7ab..4cb20744d 100644 --- a/nmap.cc +++ b/nmap.cc @@ -2968,11 +2968,6 @@ int ftp_anon_connect(struct ftpinfo *ftp) { } - -int nmap_fileexistsandisreadable(const char* pathname) { - return fileexistsandisreadable(pathname); -} - static char *executable_dir(const char *argv0) { char *path, *dir; @@ -3034,7 +3029,7 @@ int nmap_fetchfile(char *filename_returned, int bufferlen, const char *file) { name. Return a positive result even if the file doesn't exist or is not readable. It is the caller's responsibility to report the error if the file can't be accessed. */ - return fileexistsandisreadable(filename_returned) || 1; + return file_is_readable(filename_returned) || 1; } /* Try updates directory first. */ @@ -3059,7 +3054,7 @@ static int nmap_fetchfile_userdir(char *buf, size_t buflen, const char *file) { if (res <= 0 || res >= buflen) return 0; - return fileexistsandisreadable(buf); + return file_is_readable(buf); } #else static int nmap_fetchfile_userdir_uid(char *buf, size_t buflen, const char *file, int uid) { @@ -3073,7 +3068,7 @@ static int nmap_fetchfile_userdir_uid(char *buf, size_t buflen, const char *file if (res <= 0 || (size_t) res >= buflen) return 0; - return fileexistsandisreadable(buf); + return file_is_readable(buf); } static int nmap_fetchfile_userdir(char *buf, size_t buflen, const char *file) { @@ -3103,14 +3098,14 @@ static int nmap_fetchfile_sub(char *filename_returned, int bufferlen, const char if (o.datadir) { res = Snprintf(filename_returned, bufferlen, "%s/%s", o.datadir, file); if (res > 0 && res < bufferlen) { - foundsomething = fileexistsandisreadable(filename_returned); + foundsomething = file_is_readable(filename_returned); } } if (!foundsomething && (dirptr = getenv("NMAPDIR"))) { res = Snprintf(filename_returned, bufferlen, "%s/%s", dirptr, file); if (res > 0 && res < bufferlen) { - foundsomething = fileexistsandisreadable(filename_returned); + foundsomething = file_is_readable(filename_returned); } } @@ -3128,14 +3123,14 @@ static int nmap_fetchfile_sub(char *filename_returned, int bufferlen, const char if (!foundsomething) { /* Try the nMap directory */ res = Snprintf(filename_returned, bufferlen, "%s/%s", dir, file); if (res > 0 && res < bufferlen) { - foundsomething = fileexistsandisreadable(filename_returned); + foundsomething = file_is_readable(filename_returned); } } #ifndef WIN32 if (!foundsomething) { res = Snprintf(filename_returned, bufferlen, "%s/../share/nmap/%s", dir, file); if (res > 0 && res < bufferlen) { - foundsomething = fileexistsandisreadable(filename_returned); + foundsomething = file_is_readable(filename_returned); } } #endif @@ -3145,14 +3140,14 @@ static int nmap_fetchfile_sub(char *filename_returned, int bufferlen, const char if (!foundsomething) { res = Snprintf(filename_returned, bufferlen, "%s/%s", NMAPDATADIR, file); if (res > 0 && res < bufferlen) { - foundsomething = fileexistsandisreadable(filename_returned); + foundsomething = file_is_readable(filename_returned); } } if (foundsomething && (*filename_returned != '.')) { res = Snprintf(dot_buffer, sizeof(dot_buffer), "./%s", file); if (res > 0 && res < bufferlen) { - if (fileexistsandisreadable(dot_buffer) && !same_file(filename_returned, dot_buffer)) { + if (file_is_readable(dot_buffer) && !same_file(filename_returned, dot_buffer)) { #ifdef WIN32 if (warningcount++ < 1 && o.debugging) #else diff --git a/nping/ArgParser.cc b/nping/ArgParser.cc index 2450d9696..ea8035032 100644 --- a/nping/ArgParser.cc +++ b/nping/ArgParser.cc @@ -834,7 +834,7 @@ char errstr[256]; if ( o.issetPayloadFilename() ) { outFatal(QT_3,"Only one payload input filename allowed"); }else { - int tmp = fileexistsandisreadable(optarg); + int tmp = file_is_readable(optarg); if ( tmp == 1 ) o.setPayloadFilename(optarg); else if ( tmp==2) diff --git a/nping/utils_net.cc b/nping/utils_net.cc index 321e8365f..1859f7df6 100644 --- a/nping/utils_net.cc +++ b/nping/utils_net.cc @@ -1517,7 +1517,7 @@ int getinterfaces_inet6_linux(if6_t *ifbuf, int max_ifaces){ outFatal(QT_3,"getinterfaces_inet6_linux() NULL values supplied"); /* TODO: Do we fatal() or should we just error and return OP_FAILURE? */ - if ( !fileexistsandisreadable(PATH_PROC_IFINET6) ) + if ( !file_is_readable(PATH_PROC_IFINET6) ) outFatal(QT_3, "Couldn't get IPv6 interface information. File %s does not exist or you don't have read permissions.", PATH_PROC_IFINET6); if( (if6file=fopen(PATH_PROC_IFINET6, "r"))==NULL ) outFatal(QT_3, "Failed to open %s.", PATH_PROC_IFINET6); @@ -1711,7 +1711,7 @@ int getroutes_inet6_linux(route6_t *rtbuf, int max_routes){ outFatal(QT_3,"getroutes_inet6_linux() NULL values supplied"); /* TODO: Do we fatal() or should we just error and return OP_FAILURE? */ - if ( !fileexistsandisreadable(PATH_PROC_IPV6ROUTE) ) + if ( !file_is_readable(PATH_PROC_IPV6ROUTE) ) outFatal(QT_3, "Couldn't get IPv6 route information. File %s does not exist or you don't have read permissions.", PATH_PROC_IPV6ROUTE); if( (route6file=fopen(PATH_PROC_IPV6ROUTE, "r"))==NULL ) outFatal(QT_3, "Failed to open %s.", PATH_PROC_IPV6ROUTE); diff --git a/nse_main.cc b/nse_main.cc index bf58c76c8..362d1675d 100644 --- a/nse_main.cc +++ b/nse_main.cc @@ -305,7 +305,7 @@ static int nse_fetchfile_absolute(char *path, size_t path_len, const char *file) if (o.debugging > 1) log_write(LOG_STDOUT, "%s: Trying absolute path %s\n", SCRIPT_ENGINE, file); Strncpy(path, file, path_len); - return nmap_fileexistsandisreadable(file); + return file_is_readable(file); } return nmap_fetchfile(path, path_len, file); @@ -324,7 +324,7 @@ static int nse_fetchscript(char *path, size_t path_len, const char *file) { if (o.debugging > 1) log_write(LOG_STDOUT, "%s: Trying absolute path %s\n", SCRIPT_ENGINE, file); Strncpy(path, file, path_len); - return nmap_fileexistsandisreadable(file); + return file_is_readable(file); } // lets look in /scripts @@ -333,7 +333,7 @@ static int nse_fetchscript(char *path, size_t path_len, const char *file) { if (type == 0) { // current directory Strncpy(path, file, path_len); - return nmap_fileexistsandisreadable(file); + return file_is_readable(file); } return type;