/* Allocate buffer */
jcr->pki_session_encoded = (uint8_t *)malloc(size);
- if (!jcr->pki_session_encoded) {
- return 0;
- }
/* Encode session data */
if (crypto_session_encode(jcr->pki_session, jcr->pki_session_encoded, &size) == false) {
stop_heartbeat_monitor(jcr);
- bnet_sig(sd, BNET_EOD); /* end of sending data */
+ sd->signal(BNET_EOD); /* end of sending data */
if (jcr->big_buf) {
free(jcr->big_buf);
}
if (jcr->pki_session_encoded) {
free(jcr->pki_session_encoded);
+ jcr->pki_session_encoded = NULL;
}
Dmsg1(100, "end blast_data ok=%d\n", ok);
DIGEST *signing_digest = NULL;
int digest_stream = STREAM_NONE;
SIGNATURE *sig = NULL;
- uint8_t *buf = NULL;
bool has_file_data = false;
// TODO landonf: Allow the user to specify the digest algorithm
#ifdef HAVE_SHA2
if (has_file_data) {
/*
* Setup for digest handling. If this fails, the digest will be set to NULL
- * and not used.
+ * and not used. Note, the digest (file hash) can be any one of the four
+ * algorithms below.
+ *
+ * The signing digest is a single algorithm depending on
+ * whether or not we have SHA2.
+ * ****FIXME**** the signing algoritm should really be
+ * determined a different way!!!!!! What happens if
+ * sha2 was available during backup but not restore?
*/
if (ff_pkt->flags & FO_MD5) {
digest = crypto_digest_new(jcr, CRYPTO_DIGEST_MD5);
if (has_file_data && jcr->pki_encrypt) {
/* Send our header */
Dmsg2(100, "Send hdr fi=%ld stream=%d\n", jcr->JobFiles, STREAM_ENCRYPTED_SESSION_DATA);
- bnet_fsend(sd, "%ld %d 0", jcr->JobFiles, STREAM_ENCRYPTED_SESSION_DATA);
+ sd->fsend("%ld %d 0", jcr->JobFiles, STREAM_ENCRYPTED_SESSION_DATA);
/* Grow the bsock buffer to fit our message if necessary */
if (sizeof_pool_memory(sd->msg) < jcr->pki_session_encoded_size) {
jcr->JobBytes += sd->msglen;
Dmsg1(100, "Send data len=%d\n", sd->msglen);
- bnet_send(sd);
- bnet_sig(sd, BNET_EOD);
+ sd->send();
+ sd->signal(BNET_EOD);
}
/*
}
Dmsg1(300, "Saving Finder Info for \"%s\"\n", ff_pkt->fname);
- bnet_fsend(sd, "%ld %d 0", jcr->JobFiles, STREAM_HFSPLUS_ATTRIBUTES);
+ sd->fsend("%ld %d 0", jcr->JobFiles, STREAM_HFSPLUS_ATTRIBUTES);
Dmsg1(300, "bfiled>stored:header %s\n", sd->msg);
memcpy(sd->msg, ff_pkt->hfsinfo.fndrinfo, 32);
sd->msglen = 32;
if (signing_digest) {
crypto_digest_update(signing_digest, (uint8_t *)sd->msg, sd->msglen);
}
- bnet_send(sd);
- bnet_sig(sd, BNET_EOD);
+ sd->send();
+ sd->signal(BNET_EOD);
}
#endif
goto bail_out;
}
- if (crypto_sign_add_signer(sig, signing_digest, jcr->pki_keypair) == false) {
+ if (!crypto_sign_add_signer(sig, signing_digest, jcr->pki_keypair)) {
Jmsg(jcr, M_FATAL, 0, _("An error occurred while signing the stream.\n"));
goto bail_out;
}
/* Get signature size */
- if (crypto_sign_encode(sig, NULL, &size) == false) {
+ if (!crypto_sign_encode(sig, NULL, &size)) {
Jmsg(jcr, M_FATAL, 0, _("An error occurred while signing the stream.\n"));
goto bail_out;
}
- /* Allocate signature data buffer */
- buf = (uint8_t *)malloc(size);
- if (!buf) {
- goto bail_out;
- }
-
- /* Encode signature data */
- if (crypto_sign_encode(sig, buf, &size) == false) {
- Jmsg(jcr, M_FATAL, 0, _("An error occurred while signing the stream.\n"));
- goto bail_out;
+ /* Grow the bsock buffer to fit our message if necessary */
+ if (sizeof_pool_memory(sd->msg) < (int32_t)size) {
+ sd->msg = realloc_pool_memory(sd->msg, size);
}
/* Send our header */
- bnet_fsend(sd, "%ld %d 0", jcr->JobFiles, STREAM_SIGNED_DIGEST);
+ sd->fsend("%ld %d 0", jcr->JobFiles, STREAM_SIGNED_DIGEST);
Dmsg1(300, "bfiled>stored:header %s\n", sd->msg);
- /* Grow the bsock buffer to fit our message if necessary */
- if (sizeof_pool_memory(sd->msg) < (int32_t)size) {
- sd->msg = realloc_pool_memory(sd->msg, size);
+ /* Encode signature data */
+ if (!crypto_sign_encode(sig, (uint8_t *)sd->msg, &size)) {
+ Jmsg(jcr, M_FATAL, 0, _("An error occurred while signing the stream.\n"));
+ goto bail_out;
}
- /* Copy our message over and send it */
- memcpy(sd->msg, buf, size);
sd->msglen = size;
- bnet_send(sd);
- bnet_sig(sd, BNET_EOD); /* end of checksum */
+ sd->send();
+ sd->signal(BNET_EOD); /* end of checksum */
}
/* Terminate any digest and send it to Storage daemon and the Director */
if (digest) {
- uint8_t md[CRYPTO_DIGEST_MAX_SIZE];
uint32_t size;
- size = sizeof(md);
+ sd->fsend("%ld %d 0", jcr->JobFiles, digest_stream);
+ Dmsg1(300, "bfiled>stored:header %s\n", sd->msg);
+
+ size = sizeof(CRYPTO_DIGEST_MAX_SIZE);
+ /* Grow the bsock buffer to fit our message if necessary */
+ if (sizeof_pool_memory(sd->msg) < (int32_t)size) {
+ sd->msg = realloc_pool_memory(sd->msg, size);
+ }
- if (crypto_digest_finalize(digest, md, &size)) {
- bnet_fsend(sd, "%ld %d 0", jcr->JobFiles, digest_stream);
- Dmsg1(300, "bfiled>stored:header %s\n", sd->msg);
- memcpy(sd->msg, md, size);
- sd->msglen = size;
- bnet_send(sd);
- bnet_sig(sd, BNET_EOD); /* end of checksum */
+ if (!crypto_digest_finalize(digest, (uint8_t *)sd->msg, &size)) {
+ Jmsg(jcr, M_FATAL, 0, _("An error occurred finalizing signing the stream.\n"));
+ goto bail_out;
}
+
+ sd->msglen = size;
+ sd->send();
+ sd->signal(BNET_EOD); /* end of checksum */
}
good_rtn:
if (sig) {
crypto_sign_free(sig);
}
- if (buf) {
- free(buf);
- }
return rtnstat;
}
* Send Data header to Storage daemon
* <file-index> <stream> <info>
*/
- if (!bnet_fsend(sd, "%ld %d 0", jcr->JobFiles, stream)) {
+ if (!sd->fsend("%ld %d 0", jcr->JobFiles, stream)) {
Jmsg1(jcr, M_FATAL, 0, _("Network send error to SD. ERR=%s\n"),
- bnet_strerror(sd));
+ sd->bstrerror());
goto err;
}
Dmsg1(300, ">stored: datahdr %s\n", sd->msg);
sd->msglen += SPARSE_FADDR_SIZE; /* include fileAddr in size */
}
sd->msg = wbuf; /* set correct write buffer */
- if (!bnet_send(sd)) {
+ if (!sd->send()) {
Jmsg1(jcr, M_FATAL, 0, _("Network send error to SD. ERR=%s\n"),
- bnet_strerror(sd));
+ sd->bstrerror());
goto err;
}
Dmsg1(130, "Send data to SD len=%d\n", sd->msglen);
if (encrypted_len > 0) {
sd->msglen = encrypted_len; /* set encrypted length */
sd->msg = jcr->crypto_buf; /* set correct write buffer */
- if (!bnet_send(sd)) {
+ if (!sd->send()) {
Jmsg1(jcr, M_FATAL, 0, _("Network send error to SD. ERR=%s\n"),
- bnet_strerror(sd));
+ sd->bstrerror());
goto err;
}
Dmsg1(130, "Send data to SD len=%d\n", sd->msglen);
}
}
- if (!bnet_sig(sd, BNET_EOD)) { /* indicate end of file data */
+ if (!sd->signal(BNET_EOD)) { /* indicate end of file data */
Jmsg1(jcr, M_FATAL, 0, _("Network send error to SD. ERR=%s\n"),
- bnet_strerror(sd));
+ sd->bstrerror());
goto err;
}
}
/* Send header */
- if (!bnet_fsend(sd, "%ld %d 0", jcr->JobFiles, stream)) {
+ if (!sd->fsend("%ld %d 0", jcr->JobFiles, stream)) {
Jmsg1(jcr, M_FATAL, 0, _("Network send error to SD. ERR=%s\n"),
- bnet_strerror(sd));
+ sd->bstrerror());
return false;
}
msgsave = sd->msg;
sd->msg = jcr->acl_text;
sd->msglen = len + 1;
- if (!bnet_send(sd)) {
+ if (!sd->send()) {
sd->msg = msgsave;
sd->msglen = 0;
Jmsg1(jcr, M_FATAL, 0, _("Network send error to SD. ERR=%s\n"),
- bnet_strerror(sd));
+ sd->bstrerror());
return false;
}
jcr->JobBytes += sd->msglen;
sd->msg = msgsave;
- if (!bnet_sig(sd, BNET_EOD)) {
+ if (!sd->signal(BNET_EOD)) {
Jmsg1(jcr, M_FATAL, 0, _("Network send error to SD. ERR=%s\n"),
- bnet_strerror(sd));
+ sd->bstrerror());
return false;
}
* Send Attributes header to Storage daemon
* <file-index> <stream> <info>
*/
- if (!bnet_fsend(sd, "%ld %d 0", jcr->JobFiles, attr_stream)) {
+ if (!sd->fsend("%ld %d 0", jcr->JobFiles, attr_stream)) {
Jmsg1(jcr, M_FATAL, 0, _("Network send error to SD. ERR=%s\n"),
- bnet_strerror(sd));
+ sd->bstrerror());
return false;
}
Dmsg1(300, ">stored: attrhdr %s\n", sd->msg);
strip_path(ff_pkt);
if (ff_pkt->type == FT_LNK || ff_pkt->type == FT_LNKSAVED) {
Dmsg2(300, "Link %s to %s\n", ff_pkt->fname, ff_pkt->link);
- stat = bnet_fsend(sd, "%ld %d %s%c%s%c%s%c%s%c", jcr->JobFiles,
+ stat = sd->fsend("%ld %d %s%c%s%c%s%c%s%c", jcr->JobFiles,
ff_pkt->type, ff_pkt->fname, 0, attribs, 0, ff_pkt->link, 0,
attribsEx, 0);
} else if (ff_pkt->type == FT_DIREND) {
/* Here link is the canonical filename (i.e. with trailing slash) */
- stat = bnet_fsend(sd, "%ld %d %s%c%s%c%c%s%c", jcr->JobFiles,
+ stat = sd->fsend("%ld %d %s%c%s%c%c%s%c", jcr->JobFiles,
ff_pkt->type, ff_pkt->link, 0, attribs, 0, 0, attribsEx, 0);
} else {
- stat = bnet_fsend(sd, "%ld %d %s%c%s%c%c%s%c", jcr->JobFiles,
+ stat = sd->fsend("%ld %d %s%c%s%c%c%s%c", jcr->JobFiles,
ff_pkt->type, ff_pkt->fname, 0, attribs, 0, 0, attribsEx, 0);
}
unstrip_path(ff_pkt);
Dmsg2(300, ">stored: attr len=%d: %s\n", sd->msglen, sd->msg);
if (!stat) {
Jmsg1(jcr, M_FATAL, 0, _("Network send error to SD. ERR=%s\n"),
- bnet_strerror(sd));
+ sd->bstrerror());
return false;
}
- bnet_sig(sd, BNET_EOD); /* indicate end of attributes data */
+ sd->signal(BNET_EOD); /* indicate end of attributes data */
return true;
}