-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 This patch looks good to me. acked. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAk45txAACgkQrlYvE4MpobPoRQCfWj1Hhlo6FDfxUmmq+iLj+kam eDQAoOXFBcvkKG/5HmHpyoCYqQ5TJSbt =qNvE -----END PGP SIGNATURE-----
>From a7a8d9d20393a703430e0a94059c5bf037a76e54 Mon Sep 17 00:00:00 2001 From: Eric Paris <eparis@xxxxxxxxxx> Date: Sun, 10 Jul 2011 17:06:00 +0200 Subject: [PATCH 040/155] 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@xxxxxxxxxx> --- policycoreutils/setfiles/restore.c | 23 +++++++++++++++++++++++ policycoreutils/setfiles/restore.h | 1 + policycoreutils/setfiles/setfiles.c | 5 +++-- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/policycoreutils/setfiles/restore.c b/policycoreutils/setfiles/restore.c index beef128..d8965e7 100644 --- a/policycoreutils/setfiles/restore.c +++ b/policycoreutils/setfiles/restore.c @@ -1,4 +1,5 @@ #include "restore.h" +#include <glob.h> #define SKIP -2 #define ERR -1 @@ -357,6 +358,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; diff --git a/policycoreutils/setfiles/restore.h b/policycoreutils/setfiles/restore.h index 15d198b..00743a0 100644 --- a/policycoreutils/setfiles/restore.h +++ b/policycoreutils/setfiles/restore.h @@ -47,6 +47,7 @@ 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); void exclude_non_seclabel_mounts(); #endif diff --git a/policycoreutils/setfiles/setfiles.c b/policycoreutils/setfiles/setfiles.c index bde58c9..e4f87bc 100644 --- a/policycoreutils/setfiles/setfiles.c +++ b/policycoreutils/setfiles/setfiles.c @@ -410,7 +410,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); @@ -418,7 +418,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); } } -- 1.7.6
Attachment:
0040-policycoreutils-setfiles-use-glob-to-handle-and-.-in.patch.sig
Description: PGP signature