2009-09-10 18:54:35 +00:00
|
|
|
#include "restore.h"
|
2008-08-19 19:30:36 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdio_ext.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <regex.h>
|
|
|
|
#include <sys/vfs.h>
|
|
|
|
#define __USE_XOPEN_EXTENDED 1 /* nftw */
|
|
|
|
#include <libgen.h>
|
|
|
|
#ifdef USE_AUDIT
|
|
|
|
#include <libaudit.h>
|
|
|
|
|
|
|
|
#ifndef AUDIT_FS_RELABEL
|
|
|
|
#define AUDIT_FS_RELABEL 2309
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2009-09-10 18:54:35 +00:00
|
|
|
/* cmdline opts*/
|
2008-08-19 19:30:36 +00:00
|
|
|
|
|
|
|
static char *policyfile = NULL;
|
|
|
|
static int warn_no_match = 0;
|
|
|
|
static int null_terminated = 0;
|
2009-09-10 18:54:35 +00:00
|
|
|
static struct restore_opts r_opts;
|
|
|
|
|
|
|
|
#define STAT_BLOCK_SIZE 1
|
|
|
|
|
2012-08-22 07:13:43 +00:00
|
|
|
/* setfiles will abort its operation after reaching the
|
|
|
|
* following number of errors (e.g. invalid contexts),
|
|
|
|
* unless it is used in "debug" mode (-d option).
|
|
|
|
*/
|
|
|
|
#ifndef ABORT_ON_ERRORS
|
|
|
|
#define ABORT_ON_ERRORS 10
|
|
|
|
#endif
|
2008-08-19 19:30:36 +00:00
|
|
|
|
|
|
|
#define SETFILES "setfiles"
|
|
|
|
#define RESTORECON "restorecon"
|
|
|
|
static int iamrestorecon;
|
|
|
|
|
|
|
|
/* Behavior flags determined based on setfiles vs. restorecon */
|
|
|
|
static int ctx_validate; /* Validate contexts */
|
|
|
|
static const char *altpath; /* Alternate path to file_contexts */
|
|
|
|
|
|
|
|
void usage(const char *const name)
|
|
|
|
{
|
|
|
|
if (iamrestorecon) {
|
|
|
|
fprintf(stderr,
|
2012-08-22 07:13:43 +00:00
|
|
|
"usage: %s [-iFnprRv0] [-e excludedir] [-o filename] pathname...\n"
|
|
|
|
"usage: %s [-iFnprRv0] [-e excludedir] [-o filename] -f filename\n",
|
|
|
|
name, name);
|
2008-08-19 19:30:36 +00:00
|
|
|
} else {
|
|
|
|
fprintf(stderr,
|
2012-08-22 07:13:43 +00:00
|
|
|
"usage: %s [-dilnpqvFW] [-e excludedir] [-o filename] [-r alt_root_path] spec_file pathname...\n"
|
|
|
|
"usage: %s [-dilnpqvFW] [-e excludedir] [-o filename] [-r alt_root_path] spec_file -f filename\n"
|
|
|
|
"usage: %s -s [-dilnpqvFW] [-o filename] spec_file\n"
|
|
|
|
"usage: %s -c policyfile spec_file\n",
|
|
|
|
name, name, name, name);
|
2008-08-19 19:30:36 +00:00
|
|
|
}
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int nerr = 0;
|
|
|
|
|
|
|
|
void inc_err()
|
|
|
|
{
|
|
|
|
nerr++;
|
2012-08-22 07:13:43 +00:00
|
|
|
if (nerr > ABORT_ON_ERRORS - 1 && !r_opts.debug) {
|
|
|
|
fprintf(stderr, "Exiting after %d errors.\n", ABORT_ON_ERRORS);
|
2008-08-19 19:30:36 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void set_rootpath(const char *arg)
|
|
|
|
{
|
|
|
|
int len;
|
|
|
|
|
2009-09-10 18:54:35 +00:00
|
|
|
r_opts.rootpath = strdup(arg);
|
|
|
|
if (NULL == r_opts.rootpath) {
|
|
|
|
fprintf(stderr, "%s: insufficient memory for r_opts.rootpath\n",
|
|
|
|
r_opts.progname);
|
2008-08-19 19:30:36 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* trim trailing /, if present */
|
2009-09-10 18:54:35 +00:00
|
|
|
len = strlen(r_opts.rootpath);
|
|
|
|
while (len && ('/' == r_opts.rootpath[len - 1]))
|
|
|
|
r_opts.rootpath[--len] = 0;
|
|
|
|
r_opts.rootpathlen = len;
|
2008-08-19 19:30:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int canoncon(char **contextp)
|
|
|
|
{
|
|
|
|
char *context = *contextp, *tmpcon;
|
|
|
|
int rc = 0;
|
|
|
|
|
|
|
|
if (policyfile) {
|
|
|
|
if (sepol_check_context(context) < 0) {
|
|
|
|
fprintf(stderr, "invalid context %s\n", context);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
} else if (security_canonicalize_context_raw(context, &tmpcon) == 0) {
|
|
|
|
free(context);
|
|
|
|
*contextp = tmpcon;
|
|
|
|
} else if (errno != ENOENT) {
|
|
|
|
rc = -1;
|
|
|
|
inc_err();
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef USE_AUDIT
|
2011-07-10 15:32:14 +00:00
|
|
|
static void maybe_audit_mass_relabel(int mass_relabel __attribute__((unused)),
|
|
|
|
int mass_relabel_errs __attribute__((unused)))
|
2008-08-19 19:30:36 +00:00
|
|
|
{
|
|
|
|
#else
|
2011-07-10 15:32:14 +00:00
|
|
|
static void maybe_audit_mass_relabel(int mass_relabel, int mass_relabel_errs)
|
2008-08-19 19:30:36 +00:00
|
|
|
{
|
|
|
|
int audit_fd = -1;
|
|
|
|
int rc = 0;
|
|
|
|
|
|
|
|
if (!mass_relabel) /* only audit a forced full relabel */
|
|
|
|
return;
|
|
|
|
|
|
|
|
audit_fd = audit_open();
|
|
|
|
|
|
|
|
if (audit_fd < 0) {
|
|
|
|
fprintf(stderr, "Error connecting to audit system.\n");
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = audit_log_user_message(audit_fd, AUDIT_FS_RELABEL,
|
|
|
|
"op=mass relabel", NULL, NULL, NULL, !mass_relabel_errs);
|
|
|
|
if (rc <= 0) {
|
|
|
|
fprintf(stderr, "Error sending audit message: %s.\n",
|
|
|
|
strerror(errno));
|
|
|
|
/* exit(-1); -- don't exit atm. as fix for eff_cap isn't in most kernels */
|
|
|
|
}
|
|
|
|
audit_close(audit_fd);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
struct stat sb;
|
|
|
|
int opt, i = 0;
|
|
|
|
char *input_filename = NULL;
|
|
|
|
int use_input_file = 0;
|
|
|
|
char *buf = NULL;
|
|
|
|
size_t buf_len;
|
2009-09-10 18:54:35 +00:00
|
|
|
int recurse; /* Recursive descent. */
|
2008-08-19 19:30:36 +00:00
|
|
|
char *base;
|
2011-07-10 15:32:14 +00:00
|
|
|
int mass_relabel = 0, errors = 0;
|
2009-09-10 18:54:35 +00:00
|
|
|
|
|
|
|
memset(&r_opts, 0, sizeof(r_opts));
|
|
|
|
|
|
|
|
/* Initialize variables */
|
|
|
|
r_opts.progress = 0;
|
|
|
|
r_opts.count = 0;
|
2012-02-03 16:56:39 +00:00
|
|
|
r_opts.nfile = 0;
|
2009-09-10 18:54:35 +00:00
|
|
|
r_opts.debug = 0;
|
|
|
|
r_opts.change = 1;
|
|
|
|
r_opts.verbose = 0;
|
|
|
|
r_opts.logging = 0;
|
|
|
|
r_opts.rootpath = NULL;
|
|
|
|
r_opts.rootpathlen = 0;
|
|
|
|
r_opts.outfile = NULL;
|
|
|
|
r_opts.force = 0;
|
|
|
|
r_opts.hard_links = 1;
|
2008-08-19 19:30:36 +00:00
|
|
|
|
|
|
|
altpath = NULL;
|
|
|
|
|
2009-09-10 18:54:35 +00:00
|
|
|
r_opts.progname = strdup(argv[0]);
|
|
|
|
if (!r_opts.progname) {
|
2008-08-19 19:30:36 +00:00
|
|
|
fprintf(stderr, "%s: Out of memory!\n", argv[0]);
|
|
|
|
exit(1);
|
|
|
|
}
|
2009-09-10 18:54:35 +00:00
|
|
|
base = basename(r_opts.progname);
|
2008-08-19 19:30:36 +00:00
|
|
|
|
|
|
|
if (!strcmp(base, SETFILES)) {
|
|
|
|
/*
|
|
|
|
* setfiles:
|
|
|
|
* Recursive descent,
|
|
|
|
* Does not expand paths via realpath,
|
|
|
|
* Aborts on errors during the file tree walk,
|
|
|
|
* Try to track inode associations for conflict detection,
|
|
|
|
* Does not follow mounts,
|
|
|
|
* Validates all file contexts at init time.
|
|
|
|
*/
|
|
|
|
iamrestorecon = 0;
|
|
|
|
recurse = 1;
|
2009-09-10 18:54:35 +00:00
|
|
|
r_opts.expand_realpath = 0;
|
|
|
|
r_opts.abort_on_error = 1;
|
|
|
|
r_opts.add_assoc = 1;
|
|
|
|
r_opts.fts_flags = FTS_PHYSICAL | FTS_XDEV;
|
2008-08-19 19:30:36 +00:00
|
|
|
ctx_validate = 1;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* restorecon:
|
|
|
|
* No recursive descent unless -r/-R,
|
|
|
|
* Expands paths via realpath,
|
|
|
|
* Do not abort on errors during the file tree walk,
|
|
|
|
* Do not try to track inode associations for conflict detection,
|
|
|
|
* Follows mounts,
|
|
|
|
* Does lazy validation of contexts upon use.
|
|
|
|
*/
|
2009-09-10 18:54:35 +00:00
|
|
|
if (strcmp(base, RESTORECON) && !r_opts.quiet)
|
2008-08-19 19:30:36 +00:00
|
|
|
printf("Executed with an unrecognized name (%s), defaulting to %s behavior.\n", base, RESTORECON);
|
|
|
|
iamrestorecon = 1;
|
|
|
|
recurse = 0;
|
2009-09-10 18:54:35 +00:00
|
|
|
r_opts.expand_realpath = 1;
|
|
|
|
r_opts.abort_on_error = 0;
|
|
|
|
r_opts.add_assoc = 0;
|
|
|
|
r_opts.fts_flags = FTS_PHYSICAL;
|
2008-08-19 19:30:36 +00:00
|
|
|
ctx_validate = 0;
|
|
|
|
|
|
|
|
/* restorecon only: silent exit if no SELinux.
|
|
|
|
Allows unconditional execution by scripts. */
|
|
|
|
if (is_selinux_enabled() <= 0)
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2009-07-17 14:48:31 +00:00
|
|
|
/* This must happen before getopt. */
|
2012-02-03 16:56:39 +00:00
|
|
|
r_opts.nfile = exclude_non_seclabel_mounts();
|
2009-07-17 14:48:31 +00:00
|
|
|
|
2008-08-19 19:30:36 +00:00
|
|
|
/* Process any options. */
|
2012-08-22 07:13:43 +00:00
|
|
|
while ((opt = getopt(argc, argv, "c:de:f:hilno:pqrsvFRW0")) > 0) {
|
2008-08-19 19:30:36 +00:00
|
|
|
switch (opt) {
|
|
|
|
case 'c':
|
|
|
|
{
|
|
|
|
FILE *policystream;
|
|
|
|
|
|
|
|
if (iamrestorecon)
|
|
|
|
usage(argv[0]);
|
|
|
|
|
|
|
|
policyfile = optarg;
|
|
|
|
|
|
|
|
policystream = fopen(policyfile, "r");
|
|
|
|
if (!policystream) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"Error opening %s: %s\n",
|
|
|
|
policyfile, strerror(errno));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
__fsetlocking(policystream,
|
|
|
|
FSETLOCKING_BYCALLER);
|
|
|
|
|
|
|
|
if (sepol_set_policydb_from_file(policystream) <
|
|
|
|
0) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"Error reading policy %s: %s\n",
|
|
|
|
policyfile, strerror(errno));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
fclose(policystream);
|
|
|
|
|
|
|
|
ctx_validate = 1;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'e':
|
2009-07-17 14:48:31 +00:00
|
|
|
remove_exclude(optarg);
|
Patch setfiles to only warn if add_remove fails to lstat on user initiated excludes.
On Tue, 2009-08-11 at 08:12 -0400, Daniel J Walsh wrote:
> On 08/10/2009 04:12 PM, Stephen Smalley wrote:
> > On Mon, 2009-08-10 at 16:03 -0400, Stephen Smalley wrote:
> >> On Mon, 2009-08-10 at 11:13 -0400, Daniel J Walsh wrote:
> >>> Currently in F12 if you have file systems that root can not read
> >>>
> >>> # restorecon -R -v /var/lib/libvirt/
> >>> Can't stat directory "/home/dwalsh/.gvfs", Permission denied.
> >>> Can't stat directory "/home/dwalsh/redhat", Permission denied.
> >>>
> >>> After patch
> >>>
> >>> # ./restorecon -R -v /var/lib/libvirt/
> >>
> >> But if you were to run
> >> ./restorecon -R /home/dwalsh
> >> that would try to descend into .gvfs and redhat, right?
> >>
> >> I think you want instead to ignore the lstat error if the error was
> >> permission denied and add the entry to the exclude list so that
> >> restorecon will not try to descend into it. It is ok to exclude a
> >> directory to which you lack permission. Try this:
> >
> > Also, why limit -e to only directories? Why not let the user exclude
> > individual files if they choose to do so? In which case we could drop
> > the mode test altogether, and possibly drop the lstat() call altogether?
> > Or if you truly want to warn the user about non-existent paths, then
> > take the lstat() and warning to the 'e' option processing in main()
> > instead of doing it inside of add_exclude().
> >
> I agree lets remove the directory check and warn on non existing files.
Does this handle it correctly for you?
Remove the directory check for the -e option and only apply the
existence test to user-specified entries. Also ignore permission denied
errors as it is ok to exclude a directory or file to which the caller
lacks permission.
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2009-08-11 13:33:29 +00:00
|
|
|
if (lstat(optarg, &sb) < 0 && errno != EACCES) {
|
|
|
|
fprintf(stderr, "Can't stat exclude path \"%s\", %s - ignoring.\n",
|
|
|
|
optarg, strerror(errno));
|
|
|
|
break;
|
|
|
|
}
|
2008-08-19 19:30:36 +00:00
|
|
|
if (add_exclude(optarg))
|
|
|
|
exit(1);
|
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
use_input_file = 1;
|
|
|
|
input_filename = optarg;
|
|
|
|
break;
|
|
|
|
case 'd':
|
2012-08-22 07:13:43 +00:00
|
|
|
if (iamrestorecon)
|
|
|
|
usage(argv[0]);
|
2009-09-10 18:54:35 +00:00
|
|
|
r_opts.debug = 1;
|
2008-08-19 19:30:36 +00:00
|
|
|
break;
|
|
|
|
case 'i':
|
2011-07-10 14:38:41 +00:00
|
|
|
r_opts.ignore_enoent = 1;
|
2008-08-19 19:30:36 +00:00
|
|
|
break;
|
|
|
|
case 'l':
|
2009-09-10 18:54:35 +00:00
|
|
|
r_opts.logging = 1;
|
2008-08-19 19:30:36 +00:00
|
|
|
break;
|
|
|
|
case 'F':
|
2009-09-10 18:54:35 +00:00
|
|
|
r_opts.force = 1;
|
2008-08-19 19:30:36 +00:00
|
|
|
break;
|
|
|
|
case 'n':
|
2009-09-10 18:54:35 +00:00
|
|
|
r_opts.change = 0;
|
2008-08-19 19:30:36 +00:00
|
|
|
break;
|
|
|
|
case 'o':
|
|
|
|
if (strcmp(optarg, "-") == 0) {
|
2009-09-10 18:54:35 +00:00
|
|
|
r_opts.outfile = stdout;
|
2008-08-19 19:30:36 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-09-10 18:54:35 +00:00
|
|
|
r_opts.outfile = fopen(optarg, "w");
|
|
|
|
if (!r_opts.outfile) {
|
2008-08-19 19:30:36 +00:00
|
|
|
fprintf(stderr, "Error opening %s: %s\n",
|
|
|
|
optarg, strerror(errno));
|
|
|
|
|
|
|
|
usage(argv[0]);
|
|
|
|
}
|
2009-09-10 18:54:35 +00:00
|
|
|
__fsetlocking(r_opts.outfile, FSETLOCKING_BYCALLER);
|
2008-08-19 19:30:36 +00:00
|
|
|
break;
|
|
|
|
case 'q':
|
2009-09-10 18:54:35 +00:00
|
|
|
r_opts.quiet = 1;
|
2008-08-19 19:30:36 +00:00
|
|
|
break;
|
|
|
|
case 'R':
|
|
|
|
case 'r':
|
|
|
|
if (iamrestorecon) {
|
|
|
|
recurse = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (optind + 1 >= argc) {
|
2011-07-10 14:42:18 +00:00
|
|
|
fprintf(stderr, "usage: %s -r rootpath\n",
|
2008-08-19 19:30:36 +00:00
|
|
|
argv[0]);
|
|
|
|
exit(1);
|
|
|
|
}
|
2009-09-10 18:54:35 +00:00
|
|
|
if (NULL != r_opts.rootpath) {
|
2008-08-19 19:30:36 +00:00
|
|
|
fprintf(stderr,
|
|
|
|
"%s: only one -r can be specified\n",
|
|
|
|
argv[0]);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
set_rootpath(argv[optind++]);
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
use_input_file = 1;
|
|
|
|
input_filename = "-";
|
2009-09-10 18:54:35 +00:00
|
|
|
r_opts.add_assoc = 0;
|
2008-08-19 19:30:36 +00:00
|
|
|
break;
|
|
|
|
case 'v':
|
2009-09-10 18:54:35 +00:00
|
|
|
if (r_opts.progress) {
|
2008-08-19 19:30:36 +00:00
|
|
|
fprintf(stderr,
|
|
|
|
"Progress and Verbose mutually exclusive\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
2009-09-10 18:54:35 +00:00
|
|
|
r_opts.verbose++;
|
2008-08-19 19:30:36 +00:00
|
|
|
break;
|
|
|
|
case 'p':
|
2009-09-10 18:54:35 +00:00
|
|
|
if (r_opts.verbose) {
|
2008-08-19 19:30:36 +00:00
|
|
|
fprintf(stderr,
|
|
|
|
"Progress and Verbose mutually exclusive\n");
|
|
|
|
usage(argv[0]);
|
|
|
|
}
|
2012-02-03 16:56:39 +00:00
|
|
|
r_opts.progress++;
|
2008-08-19 19:30:36 +00:00
|
|
|
break;
|
|
|
|
case 'W':
|
|
|
|
warn_no_match = 1;
|
|
|
|
break;
|
|
|
|
case '0':
|
|
|
|
null_terminated = 1;
|
|
|
|
break;
|
2012-08-22 07:13:43 +00:00
|
|
|
case 'h':
|
2008-08-19 19:30:36 +00:00
|
|
|
case '?':
|
|
|
|
usage(argv[0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-03 16:56:39 +00:00
|
|
|
for (i = optind; i < argc; i++) {
|
|
|
|
if (!strcmp(argv[i], "/")) {
|
|
|
|
mass_relabel = 1;
|
|
|
|
if (r_opts.progress)
|
|
|
|
r_opts.progress++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-19 19:30:36 +00:00
|
|
|
if (!iamrestorecon) {
|
|
|
|
if (policyfile) {
|
|
|
|
if (optind != (argc - 1))
|
|
|
|
usage(argv[0]);
|
|
|
|
} else if (use_input_file) {
|
|
|
|
if (optind != (argc - 1)) {
|
|
|
|
/* Cannot mix with pathname arguments. */
|
|
|
|
usage(argv[0]);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (optind > (argc - 2))
|
|
|
|
usage(argv[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Use our own invalid context checking function so that
|
|
|
|
we can support either checking against the active policy or
|
|
|
|
checking against a binary policy file. */
|
|
|
|
selinux_set_callback(SELINUX_CB_VALIDATE,
|
|
|
|
(union selinux_callback)&canoncon);
|
|
|
|
|
|
|
|
if (stat(argv[optind], &sb) < 0) {
|
|
|
|
perror(argv[optind]);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (!S_ISREG(sb.st_mode)) {
|
|
|
|
fprintf(stderr, "%s: spec file %s is not a regular file.\n",
|
|
|
|
argv[0], argv[optind]);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
altpath = argv[optind];
|
|
|
|
optind++;
|
2012-08-22 07:13:43 +00:00
|
|
|
} else if (argc == 1)
|
|
|
|
usage(argv[0]);
|
2008-08-19 19:30:36 +00:00
|
|
|
|
|
|
|
/* Load the file contexts configuration and check it. */
|
2009-09-10 18:54:35 +00:00
|
|
|
r_opts.selabel_opt_validate = (ctx_validate ? (char *)1 : NULL);
|
|
|
|
r_opts.selabel_opt_path = altpath;
|
2008-08-19 19:30:36 +00:00
|
|
|
|
|
|
|
if (nerr)
|
|
|
|
exit(1);
|
|
|
|
|
2009-09-10 18:54:35 +00:00
|
|
|
restore_init(&r_opts);
|
2008-08-19 19:30:36 +00:00
|
|
|
if (use_input_file) {
|
|
|
|
FILE *f = stdin;
|
|
|
|
ssize_t len;
|
|
|
|
int delim;
|
|
|
|
if (strcmp(input_filename, "-") != 0)
|
|
|
|
f = fopen(input_filename, "r");
|
|
|
|
if (f == NULL) {
|
|
|
|
fprintf(stderr, "Unable to open %s: %s\n", input_filename,
|
|
|
|
strerror(errno));
|
|
|
|
usage(argv[0]);
|
|
|
|
}
|
|
|
|
__fsetlocking(f, FSETLOCKING_BYCALLER);
|
|
|
|
|
|
|
|
delim = (null_terminated != 0) ? '\0' : '\n';
|
|
|
|
while ((len = getdelim(&buf, &buf_len, delim, f)) > 0) {
|
|
|
|
buf[len - 1] = 0;
|
2009-09-10 18:54:35 +00:00
|
|
|
if (!strcmp(buf, "/"))
|
|
|
|
mass_relabel = 1;
|
2012-03-11 22:59:08 +00:00
|
|
|
errors |= process_glob(buf, recurse) < 0;
|
2008-08-19 19:30:36 +00:00
|
|
|
}
|
|
|
|
if (strcmp(input_filename, "-") != 0)
|
|
|
|
fclose(f);
|
|
|
|
} else {
|
2012-02-03 16:56:39 +00:00
|
|
|
for (i = optind; i < argc; i++)
|
2012-03-11 22:59:08 +00:00
|
|
|
errors |= process_glob(argv[i], recurse) < 0;
|
2008-08-19 19:30:36 +00:00
|
|
|
}
|
2009-09-10 18:54:35 +00:00
|
|
|
|
2011-07-10 15:32:14 +00:00
|
|
|
maybe_audit_mass_relabel(mass_relabel, errors);
|
2008-08-19 19:30:36 +00:00
|
|
|
|
|
|
|
if (warn_no_match)
|
2009-09-10 18:54:35 +00:00
|
|
|
selabel_stats(r_opts.hnd);
|
2008-08-19 19:30:36 +00:00
|
|
|
|
2009-09-10 18:54:35 +00:00
|
|
|
selabel_close(r_opts.hnd);
|
|
|
|
restore_finish();
|
2008-08-19 19:30:36 +00:00
|
|
|
|
2009-09-10 18:54:35 +00:00
|
|
|
if (r_opts.outfile)
|
|
|
|
fclose(r_opts.outfile);
|
2008-08-19 19:30:36 +00:00
|
|
|
|
2012-08-22 07:13:43 +00:00
|
|
|
if (r_opts.progress && r_opts.count >= STAR_COUNT)
|
|
|
|
printf("\n");
|
2008-08-19 19:30:36 +00:00
|
|
|
exit(errors);
|
|
|
|
}
|