[PATCH 28/96] policycoreutils: setfiles: use glob to handle ~ and .

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



-----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/

iEYEARECAAYFAk5D6OsACgkQrlYvE4MpobNjVACgxTutXesruAIl55/JesILZQc3
eG4AoMm0TYw4uH3ozJXZWrUsM+yNb1Y7
=U9vp
-----END PGP SIGNATURE-----
>From 1647f7ade166da94d60cbc0b94cecf65ecfebf4c Mon Sep 17 00:00:00 2001
From: Eric Paris <eparis@xxxxxxxxxx>
Date: Sun, 10 Jul 2011 17:06:00 +0200
Subject: [PATCH 28/96] 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>
Acked-by: Dan Walsh <dwalsh@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 c54876f..f3f2339 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
@@ -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;
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: 0028-policycoreutils-setfiles-use-glob-to-handle-and-.-in.patch.sig
Description: PGP signature


[Index of Archives]     [Selinux Refpolicy]     [Linux SGX]     [Fedora Users]     [Fedora Desktop]     [Yosemite Photos]     [Yosemite Camping]     [Yosemite Campsites]     [KDE Users]     [Gnome Users]

  Powered by Linux