Mailing List Archive

nessus-libraries/libnessus services.h, 1.8, 1.8.2.1 services1.c, 1.15.2.1, 1.15.2.2
Update of /usr/local/cvs/nessus-libraries/libnessus
In directory raccoon.nessus.org:/tmp/cvs-serv94485

Modified Files:
Tag: NESSUS_2_2
services.h services1.c
Log Message:
only use the services file provided by the Nessus installation (consistency)

Index: services.h
===================================================================
RCS file: /usr/local/cvs/nessus-libraries/libnessus/services.h,v
retrieving revision 1.8
retrieving revision 1.8.2.1
diff -u -d -r1.8 -r1.8.2.1
--- services.h 31 Dec 2003 17:44:59 -0000 1.8
+++ services.h 15 Jan 2006 15:33:32 -0000 1.8.2.1
@@ -34,7 +34,7 @@

/* **** FILES **** */

-#define NESSUS_SERVICES CONF_DIR "/nessus-services"
+#define NESSUS_SERVICES NESSUS_STATE_DIR "/nessus/nessus-services"
/* If you want Nessus to use a second input file, uncomment next line */
/*#define NESSUS_IANA_PORTS CONF_DIR "/iana-port-numbers"*/


Index: services1.c
===================================================================
RCS file: /usr/local/cvs/nessus-libraries/libnessus/services1.c,v
retrieving revision 1.15.2.1
retrieving revision 1.15.2.2
diff -u -d -r1.15.2.1 -r1.15.2.2
--- services1.c 21 Dec 2004 19:24:05 -0000 1.15.2.1
+++ services1.c 15 Jan 2006 15:33:32 -0000 1.15.2.2
@@ -1,6 +1,8 @@
/*
* Copyright (C) 2002 Michel Arboi
*
+ * Some modifications (C) Tenable Network Security
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
@@ -18,6 +20,7 @@
* TCP/IP service functions (getservent enhancement)
*/

+
#define EXPORTING
#include "includes.h"
#include <stdarg.h>
@@ -26,7 +29,6 @@
#include <unistd.h>

#include "services.h"
-#include "libnessus.h"

#ifndef MAP_FAILED
#define MAP_FAILED (void*)(-1)
@@ -39,9 +41,6 @@

