2011-09-02 12:58:11 +00:00
diff --git a/libselinux/man/man3/matchpathcon.3 b/libselinux/man/man3/matchpathcon.3
index cdbb252..0cc2268 100644
--- a/libselinux/man/man3/matchpathcon.3
+++ b/libselinux/man/man3/matchpathcon.3
@@ -8,7 +8,7 @@ matchpathcon, matchpathcon_index \- get the default SELinux security context for
.BI "int matchpathcon_init(const char *" path ");"
-.BI "int matchpathcon_init_prefix(const char *" path ", const char *" subset ");"
+.BI "int matchpathcon_init_prefix(const char *" path ", const char *" prefix ");"
.BI "int matchpathcon_fini(void);"
.sp
@@ -48,7 +48,7 @@ is the same as
but only loads entries with regular expressions that have stems prefixed
by
.I prefix.
-
+prefix can have multiple paths separated by ";", for example "/dev;/var/run;/tmp"
.sp
.B matchpathcon_fini
frees the memory allocated by a prior call to
diff --git a/libselinux/man/man3/selabel_open.3 b/libselinux/man/man3/selabel_open.3
index 8674e37..23df23b 100644
--- a/libselinux/man/man3/selabel_open.3
+++ b/libselinux/man/man3/selabel_open.3
@@ -66,6 +66,13 @@ A non-null value for this option enables context validation. By default,
is used; a custom validation function can be provided via
.BR selinux_set_callback (3).
Note that an invalid context may not be treated as an error unless it is actually encountered during a lookup operation.
+.TP
+.B SELABEL_OPT_SUBSET
+A ";" separates string of path prefixes that tell the system to only loads entries with regular expressions that could match this strings. For example "/dev;/var/run;/tmp". This option can cause the system to use less memory and work faster, but you should only use paths that begin with a prefix.
+.TP
+.B SELABEL_OPT_PATH
+A string representing an alternate path the the regular expressions.
+.sp
.SH "BACKENDS"
@@ -99,4 +106,3 @@ Eamon Walsh <ewalsh@tycho.nsa.gov>
.BR selabel_stats (3),
.BR selinux_set_callback (3),
.BR selinux (8)
-
2010-12-21 21:29:19 +00:00
diff --git a/libselinux/src/callbacks.c b/libselinux/src/callbacks.c
index b245364..7c47222 100644
--- a/libselinux/src/callbacks.c
+++ b/libselinux/src/callbacks.c
@@ -16,6 +16,7 @@ default_selinux_log(int type __attribute__((unused)), const char *fmt, ...)
2008-07-09 20:57:21 +00:00
{
2008-07-29 13:22:45 +00:00
int rc;
va_list ap;
+ if (is_selinux_enabled() == 0) return 0;
va_start(ap, fmt);
rc = vfprintf(stderr, fmt, ap);
va_end(ap);
2011-09-02 12:58:11 +00:00
diff --git a/libselinux/src/label_file.c b/libselinux/src/label_file.c
2011-09-06 13:46:57 +00:00
index 3b8346d..ead3b0b 100644
2011-09-02 12:58:11 +00:00
--- a/libselinux/src/label_file.c
+++ b/libselinux/src/label_file.c
@@ -27,6 +27,7 @@
* Internals, mostly moved over from matchpathcon.c
*/
+#define MAX_PREFIX 100
/* A file security context specification. */
typedef struct spec {
struct selabel_lookup_rec lr; /* holds contexts for lookup result */
@@ -279,7 +280,7 @@ static int compile_regex(struct saved_data *data, spec_t *spec, char **errbuf)
static int process_line(struct selabel_handle *rec,
- const char *path, const char *prefix,
+ const char *path, const char **prefix_array,
char *line_buf, int pass, unsigned lineno)
{
int items, len;
@@ -313,12 +314,24 @@ static int process_line(struct selabel_handle *rec,
}
len = get_stem_from_spec(regex);
- if (len && prefix && strncmp(prefix, regex, len)) {
- /* Stem of regex does not match requested prefix, discard. */
- free(regex);
- free(type);
- free(context);
- return 0;
+ if (len && prefix_array[0]) {
+ int i = 0;
+ int found = 0;
+ while (i < MAX_PREFIX && prefix_array[i]) {
+ if (strncmp(prefix_array[i], regex, len) == 0) {
+ found = 1;
+ break;
+ }
+ i++;
+ }
+
+ if (! found) {
+ /* Stem of regex does not match requested prefix, discard. */
+ free(regex);
+ free(type);
+ free(context);
+ return 0;
+ }
}
if (pass == 1) {
@@ -400,7 +413,7 @@ static int init(struct selabel_handle *rec, struct selinux_opt *opts,
{
struct saved_data *data = (struct saved_data *)rec->data;
const char *path = NULL;
- const char *prefix = NULL;
+ const char *prefix_array[MAX_PREFIX] = {NULL,};
FILE *fp;
FILE *localfp = NULL;
FILE *homedirfp = NULL;
2011-09-06 13:46:57 +00:00
@@ -421,8 +434,19 @@ static int init(struct selabel_handle *rec, struct selinux_opt *opts,
2011-09-02 12:58:11 +00:00
path = opts[n].value;
break;
case SELABEL_OPT_SUBSET:
- prefix = opts[n].value;
+ {
+ char *ptr;
+ i = 0;
2011-09-06 13:46:57 +00:00
+ if (opts[n].value) {
+ prefix_array[i] = strtok_r((char *)opts[n].value, ";", &ptr);
+ while ((prefix_array[i] != NULL) && i < MAX_PREFIX - 1) {
+ i++;
+ prefix_array[i] = strtok_r(NULL, ";", &ptr);
+ }
2011-09-02 12:58:11 +00:00
+ }
+
break;
+ }
case SELABEL_OPT_BASEONLY:
baseonly = !!opts[n].value;
break;
2011-09-06 13:46:57 +00:00
@@ -481,7 +505,7 @@ static int init(struct selabel_handle *rec, struct selinux_opt *opts,
2011-09-02 12:58:11 +00:00
data->ncomp = 0;
while (getline(&line_buf, &line_len, fp) > 0
&& data->nspec < maxnspec) {
- if (process_line(rec, path, prefix, line_buf,
+ if (process_line(rec, path, prefix_array, line_buf,
pass, ++lineno) != 0)
goto finish;
}
2011-09-06 13:46:57 +00:00
@@ -495,7 +519,7 @@ static int init(struct selabel_handle *rec, struct selinux_opt *opts,
2011-09-02 12:58:11 +00:00
while (getline(&line_buf, &line_len, homedirfp) > 0
&& data->nspec < maxnspec) {
if (process_line
- (rec, homedir_path, prefix,
+ (rec, homedir_path, prefix_array,
line_buf, pass, ++lineno) != 0)
goto finish;
}
2011-09-06 13:46:57 +00:00
@@ -505,7 +529,7 @@ static int init(struct selabel_handle *rec, struct selinux_opt *opts,
2011-09-02 12:58:11 +00:00
while (getline(&line_buf, &line_len, localfp) > 0
&& data->nspec < maxnspec) {
if (process_line
- (rec, local_path, prefix, line_buf,
+ (rec, local_path, prefix_array, line_buf,
pass, ++lineno) != 0)
goto finish;
}
2010-12-21 21:29:19 +00:00
diff --git a/libselinux/src/matchpathcon.c b/libselinux/src/matchpathcon.c
2011-08-30 15:08:49 +00:00
index 9717b14..df83b30 100644
2010-12-21 21:29:19 +00:00
--- a/libselinux/src/matchpathcon.c
+++ b/libselinux/src/matchpathcon.c
2011-08-30 15:08:49 +00:00
@@ -2,6 +2,7 @@
2009-03-27 18:25:16 +00:00
#include <string.h>
#include <errno.h>
#include <stdio.h>
+#include <syslog.h>
#include "selinux_internal.h"
#include "label_internal.h"
#include "callbacks.h"
2011-08-30 15:08:49 +00:00
@@ -62,7 +63,7 @@ static void
2009-03-27 18:25:16 +00:00
{
va_list ap;
va_start(ap, fmt);
- vfprintf(stderr, fmt, ap);
+ vsyslog(LOG_ERR, fmt, ap);
va_end(ap);
}
2009-01-27 20:00:47 +00:00
2011-08-30 15:08:49 +00:00
@@ -353,7 +354,7 @@ static int symlink_realpath(const char *name, char *resolved_path)
2010-06-16 13:23:15 +00:00
2011-08-30 15:08:49 +00:00
tmp_path = strdup(name);
if (!tmp_path) {
- fprintf(stderr, "symlink_realpath(%s) strdup() failed: %s\n",
+ myprintf("symlink_realpath(%s) strdup() failed: %s\n",
name, strerror(errno));
rc = -1;
goto out;
@@ -374,21 +375,24 @@ static int symlink_realpath(const char *name, char *resolved_path)
}
2011-02-01 22:40:11 +00:00
2011-08-30 15:08:49 +00:00
if (!p) {
- fprintf(stderr, "symlink_realpath(%s) realpath() failed: %s\n",
+ myprintf("symlink_realpath(%s) realpath() failed: %s\n",
name, strerror(errno));
rc = -1;
goto out;
2011-08-18 11:09:51 +00:00
}
2011-08-30 15:08:49 +00:00
len = strlen(p);
- if (len + strlen(last_component) + 1 > PATH_MAX) {
- fprintf(stderr, "symlink_realpath(%s) failed: Filename too long \n",
+ if (len + strlen(last_component) + 2 > PATH_MAX) {
+ myprintf("symlink_realpath(%s) failed: Filename too long \n",
name);
+ errno=ENAMETOOLONG;
rc = -1;
goto out;
}
2011-02-01 22:40:11 +00:00
2011-08-30 15:08:49 +00:00
resolved_path += len;
+ strcpy(resolved_path, "/");
+ resolved_path += 1;
strcpy(resolved_path, last_component);
out:
free(tmp_path);
2011-05-25 18:25:56 +00:00
diff --git a/libselinux/utils/matchpathcon.c b/libselinux/utils/matchpathcon.c
2011-08-30 15:08:49 +00:00
index 2fa21bc..5f0a4c2 100644
2011-05-25 18:25:56 +00:00
--- a/libselinux/utils/matchpathcon.c
+++ b/libselinux/utils/matchpathcon.c
2011-08-30 15:08:49 +00:00
@@ -45,7 +45,7 @@ int printmatchpathcon(char *path, int header, int mode)
2011-05-25 18:25:56 +00:00
2011-08-18 11:09:51 +00:00
int main(int argc, char **argv)
2011-05-25 18:25:56 +00:00
{
2011-08-30 15:08:49 +00:00
- int i, init = 0, rc = 0;
+ int i, init = 0;
int header = 1, opt;
int verify = 0;
int notrans = 0;