src/stored/hello.c
void handle_client_connection(BSOCK *fd)
{
   JCR *jcr;
   int fd_version = 0;
   int sd_version = 0;
   char job_name[500];
   /*
    * Do a sanity check on the message received
    */
   if (fd->msglen < 25 || fd->msglen > (int)sizeof(job_name)) {
      Pmsg1(000, "<filed: %s", fd->msg);
      Qmsg2(NULL, M_SECURITY, 0, _("Invalid connection from %s. Len=%d\n"), fd->who(), fd->msglen);
      bmicrosleep(5, 0);   /* make user wait 5 seconds */
      fd->destroy();
      return;
   }

   Dmsg1(100, "Conn: %s", fd->msg);
   /*
    * See if this is a File daemon connection. If so
    *   call FD handler.
    */
   if (sscanf(fd->msg, "Hello Bacula SD: Start Job %127s %d %d", job_name, &fd_version, &sd_version) != 3 &&
       sscanf(fd->msg, "Hello FD: Bacula Storage calling Start Job %127s %d", job_name, &sd_version) != 2 &&
       sscanf(fd->msg, "Hello Start Job %127s", job_name) != 1) {
      Qmsg2(NULL, M_SECURITY, 0, _("Invalid Hello from %s. Len=%d\n"), fd->who(), fd->msglen);
      sleep(5);
      fd->destroy();
      return;
   }

   if (!(jcr=get_jcr_by_full_name(job_name))) {
      Qmsg1(NULL, M_SECURITY, 0, _("Client connect failed: Job name not found: %s\n"), job_name);
      Dmsg1(3, "**** Job \"%s\" not found.\n", job_name);
      sleep(5);
      fd->destroy();
      return;
   }

   /* After this point, we can use bail_out */
   Dmsg1(100, "Found Client Job %s\n", job_name);
   if (jcr->authenticated) {
      Jmsg3(jcr, M_SECURITY, 0, _("A Client \"%s\" tried to authenticate for Job %s, "
                                 "but the Job is already authenticated with \"%s\".\n"),
            fd->who(), jcr->Job, jcr->file_bsock?jcr->file_bsock->who():"N/A");
      Dmsg2(050, "Hey!!!! JobId %u Job %s already authenticated.\n",
         (uint32_t)jcr->JobId, jcr->Job);
      goto bail_out;
   }

   fd->set_jcr(jcr);
   Dmsg2(050, "fd_version=%d sd_version=%d\n", fd_version, sd_version);

   /* Turn on compression for newer FDs */
   if (fd_version >= 214 || sd_version >= 306) {
      fd->set_compress();             /* set compression allowed */
   } else {
      fd->clear_compress();
      Dmsg0(050, "*** No SD compression to FD\n");
   }

   /*
    * Authenticate the Client (FD or SD)
    */
   jcr->lock_auth();     /* Ensure that only one thread is dealing with auth */
   if (jcr->authenticated) {
      Jmsg2(jcr, M_SECURITY, 0, _("A Client \"%s\" tried to authenticate for Job %s, "
                                 "but the job is already authenticated.\n"),
            fd->who(), jcr->Job);

   } else if (!authenticate_filed(jcr, fd, fd_version)) {
      Dmsg1(50, "Authentication failed Job %s\n", jcr->Job);
      /* Job not yet started, we can cancel */
      Jmsg(jcr, M_SECURITY, 0, _("Unable to authenticate File daemon\n"));

   } else {
      Dmsg2(050, "OK Authentication jid=%u Job %s\n", (uint32_t)jcr->JobId, jcr->Job);
      jcr->file_bsock = fd;
      jcr->FDVersion = fd_version;
      jcr->SDVersion = sd_version;
      jcr->authenticated = true;

      if (sd_version > 0) {
         jcr->sd_client = true;
      }
   }
   jcr->unlock_auth();

   if (!jcr->authenticated) {
      jcr->setJobStatus(JS_ErrorTerminated);
   }

   Dmsg4(050, "=== Auth %s, unblock Job %s jid=%d sd_ver=%d\n",
         jcr->authenticated?"OK":"KO", job_name, jcr->JobId, sd_version);

bail_out:
   /* file_bsock might be NULL or a previous BSOCK */
   if (jcr->file_bsock != fd) {
      fd->destroy();
   }
   pthread_cond_signal(&jcr->job_start_wait); /* wake waiting job */
   free_jcr(jcr);
   if (!jcr->authenticated) {
      sleep(5);
   }
   return;
}
/*
 * After receiving a connection (in dircmd.c) if it is
 *   from the File daemon, this routine is called.
 */
