cfengine  3.15.4
About: CFEngine is a configuration management system for configuring and maintaining Unix-like computers (using an own high level policy language). Community version.
  Fossies Dox: cfengine-3.15.4.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

sysinfo.c File Reference
#include <platform.h>
#include <sysinfo.h>
#include <sysinfo_priv.h>
#include <cf3.extern.h>
#include <eval_context.h>
#include <files_names.h>
#include <files_interfaces.h>
#include <hash.h>
#include <scope.h>
#include <item_lib.h>
#include <matching.h>
#include <systype.h>
#include <unix.h>
#include <string_lib.h>
#include <regex.h>
#include <misc_lib.h>
#include <file_lib.h>
#include <rlist.h>
#include <audit.h>
#include <pipes.h>
#include <known_dirs.h>
#include <files_lib.h>
#include <printsize.h>
#include <cf-windows-functions.h>
#include <ornaments.h>
#include <feature.h>
#include <evalfunction.h>
#include <json-utils.h>
Include dependency graph for sysinfo.c:

Go to the source code of this file.

Macros

#define BOOT_TIME_WITH_PROCFS
 
#define LSB_RELEASE_FILENAME   "/etc/lsb-release"
 
#define DEBIAN_VERSION_FILENAME   "/etc/debian_version"
 
#define DEBIAN_ISSUE_FILENAME   "/etc/issue"
 
#define COMPONENTS_SIZE   16
 
#define UPTIME_REGEXP   " up (\\d+ day[^,]*,|) *(\\d+( ho?u?r|:(\\d+))|(\\d+) min)"
 
#define UPTIME_BACKREFS   5
 
#define UPTIME_OVECTOR   ((UPTIME_BACKREFS + 1) * 3)
 

Functions

static time_t GetBootTimeFromUptimeCommand (time_t now)
 
void CalculateDomainName (const char *nodename, const char *dnsname, char *fqname, size_t fqname_size, char *uqname, size_t uqname_size, char *domain, size_t domain_size)
 
static void GetCPUInfo (EvalContext *ctx)
 
void DetectDomainName (EvalContext *ctx, const char *orig_nodename)
 
void DiscoverVersion (EvalContext *ctx)
 
static void GetNameInfo3 (EvalContext *ctx)
 
void LoadSlowlyVaryingObservations (EvalContext *ctx)
 
static void Get3Environment (EvalContext *ctx)
 
static void BuiltinClasses (EvalContext *ctx)
 
void CreateHardClassesFromCanonification (EvalContext *ctx, const char *canonified, char *tags)
 
static void SetFlavor (EvalContext *ctx, const char *flavor)
 
static void OSClasses (EvalContext *ctx)
 
int GetUptimeSeconds (time_t now)
 
int GetUptimeMinutes (time_t now)
 
JsonElementGetUserInfo (const void *passwd)
 
void GetSysVars (EvalContext *ctx)
 
void GetDefVars (EvalContext *ctx)
 
void DetectEnvironment (EvalContext *ctx)
 

Variables

static const char *const CLASSATTRIBUTES [][3]
 
static const char *const VRESOLVCONF []
 
static const char *const VMAILDIR []
 
static const char *const VEXPORTS []
 

Macro Definition Documentation

◆ BOOT_TIME_WITH_PROCFS

#define BOOT_TIME_WITH_PROCFS

Definition at line 132 of file sysinfo.c.

◆ COMPONENTS_SIZE

#define COMPONENTS_SIZE   16

◆ DEBIAN_ISSUE_FILENAME

#define DEBIAN_ISSUE_FILENAME   "/etc/issue"

Definition at line 144 of file sysinfo.c.

◆ DEBIAN_VERSION_FILENAME

#define DEBIAN_VERSION_FILENAME   "/etc/debian_version"

Definition at line 143 of file sysinfo.c.

◆ LSB_RELEASE_FILENAME

#define LSB_RELEASE_FILENAME   "/etc/lsb-release"

Definition at line 142 of file sysinfo.c.

◆ UPTIME_BACKREFS

