svn commit: samba r18225 - in branches/SAMBA_3_0/source/libads: .

jra at samba.org jra at samba.org
Thu Sep 7 17:29:23 GMT 2006


Author: jra
Date: 2006-09-07 17:29:23 +0000 (Thu, 07 Sep 2006)
New Revision: 18225

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=18225

Log:
If we're going to overwrite krb5.conf, at least
be polite enough to make a backup.
Jeremy.

Modified:
   branches/SAMBA_3_0/source/libads/kerberos.c


Changeset:
Modified: branches/SAMBA_3_0/source/libads/kerberos.c
===================================================================
--- branches/SAMBA_3_0/source/libads/kerberos.c	2006-09-07 16:51:17 UTC (rev 18224)
+++ branches/SAMBA_3_0/source/libads/kerberos.c	2006-09-07 17:29:23 UTC (rev 18225)
@@ -616,32 +616,54 @@
 
 #if defined(OVERWRITE_SYSTEM_KRB5_CONF)
 
+#define SYSTEM_KRB5_CONF_PATH "/etc/krb5.conf"
 	/* Insanity, sheer insanity..... */
 
-	if (symlink(fname, "/etc/krb5.conf") == -1) {
-		if (errno != EEXIST) {
-			DEBUG(0,("create_local_private_krb5_conf_for_domain: symlink "
-				"of %s to /etc/krb5.conf failed. Errno %s\n",
-				fname, strerror(errno) ));
+
+	{
+		pstring linkpath;
+		int lret;
+
+		lret = readlink(SYSTEM_KRB5_CONF_PATH, linkpath, sizeof(linkpath)-1);
+		linkpath[sizeof(pstring)-1] = '\0';
+
+		if (lret == 0 || strcmp(linkpath, fname) == 0) {
+			/* Symlink already exists. */
 			TALLOC_FREE(dname);
-			return True; /* Not a fatal error. */
+			return True;
 		}
 
-		/* Yes, this is a race conditon... too bad. */
-		if (unlink("/etc/krb5.conf") == -1) {
-			DEBUG(0,("create_local_private_krb5_conf_for_domain: unlink "
-				"of /etc/krb5.conf failed. Errno %s\n",
-				strerror(errno) ));
-			TALLOC_FREE(dname);
-			return True; /* Not a fatal error. */
+		/* Try and replace with a symlink. */
+		if (symlink(fname, SYSTEM_KRB5_CONF_PATH) == -1) {
+			if (errno != EEXIST) {
+				DEBUG(0,("create_local_private_krb5_conf_for_domain: symlink "
+					"of %s to %s failed. Errno %s\n",
+					fname, SYSTEM_KRB5_CONF_PATH, strerror(errno) ));
+				TALLOC_FREE(dname);
+				return True; /* Not a fatal error. */
+			}
+
+			pstrcpy(linkpath, SYSTEM_KRB5_CONF_PATH);
+			pstrcat(linkpath, ".saved");
+
+			/* Yes, this is a race conditon... too bad. */
+			if (rename(SYSTEM_KRB5_CONF_PATH, linkpath) == -1) {
+				DEBUG(0,("create_local_private_krb5_conf_for_domain: rename "
+					"of %s to %s failed. Errno %s\n",
+					SYSTEM_KRB5_CONF_PATH, linkpath,
+					strerror(errno) ));
+				TALLOC_FREE(dname);
+				return True; /* Not a fatal error. */
+			}
+
+			if (symlink(fname, "/etc/krb5.conf") == -1) {
+				DEBUG(0,("create_local_private_krb5_conf_for_domain: "
+					"forced symlink of %s to /etc/krb5.conf failed. Errno %s\n",
+					fname, strerror(errno) ));
+				TALLOC_FREE(dname);
+				return True; /* Not a fatal error. */
+			}
 		}
-		if (symlink(fname, "/etc/krb5.conf") == -1) {
-			DEBUG(0,("create_local_private_krb5_conf_for_domain: "
-				"forced symlink of %s to /etc/krb5.conf failed. Errno %s\n",
-				fname, strerror(errno) ));
-			TALLOC_FREE(dname);
-			return True; /* Not a fatal error. */
-		}
 	}
 #endif
 



More information about the samba-cvs mailing list