Skip to content

Commit

Permalink
Merge pull request OpenSCAP#560 from radzy/20161019-osrelease-singoovi
Browse files Browse the repository at this point in the history
Update is_wrlinux to check /etc/os-release
  • Loading branch information
rsprudencio authored Nov 7, 2016
2 parents b45fa2a + 7f18f14 commit 615c4a7
Showing 1 changed file with 41 additions and 2 deletions.
43 changes: 41 additions & 2 deletions src/OVAL/probes/unix/runlevel.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <strings.h>
#include <errno.h>
#include <assert.h>
#include <unistd.h>
Expand All @@ -69,6 +70,9 @@
#include <alloc.h>
#include "common/debug_priv.h"

#define RELEASENAME_MAX_SIZE 256
#define RELEASENAME_PATTERN "CPE_NAME=\"%255s\""

struct runlevel_req {
SEXP_t *service_name_ent;
SEXP_t *runlevel_ent;
Expand Down Expand Up @@ -281,6 +285,42 @@ static int get_runlevel_common (struct runlevel_req *req, struct runlevel_rep **

#if !defined(LINUX_DISTRO)
# define LINUX_DISTRO generic

static int parse_os_release(const char * cpe)
{
struct stat st;
int got;
int ret;
FILE * osrelease;
char buf[RELEASENAME_MAX_SIZE];
char *releasename = &buf[0];
char c;

got = stat ("/etc/os-release", &st);
if ( got ) return (got == 0);

osrelease = fopen("/etc/os-release", "r");
if ( osrelease < 0 ) return (! errno);

bzero(releasename, RELEASENAME_MAX_SIZE);

got = fscanf(osrelease, RELEASENAME_PATTERN , releasename);
while ( got == 0 ) {
c = fgetc(osrelease);
got = fscanf(osrelease, RELEASENAME_PATTERN , releasename);
}
if ( got < 0 ) {
ret = !got;
goto done;
}

ret = strncmp(releasename, cpe, strlen(cpe)) == 0;

done:
fclose(osrelease);
return(ret);
}

static int is_redhat (void)
{
struct stat st;
Expand Down Expand Up @@ -334,8 +374,7 @@ static int is_solaris (void)

static int is_wrlinux (void)
{
struct stat st;
return (stat ("/etc/wrlinux-release", &st) == 0 );
return (parse_os_release("cpe:/o:windriver:wrlinux"));
}

static int is_common (void)
Expand Down

0 comments on commit 615c4a7

Please sign in to comment.