#define UPTIME_BACKREFS   5

Definition at line 3185 of file sysinfo.c.

◆ UPTIME_OVECTOR

#define UPTIME_OVECTOR   ((UPTIME_BACKREFS + 1) * 3)

Definition at line 3186 of file sysinfo.c.

◆ UPTIME_REGEXP

#define UPTIME_REGEXP   " up (\\d+ day[^,]*,|) *(\\d+( ho?u?r|:(\\d+))|(\\d+) min)"

Definition at line 3184 of file sysinfo.c.

Function Documentation

◆ BuiltinClasses()

static void BuiltinClasses ( EvalContext ctx)
static

◆ CalculateDomainName()

void CalculateDomainName ( const char *  nodename,
const char *  dnsname,
char *  fqname,
size_t  fqname_size,
char *  uqname,
size_t  uqname_size,
char *  domain,
size_t  domain_size 
)

Definition at line 290 of file sysinfo.c.

References MIN, NULL, strlcpy(), and strstr().

Referenced by DetectDomainName().

◆ CreateHardClassesFromCanonification()

void CreateHardClassesFromCanonification ( EvalContext ctx,
const char *  canonified,
char *  tags 
)

Definition at line 1041 of file sysinfo.c.

References CF_MAXVARSIZE, EvalContextClassPutHard(), and strlcpy().

Referenced by BuiltinClasses(), and CreateHardClassesFromFeatures().

◆ DetectDomainName()

◆ DetectEnvironment()

◆ DiscoverVersion()

void DiscoverVersion ( EvalContext ctx)

◆ Get3Environment()

◆ GetBootTimeFromUptimeCommand()

static time_t GetBootTimeFromUptimeCommand ( time_t  now)
static

◆ GetCPUInfo()

◆ GetDefVars()

void GetDefVars ( EvalContext ctx)

Definition at line 3323 of file sysinfo.c.

References CF_DATA_TYPE_STRING, EvalContextVariablePutSpecial(), and SPECIAL_SCOPE_DEF.

Referenced by DetectEnvironment().

◆ GetNameInfo3()

◆ GetSysVars()

void GetSysVars ( EvalContext ctx)

◆ GetUptimeMinutes()

int GetUptimeMinutes ( time_t  now)

Definition at line 3164 of file sysinfo.c.

References GetUptimeSeconds(), and SECONDS_PER_MINUTE.

Referenced by GetNameInfo3().

◆ GetUptimeSeconds()

int GetUptimeSeconds ( time_t  now)

Return the number of seconds the system has been online given the current time() as an argument, or return -1 if unavailable or unimplemented.

Definition at line 3061 of file sysinfo.c.

References errno, GetBootTimeFromUptimeCommand(), GetErrorStr(), Log(), LOG_LEVEL_VERBOSE, and NULL.

Referenced by GetUptimeMinutes(), and VerifyThatDatabaseIsNotCorrupt_once().

◆ GetUserInfo()

JsonElement* GetUserInfo ( const void *  passwd)

◆ LoadSlowlyVaryingObservations()

◆ OSClasses()

◆ SetFlavor()

static void SetFlavor ( EvalContext ctx,
const char *  flavor 
)
static

Variable Documentation

◆ CLASSATTRIBUTES

