Skip to contentSkip to conversation

setfiles patch

DISCUSSION Russell Coker 2 participants 3 messages Apr 18, 2002 – Apr 19, 2002 SELinux security module

lore
Share & tools
lore
#0 lore raw

Right, thanks for the advice.

I have relised my mistake, I was over-riding those CFLAGS in my build
process.

I have attached my latest patch which just adds a "-s" switch for taking file names from standard input and a "-m" switch to not display the missed regular expressions afterwards.

Actually maybe it should be the other way around, use a "-m" if you want to see the unmatched regex's - they don't seem very useful to me.

Sorry, forgot the patch on the last message.

setfiles/setfiles.8 +64 -0
@@ -0,0 +1,64 @@
+.TH "setfiles" "8" "2002031409" "" ""
+.SH "NAME"
+setfiles \- initialise the SIDs on a partition.
+
+.SH "SYNOPSIS"
+.B setfiles
+.I [\-d] [\-n] [\-v] [\-m] [\-s] [\-R] spec_file pathname [more paths]
+
+.SH "DESCRIPTION"
+This manual page documents briefly the
+.BR setfiles ,
+program.
+.P
+This program is primarily used to initialise the security context database on
+a filesystem.  This will be run as part of the SE Linux installation process.
+.P
+It can also be run at any time to correct errors, to add support for new policy,
+or with the \-n option it can just check whether the file contexts are all as
+you expect.
+
+.SH "OPTIONS"
+.TP 
+.B \-d
+show what specification matched each file.
+.TP 
+.B \-n
+don't change any file labels.
+.TP 
+.B \-v
+show changes in file labels.
+.TP 
+.B \-m
+don't warn about specifications that don't match any files.
+.TP 
+.B \-s
+take a list of files from standard input instead of using a pathname on the
+command line.
+.TP 
+.B \-R
+recreate the persistent label mappings from scratch.
+Must reboot to take affect.
+.TP 
+.B spec_file
+the specification file which contains lines of the following form
+.B regexp [ \-type ] ( context | <<none>> )
+The regular expression is anchored at both ends.  The type field will contain
+\-\- or \-d for whether you want to match regular files or directories.  The
+context can be a regular SE security context of the string <<none>> to specify
+that the file is not to have it's context changed.
+.BR 
+The last matching specification is used.
+.TP 
+.B pathname
+is the root of a file system that is to be checked. Not used if the
+.B \-s
+parameter is used.
+
+.SH "AUTHOR"
+This man page, was written by Russell Coker <[email protected]>.
+The program was written by Stephen Smalley, NAI Labs <[email protected]>
+
+.SH "SEE ALSO"
+.BR load_policy (8),
+.BR checkpolicy (8)
setfiles/setfiles.c +78 -3

133 lines not on this page · raw message

#1 lore raw
Quoted 6 lines · Russell Coker

I have attached my latest patch which just adds a "-s" switch for taking file names from standard input and a "-m" switch to not display the missed regular expressions afterwards.

Actually maybe it should be the other way around, use a "-m" if you want to see the unmatched regex's - they don't seem very useful to me.

I've merged this support, but with a number of modifications. See the attached complete setfiles.c and setfiles.8 files. Explanations and descriptions of my changes below:

1) The processing for the standard input option (-s) doesn't work well when run with the reset option (-R) or when run on a non-SELinux kernel. In those cases, setfiles needs the pathname of the root directory of the filesystem in order to directly access the persistent label mappings. The original patch would end up dereferencing nulls if no pathname argument was specified in those cases, and if you did specify a pathname argument, there was no guarantee that it had any real relationship to the files in the input list. Unless you want to reconstruct the root directory pathname for the filesystem for each file in the list and use it, this just won't work. Hence, I've added explicit tests to ensure that people do not try to use -s with pathname arguments, the -R option, or on a non-SELinux kernel, and removed the extraneous code from the standard input processing.

2) When using the -s option, the existing hash table of associations between inodes and specifications can't be used safely because it only maintains the inode number, not the device. This is fine for the normal case, because the table is constructed for each filesystem and is then reset for the next filesystem, so inode numbers are sufficient to uniquely identify entries. But there is no guarantee that the input list of file names will be within a single filesystem. The associations are only necessary if we want to detect conflicts for multiple hard links. For the moment, I've simply modified setfiles to not maintain or use the associations when running with -s. If we want this functionality with -s, then we'll need to extend the hash table to also use the device number (or force the input list to be within a single filesystem).

