]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/dird/fd_cmds.c
Fix buffer overrun in FD
[bacula/bacula] / bacula / src / dird / fd_cmds.c
index 91895887ea8c536005a9ef9e5a8b1b9ec1cde592..9d95ce50c2f9d8b9cb5caaa484d511c1f4a1b5f0 100644 (file)
@@ -1,21 +1,7 @@
-/*
- *
- *   Bacula Director -- fd_cmds.c -- send commands to File daemon
- *
- *     Kern Sibbald, October MM
- *
- *    This routine is run as a separate thread.  There may be more
- *    work to be done to make it totally reentrant!!!!
- *
- *  Utility functions for sending info to File Daemon.
- *   These functions are used by both backup and verify.
- *
- *   Version $Id$
- */
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2000-2006 Free Software Foundation Europe e.V.
+   Copyright (C) 2000-2007 Free Software Foundation Europe e.V.
 
    The main author of Bacula is Kern Sibbald, with contributions from
    many others, a complete list can be found in the file AUTHORS.
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   Bacula® is a registered trademark ofJohn Walker.
+   Bacula® is a registered trademark of John Walker.
    The licensor of Bacula is the Free Software Foundation Europe
    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
    Switzerland, email:ftf@fsfeurope.org.
 */
+/*
+ *
+ *   Bacula Director -- fd_cmds.c -- send commands to File daemon
+ *
+ *     Kern Sibbald, October MM
+ *
+ *    This routine is run as a separate thread.  There may be more
+ *    work to be done to make it totally reentrant!!!!
+ *
+ *  Utility functions for sending info to File Daemon.
+ *   These functions are used by both backup and verify.
+ *
+ *   Version $Id$
+ */
 
 #include "bacula.h"
 #include "dird.h"
@@ -79,9 +79,16 @@ int connect_to_file_daemon(JCR *jcr, int retry_interval, int max_retry_time,
 {
    BSOCK   *fd;
    char ed1[30];
+   utime_t heart_beat;
+
+   if (jcr->client->heartbeat_interval) {
+      heart_beat = jcr->client->heartbeat_interval;
+   } else {           
+      heart_beat = director->heartbeat_interval;
+   }
 
    if (!jcr->file_bsock) {
-      fd = bnet_connect(jcr, retry_interval, max_retry_time,
+      fd = bnet_connect(jcr, retry_interval, max_retry_time, heart_beat,
            _("File daemon"), jcr->client->address,
            NULL, jcr->client->FDport, verbose);
       if (fd == NULL) {
@@ -345,7 +352,7 @@ static bool send_fileset(JCR *jcr)
                if (!bpipe) {
                   berrno be;
                   Jmsg(jcr, M_FATAL, 0, _("Cannot run program: %s. ERR=%s\n"),
-                     p, be.strerror());
+                     p, be.bstrerror());
                   goto bail_out;
                }
                bstrncpy(buf, "F ", sizeof(buf));
@@ -362,7 +369,7 @@ static bool send_fileset(JCR *jcr)
                if ((stat=close_bpipe(bpipe)) != 0) {
                   berrno be;
                   Jmsg(jcr, M_FATAL, 0, _("Error running program: %s. ERR=%s\n"),
-                     p, be.strerror(stat));
+                     p, be.bstrerror(stat));
                   goto bail_out;
                }
                break;
@@ -371,7 +378,7 @@ static bool send_fileset(JCR *jcr)
                if ((ffd = fopen(p, "rb")) == NULL) {
                   berrno be;
                   Jmsg(jcr, M_FATAL, 0, _("Cannot open included file: %s. ERR=%s\n"),
-                     p, be.strerror());
+                     p, be.bstrerror());
                   goto bail_out;
                }
                bstrncpy(buf, "F ", sizeof(buf));
@@ -466,7 +473,7 @@ bool send_bootstrap_file(JCR *jcr, BSOCK *sock)
    if (!bs) {
       berrno be;
       Jmsg(jcr, M_FATAL, 0, _("Could not open bootstrap file %s: ERR=%s\n"),
-         jcr->RestoreBootstrap, be.strerror());
+         jcr->RestoreBootstrap, be.bstrerror());
       set_jcr_job_status(jcr, JS_ErrorTerminated);
       return false;
    }
@@ -505,6 +512,9 @@ int send_runscript_with_old_proto(JCR *jcr, int when, POOLMEM *msg)
 
 /*
  * Send RunScripts to File daemon
+ * 1) We send all runscript to FD, they can be executed Before, After, or twice
+ * 2) Then, we send a "RunBeforeNow" command to the FD to tell him to do the
+ *    first run_script() call. (ie ClientRunBeforeJob)
  */
 int send_runscripts_commands(JCR *jcr)
 {
@@ -552,15 +562,16 @@ int send_runscripts_commands(JCR *jcr)
                return 0;
             }
          }
+         /* TODO : we have to play with other client */
          /*
            else {
            send command to an other client
            }
          */
       }        
-   }
-   
-   /* TODO : we have to play with other client */
+   } 
+
+   /* We tell to the FD that i can execute commands (ie ClientRunBeforeJob) */
    if (launch_before_cmd) {
       bnet_fsend(fd, runbeforenow);
       if (!response(jcr, fd, OKRunBeforeNow, "RunBeforeNow", DISPLAY_ERROR)) {