const char* const CLASSATTRIBUTES[][3]
static
Initial value:
=
{
[PLATFORM_CONTEXT_UNKNOWN] = {"-", "-", "-"},
[PLATFORM_CONTEXT_OPENVZ] = {"virt_host_vz_vzps", ".*", ".*"},
[PLATFORM_CONTEXT_HP] = {"hp-ux", ".*", ".*"},
[PLATFORM_CONTEXT_AIX] = {"aix", ".*", ".*"},
[PLATFORM_CONTEXT_LINUX] = {"linux", ".*", ".*"},
[PLATFORM_CONTEXT_BUSYBOX] = {"busybox", ".*", ".*"},
[PLATFORM_CONTEXT_SOLARIS] = {"sunos", ".*",
"5\\.1[1-9].*"},
[PLATFORM_CONTEXT_SUN_SOLARIS] = {"sunos", ".*",
"5\\.([2-9]|10)(\\..*)?"},
[PLATFORM_CONTEXT_FREEBSD] = {"freebsd", ".*", ".*"},
[PLATFORM_CONTEXT_NETBSD] = {"netbsd", ".*", ".*"},
[PLATFORM_CONTEXT_CRAYOS] = {"sn.*", "cray*", ".*"},
[PLATFORM_CONTEXT_WINDOWS_NT] = {"cygwin_nt.*", ".*", ".*"},
[PLATFORM_CONTEXT_SYSTEMV] = {"unix_sv", ".*", ".*"},
[PLATFORM_CONTEXT_OPENBSD] = {"openbsd", ".*", ".*"},
[PLATFORM_CONTEXT_CFSCO] = {"sco_sv", ".*", ".*"},
[PLATFORM_CONTEXT_DARWIN] = {"darwin", ".*", ".*"},
[PLATFORM_CONTEXT_QNX] = {"qnx", ".*", ".*"},
[PLATFORM_CONTEXT_DRAGONFLY] = {"dragonfly", ".*", ".*"},
[PLATFORM_CONTEXT_MINGW] = {"windows_nt.*", ".*", ".*"},
[PLATFORM_CONTEXT_VMWARE] = {"vmkernel", ".*", ".*"},
[PLATFORM_CONTEXT_ANDROID] = {"android", ".*", ".*"},
}
@ PLATFORM_CONTEXT_UNKNOWN
Definition: systype.h:32
@ PLATFORM_CONTEXT_NETBSD
Definition: systype.h:41
@ PLATFORM_CONTEXT_OPENVZ
Definition: systype.h:33
@ PLATFORM_CONTEXT_MINGW
Definition: systype.h:50
@ PLATFORM_CONTEXT_AIX
Definition: systype.h:35
@ PLATFORM_CONTEXT_SOLARIS
Definition: systype.h:38
@ PLATFORM_CONTEXT_DRAGONFLY
Definition: systype.h:49
@ PLATFORM_CONTEXT_VMWARE
Definition: systype.h:51
@ PLATFORM_CONTEXT_FREEBSD
Definition: systype.h:40
@ PLATFORM_CONTEXT_HP
Definition: systype.h:34
@ PLATFORM_CONTEXT_QNX
Definition: systype.h:48
@ PLATFORM_CONTEXT_DARWIN
Definition: systype.h:47
@ PLATFORM_CONTEXT_LINUX
Definition: systype.h:36
@ PLATFORM_CONTEXT_OPENBSD
Definition: systype.h:45
@ PLATFORM_CONTEXT_SYSTEMV
Definition: systype.h:44
@ PLATFORM_CONTEXT_ANDROID
Definition: systype.h:52
@ PLATFORM_CONTEXT_CFSCO
Definition: systype.h:46
@ PLATFORM_CONTEXT_BUSYBOX
Definition: systype.h:37
@ PLATFORM_CONTEXT_SUN_SOLARIS
Definition: systype.h:39
@ PLATFORM_CONTEXT_WINDOWS_NT
Definition: systype.h:43
@ PLATFORM_CONTEXT_CRAYOS
Definition: systype.h:42

Definition at line 185 of file sysinfo.c.

Referenced by GetNameInfo3().

◆ VEXPORTS

const char* const VEXPORTS[]
static
Initial value:
=
{
[PLATFORM_CONTEXT_OPENVZ] = "/etc/exports",
[PLATFORM_CONTEXT_HP] = "/etc/exports",
[PLATFORM_CONTEXT_AIX] = "/etc/exports",
[PLATFORM_CONTEXT_LINUX] = "/etc/exports",
[PLATFORM_CONTEXT_SOLARIS] = "/etc/dfs/dfstab",
[PLATFORM_CONTEXT_SUN_SOLARIS] = "/etc/dfs/dfstab",
[PLATFORM_CONTEXT_FREEBSD] = "/etc/exports",
[PLATFORM_CONTEXT_NETBSD] = "/etc/exports",
[PLATFORM_CONTEXT_CRAYOS] = "/etc/exports",
[PLATFORM_CONTEXT_WINDOWS_NT] = "/etc/exports",
[PLATFORM_CONTEXT_SYSTEMV] = "/etc/dfs/dfstab",
[PLATFORM_CONTEXT_OPENBSD] = "/etc/exports",
[PLATFORM_CONTEXT_CFSCO] = "/etc/dfs/dfstab",
[PLATFORM_CONTEXT_DARWIN] = "/etc/exports",
[PLATFORM_CONTEXT_QNX] = "/etc/exports",
[PLATFORM_CONTEXT_DRAGONFLY] = "/etc/exports",
}