After receiving a connection (in dircmd.c) if it is
from the File daemon, this routine is called.
After receiving a connection ( in dircmd . c ) if it is from the File daemon this routine is called .
void handle_client_connection(BSOCK *fd)
{
   JCR *jcr;
   int fd_version = 0;
   int sd_version = 0;
   char job_name[500];
   if (fd->msglen < 25 || fd->msglen > (int)sizeof(job_name)) {
      Pmsg1(000, "<filed: %s", fd->msg);
      Qmsg2(NULL, M_SECURITY, 0, _("Invalid connection from %s. Len=%d\n"), fd->who(), fd->msglen);
      bmicrosleep(5, 0);   
      fd->destroy();
      return;
   }
   Dmsg1(100, "Conn: %s", fd->msg);
   if (sscanf(fd->msg, "Hello Bacula SD: Start Job %127s %d %d", job_name, &fd_version, &sd_version) != 3 &&
       sscanf(fd->msg, "Hello FD: Bacula Storage calling Start Job %127s %d", job_name, &sd_version) != 2 &&
       sscanf(fd->msg, "Hello Start Job %127s", job_name) != 1) {
      Qmsg2(NULL, M_SECURITY, 0, _("Invalid Hello from %s. Len=%d\n"), fd->who(), fd->msglen);
      sleep(5);
      fd->destroy();
      return;
   }
   if (!(jcr=get_jcr_by_full_name(job_name))) {
      Qmsg1(NULL, M_SECURITY, 0, _("Client connect failed: Job name not found: %s\n"), job_name);
      Dmsg1(3, "**** Job \"%s\" not found.\n", job_name);
      sleep(5);
      fd->destroy();
      return;
   }
   Dmsg1(100, "Found Client Job %s\n", job_name);
   if (jcr->authenticated) {
      Jmsg3(jcr, M_SECURITY, 0, _("A Client \"%s\" tried to authenticate for Job %s, "
                                 "but the Job is already authenticated with \"%s\".\n"),
            fd->who(), jcr->Job, jcr->file_bsock?jcr->file_bsock->who():"N/A");
      Dmsg2(050, "Hey!!!! JobId %u Job %s already authenticated.\n",
         (uint32_t)jcr->JobId, jcr->Job);
      goto bail_out;
   }
   fd->set_jcr(jcr);
   Dmsg2(050, "fd_version=%d sd_version=%d\n", fd_version, sd_version);
   if (fd_version >= 214 || sd_version >= 306) {
      fd->set_compress();             
   } else {
      fd->clear_compress();
      Dmsg0(050, "*** No SD compression to FD\n");
   }
   jcr->lock_auth();     
   if (jcr->authenticated) {
      Jmsg2(jcr, M_SECURITY, 0, _("A Client \"%s\" tried to authenticate for Job %s, "
                                 "but the job is already authenticated.\n"),
            fd->who(), jcr->Job);
   } else if (!authenticate_filed(jcr, fd, fd_version)) {
      Dmsg1(50, "Authentication failed Job %s\n", jcr->Job);
      Jmsg(jcr, M_SECURITY, 0, _("Unable to authenticate File daemon\n"));
   } else {
      Dmsg2(050, "OK Authentication jid=%u Job %s\n", (uint32_t)jcr->JobId, jcr->Job);
      jcr->file_bsock = fd;
      jcr->FDVersion = fd_version;
      jcr->SDVersion = sd_version;
      jcr->authenticated = true;
      if (sd_version > 0) {
         jcr->sd_client = true;
      }
   }
   jcr->unlock_auth();
   if (!jcr->authenticated) {
      jcr->setJobStatus(JS_ErrorTerminated);
   }
   Dmsg4(050, "=== Auth %s, unblock Job %s jid=%d sd_ver=%d\n",
         jcr->authenticated?"OK":"KO", job_name, jcr->JobId, sd_version);
bail_out:
   if (jcr->file_bsock != fd) {
      fd->destroy();
   }
   pthread_cond_signal(&jcr->job_start_wait); 
   free_jcr(jcr);
   if (!jcr->authenticated) {
      sleep(5);
   }
   return;
}
void handle_client_connection ( BSOCK * fd ) { JCR * jcr ; int fd_version = 0 ; int sd_version = 0 ; char job_name [ 500 ] ; if ( fd -> msglen < 25 || fd -> msglen > ( int ) sizeof ( job_name ) ) { Pmsg1 ( 000 , " " , fd -> msg ) ; Qmsg2 ( NULL , M_SECURITY , 0 , _ ( " \n " ) , fd -> who ( ) , fd -> msglen ) ; bmicrosleep ( 5 , 0 ) ; fd -> destroy ( ) ; return ; } Dmsg1 ( 100 , " " , fd -> msg ) ; if ( sscanf ( fd -> msg , " " , job_name , & fd_version , & sd_version ) != 3 && sscanf ( fd -> msg , " " , job_name , & sd_version ) != 2 && sscanf ( fd -> msg , " " , job_name ) != 1 ) { Qmsg2 ( NULL , M_SECURITY , 0 , _ ( " \n " ) , fd -> who ( ) , fd -> msglen ) ; sleep ( 5 ) ; fd -> destroy ( ) ; return ; } if ( ! ( jcr = get_jcr_by_full_name ( job_name ) ) ) { Qmsg1 ( NULL , M_SECURITY , 0 , _ ( " \n " ) , job_name ) ; Dmsg1 ( 3 , " \" \" \n " , job_name ) ; sleep ( 5 ) ; fd -> destroy ( ) ; return ; } Dmsg1 ( 100 , " \n " , job_name ) ; if ( jcr -> authenticated ) { Jmsg3 ( jcr , M_SECURITY , 0 , _ ( " \" \" " " \" \" \n " ) , fd -> who ( ) , jcr -> Job , jcr -> file_bsock ? jcr -> file_bsock -> who ( ) : " " ) ; Dmsg2 ( 050 , " \n " , ( uint32_t ) jcr -> JobId , jcr -> Job ) ; goto bail_out ; } fd -> set_jcr ( jcr ) ; Dmsg2 ( 050 , " \n " , fd_version , sd_version ) ; if ( fd_version >= 214 || sd_version >= 306 ) { fd -> set_compress ( ) ; } else { fd -> clear_compress ( ) ; Dmsg0 ( 050 , " \n " ) ; } jcr -> lock_auth ( ) ; if ( jcr -> authenticated ) { Jmsg2 ( jcr , M_SECURITY , 0 , _ ( " \" \" " " \n " ) , fd -> who ( ) , jcr -> Job ) ; } else if ( ! authenticate_filed ( jcr , fd , fd_version ) ) { Dmsg1 ( 50 , " \n " , jcr -> Job ) ; Jmsg ( jcr , M_SECURITY , 0 , _ ( " \n " ) ) ; } else { Dmsg2 ( 050 , " \n " , ( uint32_t ) jcr -> JobId , jcr -> Job ) ; jcr -> file_bsock = fd ; jcr -> FDVersion = fd_version ; jcr -> SDVersion = sd_version ; jcr -> authenticated = true ; if ( sd_version > 0 ) { jcr -> sd_client = true ; } } jcr -> unlock_auth ( ) ; if ( ! jcr -> authenticated ) { jcr -> setJobStatus ( JS_ErrorTerminated ) ; } Dmsg4 ( 050 , " \n " , jcr -> authenticated ? " " : " " , job_name , jcr -> JobId , sd_version ) ; bail_out : if ( jcr -> file_bsock != fd ) { fd -> destroy ( ) ; } pthread_cond_signal ( & jcr -> job_start_wait ) ; free_jcr ( jcr ) ; if ( ! jcr -> authenticated ) { sleep ( 5 ) ; } return ; }
After receiving a connection (in dircmd.c) if it is
   from the File daemon, this routine is called.
After receiving a connection ( in dircmd . c ) if it is from the File daemon this routine is called .
/*
    * Do a sanity check on the message received
    */ /* make user wait 5 seconds */ /*
    * See if this is a File daemon connection. If so
    *   call FD handler.
    */ /* After this point, we can use bail_out */ /* Turn on compression for newer FDs */ /* set compression allowed */ /*
    * Authenticate the Client (FD or SD)
    */ /* Ensure that only one thread is dealing with auth */ /* Job not yet started, we can cancel */ /* file_bsock might be NULL or a previous BSOCK */ /* wake waiting job */