3) The default is now "no warnings", as you suggested. If you want warnings, use the new -W option. The -m option is currently accepted by getopt (but does nothing now) for compatibility, but I can remove it if/when you update your packages.

4) I made minor revisions to the man page.

--
Stephen D. Smalley, NAI Labs
[email protected]

/*
* setfiles
*
* AUTHOR: Stephen Smalley, NAI Labs <[email protected]>
* This program was derived in part from the setfiles.pl script
* developed by Secure Computing Corporation.
*
* PURPOSE:
* This program reads a set of file security context specifications
* based on pathname regular expressions and labels files
* accordingly, traversing a set of file systems specified by
* the user. The program does not cross file system boundaries. *
* USAGE:
* setfiles [-dnsvRW] spec_file pathname...
*
* -d Show what specification matched each file.
* -n Do not change any file labels.
* -s Use stdin for a list of files instead of searching a partition.
* -v Show changes in file labels.

 * -R   Recreate the persistent label mappings from scratch.
 *      Must reboot to take affect.
 * -W   Warn about entries that have no matching file.

* spec_file The specification file.
* pathname... The file systems to label.
*
* EXAMPLE USAGE:
* ./setfiles -v file_contexts mount | awk '/ext2/{print $3}' *
* SPECIFICATION FILE:
* Each specification has the form:
* regexp [ -type ] ( context | <<none>> )
*
* By default, the regexp is an anchored match on both ends (i.e. a
* caret (^) is prepended and a dollar sign ($) is appended automatically).
* This default may be overridden by using .* at the beginning and/or
* end of the regular expression.
*
* The optional type field specifies the file type as shown in the mode
* field by ls, e.g. use -d to match only directories or -- to match only
* regular files.
*
* The value of <<none> may be used to indicate that matching files
* should not be relabeled.
*
* The last matching specification is used.
*
* If there are multiple hard links to a file that match
* different specifications and those specifications indicate
* different security contexts, then a warning is displayed
* but the file is still labeled based on the last matching
* specification other than <<none>>.
*/

#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <ctype.h>
#include <regex.h>
#include <sys/vfs.h>
#define __USE_XOPEN_EXTENDED 1 /* nftw */
#include <ftw.h>
#include <flask_util.h>
#include <fs_secure.h>
#include <ss.h>
#include "psid.h"
#include <limits.h>

struct psidtab *psids;

#define FILE_CONTEXT "system_u:object_r:file_t"
#define FS_CONTEXT "system_u:object_r:fs_t"

static int flask_enabled = 0;
static int add_assoc = 1;

/*
* Command-line options.
*/
static int change = 1;
static int warn_no_match = 0;
static int debug = 0;
static int verbose = 0;
static int reset = 0;
static int use_stdin = 0;

/*
* Program name and error message buffer.
*/
static char *progname;
static char errbuf[255 + 1];

/*
* A file security context specification.
*/
typedef struct spec {
char *regex_str; /* regular expession string for diagnostic messages */
char *type_str; /* type string for diagnostic messages */
char *context; /* context string */
regex_t regex; /* compiled regular expression */
mode_t mode; /* mode format value */
security_id_t sid; /* SID */
int matches; /* number of matching pathnames */
} spec_t;

/*
* The array of specifications, in the
* same order as in the specification file.
*/
static spec_t *spec;
static int nspec;

/*
* An association between an inode and a
* specification.
*/
typedef struct file_spec {
ino_t ino; /* inode number */
int specind; /* index of specification in spec */
char *file; /* full pathname for diagnostic messages about conflicts */
struct file_spec *next; /* next association in hash bucket chain */
} file_spec_t;

/*
* The hash table of associations, hashed by inode number.
* Chaining is used for collisions, with elements ordered
* by inode number in each bucket. Each hash bucket has a dummy
* header.
*/
#define HASH_BITS 16
#define HASH_BUCKETS (1 << HASH_BITS)
#define HASH_MASK (HASH_BUCKETS-1)
static file_spec_t fl_head[HASH_BUCKETS];

