Skip to content

Commit 1e6fbb6

Browse files
committed
Using vendor defined directories for configuration files besides user/admin defined configuration files.
1 parent 97fa708 commit 1e6fbb6

File tree

4 files changed

+90
-5
lines changed

4 files changed

+90
-5
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@ This may render your system unusable if the upstream SELinux userspace
135135
lacks library functions or other dependencies relied upon by your
136136
distribution. If it breaks, you get to keep both pieces.
137137

138+
A directory for distribution provided configuration files (in e.g. /usr/etc) can be set by:
139+
140+
make VENDORDIR=/usr/etc
141+
142+
If distribution provided configuration files are used, the library libeconf is
143+
needed for parsing these files in the correct order.
138144

139145
## Setting CFLAGS
140146

policycoreutils/sestatus/Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ BINDIR ?= $(PREFIX)/bin
55
SBINDIR ?= $(PREFIX)/sbin
66
MANDIR = $(PREFIX)/share/man
77
ETCDIR ?= /etc
8+
LIBECONFH ?= $(shell test -f /usr/include/libeconf.h && echo y)
89

910
CFLAGS ?= -Werror -Wall -W
1011
override CFLAGS += -D_FILE_OFFSET_BITS=64
@@ -13,6 +14,13 @@ override LDLIBS += -lselinux
1314
all: sestatus
1415

1516
sestatus: sestatus.o
17+
ifdef VENDORDIR
18+
ifneq ($(LIBECONFH), y)
19+
(echo "VENDORDIR defined but libeconf not available."; exit 1)
20+
endif
21+
override CFLAGS += -DVENDORDIR='"${VENDORDIR}"'
22+
override LDLIBS += -leconf
23+
endif
1624

1725
install: all
1826
[ -d $(DESTDIR)$(MANDIR)/man8 ] || mkdir -p $(DESTDIR)$(MANDIR)/man8

policycoreutils/sestatus/sestatus.c

Lines changed: 75 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,16 @@
2121

2222
#define PROC_BASE "/proc"
2323
#define MAX_CHECK 50
24-
#define CONF "/etc/sestatus.conf"
24+
#define CONFDIR "/etc"
25+
#define CONFNAME "sestatus"
26+
#define CONFPOST "conf"
27+
#define CONF CONFDIR "/" CONFNAME "." CONFPOST
2528

2629
/* conf file sections */
27-
#define PROCS "[process]"
28-
#define FILES "[files]"
30+
#define SECTIONPROCS "process"
31+
#define SECTIONFILES "files"
32+
#define PROCS "[" SECTIONPROCS "]"
33+
#define FILES "[" SECTIONFILES "]"
2934

3035
/* buffer size for cmp_cmdline */
3136
#define BUFSIZE 255
@@ -92,9 +97,75 @@ static int pidof(const char *command)
9297
return ret;
9398
}
9499

95-
static void load_checks(char *pc[], int *npc, char *fc[], int *nfc)
100+
#ifdef VENDORDIR
101+
#include <libeconf.h>
102+
103+
static void load_checks_with_vendor_settings(char *pc[], int *npc, char *fc[], int *nfc)
96104
{
105+
econf_file *key_file = NULL;
106+
econf_err error;
107+
char **keys;
108+
size_t key_number;
109+
110+
error = econf_readDirs (&key_file,
111+
VENDORDIR,
112+
CONFDIR,
113+
CONFNAME,
114+
CONFPOST,
115+
"", "#");
116+
if (error != ECONF_SUCCESS) {
117+
printf("\nCannot read settings %s.%s: %s\n",
118+
CONFNAME,
119+
CONFPOST,
120+
econf_errString( error ));
121+
return;
122+
}
123+
124+
error = econf_getKeys(key_file, SECTIONPROCS, &key_number, &keys);
125+
if (error != ECONF_SUCCESS) {
126+
printf("\nCannot read group %s: %s\n",
127+
SECTIONPROCS,
128+
econf_errString( error ));
129+
} else {
130+
for (size_t i = 0; i < key_number; i++) {
131+
if (*npc >= MAX_CHECK)
132+
break;
133+
pc[*npc] = strdup(keys[i]);
134+
if (!pc[*npc])
135+
break;
136+
(*npc)++;
137+
}
138+
econf_free (keys);
139+
}
140+
141+
error = econf_getKeys(key_file, SECTIONFILES, &key_number, &keys);
142+
if (error != ECONF_SUCCESS) {
143+
printf("\nCannot read group %s: %s\n",
144+
SECTIONFILES,
145+
econf_errString( error ));
146+
} else {
147+
for (size_t i = 0; i < key_number; i++) {
148+
if (*nfc >= MAX_CHECK)
149+
break;
150+
fc[*nfc] = strdup(keys[i]);
151+
if (!fc[*nfc])
152+
break;
153+
(*nfc)++;
154+
}
155+
econf_free (keys);
156+
}
97157

158+
econf_free (key_file);
159+
return;
160+
}
161+
#endif
162+
163+
static void load_checks(char *pc[], int *npc, char *fc[], int *nfc)
164+
{
165+
#ifdef VENDORDIR
166+
load_checks_with_vendor_settings(pc, npc, fc, nfc);
167+
return;
168+
#endif
98169
FILE *fp = fopen(CONF, "r");
99170
char buf[255], *bufp;
100171
int buf_len, section = -1;

policycoreutils/sestatus/sestatus.conf.5

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ The \fIsestatus.conf\fR file is used by the \fBsestatus\fR(8) command with the \
88
.sp
99
The fully qualified path name of the configuration file is:
1010
.RS
11-
\fI/etc/sestatus.conf\fR
11+
\fI/etc/sestatus.conf\fR or \fI<vendordir>/sestatus.conf\fR if it is not available
1212
.RE
1313
.RE
1414
.sp

0 commit comments

Comments
 (0)