bs->fsend(OK_msg);/* send response */
return n; /* end of data */
case BNET_TERMINATE:
- bs->m_terminated = 1;
+ bs->set_terminated();
return n;
case BNET_POLL:
bs->fsend(OK_msg); /* send response */
V(mutex);
if (job_canceled(jcr)) {
if (jcr->SD_msg_chan) {
- jcr->store_bsock->m_timed_out = 1;
- jcr->store_bsock->m_terminated = 1;
+ jcr->store_bsock->set_timed_out();
+ jcr->store_bsock->set_terminated();
Dmsg2(400, "kill jobid=%d use=%d\n", (int)jcr->JobId, jcr->use_count());
pthread_kill(jcr->SD_msg_chan, TIMEOUT_SIGNAL);
}
}
if (jcr->hb_bsock) {
- jcr->hb_bsock->m_timed_out = true; /* set timed_out to terminate read */
- jcr->hb_bsock->m_terminated = true; /* set to terminate read */
+ jcr->hb_bsock->set_timed_out(); /* set timed_out to terminate read */
+ jcr->hb_bsock->set_terminated(); /* set to terminate read */
}
if (jcr->hb_dir_bsock) {
- jcr->hb_dir_bsock->m_timed_out = true; /* set timed_out to terminate read */
- jcr->hb_dir_bsock->m_terminated = true; /* set to terminate read */
+ jcr->hb_dir_bsock->set_timed_out(); /* set timed_out to terminate read */
+ jcr->hb_dir_bsock->set_terminated(); /* set to terminate read */
}
Dmsg0(100, "Send kill to heartbeat id\n");
pthread_kill(jcr->heartbeat_id, TIMEOUT_SIGNAL); /* make heartbeat thread go away */
bnet_fsend(dir, _("2901 Job %s not found.\n"), Job);
} else {
if (cjcr->store_bsock) {
- cjcr->store_bsock->m_timed_out = 1;
- cjcr->store_bsock->m_terminated = 1;
+ cjcr->store_bsock->set_timed_out();
+ cjcr->store_bsock->set_terminated();
pthread_kill(cjcr->my_thread_id, TIMEOUT_SIGNAL);
}
set_jcr_job_status(cjcr, JS_Canceled);
uint32_t StartBlock;
uint32_t EndBlock;
pthread_t heartbeat_id; /* id of heartbeat thread */
- volatile BSOCK *hb_bsock; /* duped SD socket */
- volatile BSOCK *hb_dir_bsock; /* duped DIR socket */
+ BSOCK *hb_bsock; /* duped SD socket */
+ BSOCK *hb_dir_bsock; /* duped DIR socket */
alist *RunScripts; /* Commands to run before and after job */
bool pki_sign; /* Enable PKI Signatures? */
bool pki_encrypt; /* Enable PKI Encryption? */
{
int32_t nleft, nwritten;
- if (bsock->m_spool) {
+ if (bsock->is_spooling()) {
nwritten = fwrite(ptr, 1, nbytes, bsock->m_spool_fd);
if (nwritten != nbytes) {
berrno be;
if (osock->host()) {
bsock->set_host(bstrdup(osock->host()));
}
- bsock->m_duped = true;
+ bsock->set_duped();
return bsock;
}
/* send data packet */
timer_start = watchdog_time; /* start timer */
- m_timed_out = 0;
+ clear_timed_out();
/* Full I/O done in one write */
rc = write_nbytes(this, (char *)hdr, pktsiz);
timer_start = 0; /* clear timer */
read_seqno++; /* bump sequence number */
timer_start = watchdog_time; /* set start wait time */
- m_timed_out = 0;
+ clear_timed_out();
/* get data size -- in int32_t */
if ((nbytes = read_nbytes(this, (char *)&pktsiz, sizeof(int32_t))) <= 0) {
timer_start = 0; /* clear timer */
}
timer_start = watchdog_time; /* set start wait time */
- m_timed_out = 0;
+ clear_timed_out();
/* now read the actual data */
if ((nbytes = read_nbytes(this, msg, pktsiz)) <= 0) {
timer_start = 0; /* clear timer */
char *m_host; /* Host name/IP */
int m_port; /* desired port */
btimer_t *m_tid; /* timer id */
+ volatile bool m_timed_out: 1; /* timed out in read/write */
+ volatile bool m_terminated: 1; /* set when BNET_TERMINATE arrives */
+ bool m_duped: 1; /* set if duped BSOCK */
+ bool m_spool: 1; /* set for spooling */
void fin_init(JCR * jcr, int sockfd, const char *who, const char *host, int port,
struct sockaddr *lclient_addr);
int m_blocking; /* blocking state (0 = nonblocking, 1 = blocking) */
volatile int errors; /* incremented for each error on socket */
volatile bool m_suppress_error_msgs: 1; /* set to suppress error messages */
- volatile bool m_timed_out: 1; /* timed out in read/write */
- volatile bool m_terminated: 1; /* set when BNET_TERMINATE arrives */
- bool m_duped: 1; /* set if duped BSOCK */
- bool m_spool: 1; /* set for spooling */
volatile time_t timer_start; /* time started read/write */
volatile time_t timeout; /* timeout BSOCK after this interval */
POOLMEM *msg; /* message pool buffer */
int port() { return m_port; };
JCR *jcr() { return m_jcr; };
JCR *get_jcr() { return m_jcr; };
+ bool is_spooling() { return m_spool; };
+ bool is_duped() { return m_duped; };
bool is_terminated() { return m_terminated; };
bool is_timed_out() { return m_timed_out; };
+ void set_spooling() { m_spool = true; };
+ void clear_spooling() { m_spool = false; };
+ void set_duped() { m_duped = true; };
+ void set_timed_out() { m_timed_out = true; };
+ void clear_timed_out() { m_timed_out = false; };
void set_terminated() { m_terminated = true; };
void start_timer(int sec) { m_tid = start_bsock_timer(this, sec); };
void stop_timer() { stop_bsock_timer(m_tid); };
wid->type == TYPE_BSOCK ? "bsock" : "thread", wid->tid, time(NULL));
if (wid->type == TYPE_BSOCK && wid->bsock) {
- wid->bsock->m_timed_out = true;
+ wid->bsock->set_timed_out();
}
pthread_kill(wid->tid, TIMEOUT_SIGNAL);
}
timer_start = fd->timer_start;
if (timer_start && (watchdog_time - timer_start) > fd->timeout) {
fd->timer_start = 0; /* turn off timer */
- fd->m_timed_out = true;
+ fd->set_timed_out();
Jmsg(jcr, M_ERROR, 0, _(
"Watchdog sending kill after %d secs to thread stalled reading Storage daemon.\n"),
watchdog_time - timer_start);
timer_start = fd->timer_start;
if (timer_start && (watchdog_time - timer_start) > fd->timeout) {
fd->timer_start = 0; /* turn off timer */
- fd->m_timed_out = true;
+ fd->set_timed_out();
Jmsg(jcr, M_ERROR, 0, _(
"Watchdog sending kill after %d secs to thread stalled reading File daemon.\n"),
watchdog_time - timer_start);
timer_start = fd->timer_start;
if (timer_start && (watchdog_time - timer_start) > fd->timeout) {
fd->timer_start = 0; /* turn off timer */
- fd->m_timed_out = true;
+ fd->set_timed_out();
Jmsg(jcr, M_ERROR, 0, _(
"Watchdog sending kill after %d secs to thread stalled reading Director.\n"),
watchdog_time - timer_start);
-/*
- * tls.c TLS support functions
- *
- * Author: Landon Fuller <landonf@threerings.net>
- *
- * Version $Id$
- *
- * This file was contributed to the Bacula project by Landon Fuller
- * and Three Rings Design, Inc.
- *
- * Three Rings Design, Inc. has been granted a perpetual, worldwide,
- * non-exclusive, no-charge, royalty-free, irrevocable copyright
- * license to reproduce, prepare derivative works of, publicly
- * display, publicly perform, sublicense, and distribute the original
- * work contributed by Three Rings Design, Inc. and its employees to
- * the Bacula project in source or object form.
- *
- * If you wish to license contributions from Three Rings Design, Inc,
- * under an alternate open source license please contact
- * Landon Fuller <landonf@threerings.net>.
- */
/*
Bacula® - The Network Backup Solution
(FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
Switzerland, email:ftf@fsfeurope.org.
*/
+/*
+ * tls.c TLS support functions
+ *
+ * Author: Landon Fuller <landonf@threerings.net>
+ *
+ * Version $Id$
+ *
+ * This file was contributed to the Bacula project by Landon Fuller
+ * and Three Rings Design, Inc.
+ *
+ * Three Rings Design, Inc. has been granted a perpetual, worldwide,
+ * non-exclusive, no-charge, royalty-free, irrevocable copyright
+ * license to reproduce, prepare derivative works of, publicly
+ * display, publicly perform, sublicense, and distribute the original
+ * work contributed by Three Rings Design, Inc. and its employees to
+ * the Bacula project in source or object form.
+ *
+ * If you wish to license contributions from Three Rings Design, Inc,
+ * under an alternate open source license please contact
+ * Landon Fuller <landonf@threerings.net>.
+ */
#include "bacula.h"
BIO_free(bio);
SSL_free(tls->openssl);
free(tls);
-
return NULL;
}
fdmax = bsock->m_fd + 1;
/* Ensure that socket is non-blocking */
- flags = bnet_set_nonblocking(bsock);
+ flags = bsock->set_nonblocking();
/* start timer */
bsock->timer_start = watchdog_time;
- bsock->m_timed_out = 0;
+ bsock->set_timed_out(false);
for (;;) {
if (server) {
cleanup:
/* Restore saved flags */
- bnet_restore_blocking(bsock, flags);
+ bsock->restore_blocking(flags);
/* Clear timer */
bsock->timer_start = 0;
bool tls_bsock_connect(BSOCK *bsock)
{
/* SSL_connect(bsock->tls) */
- return (openssl_bsock_session_start(bsock, false));
+ return openssl_bsock_session_start(bsock, false);
}
/*
bool tls_bsock_accept(BSOCK *bsock)
{
/* SSL_accept(bsock->tls) */
- return (openssl_bsock_session_start(bsock, true));
+ return openssl_bsock_session_start(bsock, true);
}
/*
err = SSL_shutdown(bsock->tls->openssl);
switch (SSL_get_error(bsock->tls->openssl, err)) {
- case SSL_ERROR_NONE:
- break;
- case SSL_ERROR_ZERO_RETURN:
- /* TLS connection was shut down on us via a TLS protocol-level closure */
- openssl_post_errors(M_ERROR, _("TLS shutdown failure."));
- break;
- default:
- /* Socket Error Occured */
- openssl_post_errors(M_ERROR, _("TLS shutdown failure."));
- break;
+ case SSL_ERROR_NONE:
+ break;
+ case SSL_ERROR_ZERO_RETURN:
+ /* TLS connection was shut down on us via a TLS protocol-level closure */
+ openssl_post_errors(M_ERROR, _("TLS shutdown failure."));
+ break;
+ default:
+ /* Socket Error Occured */
+ openssl_post_errors(M_ERROR, _("TLS shutdown failure."));
+ break;
}
/* Restore saved flags */
/* start timer */
bsock->timer_start = watchdog_time;
- bsock->m_timed_out = 0;
+ bsock->set_timed_out(false);
nleft = nbytes;
while (nleft > 0) {
-
if (write) {
nwritten = SSL_write(tls->openssl, ptr, nleft);
} else {
ptr += nwritten;
}
break;
- case SSL_ERROR_ZERO_RETURN:
- /* TLS connection was cleanly shut down */
- openssl_post_errors(M_ERROR, _("TLS read/write failure."));
- goto cleanup;
+
case SSL_ERROR_WANT_READ:
- /* If we timeout of a select, this will be unset */
- FD_SET((unsigned) bsock->m_fd, &fdset);
- tv.tv_sec = 10;
- tv.tv_usec = 0;
- /* Block until we can read */
- select(fdmax, &fdset, NULL, &fdset, &tv);
- break;
case SSL_ERROR_WANT_WRITE:
- /* If we timeout of a select, this will be unset */
- FD_SET((unsigned) bsock->m_fd, &fdset);
+ /* If we timeout on a select, this will be unset */
+ FD_SET((unsigned)bsock->m_fd, &fdset);
tv.tv_sec = 10;
tv.tv_usec = 0;
- /* Block until we can write */
+ /* Block until we can read or write */
select(fdmax, NULL, &fdset, &fdset, &tv);
break;
+
+ case SSL_ERROR_ZERO_RETURN:
+ /* TLS connection was cleanly shut down */
+ /* Fall through wanted */
default:
/* Socket Error Occured */
openssl_post_errors(M_ERROR, _("TLS read/write failure."));
/* Clear timer */
bsock->timer_start = 0;
-
return nbytes - nleft;
}
-int tls_bsock_writen(BSOCK *bsock, char *ptr, int32_t nbytes) {
+int tls_bsock_writen(BSOCK *bsock, char *ptr, int32_t nbytes)
+{
/* SSL_write(bsock->tls->openssl, ptr, nbytes) */
- return (openssl_bsock_readwrite(bsock, ptr, nbytes, true));
+ return openssl_bsock_readwrite(bsock, ptr, nbytes, true);
}
-int tls_bsock_readn(BSOCK *bsock, char *ptr, int32_t nbytes) {
+int tls_bsock_readn(BSOCK *bsock, char *ptr, int32_t nbytes)
+{
/* SSL_read(bsock->tls->openssl, ptr, nbytes) */
- return (openssl_bsock_readwrite(bsock, ptr, nbytes, false));
+ return openssl_bsock_readwrite(bsock, ptr, nbytes, false);
}
#else /* HAVE_OPENSSL */
# error No TLS implementation available.
#endif /* !HAVE_OPENSSL */
-#else
+
+#else /* TLS NOT enabled, dummy routines substituted */
+
/* Dummy routines */
TLS_CONTEXT *new_tls_context(const char *ca_certfile, const char *ca_certdir,
crypto_digest_stream_type(stream) != CRYPTO_DIGEST_NONE) {
if (!jcr->no_attributes) {
if (are_attributes_spooled(jcr)) {
- jcr->dir_bsock->m_spool = true;
+ jcr->dir_bsock->set_spooling();
}
Dmsg0(850, "Send attributes to dir.\n");
if (!dir_update_file_attributes(dcr, &rec)) {
- jcr->dir_bsock->m_spool = false;
+ jcr->dir_bsock->clear_spooling();
Jmsg(jcr, M_FATAL, 0, _("Error updating file attributes. ERR=%s\n"),
bnet_strerror(jcr->dir_bsock));
ok = false;
break;
}
- jcr->dir_bsock->m_spool = false;
+ jcr->dir_bsock->clear_spooling();
}
}
Dmsg0(650, "Enter bnet_get\n");
crypto_digest_stream_type(stream) != CRYPTO_DIGEST_NONE) {
if (!jcr->no_attributes) {
if (are_attributes_spooled(jcr)) {
- jcr->dir_bsock->m_spool = true;
+ jcr->dir_bsock->set_spooling();
}
Dmsg0(850, "Send attributes to dir.\n");
if (!dir_update_file_attributes(jcr->dcr, rec)) {
- jcr->dir_bsock->m_spool = false;
+ jcr->dir_bsock->clear_spooling();
Jmsg(jcr, M_FATAL, 0, _("Error updating file attributes. ERR=%s\n"),
bnet_strerror(jcr->dir_bsock));
return false;
}
- jcr->dir_bsock->m_spool = false;
+ jcr->dir_bsock->clear_spooling();
}
}
unlink(name);
free_pool_memory(name);
bs->m_spool_fd = NULL;
- bs->m_spool = false;
+ bs->clear_spooling();
return true;
}
set_jcr_job_status(jcr, JS_Canceled);
fd = jcr->file_bsock;
if (fd) {
- fd->m_timed_out = true;
+ fd->set_timed_out();
Dmsg1(100, "term_stored killing JobId=%d\n", jcr->JobId);
pthread_kill(jcr->my_thread_id, TIMEOUT_SIGNAL);
/* ***FIXME*** wiffle through all dcrs */
#undef VERSION
#define VERSION "2.1.21"
-#define BDATE "21 June 2007"
-#define LSMDATE "21Jun07"
+#define BDATE "23 June 2007"
+#define LSMDATE "23Jun07"
#define PROG_COPYRIGHT "Copyright (C) %d-2007 Free Software Foundation Europe e.V.\n"
#define BYEAR "2007" /* year for copyright messages in progs */
Technical notes on version 2.1
General:
+23Jun07
+kes Remove some duplicated code in tls.c
+kes Move more of the bsock member variables into private and access
+ them with methods.
+kes Add Frank Sweetser's tls-test to the regression suite.
22Jun07
kes Add Swedish sv.po file
21Jun07