]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/dird/fd_cmds.c
e6e2853a3c87a2be3f935b1725505521f2100095
[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 fileset[]     = "fileset\n"; /* set full fileset */
42 static char jobcmd[]      = "JobId=%d Job=%s SDid=%u SDtime=%u Authorization=%s\n";
43 /* Note, mtime_only is not used here -- implemented as file option */
44 static char levelcmd[]    = "level = %s%s mtime_only=%d\n";
45 static char runbefore[]   = "RunBeforeJob %s\n";
46 static char runafter[]    = "RunAfterJob %s\n";
47
48
49 /* Responses received from File daemon */
50 static char OKinc[]       = "2000 OK include\n";
51 static char OKexc[]       = "2000 OK exclude\n";
52 static char OKjob[]       = "2000 OK Job";
53 static char OKbootstrap[] = "2000 OK bootstrap\n";
54 static char OKlevel[]     = "2000 OK level\n";
55 static char OKRunBefore[] = "2000 OK RunBefore\n";
56 static char OKRunAfter[]  = "2000 OK RunAfter\n";
57
58 /* Forward referenced functions */
59
60 /* External functions */
61 extern int debug_level;
62 extern DIRRES *director; 
63 extern int FDConnectTimeout;
64
65 #define INC_LIST 0
66 #define EXC_LIST 1
67
68 /*
69  * Open connection with File daemon. 
70  * Try connecting every retry_interval (default 10 sec), and
71  *   give up after max_retry_time (default 30 mins).
72  */
73
74 int connect_to_file_daemon(JCR *jcr, int retry_interval, int max_retry_time,
75                            int verbose)
76 {
77    BSOCK   *fd;
78
79    fd = bnet_connect(jcr, retry_interval, max_retry_time,
80         _("File daemon"), jcr->client->address, 
81         NULL, jcr->client->FDport, verbose);
82    if (fd == NULL) {
83       set_jcr_job_status(jcr, JS_ErrorTerminated);
84       return 0;
85    }
86    Dmsg0(10, "Opened connection with File daemon\n");
87    fd->res = (RES *)jcr->client;      /* save resource in BSOCK */
88    jcr->file_bsock = fd;
89    set_jcr_job_status(jcr, JS_Running);
90
91    if (!authenticate_file_daemon(jcr)) {
92       set_jcr_job_status(jcr, JS_ErrorTerminated);
93       return 0;
94    }
95         
96    /*
97     * Now send JobId and authorization key
98     */
99    bnet_fsend(fd, jobcmd, jcr->JobId, jcr->Job, jcr->VolSessionId, 
100       jcr->VolSessionTime, jcr->sd_auth_key);
101    if (strcmp(jcr->sd_auth_key, "dummy") != 0) {
102       memset(jcr->sd_auth_key, 0, strlen(jcr->sd_auth_key));
103    }
104    Dmsg1(100, ">filed: %s", fd->msg);
105    if (bget_dirmsg(fd) > 0) {
106        Dmsg1(110, "<filed: %s", fd->msg);
107        if (strncmp(fd->msg, OKjob, strlen(OKjob)) != 0) {
108           Jmsg(jcr, M_FATAL, 0, _("File daemon \"%s\" rejected Job command: %s\n"), 
109              jcr->client->hdr.name, fd->msg);
110           set_jcr_job_status(jcr, JS_ErrorTerminated);
111           return 0;
112        } else if (jcr->db) {
113           CLIENT_DBR cr;
114           memset(&cr, 0, sizeof(cr));
115           bstrncpy(cr.Name, jcr->client->hdr.name, sizeof(cr.Name));
116           cr.AutoPrune = jcr->client->AutoPrune;
117           cr.FileRetention = jcr->client->FileRetention;
118           cr.JobRetention = jcr->client->JobRetention;
119           bstrncpy(cr.Uname, fd->msg+strlen(OKjob)+1, sizeof(cr.Uname));
120           if (!db_update_client_record(jcr, jcr->db, &cr)) {
121              Jmsg(jcr, M_WARNING, 0, _("Error updating Client record. ERR=%s\n"),
122                 db_strerror(jcr->db));
123           }
124        }
125    } else {
126       Jmsg(jcr, M_FATAL, 0, _("FD gave bad response to JobId command: %s\n"),
127          bnet_strerror(fd));
128       set_jcr_job_status(jcr, JS_ErrorTerminated);
129       return 0;
130    }
131    return 1;
132 }
133
134 /*
135  * This subroutine edits the last job start time into a
136  *   "since=date/time" buffer that is returned in the  
137  *   variable since.  This is used for display purposes in
138  *   the job report.  The time in jcr->stime is later 
139  *   passed to tell the File daemon what to do.
140  */
141 void get_level_since_time(JCR *jcr, char *since, int since_len)
142 {
143    /* Lookup the last 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;     /* flag for db_find_job_start time */
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.JobLevel = L_FULL;
162       } else {
163          bstrncpy(since, ", since=", since_len);
164          bstrncat(since, jcr->stime, since_len);
165       }
166       jcr->jr.JobId = jcr->JobId;
167       break;
168    }
169    Dmsg2(100, "Level=%c last start time=%s\n", jcr->JobLevel, jcr->stime);
170 }
171
172
173 /*
174  * Send level command to FD. 
175  * Used for backup jobs and estimate command.
176  */
177 int send_level_command(JCR *jcr) 
178 {
179    BSOCK   *fd = jcr->file_bsock;
180    utime_t stime;
181    char ed1[50];
182    /* 
183     * Send Level command to File daemon
184     */
185    switch (jcr->JobLevel) {
186    case L_BASE:
187       bnet_fsend(fd, levelcmd, "base", " ", 0);
188       break;
189    /* L_NONE is the console, sending something off to the FD */
190    case L_NONE:
191    case L_FULL:
192       bnet_fsend(fd, levelcmd, "full", " ", 0);
193       break;
194    case L_DIFFERENTIAL:
195    case L_INCREMENTAL:
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                berrno be;
257                Jmsg(jcr, M_FATAL, 0, _("Cannot run program: %s. ERR=%s\n"),
258                   p, be.strerror());
259                goto bail_out;
260             }
261             /* Copy File options */
262             if (ie->num_opts) {
263                bstrncpy(buf, ie->opts_list[0]->opts, sizeof(buf));
264                bstrncat(buf, " ", sizeof(buf));
265             } else {
266                bstrncpy(buf, "0 ", sizeof(buf));
267             }
268             Dmsg1(500, "Opts=%s\n", buf);
269             optlen = strlen(buf);
270             while (fgets(buf+optlen, sizeof(buf)-optlen, bpipe->rfd)) {
271                fd->msglen = Mmsg(fd->msg, "%s", buf);
272                Dmsg2(500, "Inc/exc len=%d: %s", fd->msglen, fd->msg);
273                if (!bnet_send(fd)) {
274                   Jmsg(jcr, M_FATAL, 0, _(">filed: write error on socket\n"));
275                   goto bail_out;
276                }
277             }
278             if ((stat=close_bpipe(bpipe)) != 0) {
279                berrno be;
280                be.set_errno(stat);
281                Jmsg(jcr, M_FATAL, 0, _("Error running program %p: ERR=%s\n"),
282                   p, be.strerror());
283                goto bail_out;
284             }
285             break;
286          case '<':
287             p++;                      /* skip over < */
288             if ((ffd = fopen(p, "r")) == NULL) {
289                Jmsg(jcr, M_FATAL, 0, _("Cannot open %s file: %s. ERR=%s\n"),
290                   list==INC_LIST?"included":"excluded", p, strerror(errno));
291                goto bail_out;
292             }
293             /* Copy File options */
294             if (ie->num_opts) {
295                bstrncpy(buf, ie->opts_list[0]->opts, sizeof(buf));
296                bstrncat(buf, " ", sizeof(buf));
297             } else {
298                bstrncpy(buf, "0 ", sizeof(buf));
299             }
300             Dmsg1(500, "Opts=%s\n", buf);
301             optlen = strlen(buf);
302             while (fgets(buf+optlen, sizeof(buf)-optlen, ffd)) {
303                fd->msglen = Mmsg(fd->msg, "%s", buf);
304                if (!bnet_send(fd)) {
305                   Jmsg(jcr, M_FATAL, 0, _(">filed: write error on socket\n"));
306                   goto bail_out;
307                }
308             }
309             fclose(ffd);
310             break;
311          case '\\':
312             p++;                      /* skip over \ */
313             /* Note, fall through wanted */
314          default:
315             if (ie->num_opts) {
316                Dmsg2(500, "numopts=%d opts=%s\n", ie->num_opts, NPRT(ie->opts_list[0]->opts));
317                pm_strcpy(fd->msg, ie->opts_list[0]->opts);
318                pm_strcat(fd->msg, " ");
319             } else {
320                pm_strcpy(fd->msg, "0 ");
321             }
322             fd->msglen = pm_strcat(fd->msg, p);
323             Dmsg1(500, "Inc/Exc name=%s\n", fd->msg);
324             if (!bnet_send(fd)) {
325                Jmsg(jcr, M_FATAL, 0, _(">filed: write error on socket\n"));
326                goto bail_out;
327             }
328             break;
329          }
330       }
331    }
332    bnet_sig(fd, BNET_EOD);            /* end of data */
333    if (list == INC_LIST) {
334       if (!response(jcr, fd, OKinc, "Include", DISPLAY_ERROR)) {
335          goto bail_out;
336       }
337    } else if (!response(jcr, fd, OKexc, "Exclude", DISPLAY_ERROR)) {
338         goto bail_out;
339    }
340    return 1;
341
342 bail_out:
343    set_jcr_job_status(jcr, JS_ErrorTerminated);
344    return 0;
345
346 }
347
348
349 /*
350  * Send either an Included or an Excluded list to FD
351  */
352 static int send_fileset(JCR *jcr)
353 {
354    FILESET *fileset = jcr->fileset;
355    BSOCK   *fd = jcr->file_bsock;
356    int num;
357    bool include = true;
358
359    for ( ;; ) {
360       if (include) {
361          num = fileset->num_includes;
362       } else {
363          num = fileset->num_excludes;
364       }  
365       for (int i=0; i<num; i++) {
366          BPIPE *bpipe;
367          FILE *ffd;
368          char buf[2000];
369          char *p;
370          int optlen, stat;
371          INCEXE *ie;
372          int j, k;
373
374          if (include) {
375             ie = fileset->include_items[i];
376             bnet_fsend(fd, "I\n");
377          } else {
378             ie = fileset->exclude_items[i];
379             bnet_fsend(fd, "E\n");
380          }       
381          for (j=0; j<ie->num_opts; j++) {
382             FOPTS *fo = ie->opts_list[j];
383             bnet_fsend(fd, "O %s\n", fo->opts);
384             for (k=0; k<fo->regex.size(); k++) {
385                bnet_fsend(fd, "R %s\n", fo->regex.get(k));
386             }
387             for (k=0; k<fo->wild.size(); k++) {
388                bnet_fsend(fd, "W %s\n", fo->wild.get(k));
389             }
390             for (k=0; k<fo->base.size(); k++) {
391                bnet_fsend(fd, "B %s\n", fo->base.get(k));
392             }
393             if (fo->reader) {
394                bnet_fsend(fd, "D %s\n", fo->reader);
395             }
396             if (fo->writer) {
397                bnet_fsend(fd, "T %s\n", fo->writer);
398             }
399             bnet_fsend(fd, "N\n");
400          }
401
402          for (j=0; j<ie->name_list.size(); j++) {
403             p = (char *)ie->name_list.get(j);
404             switch (*p) {
405             case '|':
406                p++;                      /* skip over the | */
407                fd->msg = edit_job_codes(jcr, fd->msg, p, "");
408                bpipe = open_bpipe(fd->msg, 0, "r");
409                if (!bpipe) {
410                   Jmsg(jcr, M_FATAL, 0, _("Cannot run program: %s. ERR=%s\n"),
411                      p, strerror(errno));
412                   goto bail_out;
413                }
414                bstrncpy(buf, "F ", sizeof(buf));
415                Dmsg1(500, "Opts=%s\n", buf);
416                optlen = strlen(buf);
417                while (fgets(buf+optlen, sizeof(buf)-optlen, bpipe->rfd)) {
418                   fd->msglen = Mmsg(fd->msg, "%s", buf);
419                   Dmsg2(500, "Inc/exc len=%d: %s", fd->msglen, fd->msg);
420                   if (!bnet_send(fd)) {
421                      Jmsg(jcr, M_FATAL, 0, _(">filed: write error on socket\n"));
422                      goto bail_out;
423                   }
424                }
425                if ((stat=close_bpipe(bpipe)) != 0) {
426                   berrno be;
427                   be.set_errno(stat);
428                   Jmsg(jcr, M_FATAL, 0, _("Error running program: %s. ERR=%s\n"),
429                      p, be.strerror());
430                   goto bail_out;
431                }
432                break;
433             case '<':
434                p++;                      /* skip over < */
435                if ((ffd = fopen(p, "r")) == NULL) {
436                   Jmsg(jcr, M_FATAL, 0, _("Cannot open included file: %s. ERR=%s\n"),
437                      p, strerror(errno));
438                   goto bail_out;
439                }
440                bstrncpy(buf, "F ", sizeof(buf));
441                Dmsg1(500, "Opts=%s\n", buf);
442                optlen = strlen(buf);
443                while (fgets(buf+optlen, sizeof(buf)-optlen, ffd)) {
444                   fd->msglen = Mmsg(fd->msg, "%s", buf);
445                   if (!bnet_send(fd)) {
446                      Jmsg(jcr, M_FATAL, 0, _(">filed: write error on socket\n"));
447                      goto bail_out;
448                   }
449                }
450                fclose(ffd);
451                break;
452             case '\\':
453                p++;                      /* skip over \ */
454                /* Note, fall through wanted */
455             default:
456                pm_strcpy(fd->msg, "F ");
457                fd->msglen = pm_strcat(fd->msg, p);
458                Dmsg1(500, "Inc/Exc name=%s\n", fd->msg);
459                if (!bnet_send(fd)) {
460                   Jmsg(jcr, M_FATAL, 0, _(">filed: write error on socket\n"));
461                   goto bail_out;
462                }
463                break;
464             }
465          }
466          bnet_fsend(fd, "N\n");
467       }
468       if (!include) {                 /* If we just did excludes */
469          break;                       /*   all done */
470       }
471       include = false;                /* Now do excludes */
472    }
473
474    bnet_sig(fd, BNET_EOD);            /* end of data */
475    if (!response(jcr, fd, OKinc, "Include", DISPLAY_ERROR)) {
476       goto bail_out;
477    }
478    return 1;
479
480 bail_out:
481    set_jcr_job_status(jcr, JS_ErrorTerminated);
482    return 0;
483
484 }
485
486
487 /*
488  * Send include list to File daemon
489  */
490 int send_include_list(JCR *jcr)
491 {
492    BSOCK *fd = jcr->file_bsock;
493    if (jcr->fileset->new_include) {
494       bnet_fsend(fd, fileset);
495       return send_fileset(jcr);
496    } else {
497       bnet_fsend(fd, inc);
498    }
499    return send_list(jcr, INC_LIST);
500 }
501
502
503 /*
504  * Send exclude list to File daemon 
505  */
506 int send_exclude_list(JCR *jcr)
507 {
508    BSOCK *fd = jcr->file_bsock;
509    if (jcr->fileset->new_include) {
510       return 1;
511    }
512    bnet_fsend(fd, exc);
513    return send_list(jcr, EXC_LIST);
514 }
515
516
517 /*
518  * Send bootstrap file if any to the File daemon.
519  *  This is used for restore and verify VolumeToCatalog
520  */
521 int send_bootstrap_file(JCR *jcr)
522 {
523    FILE *bs;
524    char buf[1000];
525    BSOCK *fd = jcr->file_bsock;
526    const char *bootstrap = "bootstrap\n";
527
528    Dmsg1(400, "send_bootstrap_file: %s\n", jcr->RestoreBootstrap);
529    if (!jcr->RestoreBootstrap) {
530       return 1;
531    }
532    bs = fopen(jcr->RestoreBootstrap, "r");
533    if (!bs) {
534       Jmsg(jcr, M_FATAL, 0, _("Could not open bootstrap file %s: ERR=%s\n"), 
535          jcr->RestoreBootstrap, strerror(errno));
536       set_jcr_job_status(jcr, JS_ErrorTerminated);
537       return 0;
538    }
539    bnet_fsend(fd, bootstrap);
540    while (fgets(buf, sizeof(buf), bs)) {
541       bnet_fsend(fd, "%s", buf);       
542    }
543    bnet_sig(fd, BNET_EOD);
544    fclose(bs);
545    if (!response(jcr, fd, OKbootstrap, "Bootstrap", DISPLAY_ERROR)) {
546       set_jcr_job_status(jcr, JS_ErrorTerminated);
547       return 0;
548    }
549    return 1;
550 }
551
552 /*
553  * Send ClientRunBeforeJob and ClientRunAfterJob to File daemon
554  */
555 int send_run_before_and_after_commands(JCR *jcr)
556 {
557    POOLMEM *msg = get_pool_memory(PM_FNAME);
558    BSOCK *fd = jcr->file_bsock;
559    if (jcr->job->ClientRunBeforeJob) {
560       pm_strcpy(msg, jcr->job->ClientRunBeforeJob);
561       bash_spaces(msg);
562       bnet_fsend(fd, runbefore, msg);
563       if (!response(jcr, fd, OKRunBefore, "ClientRunBeforeJob", DISPLAY_ERROR)) {
564          set_jcr_job_status(jcr, JS_ErrorTerminated);
565          free_pool_memory(msg);
566          return 0;
567       }
568    }
569    if (jcr->job->ClientRunAfterJob) {
570       fd->msglen = pm_strcpy(msg, jcr->job->ClientRunAfterJob);
571       bash_spaces(msg);
572       bnet_fsend(fd, runafter, msg);
573       if (!response(jcr, fd, OKRunAfter, "ClientRunAfterJob", DISPLAY_ERROR)) {
574          set_jcr_job_status(jcr, JS_ErrorTerminated);
575          free_pool_memory(msg);
576          return 0;
577       }
578    }
579    free_pool_memory(msg);
580    return 1;
581 }
582
583
584 /* 
585  * Read the attributes from the File daemon for
586  * a Verify job and store them in the catalog.
587  */
588 int get_attributes_and_put_in_catalog(JCR *jcr)
589 {
590    BSOCK   *fd;
591    int n = 0;
592    ATTR_DBR ar;
593
594    fd = jcr->file_bsock;
595    jcr->jr.FirstIndex = 1;
596    memset(&ar, 0, sizeof(ar));
597    jcr->FileIndex = 0;
598
599    Dmsg0(120, "bdird: waiting to receive file attributes\n");
600    /* Pickup file attributes and signature */
601    while (!fd->errors && (n = bget_dirmsg(fd)) > 0) {
602
603    /*****FIXME****** improve error handling to stop only on 
604     * really fatal problems, or the number of errors is too
605     * large.
606     */
607       long file_index;
608       int stream, len;
609       char *attr, *p, *fn;
610       char Opts_SIG[MAXSTRING];      /* either Verify opts or MD5/SHA1 signature */
611       char SIG[MAXSTRING];
612
613       jcr->fname = check_pool_memory_size(jcr->fname, fd->msglen);
614       if ((len = sscanf(fd->msg, "%ld %d %s", &file_index, &stream, Opts_SIG)) != 3) {
615          Jmsg(jcr, M_FATAL, 0, _("<filed: bad attributes, expected 3 fields got %d\n\
616 msglen=%d msg=%s\n"), len, fd->msglen, fd->msg);
617          set_jcr_job_status(jcr, JS_ErrorTerminated);
618          return 0;
619       }
620       p = fd->msg;
621       skip_nonspaces(&p);             /* skip FileIndex */
622       skip_spaces(&p);
623       skip_nonspaces(&p);             /* skip Stream */
624       skip_spaces(&p);
625       skip_nonspaces(&p);             /* skip Opts_SHA1 */   
626       p++;                            /* skip space */
627       fn = jcr->fname;
628       while (*p != 0) {
629          *fn++ = *p++;                /* copy filename */
630       }
631       *fn = *p++;                     /* term filename and point to attribs */
632       attr = p;
633
634       if (stream == STREAM_UNIX_ATTRIBUTES || stream == STREAM_UNIX_ATTRIBUTES_EX) {
635          jcr->JobFiles++;
636          jcr->FileIndex = file_index;
637          ar.attr = attr;
638          ar.fname = jcr->fname;
639          ar.FileIndex = file_index;
640          ar.Stream = stream;
641          ar.link = NULL;
642          ar.JobId = jcr->JobId;
643          ar.ClientId = jcr->ClientId;
644          ar.PathId = 0;
645          ar.FilenameId = 0;
646
647          Dmsg2(111, "dird<filed: stream=%d %s\n", stream, jcr->fname);
648          Dmsg1(120, "dird<filed: attr=%s\n", attr);
649
650          if (!db_create_file_attributes_record(jcr, jcr->db, &ar)) {
651             Jmsg1(jcr, M_ERROR, 0, "%s", db_strerror(jcr->db));
652             set_jcr_job_status(jcr, JS_Error);
653             continue;
654          }
655          jcr->FileId = ar.FileId;
656       } else if (stream == STREAM_MD5_SIGNATURE || stream == STREAM_SHA1_SIGNATURE) {
657          if (jcr->FileIndex != (uint32_t)file_index) {
658             Jmsg2(jcr, M_ERROR, 0, _("MD5/SHA1 index %d not same as attributes %d\n"),
659                file_index, jcr->FileIndex);
660             set_jcr_job_status(jcr, JS_Error);
661             continue;
662          }
663          db_escape_string(SIG, Opts_SIG, strlen(Opts_SIG));
664          Dmsg2(120, "SIGlen=%d SIG=%s\n", strlen(SIG), SIG);
665          if (!db_add_SIG_to_file_record(jcr, jcr->db, jcr->FileId, SIG, 
666                    stream==STREAM_MD5_SIGNATURE?MD5_SIG:SHA1_SIG)) {
667             Jmsg1(jcr, M_ERROR, 0, "%s", db_strerror(jcr->db));
668             set_jcr_job_status(jcr, JS_Error);
669          }
670       }
671       jcr->jr.JobFiles = jcr->JobFiles = file_index;
672       jcr->jr.LastIndex = file_index;
673    } 
674    if (is_bnet_error(fd)) {
675       Jmsg1(jcr, M_FATAL, 0, _("<filed: Network error getting attributes. ERR=%s\n"),
676                         bnet_strerror(fd));
677       set_jcr_job_status(jcr, JS_ErrorTerminated);
678       return 0;
679    }
680
681    set_jcr_job_status(jcr, JS_Terminated);
682    return 1;
683 }