policycoreutils: Using vendor defined directories for configuration files
PATCH 1/1 policycoreutils: Using vendor defined directories for configuration files
Besides user/admin defined configuration files. Useful for systems that have config files in /usr/etc
--- policycoreutils/sestatus/Makefile | 8 +++ policycoreutils/sestatus/sestatus.c | 78 +++++++++++++++++++++++- policycoreutils/sestatus/sestatus.conf.5 | 2 +- 3 files changed, 84 insertions(+), 4 deletions(-)
policycoreutils/sestatus/Makefile +8 -0
@@ -5,6 +5,7 @@ BINDIR ?= $(PREFIX)/bin SBINDIR ?= $(PREFIX)/sbin MANDIR = $(PREFIX)/share/man ETCDIR ?= /etc +LIBECONFH ?= $(shell test -f /usr/include/libeconf.h && echo y) CFLAGS ?= -Werror -Wall -W override CFLAGS += -I../../libselinux/include -D_FILE_OFFSET_BITS=64
@@ -14,6 +15,13 @@ override LDLIBS += $(LIBSELINUX_LDLIBS) all: sestatus sestatus: sestatus.o +ifdef VENDORDIR +ifneq ($(LIBECONFH), y) + (echo "VENDORDIR defined but libeconf not available."; exit 1) +endif +override CFLAGS += -DVENDORDIR='"${VENDORDIR}"' +override LDLIBS += -leconf +endif install: all [ -d $(DESTDIR)$(MANDIR)/man8 ] || mkdir -p $(DESTDIR)$(MANDIR)/man8
policycoreutils/sestatus/sestatus.c +75 -3
94 lines not on this page · raw message
policycoreutils/sestatus/sestatus.conf.5 +1 -1
@@ -8,7 +8,7 @@ The \fIsestatus.conf\fR file is used by the \fBsestatus\fR(8) command with the \ .sp The fully qualified path name of the configuration file is: .RS -\fI/etc/sestatus.conf\fR +\fI/etc/sestatus.conf\fR or \fI<vendordir>/sestatus.conf\fR if it is not available .RE .RE .sp
Signature · 1 line
2.55.0
Stephen Smalley
maintainerQuoted 54 lines · Johannes Segitz
Besides user/admin defined configuration files. Useful for systems that have config files in
/usr/etcSigned-off-by Stefan Schubert <[email protected]>---
policycoreutils/sestatus/sestatus.c +27
-3@@ -21,11 +21,16 @@#define PROC_BASE "/proc"#define MAX_CHECK 50 -#define CONF "/etc/sestatus.conf" +#define CONFDIR "/etc" +#define CONFNAME "sestatus" +#define CONFPOST "conf" +#define CONF CONFDIR "/" CONFNAME "." CONFPOST/* conf file sections */ -#define PROCS "[process]" -#define FILES "[files]" +#define SECTIONPROCS "process" +#define SECTIONFILES "files" +#define PROCS "[" SECTIONPROCS "]" +#define FILES "[" SECTIONFILES "]"/* buffer size for cmp_cmdline */ #define BUFSIZE 255@@ -91,8 +96,75 @@ static int pidof(const char *command)return ret; } +#ifdef VENDORDIR +#include <libeconf.h> + +static void load_checks_with_vendor_settings (char *pc[],int *npc,char *fc[],int *nfc) +{ +econf_file *key_file =NULL ; +econf_err error; +char **keys; +size_t key_number; + + error =econf_readDirs (&key_file, +VENDORDIR , +CONFDIR , +CONFNAME , +CONFPOST , +"" ,"#" ); +if (error !=ECONF_SUCCESS ) { + printf("\nCannot read settings %s.%s: %s\n", + CONFNAME,
policycoreutils/sestatus/sestatus.c static int pidof(const char *command) · line 127
Quoted 10 lines
policycoreutils/sestatus/sestatus.c +10
-0+CONFPOST , + econf_errString( error )); +return ; + } + + error =econf_getKeys (key_file,SECTIONPROCS , &key_number, &keys); +if (error !=ECONF_SUCCESS ) { +printf ("\nCannot read group %s: %s\n" , +SECTIONPROCS , +econf_errString ( error ));
Do you want to print this message even for ECONF_NOKEY? Previously we ignored missing sections silently.
Quoted 33 lines
policycoreutils/sestatus/sestatus.c +33
-0+ } else { +for (size_t i =0 ; i < key_number; i++) { +if (*npc >=MAX_CHECK ) +break ; + pc[*npc] =strdup (keys[i]); +if (!pc[*npc]) +break ; + (*npc)++; + } +econf_free (keys); + } + + error =econf_getKeys (key_file,SECTIONFILES , &key_number, &keys); +if (error !=ECONF_SUCCESS ) { +printf ("\nCannot read group %s: %s\n" , +SECTIONFILES , +econf_errString ( error )); + }else { +for (size_t i =0 ; i < key_number; i++) { +if (*nfc >=MAX_CHECK ) +break ; + fc[*nfc] =strdup (keys[i]); +if (!fc[*nfc]) +break ; + (*nfc)++; + } +econf_free (keys); + } + +econf_free (key_file); +return ; +} +#endif
policycoreutils/sestatus/sestatus.c static int pidof(const char *command) · line 170
Quoted 10 lines
policycoreutils/sestatus/sestatus.c +5
-0+static void load_checks (char *pc[],int *npc,char *fc[],int *nfc) { +#ifdef VENDORDIR +load_checks_with_vendor_settings (pc, npc, fc, nfc); +return ; +#endif FILE *fp =fopen (CONF ,"r" );char buf[255 ], *bufp;int buf_len, section =-1 ;
This code doesn't pass make check-format; can fix on merge if desired.
policycoreutils/sestatus/sestatus.conf.5 The \fIsestatus.conf\fR file is used by the \fBsestatus\fR(8) command with the \ · line 11
Quoted 10 lines
policycoreutils/sestatus/sestatus.conf.5 +1
-1@@ -8,7 +8,7 @@ The \fIsestatus.conf\fR file is used by the \fBsestatus\fR(8) command with the \ .sp The fully qualified path name of the configuration file is: .RS -\fI/etc/sestatus.conf\fR +\fI/etc/sestatus.conf\fR or \fI<vendordir>/sestatus.conf\fR if it is not available
This says "or" but econf_readDirs() will merge the two - should say layered.
Quoted 7 lines
policycoreutils/sestatus/sestatus.conf.5 +0
-1.RE .RE .sp --2.55.0
Quoted 9 lines · Stephen Smalley
policycoreutils/sestatus/sestatus.c static int pidof(const char *command) · line 127
Quoted 5 lines · Johannes Segitz
policycoreutils/sestatus/sestatus.c +5
-0+ error =econf_getKeys (key_file,SECTIONPROCS , &key_number, &keys); +if (error !=ECONF_SUCCESS ) { +printf ("\nCannot read group %s: %s\n" , +SECTIONPROCS , +econf_errString ( error ));Do you want to print this message even for
ECONF_NOKEY? Previously we ignored missing sections silently.
I think it would be benefitial, but I don't feel strongly about this. If you prefer ECONF_NOKEY can also be excluded
Quoted 11 lines
policycoreutils/sestatus/sestatus.c static int pidof(const char *command) · line 170
Quoted 9 lines
static void
load_checks(char *pc[], int *npc, char *fc[], int *nfc){policycoreutils/sestatus/sestatus.c +4
-0+#ifdef VENDORDIR +load_checks_with_vendor_settings (pc, npc, fc, nfc); +return ; +#endif FILE *fp =fopen (CONF ,"r" );char buf[255 ], *bufp;int buf_len, section =-1 ;This code doesn't pass make check-format; can fix on merge if desired.
Depending on the decision on ECONF_NOKEY I'll do it if I need to resend a v2
Quoted 4 lines
Quoted 4 lines
policycoreutils/sestatus/sestatus.conf.5 +0
-0
Quoted 8 lines
policycoreutils/sestatus/sestatus.conf.5 The \fIsestatus.conf\fR file is used by the \fBsestatus\fR(8) command with the \ · line 11
Quoted 6 lines
policycoreutils/sestatus/sestatus.conf.5 +1
-1@@ -8,7 +8,7 @@ The \fIsestatus.conf\fR file is used by the \fBsestatus\fR(8) command with the \ .sp The fully qualified path name of the configuration file is: .RS -\fI/etc/sestatus.conf\fR +\fI/etc/sestatus.conf\fR or \fI<vendordir>/sestatus.conf\fR if it is not availableThis says "or" but
econf_readDirs()will merge the two - should say layered.
I talked to Stefan and he intentionally used or here because of
https://github.com/uapi-group/specifications/blob/main/specs/configuration_files_specification.md#masking
Johannes
Signature · 4 lines
GPG Key EE16 6BCE AD56 E034 BFB3 3ADD 7BF7 29D5 E7C8 1FA0 Subkey fingerprint: 250F 43F5 F7CE 6F1E 9C59 4F95 BC27 DD9D 2CC4 FD66 SUSE Software Solutions Germany GmbH, Frankenstr. 146, 90461 Nürnberg, Germany www.suse.com, Geschäftsführer: Jochen Jaser, Andrew McDonald, Abhinav Puri, (HRB 36809, AG Nürnberg)
Quoted 5 lines · Johannes Segitz
Besides user/admin defined configuration files. Useful for systems that have config files in
/usr/etcSigned-off-by Stefan Schubert <[email protected]>
Will reformat on merge.
Quoted 149 lines
--- policycoreutils/sestatus/Makefile | 8 +++ policycoreutils/sestatus/sestatus.c | 78 +++++++++++++++++++++++- policycoreutils/sestatus/sestatus.conf.5 | 2 +- 3 files changed, 84 insertions(+), 4 deletions(-)policycoreutils/sestatus/Makefile +8
-0@@ -5,6 +5,7 @@ BINDIR ?= $(PREFIX)/bin SBINDIR ?= $(PREFIX)/sbin MANDIR = $(PREFIX)/share/man ETCDIR ?= /etc +LIBECONFH ?= $(shell test -f /usr/include/libeconf.h && echo y) CFLAGS ?= -Werror -Wall -W override CFLAGS += -I../../libselinux/include -D_FILE_OFFSET_BITS=64@@ -14,6 +15,13 @@ override LDLIBS += $(LIBSELINUX_LDLIBS) all: sestatus sestatus: sestatus.o +ifdef VENDORDIR +ifneq ($(LIBECONFH), y) + (echo "VENDORDIR defined but libeconf not available."; exit 1) +endif +override CFLAGS += -DVENDORDIR='"${VENDORDIR}"' +override LDLIBS += -leconf +endif install: all [ -d $(DESTDIR)$(MANDIR)/man8 ] || mkdir -p $(DESTDIR)$(MANDIR)/man8policycoreutils/sestatus/sestatus.c +75
-3@@ -21,11 +21,16 @@#define PROC_BASE "/proc"#define MAX_CHECK 50 -#define CONF "/etc/sestatus.conf" +#define CONFDIR "/etc" +#define CONFNAME "sestatus" +#define CONFPOST "conf" +#define CONF CONFDIR "/" CONFNAME "." CONFPOST/* conf file sections */ -#define PROCS "[process]" -#define FILES "[files]" +#define SECTIONPROCS "process" +#define SECTIONFILES "files" +#define PROCS "[" SECTIONPROCS "]" +#define FILES "[" SECTIONFILES "]"/* buffer size for cmp_cmdline */ #define BUFSIZE 255@@ -91,8 +96,75 @@ static int pidof(const char *command)return ret; } +#ifdef VENDORDIR +#include <libeconf.h> + +static void load_checks_with_vendor_settings (char *pc[],int *npc,char *fc[],int *nfc) +{ +econf_file *key_file =NULL ; +econf_err error; +char **keys; +size_t key_number; + + error =econf_readDirs (&key_file, +VENDORDIR , +CONFDIR , +CONFNAME , +CONFPOST , +"" ,"#" ); +if (error !=ECONF_SUCCESS ) { +printf ("\nCannot read settings %s.%s: %s\n" , +CONFNAME , +CONFPOST , +econf_errString ( error )); +return ; + } + + error =econf_getKeys (key_file,SECTIONPROCS , &key_number, &keys); +if (error !=ECONF_SUCCESS ) { +printf ("\nCannot read group %s: %s\n" , +SECTIONPROCS , +econf_errString ( error )); + }else { +for (size_t i =0 ; i < key_number; i++) { +if (*npc >=MAX_CHECK ) +break ; + pc[*npc] =strdup (keys[i]); +if (!pc[*npc]) +break ; + (*npc)++; + } +econf_free (keys); + } + + error =econf_getKeys (key_file,SECTIONFILES , &key_number, &keys); +if (error !=ECONF_SUCCESS ) { +printf ("\nCannot read group %s: %s\n" , +SECTIONFILES , +econf_errString ( error )); + }else { +for (size_t i =0 ; i < key_number; i++) { +if (*nfc >=MAX_CHECK ) +break ; + fc[*nfc] =strdup (keys[i]); +if (!fc[*nfc]) +break ; + (*nfc)++; + } +econf_free (keys); + } + +econf_free (key_file); +return ; +} +#endif +static void load_checks (char *pc[],int *npc,char *fc[],int *nfc) { +#ifdef VENDORDIR +load_checks_with_vendor_settings (pc, npc, fc, nfc); +return ; +#endif FILE *fp =fopen (CONF ,"r" );char buf[255 ], *bufp;int buf_len, section =-1 ;policycoreutils/sestatus/sestatus.conf.5 +1
-2@@ -8,7 +8,7 @@ The \fIsestatus.conf\fR file is used by the \fBsestatus\fR(8) command with the \ .sp The fully qualified path name of the configuration file is: .RS -\fI/etc/sestatus.conf\fR +\fI/etc/sestatus.conf\fR or \fI<vendordir>/sestatus.conf\fR if it is not available .RE .RE .sp --2.55.0
Stephen Smalley
maintainerQuoted 11 lines · Stephen Smalley
Quoted 5 lines · Johannes Segitz
Besides user/admin defined configuration files. Useful for systems that have config files in
/usr/etcSigned-off-by Stefan Schubert <[email protected]>Will reformat on merge.
Acked-by Stephen Smalley <[email protected]>
Merged.
Quoted 150 lines
Quoted 150 lines
--- policycoreutils/sestatus/Makefile | 8 +++ policycoreutils/sestatus/sestatus.c | 78 +++++++++++++++++++++++- policycoreutils/sestatus/sestatus.conf.5 | 2 +- 3 files changed, 84 insertions(+), 4 deletions(-)policycoreutils/sestatus/Makefile +8
-0@@ -5,6 +5,7 @@ BINDIR ?= $(PREFIX)/bin SBINDIR ?= $(PREFIX)/sbin MANDIR = $(PREFIX)/share/man ETCDIR ?= /etc +LIBECONFH ?= $(shell test -f /usr/include/libeconf.h && echo y) CFLAGS ?= -Werror -Wall -W override CFLAGS += -I../../libselinux/include -D_FILE_OFFSET_BITS=64@@ -14,6 +15,13 @@ override LDLIBS += $(LIBSELINUX_LDLIBS) all: sestatus sestatus: sestatus.o +ifdef VENDORDIR +ifneq ($(LIBECONFH), y) + (echo "VENDORDIR defined but libeconf not available."; exit 1) +endif +override CFLAGS += -DVENDORDIR='"${VENDORDIR}"' +override LDLIBS += -leconf +endif install: all [ -d $(DESTDIR)$(MANDIR)/man8 ] || mkdir -p $(DESTDIR)$(MANDIR)/man8policycoreutils/sestatus/sestatus.c +75
-3@@ -21,11 +21,16 @@#define PROC_BASE "/proc"#define MAX_CHECK 50 -#define CONF "/etc/sestatus.conf" +#define CONFDIR "/etc" +#define CONFNAME "sestatus" +#define CONFPOST "conf" +#define CONF CONFDIR "/" CONFNAME "." CONFPOST/* conf file sections */ -#define PROCS "[process]" -#define FILES "[files]" +#define SECTIONPROCS "process" +#define SECTIONFILES "files" +#define PROCS "[" SECTIONPROCS "]" +#define FILES "[" SECTIONFILES "]"/* buffer size for cmp_cmdline */ #define BUFSIZE 255@@ -91,8 +96,75 @@ static int pidof(const char *command)return ret; } +#ifdef VENDORDIR +#include <libeconf.h> + +static void load_checks_with_vendor_settings (char *pc[],int *npc,char *fc[],int *nfc) +{ +econf_file *key_file =NULL ; +econf_err error; +char **keys; +size_t key_number; + + error =econf_readDirs (&key_file, +VENDORDIR , +CONFDIR , +CONFNAME , +CONFPOST , +"" ,"#" ); +if (error !=ECONF_SUCCESS ) { +printf ("\nCannot read settings %s.%s: %s\n" , +CONFNAME , +CONFPOST , +econf_errString ( error )); +return ; + } + + error =econf_getKeys (key_file,SECTIONPROCS , &key_number, &keys); +if (error !=ECONF_SUCCESS ) { +printf ("\nCannot read group %s: %s\n" , +SECTIONPROCS , +econf_errString ( error )); + }else { +for (size_t i =0 ; i < key_number; i++) { +if (*npc >=MAX_CHECK ) +break ; + pc[*npc] =strdup (keys[i]); +if (!pc[*npc]) +break ; + (*npc)++; + } +econf_free (keys); + } + + error =econf_getKeys (key_file,SECTIONFILES , &key_number, &keys); +if (error !=ECONF_SUCCESS ) { +printf ("\nCannot read group %s: %s\n" , +SECTIONFILES , +econf_errString ( error )); + }else { +for (size_t i =0 ; i < key_number; i++) { +if (*nfc >=MAX_CHECK ) +break ; + fc[*nfc] =strdup (keys[i]); +if (!fc[*nfc]) +break ; + (*nfc)++; + } +econf_free (keys); + } + +econf_free (key_file); +return ; +} +#endif +static void load_checks (char *pc[],int *npc,char *fc[],int *nfc) { +#ifdef VENDORDIR +load_checks_with_vendor_settings (pc, npc, fc, nfc); +return ; +#endif FILE *fp =fopen (CONF ,"r" );char buf[255 ], *bufp;int buf_len, section =-1 ;policycoreutils/sestatus/sestatus.conf.5 +1
-2@@ -8,7 +8,7 @@ The \fIsestatus.conf\fR file is used by the \fBsestatus\fR(8) command with the \ .sp The fully qualified path name of the configuration file is: .RS -\fI/etc/sestatus.conf\fR +\fI/etc/sestatus.conf\fR or \fI<vendordir>/sestatus.conf\fR if it is not available .RE .RE .sp --2.55.0