]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/dird/fd_cmds.c
Remove old comments
[bacula/bacula] / bacula / src / dird / fd_cmds.c
1 /*
2  *
3  *   Bacula Director -- fd_cmds.c -- send commands to File daemon
4  *
5  *     Kern Sibbald, October MM
6  *
7  *    This routine is run as a separate thread.  There may be more
8  *    work to be done to make it totally reentrant!!!!
9  * 
10  *  Utility functions for sending info to File Daemon.
11  *   These functions are used by both backup and verify.
12  *   
13  *   Version $Id$
14  */
15 /*
16    Copyright (C) 2000-2004 Kern Sibbald and John Walker
17
18    This program is free software; you can redistribute it and/or
19    modify it under the terms of the GNU General Public License as
20    published by the Free Software Foundation; either version 2 of
21    the License, or (at your option) any later version.
22
23    This program is distributed in the hope that it will be useful,
24    but WITHOUT ANY WARRANTY; without even the implied warranty of
25    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
26    General Public License for more details.
27
28    You should have received a copy of the GNU General Public
29    License along with this program; if not, write to the Free
30    Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
31    MA 02111-1307, USA.
32
33  */
34
35 #include "bacula.h"
36 #include "dird.h"
37
38 /* Commands sent to File daemon */
39 static char inc[]         = "include\n";
40 static char exc[]         = "exclude\n";
41 static char incopts[]     = "incopts\n"; /* new include with options */
42 static char jobcmd[]      = "JobId=%d Job=%s SDid=%u SDtime=%u Authorization=%s\n";
43 static char levelcmd[]    = "level = %s%s mtime_only=%d\n";
44 static char runbefore[]   = "RunBeforeJob %s\n";
45 static char runafter[]    = "RunAfterJob %s\n";
46
47
48 /* Responses received from File daemon */
49 static char OKinc[]       = "2000 OK include\n";
50 static char OKexc[]       = "2000 OK exclude\n";
51 static char OKjob[]       = "2000 OK Job";
52 static char OKbootstrap[] = "2000 OK bootstrap\n";
53 static char OKlevel[]     = "2000 OK level\n";
54 static char OKRunBefore[] = "2000 OK RunBefore\n";
55 static char OKRunAfter[]  = "2000 OK RunAfter\n";
56
57 /* Forward referenced functions */
58
59 /* External functions */
60 extern int debug_level;
61 extern DIRRES *director; 
62 extern int FDConnectTimeout;
63
64 #define INC_LIST 0
65 #define EXC_LIST 1
66
67 /*
68  * Open connection with File daemon. 
69  * Try connecting every retry_interval (default 10 sec), and
70  *   give up after max_retry_time (default 30 mins).
71  */
72
73 int connect_to_file_daemon(JCR *jcr, int retry_interval, int max_retry_time,
74                            int verbose)
75 {
76    BSOCK   *fd;
77
78    fd = bnet_connect(jcr, retry_interval, max_retry_time,
79         _("File daemon"), jcr->client->address, 
80         NULL, jcr->client->FDport, verbose);
81    if (fd == NULL) {
82       set_jcr_job_status(jcr, JS_ErrorTerminated);
83       return 0;
84    }
85    Dmsg0(10, "Opened connection with File daemon\n");
86    fd->res = (RES *)jcr->client;      /* save resource in BSOCK */
87    jcr->file_bsock = fd;
88    set_jcr_job_status(jcr, JS_Running);
89
90    if (!authenticate_file_daemon(jcr)) {
91       set_jcr_job_status(jcr, JS_ErrorTerminated);
92       return 0;
93    }
94         
95    /*
96     * Now send JobId and authorization key
97     */
98    bnet_fsend(fd, jobcmd, jcr->JobId, jcr->Job, jcr->VolSessionId, 
99       jcr->VolSessionTime, jcr->sd_auth_key);
100    if (strcmp(jcr->sd_auth_key, "dummy") != 0) {
101       memset(jcr->sd_auth_key, 0, strlen(jcr->sd_auth_key));
102    }
103    Dmsg1(100, ">filed: %s", fd->msg);
104    if (bget_dirmsg(fd) > 0) {
105        Dmsg1(110, "<filed: %s", fd->msg);
106        if (strncmp(fd->msg, OKjob, strlen(OKjob)) != 0) {
107           Jmsg(jcr, M_FATAL, 0, _("File daemon \"%s\" rejected Job command: %s\n"), 
108              jcr->client->hdr.name, fd->msg);
109           set_jcr_job_status(jcr, JS_ErrorTerminated);
110           return 0;
111        } else if (jcr->db) {
112           CLIENT_DBR cr;
113           memset(&cr, 0, sizeof(cr));
114           bstrncpy(cr.Name, jcr->client->hdr.name, sizeof(cr.Name));
115           cr.AutoPrune = jcr->client->AutoPrune;
116           cr.FileRetention = jcr->client->FileRetention;
117           cr.JobRetention = jcr->client->JobRetention;
118           bstrncpy(cr.Uname, fd->msg+strlen(OKjob)+1, sizeof(cr.Uname));
119           if (!db_update_client_record(jcr, jcr->db, &cr)) {
120              Jmsg(jcr, M_WARNING, 0, _("Error updating Client record. ERR=%s\n"),
121                 db_strerror(jcr->db));
122           }
123        }
124    } else {
125       Jmsg(jcr, M_FATAL, 0, _("FD gave bad response to JobId command: %s\n"),
126          bnet_strerror(fd));
127       set_jcr_job_status(jcr, JS_ErrorTerminated);
128       return 0;
129    }
130    return 1;
131 }
132
133 /*
134  * This subroutine edits the last job start time into a
135  *   "since=date/time" buffer that is returned in the  
136  *   variable since.  This is used for display purposes in
137  *   the job report.  The time in jcr->stime is later 
138  *   passed to tell the File daemon what to do.
139  */
140 void get_level_since_time(JCR *jcr, char *since, int since_len)
141 {
142    /* Lookup the last
143     * FULL backup job to get the time/date for a 
144     * differential or incremental save.
145     */
146    if (!jcr->stime) {
147       jcr->stime = get_pool_memory(PM_MESSAGE);
148    }
149    jcr->stime[0] = 0;
150    since[0] = 0;
151    switch (jcr->JobLevel) {
152    case L_DIFFERENTIAL:
153    case L_INCREMENTAL:
154       /* Look up start time of last job */
155       jcr->jr.JobId = 0;
156       if (!db_find_job_start_time(jcr, jcr->db, &jcr->jr, &jcr->stime)) {
157          Jmsg(jcr, M_INFO, 0, "%s", db_strerror(jcr->db));
158          Jmsg(jcr, M_INFO, 0, _("No prior or suitable Full backup found. Doing FULL backup.\n"));
159          bsnprintf(since, since_len, " (upgraded from %s)", 
160             level_to_str(jcr->JobLevel));
161          jcr->JobLevel = jcr->jr.Level = L_FULL;
162       } else {
163          bstrncpy(since, ", since=", since_len);
164          bstrncat(since, jcr->stime, since_len);
165       }
166       Dmsg1(100, "Last start time = %s\n", jcr->stime);
167       break;
168    }
169 }
170
171
172 /*
173  * Send level command to FD. 
174  * Used for backup jobs and estimate command.
175  */
176 int send_level_command(JCR *jcr) 
177 {
178    BSOCK   *fd = jcr->file_bsock;
179    utime_t stime;
180    char ed1[50];
181    /* 
182     * Send Level command to File daemon
183     */
184    switch (jcr->JobLevel) {
185    case L_BASE:
186       bnet_fsend(fd, levelcmd, "base", " ", 0);
187       break;
188    /* L_NONE is the console, sending something off to the FD */
189    case L_NONE:
190    case L_FULL:
191       bnet_fsend(fd, levelcmd, "full", " ", 0);
192       break;
193    case L_DIFFERENTIAL:
194    case L_INCREMENTAL:
195 //    bnet_fsend(fd, levelcmd, "since ", jcr->stime, 0); /* old code, deprecated */
196       stime = str_to_utime(jcr->stime);
197       bnet_fsend(fd, levelcmd, "since_utime ", edit_uint64(stime, ed1), 0);
198       while (bget_dirmsg(fd) >= 0) {  /* allow him to poll us to sync clocks */
199          Jmsg(jcr, M_INFO, 0, "%s\n", fd->msg);
200       }
201       break;
202    case L_SINCE:
203    default:
204       Jmsg2(jcr, M_FATAL, 0, _("Unimplemented backup level %d %c\n"), 
205          jcr->JobLevel, jcr->JobLevel);
206       return 0;
207    }
208    Dmsg1(120, ">filed: %s", fd->msg);
209    if (!response(jcr, fd, OKlevel, "Level", DISPLAY_ERROR)) {
210       return 0;
211    }
212    return 1;
213 }
214
215
216 /*
217  * Send either an Included or an Excluded list to FD
218  */
219 static int send_list(JCR *jcr, int list)
220 {
221    FILESET *fileset;
222    BSOCK   *fd;
223    int num;
224
225    fd = jcr->file_bsock;
226    fileset = jcr->fileset;
227
228    if (list == INC_LIST) {
229       num = fileset->num_includes;
230    } else {
231       num = fileset->num_excludes;
232    }
233
234    for (int i=0; i < num; i++) {
235       BPIPE *bpipe;
236       FILE *ffd;
237       char buf[2000];
238       char *p;
239       int optlen, stat;
240       INCEXE *ie;
241
242
243       if (list == INC_LIST) {
244          ie = fileset->include_items[i];
245       } else {
246          ie = fileset->exclude_items[i];
247       }
248       for (int j=0; j<ie->name_list.size(); j++) {
249          p = (char *)ie->name_list.get(j);
250          switch (*p) {
251          case '|':
252             p++;                      /* skip over the | */
253             fd->msg = edit_job_codes(jcr, fd->msg, p, "");
254             bpipe = open_bpipe(fd->msg, 0, "r");
255             if (!bpipe) {
256                Jmsg(jcr, M_FATAL, 0, _("Cannot run program: %s. ERR=%s\n"),
257                   p, strerror(errno));
258                goto bail_out;
259             }
260             /* Copy File options */
261             if (ie->num_opts) {
262                bstrncpy(buf, ie->opts_list[0]->opts, sizeof(buf));
263                bstrncat(buf, " ", sizeof(buf));
264             } else {
265                bstrncpy(buf, "0 ", sizeof(buf));
266             }
267             Dmsg1(100, "Opts=%s\n", buf);
268             optlen = strlen(buf);
269             while (fgets(buf+optlen, sizeof(buf)-optlen, bpipe->rfd)) {
270                fd->msglen = Mmsg(&fd->msg, "%s", buf);
271                Dmsg2(200, "Inc/exc len=%d: %s", fd->msglen, fd->msg);
272                if (!bnet_send(fd)) {
273                   Jmsg(jcr, M_FATAL, 0, _(">filed: write error on socket\n"));
274                   goto bail_out;
275                }
276             }
277             if ((stat=close_bpipe(bpipe)) != 0) {
278                Jmsg(jcr, M_FATAL, 0, _("Error running program: %s. RtnStat=%d ERR=%s\n"),
279                   p, stat, strerror(errno));
280                goto bail_out;
281             }
282             break;
283          case '<':
284             p++;                      /* skip over < */
285             if ((ffd = fopen(p, "r")) == NULL) {
286                Jmsg(jcr, M_FATAL, 0, _("Cannot open %s file: %s. ERR=%s\n"),
287                   list==INC_LIST?"included":"excluded", p, strerror(errno));
288                goto bail_out;
289             }
290             /* Copy File options */
291             if (ie->num_opts) {
292                bstrncpy(buf, ie->opts_list[0]->opts, sizeof(buf));
293                bstrncat(buf, " ", sizeof(buf));
294             } else {
295                bstrncpy(buf, "0 ", sizeof(buf));
296             }
297             Dmsg1(100, "Opts=%s\n", buf);
298             optlen = strlen(buf);
299             while (fgets(buf+optlen, sizeof(buf)-optlen, ffd)) {
300                fd->msglen = Mmsg(&fd->msg, "%s", buf);
301                if (!bnet_send(fd)) {
302                   Jmsg(jcr, M_FATAL, 0, _(">filed: write error on socket\n"));
303                   goto bail_out;
304                }
305             }
306             fclose(ffd);
307             break;
308          case '\\':
309             p++;                      /* skip over \ */
310             /* Note, fall through wanted */
311          default:
312             if (ie->num_opts) {
313                Dmsg2(100, "numopts=%d opts=%s\n", ie->num_opts, NPRT(ie->opts_list[0]->opts));
314                pm_strcpy(&fd->msg, ie->opts_list[0]->opts);
315                pm_strcat(&fd->msg, " ");
316             } else {
317                pm_strcpy(&fd->msg, "0 ");
318             }
319             fd->msglen = pm_strcat(&fd->msg, p);
320             Dmsg1(100, "Inc/Exc name=%s\n", fd->msg);
321             if (!bnet_send(fd)) {
322                Jmsg(jcr, M_FATAL, 0, _(">filed: write error on socket\n"));
323                goto bail_out;
324             }
325             break;
326          }
327       }
328    }
329    bnet_sig(fd, BNET_EOD);            /* end of data */
330    if (list == INC_LIST) {
331       if (!response(jcr, fd, OKinc, "Include", DISPLAY_ERROR)) {
332          goto bail_out;
333       }
334    } else if (!response(jcr, fd, OKexc, "Exclude", DISPLAY_ERROR)) {
335         goto bail_out;
336    }
337    return 1;
338
339 bail_out:
340    set_jcr_job_status(jcr, JS_ErrorTerminated);
341    return 0;
342
343 }
344
345
346 /*
347  * Send either an Included or an Excluded list to FD
348  */
349 static int send_incopts(JCR *jcr)
350 {
351    FILESET *fileset = jcr->fileset;
352    BSOCK   *fd = jcr->file_bsock;
353    int num = fileset->num_includes;
354
355    for (int i=0; i<num; i++) {
356       BPIPE *bpipe;
357       FILE *ffd;
358       char buf[2000];
359       char *p;
360       int optlen, stat;
361       INCEXE *ie;
362       int j, k;
363
364       ie = fileset->include_items[i];
365
366       for (j=0; j<ie->num_opts; j++) {
367          FOPTS *fo = ie->opts_list[j];
368          bnet_fsend(fd, "O %s\n", fo->opts);
369          for (k=0; k<fo->regex.size(); k++) {
370             bnet_fsend(fd, "R %s\n", fo->regex.get(k));
371          }
372          for (k=0; k<fo->wild.size(); k++) {
373             bnet_fsend(fd, "W %s\n", fo->wild.get(k));
374          }
375          for (k=0; k<fo->base.size(); k++) {
376             bnet_fsend(fd, "B %s\n", fo->base.get(k));
377          }
378          bnet_fsend(fd, "N\n");
379       }
380
381       for (j=0; j<ie->name_list.size(); j++) {
382          p = (char *)ie->name_list.get(j);
383          switch (*p) {
384          case '|':
385             p++;                      /* skip over the | */
386             fd->msg = edit_job_codes(jcr, fd->msg, p, "");
387             bpipe = open_bpipe(fd->msg, 0, "r");
388             if (!bpipe) {
389                Jmsg(jcr, M_FATAL, 0, _("Cannot run program: %s. ERR=%s\n"),
390                   p, strerror(errno));
391                goto bail_out;
392             }
393             bstrncpy(buf, "I ", sizeof(buf));
394             Dmsg1(100, "Opts=%s\n", buf);
395             optlen = strlen(buf);
396             while (fgets(buf+optlen, sizeof(buf)-optlen, bpipe->rfd)) {
397                fd->msglen = Mmsg(&fd->msg, "%s", buf);
398                Dmsg2(200, "Inc/exc len=%d: %s", fd->msglen, fd->msg);
399                if (!bnet_send(fd)) {
400                   Jmsg(jcr, M_FATAL, 0, _(">filed: write error on socket\n"));
401                   goto bail_out;
402                }
403             }
404             if ((stat=close_bpipe(bpipe)) != 0) {
405                Jmsg(jcr, M_FATAL, 0, _("Error running program: %s. RtnStat=%d ERR=%s\n"),
406                   p, stat, strerror(errno));
407                goto bail_out;
408             }
409             break;
410          case '<':
411             p++;                      /* skip over < */
412             if ((ffd = fopen(p, "r")) == NULL) {
413                Jmsg(jcr, M_FATAL, 0, _("Cannot open included file: %s. ERR=%s\n"),
414                   p, strerror(errno));
415                goto bail_out;
416             }
417             bstrncpy(buf, "I ", sizeof(buf));
418             Dmsg1(100, "Opts=%s\n", buf);
419             optlen = strlen(buf);
420             while (fgets(buf+optlen, sizeof(buf)-optlen, ffd)) {
421                fd->msglen = Mmsg(&fd->msg, "%s", buf);
422                if (!bnet_send(fd)) {
423                   Jmsg(jcr, M_FATAL, 0, _(">filed: write error on socket\n"));
424                   goto bail_out;
425                }
426             }
427             fclose(ffd);
428             break;
429          case '\\':
430             p++;                      /* skip over \ */
431             /* Note, fall through wanted */
432          default:
433             pm_strcpy(&fd->msg, "I ");
434             fd->msglen = pm_strcat(&fd->msg, p);
435             Dmsg1(100, "Inc/Exc name=%s\n", fd->msg);
436             if (!bnet_send(fd)) {
437                Jmsg(jcr, M_FATAL, 0, _(">filed: write error on socket\n"));
438                goto bail_out;
439             }
440             break;
441          }
442       }
443       bnet_fsend(fd, "N\n");
444    }
445
446    bnet_sig(fd, BNET_EOD);            /* end of data */
447    if (!response(jcr, fd, OKinc, "Include", DISPLAY_ERROR)) {
448       goto bail_out;
449    }
450    return 1;
451
452 bail_out:
453    set_jcr_job_status(jcr, JS_ErrorTerminated);
454    return 0;
455
456 }
457
458
459 /*
460  * Send include list to File daemon
461  */
462 int send_include_list(JCR *jcr)
463 {
464    BSOCK *fd = jcr->file_bsock;
465    if (jcr->fileset->new_include) {
466       bnet_fsend(fd, incopts);
467       return send_incopts(jcr);
468    } else {
469       bnet_fsend(fd, inc);
470    }
471    return send_list(jcr, INC_LIST);
472 }
473
474
475 /*
476  * Send exclude list to File daemon 
477  */
478 int send_exclude_list(JCR *jcr)
479 {
480    BSOCK *fd = jcr->file_bsock;
481    bnet_fsend(fd, exc);
482    return send_list(jcr, EXC_LIST);
483 }
484
485
486 /*
487  * Send bootstrap file if any to the File daemon.
488  *  This is used for restore and verify VolumeToCatalog
489  */
490 int send_bootstrap_file(JCR *jcr)
491 {
492    FILE *bs;
493    char buf[1000];
494    BSOCK *fd = jcr->file_bsock;
495    char *bootstrap = "bootstrap\n";
496
497    Dmsg1(400, "send_bootstrap_file: %s\n", jcr->RestoreBootstrap);
498    if (!jcr->RestoreBootstrap) {
499       return 1;
500    }
501    bs = fopen(jcr->RestoreBootstrap, "r");
502    if (!bs) {
503       Jmsg(jcr, M_FATAL, 0, _("Could not open bootstrap file %s: ERR=%s\n"), 
504          jcr->RestoreBootstrap, strerror(errno));
505       set_jcr_job_status(jcr, JS_ErrorTerminated);
506       return 0;
507    }
508    bnet_fsend(fd, bootstrap);
509    while (fgets(buf, sizeof(buf), bs)) {
510       bnet_fsend(fd, "%s", buf);       
511    }
512    bnet_sig(fd, BNET_EOD);
513    fclose(bs);
514    if (!response(jcr, fd, OKbootstrap, "Bootstrap", DISPLAY_ERROR)) {
515       set_jcr_job_status(jcr, JS_ErrorTerminated);
516       return 0;
517    }
518    return 1;
519 }
520
521 /*
522  * Send ClientRunBeforeJob and ClientRunAfterJob to File daemon
523  */
524 int send_run_before_and_after_commands(JCR *jcr)
525 {
526    POOLMEM *msg = get_pool_memory(PM_FNAME);
527    BSOCK *fd = jcr->file_bsock;
528    if (jcr->job->ClientRunBeforeJob) {
529       pm_strcpy(&msg, jcr->job->ClientRunBeforeJob);
530       bash_spaces(msg);
531       bnet_fsend(fd, runbefore, msg);
532       if (!response(jcr, fd, OKRunBefore, "ClientRunBeforeJob", DISPLAY_ERROR)) {
533          set_jcr_job_status(jcr, JS_ErrorTerminated);
534          free_pool_memory(msg);
535          return 0;
536       }
537    }
538    if (jcr->job->ClientRunAfterJob) {
539       fd->msglen = pm_strcpy(&msg, jcr->job->ClientRunAfterJob);
540       bash_spaces(msg);
541       bnet_fsend(fd, runafter, msg);
542       if (!response(jcr, fd, OKRunAfter, "ClientRunAfterJob", DISPLAY_ERROR)) {
543          set_jcr_job_status(jcr, JS_ErrorTerminated);
544          free_pool_memory(msg);
545          return 0;
546       }
547    }
548    free_pool_memory(msg);
549    return 1;
550 }
551
552
553 /* 
554  * Read the attributes from the File daemon for
555  * a Verify job and store them in the catalog.
556  */
557 int get_attributes_and_put_in_catalog(JCR *jcr)
558 {
559    BSOCK   *fd;
560    int n = 0;
561    ATTR_DBR ar;
562
563    fd = jcr->file_bsock;
564    jcr->jr.FirstIndex = 1;
565    memset(&ar, 0, sizeof(ar));
566    jcr->FileIndex = 0;
567
568    Dmsg0(120, "bdird: waiting to receive file attributes\n");
569    /* Pickup file attributes and signature */
570    while (!fd->errors && (n = bget_dirmsg(fd)) > 0) {
571
572    /*****FIXME****** improve error handling to stop only on 
573     * really fatal problems, or the number of errors is too
574     * large.
575     */
576       long file_index;
577       int stream, len;
578       char *attr, *p, *fn;
579       char Opts_SIG[MAXSTRING];      /* either Verify opts or MD5/SHA1 signature */
580       char SIG[MAXSTRING];
581
582       jcr->fname = check_pool_memory_size(jcr->fname, fd->msglen);
583       if ((len = sscanf(fd->msg, "%ld %d %s", &file_index, &stream, Opts_SIG)) != 3) {
584          Jmsg(jcr, M_FATAL, 0, _("<filed: bad attributes, expected 3 fields got %d\n\
585 msglen=%d msg=%s\n"), len, fd->msglen, fd->msg);
586          set_jcr_job_status(jcr, JS_ErrorTerminated);
587          return 0;
588       }
589       p = fd->msg;
590       skip_nonspaces(&p);             /* skip FileIndex */
591       skip_spaces(&p);
592       skip_nonspaces(&p);             /* skip Stream */
593       skip_spaces(&p);
594       skip_nonspaces(&p);             /* skip Opts_SHA1 */   
595       p++;                            /* skip space */
596       fn = jcr->fname;
597       while (*p != 0) {
598          *fn++ = *p++;                /* copy filename */
599       }
600       *fn = *p++;                     /* term filename and point to attribs */
601       attr = p;
602
603       if (stream == STREAM_UNIX_ATTRIBUTES || stream == STREAM_UNIX_ATTRIBUTES_EX) {
604          jcr->JobFiles++;
605          jcr->FileIndex = file_index;
606          ar.attr = attr;
607          ar.fname = jcr->fname;
608          ar.FileIndex = file_index;
609          ar.Stream = stream;
610          ar.link = NULL;
611          ar.JobId = jcr->JobId;
612          ar.ClientId = jcr->ClientId;
613          ar.PathId = 0;
614          ar.FilenameId = 0;
615
616          Dmsg2(111, "dird<filed: stream=%d %s\n", stream, jcr->fname);
617          Dmsg1(120, "dird<filed: attr=%s\n", attr);
618
619          if (!db_create_file_attributes_record(jcr, jcr->db, &ar)) {
620             Jmsg1(jcr, M_ERROR, 0, "%s", db_strerror(jcr->db));
621             set_jcr_job_status(jcr, JS_Error);
622             continue;
623          }
624          jcr->FileId = ar.FileId;
625       } else if (stream == STREAM_MD5_SIGNATURE || stream == STREAM_SHA1_SIGNATURE) {
626          if (jcr->FileIndex != (uint32_t)file_index) {
627             Jmsg2(jcr, M_ERROR, 0, _("MD5/SHA1 index %d not same as attributes %d\n"),
628                file_index, jcr->FileIndex);
629             set_jcr_job_status(jcr, JS_Error);
630             continue;
631          }
632          db_escape_string(SIG, Opts_SIG, strlen(Opts_SIG));
633          Dmsg2(120, "SIGlen=%d SIG=%s\n", strlen(SIG), SIG);
634          if (!db_add_SIG_to_file_record(jcr, jcr->db, jcr->FileId, SIG, 
635                    stream==STREAM_MD5_SIGNATURE?MD5_SIG:SHA1_SIG)) {
636             Jmsg1(jcr, M_ERROR, 0, "%s", db_strerror(jcr->db));
637             set_jcr_job_status(jcr, JS_Error);
638          }
639       }
640       jcr->jr.JobFiles = jcr->JobFiles = file_index;
641       jcr->jr.LastIndex = file_index;
642    } 
643    if (is_bnet_error(fd)) {
644       Jmsg1(jcr, M_FATAL, 0, _("<filed: Network error getting attributes. ERR=%s\n"),
645                         bnet_strerror(fd));
646       set_jcr_job_status(jcr, JS_ErrorTerminated);
647       return 0;
648    }
649
650    set_jcr_job_status(jcr, JS_Terminated);
651    return 1;
652 }