[Autosec-devel] sonar/src error.c,1.9,1.10 log.c,1.8,1.9 log.h,1.2,1.3 mem.c,1.1,1.2 mem.h,1.1,1.2 m
Brought to you by:
red0x
From: red0x <re...@us...> - 2004-04-13 03:56:07
|
Update of /cvsroot/autosec/sonar/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24331/src Modified Files: error.c log.c log.h mem.c mem.h mutex.c mutex.h net.c plugin.c plugin.h popts.c popts.h service.c service.h sonar.c sonar.h target.c target.h types.h util.c util.h Log Message: Massive code 'indent' Index: mem.h =================================================================== RCS file: /cvsroot/autosec/sonar/src/mem.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** mem.h 6 Feb 2004 06:20:50 -0000 1.1 --- mem.h 13 Apr 2004 03:42:08 -0000 1.2 *************** *** 18,22 **** * File contains memory wrappers */ ! #include <stdlib.h> #include <assert.h> --- 18,22 ---- * File contains memory wrappers */ ! #include <stdlib.h> #include <assert.h> *************** *** 25,27 **** void *Malloc(size_t size); void *Realloc(void *ptr, size_t size); - --- 25,26 ---- Index: log.c =================================================================== RCS file: /cvsroot/autosec/sonar/src/log.c,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** log.c 9 Apr 2004 15:26:33 -0000 1.8 --- log.c 13 Apr 2004 03:42:08 -0000 1.9 *************** *** 30,80 **** * \param msg Format string to output */ ! void log_write(int flags, char *msg, ...) { ! va_list ap; ! int i; ! va_start(ap, msg); #ifdef DEBUG ! if(flags & LOG_DBUG) ! { ! fprintf(stderr, "DEBUG: "); ! vfprintf(stderr, msg, ap); ! return; ! } #endif ! if(flags & LOG_CONSOLE) { - /* if we are forked, or quiet, dont do this */ - if(!mthis.opts.bFork && mthis.opts.iVerbose >= 0) - { #ifdef DEBUG ! fprintf(stderr, "CONSOLE: "); ! #endif ! vfprintf(stderr, msg, ap); ! } } ! if(flags & LOG_SLOG) { ! /* only print in syslog if we are forked */ ! if(mthis.opts.bFork) ! { ! /*openlog("sonar", LOG_PID, LOG_DAEMON);*/ ! vsyslog(LOG_DAEMON | LOG_NOTICE, msg, ap); ! /*closelog();*/ ! } } ! if(flags & LOG_PLUGINS) { ! for(i = 0; i < num_out; i++) ! { ! if(output_list[i].plug != NULL) ! if(output_list[i].plug->selected ! && output_list[i].plug->ready) ! output_list[i].plug-> ! plugin_output(msg, &ap); ! } } ! va_end(ap); } --- 30,80 ---- * \param msg Format string to output */ ! void ! log_write(int flags, char *msg, ...) { ! va_list ap; ! int i; ! va_start(ap, msg); #ifdef DEBUG ! if(flags & LOG_DBUG) ! { ! fprintf(stderr, "DEBUG: "); ! vfprintf(stderr, msg, ap); ! return; ! } #endif ! if(flags & LOG_CONSOLE) ! { ! /* if we are forked, or quiet, dont do this */ ! if(!mthis.opts.bFork && mthis.opts.iVerbose >= 0) { #ifdef DEBUG ! fprintf(stderr, "CONSOLE: "); ! #endif ! vfprintf(stderr, msg, ap); } ! } ! if(flags & LOG_SLOG) ! { ! /* only print in syslog if we are forked */ ! if(mthis.opts.bFork) { ! /* openlog("sonar", LOG_PID, LOG_DAEMON); */ ! vsyslog(LOG_DAEMON | LOG_NOTICE, msg, ap); ! /* closelog(); */ } ! } ! if(flags & LOG_PLUGINS) ! { ! for(i = 0; i < num_out; i++) { ! if(output_list[i].plug != NULL) ! if(output_list[i].plug->selected ! && output_list[i].plug->ready) ! output_list[i].plug->plugin_output(msg, &ap); } ! } ! va_end(ap); } Index: sonar.h =================================================================== RCS file: /cvsroot/autosec/sonar/src/sonar.h,v retrieving revision 1.32 retrieving revision 1.33 diff -C2 -d -r1.32 -r1.33 *** sonar.h 11 Apr 2004 04:47:49 -0000 1.32 --- sonar.h 13 Apr 2004 03:42:08 -0000 1.33 *************** *** 42,46 **** {"debug", 0, NULL, 'b'}, \ {"plugin_list", 0, NULL, 'l'}, \ ! int h_errno; --- 42,46 ---- {"debug", 0, NULL, 'b'}, \ {"plugin_list", 0, NULL, 'l'}, \ ! int h_errno; *************** *** 49,53 **** void sonar_status_report(sonar_t mthis); int sonar_rawoutput(char *msg, ...); ! int sonar_sweep(target_t *targets); void default_context(void *in); --- 49,53 ---- void sonar_status_report(sonar_t mthis); int sonar_rawoutput(char *msg, ...); ! int sonar_sweep(target_t * targets); void default_context(void *in); Index: service.h =================================================================== RCS file: /cvsroot/autosec/sonar/src/service.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** service.h 4 Nov 2003 23:48:40 -0000 1.2 --- service.h 13 Apr 2004 03:42:08 -0000 1.3 *************** *** 24,30 **** /*#include "target.h"*/ ! int sonar_resolve_service(char *serv, target_t *result); ! int sonar_resolve_service_r(char *low, char *high, target_t *result); ! #endif //_SERVICE_H_ --- 24,30 ---- /*#include "target.h"*/ ! int sonar_resolve_service(char *serv, target_t * result); ! int sonar_resolve_service_r(char *low, char *high, target_t * result); ! #endif // _SERVICE_H_ Index: plugin.h =================================================================== RCS file: /cvsroot/autosec/sonar/src/plugin.h,v retrieving revision 1.43 retrieving revision 1.44 diff -C2 -d -r1.43 -r1.44 *** plugin.h 11 Apr 2004 04:44:18 -0000 1.43 --- plugin.h 13 Apr 2004 03:42:08 -0000 1.44 *************** *** 110,119 **** typedef struct stats_s stats_t; ! struct stats_s { ! unsigned int packets_sent; ! unsigned int packets_recvd; ! unsigned short ttl; ! double rtt_min, rtt_max, rtt_avg; }; --- 110,119 ---- typedef struct stats_s stats_t; ! struct stats_s { ! unsigned int packets_sent; ! unsigned int packets_recvd; ! unsigned short ttl; ! double rtt_min, rtt_max, rtt_avg; }; *************** *** 122,143 **** struct target_s { ! /// next target in list ! target_t *next; ! /// user specified entry ! char *entry; ! /// list of ports to scan ! int ports[MAX_PORTS]; ! /// address info, including family, protocol, and socket type ! struct addrinfo *addrinfo; ! /// netmask ! unsigned int netmask; ! /// extra hosts involved in this (ie, w/netmask) ! unsigned int extra_hosts; ! /// broadcast address ! unsigned short broadcast; ! /// number of ports in this host ! uint32_t num_ports; ! /// statistics ! stats_t stats; }; --- 122,143 ---- struct target_s { ! // / next target in list ! target_t *next; ! // / user specified entry ! char *entry; ! // / list of ports to scan ! int ports[MAX_PORTS]; ! // / address info, including family, protocol, and socket type ! struct addrinfo *addrinfo; ! // / netmask ! unsigned int netmask; ! // / extra hosts involved in this (ie, w/netmask) ! unsigned int extra_hosts; ! // / broadcast address ! unsigned short broadcast; ! // / number of ports in this host ! uint32_t num_ports; ! // / statistics ! stats_t stats; }; *************** *** 147,170 **** typedef struct sonar_options_s { ! /// Delay after running this type of scan (advanced option) int iPostDelay; ! /// Delay after each host int iHostDelay; ! /// Timeout per host int iTimeout; ! /// do we have broadcast addresses in the targets? int bBroadcast; ! /// Verbosity level (0 to 5) int iVerbose; ! /// Fork into daemon mode? (0/1) int bFork; ! /// Command line char *sCommandLine; ! /// Number of scanning cycles to run unsigned int iCount; ! /// Random order of hosts? int bRandom; ! }sonar_options_t; /** \struct plugin_s --- 147,170 ---- typedef struct sonar_options_s { ! // / Delay after running this type of scan (advanced option) int iPostDelay; ! // / Delay after each host int iHostDelay; ! // / Timeout per host int iTimeout; ! // / do we have broadcast addresses in the targets? int bBroadcast; ! // / Verbosity level (0 to 5) int iVerbose; ! // / Fork into daemon mode? (0/1) int bFork; ! // / Command line char *sCommandLine; ! // / Number of scanning cycles to run unsigned int iCount; ! // / Random order of hosts? int bRandom; ! } sonar_options_t; /** \struct plugin_s *************** *** 174,226 **** typedef struct plugin_s { ! /// unique ID assigned at run time ! uint32_t pluginID; ! /// plugin api interface version, lower versions _may_ be supported ! uint8_t version; ! /// plugin type (INPUT_PLUGIN | OUTPUT_PLUGIN for an I/O plugin) ! uint8_t type; ! /// last error from this plugin ! int16_t *err; ! /// ready to use flag, not modified by sonar ! uint8_t ready:4, ! /// The plugin was selected ! selected:4; ! /// Plugin character (ie, -sI, -sA, -sL, -oL) ! char plugin_char; ! /// Short name (ie, "icmp scan", "log file output") ! char *shortname; ! /// Long name (ie, "ICMP Scanning Plugin: requires root...") ! char *longname; ! /// Initialize this plugin ! void *(*plugin_init) (void *in_data); ! /// Destroy this plugin ! int (*plugin_destroy) (void); ! /// Open the input/output/network source ! int (*plugin_open) (void *c_data, int i_data); ! /// Close the input/output/network source ! int (*plugin_close) (void); ! /// Get next host, returned in hostname, only for input plugins ! /// Set next host, for network plugins ! int (*plugin_next) (char *hostname); ! /// Do the sweep (network plugins) ! int (*plugin_sweep) (target_t *targets); ! /// Output plugin's general message output function ! int (*plugin_output) (char *msg, va_list * ap); ! /// output plugins result output function ! int (*plugin_results) (target_t *result, unsigned int num); ! /// prints, via sonar_t->output(), line(s) to add to sonar_usage() ! void (*plugin_usage) (void); ! /// prints, via sonar_t->output(), line(s) to add to the status report ! void (*plugin_status) (void); ! /// Return the last error ! int (*plugin_last_error) (void); } plugin_t; --- 174,226 ---- typedef struct plugin_s { ! // / unique ID assigned at run time ! uint32_t pluginID; ! // / plugin api interface version, lower versions _may_ be supported ! uint8_t version; ! // / plugin type (INPUT_PLUGIN | OUTPUT_PLUGIN for an I/O plugin) ! uint8_t type; ! // / last error from this plugin ! int16_t *err; ! // / ready to use flag, not modified by sonar ! uint8_t ready:4, ! // / The plugin was selected ! selected:4; ! // / Plugin character (ie, -sI, -sA, -sL, -oL) ! char plugin_char; ! // / Short name (ie, "icmp scan", "log file output") ! char *shortname; ! // / Long name (ie, "ICMP Scanning Plugin: requires root...") ! char *longname; ! // / Initialize this plugin ! void *(*plugin_init) (void *in_data); ! // / Destroy this plugin ! int (*plugin_destroy) (void); ! // / Open the input/output/network source ! int (*plugin_open) (void *c_data, int i_data); ! // / Close the input/output/network source ! int (*plugin_close) (void); ! // / Get next host, returned in hostname, only for input plugins ! // / Set next host, for network plugins ! int (*plugin_next) (char *hostname); ! // / Do the sweep (network plugins) ! int (*plugin_sweep) (target_t * targets); ! // / Output plugin's general message output function ! int (*plugin_output) (char *msg, va_list * ap); ! // / output plugins result output function ! int (*plugin_results) (target_t * result, unsigned int num); ! // / prints, via sonar_t->output(), line(s) to add to sonar_usage() ! void (*plugin_usage) (void); ! // / prints, via sonar_t->output(), line(s) to add to the status report ! void (*plugin_status) (void); ! // / Return the last error ! int (*plugin_last_error) (void); } plugin_t; *************** *** 234,280 **** typedef struct sonar_s { ! /// Major version number ! uint8_t ver_major, ! /// Minor version number ! ver_minor, ! /// Revision number ! revision, ! /// Plugin API version 1.X (so for 1.4, set this to 4) ! api; ! /// Pointer to a memory copier from sonar (XXX: remove) ! void (*memput) (char **dest, const char *src, const int len); ! ! /// Pointer to the Messsage output (ie, with a timestamp) function from sonar ! void (*message) (char *msg, ...); ! ! /// let the resolving function live in sonar, so each network plugin wont have to write its own ! /// unless it wants to ! struct addrinfo * (*resolve) (const char *host, const char *serv, int family, ! int socktype); ! /// Pointer to sonar's output to console function (no timestamp) ! int (*output) (char *msg, ...); ! /// Pointer to usage function, for error reports ! void (*usage) (const char *); ! /// Pointer to a function to get root priveleges ! int (*getprivs) (void); ! /// Pointer to a function to drop root priveleges ! int (*dropprivs) (uid_t); ! /// find a target, for updating ! target_t *(*find_target) (struct sonar_s *this, struct addrinfo *ai); ! /// Name of file we are (for permissions checking) ! char *my_name; ! /// list of attack vectors ! target_t *vectors; ! /// number of targets ! unsigned int num_targets; ! /// number of ports ! unsigned int num_ports; ! /// Useful global options sonar_options_t opts; } sonar_t; --- 234,282 ---- typedef struct sonar_s { ! // / Major version number ! uint8_t ver_major, ! // / Minor version number ! ver_minor, ! // / Revision number ! revision, ! // / Plugin API version 1.X (so for 1.4, set this to 4) ! api; ! // / Pointer to a memory copier from sonar (XXX: remove) ! void (*memput) (char **dest, const char *src, const int len); ! // / Pointer to the Messsage output (ie, with a timestamp) function from ! // sonar ! void (*message) (char *msg, ...); ! // / let the resolving function live in sonar, so each network plugin ! // wont have to write its own ! // / unless it wants to ! struct addrinfo *(*resolve) (const char *host, const char *serv, ! int family, int socktype); ! // / Pointer to sonar's output to console function (no timestamp) ! int (*output) (char *msg, ...); ! // / Pointer to usage function, for error reports ! void (*usage) (const char *); ! // / Pointer to a function to get root priveleges ! int (*getprivs) (void); ! // / Pointer to a function to drop root priveleges ! int (*dropprivs) (uid_t); ! // / find a target, for updating ! target_t *(*find_target) (struct sonar_s * this, struct addrinfo * ai); ! // / Name of file we are (for permissions checking) ! char *my_name; ! ! // / list of attack vectors ! target_t *vectors; ! // / number of targets ! unsigned int num_targets; ! // / number of ports ! unsigned int num_ports; ! ! // / Useful global options sonar_options_t opts; } sonar_t; *************** *** 285,292 **** typedef struct plugin_list_s { ! /// Pointer to a plugin_t structure ! plugin_t *plug; ! /// Handle to library opened with \c lt_dlopen(3) ! void *handle; } plugin_list_t; --- 287,294 ---- typedef struct plugin_list_s { ! // / Pointer to a plugin_t structure ! plugin_t *plug; ! // / Handle to library opened with \c lt_dlopen(3) ! void *handle; } plugin_list_t; *************** *** 299,303 **** int plugin_command_handler(char opt, char *optarg); void plugin_message_hook(char *msg, va_list * ap); ! void clear_opts(sonar_options_t*); --- 301,305 ---- int plugin_command_handler(char opt, char *optarg); void plugin_message_hook(char *msg, va_list * ap); ! void clear_opts(sonar_options_t *); *************** *** 448,450 **** */ ! #endif //_PLUGIN_H --- 450,452 ---- */ ! #endif // _PLUGIN_H Index: net.c =================================================================== RCS file: /cvsroot/autosec/sonar/src/net.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** net.c 28 Feb 2004 08:57:14 -0000 1.3 --- net.c 13 Apr 2004 03:42:08 -0000 1.4 *************** *** 34,54 **** static const char rcsid[] = ! "\100$ autosec/sonar: $Id$"; ! struct addrinfo *host_serv(const char *host, const char *serv, int family, ! int socktype) { ! int n; ! struct addrinfo hints, *res; ! bzero(&hints, sizeof(struct addrinfo)); ! hints.ai_flags = AI_CANONNAME; /* always return canonical name */ ! hints.ai_family = family; /* AF_UNSPEC, AF_INET, AF_INET6, etc. */ ! hints.ai_socktype = socktype; /* 0, SOCK_STREAM, SOCK_DGRAM, etc. */ ! if((n = getaddrinfo(host, serv, &hints, &res)) != 0) ! return (NULL); ! return (res); /* return pointer to first on linked list */ } --- 34,54 ---- static const char rcsid[] = ! "\100$ autosec/sonar: $Id$"; ! struct addrinfo * ! host_serv(const char *host, const char *serv, int family, int socktype) { ! int n; ! struct addrinfo hints, *res; ! bzero(&hints, sizeof(struct addrinfo)); ! hints.ai_flags = AI_CANONNAME; /* always return canonical name */ ! hints.ai_family = family; /* AF_UNSPEC, AF_INET, AF_INET6, etc. */ ! hints.ai_socktype = socktype; /* 0, SOCK_STREAM, SOCK_DGRAM, etc. */ ! if((n = getaddrinfo(host, serv, &hints, &res)) != 0) ! return (NULL); ! return (res); /* return pointer to first on linked list */ } *************** *** 62,82 **** */ ! struct addrinfo *Host_serv(const char *host, const char *serv, int family, ! int socktype) { ! int n; ! struct addrinfo hints, *res; ! bzero(&hints, sizeof(struct addrinfo)); ! hints.ai_flags = AI_CANONNAME; /* always return canonical name */ ! hints.ai_family = family; /* 0, AF_INET, AF_INET6, etc. */ ! hints.ai_socktype = socktype; /* 0, SOCK_STREAM, SOCK_DGRAM, etc. */ ! if((n = getaddrinfo(host, serv, &hints, &res)) != 0) ! err_quit("host_serv error for %s, %s: %s", ! (host == NULL) ? "(no hostname)" : host, ! (serv == NULL) ? "(no service name)" : serv, ! gai_strerror(n)); ! return (res); /* return pointer to first on linked list */ } --- 62,82 ---- */ ! struct addrinfo * ! Host_serv(const char *host, const char *serv, int family, int socktype) { ! int n; ! struct addrinfo hints, *res; ! bzero(&hints, sizeof(struct addrinfo)); ! hints.ai_flags = AI_CANONNAME; /* always return canonical name */ ! hints.ai_family = family; /* 0, AF_INET, AF_INET6, etc. */ ! hints.ai_socktype = socktype; /* 0, SOCK_STREAM, SOCK_DGRAM, etc. */ ! if((n = getaddrinfo(host, serv, &hints, &res)) != 0) ! err_quit("host_serv error for %s, %s: %s", ! (host == NULL) ? "(no hostname)" : host, ! (serv == NULL) ? "(no service name)" : serv, ! gai_strerror(n)); ! return (res); /* return pointer to first on linked list */ } Index: mem.c =================================================================== RCS file: /cvsroot/autosec/sonar/src/mem.c,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** mem.c 6 Feb 2004 06:20:50 -0000 1.1 --- mem.c 13 Apr 2004 03:42:08 -0000 1.2 *************** *** 22,47 **** #include "error.h" ! void *Calloc(size_t nmemb, size_t size) { ! void *ptr = calloc(nmemb, size); ! if(!ptr) ! err_sys("calloc failed\n"); ! return ptr; } ! void *Malloc(size_t size) { ! void *ptr = malloc(size); ! if(!ptr) ! err_sys("Malloc failed\n"); ! return ptr; } ! void *Realloc(void *ptr, size_t size) { ! void *ptr2; ! ptr2 = realloc(ptr, size); ! if(!ptr) ! err_sys("realloc failed\n"); ! return ptr2; } --- 22,50 ---- #include "error.h" ! void * ! Calloc(size_t nmemb, size_t size) { ! void *ptr = calloc(nmemb, size); ! if(!ptr) ! err_sys("calloc failed\n"); ! return ptr; } ! void * ! Malloc(size_t size) { ! void *ptr = malloc(size); ! if(!ptr) ! err_sys("Malloc failed\n"); ! return ptr; } ! void * ! Realloc(void *ptr, size_t size) { ! void *ptr2; ! ptr2 = realloc(ptr, size); ! if(!ptr) ! err_sys("realloc failed\n"); ! return ptr2; } Index: plugin.c =================================================================== RCS file: /cvsroot/autosec/sonar/src/plugin.c,v retrieving revision 1.34 retrieving revision 1.35 diff -C2 -d -r1.34 -r1.35 *** plugin.c 11 Apr 2004 04:44:18 -0000 1.34 --- plugin.c 13 Apr 2004 03:42:08 -0000 1.35 *************** *** 51,67 **** static const char rcsid[] = ! "\100$ autosec/sonar: $Id$"; /*woutput(char *msg, ...); extern int verbose;*/ ! static int plugin_add(int type, plugin_t * p_data, sonar_t * mthis, void *hptr); /// list of input plugins ! plugin_list_t input_list[MAX_INP]; ! uint32_t input_buf[MAX_INP]; /// list of output plugins ! plugin_list_t output_list[MAX_OUT]; /// list of network plugins ! plugin_list_t network_list[MAX_NET]; /// plugin id system PID --- 51,68 ---- static const char rcsid[] = ! "\100$ autosec/sonar: $Id$"; /*woutput(char *msg, ...); extern int verbose;*/ ! static int plugin_add(int type, plugin_t * p_data, sonar_t * mthis, ! void *hptr); /// list of input plugins ! plugin_list_t input_list[MAX_INP]; ! uint32_t input_buf[MAX_INP]; /// list of output plugins ! plugin_list_t output_list[MAX_OUT]; /// list of network plugins ! plugin_list_t network_list[MAX_NET]; /// plugin id system PID *************** *** 70,76 **** unsigned long int num_inp, /// number of output plugins ! num_out, /// number of network plugins ! num_net; /** @name Plugin API Internals --- 71,77 ---- unsigned long int num_inp, /// number of output plugins ! num_out, /// number of network plugins ! num_net; /** @name Plugin API Internals *************** *** 88,92 **** * @return 1 if the system is ready */ ! static int inline plugin_ready() { // are they all defined? --- 89,94 ---- * @return 1 if the system is ready */ ! static int inline ! plugin_ready() { // are they all defined? *************** *** 103,112 **** * @param plugin_list plugin_list_t pointer */ ! static void inline plugin_init(plugin_list_t * plugin_list) { // set the plugin to NULL plugin_list->plug = NULL; ! plugin_list->handle = NULL; ! memset(input_buf, 0, MAX_INP * sizeof(uint32_t)); } --- 105,115 ---- * @param plugin_list plugin_list_t pointer */ ! static void inline ! plugin_init(plugin_list_t * plugin_list) { // set the plugin to NULL plugin_list->plug = NULL; ! plugin_list->handle = NULL; ! memset(input_buf, 0, MAX_INP * sizeof(uint32_t)); } *************** *** 116,123 **** * @return A new, unique plugin ID */ ! static int inline plugin_newid() { ! return (unsigned long int) ++first_pid; ! /* (first_pid += ((unsigned int)(200.0 * rand() / (RAND_MAX + 64.0))));*/ } --- 119,127 ---- * @return A new, unique plugin ID */ ! static int inline ! plugin_newid() { ! return (unsigned long int) ++first_pid; ! /* (first_pid += ((unsigned int)(200.0 * rand() / (RAND_MAX + 64.0)))); */ } *************** *** 139,147 **** * @return PLUGIN_OK if ok, PLUGIN_ERROR otherwise */ ! int plugin_start(sonar_t * mthis) { if(!input_list) { ! err_sys("Input Array not Initialized: %s line %d", __FILE__, __LINE__); return PLUGIN_ERROR; } --- 143,153 ---- * @return PLUGIN_OK if ok, PLUGIN_ERROR otherwise */ ! int ! plugin_start(sonar_t * mthis) { if(!input_list) { ! err_sys("Input Array not Initialized: %s line %d", __FILE__, ! __LINE__); return PLUGIN_ERROR; } *************** *** 149,153 **** if(!output_list) { ! err_sys("Output Array not Initialized: %s line %d", __FILE__, __LINE__); return PLUGIN_ERROR; } --- 155,160 ---- if(!output_list) { ! err_sys("Output Array not Initialized: %s line %d", __FILE__, ! __LINE__); return PLUGIN_ERROR; } *************** *** 155,159 **** if(!network_list) { ! err_sys("Network Array not Initialized: %s line %d", __FILE__,__LINE__); return PLUGIN_ERROR; } --- 162,167 ---- if(!network_list) { ! err_sys("Network Array not Initialized: %s line %d", __FILE__, ! __LINE__); return PLUGIN_ERROR; } *************** *** 169,173 **** * @return PLUGIN_OK */ ! int plugin_end() { #ifdef DEBUG --- 177,182 ---- * @return PLUGIN_OK */ ! int ! plugin_end() { #ifdef DEBUG *************** *** 186,190 **** * @todo Lock the plugin library while checking permissions, to avoid a race */ ! int plugin_loadall(sonar_t * mthis) { /* directory to search defined as PLUGINDIR */ --- 195,200 ---- * @todo Lock the plugin library while checking permissions, to avoid a race */ ! int ! plugin_loadall(sonar_t * mthis) { /* directory to search defined as PLUGINDIR */ *************** *** 198,202 **** /* try to get the owner and mode of sonar */ if((my_buf = get_stats(mthis->my_name)) == NULL) ! err_sys("could not stat %s", mthis->my_name); log_write(LOG_DBUG, " opendir(%s);\n", PLUGINDIR); --- 208,212 ---- /* try to get the owner and mode of sonar */ if((my_buf = get_stats(mthis->my_name)) == NULL) ! err_sys("could not stat %s", mthis->my_name); log_write(LOG_DBUG, " opendir(%s);\n", PLUGINDIR); *************** *** 213,225 **** int len = strlen(entry->d_name); log_write(LOG_DBUG, " found %s\n", entry->d_name); ! /* all plugins must have this in their names, at the ! beginning */ if(len < strlen(PLUGIN_HEADER)) continue; ! /* this code filters out other libraries ! needed once we went libtool */ if(strncmp(entry->d_name, PLUGIN_HEADER, ! strlen(PLUGIN_HEADER)) != 0) ! continue; /* not the one */ if((entry->d_name[len - 3] == '.') && (entry->d_name[len - 2] == 's') && --- 223,234 ---- int len = strlen(entry->d_name); log_write(LOG_DBUG, " found %s\n", entry->d_name); ! /* all plugins must have this in their names, at the beginning */ if(len < strlen(PLUGIN_HEADER)) continue; ! /* this code filters out other libraries needed once we went ! * libtool */ if(strncmp(entry->d_name, PLUGIN_HEADER, ! strlen(PLUGIN_HEADER)) != 0) ! continue; /* not the one */ if((entry->d_name[len - 3] == '.') && (entry->d_name[len - 2] == 's') && *************** *** 241,245 **** { log_write(LOG_CONSOLE | LOG_SLOG, ! "CRITICAL: %s is world writable! not loading!", str); continue; } --- 250,255 ---- { log_write(LOG_CONSOLE | LOG_SLOG, ! "CRITICAL: %s is world writable! not loading!", ! str); continue; } *************** *** 251,258 **** if(stat_buf.st_uid != 0) { ! log_write(LOG_CONSOLE | LOG_SLOG, ! "CRITICAL: %s owned by someone else (%d, not %d)! " ! "not loading!", ! str, stat_buf.st_uid, my_buf->st_uid); continue; } --- 261,268 ---- if(stat_buf.st_uid != 0) { ! log_write(LOG_CONSOLE | LOG_SLOG, ! "CRITICAL: %s owned by someone else (%d, not %d)! " ! "not loading!", ! str, stat_buf.st_uid, my_buf->st_uid); continue; } *************** *** 262,266 **** /* end check */ lt_dlinit(); ! log_write(LOG_DBUG," lt_dlopen(%s); => ",str); if((plugin = lt_dlopen(str)) == NULL) --- 272,276 ---- /* end check */ lt_dlinit(); ! log_write(LOG_DBUG, " lt_dlopen(%s); => ", str); if((plugin = lt_dlopen(str)) == NULL) *************** *** 268,273 **** char *dl_error_msg = (char *) lt_dlerror(); log_write(LOG_DBUG, " FAILED!\n"); ! log_write(LOG_CONSOLE | LOG_SLOG, ! "could not load %s: %s\n", str, dl_error_msg); continue; } --- 278,283 ---- char *dl_error_msg = (char *) lt_dlerror(); log_write(LOG_DBUG, " FAILED!\n"); ! log_write(LOG_CONSOLE | LOG_SLOG, ! "could not load %s: %s\n", str, dl_error_msg); continue; } *************** *** 286,291 **** { log_write(LOG_DBUG, " FAILED!\n"); ! log_write(LOG_CONSOLE | LOG_SLOG," Could not load " ! "%s:\nplugin_init failed\n", str); } else --- 296,301 ---- { log_write(LOG_DBUG, " FAILED!\n"); ! log_write(LOG_CONSOLE | LOG_SLOG, " Could not load " ! "%s:\nplugin_init failed\n", str); } else *************** *** 293,308 **** log_write(LOG_DBUG, " %p (ok)\n", plug); /* only support from version API_SUPPORT on up */ ! if(plug->version > API_VER || plug->version < API_SUPPORT) { ! log_write(LOG_CONSOLE | LOG_SLOG, ! " Warning: Plugin \"%s\" wanted an unsupported" ! " api, version \'%d\', not loading\n", ! plug->shortname, plug->version); lt_dlclose(plugin); continue; } ! log_write(LOG_DBUG, " plugin_add(%d, %p, %p, %p);\n", ! plug, plug->type, plug, mthis, plugin); plugin_add(plug->type, plug, mthis, plugin); } --- 303,318 ---- log_write(LOG_DBUG, " %p (ok)\n", plug); /* only support from version API_SUPPORT on up */ ! if(plug->version > API_VER || plug->version < API_SUPPORT) { ! log_write(LOG_CONSOLE | LOG_SLOG, ! " Warning: Plugin \"%s\" wanted an unsupported" ! " api, version \'%d\', not loading\n", ! plug->shortname, plug->version); lt_dlclose(plugin); continue; } ! log_write(LOG_DBUG, " plugin_add(%d, %p, %p, %p);\n", ! plug, plug->type, plug, mthis, plugin); plugin_add(plug->type, plug, mthis, plugin); } *************** *** 313,317 **** log_write(LOG_DBUG, " FAILED!\n"); log_write(LOG_CONSOLE | LOG_SLOG, " could not load " ! "plugin_init in %s:\n%s\n", str, dl_error_msg); } } --- 323,327 ---- log_write(LOG_DBUG, " FAILED!\n"); log_write(LOG_CONSOLE | LOG_SLOG, " could not load " ! "plugin_init in %s:\n%s\n", str, dl_error_msg); } } *************** *** 334,344 **** * @return PLUGIN_OK if ok, PLUGIN_ERROR otherwise */ ! int plugin_killall(void) { int err = PLUGIN_OK; ! log_write(LOG_DBUG, " plugin_killall();\n"); ! ! //get all input, output, network plugins ! //call the plugin_destroy function for(; num_inp > 0; num_inp--) { --- 344,355 ---- * @return PLUGIN_OK if ok, PLUGIN_ERROR otherwise */ ! int ! plugin_killall(void) { int err = PLUGIN_OK; ! log_write(LOG_DBUG, " plugin_killall();\n"); ! ! // get all input, output, network plugins ! // call the plugin_destroy function for(; num_inp > 0; num_inp--) { *************** *** 346,359 **** assert(input_list[num_inp - 1].plug != NULL); assert(input_list[num_inp - 1].plug->plugin_destroy != NULL); ! //if plugin is also an output plugin, let that call its destroy function if(!(input_list[num_inp - 1].plug->type & OUTPUT_PLUGIN)) { log_write(LOG_DBUG, " unloading %s\n", ! input_list[num_inp - 1].plug->shortname); log_write(LOG_DBUG, " input_list[%d].plug->plugin_destroy();\n", ! num_inp - 1); if((my_err = input_list[num_inp - 1].plug->plugin_destroy()) != ! PLUGIN_UNLOADED) { log_write(LOG_DBUG, " plugin not unloaded\n"); --- 357,371 ---- assert(input_list[num_inp - 1].plug != NULL); assert(input_list[num_inp - 1].plug->plugin_destroy != NULL); ! // if plugin is also an output plugin, let that call its destroy ! // function if(!(input_list[num_inp - 1].plug->type & OUTPUT_PLUGIN)) { log_write(LOG_DBUG, " unloading %s\n", ! input_list[num_inp - 1].plug->shortname); log_write(LOG_DBUG, " input_list[%d].plug->plugin_destroy();\n", ! num_inp - 1); if((my_err = input_list[num_inp - 1].plug->plugin_destroy()) != ! PLUGIN_UNLOADED) { log_write(LOG_DBUG, " plugin not unloaded\n"); *************** *** 371,385 **** assert(output_list[num_out - 1].plug->plugin_close != NULL); ! //if plugin is also a network plugin, let that call it destroy function if(!(output_list[num_out - 1].plug->type & NETWORK_PLUGIN)) { log_write(LOG_DBUG, " unloading %s\n", ! output_list[num_out - 1].plug->shortname); log_write(LOG_DBUG, " output_list[%d].plug->plugin_destroy();\n", ! num_out - 1); ! if(output_list[num_out -1].plug->ready) output_list[num_out - 1].plug->plugin_close(); if((my_err = output_list[num_out - 1].plug->plugin_destroy()) != ! PLUGIN_UNLOADED) { log_write(LOG_DBUG, " plugin not unloaded"); --- 383,398 ---- assert(output_list[num_out - 1].plug->plugin_close != NULL); ! // if plugin is also a network plugin, let that call it destroy ! // function if(!(output_list[num_out - 1].plug->type & NETWORK_PLUGIN)) { log_write(LOG_DBUG, " unloading %s\n", ! output_list[num_out - 1].plug->shortname); log_write(LOG_DBUG, " output_list[%d].plug->plugin_destroy();\n", ! num_out - 1); ! if(output_list[num_out - 1].plug->ready) output_list[num_out - 1].plug->plugin_close(); if((my_err = output_list[num_out - 1].plug->plugin_destroy()) != ! PLUGIN_UNLOADED) { log_write(LOG_DBUG, " plugin not unloaded"); *************** *** 396,404 **** assert(network_list[num_net - 1].plug->plugin_destroy != NULL); log_write(LOG_DBUG, " unloading %s\n", ! network_list[num_net - 1].plug->shortname); log_write(LOG_DBUG, " network_list[%d].plug->plugin_destroy();\n", ! num_net - 1); if((my_err = network_list[num_net - 1].plug->plugin_destroy()) != ! PLUGIN_UNLOADED) { log_write(LOG_DBUG, " plugin not unloaded\n"); --- 409,417 ---- assert(network_list[num_net - 1].plug->plugin_destroy != NULL); log_write(LOG_DBUG, " unloading %s\n", ! network_list[num_net - 1].plug->shortname); log_write(LOG_DBUG, " network_list[%d].plug->plugin_destroy();\n", ! num_net - 1); if((my_err = network_list[num_net - 1].plug->plugin_destroy()) != ! PLUGIN_UNLOADED) { log_write(LOG_DBUG, " plugin not unloaded\n"); *************** *** 422,426 **** * @return PLUGIN_OK if ok, PLUGIN_ERROR otherwise */ ! static int plugin_add(int type, plugin_t * p_data, sonar_t * mthis, void *hptr) { if(!plugin_ready()) --- 435,440 ---- * @return PLUGIN_OK if ok, PLUGIN_ERROR otherwise */ ! static int ! plugin_add(int type, plugin_t * p_data, sonar_t * mthis, void *hptr) { if(!plugin_ready()) *************** *** 429,437 **** return PLUGIN_ERROR; } ! ! assert(p_data != NULL); ! assert(mthis != NULL); ! assert(hptr != NULL); ! if(type & INPUT_PLUGIN) { --- 443,451 ---- return PLUGIN_ERROR; } ! ! assert(p_data != NULL); ! assert(mthis != NULL); ! assert(hptr != NULL); ! if(type & INPUT_PLUGIN) { *************** *** 440,445 **** input_list[num_inp].handle = hptr; input_list[num_inp].plug->pluginID = plugin_newid(); ! log_write(LOG_DBUG, " input_list[%d].plug->pluginID = %d\n", num_inp, ! input_list[num_inp].plug->pluginID); num_inp++; if(num_inp > MAX_INP) --- 454,459 ---- input_list[num_inp].handle = hptr; input_list[num_inp].plug->pluginID = plugin_newid(); ! log_write(LOG_DBUG, " input_list[%d].plug->pluginID = %d\n", num_inp, ! input_list[num_inp].plug->pluginID); num_inp++; if(num_inp > MAX_INP) *************** *** 455,460 **** output_list[num_out].handle = hptr; output_list[num_out].plug->pluginID = plugin_newid(); ! log_write(LOG_DBUG, " output_list[%d].plug->pluginID = %d\n", num_out, ! output_list[num_out].plug->pluginID); num_out++; if(num_out > MAX_OUT) --- 469,474 ---- output_list[num_out].handle = hptr; output_list[num_out].plug->pluginID = plugin_newid(); ! log_write(LOG_DBUG, " output_list[%d].plug->pluginID = %d\n", ! num_out, output_list[num_out].plug->pluginID); num_out++; if(num_out > MAX_OUT) *************** *** 470,475 **** network_list[num_net].handle = hptr; network_list[num_net].plug->pluginID = plugin_newid(); ! log_write(LOG_DBUG, " network_list[%d].plug->pluginID = %d\n", num_net, ! network_list[num_net].plug->pluginID); num_net++; if(num_net > MAX_NET) --- 484,489 ---- network_list[num_net].handle = hptr; network_list[num_net].plug->pluginID = plugin_newid(); ! log_write(LOG_DBUG, " network_list[%d].plug->pluginID = %d\n", ! num_net, network_list[num_net].plug->pluginID); num_net++; if(num_net > MAX_NET) *************** *** 495,503 **** * at the status screen */ ! void plugin_status_hook(void) { unsigned int plug; ! //get all input, output, network plugins ! //call the plugin_status function for(plug = 0; plug < num_inp; plug++) --- 509,518 ---- * at the status screen */ ! void ! plugin_status_hook(void) { unsigned int plug; ! // get all input, output, network plugins ! // call the plugin_status function for(plug = 0; plug < num_inp; plug++) *************** *** 540,549 **** * @param ap va_list of arguments */ ! void plugin_message_hook(char *msg, va_list * ap) { unsigned int plug; int err_val = 0; ! //get all output plugins ! //call the plugin_output function for(plug = 0; plug < num_out; plug++) --- 555,565 ---- * @param ap va_list of arguments */ ! void ! plugin_message_hook(char *msg, va_list * ap) { unsigned int plug; int err_val = 0; ! // get all output plugins ! // call the plugin_output function for(plug = 0; plug < num_out; plug++) *************** *** 566,582 **** //@} ! void clear_opts(sonar_options_t *in) { assert(in != NULL); ! memset((void*)in,0,sizeof(sonar_options_t)); ! in->iPostDelay=0; ! in->iHostDelay=0; ! in->iTimeout=5; ! in->iVerbose=1; ! in->bFork=0; ! in->sCommandLine=NULL; ! in->iCount=1; ! in->bRandom=0; ! in->bBroadcast=0; } - --- 582,598 ---- //@} ! void ! clear_opts(sonar_options_t * in) { assert(in != NULL); ! memset((void *) in, 0, sizeof(sonar_options_t)); ! in->iPostDelay = 0; ! in->iHostDelay = 0; ! in->iTimeout = 5; ! in->iVerbose = 1; ! in->bFork = 0; ! in->sCommandLine = NULL; ! in->iCount = 1; ! in->bRandom = 0; ! in->bBroadcast = 0; } Index: service.c =================================================================== RCS file: /cvsroot/autosec/sonar/src/service.c,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** service.c 28 Feb 2004 12:01:17 -0000 1.5 --- service.c 13 Apr 2004 03:42:08 -0000 1.6 *************** *** 31,119 **** static const char rcsid[] = ! "\100$ autosec/sonar: $Id$"; ! int sonar_resolve_service(char *serv, target_t *target) { ! struct servent *service; ! int num = atoi(serv), port = 0; ! log_write(LOG_DBUG, " looking up \'%s\' service\n", serv); ! setservent(0); ! service = getservbyname(serv, NULL); ! if(!service) // if not, { ! log_write(LOG_DBUG, " service not found by name: %s\n", serv); ! // try by number ! service = getservbyport(htons(num), NULL); ! if(!service) // still not? ! { ! log_write(LOG_DBUG, " service not found by port: %d\n", ! num); ! // see if its in range ! if(num >= 0 && num <= 65535) ! { ! log_write(LOG_DBUG, " setting port #%d\n", ! num); ! target->ports[num] = 1; ! port = num; ! } ! else // nope? error ! { ! err_msg("port out of range, skipping"); ! return 0; ! } - } - else // got it by number - { - log_write(LOG_DBUG, " found service by number: %s\n", - service->s_name); - port = ntohs(service->s_port); - if(port < 0 || port > 65535) - { - err_msg("port out of range, skipping"); - return 0; - } - target->ports[port] = 1; - } } ! else // got it by name { ! log_write(LOG_DBUG, " found service by name. port: %u, name: " ! "%s\n", ! ntohs(service->s_port), service->s_name); ! port = ntohs(service->s_port); ! if(port < 0 || port > 65535) ! { ! err_msg("port out of range, skipping"); ! return 0; ! } ! target->ports[port] = 1; } ! endservent(); ! return port; } ! int sonar_resolve_service_r(char *low, char *high, target_t *result) { ! int i, fin, moyen, ret = 0; ! assert(low != NULL); ! assert(high != NULL); ! moyen = sonar_resolve_service(low, result); ! fin = sonar_resolve_service(high, result); ! if(moyen < 0 || fin < 0) ! { ! err_msg("ports out of range, bailing"); ! return 0; ! } ! // fill in the gaps in the range ! for(i = moyen; i < fin; i++) ! { ! result->ports[i] = 1; ! ret++; ! } ! ret++; ! return ret; } --- 31,118 ---- static const char rcsid[] = ! "\100$ autosec/sonar: $Id$"; ! int ! sonar_resolve_service(char *serv, target_t * target) { ! struct servent *service; ! int num = atoi(serv), port = 0; ! log_write(LOG_DBUG, " looking up \'%s\' service\n", serv); ! setservent(0); ! service = getservbyname(serv, NULL); ! if(!service) // if not, ! { ! log_write(LOG_DBUG, " service not found by name: %s\n", serv); ! // try by number ! service = getservbyport(htons(num), NULL); ! if(!service) // still not? { ! log_write(LOG_DBUG, " service not found by port: %d\n", num); ! // see if its in range ! if(num >= 0 && num <= 65535) ! { ! log_write(LOG_DBUG, " setting port #%d\n", num); ! target->ports[num] = 1; ! port = num; ! } ! else // nope? error ! { ! err_msg("port out of range, skipping"); ! return 0; ! } } ! else // got it by number { ! log_write(LOG_DBUG, " found service by number: %s\n", ! service->s_name); ! port = ntohs(service->s_port); ! if(port < 0 || port > 65535) ! { ! err_msg("port out of range, skipping"); ! return 0; ! } ! target->ports[port] = 1; } ! } ! else // got it by name ! { ! log_write(LOG_DBUG, " found service by name. port: %u, name: " ! "%s\n", ntohs(service->s_port), service->s_name); ! port = ntohs(service->s_port); ! if(port < 0 || port > 65535) ! { ! err_msg("port out of range, skipping"); ! return 0; ! } ! target->ports[port] = 1; ! } ! endservent(); ! return port; } ! int ! sonar_resolve_service_r(char *low, char *high, target_t * result) { ! int i, fin, moyen, ret = 0; ! assert(low != NULL); ! assert(high != NULL); ! moyen = sonar_resolve_service(low, result); ! fin = sonar_resolve_service(high, result); ! if(moyen < 0 || fin < 0) ! { ! err_msg("ports out of range, bailing"); ! return 0; ! } ! // fill in the gaps in the range ! for(i = moyen; i < fin; i++) ! { ! result->ports[i] = 1; ! ret++; ! } ! ret++; ! return ret; } Index: sonar.c =================================================================== RCS file: /cvsroot/autosec/sonar/src/sonar.c,v retrieving revision 1.43 retrieving revision 1.44 diff -C2 -d -r1.43 -r1.44 *** sonar.c 11 Apr 2004 02:20:48 -0000 1.43 --- sonar.c 13 Apr 2004 03:42:08 -0000 1.44 *************** *** 45,49 **** static const char rcsid[] = ! "\100$ autosec/sonar: $Id$"; //these are contained in plugin.c --- 45,49 ---- static const char rcsid[] = ! "\100$ autosec/sonar: $Id$"; [...1228 lines suppressed...] ! assert(network_list[plug].plug != NULL); ! assert(network_list[plug].plug->plugin_sweep != NULL); ! } ! // only run this sweep if the plugin is ready ! if(network_list[plug].plug->ready == true ! && network_list[plug].plug->selected == true) ! { ! status = network_list[plug].plug->plugin_sweep(targets); #ifdef DEBUG ! err_msg("network_list[%d].plug->plugin_sweep(%p); => %d", plug, ! targets, status); #endif ! /* XXX: add some sort of error reporting here */ } ! if(status != PLUGIN_OK) ! return status; ! } ! return SONAR_OK; } Index: mutex.h =================================================================== RCS file: /cvsroot/autosec/sonar/src/mutex.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** mutex.h 14 May 2003 06:23:03 -0000 1.1 --- mutex.h 13 Apr 2004 03:42:08 -0000 1.2 *************** *** 26,32 **** typedef struct { ! pthread_mutex_t mutex; ! char id[80]; ! char *locked_by; } sonar_mutex_t; --- 26,32 ---- typedef struct { ! pthread_mutex_t mutex; ! char id[80]; ! char *locked_by; } sonar_mutex_t; Index: types.h =================================================================== RCS file: /cvsroot/autosec/sonar/src/types.h,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** types.h 28 Apr 2003 23:11:32 -0000 1.20 --- types.h 13 Apr 2004 03:42:08 -0000 1.21 *************** *** 28,36 **** #ifndef __USE_BSD ! #define __USE_BSD //for portability #endif #ifndef __FAVOR_BSD ! #define __FAVOR_BSD //for portability #endif --- 28,36 ---- #ifndef __USE_BSD ! #define __USE_BSD // for portability #endif #ifndef __FAVOR_BSD ! #define __FAVOR_BSD // for portability #endif *************** *** 61,65 **** #ifdef HAVE_SYS_TIME_H #include <sys/time.h> ! #endif //HAVE_SYS_TIME_H #include <time.h> #else --- 61,65 ---- #ifdef HAVE_SYS_TIME_H #include <sys/time.h> ! #endif // HAVE_SYS_TIME_H #include <time.h> #else *************** *** 67,75 **** #ifdef HAVE_SYS_TIME_H #include <sys/time.h> ! #endif //HAVE_SYS_TIME_H #else #include <time.h> ! #endif //TM_IN_SYS_TIME ! #endif //TIME_WITH_SYS_TIME /** --- 67,75 ---- #ifdef HAVE_SYS_TIME_H #include <sys/time.h> ! #endif // HAVE_SYS_TIME_H #else #include <time.h> ! #endif // TM_IN_SYS_TIME ! #endif // TIME_WITH_SYS_TIME /** *************** *** 81,91 **** { /** Socket Family */ ! unsigned short family, /** Destination Port */ ! dport; /** IP Address */ ! unsigned int addr; /** Padding (zeros) */ ! unsigned char zero[8]; }; --- 81,91 ---- { /** Socket Family */ ! unsigned short family, /** Destination Port */ ! dport; /** IP Address */ ! unsigned int addr; /** Padding (zeros) */ ! unsigned char zero[8]; }; Index: util.c =================================================================== RCS file: /cvsroot/autosec/sonar/src/util.c,v retrieving revision 1.28 retrieving revision 1.29 diff -C2 -d -r1.28 -r1.29 *** util.c 8 Apr 2004 21:09:40 -0000 1.28 --- util.c 13 Apr 2004 03:42:08 -0000 1.29 *************** *** 42,46 **** static const char rcsid[] = ! "\100$ autosec/sonar: $Id$"; /** --- 42,46 ---- static const char rcsid[] = ! "\100$ autosec/sonar: $Id$"; /** *************** *** 49,55 **** * @param err Error to report */ ! void sonar_usage(const char *err) { ! sonar_opt_usage(-1, "error", (char *) err); } --- 49,56 ---- * @param err Error to report */ ! void ! sonar_usage(const char *err) { ! sonar_opt_usage(-1, "error", (char *) err); } *************** *** 62,70 **** * @todo Deprecate using this */ ! void bput(char **dest, const char *src, const int len) { ! *dest = (char *) Malloc(len + 2); ! memset(*dest, 0, len + 2); ! strncpy(*dest, src, len); // return dest; } --- 63,72 ---- * @todo Deprecate using this */ ! void ! bput(char **dest, const char *src, const int len) { ! *dest = (char *) Malloc(len + 2); ! memset(*dest, 0, len + 2); ! strncpy(*dest, src, len); // return dest; } *************** *** 77,95 **** * @param out Double pointer to destination */ ! void sonar_commandline(char *argv[], int argc, char **out) { ! int i, len = 0; ! for(i = 0; i < argc; i++) ! len += strlen(argv[i]) + 1; ! *out = (char *) Malloc(len + 2); ! memset(*out, 0, len + 2); ! for(i = 0; i < argc; i++) ! { ! strncat(*out, argv[i], strlen(argv[i])); ! strcat(*out, " "); ! } } --- 79,98 ---- * @param out Double pointer to destination */ ! void ! sonar_commandline(char *argv[], int argc, char **out) { ! int i, len = 0; ! for(i = 0; i < argc; i++) ! len += strlen(argv[i]) + 1; ! *out = (char *) Malloc(len + 2); ! memset(*out, 0, len + 2); ! for(i = 0; i < argc; i++) ! { ! strncat(*out, argv[i], strlen(argv[i])); ! strcat(*out, " "); ! } } *************** *** 100,236 **** * @param msg Format specifier like printf */ ! void sonar_msg(char *msg, ...) { ! va_list ap; ! char *buf; ! ! va_start(ap, msg); ! buf = (char *) Malloc(128); ! memset(buf, 0, 128); ! va_start(ap, msg); ! vsnprintf(buf, 127, msg, ap); ! ! if(mthis.opts.bFork) ! log_write(LOG_PLUGINS | LOG_SLOG, buf); ! else ! log_write(LOG_PLUGINS | LOG_CONSOLE, buf); ! free(buf); ! va_end(ap); } ! RETSIGTYPE sig_int(int i) { ! switch(i) ! { ! case SIGINT: ! err_msg("caught SIGINT, cleaning up..\n"); ! break; ! case SIGTERM: ! err_msg("caught SIGTERM, cleaning up..\n"); ! break; ! case SIGHUP: ! err_msg("caught SIGHUP, restarting..\n"); ! sonar_sweep(); ! break; ! case SIGSEGV: ! err_msg("oops! sonar segmentation fault.\n"); ! /*plugin_killall();*/ ! abort(); ! break; ! } ! /*plugin_killall();*/ ! ! exit(0); } ! struct stat *get_stats(const char *file) { ! struct stat *buf; ! char *path = NULL, *token, *str, cwd[PATH_MAX]; ! assert(file != NULL); ! buf = (struct stat *) Malloc(sizeof(struct stat)); ! ! log_write(LOG_DBUG, " get_stats: checking for %s\n", file); ! // if we have the full path ! if(stat(file, buf) == 0) ! return buf; ! log_write(LOG_DBUG, " get_stats: not found, checking in $PATH\n"); ! path = getenv("PATH"); ! // check in the paths ! if(path) ! { ! log_write(LOG_DBUG, " get_stats: $PATH=\"%s\"\n", path); ! token = strtok(path, ":"); ! while(token != NULL) ! { ! // check this location for file ! int tok = strlen(token); ! int pth = strlen(file); ! int len = tok + pth + 2; ! str = (char *) Malloc(len); ! memset(str, 0, len); ! // build the path name ! strncpy(str, token, tok); ! strncat(str, "/", 1); ! strncat(str, file, pth); ! log_write(LOG_DBUG, " get_stats: trying %s\n", str); ! ! // try to stat ! if(stat(str, buf) == 0) ! return buf; ! // not found, clear the mem ! memset(str, 0, len); ! // free the mem ! free(str); ! // next token ! token = strtok(NULL, ":"); ! } ! } ! // not found in path? check current working dir ! memset(cwd, 0, PATH_MAX); ! getcwd(cwd, PATH_MAX - 1); ! log_write(LOG_DBUG, " get_stats: trying cwd\n"); ! // we can get the cwd ! if(cwd) { ! // check here for file ! int pth = strlen(file); ! int lcw = strlen(cwd); ! int len = pth + lcw + 2; ! str = (char *) Malloc(len); ! memset(str, 0, len); ! // build the path name ! strncpy(str, cwd, lcw); ! strncat(str, "/", 1); ! strncat(str, file, pth); ! log_write(LOG_DBUG, " get_stats: trying %s\n", str); ! // try to stat ! if(stat(str, buf) == 0) ! return buf; ! // not found, clear mem ! memset(str, 0, len); ! // free ! free(str); } ! log_write(LOG_DBUG, " could not find/stat %s\n", file); ! return NULL; } ! RETSIGTYPE sig_chld(int sig) { ! pid_t pid; ! int stat; ! ! pid = wait(&stat); #if RETSIGTYPE == void ! return; #else ! return (0); #endif } --- 103,243 ---- * @param msg Format specifier like printf */ ! void ! sonar_msg(char *msg, ...) { ! va_list ap; ! char *buf; ! ! va_start(ap, msg); ! buf = (char *) Malloc(128); ! memset(buf, 0, 128); ! va_start(ap, msg); ! vsnprintf(buf, 127, msg, ap); ! ! if(mthis.opts.bFork) ! log_write(LOG_PLUGINS | LOG_SLOG, buf); ! else ! log_write(LOG_PLUGINS | LOG_CONSOLE, buf); ! free(buf); ! va_end(ap); } ! RETSIGTYPE ! sig_int(int i) { ! switch (i) ! { ! case SIGINT: ! err_msg("caught SIGINT, cleaning up..\n"); ! break; ! case SIGTERM: ! err_msg("caught SIGTERM, cleaning up..\n"); ! break; ! case SIGHUP: ! err_msg("caught SIGHUP, restarting..\n"); ! sonar_sweep(); ! break; ! case SIGSEGV: ! err_msg("oops! sonar segmentation fault.\n"); ! /* plugin_killall(); */ ! abort(); ! break; ! } ! /* plugin_killall(); */ ! ! exit(0); } ! struct stat * ! get_stats(const char *file) { ! struct stat *buf; ! char *path = NULL, *token, *str, cwd[PATH_MAX]; ! assert(file != NULL); ! buf = (struct stat *) Malloc(sizeof(struct stat)); ! log_write(LOG_DBUG, " get_stats: checking for %s\n", file); ! // if we have the full path ! if(stat(file, buf) == 0) ! return buf; ! log_write(LOG_DBUG, " get_stats: not found, checking in $PATH\n"); ! path = getenv("PATH"); ! // check in the paths ! if(path) ... [truncated message content] |