/*
* Try to add an association between an inode and
* a specification. If there is already an association
* for the inode and it conflicts with this specification,
* then use the specification that occurs later in the
* specification array.
*/
static file_spec_t *file_spec_add(ino_t ino, int specind, const char *file)

{
	file_spec_t *prevfl, *fl;
	int h, no_conflict;

	h = (ino + (ino >> HASH_BITS)) & HASH_MASK;
	for (prevfl = &fl_head[h], fl = fl_head[h].next; fl;
	     prevfl = fl, fl = fl->next) {
		if (ino == fl->ino) {
			if (flask_enabled) 
				no_conflict = (spec[fl->specind].sid == spec[specind].sid);
			else
				no_conflict = (strcmp(spec[fl->specind].context,spec[specind].context) == 0);
			if (no_conflict)
				return fl;

			fprintf(stderr,
				"%s:  conflicting specifications for %s and %s, using %s.\n",
				progname, file, fl->file,
				((specind > fl->specind) ? spec[specind].
				 context : spec[fl->specind].context));
			fl->specind =
			    (specind >
			     fl->specind) ? specind : fl->specind;
			free(fl->file);
			fl->file = malloc(strlen(file) + 1);
			if (!fl->file) {
				fprintf(stderr,
					"%s:  insufficient memory for file label entry for %s\n",
					progname, file);
				return NULL;
			}
			strcpy(fl->file, file);
			return fl;
		}

		if (ino > fl->ino)
			break;
	}

	fl = malloc(sizeof(file_spec_t));
	if (!fl) {
		fprintf(stderr,
			"%s:  insufficient memory for file label entry for %s\n",
			progname, file);
		return NULL;
	}
	fl->ino = ino;
	fl->specind = specind;
	fl->file = malloc(strlen(file) + 1);
	if (!fl->file) {
		fprintf(stderr,
			"%s:  insufficient memory for file label entry for %s\n",
			progname, file);
		return NULL;
	}
	strcpy(fl->file, file);
	fl->next = prevfl->next;
	prevfl->next = fl;
	return fl;
}

/*
* Evaluate the association hash table distribution. */
static void file_spec_eval(void)

{
	file_spec_t *fl;
	int h, used, nel, len, longest;

	used = 0;
	longest = 0;
	nel = 0;
	for (h = 0; h < HASH_BUCKETS; h++) {
		len = 0;
		for (fl = fl_head[h].next; fl; fl = fl->next) {
			len++;
		}
		if (len)
			used++;
		if (len > longest)
			longest = len;
		nel += len;
	}

	printf
	    ("%s:  hash table stats: %d elements, %d/%d buckets used, longest chain length %d\n",
	     progname, nel, used, HASH_BUCKETS, longest);
}

/*
* Destroy the association hash table.
*/
static void file_spec_destroy(void)

{
	file_spec_t *fl, *tmp;
	int h;

	for (h = 0; h < HASH_BUCKETS; h++) {
		fl = fl_head[h].next;
		while (fl) {
			tmp = fl;
			fl = fl->next;
			free(tmp->file);
			free(tmp);
		}
		fl_head[h].next = NULL;
	}
}

int match(const char *name, struct stat *sb, security_id_t *out_sid)

{
	int i, ret;

	if (flask_enabled) {
		ret = lstat_secure(name, sb, out_sid);
	} else {
		ret = lstat(name, sb);
	} 
	if (ret) {
		fprintf(stderr, "%s:  unable to stat file %s\n", progname,
			name);
		return -1;
	}

	/* 
	 * Check for matching specifications in reverse order, so that
	 * the last matching specification is used.
	 */
	for (i = nspec - 1; i >= 0; i--) {
		ret = regexec(&spec[i].regex, name, 0, NULL, 0);
		if (ret == 0 &&
		    (!spec[i].mode
		     || (sb->st_mode & S_IFMT) == spec[i].mode)) break;
		if (ret) {
			if (ret == REG_NOMATCH)
				continue;
			regerror(ret, &spec[i].regex, errbuf,
				 sizeof errbuf);
			fprintf(stderr,
				"%s:  unable to match %s against %s:  %s\n",
				progname, name, spec[i].regex_str,
				errbuf);
			return -1;
		}
	}

	if (i < 0)
		/* No matching specification. */
		return -1;

	spec[i].matches++;

	return i;
}

