]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/filed/backup.c
Integrate Preben 'Peppe' Guldberg <peppe@wielders.org>'s
[bacula/bacula] / bacula / src / filed / backup.c
1 /*
2  *  Bacula File Daemon  backup.c  send file attributes and data
3  *   to the Storage daemon.
4  *
5  *    Kern Sibbald, March MM
6  *
7  *   Version $Id$
8  *
9  */
10 /*
11    Copyright (C) 2000-2005 Kern Sibbald
12
13    This program is free software; you can redistribute it and/or
14    modify it under the terms of the GNU General Public License as
15    published by the Free Software Foundation; either version 2 of
16    the License, or (at your option) any later version.
17
18    This program is distributed in the hope that it will be useful,
19    but WITHOUT ANY WARRANTY; without even the implied warranty of
20    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21    General Public License for more details.
22
23    You should have received a copy of the GNU General Public
24    License along with this program; if not, write to the Free
25    Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
26    MA 02111-1307, USA.
27
28  */
29
30 #include "bacula.h"
31 #include "filed.h"
32
33 static int save_file(FF_PKT *ff_pkt, void *pkt);
34 static int send_data(JCR *jcr, int stream, FF_PKT *ff_pkt, struct CHKSUM *chksum);
35 #ifdef HAVE_ACL
36 static int read_and_send_acl(JCR *jcr, int acltype, int stream);
37 #endif
38
39 /*
40  * Find all the requested files and send them
41  * to the Storage daemon.
42  *
43  * Note, we normally carry on a one-way
44  * conversation from this point on with the SD, simply blasting
45  * data to him.  To properly know what is going on, we
46  * also run a "heartbeat" monitor which reads the socket and
47  * reacts accordingly (at the moment it has nothing to do
48  * except echo the heartbeat to the Director).
49  *
50  */
51 bool blast_data_to_storage_daemon(JCR *jcr, char *addr)
52 {
53    BSOCK *sd;
54    bool ok = true;
55
56    sd = jcr->store_bsock;
57
58    set_jcr_job_status(jcr, JS_Running);
59
60    Dmsg1(300, "bfiled: opened data connection %d to stored\n", sd->fd);
61
62    LockRes();
63    CLIENT *client = (CLIENT *)GetNextRes(R_CLIENT, NULL);
64    UnlockRes();
65    uint32_t buf_size;
66    if (client) {
67       buf_size = client->max_network_buffer_size;
68    } else {
69       buf_size = 0;                   /* use default */
70    }
71    if (!bnet_set_buffer_size(sd, buf_size, BNET_SETBUF_WRITE)) {
72       set_jcr_job_status(jcr, JS_ErrorTerminated);
73       Jmsg(jcr, M_FATAL, 0, _("Cannot set buffer size FD->SD.\n"));
74       return false;
75    }
76
77    jcr->buf_size = sd->msglen;
78    /* Adjust for compression so that output buffer is
79     * 12 bytes + 0.1% larger than input buffer plus 18 bytes.
80     * This gives a bit extra plus room for the sparse addr if any.
81     * Note, we adjust the read size to be smaller so that the
82     * same output buffer can be used without growing it.
83     */
84    jcr->compress_buf_size = jcr->buf_size + ((jcr->buf_size+999) / 1000) + 30;
85    jcr->compress_buf = get_memory(jcr->compress_buf_size);
86
87    Dmsg1(300, "set_find_options ff=%p\n", jcr->ff);
88    set_find_options((FF_PKT *)jcr->ff, jcr->incremental, jcr->mtime);
89    Dmsg0(300, "start find files\n");
90
91    start_heartbeat_monitor(jcr);
92
93    jcr->acl_text = get_pool_memory(PM_MESSAGE);
94
95    /* Subroutine save_file() is called for each file */
96    if (!find_files(jcr, (FF_PKT *)jcr->ff, save_file, (void *)jcr)) {
97       ok = false;                     /* error */
98       set_jcr_job_status(jcr, JS_ErrorTerminated);
99 //    Jmsg(jcr, M_FATAL, 0, _("Find files error.\n"));
100    }
101
102    free_pool_memory(jcr->acl_text);
103
104    stop_heartbeat_monitor(jcr);
105
106    bnet_sig(sd, BNET_EOD);            /* end data connection */
107
108    if (jcr->big_buf) {
109       free(jcr->big_buf);
110       jcr->big_buf = NULL;
111    }
112    if (jcr->compress_buf) {
113       free_pool_memory(jcr->compress_buf);
114       jcr->compress_buf = NULL;
115    }
116    Dmsg1(300, "end blast_data stat=%d\n", ok);
117    return ok;
118 }
119
120 /*
121  * Called here by find() for each file included.
122  *   This is a callback. The original is find_files() above.
123  *
124  *  Send the file and its data to the Storage daemon.
125  *
126  *  Returns: 1 if OK
127  *           0 if error
128  *          -1 to ignore file/directory (not used here)
129  */
130 static int save_file(FF_PKT *ff_pkt, void *vjcr)
131 {
132    char attribs[MAXSTRING];
133    char attribsEx[MAXSTRING];
134    int stat, attr_stream, data_stream;
135    struct CHKSUM chksum;
136    BSOCK *sd;
137    JCR *jcr = (JCR *)vjcr;
138
139    if (job_canceled(jcr)) {
140       return 0;
141    }
142
143    sd = jcr->store_bsock;
144    jcr->num_files_examined++;         /* bump total file count */
145
146    switch (ff_pkt->type) {
147    case FT_LNKSAVED:                  /* Hard linked, file already saved */
148       Dmsg2(130, "FT_LNKSAVED hard link: %s => %s\n", ff_pkt->fname, ff_pkt->link);
149       break;
150    case FT_REGE:
151       Dmsg1(130, "FT_REGE saving: %s\n", ff_pkt->fname);
152       break;
153    case FT_REG:
154       Dmsg1(130, "FT_REG saving: %s\n", ff_pkt->fname);
155       break;
156    case FT_LNK:
157       Dmsg2(130, "FT_LNK saving: %s -> %s\n", ff_pkt->fname, ff_pkt->link);
158       break;
159    case FT_DIRBEGIN:
160       return 1;                       /* not used */
161    case FT_NORECURSE:
162    case FT_NOFSCHG:
163    case FT_INVALIDFS:
164    case FT_DIREND:
165       if (ff_pkt->type == FT_NORECURSE) {
166          Jmsg(jcr, M_INFO, 1, _("     Recursion turned off. Will not descend into %s\n"),
167             ff_pkt->fname);
168       } else if (ff_pkt->type == FT_NOFSCHG) {
169          Jmsg(jcr, M_INFO, 1, _("     File system change prohibited. Will not descend into %s\n"),
170             ff_pkt->fname);
171       } else if (ff_pkt->type == FT_INVALIDFS) {
172          Jmsg(jcr, M_INFO, 1, _("     Disallowed filesystem. Will not descend into %s\n"),
173             ff_pkt->fname);
174       }
175       ff_pkt->type = FT_DIREND;       /* value is used below */
176       Dmsg1(130, "FT_DIR saving: %s\n", ff_pkt->link);
177       break;
178    case FT_SPEC:
179       Dmsg1(130, "FT_SPEC saving: %s\n", ff_pkt->fname);
180       break;
181    case FT_RAW:
182       Dmsg1(130, "FT_RAW saving: %s\n", ff_pkt->fname);
183       break;
184    case FT_FIFO:
185       Dmsg1(130, "FT_FIFO saving: %s\n", ff_pkt->fname);
186       break;
187    case FT_NOACCESS: {
188       berrno be;
189       Jmsg(jcr, M_NOTSAVED, 0, _("     Could not access %s: ERR=%s\n"), ff_pkt->fname,
190          be.strerror(ff_pkt->ff_errno));
191       jcr->Errors++;
192       return 1;
193    }
194    case FT_NOFOLLOW: {
195       berrno be;
196       Jmsg(jcr, M_NOTSAVED, 0, _("     Could not follow link %s: ERR=%s\n"), ff_pkt->fname,
197          be.strerror(ff_pkt->ff_errno));
198       jcr->Errors++;
199       return 1;
200    }
201    case FT_NOSTAT: {
202       berrno be;
203       Jmsg(jcr, M_NOTSAVED, 0, _("     Could not stat %s: ERR=%s\n"), ff_pkt->fname,
204          be.strerror(ff_pkt->ff_errno));
205       jcr->Errors++;
206       return 1;
207    }
208    case FT_DIRNOCHG:
209    case FT_NOCHG:
210       Jmsg(jcr, M_SKIPPED, 1, _("     Unchanged file skipped: %s\n"), ff_pkt->fname);
211       return 1;
212    case FT_ISARCH:
213       Jmsg(jcr, M_NOTSAVED, 0, _("     Archive file not saved: %s\n"), ff_pkt->fname);
214       return 1;
215    case FT_NOOPEN: {
216       berrno be;
217       Jmsg(jcr, M_NOTSAVED, 0, _("     Could not open directory %s: ERR=%s\n"), ff_pkt->fname,
218          be.strerror(ff_pkt->ff_errno));
219       jcr->Errors++;
220       return 1;
221    }
222    default:
223       Jmsg(jcr, M_NOTSAVED, 0,  _("     Unknown file type %d; not saved: %s\n"), ff_pkt->type, ff_pkt->fname);
224       jcr->Errors++;
225       return 1;
226    }
227
228    Dmsg1(130, "bfiled: sending %s to stored\n", ff_pkt->fname);
229
230    /* Find what data stream we will use, then encode the attributes */
231    data_stream = select_data_stream(ff_pkt);
232    encode_stat(attribs, ff_pkt, data_stream);
233
234    /* Now possibly extend the attributes */
235    attr_stream = encode_attribsEx(jcr, attribsEx, ff_pkt);
236
237    Dmsg3(300, "File %s\nattribs=%s\nattribsEx=%s\n", ff_pkt->fname, attribs, attribsEx);
238
239    P(jcr->mutex);
240    jcr->JobFiles++;                    /* increment number of files sent */
241    ff_pkt->FileIndex = jcr->JobFiles;  /* return FileIndex */
242    pm_strcpy(jcr->last_fname, ff_pkt->fname);
243    V(jcr->mutex);
244
245    /*
246     * Send Attributes header to Storage daemon
247     *    <file-index> <stream> <info>
248     */
249    if (!bnet_fsend(sd, "%ld %d 0", jcr->JobFiles, attr_stream)) {
250       Jmsg1(jcr, M_FATAL, 0, _("Network send error to SD. ERR=%s\n"),
251             bnet_strerror(sd));
252       return 0;
253    }
254    Dmsg1(300, ">stored: attrhdr %s\n", sd->msg);
255
256    /*
257     * Send file attributes to Storage daemon
258     *   File_index
259     *   File type
260     *   Filename (full path)
261     *   Encoded attributes
262     *   Link name (if type==FT_LNK or FT_LNKSAVED)
263     *   Encoded extended-attributes (for Win32)
264     *
265     * For a directory, link is the same as fname, but with trailing
266     * slash. For a linked file, link is the link.
267     */
268    if (ff_pkt->type == FT_LNK || ff_pkt->type == FT_LNKSAVED) {
269       Dmsg2(300, "Link %s to %s\n", ff_pkt->fname, ff_pkt->link);
270       stat = bnet_fsend(sd, "%ld %d %s%c%s%c%s%c%s%c", jcr->JobFiles,
271                ff_pkt->type, ff_pkt->fname, 0, attribs, 0, ff_pkt->link, 0,
272                attribsEx, 0);
273    } else if (ff_pkt->type == FT_DIREND) {
274       /* Here link is the canonical filename (i.e. with trailing slash) */
275       stat = bnet_fsend(sd, "%ld %d %s%c%s%c%c%s%c", jcr->JobFiles,
276                ff_pkt->type, ff_pkt->link, 0, attribs, 0, 0, attribsEx, 0);
277    } else {
278       stat = bnet_fsend(sd, "%ld %d %s%c%s%c%c%s%c", jcr->JobFiles,
279                ff_pkt->type, ff_pkt->fname, 0, attribs, 0, 0, attribsEx, 0);
280    }
281
282    Dmsg2(300, ">stored: attr len=%d: %s\n", sd->msglen, sd->msg);
283    if (!stat) {
284       Jmsg1(jcr, M_FATAL, 0, _("Network send error to SD. ERR=%s\n"),
285             bnet_strerror(sd));
286       return 0;
287    }
288    bnet_sig(sd, BNET_EOD);            /* indicate end of attributes data */
289
290    /*
291     * Setup for signature handling.
292     * Then initialise the file descriptor we use for data and other streams.
293     */
294    chksum_init(&chksum, ff_pkt->flags);
295
296    binit(&ff_pkt->bfd);
297    if (ff_pkt->flags & FO_PORTABLE) {
298       set_portable_backup(&ff_pkt->bfd); /* disable Win32 BackupRead() */
299    }
300    if (ff_pkt->reader) {
301       set_prog(&ff_pkt->bfd, ff_pkt->reader, jcr);
302    }
303
304    /*
305     * Open any file with data that we intend to save, then save it.
306     *
307     * Note, if is_win32_backup, we must open the Directory so that
308     * the BackupRead will save its permissions and ownership streams.
309     */
310    if (ff_pkt->type != FT_LNKSAVED && (S_ISREG(ff_pkt->statp.st_mode) &&
311          ff_pkt->statp.st_size > 0) ||
312          ff_pkt->type == FT_RAW || ff_pkt->type == FT_FIFO ||
313          (!is_portable_backup(&ff_pkt->bfd) && ff_pkt->type == FT_DIREND)) {
314       btimer_t *tid;
315       if (ff_pkt->type == FT_FIFO) {
316          tid = start_thread_timer(pthread_self(), 60);
317       } else {
318          tid = NULL;
319       }
320       if (bopen(&ff_pkt->bfd, ff_pkt->fname, O_RDONLY | O_BINARY, 0) < 0) {
321          ff_pkt->ff_errno = errno;
322          berrno be;
323          Jmsg(jcr, M_NOTSAVED, 0, _("     Cannot open %s: ERR=%s.\n"), ff_pkt->fname,
324               be.strerror());
325          jcr->Errors++;
326          if (tid) {
327             stop_thread_timer(tid);
328             tid = NULL;
329          }
330          return 1;
331       }
332       if (tid) {
333          stop_thread_timer(tid);
334          tid = NULL;
335       }
336       stat = send_data(jcr, data_stream, ff_pkt, &chksum);
337       bclose(&ff_pkt->bfd);
338       if (!stat) {
339          return 0;
340       }
341    }
342
343 #ifdef HAVE_DARWIN_OS
344    /* Open resource fork if necessary and save content */
345    if (ff_pkt->type != FT_LNKSAVED && (S_ISREG(ff_pkt->statp.st_mode) &&
346             ff_pkt->flags & FO_HFSPLUS)) {
347       if (ff_pkt->hfsinfo.rsrclength > 0) {
348          int flags;
349          if (!bopen_rsrc(&ff_pkt->bfd, ff_pkt->fname, O_RDONLY | O_BINARY, 0) < 0) {
350             ff_pkt->ff_errno = errno;
351             berrno be;
352             Jmsg(jcr, M_NOTSAVED, -1, _("     Cannot open resource fork for %s: ERR=%s.\n"), ff_pkt->fname,
353                   be.strerror());
354             jcr->Errors++;
355             if (is_bopen(&ff_pkt->bfd)) {
356                bclose(&ff_pkt->bfd);
357             }
358             return 1;
359          }
360          flags = ff_pkt->flags;
361          ff_pkt->flags &= ~(FO_GZIP|FO_SPARSE);
362          stat = send_data(jcr, STREAM_MACOS_FORK_DATA, ff_pkt, &chksum);
363          ff_pkt->flags = flags;
364          bclose(&ff_pkt->bfd);
365          if (!stat) {
366             return 0;
367          }
368       }
369
370       Dmsg1(300, "Saving Finder Info for \"%s\"\n", ff_pkt->fname);
371       bnet_fsend(sd, "%ld %d 0", jcr->JobFiles, STREAM_HFSPLUS_ATTRIBUTES);
372       Dmsg1(300, "bfiled>stored:header %s\n", sd->msg);
373       memcpy(sd->msg, ff_pkt->hfsinfo.fndrinfo, 32);
374       sd->msglen = 32;
375       chksum_update(&chksum, (unsigned char *)sd->msg, sd->msglen);
376       bnet_send(sd);
377       bnet_sig(sd, BNET_EOD);
378    }
379 #endif
380
381 #ifdef HAVE_ACL
382    /* Read access ACLs for files, dirs and links */
383    if (!read_and_send_acl(jcr, BACL_TYPE_ACCESS, STREAM_UNIX_ATTRIBUTES_ACCESS_ACL)) {
384       return 0;
385    }
386    /* Directories can have default ACLs too */
387    if (ff_pkt->type == FT_DIREND && (BACL_CAP & BACL_CAP_DEFAULTS_DIR)) {
388       if (!read_and_send_acl(jcr, BACL_TYPE_DEFAULT, STREAM_UNIX_ATTRIBUTES_DEFAULT_ACL)) {
389          return 0;
390       }
391    }
392 #endif
393
394    /* Terminate any signature and send it to Storage daemon and the Director */
395    if (chksum.updated) {
396       int stream = 0;
397       chksum_final(&chksum);
398       if (chksum.type == CHKSUM_MD5) {
399          stream = STREAM_MD5_SIGNATURE;
400       } else if (chksum.type == CHKSUM_SHA1) {
401          stream = STREAM_SHA1_SIGNATURE;
402       } else {
403          Jmsg1(jcr, M_WARNING, 0, _("Unknown signature type %i.\n"), chksum.type);
404       }
405       if (stream != 0) {
406          bnet_fsend(sd, "%ld %d 0", jcr->JobFiles, stream);
407          Dmsg1(300, "bfiled>stored:header %s\n", sd->msg);
408          memcpy(sd->msg, chksum.signature, chksum.length);
409          sd->msglen = chksum.length;
410          bnet_send(sd);
411          bnet_sig(sd, BNET_EOD);              /* end of checksum */
412       }
413    }
414
415    return 1;
416 }
417
418 /*
419  * Send data read from an already open file descriptor.
420  *
421  * We return 1 on sucess and 0 on errors.
422  *
423  * ***FIXME***
424  * We use ff_pkt->statp.st_size when FO_SPARSE.
425  * Currently this is not a problem as the only other stream, resource forks,
426  * are not handled as sparse files.
427  */
428 int send_data(JCR *jcr, int stream, FF_PKT *ff_pkt, struct CHKSUM *chksum)
429 {
430    BSOCK *sd = jcr->store_bsock;
431    uint64_t fileAddr = 0;             /* file address */
432    char *rbuf, *wbuf;
433    int rsize = jcr->buf_size;      /* read buffer size */
434    POOLMEM *msgsave;
435
436    msgsave = sd->msg;
437    rbuf = sd->msg;                    /* read buffer */
438    wbuf = sd->msg;                    /* write buffer */
439
440
441    Dmsg1(300, "Saving data, type=%d\n", ff_pkt->type);
442
443
444 #ifdef HAVE_LIBZ
445    uLong compress_len, max_compress_len = 0;
446    const Bytef *cbuf = NULL;
447
448    if (ff_pkt->flags & FO_GZIP) {
449       if (ff_pkt->flags & FO_SPARSE) {
450          cbuf = (Bytef *)jcr->compress_buf + SPARSE_FADDR_SIZE;
451          max_compress_len = jcr->compress_buf_size - SPARSE_FADDR_SIZE;
452       } else {
453          cbuf = (Bytef *)jcr->compress_buf;
454          max_compress_len = jcr->compress_buf_size; /* set max length */
455       }
456       wbuf = jcr->compress_buf;    /* compressed output here */
457    }
458 #endif
459
460    /*
461     * Send Data header to Storage daemon
462     *    <file-index> <stream> <info>
463     */
464    if (!bnet_fsend(sd, "%ld %d 0", jcr->JobFiles, stream)) {
465       Jmsg1(jcr, M_FATAL, 0, _("Network send error to SD. ERR=%s\n"),
466             bnet_strerror(sd));
467       return 0;
468    }
469    Dmsg1(300, ">stored: datahdr %s\n", sd->msg);
470
471    /*
472     * Make space at beginning of buffer for fileAddr because this
473     *   same buffer will be used for writing if compression if off.
474     */
475    if (ff_pkt->flags & FO_SPARSE) {
476       rbuf += SPARSE_FADDR_SIZE;
477       rsize -= SPARSE_FADDR_SIZE;
478 #ifdef HAVE_FREEBSD_OS
479       /*
480        * To read FreeBSD partitions, the read size must be
481        *  a multiple of 512.
482        */
483       rsize = (rsize/512) * 512;
484 #endif
485    }
486
487    /*
488     * Read the file data
489     */
490    while ((sd->msglen=(uint32_t)bread(&ff_pkt->bfd, rbuf, rsize)) > 0) {
491       int sparseBlock = 0;
492
493       /* Check for sparse blocks */
494       if (ff_pkt->flags & FO_SPARSE) {
495          ser_declare;
496          if (sd->msglen == rsize &&
497              (fileAddr+sd->msglen < (uint64_t)ff_pkt->statp.st_size)) {
498             sparseBlock = is_buf_zero(rbuf, rsize);
499          }
500
501          ser_begin(wbuf, SPARSE_FADDR_SIZE);
502          ser_uint64(fileAddr);     /* store fileAddr in begin of buffer */
503       }
504
505       jcr->ReadBytes += sd->msglen;         /* count bytes read */
506       fileAddr += sd->msglen;
507
508       /* Update checksum if requested */
509       chksum_update(chksum, (unsigned char *)rbuf, sd->msglen);
510
511 #ifdef HAVE_LIBZ
512       /* Do compression if turned on */
513       if (!sparseBlock && ff_pkt->flags & FO_GZIP) {
514          int zstat;
515          compress_len = max_compress_len;
516          Dmsg4(400, "cbuf=0x%x len=%u rbuf=0x%x len=%u\n", cbuf, compress_len,
517             rbuf, sd->msglen);
518          /* NOTE! This call modifies compress_len !!! */
519          if ((zstat=compress2((Bytef *)cbuf, &compress_len,
520                (const Bytef *)rbuf, (uLong)sd->msglen,
521                ff_pkt->GZIP_level)) != Z_OK) {
522             Jmsg(jcr, M_FATAL, 0, _("Compression error: %d\n"), zstat);
523             sd->msg = msgsave;
524             sd->msglen = 0;
525             set_jcr_job_status(jcr, JS_ErrorTerminated);
526             return 0;
527          }
528          Dmsg2(400, "compressed len=%d uncompressed len=%d\n",
529             compress_len, sd->msglen);
530
531          sd->msglen = compress_len;      /* set compressed length */
532       }
533 #endif
534
535       /* Send the buffer to the Storage daemon */
536       if (!sparseBlock) {
537          if (ff_pkt->flags & FO_SPARSE) {
538             sd->msglen += SPARSE_FADDR_SIZE; /* include fileAddr in size */
539          }
540          sd->msg = wbuf;              /* set correct write buffer */
541          if (!bnet_send(sd)) {
542             Jmsg2(jcr, M_FATAL, 0, _("Network send error %d to SD. ERR=%s\n"),
543                   sd->msglen, bnet_strerror(sd));
544             sd->msg = msgsave;     /* restore bnet buffer */
545             sd->msglen = 0;
546             return 0;
547          }
548       }
549       Dmsg1(130, "Send data to SD len=%d\n", sd->msglen);
550       /*          #endif */
551       jcr->JobBytes += sd->msglen;      /* count bytes saved possibly compressed */
552       sd->msg = msgsave;                /* restore read buffer */
553
554    } /* end while read file data */
555
556
557    if (sd->msglen < 0) {
558       berrno be;
559       Jmsg(jcr, M_ERROR, 0, _("Read error on file %s. ERR=%s\n"),
560          ff_pkt->fname, be.strerror(ff_pkt->bfd.berrno));
561    }
562
563    if (!bnet_sig(sd, BNET_EOD)) {        /* indicate end of file data */
564       Jmsg1(jcr, M_FATAL, 0, _("Network send error to SD. ERR=%s\n"),
565             bnet_strerror(sd));
566       return 0;
567    }
568
569    return 1;
570 }
571
572 #ifdef HAVE_ACL
573 /*
574  * Read and send an ACL for the last encountered file.
575  */
576 static int read_and_send_acl(JCR *jcr, int acltype, int stream)
577 {
578    BSOCK *sd = jcr->store_bsock;
579    POOLMEM *msgsave;
580    int len;
581
582    len = bacl_get(jcr, acltype);
583    if (len < 0) {
584       Jmsg1(jcr, M_WARNING, 0, "Error reading ACL of %s\n", jcr->last_fname);
585       return 1;
586    }
587    if (len == 0) {
588       return 1;                       /* no ACL */
589    }
590
591    /* Send header */
592    if (!bnet_fsend(sd, "%ld %d 0", jcr->JobFiles, stream)) {
593       Jmsg1(jcr, M_FATAL, 0, _("Network send error to SD. ERR=%s\n"),
594             bnet_strerror(sd));
595       return 0;
596    }
597
598    /* Send the buffer to the storage deamon */
599    Dmsg2(400, "Backing up ACL type 0x%2x <%s>\n", acltype, jcr->acl_text);
600    msgsave = sd->msg;
601    sd->msg = jcr->acl_text;
602    sd->msglen = len + 1;
603    if (!bnet_send(sd)) {
604       sd->msg = msgsave;
605       sd->msglen = 0;
606       Jmsg1(jcr, M_FATAL, 0, _("Network send error to SD. ERR=%s\n"),
607             bnet_strerror(sd));
608       return 0;
609    }
610
611    jcr->JobBytes += sd->msglen;
612    sd->msg = msgsave;
613    if (!bnet_sig(sd, BNET_EOD)) {
614       Jmsg1(jcr, M_FATAL, 0, _("Network send error to SD. ERR=%s\n"),
615             bnet_strerror(sd));
616       return 0;
617    }
618
619    Dmsg1(200, "ACL of file: %s successfully backed up!\n", jcr->last_fname);
620    return 1;
621 }
622 #endif