From 7da598fcee5d359ff12967272bec4da3b663654f Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Thu, 7 Jun 2007 13:21:44 +0000 Subject: [PATCH] kes Fix sscanf problems reported by Peter Buschman that caused a bus error on Solaris. kes Rework (simplify) the select prompt in bat. kes Move get_jobid_from_tid() into lib and create a get_jcr_from_tid(). kes Use get_jcr_from_tid() to conver all tls Emsg() to Jmsg(). This should definitely fix the problem of lost error messages in the encryption code. kes Remove over zellous addition of FSFE copyright in a few eggxxx files. kes Eliminate tcpd.h from the project. Enclose the #include from the library with extern C ... kes Add print of signal name when a signal is trapped. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@4990 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/filed/job.c | 13 +- bacula/src/lib/address_conf.h | 15 +- bacula/src/lib/bnet_server.c | 4 +- bacula/src/lib/crypto.c | 21 +- bacula/src/lib/jcr.c | 46 +++++ bacula/src/lib/openssl.c | 19 +- bacula/src/lib/protos.h | 4 + bacula/src/lib/runscript.h | 18 +- bacula/src/lib/signal.c | 9 +- bacula/src/lib/tcpd.h | 235 ---------------------- bacula/src/lib/tls.c | 12 +- bacula/src/lib/util.c | 14 +- bacula/src/lib/var.c | 40 ++-- bacula/src/lib/workq.c | 54 ++--- bacula/src/qt-console/console/console.cpp | 12 +- bacula/src/qt-console/select/select.cpp | 19 +- bacula/src/stored/device.c | 24 +-- bacula/src/stored/protos.h | 1 - bacula/technotes-2.1 | 15 ++ 19 files changed, 207 insertions(+), 368 deletions(-) delete mode 100644 bacula/src/lib/tcpd.h diff --git a/bacula/src/filed/job.c b/bacula/src/filed/job.c index cfb569317f..8fc6dbdc5d 100644 --- a/bacula/src/filed/job.c +++ b/bacula/src/filed/job.c @@ -120,7 +120,7 @@ static char verifycmd[] = "verify level=%30s"; static char estimatecmd[] = "estimate listing=%d"; static char runbefore[] = "RunBeforeJob %s"; static char runafter[] = "RunAfterJob %s"; -static char runscript[] = "Run OnSuccess=%u OnFailure=%u AbortOnError=%u When=%u Command=%s"; +static char runscript[] = "Run OnSuccess=%d OnFailure=%d AbortOnError=%d When=%d Command=%s"; /* Responses sent to Director */ static char errmsg[] = "2999 Invalid command\n"; @@ -530,13 +530,15 @@ static int runscript_cmd(JCR *jcr) { BSOCK *dir = jcr->dir_bsock; POOLMEM *msg = get_memory(dir->msglen+1); + int on_success, on_failure, abort_on_error; RUNSCRIPT *cmd = new_runscript() ; Dmsg1(100, "runscript_cmd: '%s'\n", dir->msg); - if (sscanf(dir->msg, runscript, &cmd->on_success, - &cmd->on_failure, - &cmd->abort_on_error, + /* Note, we cannot sscanf into bools */ + if (sscanf(dir->msg, runscript, &on_success, + &on_failure, + &abort_on_error, &cmd->when, msg) != 5) { pm_strcpy(jcr->errmsg, dir->msg); @@ -546,6 +548,9 @@ static int runscript_cmd(JCR *jcr) free_memory(msg); return 0; } + cmd->on_success = on_success; + cmd->on_failure = on_failure; + cmd->abort_on_error = abort_on_error; unbash_spaces(msg); cmd->set_command(msg); diff --git a/bacula/src/lib/address_conf.h b/bacula/src/lib/address_conf.h index 78d7992d2b..de80c863d5 100644 --- a/bacula/src/lib/address_conf.h +++ b/bacula/src/lib/address_conf.h @@ -1,13 +1,7 @@ -/* - * - * Written by Meno Abels, June MMIV - * - * Version $Id$ - */ /* Bacula® - The Network Backup Solution - Copyright (C) 2004-2006 Free Software Foundation Europe e.V. + Copyright (C) 2004-2007 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. @@ -31,6 +25,13 @@ (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich, Switzerland, email:ftf@fsfeurope.org. */ +/* + * + * Written by Meno Abels, June MMIV + * + * Version $Id$ + */ + class IPADDR : public SMARTALLOC { public: diff --git a/bacula/src/lib/bnet_server.c b/bacula/src/lib/bnet_server.c index b30d17e14f..00115e5363 100644 --- a/bacula/src/lib/bnet_server.c +++ b/bacula/src/lib/bnet_server.c @@ -49,7 +49,9 @@ static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; #ifdef HAVE_LIBWRAP -#include "tcpd.h" +extern "C" { +#include +} int allow_severity = LOG_NOTICE; int deny_severity = LOG_WARNING; #endif diff --git a/bacula/src/lib/crypto.c b/bacula/src/lib/crypto.c index f6fa8847df..e256aac442 100644 --- a/bacula/src/lib/crypto.c +++ b/bacula/src/lib/crypto.c @@ -451,13 +451,15 @@ int crypto_keypair_load_cert(X509_KEYPAIR *keypair, const char *file) /* Extract the subjectKeyIdentifier extension field */ if ((keypair->keyid = openssl_cert_keyid(cert)) == NULL) { - Emsg0(M_ERROR, 0, _("Provided certificate does not include the required subjectKeyIdentifier extension.")); + Jmsg0(get_jcr_from_tid(), M_ERROR, 0, + _("Provided certificate does not include the required subjectKeyIdentifier extension.")); goto err; } /* Validate the public key type (only RSA is supported) */ if (EVP_PKEY_type(keypair->pubkey->type) != EVP_PKEY_RSA) { - Emsg1(M_ERROR, 0, _("Unsupported key type provided: %d\n"), EVP_PKEY_type(keypair->pubkey->type)); + Jmsg1(get_jcr_from_tid(), M_ERROR, 0, + _("Unsupported key type provided: %d\n"), EVP_PKEY_type(keypair->pubkey->type)); goto err; } @@ -1020,7 +1022,7 @@ CRYPTO_SESSION *crypto_session_new (crypto_cipher_t cipher, alist *pubkeys) ec = EVP_bf_cbc(); break; default: - Emsg0(M_ERROR, 0, _("Unsupported cipher type specified\n")); + Jmsg0(get_jcr_from_tid(), M_ERROR, 0, _("Unsupported cipher type specified\n")); crypto_session_free(cs); return NULL; } @@ -1263,7 +1265,8 @@ CIPHER_CONTEXT *crypto_cipher_new(CRYPTO_SESSION *cs, bool encrypt, uint32_t *bl * Acquire a cipher instance for the given ASN.1 cipher NID */ if ((ec = EVP_get_cipherbyobj(cs->cryptoData->contentEncryptionAlgorithm)) == NULL) { - Emsg1(M_ERROR, 0, _("Unsupported contentEncryptionAlgorithm: %d\n"), OBJ_obj2nid(cs->cryptoData->contentEncryptionAlgorithm)); + Jmsg1(get_jcr_from_tid(), M_ERROR, 0, + _("Unsupported contentEncryptionAlgorithm: %d\n"), OBJ_obj2nid(cs->cryptoData->contentEncryptionAlgorithm)); free(cipher_ctx); return NULL; } @@ -1366,7 +1369,9 @@ int init_crypto (void) int stat; if ((stat = openssl_init_threads()) != 0) { - Emsg1(M_ABORT, 0, _("Unable to init OpenSSL threading: ERR=%s\n"), strerror(stat)); + berrno be; + Jmsg1(get_jcr_from_tid(), M_ABORT, 0, + _("Unable to init OpenSSL threading: ERR=%s\n"), be.bstrerror(stat)); } /* Load libssl and libcrypto human-readable error strings */ @@ -1379,7 +1384,7 @@ int init_crypto (void) OpenSSL_add_all_algorithms(); if (!openssl_seed_prng()) { - Emsg0(M_ERROR_TERM, 0, _("Failed to seed OpenSSL PRNG\n")); + Jmsg0(get_jcr_from_tid(), M_ERROR_TERM, 0, _("Failed to seed OpenSSL PRNG\n")); } crypto_initialized = true; @@ -1405,7 +1410,7 @@ int cleanup_crypto (void) } if (!openssl_save_prng()) { - Emsg0(M_ERROR, 0, _("Failed to save OpenSSL PRNG\n")); + Jmsg0(get_jcr_from_tid(), M_ERROR, 0, _("Failed to save OpenSSL PRNG\n")); } openssl_cleanup_threads(); @@ -1486,7 +1491,7 @@ bool crypto_digest_update(DIGEST *digest, const uint8_t *data, uint32_t length) if ((ret = SHA1Update(&digest->sha1, (const u_int8_t *) data, length)) == shaSuccess) { return true; } else { - Emsg1(M_ERROR, 0, _("SHA1Update() returned an error: %d\n"), ret); + Jmsg1(get_jcr_from_tid(), M_ERROR, 0, _("SHA1Update() returned an error: %d\n"), ret); return false; } break; diff --git a/bacula/src/lib/jcr.c b/bacula/src/lib/jcr.c index 40d641e103..1bad4fdb23 100644 --- a/bacula/src/lib/jcr.c +++ b/bacula/src/lib/jcr.c @@ -451,6 +451,52 @@ void free_jcr(JCR *jcr) garbage_collect_memory_pool(); Dmsg0(3400, "Exit free_jcr\n"); } + +/* + * Find which JobId corresponds to the current thread + */ +uint32_t get_jobid_from_tid() +{ + return get_jobid_from_tid(pthread_self()); +} + +uint32_t get_jobid_from_tid(pthread_t tid) +{ + JCR *jcr; + uint32_t JobId = 0; + foreach_jcr(jcr) { + if (pthread_equal(jcr->my_thread_id, tid)) { + JobId = (uint32_t)jcr->JobId; + break; + } + } + endeach_jcr(jcr); + return JobId; +} + +/* + * Find the jcr that corresponds to the current thread + */ +JCR *get_jcr_from_tid() +{ + return get_jcr_from_tid(pthread_self()); +} + +JCR *get_jcr_from_tid(pthread_t tid) +{ + JCR *jcr; + JCR *rtn_jcr = NULL; + + foreach_jcr(jcr) { + if (pthread_equal(jcr->my_thread_id, tid)) { + rtn_jcr = jcr; + break; + } + } + endeach_jcr(jcr); + return rtn_jcr; +} + /* diff --git a/bacula/src/lib/openssl.c b/bacula/src/lib/openssl.c index 96ffcb52bf..09d274c74a 100644 --- a/bacula/src/lib/openssl.c +++ b/bacula/src/lib/openssl.c @@ -66,7 +66,7 @@ struct CRYPTO_dynlock_value { */ void openssl_post_errors(int code, const char *errstring) { - openssl_post_errors(NULL, code, errstring); + openssl_post_errors(get_jcr_from_tid(), code, errstring); } @@ -95,6 +95,11 @@ void openssl_post_errors(JCR *jcr, int code, const char *errstring) static unsigned long get_openssl_thread_id(void) { /* Comparison without use of pthread_equal() is mandated by the OpenSSL API */ + /* + * Note that this creates problems with the new Win32 pthreads + * emulation code, which defines pthread_t as a structure. For + * this reason, we continue to use a very old implementation. + */ return ((unsigned long)pthread_self()); } @@ -110,7 +115,8 @@ static struct CRYPTO_dynlock_value *openssl_create_dynamic_mutex (const char *fi if ((stat = pthread_mutex_init(&dynlock->mutex, NULL)) != 0) { berrno be; - Emsg1(M_ABORT, 0, _("Unable to init mutex: ERR=%s\n"), be.bstrerror(stat)); + Jmsg1(get_jcr_from_tid(), M_ABORT, 0, _("Unable to init mutex: ERR=%s\n"), + be.bstrerror(stat)); } return dynlock; @@ -131,7 +137,8 @@ static void openssl_destroy_dynamic_mutex(struct CRYPTO_dynlock_value *dynlock, if ((stat = pthread_mutex_destroy(&dynlock->mutex)) != 0) { berrno be; - Emsg1(M_ABORT, 0, _("Unable to destroy mutex: ERR=%s\n"), be.bstrerror(stat)); + Jmsg1(get_jcr_from_tid(), M_ABORT, 0, _("Unable to destroy mutex: ERR=%s\n"), + be.bstrerror(stat)); } free(dynlock); @@ -169,7 +176,8 @@ int openssl_init_threads (void) for (i = 0; i < numlocks; i++) { if ((stat = pthread_mutex_init(&mutexes[i], NULL)) != 0) { berrno be; - Emsg1(M_ERROR, 0, _("Unable to init mutex: ERR=%s\n"), be.bstrerror(stat)); + Jmsg1(get_jcr_from_tid(), M_ERROR, 0, _("Unable to init mutex: ERR=%s\n"), + be.bstrerror(stat)); return stat; } } @@ -202,7 +210,8 @@ void openssl_cleanup_threads(void) 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"), be.bstrerror(stat)); + Jmsg1(get_jcr_from_tid(), M_ERROR, 0, _("Unable to destroy mutex: ERR=%s\n"), + be.bstrerror(stat)); } } diff --git a/bacula/src/lib/protos.h b/bacula/src/lib/protos.h index 16b87f0e04..d7b5a18b11 100644 --- a/bacula/src/lib/protos.h +++ b/bacula/src/lib/protos.h @@ -198,6 +198,10 @@ void unlock_jobs(); JCR *jcr_walk_start(); JCR *jcr_walk_next(JCR *prev_jcr); void jcr_walk_end(JCR *jcr); +uint32_t get_jobid_from_tid(pthread_t tid); +uint32_t get_jobid_from_tid(); +JCR *get_jcr_from_tid(pthread_t tid); +JCR *get_jcr_from_tid(); /* lex.c */ diff --git a/bacula/src/lib/runscript.h b/bacula/src/lib/runscript.h index 42b1c898d9..451541c3ae 100644 --- a/bacula/src/lib/runscript.h +++ b/bacula/src/lib/runscript.h @@ -1,12 +1,7 @@ -/* - * Bacula RUNSCRIPT Structure definition for FileDaemon and Director - * Eric Bollengier May 2006 - * Version $Id$ - */ /* Bacula® - The Network Backup Solution - Copyright (C) 2006-2006 Free Software Foundation Europe e.V. + Copyright (C) 2006-2007 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. @@ -30,7 +25,12 @@ (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich, Switzerland, email:ftf@fsfeurope.org. */ - +/* + * Bacula RUNSCRIPT Structure definition for FileDaemon and Director + * Eric Bollengier May 2006 + * Version $Id$ + */ + #ifndef __RUNSCRIPT_H_ #define __RUNSCRIPT_H_ 1 @@ -45,7 +45,7 @@ * script->on_failure = true; * script->when = SCRIPT_After; * - * script->run("LabelBefore"); // the label must contain "Before" or "After" special keyword + * script->run("LabelBefore"); // the label must contain "Before" or "After" special keyword * free_runscript(script); */ @@ -66,11 +66,11 @@ class RUNSCRIPT { public: POOLMEM *command; /* command string */ POOLMEM *target; /* host target */ + int when; /* SCRIPT_Before|Script_After BEFORE/AFTER JOB*/ char level; /* Base|Full|Incr...|All (NYI) */ bool on_success; /* executre command on job success (After) */ bool on_failure; /* executre command on job failure (After) */ bool abort_on_error; /* abort job on error (Before) */ - int when; /* SCRIPT_Before|Script_After BEFORE/AFTER JOB*/ /* TODO : drop this with bacula 1.42 */ bool old_proto; /* used by old 1.3X protocol */ diff --git a/bacula/src/lib/signal.c b/bacula/src/lib/signal.c index f395122b31..3b34cd1525 100644 --- a/bacula/src/lib/signal.c +++ b/bacula/src/lib/signal.c @@ -91,7 +91,7 @@ extern "C" void signal_handler(int sig) if (sig == SIGTERM) { // Emsg1(M_TERM, -1, "Shutting down Bacula service: %s ...\n", my_name); } else { - Emsg2(M_FATAL, -1, _("Bacula interrupted by signal %d: %s\n"), sig, sig_names[sig]); + Emsg2(M_FATAL, -1, _("Bacula interrupted by signal %d: %s\n"), sig, get_signal_name(sig)); } #ifdef TRACEBACK @@ -104,8 +104,8 @@ extern "C" void signal_handler(int sig) pid_t pid; int exelen = strlen(exepath); - fprintf(stderr, _("Kaboom! %s, %s got signal %d. Attempting traceback.\n"), - exename, my_name, sig); + fprintf(stderr, _("Kaboom! %s, %s got signal %d - %s. Attempting traceback.\n"), + exename, my_name, sig, get_signal_name(sig)); fprintf(stderr, _("Kaboom! exepath=%s\n"), exepath); if (exelen + 12 > (int)sizeof(btpath)) { @@ -149,7 +149,8 @@ extern "C" void signal_handler(int sig) argv[3] = (char *)NULL; fprintf(stderr, _("Calling: %s %s %s\n"), btpath, exepath, pid_buf); if (execv(btpath, argv) != 0) { - printf(_("execv: %s failed: ERR=%s\n"), btpath, strerror(errno)); + berrno be; + printf(_("execv: %s failed: ERR=%s\n"), btpath, be.bstrerror()); } exit(-1); default: /* parent */ diff --git a/bacula/src/lib/tcpd.h b/bacula/src/lib/tcpd.h deleted file mode 100644 index b8a9ee6434..0000000000 --- a/bacula/src/lib/tcpd.h +++ /dev/null @@ -1,235 +0,0 @@ - /* - * @(#) tcpd.h 1.5 96/03/19 16:22:24 - * - * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands. - */ - -/* - * This version of the file has been hacked over by - * Kern Sibbald to make it compatible with C++ for - * the few functions that Bacula uses. 19 April 2002 - * It now compiles with C++ but remains untested. - * A correct fix would require significantly more work. - */ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Structure to describe one communications endpoint. */ - -#define STRING_LENGTH 128 /* hosts, users, processes */ - -struct host_info { - char name[STRING_LENGTH]; /* access via eval_hostname(host) */ - char addr[STRING_LENGTH]; /* access via eval_hostaddr(host) */ - struct sockaddr_in *sin; /* socket address or 0 */ - struct t_unitdata *unit; /* TLI transport address or 0 */ - struct request_info *request; /* for shared information */ -}; - -/* Structure to describe what we know about a service request. */ - -struct request_info { - int fd; /* socket handle */ - char user[STRING_LENGTH]; /* access via eval_user(request) */ - char daemon[STRING_LENGTH]; /* access via eval_daemon(request) */ - char pid[10]; /* access via eval_pid(request) */ - struct host_info client[1]; /* client endpoint info */ - struct host_info server[1]; /* server endpoint info */ - void (*sink) (); /* datagram sink function or 0 */ - void (*hostname) (); /* address to printable hostname */ - void (*hostaddr) (); /* address to printable address */ - void (*cleanup) (); /* cleanup function or 0 */ - struct netconfig *config; /* netdir handle */ -}; - -/* Common string operations. Less clutter should be more readable. */ - -#define STRN_CPY(d,s,l) { strncpy((d),(s),(l)); (d)[(l)-1] = 0; } - -#define STRN_EQ(x,y,l) (strncasecmp((x),(y),(l)) == 0) -#define STRN_NE(x,y,l) (strncasecmp((x),(y),(l)) != 0) -#define STR_EQ(x,y) (strcasecmp((x),(y)) == 0) -#define STR_NE(x,y) (strcasecmp((x),(y)) != 0) - - /* - * Initially, all above strings have the empty value. Information that - * cannot be determined at runtime is set to "unknown", so that we can - * distinguish between `unavailable' and `not yet looked up'. A hostname - * that we do not believe in is set to "paranoid". - */ - -#define STRING_UNKNOWN "unknown" /* lookup failed */ -#define STRING_PARANOID "paranoid" /* hostname conflict */ - -extern char unknown[]; -extern char paranoid[]; - -#define HOSTNAME_KNOWN(s) (STR_NE((s),unknown) && STR_NE((s),paranoid)) - -#define NOT_INADDR(s) (s[strspn(s,"01234567890./")] != 0) - -/* Global functions. */ - -#if defined(TLI) || defined(PTX) || defined(TLI_SEQUENT) -extern void fromhost(); /* get/validate client host info */ -#else -#define fromhost sock_host /* no TLI support needed */ -#endif - -extern int hosts_access(struct request_info *); /* access control */ -extern void shell_cmd(); /* execute shell command */ -extern char *percent_x(); /* do % expansion */ -extern void rfc931(); /* client name from RFC 931 daemon */ -extern void clean_exit(); /* clean up and exit */ -extern void refuse(); /* clean up and exit */ -extern char *xgets(); /* fgets() on steroids */ -extern char *split_at(); /* strchr() and split */ -extern unsigned long dot_quad_addr(); /* restricted inet_addr() */ - -/* Global variables. */ - -extern int allow_severity; /* for connection logging */ -extern int deny_severity; /* for connection logging */ -extern char *hosts_allow_table; /* for verification mode redirection */ -extern char *hosts_deny_table; /* for verification mode redirection */ -extern int hosts_access_verbose; /* for verbose matching mode */ -extern int rfc931_timeout; /* user lookup timeout */ -extern int resident; /* > 0 if resident process */ - - /* - * Routines for controlled initialization and update of request structure - * attributes. Each attribute has its own key. - */ - -#ifdef __STDC__ -extern struct request_info *request_init(struct request_info *,...); -extern struct request_info *request_set(struct request_info *,...); -#else -extern struct request_info *request_init(); /* initialize request */ -extern struct request_info *request_set(); /* update request structure */ -#endif - -#define RQ_FILE 1 /* file descriptor */ -#define RQ_DAEMON 2 /* server process (argv[0]) */ -#define RQ_USER 3 /* client user name */ -#define RQ_CLIENT_NAME 4 /* client host name */ -#define RQ_CLIENT_ADDR 5 /* client host address */ -#define RQ_CLIENT_SIN 6 /* client endpoint (internal) */ -#define RQ_SERVER_NAME 7 /* server host name */ -#define RQ_SERVER_ADDR 8 /* server host address */ -#define RQ_SERVER_SIN 9 /* server endpoint (internal) */ - - /* - * Routines for delayed evaluation of request attributes. Each attribute - * type has its own access method. The trivial ones are implemented by - * macros. The other ones are wrappers around the transport-specific host - * name, address, and client user lookup methods. The request_info and - * host_info structures serve as caches for the lookup results. - */ - -extern char *eval_user(); /* client user */ -extern char *eval_hostname(); /* printable hostname */ -extern char *eval_hostaddr(); /* printable host address */ -extern char *eval_hostinfo(); /* host name or address */ -extern char *eval_client(struct request_info *); /* whatever is available */ -extern char *eval_server(); /* whatever is available */ -#define eval_daemon(r) ((r)->daemon) /* daemon process name */ -#define eval_pid(r) ((r)->pid) /* process id */ - -/* Socket-specific methods, including DNS hostname lookups. */ - -extern void sock_host(struct request_info *); -extern void sock_hostname(); /* translate address to hostname */ -extern void sock_hostaddr(); /* address to printable address */ -#define sock_methods(r) \ - { (r)->hostname = sock_hostname; (r)->hostaddr = sock_hostaddr; } - -/* The System V Transport-Level Interface (TLI) interface. */ - -#if defined(TLI) || defined(PTX) || defined(TLI_SEQUENT) -extern void tli_host(); /* look up endpoint addresses etc. */ -#endif - - /* - * Problem reporting interface. Additional file/line context is reported - * when available. The jump buffer (tcpd_buf) is not declared here, or - * everyone would have to include . - */ - -#ifdef __STDC__ -extern void tcpd_warn(char *, ...); /* report problem and proceed */ -extern void tcpd_jump(char *, ...); /* report problem and jump */ -#else -extern void tcpd_warn(); -extern void tcpd_jump(); -#endif - -struct tcpd_context { - char *file; /* current file */ - int line; /* current line */ -}; -extern struct tcpd_context tcpd_context; - - /* - * While processing access control rules, error conditions are handled by - * jumping back into the hosts_access() routine. This is cleaner than - * checking the return value of each and every silly little function. The - * (-1) returns are here because zero is already taken by longjmp(). - */ - -#define AC_PERMIT 1 /* permit access */ -#define AC_DENY (-1) /* deny_access */ -#define AC_ERROR AC_DENY /* XXX */ - - /* - * In verification mode an option function should just say what it would do, - * instead of really doing it. An option function that would not return - * should clear the dry_run flag to inform the caller of this unusual - * behavior. - */ - -extern void process_options(); /* execute options */ -extern int dry_run; /* verification flag */ - -/* Bug workarounds. */ - -#ifdef INET_ADDR_BUG /* inet_addr() returns struct */ -#define inet_addr fix_inet_addr -extern long fix_inet_addr(); -#endif - -#ifdef BROKEN_FGETS /* partial reads from sockets */ -#define fgets fix_fgets -extern char *fix_fgets(); -#endif - -#ifdef RECVFROM_BUG /* no address family info */ -#define recvfrom fix_recvfrom -extern int fix_recvfrom(); -#endif - -#ifdef GETPEERNAME_BUG /* claims success with UDP */ -#define getpeername fix_getpeername -extern int fix_getpeername(); -#endif - -#ifdef SOLARIS_24_GETHOSTBYNAME_BUG /* lists addresses as aliases */ -#define gethostbyname fix_gethostbyname -extern struct hostent *fix_gethostbyname(); -#endif - -#ifdef USE_STRSEP /* libc calls strtok() */ -#define strtok fix_strtok -extern char *fix_strtok(); -#endif - -#ifdef LIBC_CALLS_STRTOK /* libc calls strtok() */ -#define strtok my_strtok -extern char *my_strtok(); -#endif - -#ifdef __cplusplus -} -#endif diff --git a/bacula/src/lib/tls.c b/bacula/src/lib/tls.c index d4919c83c1..b6d928e873 100644 --- a/bacula/src/lib/tls.c +++ b/bacula/src/lib/tls.c @@ -90,7 +90,7 @@ static int openssl_verify_peer(int ok, X509_STORE_CTX *store) X509_NAME_oneline(X509_get_issuer_name(cert), issuer, 256); X509_NAME_oneline(X509_get_subject_name(cert), subject, 256); - Emsg5(M_ERROR, 0, _("Error with certificate at depth: %d, issuer = %s," + Jmsg5(get_jcr_from_tid(), M_ERROR, 0, _("Error with certificate at depth: %d, issuer = %s," " subject = %s, ERR=%d:%s\n"), depth, issuer, subject, err, X509_verify_cert_error_string(err)); @@ -153,7 +153,7 @@ TLS_CONTEXT *new_tls_context(const char *ca_certfile, const char *ca_certdir, } } else if (verify_peer) { /* At least one CA is required for peer verification */ - Emsg0(M_ERROR, 0, _("Either a certificate file or a directory must be" + Jmsg0(get_jcr_from_tid(), M_ERROR, 0, _("Either a certificate file or a directory must be" " specified as a verification store\n")); goto err; } @@ -199,7 +199,8 @@ TLS_CONTEXT *new_tls_context(const char *ca_certfile, const char *ca_certdir, } if (SSL_CTX_set_cipher_list(ctx->openssl, TLS_DEFAULT_CIPHERS) != 1) { - Emsg0(M_ERROR, 0, _("Error setting cipher list, no valid ciphers available\n")); + Jmsg0(get_jcr_from_tid(), M_ERROR, 0, + _("Error setting cipher list, no valid ciphers available\n")); goto err; } @@ -258,7 +259,7 @@ bool tls_postconnect_verify_cn(TLS_CONNECTION *tls, alist *verify_list) /* Check if peer provided a certificate */ if (!(cert = SSL_get_peer_certificate(ssl))) { - Emsg0(M_ERROR, 0, _("Peer failed to present a TLS certificate\n")); + Jmsg0(get_jcr_from_tid(), M_ERROR, 0, _("Peer failed to present a TLS certificate\n")); return false; } @@ -300,7 +301,8 @@ bool tls_postconnect_verify_host(TLS_CONNECTION *tls, const char *host) /* Check if peer provided a certificate */ if (!(cert = SSL_get_peer_certificate(ssl))) { - Emsg1(M_ERROR, 0, _("Peer %s failed to present a TLS certificate\n"), host); + Jmsg1(get_jcr_from_tid(), M_ERROR, 0, + _("Peer %s failed to present a TLS certificate\n"), host); return false; } diff --git a/bacula/src/lib/util.c b/bacula/src/lib/util.c index 9cb5e07755..e6ee972a37 100644 --- a/bacula/src/lib/util.c +++ b/bacula/src/lib/util.c @@ -1,10 +1,3 @@ -/* - * util.c miscellaneous utility subroutines for Bacula - * - * Kern Sibbald, MM - * - * Version $Id$ - */ /* Bacula® - The Network Backup Solution @@ -32,6 +25,13 @@ (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich, Switzerland, email:ftf@fsfeurope.org. */ +/* + * util.c miscellaneous utility subroutines for Bacula + * + * Kern Sibbald, MM + * + * Version $Id$ + */ #include "bacula.h" #include "jcr.h" diff --git a/bacula/src/lib/var.c b/bacula/src/lib/var.c index 27bf15d75d..26a9ff1688 100644 --- a/bacula/src/lib/var.c +++ b/bacula/src/lib/var.c @@ -1,26 +1,7 @@ -/* -** OSSP var - Variable Expansion -** Copyright (c) 2001-2002 Ralf S. Engelschall -** Copyright (c) 2001-2002 The OSSP Project (http://www.ossp.org/) -** Copyright (c) 2001-2002 Cable & Wireless Deutschland (http://www.cw.com/de/) -** -** This file is part of OSSP var, a variable expansion -** library which can be found at http://www.ossp.org/pkg/lib/var/. -** -** Permission to use, copy, modify, and distribute this software for -** any purpose with or without fee is hereby granted, provided that -** the above copyright notice and this permission notice appear in all -** copies. -** -** For disclaimer see below. -*/ -/* - * Adapted by Kern Sibbald to Bacula June 2003 - */ /* Bacula® - The Network Backup Solution - Copyright (C) 2003-2006 Free Software Foundation Europe e.V. + Copyright (C) 2003-2007 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. @@ -44,6 +25,25 @@ (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich, Switzerland, email:ftf@fsfeurope.org. */ +/* +** OSSP var - Variable Expansion +** Copyright (c) 2001-2002 Ralf S. Engelschall +** Copyright (c) 2001-2002 The OSSP Project (http://www.ossp.org/) +** Copyright (c) 2001-2002 Cable & Wireless Deutschland (http://www.cw.com/de/) +** +** This file is part of OSSP var, a variable expansion +** library which can be found at http://www.ossp.org/pkg/lib/var/. +** +** Permission to use, copy, modify, and distribute this software for +** any purpose with or without fee is hereby granted, provided that +** the above copyright notice and this permission notice appear in all +** copies. +** +** For disclaimer see below. +*/ +/* + * Adapted by Kern Sibbald to Bacula June 2003 + */ #include "bacula.h" #if defined(HAVE_PCREPOSIX) diff --git a/bacula/src/lib/workq.c b/bacula/src/lib/workq.c index fbf880b2f1..2322d772e1 100644 --- a/bacula/src/lib/workq.c +++ b/bacula/src/lib/workq.c @@ -1,3 +1,30 @@ +/* + Bacula® - The Network Backup Solution + + Copyright (C) 2001-2007 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 two of the GNU General Public + License as published by the Free Software Foundation plus additions + that are listed 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 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 John Walker. + The licensor of Bacula is the Free Software Foundation Europe + (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich, + Switzerland, email:ftf@fsfeurope.org. +*/ /* * Bacula work queue routines. Permits passing work to * multiple threads. @@ -29,33 +56,6 @@ * workq_destroy(workq_t *wq); * */ -/* - Bacula® - The Network Backup Solution - - Copyright (C) 2001-2006 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 two of the GNU General Public - License as published by the Free Software Foundation plus additions - that are listed 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 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 John Walker. - The licensor of Bacula is the Free Software Foundation Europe - (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich, - Switzerland, email:ftf@fsfeurope.org. -*/ #include "bacula.h" diff --git a/bacula/src/qt-console/console/console.cpp b/bacula/src/qt-console/console/console.cpp index e09239ed63..dbbc6f38df 100644 --- a/bacula/src/qt-console/console/console.cpp +++ b/bacula/src/qt-console/console/console.cpp @@ -548,7 +548,7 @@ int Console::write(const char *msg) void Console::beginNewCommand() { for (int i=0; i < 3; i++) { - write(".\n"); + write("."); while (read() > 0) { if (mainWin->m_displayAll) display_text(msg()); } @@ -622,11 +622,13 @@ int Console::read() if (mainWin->m_commDebug) Pmsg0(000, "CMD OK\n"); m_at_prompt = false; m_at_main_prompt = false; + mainWin->set_status(_("Command completed ...")); continue; case BNET_CMD_BEGIN: if (mainWin->m_commDebug) Pmsg0(000, "CMD BEGIN\n"); m_at_prompt = false; m_at_main_prompt = false; + mainWin->set_status(_("Processing command ...")); continue; case BNET_MAIN_PROMPT: if (mainWin->m_commDebug) Pmsg0(000, "MAIN PROMPT\n"); @@ -752,7 +754,7 @@ bool Console::is_connectedGui() return true; } else { QString message("Director "); - message += " is curerntly disconnected\n Please reconnect!!"; + message += " is currently disconnected\n Please reconnect!!"; QMessageBox::warning(this, "Bat", tr(message.toUtf8().data()), QMessageBox::Ok ); return false; @@ -768,14 +770,14 @@ bool Console::preventInUseConnect() if (!is_connected()) { QString message("Director "); message += m_dir->name(); - message += " is curerntly disconnected\n Please reconnect!!"; + message += " is currently disconnected\n Please reconnect!!"; QMessageBox::warning(this, "Bat", tr(message.toUtf8().data()), QMessageBox::Ok ); return false; } else if (!m_at_main_prompt){ QString message("Director "); message += m_dir->name(); - message += " is curerntly busy\n Please complete restore or other " + message += " is currently busy\n Please complete restore or other " " operation !! This is a limitation that will be resolved before a beta" " release. This is currently an alpha release."; QMessageBox::warning(this, "Bat", @@ -784,7 +786,7 @@ bool Console::preventInUseConnect() } else if (!m_at_prompt){ QString message("Director "); message += m_dir->name(); - message += " is curerntly not at a prompt\n Please try again!!"; + message += " is currently not at a prompt\n Please try again!!"; QMessageBox::warning(this, "Bat", tr(message.toUtf8().data()), QMessageBox::Ok ); return false; diff --git a/bacula/src/qt-console/select/select.cpp b/bacula/src/qt-console/select/select.cpp index 8772bbdb85..0dcca93d70 100644 --- a/bacula/src/qt-console/select/select.cpp +++ b/bacula/src/qt-console/select/select.cpp @@ -38,7 +38,7 @@ #include "select.h" /* - * Setup all the combo boxes and display the dialog + * Read the items for the selection */ selectDialog::selectDialog(Console *console) { @@ -50,6 +50,7 @@ selectDialog::selectDialog(Console *console) m_console = console; setupUi(this); connect(listBox, SIGNAL(currentRowChanged(int)), this, SLOT(index_change(int))); + setAttribute(Qt::WA_DeleteOnClose); m_console->read(); /* get title */ labelWidget->setText(m_console->msg()); while ((stat=m_console->read()) > 0) { @@ -57,10 +58,7 @@ selectDialog::selectDialog(Console *console) item->setText(m_console->msg()); listBox->insertItem(row++, item); } -// Dmsg1(000, "Stat=%d\n", stat); - m_console->read(); /* get prompt signal */ - m_console->read(); /* get prompt */ -// Dmsg1(000, "Prompt=%s", m_console->msg()); + m_console->displayToPrompt(); this->show(); } @@ -69,21 +67,23 @@ void selectDialog::accept() char cmd[100]; this->hide(); - bsnprintf(cmd, sizeof(cmd), "%d", m_index+1); m_console->write_dir(cmd); m_console->displayToPrompt(); - delete this; + this->close(); mainWin->resetFocus(); + m_console->displayToPrompt(); + } void selectDialog::reject() { - mainWin->set_status(" Canceled"); this->hide(); - delete this; + mainWin->set_status(" Canceled"); + this->close(); mainWin->resetFocus(); + m_console->beginNewCommand(); } /* @@ -93,6 +93,5 @@ void selectDialog::reject() */ void selectDialog::index_change(int index) { -// Dmsg1(000, "Index=%d\n", index); m_index = index; } diff --git a/bacula/src/stored/device.c b/bacula/src/stored/device.c index 9a77cdf722..b8c77b142c 100644 --- a/bacula/src/stored/device.c +++ b/bacula/src/stored/device.c @@ -323,22 +323,6 @@ bool open_device(DCR *dcr) return true; } -/* - * Find which JobId corresponds to the current thread - */ -uint32_t get_jobid_from_tid(pthread_t tid) -{ - JCR *jcr; - uint32_t JobId = 0; - foreach_jcr(jcr) { - if (pthread_equal(jcr->my_thread_id, tid)) { - JobId = (uint32_t)jcr->JobId; - break; - } - } - endeach_jcr(jcr); - return JobId; -} /* * Check if the device is blocked or not @@ -356,14 +340,14 @@ bool is_device_unmounted(DEVICE *dev) void DEVICE::_dlock(const char *file, int line) { Dmsg4(sd_dbglvl, "dlock from %s:%d precnt=%d JobId=%u\n", file, line, - m_count, get_jobid_from_tid(pthread_self())); + m_count, get_jobid_from_tid()); /* Note, this *really* should be protected by a mutex, but * since it is only debug code we don't worry too much. */ if (m_count > 0 && pthread_equal(m_pid, pthread_self())) { Dmsg5(sd_dbglvl, "Possible DEADLOCK!! lock held by JobId=%u from %s:%d m_count=%d JobId=%u\n", get_jobid_from_tid(m_pid), - file, line, m_count, get_jobid_from_tid(pthread_self())); + file, line, m_count, get_jobid_from_tid()); } P(m_mutex); m_pid = pthread_self(); @@ -374,7 +358,7 @@ void DEVICE::_dunlock(const char *file, int line) { m_count--; Dmsg4(sd_dbglvl+1, "dunlock from %s:%d postcnt=%d JobId=%u\n", file, line, - m_count, get_jobid_from_tid(pthread_self())); + m_count, get_jobid_from_tid()); V(m_mutex); } @@ -402,7 +386,7 @@ void DEVICE::r_dlock() int stat; #ifdef SD_DEBUG_LOCK Dmsg4(sd_dbglvl+1, "r_dlock blked=%s from %s:%d JobId=%u\n", this->print_blocked(), - file, line, get_jobid_from_tid(pthread_self())); + file, line, get_jobid_from_tid()); #else Dmsg1(sd_dbglvl, "reclock blked=%s\n", this->print_blocked()); #endif diff --git a/bacula/src/stored/protos.h b/bacula/src/stored/protos.h index dff2b02dcb..deb8d6c706 100644 --- a/bacula/src/stored/protos.h +++ b/bacula/src/stored/protos.h @@ -135,7 +135,6 @@ void _give_back_device_lock(const char *file, int line, DEVICE *dev, bsteal_ void set_new_volume_parameters(DCR *dcr); void set_new_file_parameters(DCR *dcr); bool is_device_unmounted(DEVICE *dev); -uint32_t get_jobid_from_tid(pthread_t tid); /* From dircmd.c */ void *handle_connection_request(void *arg); diff --git a/bacula/technotes-2.1 b/bacula/technotes-2.1 index ca29a66065..05a21b0dc7 100644 --- a/bacula/technotes-2.1 +++ b/bacula/technotes-2.1 @@ -1,6 +1,21 @@ Technical notes on version 2.1 General: +07Jun07 +kes Fix sscanf problems reported by Peter Buschman that caused + a bus error on Solaris. +kes Rework (simplify) the select prompt in bat. +kes Move get_jobid_from_tid() into lib and create a + get_jcr_from_tid(). +kes Use get_jcr_from_tid() to conver all tls Emsg() to Jmsg(). This + should definitely fix the problem of lost error messages in the + encryption code. +kes Remove over zellous addition of FSFE copyright in a few eggxxx files. +kes Eliminate tcpd.h from the project. Enclose the #include from the + library with extern C ... +kes Add print of signal name when a signal is trapped. + +Release: 2.1.12 beta 04Jun07 kes Fix a seg fault in the PostgreSQL driver dereferencing a NULL pointer. 03Jun07 -- 2.39.2