src/filed/hello.c
bool validate_dir_hello(JCR *jcr)
{
   POOLMEM *dirname;
   DIRRES *director = NULL;
   int dir_version = 0;
   BSOCK *dir = jcr->dir_bsock;
   bool auth_success = false;

   if (dir->msglen < 25 || dir->msglen > 500) {
      Dmsg2(dbglvl, "Bad Hello command from Director at %s. Len=%d.\n",
            dir->who(), dir->msglen);
      Jmsg2(jcr, M_FATAL, 0, _("Bad Hello command from Director at %s. Len=%d.\n"),
            dir->who(), dir->msglen);
      return false;
   }
   dirname = get_pool_memory(PM_MESSAGE);
   dirname = check_pool_memory_size(dirname, dir->msglen);

   if (sscanf(dir->msg, "Hello Director %127s calling %d", dirname, &dir_version) != 2 &&
       sscanf(dir->msg, "Hello Director %127s calling", dirname) != 1 && 
       sscanf(dir->msg, "Hello %127s calling %d", dirname, &dir_version) != 2 ) {
      char addr[64];
      char *who = dir->get_peer(addr, sizeof(addr)) ? dir->who() : addr;
      dir->msg[100] = 0;
      Dmsg2(dbglvl, "Bad Hello command from Director at %s: %s\n",
            dir->who(), dir->msg);
      Jmsg2(jcr, M_FATAL, 0, _("Bad Hello command from Director at %s: %s\n"),
            who, dir->msg);
      goto auth_fatal;
   }
   if (dir_version >= 1 && me->comm_compression) {
      dir->set_compress();
   } else {
      dir->clear_compress();
      Dmsg0(050, "*** No FD compression to DIR\n");
   }
   unbash_spaces(dirname);
   foreach_res(director, R_DIRECTOR) {
      if (strcmp(director->hdr.name, dirname) == 0)
         break;
   }
   if (!director) {
      char addr[64];
      char *who = dir->get_peer(addr, sizeof(addr)) ? dir->who() : addr;
      Jmsg2(jcr, M_FATAL, 0, _("Connection from unknown Director %s at %s rejected.\n"),
            dirname, who);
      goto auth_fatal;
   }
   auth_success = true;

auth_fatal:
   free_pool_memory(dirname);
   jcr->director = director;
   /* Single thread all failures to avoid DOS */
   if (!auth_success) {
      P(mutex);
      bmicrosleep(6, 0);
      V(mutex);
   }
   return auth_success;
}
/*********************************************************************
 *
 * Validate hello from the Director
 *
 * Returns: true  if Hello is good.
 *          false if Hello is bad.
 */
Validate hello from the Director
Returns: true  if Hello is good.
false if Hello is bad.
Validate hello from the Director Returns : true if Hello is good . false if Hello is bad .
bool validate_dir_hello(JCR *jcr)
{
   POOLMEM *dirname;
   DIRRES *director = NULL;
   int dir_version = 0;
   BSOCK *dir = jcr->dir_bsock;
   bool auth_success = false;
   if (dir->msglen < 25 || dir->msglen > 500) {
      Dmsg2(dbglvl, "Bad Hello command from Director at %s. Len=%d.\n",
            dir->who(), dir->msglen);
      Jmsg2(jcr, M_FATAL, 0, _("Bad Hello command from Director at %s. Len=%d.\n"),
            dir->who(), dir->msglen);
      return false;
   }
   dirname = get_pool_memory(PM_MESSAGE);
   dirname = check_pool_memory_size(dirname, dir->msglen);
   if (sscanf(dir->msg, "Hello Director %127s calling %d", dirname, &dir_version) != 2 &&
       sscanf(dir->msg, "Hello Director %127s calling", dirname) != 1 && 
       sscanf(dir->msg, "Hello %127s calling %d", dirname, &dir_version) != 2 ) {
      char addr[64];
      char *who = dir->get_peer(addr, sizeof(addr)) ? dir->who() : addr;
      dir->msg[100] = 0;
      Dmsg2(dbglvl, "Bad Hello command from Director at %s: %s\n",
            dir->who(), dir->msg);
      Jmsg2(jcr, M_FATAL, 0, _("Bad Hello command from Director at %s: %s\n"),
            who, dir->msg);
      goto auth_fatal;
   }
   if (dir_version >= 1 && me->comm_compression) {
      dir->set_compress();
   } else {
      dir->clear_compress();
      Dmsg0(050, "*** No FD compression to DIR\n");
   }
   unbash_spaces(dirname);
   foreach_res(director, R_DIRECTOR) {
      if (strcmp(director->hdr.name, dirname) == 0)
         break;
   }
   if (!director) {
      char addr[64];
      char *who = dir->get_peer(addr, sizeof(addr)) ? dir->who() : addr;
      Jmsg2(jcr, M_FATAL, 0, _("Connection from unknown Director %s at %s rejected.\n"),
            dirname, who);
      goto auth_fatal;
   }
   auth_success = true;
auth_fatal:
   free_pool_memory(dirname);
   jcr->director = director;
   if (!auth_success) {
      P(mutex);
      bmicrosleep(6, 0);
      V(mutex);
   }
   return auth_success;
}
bool validate_dir_hello ( JCR * jcr ) { POOLMEM * dirname ; DIRRES * director = NULL ; int dir_version = 0 ; BSOCK * dir = jcr -> dir_bsock ; bool auth_success = false ; if ( dir -> msglen < 25 || dir -> msglen > 500 ) { Dmsg2 ( dbglvl , " \n " , dir -> who ( ) , dir -> msglen ) ; Jmsg2 ( jcr , M_FATAL , 0 , _ ( " \n " ) , dir -> who ( ) , dir -> msglen ) ; return false ; } dirname = get_pool_memory ( PM_MESSAGE ) ; dirname = check_pool_memory_size ( dirname , dir -> msglen ) ; if ( sscanf ( dir -> msg , " " , dirname , & dir_version ) != 2 && sscanf ( dir -> msg , " " , dirname ) != 1 && sscanf ( dir -> msg , " " , dirname , & dir_version ) != 2 ) { char addr [ 64 ] ; char * who = dir -> get_peer ( addr , sizeof ( addr ) ) ? dir -> who ( ) : addr ; dir -> msg [ 100 ] = 0 ; Dmsg2 ( dbglvl , " \n " , dir -> who ( ) , dir -> msg ) ; Jmsg2 ( jcr , M_FATAL , 0 , _ ( " \n " ) , who , dir -> msg ) ; goto auth_fatal ; } if ( dir_version >= 1 && me -> comm_compression ) { dir -> set_compress ( ) ; } else { dir -> clear_compress ( ) ; Dmsg0 ( 050 , " \n " ) ; } unbash_spaces ( dirname ) ; foreach_res ( director , R_DIRECTOR ) { if ( strcmp ( director -> hdr . name , dirname ) == 0 ) break ; } if ( ! director ) { char addr [ 64 ] ; char * who = dir -> get_peer ( addr , sizeof ( addr ) ) ? dir -> who ( ) : addr ; Jmsg2 ( jcr , M_FATAL , 0 , _ ( " \n " ) , dirname , who ) ; goto auth_fatal ; } auth_success = true ; auth_fatal : free_pool_memory ( dirname ) ; jcr -> director = director ; if ( ! auth_success ) { P ( mutex ) ; bmicrosleep ( 6 , 0 ) ; V ( mutex ) ; } return auth_success ; }
Validate hello from the Director
 Returns: true  if Hello is good.
Validate hello from the Director Returns : true if Hello is good .
/* Single thread all failures to avoid DOS */