#define SZ 255

/*
* Apply the last matching specification to a file.
* This function is called by nftw on each file during
* the directory traversal.
*/
static int apply_spec(const char *file,
const struct stat *sb, int flag, struct FTW *s)

{
	const char *my_file;
	file_spec_t *fl;
	struct stat my_sb;
	security_id_t sid;
	int i, len, ret;
	char *context;

	/* Skip the extra slash at the beginning, if present. */
	if (file[0] == '/' && file[1] == '/')
		my_file = &file[1];
	else
		my_file = file;

	if (flag == FTW_DNR) {
		fprintf(stderr, "%s:  unable to read directory %s\n",
			progname, my_file);
		return 0;
	}

	i = match(my_file, &my_sb, &sid);
	if (i < 0)
		/* No matching specification. */
		return 0;

	/*
	 * Try to add an association between this inode and
	 * this specification.  If there is already an association
	 * for this inode and it conflicts with this specification,
	 * then use the last matching specification.
	 */
	if (add_assoc) {
		fl = file_spec_add(my_sb.st_ino, i, my_file);
		if (!fl)
			/* Insufficient memory to proceed. */
			return 1;

		if (fl->specind != i)
			/* There was already an association and it took precedence. */
			return 0;
	}

	if (debug) {
		if (spec[i].type_str) {
			printf("%s:  %s matched by (%s,%s,%s)\n", progname,
			       my_file, spec[i].regex_str,
			       spec[i].type_str, spec[i].context);
		} else {
			printf("%s:  %s matched by (%s,%s)\n", progname,
			       my_file, spec[i].regex_str,
			       spec[i].context);
		}
	}

	/* Get the current SID or context of the file. */
	if (flask_enabled) {
		if (lstat_secure(my_file, &my_sb, &sid)) {
			fprintf(stderr, "%s:  unable to stat file %s\n", progname,
				my_file);
			return 0;
		}
	} else {
		context = psid_to_context(psids, my_sb.st_ino);
		if (!context) {
			fprintf(stderr, "%s:  unable to obtain context of %s\n", progname,
				my_file);
			return 0;
		}
	}

	/*
	 * Do not relabel the file if the matching specification is 
	 * <<none>> or the file is already labeled according to the 
	 * specification.
	 */
	if (flask_enabled) {
		if (!spec[i].sid || sid == spec[i].sid)
			return 0;
	} else {
		if ((strcmp(spec[i].context, "<<none>>") == 0) || 
		    (strcmp(context,spec[i].context) == 0))
			return 0;
	}

	if (verbose) {
		if (flask_enabled) {
			context = malloc(SZ);
			if (!context) {
				fprintf(stderr,
					"%s:  insufficient memory for context for %s\n",
					progname, my_file);
				return 1;
			}
			len = SZ;
			ret = security_sid_to_context(sid, context, &len);
			if (ret && (len > SZ)) {
				context = realloc(context, len);
				if (!context) {
					fprintf(stderr,
						"%s:  insufficient memory for context for %s\n",
						progname, my_file);
					return 1;
				}
				ret =
				    security_sid_to_context(sid, context,
							    &len);
			}
			if (ret) {
				fprintf(stderr,
					"%s:  unable to obtain context for SID %d on file %s\n",
					progname, sid, my_file);
				return 1;
			}
		}
		printf("%s:  relabeling %s from %s to %s\n", progname,
		       my_file, context, spec[i].context);
	}

	/*
	 * Do not relabel the file if -n was used.
	 */
	if (!change)
		return 0;

	/*
	 * Relabel the file to the specified context.
	 */
	if (flask_enabled) 
		ret = lchsid(my_file, spec[i].sid);
	else 
		ret = context_to_psid(psids, my_sb.st_ino, spec[i].context);
	if (ret) {
		if (flask_enabled)
			perror(my_file);
		fprintf(stderr, "%s:  unable to relabel %s to %s\n",
			progname, my_file, spec[i].context);
		return 1;
	}

	return 0;
}

int main(int argc, char **argv)

