src/stored/dircmd.c
static bool storage_cmd(JCR *jcr)
{
   int stored_port;                /* storage daemon port */
   int enable_ssl;                 /* enable ssl to sd */
   char sd_auth_key[200];
   BSOCK *dir = jcr->dir_bsock;
   BSOCK *sd = new_bsock();        /* storage daemon bsock */
   char Job[MAX_NAME_LENGTH];

   Dmsg1(050, "StorageCmd: %s", dir->msg);
   if (sscanf(dir->msg, storaddr, &jcr->stored_addr, &stored_port,
              &enable_ssl, Job, sd_auth_key) != 5) {
      pm_strcpy(jcr->errmsg, dir->msg);
      Jmsg(jcr, M_FATAL, 0, _("[SF0103] Bad storage command: %s"), jcr->errmsg);
      Pmsg1(010, "Bad storage command: %s", jcr->errmsg);
      goto bail_out;
   }

   unbash_spaces(Job);
   if (jcr->sd_auth_key) {
      bfree_and_null(jcr->sd_auth_key);
      jcr->sd_auth_key = bstrdup(sd_auth_key);
   }
   if (stored_port != 0) {
      Dmsg2(050, "sd_calls=%d sd_client=%d\n", jcr->sd_calls_client,
         jcr->sd_client);
      jcr->sd_calls_client = false;   /* We are doing the connecting */
      Dmsg3(050, "Connect to storage and wait: %s:%d ssl=%d\n", jcr->stored_addr, stored_port,
            enable_ssl);
      /* Open command communications with Storage daemon */
      /* Try to connect for 1 hour at 10 second intervals */
      if (!sd->connect(jcr, 10, (int)me->ClientConnectTimeout, me->heartbeat_interval,
                _("Storage daemon"), jcr->stored_addr, NULL, stored_port, 1)) {
         /* destroy() OK because sd is local */
         sd->destroy();
         Jmsg(jcr, M_FATAL, 0, _("[SF0104] Failed to connect to Storage daemon: %s:%d\n"),
             jcr->stored_addr, stored_port);
         Dmsg2(010, "Failed to connect to Storage daemon: %s:%d\n",
             jcr->stored_addr, stored_port);
         goto bail_out;
      }

      Dmsg0(050, "Connection OK to SD.\n");

      jcr->store_bsock = sd;
   } else {                      /* The storage daemon called us */
      jcr->sd_calls_client = true;
      /* We should already have a storage connection! */
      if (jcr->file_bsock && jcr->store_bsock == NULL) {
         jcr->store_bsock = jcr->file_bsock;
      }
      if (jcr->store_bsock == NULL) {
         Jmsg0(jcr, M_FATAL, 0, _("[SF0105] In storage_cmd port==0, no prior Storage connection.\n"));
         Pmsg0(010, "In storage_cmd port==0, no prior Storage connection.\n");
         goto bail_out;
      }
   }

   if (!send_hello_sd(jcr, Job)) {
      goto bail_out;
   }

   if (!authenticate_storagedaemon(jcr)) {
      goto bail_out;
   }
   /*
    * We are a client so we read from the socket we just
    *   opened as if we were a FD, so set file_bsock and
    *   clear the store_bsock.
    */
   jcr->file_bsock = jcr->store_bsock;
   jcr->store_bsock = NULL;
   jcr->authenticated = true;    /* Dir authentication is sufficient */
   Dmsg1(050, "=== Storage_cmd authenticated Job=%s with SD.\n", Job);

   /* Send OK to Director */
   return dir->fsend(OKstore);

bail_out:
   Dmsg0(100, "Send storage command failed.\n");
   dir->fsend(BADcmd, "storage");
   return false;
}
/*
 * Get address of storage daemon from Director
 */