Definition at line 262 of file sysinfo.c.

Referenced by GetNameInfo3().

◆ VMAILDIR

const char* const VMAILDIR[]
static
Initial value:
=
{
[PLATFORM_CONTEXT_OPENVZ] = "/var/spool/mail",
[PLATFORM_CONTEXT_HP] = "/var/mail",
[PLATFORM_CONTEXT_AIX] = "/var/spool/mail",
[PLATFORM_CONTEXT_LINUX] = "/var/spool/mail",
[PLATFORM_CONTEXT_SOLARIS] = "/var/mail",
[PLATFORM_CONTEXT_SUN_SOLARIS] = "/var/mail",
[PLATFORM_CONTEXT_FREEBSD] = "/var/mail",
[PLATFORM_CONTEXT_NETBSD] = "/var/mail",
[PLATFORM_CONTEXT_CRAYOS] = "/usr/mail",
[PLATFORM_CONTEXT_SYSTEMV] = "/var/mail",
[PLATFORM_CONTEXT_OPENBSD] = "/var/mail",
[PLATFORM_CONTEXT_CFSCO] = "/var/spool/mail",
[PLATFORM_CONTEXT_DARWIN] = "/var/mail",
[PLATFORM_CONTEXT_QNX] = "/var/spool/mail",
[PLATFORM_CONTEXT_DRAGONFLY] = "/var/mail",
[PLATFORM_CONTEXT_VMWARE] = "/var/spool/mail",
}

Definition at line 237 of file sysinfo.c.

Referenced by GetNameInfo3().

◆ VRESOLVCONF

const char* const VRESOLVCONF[]
static
Initial value:
=
{
[PLATFORM_CONTEXT_OPENVZ] = "/etc/resolv.conf",
[PLATFORM_CONTEXT_HP] = "/etc/resolv.conf",
[PLATFORM_CONTEXT_AIX] = "/etc/resolv.conf",
[PLATFORM_CONTEXT_LINUX] = "/etc/resolv.conf",
[PLATFORM_CONTEXT_BUSYBOX] = "/etc/resolv.conf",
[PLATFORM_CONTEXT_SOLARIS] = "/etc/resolv.conf",
[PLATFORM_CONTEXT_SUN_SOLARIS] = "/etc/resolv.conf",
[PLATFORM_CONTEXT_FREEBSD] = "/etc/resolv.conf",
[PLATFORM_CONTEXT_NETBSD] = "/etc/resolv.conf",
[PLATFORM_CONTEXT_CRAYOS] = "/etc/resolv.conf",
[PLATFORM_CONTEXT_WINDOWS_NT] = "/etc/resolv.conf",
[PLATFORM_CONTEXT_SYSTEMV] = "/etc/resolv.conf",
[PLATFORM_CONTEXT_OPENBSD] = "/etc/resolv.conf",
[PLATFORM_CONTEXT_CFSCO] = "/etc/resolv.conf",
[PLATFORM_CONTEXT_DARWIN] = "/etc/resolv.conf",
[PLATFORM_CONTEXT_QNX] = "/etc/resolv.conf",
[PLATFORM_CONTEXT_DRAGONFLY] = "/etc/resolv.conf",
[PLATFORM_CONTEXT_VMWARE] = "/etc/resolv.conf",
}

Definition at line 212 of file sysinfo.c.

Referenced by GetNameInfo3().