{
	FILE *fp;
	char buf[255 + 1], *buf_p;
	char *regex, *type, *context;
	char *anchored_regex;
	char pathname[1024];
	int opt, items, len, lineno, pass, nerr, regerr, i;
	security_id_t sid;
	struct stat sb;

	/* Process any options. */
	while ((opt = getopt(argc, argv, "dmnsvRW")) > 0) {
		switch (opt) {
		case 'd':
			debug = 1;
			break;
		case 'm':
			/* This is now the default. 
			   Accept it for compatibility. */
			break;
		case 'W':
			warn_no_match = 1;
			break;
		case 'n':
			change = 0;
			break;
		case 'v':
			verbose = 1;
			break;
		case 'R':
			reset = 1;
			break;
		case 's':
			use_stdin = 1;
			add_assoc = 0;
			break;
		}
	}

	flask_enabled = is_flask_enabled();

	if (use_stdin) {
		if (optind != (argc - 1) || reset) {
			/* Cannot mix with pathname arguments or -R option. */
			fprintf(stderr,
				"usage:  %s [-dnsvW] spec_file\n", argv[0]);
			exit(1);
		}
		if (!flask_enabled) {
			/* Doesn't work on non-SELinux kernels. */
			fprintf(stderr,
				"%s:  The -s option can only be used on SELinux.\n", argv[0]);
			exit(1);
		}
	} else {
		if (optind > (argc - 2)) {
			fprintf(stderr,
				"usage:  %s [-dnvRW] spec_file pathname...\n",
				argv[0]);
			exit(1);
		}
	}

	if (reset) {
		printf("%s:  Recreating persistent label mappings from scratch.\n", argv[0]);
                /* Do not use the new syscalls, even if running on SELinux,
		   since they will access the old persistent label mappings. */
		flask_enabled = 0; 
	} else {
		if (flask_enabled) 
			printf("%s:  Running on a SELinux kernel, using new system calls\n", argv[0]);
		else 
			printf("%s:  Running on a non-SELinux kernel, directly accessing persistent label mapping\n", argv[0]);
	}

	/* Open the specification file. */
	if ((fp = fopen(argv[optind], "r")) == NULL) {
		perror(argv[optind]);
		exit(1);
	}
	optind++;

	/* 
	 * Perform two passes over the specification file.
	 * The first pass counts the number of specifications and
	 * performs simple validation of the input.  At the end
	 * of the first pass, the spec array is allocated.
	 * The second pass performs detailed validation of the input
	 * and fills in the spec array.
	 */
	for (pass = 0; pass < 2; pass++) {
		lineno = 0;
		nspec = 0;
		nerr = 0;
		while (fgets(buf, sizeof buf, fp)) {
			lineno++;
			len = strlen(buf);
			if (buf[len - 1] != '\n') {
				fprintf(stderr,
					"%s:  no newline on line number %d (only read %s)\n",
					argv[0], lineno, buf);
				nerr++;
				continue;
			}
			buf[len - 1] = 0;
			buf_p = buf;
			while (isspace(*buf_p))
				buf_p++;
			/* Skip comment lines and empty lines. */
			if (*buf_p == '#' || *buf_p == 0)
				continue;
			items =
			    sscanf(buf, "%as %as %as", &regex, &type,
				   &context);
			if (items < 2) {
				fprintf(stderr,
					"%s:  line number %d is missing fields (only read %s)\n",
					argv[0], lineno, buf);
				nerr++;
				if (items == 1)
					free(regex);
				continue;
			} else if (items == 2) {
				/* The type field is optional. */
				free(context);
				context = type;
				type = 0;
			}

			if (pass == 1) {
				/* On the second pass, compile and store the specification in spec. */
				spec[nspec].regex_str = regex;

				/* Anchor the regular expression. */
				len = strlen(regex);
				anchored_regex = malloc(len + 3);
				if (!anchored_regex) {
					fprintf(stderr,
						"%s:  insufficient memory for anchored regexp on line %d\n",
						argv[0], lineno);
					exit(1);
				}
				sprintf(anchored_regex, "^%s$", regex);

				/* Compile the regular expression. */
				regerr =
				    regcomp(&spec[nspec].regex,
					    anchored_regex,
					    REG_EXTENDED | REG_NOSUB);
				if (regerr < 0) {
					regerror(regerr,
						 &spec[nspec].regex,
						 errbuf, sizeof errbuf);
					fprintf(stderr,
						"%s:  unable to compile regular expression %s on line number %d:  %s\n",
						argv[0], regex, lineno,
						errbuf);
					nerr++;
				}
				free(anchored_regex);

				/* Convert the type string to a mode format */
				spec[nspec].type_str = type;
				spec[nspec].mode = 0;
				if (!type)
					goto skip_type;
				len = strlen(type);
				if (type[0] != '-' || len != 2) {
					fprintf(stderr,
						"%s:  invalid type specifier %s on line number %d\n",
						argv[0], type, lineno);
					nerr++;
					goto skip_type;
				}
				switch (type[1]) {
				case 'b':
					spec[nspec].mode = S_IFBLK;
					break;
				case 'c':
					spec[nspec].mode = S_IFCHR;
					break;
				case 'd':
					spec[nspec].mode = S_IFDIR;
					break;
				case 'p':
					spec[nspec].mode = S_IFIFO;
					break;
				case 'l':
					spec[nspec].mode = S_IFLNK;
					break;
				case 's':
					spec[nspec].mode = S_IFSOCK;
					break;
				case '-':
					spec[nspec].mode = S_IFREG;
					break;
				default:
					fprintf(stderr,
						"%s:  invalid type specifier %s on line number %d\n",
						argv[0], type, lineno);
					nerr++;
				}

			      skip_type:

				spec[nspec].context = context;
				if (flask_enabled) {
					if (strcmp(context, "<<none>>") == 0) {
						spec[nspec].sid = 0;
					} else {
						len = strlen(context);
						if (security_context_to_sid
						    (context, len + 1,
						     &spec[nspec].sid)) {
							fprintf(stderr,
								"%s:  invalid context %s on line number %d\n",
								argv[0], context,
								lineno);
							nerr++;
						}
					}
				}
			}

			nspec++;
			if (pass == 0) {
				free(regex);
				if (type)
					free(type);
				free(context);
			}
		}

		if (nerr)
			exit(1);

		if (pass == 0) {
			printf("%s:  read %d specifications\n", argv[0],
			       nspec);
			if (nspec == 0)
				exit(0);
			if ((spec = malloc(sizeof(spec_t) * nspec)) ==
			    NULL) {
				fprintf(stderr,
					"%s:  insufficient memory for specifications\n",
					argv[0]);
				exit(1);
			}
			bzero(spec, sizeof(spec_t) * nspec);
			rewind(fp);
		}
	}
	fclose(fp);

	/*
	 * Apply the specifications to the file systems.
	 */
	progname = argv[0];
	if(use_stdin)
	{
		char buf[PATH_MAX];
		while(fgets(buf, sizeof(buf), stdin))
		{
			struct stat sb;
			strtok(buf, "\n");
			if(buf[0] != '\n')
			{
				if(stat(buf, &sb))
					fprintf(stderr, "File \"%s\" not found.\n", buf);
				else
				{
					int flag;
					switch(sb.st_mode)
					{
					case S_IFDIR:
						flag = FTW_D;
					break;
					case S_IFLNK:
						flag = FTW_SL;
					break;
					default:
						flag = FTW_F;
					}
					apply_spec(buf, &sb, flag, NULL);
				}
			}
		}
	}
	else for (; optind < argc; optind++)
	{

		if (flask_enabled) {
			printf("%s:  labeling files under %s\n", argv[0],
			       argv[optind]);
		} else {
			sprintf(pathname, "%s/%s", argv[optind], ".");
			i = match(pathname, &sb, &sid);
			if (i < 0) 
				context = FILE_CONTEXT;
			else
				context = spec[i].context;

			printf("%s:  labeling files under %s (default file context %s)\n", argv[0],
			       argv[optind], context);

			psids = psidtab_init(argv[optind], context, FS_CONTEXT, reset);
			if (psids == NULL) {
				fprintf(stderr,
					"%s:  unable to initialize PSID mapping for %s\n",
					argv[0], argv[optind]);
				exit(1);
			}
		}
		
		/* Walk the file tree, calling apply_spec on each file. */
		if (nftw
		    (argv[optind], apply_spec, 1024,
		     FTW_PHYS | FTW_MOUNT)) {
			fprintf(stderr,
				"%s:  error while labeling files under %s\n",
				argv[0], argv[optind]);
			exit(1);
		}

		if (!flask_enabled)
			psidtab_destroy(psids);

		/*
		 * Evaluate the association hash table distribution for the
		 * directory tree just traversed.
		 */
		file_spec_eval();

		/* Reset the association hash table for the next directory tree. */
		file_spec_destroy();
	}

	if (warn_no_match) {
		for (i = 0; i < nspec; i++) {
			if (spec[i].matches == 0) {
				if (spec[i].type_str) {
					printf
						("%s:  Warning!  No matches for (%s, %s, %s)\n",
						 argv[0], spec[i].regex_str,
						 spec[i].type_str, spec[i].context);
				} else {
					printf
						("%s:  Warning!  No matches for (%s, %s)\n",
						 argv[0], spec[i].regex_str,
						 spec[i].context);
				}
			}
		}
	}

	if (!flask_enabled) {
		printf("%s:  Done.  Please %sboot your SELinux kernel and then run 'make relabel' to relabel any files that were created during the shutdown.\n", argv[0], reset ? "re" : "");
	} else {
		printf("%s:  Done.\n", argv[0]);
	}

	exit(0);
}

