src/stored/stored_conf.c
bool save_resource(CONFIG *config, int type, RES_ITEM *items, int pass)
{
   URES *res;
   int rindex = type - r_first;
   int i, size;
   int error = 0;

   /*
    * Ensure that all required items are present
    */
   for (i=0; items[i].name; i++) {
      if (items[i].flags & ITEM_REQUIRED) {
         if (!bit_is_set(i, res_all.res_dir.hdr.item_present)) {
            Mmsg(config->m_errmsg, _("\"%s\" directive is required in \"%s\" resource, but not found.\n"),
                 items[i].name, resources[rindex].name);
            return false;
         }
      }
      /* If this triggers, take a look at lib/parse_conf.h */
      if (i >= MAX_RES_ITEMS) {
         Mmsg(config->m_errmsg, _("Too many directives in \"%s\" resource\n"), resources[rindex].name);
         return false;
      }
   }

   /* During pass 2, we looked up pointers to all the resources
    * referrenced in the current resource, , now we
    * must copy their address from the static record to the allocated
    * record.
    */
   if (pass == 2) {
      DEVRES *dev;
      int errstat;
      switch (type) {
      /* Resources not containing a resource */
      case R_MSGS:
      case R_CLOUD:
         break;

      /* Resources containing a resource or an alist */
      case R_DIRECTOR:
         if ((res = (URES *)GetResWithName(R_DIRECTOR, res_all.res_dir.hdr.name)) == NULL) {
            Mmsg(config->m_errmsg, _("Cannot find Director resource %s\n"), res_all.res_dir.hdr.name);
            return false;
         }
         res->res_dir.tls_allowed_cns = res_all.res_dir.tls_allowed_cns;
         break;
      case R_STORAGE:
         if ((res = (URES *)GetResWithName(R_STORAGE, res_all.res_dir.hdr.name)) == NULL) {
            Mmsg(config->m_errmsg,  _("Cannot find Storage resource %s\n"), res_all.res_dir.hdr.name);
            return false;
         }
         res->res_store.messages = res_all.res_store.messages;
         res->res_store.tls_allowed_cns = res_all.res_store.tls_allowed_cns;
         break;
      case R_AUTOCHANGER:
         if ((res = (URES *)GetResWithName(type, res_all.res_changer.hdr.name)) == NULL) {
            Mmsg(config->m_errmsg, _("Cannot find AutoChanger resource %s\n"),
                 res_all.res_changer.hdr.name);
            return false;
         }
         /* we must explicitly copy the device alist pointer */
         res->res_changer.device   = res_all.res_changer.device;
         /*
          * Now update each device in this resource to point back
          *  to the changer resource.
          */
         foreach_alist(dev, res->res_changer.device) {
            dev->changer_res = (AUTOCHANGER *)&res->res_changer;
         }
         if ((errstat = rwl_init(&res->res_changer.changer_lock, PRIO_SD_ACH_ACCESS)) != 0) {
            berrno be;
            Mmsg(config->m_errmsg, _("Unable to init lock for Autochanger=%s: ERR=%s\n"),
                 res_all.res_changer.hdr.name, be.bstrerror(errstat));
            return false;
         }
         break;
      case R_DEVICE:
         if ((res = (URES *)GetResWithName(R_DEVICE, res_all.res_dev.hdr.name)) == NULL) {
            Mmsg(config->m_errmsg,  _("Cannot find Device resource %s\n"), res_all.res_dir.hdr.name);
            return false;
         }
         res->res_dev.cloud = res_all.res_dev.cloud;
         break;
      default:
         printf(_("Unknown resource type %d\n"), type);
         error = 1;
         break;
      }


      if (res_all.res_dir.hdr.name) {
         free(res_all.res_dir.hdr.name);
         res_all.res_dir.hdr.name = NULL;
      }
      if (res_all.res_dir.hdr.desc) {
         free(res_all.res_dir.hdr.desc);
         res_all.res_dir.hdr.desc = NULL;
      }
      return true;
   }

   /* The following code is only executed on pass 1 */
   switch (type) {
      case R_DIRECTOR:
         size = sizeof(DIRRES);
         break;
      case R_STORAGE:
         size = sizeof(STORES);
         break;
      case R_DEVICE:
         size = sizeof(DEVRES);
         break;
      case R_MSGS:
         size = sizeof(MSGS);
         break;
      case R_AUTOCHANGER:
         size = sizeof(AUTOCHANGER);
         break;
      case R_CLOUD:
         size = sizeof(CLOUD);
         break;
      default:
         printf(_("Unknown resource type %d\n"), type);
         error = 1;
         size = 1;
         break;
   }
   /* Common */
   if (!error) {
      if (!config->insert_res(rindex, size)) {
         return false;
      }
   }
   return true;
}
/* Save the new resource by chaining it into the head list for
 * the resource. If this is pass 2, we update any resource
 * or alist pointers.
 */
