All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] semanage - rename instead of copy
@ 2005-11-07 21:25 Joshua Brindle
  2005-11-07 21:35 ` Stephen Smalley
  0 siblings, 1 reply; 5+ messages in thread
From: Joshua Brindle @ 2005-11-07 21:25 UTC (permalink / raw)
  To: SELinux List; +Cc: Stephen Smalley

[-- Attachment #1: Type: text/plain, Size: 230 bytes --]

Attached patch makes libsemanage copy file to a temporary file and then
rename() instead of copying directly to the target. This is necessary so
that an install failure doesn't leave a corrupt binary policy on the
system.

Joshua

[-- Attachment #2: 1-rename-files.diff --]
[-- Type: text/x-patch, Size: 1009 bytes --]

diff -purN -x .svn libsemanage/src/semanage_store.c libsemanage/src/semanage_store.c
--- libsemanage/src/semanage_store.c	2005-11-07 11:52:28.000000000 -0500
+++ libsemanage/src/semanage_store.c	2005-11-07 16:06:04.000000000 -0500
@@ -305,12 +305,18 @@ static int semanage_filename_select(cons
  * overwrite it.  Returns 0 on success, -1 on error. */
 static int semanage_copy_file(const char *src, const char *dst) {
 	int in, out, retval = 0, amount_read;
+	char tmp[PATH_MAX] = {};
 	char buf[4192];
 
 	if ((in = open(src, O_RDONLY)) == -1) {
 		return -1;
 	}
-	if ((out = open(dst, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR)) == -1) {
+	
+	snprintf(tmp, PATH_MAX, "%s.tmp", dst);
+	if (!tmp)
+		return -1;
+
+	if ((out = open(tmp, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR)) == -1) {
 		close(in);
 		return -1;
 	}
@@ -324,6 +330,10 @@ static int semanage_copy_file(const char
 		retval = -1;
 	close(in);
 	close(out);
+
+	if (rename(tmp, dst) == -1)
+		return -1;
+
 	return retval;
 }
 

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2005-11-08 14:05 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-11-07 21:25 [PATCH] semanage - rename instead of copy Joshua Brindle
2005-11-07 21:35 ` Stephen Smalley
2005-11-07 21:50   ` Joshua Brindle
2005-11-08 13:34     ` Stephen Smalley
2005-11-08 14:05       ` Stephen Smalley

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.