.TH "setfiles" "8" "2002031409" "" ""
.SH "NAME"
setfiles \- set file security contexts.

.SH "SYNOPSIS"
.B setfiles
.I [\-d] [\-n] [\-s] [\-v] [\-R] [\-W] spec_file pathname...

.SH "DESCRIPTION"
This manual page describes the
.BR setfiles
program.
.P
This program is primarily used to initialise the security context database (persistent label mapping) on one or more filesystems. This program is initially run as part of the SE Linux installation process. .P
It can also be run at any time to correct errors, to add support for new policy, or with the \-n option it can just check whether the file contexts are all as you expect.

.SH "OPTIONS"
.TP
.B \-d
show what specification matched each file.
.TP
.B \-n
don't change any file labels.
.TP
.B \-s
take a list of files from standard input instead of using a pathname on the command line.
.TP
.B \-v
show changes in file labels.
.TP
.B \-R
recreate the persistent label mappings from scratch.
Must reboot to take affect.
.TP
.B \-W
display warnings about entries that had no matching files.

.SH "ARGUMENTS"
.B spec_file
The specification file which contains lines of the following form .br
.B regexp [ \-type ] ( context | <<none>> )
.br
The regular expression is anchored at both ends. The optional type field specifies the file type as shown in the mode field by the
.B ls(1)
program, e.g. \-\- to match only regular files or \-d to match only directories. The context can be an ordinary security context or the string <<none>> to specify that the file is not to have its context changed.
.br
The last matching specification is used. If there are multiple hard links to a file that match different specifications and those specifications indicate different security contexts, then a warning is displayed but the file is still labeled based on the last matching specification other than <<none>>.
.TP
.B pathname...
The pathname for the root directory of each file system to be relabeled. Not used if the
.B \-s
option is used.

.SH "AUTHOR"
This man page was written by Russell Coker <[email protected]>. The program was written by Stephen Smalley, NAI Labs <[email protected]>

.SH "SEE ALSO"
.BR load_policy (8),
.BR checkpolicy (8)

#2 lore raw
Quoted 3 lines · Stephen Smalley

I've merged this support, but with a number of modifications. See the attached complete setfiles.c and setfiles.8 files. Explanations and descriptions of my changes below:

That's all great. I've just uploaded a new Debian package containing it.

Quoted 4 lines

3) The default is now "no warnings", as you suggested. If you want warnings, use the new -W option. The -m option is currently accepted by getopt (but does nothing now) for compatibility, but I can remove it if/when you update your packages.

I've removed the -m option from my tree.

I just realised that I forgot to update the Makefile to match. I'll upload a new version tomorrow morning.

Signature · 9 lines
If you send email to me or to a mailing list that I use which has >4 lines
of legalistic junk at the end then you are specifically authorizing me to do
whatever I wish with the message and all other messages from your domain, by
posting the message you agree that your long legalistic sig is void.

--
You have received this message because you are subscribed to the selinux list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.