Save the new resource by chaining it into the head list for
the resource. If this is pass 2, we update any resource
or alist pointers.
Save the new resource by chaining it into the head list for the resource . If this is pass 2 we update any resource or alist pointers .
bool save_resource(CONFIG *config, int type, RES_ITEM *items, int pass)
{
   URES *res;
   int rindex = type - r_first;
   int i, size;
   int error = 0;
   for (i=0; items[i].name; i++) {
      if (items[i].flags & ITEM_REQUIRED) {
         if (!bit_is_set(i, res_all.res_dir.hdr.item_present)) {
            Mmsg(config->m_errmsg, _("\"%s\" directive is required in \"%s\" resource, but not found.\n"),
                 items[i].name, resources[rindex].name);
            return false;
         }
      }
      if (i >= MAX_RES_ITEMS) {
         Mmsg(config->m_errmsg, _("Too many directives in \"%s\" resource\n"), resources[rindex].name);
         return false;
      }
   }
   if (pass == 2) {
      DEVRES *dev;
      int errstat;
      switch (type) {
      case R_MSGS:
      case R_CLOUD:
         break;
      case R_DIRECTOR:
         if ((res = (URES *)GetResWithName(R_DIRECTOR, res_all.res_dir.hdr.name)) == NULL) {
            Mmsg(config->m_errmsg, _("Cannot find Director resource %s\n"), res_all.res_dir.hdr.name);
            return false;
         }
         res->res_dir.tls_allowed_cns = res_all.res_dir.tls_allowed_cns;
         break;
      case R_STORAGE:
         if ((res = (URES *)GetResWithName(R_STORAGE, res_all.res_dir.hdr.name)) == NULL) {
            Mmsg(config->m_errmsg,  _("Cannot find Storage resource %s\n"), res_all.res_dir.hdr.name);
            return false;
         }
         res->res_store.messages = res_all.res_store.messages;
         res->res_store.tls_allowed_cns = res_all.res_store.tls_allowed_cns;
         break;
      case R_AUTOCHANGER:
         if ((res = (URES *)GetResWithName(type, res_all.res_changer.hdr.name)) == NULL) {
            Mmsg(config->m_errmsg, _("Cannot find AutoChanger resource %s\n"),
                 res_all.res_changer.hdr.name);
            return false;
         }
         res->res_changer.device   = res_all.res_changer.device;
         foreach_alist(dev, res->res_changer.device) {
            dev->changer_res = (AUTOCHANGER *)&res->res_changer;
         }
         if ((errstat = rwl_init(&res->res_changer.changer_lock, PRIO_SD_ACH_ACCESS)) != 0) {
            berrno be;
            Mmsg(config->m_errmsg, _("Unable to init lock for Autochanger=%s: ERR=%s\n"),
                 res_all.res_changer.hdr.name, be.bstrerror(errstat));
            return false;
         }
         break;
      case R_DEVICE:
         if ((res = (URES *)GetResWithName(R_DEVICE, res_all.res_dev.hdr.name)) == NULL) {
            Mmsg(config->m_errmsg,  _("Cannot find Device resource %s\n"), res_all.res_dir.hdr.name);
            return false;
         }
         res->res_dev.cloud = res_all.res_dev.cloud;
         break;
      default:
         printf(_("Unknown resource type %d\n"), type);
         error = 1;
         break;
      }
      if (res_all.res_dir.hdr.name) {
         free(res_all.res_dir.hdr.name);
         res_all.res_dir.hdr.name = NULL;
      }
      if (res_all.res_dir.hdr.desc) {
         free(res_all.res_dir.hdr.desc);
         res_all.res_dir.hdr.desc = NULL;
      }
      return true;
   }
   switch (type) {
      case R_DIRECTOR:
         size = sizeof(DIRRES);
         break;
      case R_STORAGE:
         size = sizeof(STORES);
         break;
      case R_DEVICE:
         size = sizeof(DEVRES);
         break;
      case R_MSGS:
         size = sizeof(MSGS);
         break;
      case R_AUTOCHANGER:
         size = sizeof(AUTOCHANGER);
         break;
      case R_CLOUD:
         size = sizeof(CLOUD);
         break;
      default:
         printf(_("Unknown resource type %d\n"), type);
         error = 1;
         size = 1;
         break;
   }
   if (!error) {
      if (!config->insert_res(rindex, size)) {
         return false;
      }
   }
   return true;
}
bool save_resource ( CONFIG * config , int type , RES_ITEM * items , int pass ) { URES * res ; int rindex = type - r_first ; int i , size ; int error = 0 ; for ( i = 0 ; items [ i ] . name ; i ++ ) { if ( items [ i ] . flags & ITEM_REQUIRED ) { if ( ! bit_is_set ( i , res_all . res_dir . hdr . item_present ) ) { Mmsg ( config -> m_errmsg , _ ( " \" \" \" \" \n " ) , items [ i ] . name , resources [ rindex ] . name ) ; return false ; } } if ( i >= MAX_RES_ITEMS ) { Mmsg ( config -> m_errmsg , _ ( " \" \" \n " ) , resources [ rindex ] . name ) ; return false ; } } if ( pass == 2 ) { DEVRES * dev ; int errstat ; switch ( type ) { case R_MSGS : case R_CLOUD : break ; case R_DIRECTOR : if ( ( res = ( URES * ) GetResWithName ( R_DIRECTOR , res_all . res_dir . hdr . name ) ) == NULL ) { Mmsg ( config -> m_errmsg , _ ( " \n " ) , res_all . res_dir . hdr . name ) ; return false ; } res -> res_dir . tls_allowed_cns = res_all . res_dir . tls_allowed_cns ; break ; case R_STORAGE : if ( ( res = ( URES * ) GetResWithName ( R_STORAGE , res_all . res_dir . hdr . name ) ) == NULL ) { Mmsg ( config -> m_errmsg , _ ( " \n " ) , res_all . res_dir . hdr . name ) ; return false ; } res -> res_store . messages = res_all . res_store . messages ; res -> res_store . tls_allowed_cns = res_all . res_store . tls_allowed_cns ; break ; case R_AUTOCHANGER : if ( ( res = ( URES * ) GetResWithName ( type , res_all . res_changer . hdr . name ) ) == NULL ) { Mmsg ( config -> m_errmsg , _ ( " \n " ) , res_all . res_changer . hdr . name ) ; return false ; } res -> res_changer . device = res_all . res_changer . device ; foreach_alist ( dev , res -> res_changer . device ) { dev -> changer_res = ( AUTOCHANGER * ) & res -> res_changer ; } if ( ( errstat = rwl_init ( & res -> res_changer . changer_lock , PRIO_SD_ACH_ACCESS ) ) != 0 ) { berrno be ; Mmsg ( config -> m_errmsg , _ ( " \n " ) , res_all . res_changer . hdr . name , be . bstrerror ( errstat ) ) ; return false ; } break ; case R_DEVICE : if ( ( res = ( URES * ) GetResWithName ( R_DEVICE , res_all . res_dev . hdr . name ) ) == NULL ) { Mmsg ( config -> m_errmsg , _ ( " \n " ) , res_all . res_dir . hdr . name ) ; return false ; } res -> res_dev . cloud = res_all . res_dev . cloud ; break ; default : printf ( _ ( " \n " ) , type ) ; error = 1 ; break ; } if ( res_all . res_dir . hdr . name ) { free ( res_all . res_dir . hdr . name ) ; res_all . res_dir . hdr . name = NULL ; } if ( res_all . res_dir . hdr . desc ) { free ( res_all . res_dir . hdr . desc ) ; res_all . res_dir . hdr . desc = NULL ; } return true ; } switch ( type ) { case R_DIRECTOR : size = sizeof ( DIRRES ) ; break ; case R_STORAGE : size = sizeof ( STORES ) ; break ; case R_DEVICE : size = sizeof ( DEVRES ) ; break ; case R_MSGS : size = sizeof ( MSGS ) ; break ; case R_AUTOCHANGER : size = sizeof ( AUTOCHANGER ) ; break ; case R_CLOUD : size = sizeof ( CLOUD ) ; break ; default : printf ( _ ( " \n " ) , type ) ; error = 1 ; size = 1 ; break ; } if ( ! error ) { if ( ! config -> insert_res ( rindex , size ) ) { return false ; } } return true ; }
Save the new resource by chaining it into the head list for
 the resource.
Save the new resource by chaining it into the head list for the resource .
/*
    * Ensure that all required items are present
    */ /* If this triggers, take a look at lib/parse_conf.h */ /* During pass 2, we looked up pointers to all the resources
    * referrenced in the current resource, , now we
    * must copy their address from the static record to the allocated
    * record.
    */ /* Resources not containing a resource */ /* Resources containing a resource or an alist */ /* we must explicitly copy the device alist pointer */ /*
          * Now update each device in this resource to point back
          *  to the changer resource.
          */ /* The following code is only executed on pass 1 */ /* Common */