struct my_svc {
FILE *fp;
-#ifdef NESSUS_SVC_SORT_FILES
- int po; /* 1 if popen/pclose */
-#endif
int port; /* 2 * port + proto_idx (0 = tcp, 1 = udp) */
char name[128];
/* Debug */
@@ -54,40 +53,12 @@
{
char line[256], proto[32], *p;

-#ifdef NESSUS_SVC_READS_ETC_SERVICES
- if (psvc->fp == (void*) 1)
- {
- struct servent *psve;
-
- if ((psve = getservent()) == NULL)
- {
- endservent();
- return 0;
- }
- else
- {
- psvc->name[ sizeof(psvc->name) - 1 ] = '\0';
- strncpy(psvc->name, psve->s_name, sizeof(psvc->name) - 1);
- psvc->port = (unsigned short) ntohs(psve->s_port);
- psvc->port *= 2;
- if (strcmp(psve->s_proto, "udp") == 0)
- psvc->port ++;
- psvc->line ++;
- return 1;
- }
- }
-#endif
for (;;)
{
do
{
if (fgets(line, sizeof(line), psvc->fp) == NULL)
{
-#ifdef NESSUS_SVC_SORT_FILES
- if (psvc->po)
- pclose(psvc->fp);
- else
-#endif
fclose(psvc->fp);
return 0;
}
@@ -101,9 +72,6 @@
continue;
*p = '\0';
if (sscanf(p+1, "%d/%s", &psvc->port, proto) == 2
-#ifdef NESSUS_SVC_SORT_FILES
- || sscanf(p+1, "%d %s", &psvc->port, proto) == 2
-#endif
)
{
psvc->port *= 2;
@@ -127,9 +95,7 @@
nessus_init_svc()
{
static int flag = 0;
- char *p;
int l, error_flag = 0, rebuild = 0;
- char nmap_svc_path[MAXPATHLEN];
#define N_SVC_F 5
struct my_svc svc[N_SVC_F];
int nf = 0, i, j, prev_p, prev_p_udp;
@@ -137,28 +103,10 @@
struct nessus_service ness_svc;
struct stat st;
time_t t;
-#ifdef NESSUS_SVC_SORT_FILES
-#error "Too ugly. I refuse to compile that"
-#define SORT_CMD "cat %s | tr / ' ' | sort -k 2n -k 3"
- char cmd[MAXPATHLEN + sizeof(SORT_CMD)];
-#endif

if (flag)
return 0;

- *nmap_svc_path = '\0';
- p = find_in_path("nmap", 0); /* returns a pointer to a static array */
- if (p != NULL)
- {
- l = strlen(p);
- if (l >= 4 && l < MAXPATHLEN - 21 && strcmp(p + l - 4, "/bin") == 0)
- {
- nmap_svc_path[sizeof(nmap_svc_path) - 1] = '\0';
- strncpy(nmap_svc_path, p, sizeof(nmap_svc_path) - 1);
- strncpy(nmap_svc_path + l - 4, "/share/nmap/nmap-services", sizeof(nmap_svc_path) - l + 4 - 1);
- }
- }
-
/* Verify files date */

if (stat(NESSUS_SERVICES_TCP, &st) < 0)
@@ -182,7 +130,8 @@
if ( s->magic != SERVICES_MAGIC ) rebuild ++;
munmap(buf, len);
}
- close(fd);
+ eclose(fd);
+ fd = -1;
}
t = st.st_mtime;
if (stat(NESSUS_SERVICES_UDP, & st) < 0)
@@ -191,19 +140,13 @@
t = st.st_mtime;
}

-#ifdef NESSUS_SVC_READS_ETC_SERVICES
- if (stat("/etc/services", &st) >= 0 && (unsigned)st.st_mtime > (unsigned)t)
- rebuild ++;
-#endif
- if (*nmap_svc_path != '\0' && stat(nmap_svc_path, &st) >= 0 &&
- (unsigned)st.st_mtime > (unsigned)t)
- rebuild ++;
+ if ( stat(NESSUS_SERVICES, &st) < 0 )
+ {
+ fprintf(stderr, "**** %s could not be found. Install it and try again\n", NESSUS_SERVICES);
+ exit(1);
+ }
if (stat(NESSUS_SERVICES, &st) >= 0 && (unsigned)st.st_mtime > (unsigned)t)
rebuild ++;
-#ifdef NESSUS_IANA_PORTS
- if (stat(NESSUS_IANA_PORTS, &st) >= 0 && (unsigned)st.st_mtime > (unsigned)t)
- rebuild ++;
-#endif

if (! rebuild)
return 0;
@@ -220,33 +163,6 @@
* call getservent because the system may implement yellow pages or
* some other kind of database. getservent() is supposed to walk through it.
*/
-#ifdef NESSUS_SVC_READS_ETC_SERVICES
- setservent(0);
- svc[nf].fp = (void*) 1;
- if (get_next_svc(&svc[nf]))
- {
- svc[nf].filename = "services";
- nf ++;
- }
-
-#ifdef NESSUS_SVC_SORT_FILES
- snprintf(cmd, sizeof(cmd), SORT_CMD, "/etc/services");
- if ((svc[nf].fp = popen(cmd, "r")) == NULL)
- perror(cmd);
- else
- svc[nf].po = 1;
- if (! svc[nf].po)
-#endif
- if ((svc[nf].fp = fopen("/etc/services", "r")) == NULL)
- perror("/etc/services");
- if (svc[nf].fp != NULL)
- if (get_next_svc(&svc[nf]))
- {
- svc[nf].filename = "/etc/services";
- nf ++;
- }
-#endif
-
/* nessus-services file is supposed to be sorted */
if ((svc[nf].fp = fopen(NESSUS_SERVICES, "r")) != NULL)
{
@@ -257,37 +173,7 @@
}
}

-#ifdef NESSUS_IANA_PORTS
- /* Nessus iana-port-numbers file is supposed to be sorted */
- if ((svc[nf].fp = fopen(NESSUS_IANA_PORTS, "r")) != NULL)
- {
- if (get_next_svc(&svc[nf]))
- {
- svc[nf].filename = NESSUS_IANA_PORTS;
- nf ++;
- }
- }
-#endif

- if (*nmap_svc_path != '\0')
- {
-#ifdef NESSUS_SVC_SORT_FILES
- snprintf(cmd, sizeof(cmd), SORT_CMD, nmap_svc_path);
- if ((svc[nf].fp = popen(cmd, "r")) == NULL)
- perror(cmd);
- else
- svc[nf].po = 1;
- if (! svc[nf].po)
-#endif
- if ((svc[nf].fp = fopen(nmap_svc_path, "r")) == NULL)
- perror(nmap_svc_path);
- if (svc[nf].fp != NULL)
- if (get_next_svc(&svc[nf]))
- {
- svc[nf].filename = nmap_svc_path;
- nf ++;
- }
- }

if (nf > 0)
{
@@ -384,19 +270,11 @@
{
for (i = 0; i < nf; i ++)
if (svc[i].fp != NULL && svc[i].fp != (void*) 1)
-#ifdef NESSUS_SVC_SORT_FILES
- if (svc[i].po)
- pclose(svc[i].fp);
- else
-#endif
fclose(svc[i].fp);
unlink(NESSUS_SERVICES_TCP);
unlink(NESSUS_SERVICES_UDP);
unlink(NESSUS_SERVICES_TXT);
}
-#ifdef NESSUS_SVC_READS_ETC_SERVICES
- endservent();
-#endif
return error_flag ? -1 : 0;
}


_______________________________________________
Nessus-cvs mailing list
Nessus-cvs@list.nessus.org
http://mail.nessus.org/mailman/listinfo/nessus-cvs