mirror of
https://github.com/SELinuxProject/selinux
synced 2024-12-24 15:02:44 +00:00
policycoreutils: setfiles: use glob to handle ~ and . in filenames
Use the glob library to handle ~ and . in filenames passed from the command line. Signed-off-by: Eric Paris <eparis@redhat.com> Acked-by: Dan Walsh <dwalsh@redhat.com>
This commit is contained in:
parent
5bd734dd73
commit
17c577ace7
@ -1,4 +1,5 @@
|
||||
#include "restore.h"
|
||||
#include <glob.h>
|
||||
|
||||
#define SKIP -2
|
||||
#define ERR -1
|
||||
@ -362,6 +363,28 @@ err:
|
||||
goto out;
|
||||
}
|
||||
|
||||
int process_glob(char *name, int recurse) {
|
||||
glob_t globbuf;
|
||||
size_t i = 0;
|
||||
int errors;
|
||||
memset(&globbuf, 0, sizeof(globbuf));
|
||||
errors = glob(name, GLOB_TILDE | GLOB_PERIOD, NULL, &globbuf);
|
||||
if (errors)
|
||||
errors = process_one_realpath(name, recurse);
|
||||
else {
|
||||
for (i = 0; i < globbuf.gl_pathc; i++) {
|
||||
int len = strlen(globbuf.gl_pathv[i]) -2;
|
||||
if (len > 0 && strcmp(&globbuf.gl_pathv[i][len--], "/.") == 0)
|
||||
continue;
|
||||
if (len > 0 && strcmp(&globbuf.gl_pathv[i][len], "/..") == 0)
|
||||
continue;
|
||||
errors |= process_one_realpath(globbuf.gl_pathv[i], recurse);
|
||||
}
|
||||
globfree(&globbuf);
|
||||
}
|
||||
return errors;
|
||||
}
|
||||
|
||||
int process_one_realpath(char *name, int recurse)
|
||||
{
|
||||
int rc = 0;
|
||||
|
@ -47,5 +47,6 @@ void restore_finish();
|
||||
int add_exclude(const char *directory);
|
||||
void remove_exclude(const char *directory);
|
||||
int process_one_realpath(char *name, int recurse);
|
||||
int process_glob(char *name, int recurse);
|
||||
|
||||
#endif
|
||||
|
@ -474,7 +474,7 @@ int main(int argc, char **argv)
|
||||
buf[len - 1] = 0;
|
||||
if (!strcmp(buf, "/"))
|
||||
mass_relabel = 1;
|
||||
errors |= process_one_realpath(buf, recurse) < 0;
|
||||
errors |= process_glob(buf, recurse);
|
||||
}
|
||||
if (strcmp(input_filename, "-") != 0)
|
||||
fclose(f);
|
||||
@ -482,7 +482,8 @@ int main(int argc, char **argv)
|
||||
for (i = optind; i < argc; i++) {
|
||||
if (!strcmp(argv[i], "/"))
|
||||
mass_relabel = 1;
|
||||
errors |= process_one_realpath(argv[i], recurse) < 0;
|
||||
|
||||
errors |= process_glob(argv[i], recurse);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user