]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/lib/openssl.c
First cut of bat rerun a Job from Jobs Run
[bacula/bacula] / bacula / src / lib / openssl.c
index 929dee7c26e237d0df4f1a9cb6cafdc900708978..b8ff9978fee2930dc1d9a627e85bf9fef1bebe84 100644 (file)
@@ -1,3 +1,30 @@
+/*
+   Bacula® - The Network Backup Solution
+
+   Copyright (C) 2005-2009 Free Software Foundation Europe e.V.
+
+   The main author of Bacula is Kern Sibbald, with contributions from
+   many others, a complete list can be found in the file AUTHORS.
+   This program is Free Software; you can redistribute it and/or
+   modify it under the terms of version three of the GNU Affero General Public
+   License as published by the Free Software Foundation and included
+   in the file LICENSE.
+
+   This program is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU Affero General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301, USA.
+
+   Bacula® is a registered trademark of Kern Sibbald.
+   The licensor of Bacula is the Free Software Foundation Europe
+   (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
+   Switzerland, email:ftf@fsfeurope.org.
+*/
 /*
  * openssl.c OpenSSL support functions
  *
@@ -5,8 +32,6 @@
  *
  * Version $Id$
  *
- * Copyright (C) 2005 Kern Sibbald
- *
  * This file was contributed to the Bacula project by Landon Fuller.
  *
  * Landon Fuller has been granted a perpetual, worldwide, non-exclusive,
  * If you wish to license these contributions under an alternate open source
  * license please contact Landon Fuller <landonf@opendarwin.org>.
  */
-/*
-   Copyright (C) 2005 Kern Sibbald
-
-   This program is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License
-   version 2 as amended with additional clauses defined in the
-   file LICENSE in the main source directory.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
-   the file LICENSE for additional details.
-
- */
 
 
 #include "bacula.h"
@@ -47,11 +58,22 @@ struct CRYPTO_dynlock_value {
    pthread_mutex_t mutex;
 };
 
+/*
+ * ***FIXME*** this is a sort of dummy to avoid having to
+ *   change all the existing code to pass either a jcr or
+ *   a NULL.  Passing a NULL causes the messages to be
+ *   printed by the daemon -- not very good :-(
+ */
+void openssl_post_errors(int code, const char *errstring)
+{
+   openssl_post_errors(NULL, code, errstring);
+}
+
 
 /*
  * Post all per-thread openssl errors
  */
-void openssl_post_errors(int code, const char *errstring)
+void openssl_post_errors(JCR *jcr, int code, const char *errstring)
 {
    char buf[512];
    unsigned long sslerr;
@@ -59,8 +81,9 @@ void openssl_post_errors(int code, const char *errstring)
    /* Pop errors off of the per-thread queue */
    while((sslerr = ERR_get_error()) != 0) {
       /* Acquire the human readable string */
-      ERR_error_string_n(sslerr, (char *) &buf, sizeof(buf));
-      Emsg2(M_ERROR, 0, "%s: ERR=%s\n", errstring, buf);
+      ERR_error_string_n(sslerr, buf, sizeof(buf));
+      Dmsg3(50, "jcr=%p %s: ERR=%s\n", jcr, errstring, buf);
+      Qmsg2(jcr, M_ERROR, 0, "%s: ERR=%s\n", errstring, buf);
    }
 }
 
@@ -69,10 +92,19 @@ void openssl_post_errors(int code, const char *errstring)
  *  Returns: thread ID
  *
  */
-static unsigned long get_openssl_thread_id (void)
+static unsigned long get_openssl_thread_id(void)
 {
-   /* Comparison without use of pthread_equal() is mandated by the OpenSSL API */
-   return ((unsigned long) pthread_self());
+#ifdef HAVE_WIN32
+   return (unsigned long)getpid();
+#else
+   /*
+    * Comparison without use of pthread_equal() is mandated by the OpenSSL API 
+    *
+    * Note: this creates problems with the new Win32 pthreads
+    *   emulation code, which defines pthread_t as a structure.
+    */
+   return ((unsigned long)pthread_self());
+#endif
 }
 
 /*
@@ -83,16 +115,17 @@ static struct CRYPTO_dynlock_value *openssl_create_dynamic_mutex (const char *fi
    struct CRYPTO_dynlock_value *dynlock;
    int stat;
 
-   dynlock = (struct CRYPTO_dynlock_value *) malloc(sizeof(struct CRYPTO_dynlock_value));
+   dynlock = (struct CRYPTO_dynlock_value *)malloc(sizeof(struct CRYPTO_dynlock_value));
 
    if ((stat = pthread_mutex_init(&dynlock->mutex, NULL)) != 0) {
-      Emsg1(M_ABORT, 0, _("Unable to init mutex: ERR=%s\n"), strerror(stat));
+      berrno be;
+      Jmsg1(NULL, M_ABORT, 0, _("Unable to init mutex: ERR=%s\n"), be.bstrerror(stat));
    }
 
    return dynlock;
 }
 
-static void openssl_update_dynamic_mutex (int mode, struct CRYPTO_dynlock_value *dynlock, const char *file, int line)
+static void openssl_update_dynamic_mutex(int mode, struct CRYPTO_dynlock_value *dynlock, const char *file, int line)
 {
    if (mode & CRYPTO_LOCK) {
       P(dynlock->mutex);
@@ -101,12 +134,13 @@ static void openssl_update_dynamic_mutex (int mode, struct CRYPTO_dynlock_value
    }
 }
 
-static void openssl_destroy_dynamic_mutex (struct CRYPTO_dynlock_value *dynlock, const char *file, int line)
+static void openssl_destroy_dynamic_mutex(struct CRYPTO_dynlock_value *dynlock, const char *file, int line)
 {
    int stat;
 
    if ((stat = pthread_mutex_destroy(&dynlock->mutex)) != 0) {
-      Emsg1(M_ABORT, 0, _("Unable to destroy mutex: ERR=%s\n"), strerror(stat));
+      berrno be;
+      Jmsg1(NULL, M_ABORT, 0, _("Unable to destroy mutex: ERR=%s\n"), be.bstrerror(stat));
    }
 
    free(dynlock);
@@ -143,7 +177,8 @@ int openssl_init_threads (void)
    mutexes = (pthread_mutex_t *) malloc(numlocks * sizeof(pthread_mutex_t));
    for (i = 0; i < numlocks; i++) {
       if ((stat = pthread_mutex_init(&mutexes[i], NULL)) != 0) {
-         Emsg1(M_ERROR, 0, _("Unable to init mutex: ERR=%s\n"), strerror(stat));
+         berrno be;
+         Jmsg1(NULL, M_FATAL, 0, _("Unable to init mutex: ERR=%s\n"), be.bstrerror(stat));
          return stat;
       }
    }
@@ -162,7 +197,7 @@ int openssl_init_threads (void)
 /*
  * Clean up OpenSSL threading support
  */
-void openssl_cleanup_threads (void)
+void openssl_cleanup_threads(void)
 {
    int i, numlocks;
    int stat;
@@ -174,8 +209,10 @@ void openssl_cleanup_threads (void)
    numlocks = CRYPTO_num_locks();
    for (i = 0; i < numlocks; i++) {
       if ((stat = pthread_mutex_destroy(&mutexes[i])) != 0) {
+         berrno be;
          /* We don't halt execution, reporting the error should be sufficient */
-         Emsg1(M_ERROR, 0, _("Unable to destroy mutex: ERR=%s\n"), strerror(stat));
+         Jmsg1(NULL, M_ERROR, 0, _("Unable to destroy mutex: ERR=%s\n"), 
+               be.bstrerror(stat));
       }
    }