tls: Inform the user if the cert/ca/private key can't be saved
authorMatthieu Patou <mat@matws.net>
Wed, 27 Oct 2010 18:59:25 +0000 (22:59 +0400)
committerMatthieu Patou <mat@samba.org>
Wed, 27 Oct 2010 20:08:54 +0000 (20:08 +0000)
Most of the time this problem is due to a missing <private>/tls dir.
Should close bug 7640.

Autobuild-User: Matthieu Patou <mat@samba.org>
Autobuild-Date: Wed Oct 27 20:08:54 UTC 2010 on sn-devel-104

source4/lib/tls/tlscert.c

index 62e7a72240d6f9b33e062efd59929b61660fbd01..bef634803a6c8ddce4727d0f4e40aa80a83d0418 100644 (file)
@@ -138,15 +138,24 @@ void tls_cert_generate(TALLOC_CTX *mem_ctx,
 
        bufsize = sizeof(buf);
        TLSCHECK(gnutls_x509_crt_export(crt, GNUTLS_X509_FMT_PEM, buf, &bufsize));
-       file_save(certfile, buf, bufsize);
+       if (!file_save(certfile, buf, bufsize)) {
+               DEBUG(0,("Unable to save certificate in %s parent dir exists ?\n", certfile));
+               goto failed;
+       }
 
        bufsize = sizeof(buf);
        TLSCHECK(gnutls_x509_crt_export(cacrt, GNUTLS_X509_FMT_PEM, buf, &bufsize));
-       file_save(cafile, buf, bufsize);
+       if (!file_save(cafile, buf, bufsize)) {
+               DEBUG(0,("Unable to save ca cert in %s parent dir exists ?\n", cafile));
+               goto failed;
+       }
 
        bufsize = sizeof(buf);
        TLSCHECK(gnutls_x509_privkey_export(key, GNUTLS_X509_FMT_PEM, buf, &bufsize));
-       file_save(keyfile, buf, bufsize);
+       if (!file_save(keyfile, buf, bufsize)) {
+               DEBUG(0,("Unable to save privatekey in %s parent dir exists ?\n", keyfile));
+               goto failed;
+       }
 
        gnutls_x509_privkey_deinit(key);
        gnutls_x509_privkey_deinit(cakey);