Get address of storage daemon from Director
Get address of storage daemon from Director
static bool storage_cmd(JCR *jcr)
{
   int stored_port;                
   int enable_ssl;                 
   char sd_auth_key[200];
   BSOCK *dir = jcr->dir_bsock;
   BSOCK *sd = new_bsock();        
   char Job[MAX_NAME_LENGTH];
   Dmsg1(050, "StorageCmd: %s", dir->msg);
   if (sscanf(dir->msg, storaddr, &jcr->stored_addr, &stored_port,
              &enable_ssl, Job, sd_auth_key) != 5) {
      pm_strcpy(jcr->errmsg, dir->msg);
      Jmsg(jcr, M_FATAL, 0, _("[SF0103] Bad storage command: %s"), jcr->errmsg);
      Pmsg1(010, "Bad storage command: %s", jcr->errmsg);
      goto bail_out;
   }
   unbash_spaces(Job);
   if (jcr->sd_auth_key) {
      bfree_and_null(jcr->sd_auth_key);
      jcr->sd_auth_key = bstrdup(sd_auth_key);
   }
   if (stored_port != 0) {
      Dmsg2(050, "sd_calls=%d sd_client=%d\n", jcr->sd_calls_client,
         jcr->sd_client);
      jcr->sd_calls_client = false;   
      Dmsg3(050, "Connect to storage and wait: %s:%d ssl=%d\n", jcr->stored_addr, stored_port,
            enable_ssl);
      if (!sd->connect(jcr, 10, (int)me->ClientConnectTimeout, me->heartbeat_interval,
                _("Storage daemon"), jcr->stored_addr, NULL, stored_port, 1)) {
         sd->destroy();
         Jmsg(jcr, M_FATAL, 0, _("[SF0104] Failed to connect to Storage daemon: %s:%d\n"),
             jcr->stored_addr, stored_port);
         Dmsg2(010, "Failed to connect to Storage daemon: %s:%d\n",
             jcr->stored_addr, stored_port);
         goto bail_out;
      }
      Dmsg0(050, "Connection OK to SD.\n");
      jcr->store_bsock = sd;
   } else {                      
      jcr->sd_calls_client = true;
      if (jcr->file_bsock && jcr->store_bsock == NULL) {
         jcr->store_bsock = jcr->file_bsock;
      }
      if (jcr->store_bsock == NULL) {
         Jmsg0(jcr, M_FATAL, 0, _("[SF0105] In storage_cmd port==0, no prior Storage connection.\n"));
         Pmsg0(010, "In storage_cmd port==0, no prior Storage connection.\n");
         goto bail_out;
      }
   }
   if (!send_hello_sd(jcr, Job)) {
      goto bail_out;
   }
   if (!authenticate_storagedaemon(jcr)) {
      goto bail_out;
   }
   jcr->file_bsock = jcr->store_bsock;
   jcr->store_bsock = NULL;
   jcr->authenticated = true;    
   Dmsg1(050, "=== Storage_cmd authenticated Job=%s with SD.\n", Job);
   return dir->fsend(OKstore);
bail_out:
   Dmsg0(100, "Send storage command failed.\n");
   dir->fsend(BADcmd, "storage");
   return false;
}
static bool storage_cmd ( JCR * jcr ) { int stored_port ; int enable_ssl ; char sd_auth_key [ 200 ] ; BSOCK * dir = jcr -> dir_bsock ; BSOCK * sd = new_bsock ( ) ; char Job [ MAX_NAME_LENGTH ] ; Dmsg1 ( 050 , " " , dir -> msg ) ; if ( sscanf ( dir -> msg , storaddr , & jcr -> stored_addr , & stored_port , & enable_ssl , Job , sd_auth_key ) != 5 ) { pm_strcpy ( jcr -> errmsg , dir -> msg ) ; Jmsg ( jcr , M_FATAL , 0 , _ ( " " ) , jcr -> errmsg ) ; Pmsg1 ( 010 , " " , jcr -> errmsg ) ; goto bail_out ; } unbash_spaces ( Job ) ; if ( jcr -> sd_auth_key ) { bfree_and_null ( jcr -> sd_auth_key ) ; jcr -> sd_auth_key = bstrdup ( sd_auth_key ) ; } if ( stored_port != 0 ) { Dmsg2 ( 050 , " \n " , jcr -> sd_calls_client , jcr -> sd_client ) ; jcr -> sd_calls_client = false ; Dmsg3 ( 050 , " \n " , jcr -> stored_addr , stored_port , enable_ssl ) ; if ( ! sd -> connect ( jcr , 10 , ( int ) me -> ClientConnectTimeout , me -> heartbeat_interval , _ ( " " ) , jcr -> stored_addr , NULL , stored_port , 1 ) ) { sd -> destroy ( ) ; Jmsg ( jcr , M_FATAL , 0 , _ ( " \n " ) , jcr -> stored_addr , stored_port ) ; Dmsg2 ( 010 , " \n " , jcr -> stored_addr , stored_port ) ; goto bail_out ; } Dmsg0 ( 050 , " \n " ) ; jcr -> store_bsock = sd ; } else { jcr -> sd_calls_client = true ; if ( jcr -> file_bsock && jcr -> store_bsock == NULL ) { jcr -> store_bsock = jcr -> file_bsock ; } if ( jcr -> store_bsock == NULL ) { Jmsg0 ( jcr , M_FATAL , 0 , _ ( " \n " ) ) ; Pmsg0 ( 010 , " \n " ) ; goto bail_out ; } } if ( ! send_hello_sd ( jcr , Job ) ) { goto bail_out ; } if ( ! authenticate_storagedaemon ( jcr ) ) { goto bail_out ; } jcr -> file_bsock = jcr -> store_bsock ; jcr -> store_bsock = NULL ; jcr -> authenticated = true ; Dmsg1 ( 050 , " \n " , Job ) ; return dir -> fsend ( OKstore ) ; bail_out : Dmsg0 ( 100 , " \n " ) ; dir -> fsend ( BADcmd , " " ) ; return false ; }
Get address of storage daemon from Director
Get address of storage daemon from Director
/* storage daemon port */ /* enable ssl to sd */ /* storage daemon bsock */ /* We are doing the connecting */ /* Open command communications with Storage daemon */ /* Try to connect for 1 hour at 10 second intervals */ /* destroy() OK because sd is local */ /* The storage daemon called us */ /* We should already have a storage connection! */ /*
    * We are a client so we read from the socket we just
    *   opened as if we were a FD, so set file_bsock and
    *   clear the store_bsock.
    */ /* Dir authentication is sufficient */ /* Send OK to Director */