mirror of
https://github.com/nmap/nmap.git
synced 2025-12-06 12:41:29 +00:00
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)
This commit is contained in:
@@ -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
|
/* 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
|
* is readable by the executing process. Returns two if it is readable
|
||||||
* and is a directory. Otherwise returns 0. */
|
* 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. */
|
/* Portable, incompatible replacements for dirname and basename. */
|
||||||
char *path_get_dirname(const char *path);
|
char *path_get_dirname(const char *path);
|
||||||
|
|||||||
@@ -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
|
/* 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
|
* is readable by the executing process. Returns two if it is readable
|
||||||
* and is a directory. Otherwise returns 0. */
|
* and is a directory. Otherwise returns 0. */
|
||||||
int fileexistsandisreadable(const char *pathname) {
|
int file_is_readable(const char *pathname) {
|
||||||
char *pathname_buf = strdup(pathname);
|
char *pathname_buf = strdup(pathname);
|
||||||
int status = 0;
|
int status = 0;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
|
|||||||
23
nmap.cc
23
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) {
|
static char *executable_dir(const char *argv0) {
|
||||||
char *path, *dir;
|
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
|
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
|
readable. It is the caller's responsibility to report the error if the
|
||||||
file can't be accessed. */
|
file can't be accessed. */
|
||||||
return fileexistsandisreadable(filename_returned) || 1;
|
return file_is_readable(filename_returned) || 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Try updates directory first. */
|
/* 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)
|
if (res <= 0 || res >= buflen)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return fileexistsandisreadable(buf);
|
return file_is_readable(buf);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
static int nmap_fetchfile_userdir_uid(char *buf, size_t buflen, const char *file, int uid) {
|
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)
|
if (res <= 0 || (size_t) res >= buflen)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return fileexistsandisreadable(buf);
|
return file_is_readable(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int nmap_fetchfile_userdir(char *buf, size_t buflen, const char *file) {
|
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) {
|
if (o.datadir) {
|
||||||
res = Snprintf(filename_returned, bufferlen, "%s/%s", o.datadir, file);
|
res = Snprintf(filename_returned, bufferlen, "%s/%s", o.datadir, file);
|
||||||
if (res > 0 && res < bufferlen) {
|
if (res > 0 && res < bufferlen) {
|
||||||
foundsomething = fileexistsandisreadable(filename_returned);
|
foundsomething = file_is_readable(filename_returned);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!foundsomething && (dirptr = getenv("NMAPDIR"))) {
|
if (!foundsomething && (dirptr = getenv("NMAPDIR"))) {
|
||||||
res = Snprintf(filename_returned, bufferlen, "%s/%s", dirptr, file);
|
res = Snprintf(filename_returned, bufferlen, "%s/%s", dirptr, file);
|
||||||
if (res > 0 && res < bufferlen) {
|
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 */
|
if (!foundsomething) { /* Try the nMap directory */
|
||||||
res = Snprintf(filename_returned, bufferlen, "%s/%s", dir, file);
|
res = Snprintf(filename_returned, bufferlen, "%s/%s", dir, file);
|
||||||
if (res > 0 && res < bufferlen) {
|
if (res > 0 && res < bufferlen) {
|
||||||
foundsomething = fileexistsandisreadable(filename_returned);
|
foundsomething = file_is_readable(filename_returned);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
if (!foundsomething) {
|
if (!foundsomething) {
|
||||||
res = Snprintf(filename_returned, bufferlen, "%s/../share/nmap/%s", dir, file);
|
res = Snprintf(filename_returned, bufferlen, "%s/../share/nmap/%s", dir, file);
|
||||||
if (res > 0 && res < bufferlen) {
|
if (res > 0 && res < bufferlen) {
|
||||||
foundsomething = fileexistsandisreadable(filename_returned);
|
foundsomething = file_is_readable(filename_returned);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -3145,14 +3140,14 @@ static int nmap_fetchfile_sub(char *filename_returned, int bufferlen, const char
|
|||||||
if (!foundsomething) {
|
if (!foundsomething) {
|
||||||
res = Snprintf(filename_returned, bufferlen, "%s/%s", NMAPDATADIR, file);
|
res = Snprintf(filename_returned, bufferlen, "%s/%s", NMAPDATADIR, file);
|
||||||
if (res > 0 && res < bufferlen) {
|
if (res > 0 && res < bufferlen) {
|
||||||
foundsomething = fileexistsandisreadable(filename_returned);
|
foundsomething = file_is_readable(filename_returned);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (foundsomething && (*filename_returned != '.')) {
|
if (foundsomething && (*filename_returned != '.')) {
|
||||||
res = Snprintf(dot_buffer, sizeof(dot_buffer), "./%s", file);
|
res = Snprintf(dot_buffer, sizeof(dot_buffer), "./%s", file);
|
||||||
if (res > 0 && res < bufferlen) {
|
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
|
#ifdef WIN32
|
||||||
if (warningcount++ < 1 && o.debugging)
|
if (warningcount++ < 1 && o.debugging)
|
||||||
#else
|
#else
|
||||||
|
|||||||
@@ -834,7 +834,7 @@ char errstr[256];
|
|||||||
if ( o.issetPayloadFilename() ) {
|
if ( o.issetPayloadFilename() ) {
|
||||||
outFatal(QT_3,"Only one payload input filename allowed");
|
outFatal(QT_3,"Only one payload input filename allowed");
|
||||||
}else {
|
}else {
|
||||||
int tmp = fileexistsandisreadable(optarg);
|
int tmp = file_is_readable(optarg);
|
||||||
if ( tmp == 1 )
|
if ( tmp == 1 )
|
||||||
o.setPayloadFilename(optarg);
|
o.setPayloadFilename(optarg);
|
||||||
else if ( tmp==2)
|
else if ( tmp==2)
|
||||||
|
|||||||
@@ -1517,7 +1517,7 @@ int getinterfaces_inet6_linux(if6_t *ifbuf, int max_ifaces){
|
|||||||
outFatal(QT_3,"getinterfaces_inet6_linux() NULL values supplied");
|
outFatal(QT_3,"getinterfaces_inet6_linux() NULL values supplied");
|
||||||
|
|
||||||
/* TODO: Do we fatal() or should we just error and return OP_FAILURE? */
|
/* 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);
|
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 )
|
if( (if6file=fopen(PATH_PROC_IFINET6, "r"))==NULL )
|
||||||
outFatal(QT_3, "Failed to open %s.", PATH_PROC_IFINET6);
|
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");
|
outFatal(QT_3,"getroutes_inet6_linux() NULL values supplied");
|
||||||
|
|
||||||
/* TODO: Do we fatal() or should we just error and return OP_FAILURE? */
|
/* 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);
|
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 )
|
if( (route6file=fopen(PATH_PROC_IPV6ROUTE, "r"))==NULL )
|
||||||
outFatal(QT_3, "Failed to open %s.", PATH_PROC_IPV6ROUTE);
|
outFatal(QT_3, "Failed to open %s.", PATH_PROC_IPV6ROUTE);
|
||||||
|
|||||||
@@ -305,7 +305,7 @@ static int nse_fetchfile_absolute(char *path, size_t path_len, const char *file)
|
|||||||
if (o.debugging > 1)
|
if (o.debugging > 1)
|
||||||
log_write(LOG_STDOUT, "%s: Trying absolute path %s\n", SCRIPT_ENGINE, file);
|
log_write(LOG_STDOUT, "%s: Trying absolute path %s\n", SCRIPT_ENGINE, file);
|
||||||
Strncpy(path, file, path_len);
|
Strncpy(path, file, path_len);
|
||||||
return nmap_fileexistsandisreadable(file);
|
return file_is_readable(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
return nmap_fetchfile(path, path_len, 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)
|
if (o.debugging > 1)
|
||||||
log_write(LOG_STDOUT, "%s: Trying absolute path %s\n", SCRIPT_ENGINE, file);
|
log_write(LOG_STDOUT, "%s: Trying absolute path %s\n", SCRIPT_ENGINE, file);
|
||||||
Strncpy(path, file, path_len);
|
Strncpy(path, file, path_len);
|
||||||
return nmap_fileexistsandisreadable(file);
|
return file_is_readable(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
// lets look in <path>/scripts
|
// lets look in <path>/scripts
|
||||||
@@ -333,7 +333,7 @@ static int nse_fetchscript(char *path, size_t path_len, const char *file) {
|
|||||||
if (type == 0) {
|
if (type == 0) {
|
||||||
// current directory
|
// current directory
|
||||||
Strncpy(path, file, path_len);
|
Strncpy(path, file, path_len);
|
||||||
return nmap_fileexistsandisreadable(file);
|
return file_is_readable(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
return type;
|
return type;
|
||||||
|
|||||||
Reference in New Issue
Block a user