]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/dird/fd_cmds.c
Important protocol change -- see kes29Oct02
[bacula/bacula] / bacula / src / dird / fd_cmds.c
index 304fb776122282aa4620f786413d4259004367b0..8ec2304133d2686e7a7231b0e8456b24d0758150 100644 (file)
@@ -44,7 +44,7 @@ static char jobcmd[]      = "JobId=%d Job=%s SDid=%u SDtime=%u Authorization=%s\
 /* Responses received from File daemon */
 static char OKinc[]      = "2000 OK include\n";
 static char OKexc[]      = "2000 OK exclude\n";
-static char OKjob[]      = "2000 OK Job\n";
+static char OKjob[]      = "2000 OK Job";
 
 /* Forward referenced functions */
 
@@ -85,14 +85,16 @@ int connect_to_file_daemon(JCR *jcr, int retry_interval, int max_retry_time,
     */
    bnet_fsend(fd, jobcmd, jcr->JobId, jcr->Job, jcr->VolSessionId, 
       jcr->VolSessionTime, jcr->sd_auth_key);
-   Dmsg1(10, ">filed: %s", fd->msg);
+   Dmsg1(110, ">filed: %s", fd->msg);
    if (bnet_recv(fd) > 0) {
-       Dmsg1(10, "<filed: %s", fd->msg);
-       if (strcmp(fd->msg, OKjob) != 0) {
+       Dmsg1(110, "<filed: %s", fd->msg);
+       if (strncmp(fd->msg, OKjob, strlen(OKjob)) != 0) {
           Jmsg(jcr, M_FATAL, 0, _("File daemon rejected Job command: %s\n"), fd->msg);
          jcr->JobStatus = JS_ErrorTerminated;
          return 0;
-       } 
+       } else {
+         /***** ***FIXME***** update Client Uname */
+       }
    } else {
       Jmsg(jcr, M_FATAL, 0, _("<filed: bad response to JobId command: %s\n"),
         bnet_strerror(fd));
@@ -122,15 +124,16 @@ int send_include_list(JCR *jcr)
    bnet_send(fd);
    for (i=0; i < fileset->num_includes; i++) {
       fd->msglen = strlen(fileset->include_array[i]);
-      Dmsg1(20, "dird>filed: include file: %s\n", fileset->include_array[i]);
+      Dmsg1(120, "dird>filed: include file: %s\n", fileset->include_array[i]);
       fd->msg = fileset->include_array[i];
       if (!bnet_send(fd)) {
+        fd->msg = msgsave;
          Emsg0(M_FATAL, 0, _(">filed: write error on socket\n"));
         jcr->JobStatus = JS_ErrorTerminated;
         return 0;
       }
    }
-   bnet_sig(fd, BNET_EOF);
+   bnet_sig(fd, BNET_EOD);           /* end of data */
    fd->msg = msgsave;
    if (!response(fd, OKinc, "Include")) {
       jcr->JobStatus = JS_ErrorTerminated;
@@ -157,7 +160,7 @@ int send_exclude_list(JCR *jcr)
    bnet_send(fd);
    for (i=0; i < fileset->num_excludes; i++) {
       fd->msglen = strlen(fileset->exclude_array[i]);
-      Dmsg1(20, "dird>filed: exclude file: %s\n", fileset->exclude_array[i]);
+      Dmsg1(120, "dird>filed: exclude file: %s\n", fileset->exclude_array[i]);
       fd->msg = fileset->exclude_array[i];
       if (!bnet_send(fd)) {
          Emsg0(M_FATAL, 0, _(">filed: write error on socket\n"));
@@ -165,7 +168,7 @@ int send_exclude_list(JCR *jcr)
         return 0;
       }
    }
-   bnet_sig(fd, BNET_EOF);
+   bnet_sig(fd, BNET_EOD);
    fd->msg = msgsave;
    if (!response(fd, OKexc, "Exclude")) {
       jcr->JobStatus = JS_ErrorTerminated;
@@ -182,14 +185,15 @@ int send_exclude_list(JCR *jcr)
 int get_attributes_and_put_in_catalog(JCR *jcr)
 {
    BSOCK   *fd;
-   int n;
+   int n = 0;
    ATTR_DBR ar;
 
    fd = jcr->file_bsock;
    jcr->jr.FirstIndex = 1;
    memset(&ar, 0, sizeof(ar));
+   jcr->FileIndex = 0;
 
-   Dmsg0(20, "bdird: waiting to receive file attributes\n");
+   Dmsg0(120, "bdird: waiting to receive file attributes\n");
    /* Pickup file attributes and signature */
    while (!fd->errors && (n = bget_msg(fd, 0)) > 0) {
 
@@ -197,61 +201,74 @@ int get_attributes_and_put_in_catalog(JCR *jcr)
     * really fatal problems, or the number of errors is too
     * large.
     */
-       long file_index;
-       int stream, len;
-       char *attr, buf[MAXSTRING];
-       char Opts[MAXSTRING];         /* either Verify opts or MD5 signature */
-
-       /* ***FIXME*** check fname length */
-       if ((len = sscanf(fd->msg, "%ld %d %s %s", &file_index, &stream, 
-            Opts, jcr->fname)) != 4) {
-          Jmsg(jcr, M_FATAL, 0, _("<filed: bad attributes, expected 4 fields got %d\n\
+      long file_index;
+      int stream, len;
+      char *attr, *p, *fn;
+      char Opts_MD5[MAXSTRING];      /* either Verify opts or MD5 signature */
+      char MD5[MAXSTRING];
+
+      jcr->fname = check_pool_memory_size(jcr->fname, fd->msglen);
+      if ((len = sscanf(fd->msg, "%ld %d %s", &file_index, &stream, Opts_MD5)) != 3) {
+         Jmsg(jcr, M_FATAL, 0, _("<filed: bad attributes, expected 3 fields got %d\n\
 msglen=%d msg=%s\n"), len, fd->msglen, fd->msg);
-         jcr->JobStatus = JS_ErrorTerminated;
-         return 0;
-       }
-
-       if (stream == STREAM_UNIX_ATTRIBUTES) {
-         jcr->JobFiles++;
-         len = strlen(fd->msg);      /* length before attributes */
-         ar.attr = &fd->msg[len+1];
-         ar.fname = jcr->fname;
-         ar.FileIndex = 0;           /* used as mark field during compare */
-         ar.Stream = stream;
-         ar.link = NULL;
-         ar.JobId = jcr->JobId;
-         ar.ClientId = jcr->ClientId;
-         ar.PathId = 0;
-         ar.FilenameId = 0;
-
-          Dmsg2(11, "dird<filed: stream=%d %s\n", stream, jcr->fname);
-          Dmsg1(20, "dird<filed: attr=%s\n", attr);
-
-         /* ***FIXME*** fix link field */
-         if (!db_create_file_attributes_record(jcr->db, &ar)) {
-             Jmsg1(jcr, M_FATAL, 0, "%s", db_strerror(jcr->db));
-            jcr->JobStatus = JS_ErrorTerminated;
-            /* This probably should not really be fatal *****FIXME****** */
-            return 0;
-         }
-         jcr->FileIndex = file_index;
-         jcr->FileId = ar.FileId;
-       } else if (stream == STREAM_MD5_SIGNATURE) {
-         if (jcr->FileIndex != (uint32_t)file_index) {
-             Jmsg0(jcr, M_FATAL, 0, _("Got MD5 but not same block as attributes\n"));
-            jcr->JobStatus = JS_ErrorTerminated;
-            return 0;
-         }
-         db_escape_string(buf, Opts, strlen(Opts));
-          Dmsg2(20, "MD5len=%d MD5=%s\n", strlen(buf), buf);
-         if (!db_add_MD5_to_file_record(jcr->db, jcr->FileId, buf)) {
-             Jmsg1(jcr, M_WARNING, 0, "%s", db_strerror(jcr->db));
-         }
-       }
-       jcr->jr.JobFiles = jcr->JobFiles = file_index;
-       jcr->jr.LastIndex = file_index;
+        jcr->JobStatus = JS_ErrorTerminated;
+        return 0;
+      }
+      p = fd->msg;
+      skip_nonspaces(&p);            /* skip FileIndex */
+      skip_spaces(&p);
+      skip_nonspaces(&p);            /* skip Stream */
+      skip_spaces(&p);
+      skip_nonspaces(&p);            /* skip Opts_MD5 */   
+      p++;                           /* skip space */
+      fn = jcr->fname;
+      while (*p != 0) {
+        *fn++ = *p++;                /* copy filename */
+      }
+      *fn = *p++;                    /* term filename and point to attribs */
+      attr = p;
+
+      if (stream == STREAM_UNIX_ATTRIBUTES || stream == STREAM_WIN32_ATTRIBUTES) {
+        jcr->JobFiles++;
+        jcr->FileIndex = file_index;
+        ar.attr = attr;
+        ar.fname = jcr->fname;
+        ar.FileIndex = file_index;
+        ar.Stream = stream;
+        ar.link = NULL;
+        ar.JobId = jcr->JobId;
+        ar.ClientId = jcr->ClientId;
+        ar.PathId = 0;
+        ar.FilenameId = 0;
+
+         Dmsg2(111, "dird<filed: stream=%d %s\n", stream, jcr->fname);
+         Dmsg1(120, "dird<filed: attr=%s\n", attr);
+
+        /* ***FIXME*** fix link field */
+        if (!db_create_file_attributes_record(jcr->db, &ar)) {
+            Jmsg1(jcr, M_ERROR, 0, "%s", db_strerror(jcr->db));
+           jcr->JobStatus = JS_Error;
+           continue;
+        }
+        jcr->FileId = ar.FileId;
+      } else if (stream == STREAM_MD5_SIGNATURE) {
+        if (jcr->FileIndex != (uint32_t)file_index) {
+            Jmsg2(jcr, M_ERROR, 0, _("MD5 index %d not same as attributes %d\n"),
+              file_index, jcr->FileIndex);
+           jcr->JobStatus = JS_Error;
+           continue;
+        }
+        db_escape_string(MD5, Opts_MD5, strlen(Opts_MD5));
+         Dmsg2(120, "MD5len=%d MD5=%s\n", strlen(MD5), MD5);
+        if (!db_add_MD5_to_file_record(jcr->db, jcr->FileId, MD5)) {
+            Jmsg1(jcr, M_ERROR, 0, "%s", db_strerror(jcr->db));
+           jcr->JobStatus = JS_Error;
+        }
+      }
+      jcr->jr.JobFiles = jcr->JobFiles = file_index;
+      jcr->jr.LastIndex = file_index;
    } 
-   if (n < 0) {
+   if (is_bnet_error(fd)) {
       Jmsg1(jcr, M_FATAL, 0, _("<filed: Network error getting attributes. ERR=%s\n"),
                        bnet_strerror(fd));
       jcr->JobStatus = JS_ErrorTerminated;