diff options
author | Andreas Baumann <mail@andreasbaumann.cc> | 2014-12-13 19:53:37 +0100 |
---|---|---|
committer | Andreas Baumann <mail@andreasbaumann.cc> | 2014-12-13 19:53:37 +0100 |
commit | 259ca5ed40b727de03c45479ff374d1bb7c39630 (patch) | |
tree | 685271dfba80bd439ec5c690900728a8ed22db99 | |
parent | 991058ebf9d81d567a6f662f1c2e2e8827dcc60a (diff) | |
parent | a12ffbaf5b84aeec0b78d55cc17ee5a392c138c7 (diff) | |
download | biruda-259ca5ed40b727de03c45479ff374d1bb7c39630.tar.gz biruda-259ca5ed40b727de03c45479ff374d1bb7c39630.tar.bz2 |
Merge branch 'master' of ssh://andreasbaumann.dyndns.org:2222/biruda
-rw-r--r-- | src/3rdParty/http_tiny/http_lib.c | 3 | ||||
-rw-r--r-- | src/system.c | 150 |
2 files changed, 101 insertions, 52 deletions
diff --git a/src/3rdParty/http_tiny/http_lib.c b/src/3rdParty/http_tiny/http_lib.c index 8bb7384..db5b9b3 100644 --- a/src/3rdParty/http_tiny/http_lib.c +++ b/src/3rdParty/http_tiny/http_lib.c @@ -48,6 +48,7 @@ static char *rcsid="$Id: http_lib.c,v 3.5 1998/09/23 06:19:15 dl Exp $"; #include <netdb.h> #include <ctype.h> #include <string.h> +#include <strings.h> #include <unistd.h> #include <stdlib.h> @@ -184,7 +185,7 @@ static http_retcode http_query(command, url, additional_header, mode, : SERVER_DEFAULT ) ))) { memset((char *) &server,0, sizeof(server)); - memmove((char *) &server.sin_addr, hp->h_addr, hp->h_length); + memmove((char *) &server.sin_addr, hp->h_addr_list[0], hp->h_length); server.sin_family = hp->h_addrtype; server.sin_port = (unsigned short) htons( port ); } else diff --git a/src/system.c b/src/system.c index 57f39a0..fede36c 100644 --- a/src/system.c +++ b/src/system.c @@ -219,80 +219,128 @@ void system_os( char *name, size_t len ) break; } #elif defined( linux ) || defined( __linux ) || defined( __linux__ ) + bool has_os_release = false; + bool has_redhat_release = false; + /* new systemd-way on modern Linux systems */ FILE *f = fopen( "/etc/os-release", "r" ); if( f == NULL ) { f = fopen( "/usr/lib/os-release", "r" ); if( f == NULL ) { + f = fopen( "/etc/redhat-release", "r" ); + if( f == NULL ) { + snprintf( name, len, "cpe:/o:linux" ); + return; + } else { + has_redhat_release = true; + } /* TODO: test for /etc/xxx-release, /etc/xxx-version, not sure if we should also check and run lsb_release */ - snprintf( name, len, "cpe:/o:linux" ); - return; + } else { + has_os_release = true; } + } else { + has_os_release = true; } - char line[100]; - char *key; - char *id = NULL; - char *version_id = NULL; - char *cpe_name = NULL; - while( !feof( f ) ) { - fgets( line, sizeof( line ), f ); - if( line[0] == '#' ) continue; - char *value = strchr( line, '=' ); - if( value == NULL ) continue; - key = line; - *value++ = '\0'; - char *p = value; - char *q = p; - while( *p != '\0' ) { - if( *p == '\\' ) { - ++p; - if( *p == '\0' ) { - break; + if( has_os_release ) { + char line[100]; + char *key; + char *id = NULL; + char *version_id = NULL; + char *cpe_name = NULL; + while( !feof( f ) ) { + fgets( line, sizeof( line ), f ); + if( line[0] == '#' ) continue; + char *value = strchr( line, '=' ); + if( value == NULL ) continue; + key = line; + *value++ = '\0'; + char *p = value; + char *q = p; + while( *p != '\0' ) { + if( *p == '\\' ) { + ++p; + if( *p == '\0' ) { + break; + } + *q++ = *p++; + } + if( *p == '\"' || *p == '\'' || *p == '\n' ) { + p++; + } else { + *q++ = *p++; } - *q++ = *p++; - } - if( *p == '\"' || *p == '\'' || *p == '\n' ) { - p++; - } else { - *q++ = *p++; } - } - *q = '\0'; + *q = '\0'; - if( strcmp( key, "CPE_NAME" ) == 0 ) { - cpe_name = strdup( value ); - } else if( strcmp( key, "ID" ) == 0 ) { - id = strdup( value ); - } else if( strcmp( key, "VERSION_ID" ) == 0 ) { - version_id = strdup( value ); + if( strcmp( key, "CPE_NAME" ) == 0 ) { + cpe_name = strdup( value ); + } else if( strcmp( key, "ID" ) == 0 ) { + id = strdup( value ); + } else if( strcmp( key, "VERSION_ID" ) == 0 ) { + version_id = strdup( value ); + } } - } - fclose( f ) ; + /* do we have a CPE_NAME? In this case CPE_NAME takes + precedence */ + if( cpe_name != NULL ) { + snprintf( name, len, "%s", cpe_name ); + } else { + /* construct CPE_NAME from ID and VERSION_ID and any other + information we find */ - /* do we have a CPE_NAME? In this case CPE_NAME takes - precedence */ - if( cpe_name != NULL ) { - snprintf( name, len, "%s", cpe_name ); - } else { - /* construct CPE_NAME from ID and VERSION_ID and any other - information we find */ + /* no version information, so we have a rolling release */ + if( version_id == NULL ) { + version_id = strdup( "rolling" ); + } - /* no version information, so we have a rolling release */ - if( version_id == NULL ) { - version_id = strdup( "rolling" ); + snprintf( name, len, "cpe:/o:%s:%s:%s", id, id, version_id ); } - snprintf( name, len, "cpe:/o:%s:%s:%s", id, id, version_id ); + if( id != NULL ) free( id ); + if( version_id != NULL ) free( version_id ); + if( cpe_name != NULL ) free( cpe_name ); + } + + if( has_redhat_release ) { + //CentOS release 6.5 (Final) + char line[100]; + fgets( line, sizeof( line ), f ); + + if( strstr( line, "CentOS" ) != NULL ) { + char *p = strtok( line, " " ); + bool is_version = false; + char *version = "unknown"; + while( p != NULL ) { + if( strcmp( p, "release" ) == 0 ) { + is_version = true; + p = strtok( NULL, " " ); + continue; + } + if( is_version ) { + version = p; + is_version = false; + } + p = strtok( NULL, " " ); + } + + char *major = strtok( version, "." ); + if( p != NULL ) { + snprintf( name, len, "cpe:/o:centos:centos:%s", major ); + } else { + snprintf( name, len, "cpe:/o:centos:centos:%s", version ); + } + } else { + snprintf( name, len, "cpe:/o:redhat:unknown" ); + } } - if( id != NULL ) free( id ); - if( version_id != NULL ) free( version_id ); - if( cpe_name != NULL ) free( cpe_name ); + fclose( f ) ; + #elif defined( __FreeBSD__ ) /* resort to uname */ |