[dovecot-cvs] dovecot/src/master ssl-init.c,1.28,1.29

tss at dovecot.org tss at dovecot.org
Sun May 13 18:26:32 EEST 2007


Update of /var/lib/cvs/dovecot/src/master
In directory talvi:/tmp/cvs-serv17153

Modified Files:
	ssl-init.c 
Log Message:
If ssl-parameters.dat has been updated externally, copy it to our base_dir.



Index: ssl-init.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/master/ssl-init.c,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -d -r1.28 -r1.29
--- ssl-init.c	13 May 2007 13:45:49 -0000	1.28
+++ ssl-init.c	13 May 2007 15:26:30 -0000	1.29
@@ -13,6 +13,7 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <fcntl.h>
+#include <utime.h>
 #include <sys/stat.h>
 
 static struct timeout *to;
@@ -75,35 +76,44 @@
 static bool check_parameters_file_set(struct settings *set)
 {
 	const char *path;
-	struct stat st;
+	struct stat st, st2;
 	time_t regen_time;
 
 	if (set->ssl_disable)
 		return TRUE;
 
 	path = t_strconcat(set->login_dir, "/"SSL_PARAMETERS_FILENAME, NULL);
-	if (lstat(path, &st) < 0) {
+	if (stat(path, &st) < 0) {
 		if (errno != ENOENT) {
-			i_error("lstat() failed for SSL parameters file %s: %m",
+			i_error("stat() failed for SSL parameters file %s: %m",
 				path);
 			return TRUE;
 		}
 
-		/* try to copy the permanent parameters file here if possible */
-		if (file_copy(SSL_PARAMETERS_PERM_PATH, path, TRUE) > 0) {
-			if (stat(path, &st) < 0) {
-				i_error("stat(%s) failed: %m", path);
-				st.st_mtime = 0;
-			}
-		} else {
-			st.st_mtime = 0;
-		}
+		st.st_mtime = 0;
 	} else if (st.st_size == 0) {
 		/* broken, delete it (mostly for backwards compatibility) */
 		st.st_mtime = 0;
 		(void)unlink(path);
 	}
 
+	if (stat(SSL_PARAMETERS_PERM_PATH, &st2) == 0 &&
+	    st.st_mtime < st2.st_mtime) {
+		/* permanent parameters file has changed. use it. */
+		if (file_copy(SSL_PARAMETERS_PERM_PATH, path, TRUE) > 0) {
+			if (st.st_ino != st2.st_ino) {
+				/* preserve the mtime */
+				struct utimbuf ut;
+
+				ut.actime = ut.modtime = st2.st_mtime;
+				if (utime(path, &ut) < 0)
+					i_error("utime(%s) failed: %m", path);
+			}
+			if (stat(path, &st) < 0)
+				st.st_mtime = 0;
+		}
+	}
+
 	/* make sure it's new enough, it's not 0 sized, and the permissions
 	   are correct */
 	regen_time = set->ssl_parameters_regenerate == 0 ? ioloop_time :



More information about the dovecot-cvs mailing list