Branch: master

68049e4a 2016-09-04 15:44:50 Timothy Pearson
Don't abort on chown() failure for certificate files
M src/libtdeldap.cpp
diff --git a/src/libtdeldap.cpp b/src/libtdeldap.cpp
index 868b423..93d79a1 100644
--- a/src/libtdeldap.cpp
+++ b/src/libtdeldap.cpp
@@ -4592,8 +4592,7 @@
 		return -1;
 	}
 	if (chown(client_keyfile.ascii(), 0, 0) < 0) {
-		if (errstr) *errstr = TQString("Unable to change owner of \"%1\"").arg(client_keyfile);
-		return -1;
+		printf("[WARNING] Unable to change owner of \"%s\"", client_keyfile.ascii());
 	}
 
 	// Clean up
@@ -4653,8 +4652,7 @@
 		return -1;
 	}
 	if (chown(client_certfile.ascii(), 0, 0) < 0) {
-		if (errstr) *errstr = TQString("Unable to change owner of \"%1\"").arg(client_certfile);
-		return -1;
+		printf("[WARNING] Unable to change owner of \"%s\"", client_certfile.ascii());
 	}
 
 	// Clean up
a12aeff2 2016-09-04 16:11:26 Timothy Pearson
Close cert file handle if already open before opening for write
Fixup missing newlines in printf warnings from last commit
M src/libtdeldap.cpp
diff --git a/src/libtdeldap.cpp b/src/libtdeldap.cpp
index 93d79a1..878cd76 100644
--- a/src/libtdeldap.cpp
+++ b/src/libtdeldap.cpp
@@ -4121,6 +4121,10 @@
 	TQByteArray ba;
 	returncode = getTDECertificate(certificateName, &ba, errstr);
 	if (returncode == 0) {
+		if (fileHandle->isOpen()) {
+			printf("[WARNING] File \"%s\" was already open, closing...\n");
+			fileHandle->close();
+		}
 		if (fileHandle->open(IO_WriteOnly)) {
 			fileHandle->writeBlock(ba);
 			fileHandle->close();
@@ -4592,7 +4596,7 @@
 		return -1;
 	}
 	if (chown(client_keyfile.ascii(), 0, 0) < 0) {
-		printf("[WARNING] Unable to change owner of \"%s\"", client_keyfile.ascii());
+		printf("[WARNING] Unable to change owner of \"%s\"\n", client_keyfile.ascii());
 	}
 
 	// Clean up
@@ -4652,7 +4656,7 @@
 		return -1;
 	}
 	if (chown(client_certfile.ascii(), 0, 0) < 0) {
-		printf("[WARNING] Unable to change owner of \"%s\"", client_certfile.ascii());
+		printf("[WARNING] Unable to change owner of \"%s\"\n", client_certfile.ascii());
 	}
 
 	// Clean up