src/dird/ua_acl.c
bool acl_access_ok(UAContext *ua, int acl, const char *item, int len)
{
   /* The resource name contains nasty characters */
   if (acl != Where_ACL && !is_name_valid(item, NULL)) {
      Dmsg1(1400, "Access denied for item=%s\n", item);
      return false;
   }

   /* If no console resource => default console and all is permitted */
   if (!ua || !ua->cons) {
      Dmsg0(1400, "Root cons access OK.\n");
      return true;                    /* No cons resource -> root console OK for everything */
   }

   alist *list = ua->cons->ACL_lists[acl];
   if (!list) {                       /* empty list */
      if (len == 0 && acl == Where_ACL) {
         return true;                 /* Empty list for Where => empty where */
      }
      return false;                   /* List empty, reject everything */
   }

   /* Special case *all* gives full access */
   if (list->size() == 1 && strcasecmp("*all*", (char *)list->get(0)) == 0) {
      return true;
   }

   /* Search list for item */
   for (int i=0; i<list->size(); i++) {
      if (strcasecmp(item, (char *)list->get(i)) == 0) {
         Dmsg3(1400, "ACL found %s in %d %s\n", item, acl, (char *)list->get(i));
         return true;
      }
   }
   return false;
}
/* This version expects the length of the item which we must check. */
This version expects the length of the item which we must check.
This version expects the length of the item which we must check .
bool acl_access_ok(UAContext *ua, int acl, const char *item, int len)
{
   if (acl != Where_ACL && !is_name_valid(item, NULL)) {
      Dmsg1(1400, "Access denied for item=%s\n", item);
      return false;
   }
   if (!ua || !ua->cons) {
      Dmsg0(1400, "Root cons access OK.\n");
      return true;                    
   }
   alist *list = ua->cons->ACL_lists[acl];
   if (!list) {                       
      if (len == 0 && acl == Where_ACL) {
         return true;                 
      }
      return false;                   
   }
   if (list->size() == 1 && strcasecmp("*all*", (char *)list->get(0)) == 0) {
      return true;
   }
   for (int i=0; i<list->size(); i++) {
      if (strcasecmp(item, (char *)list->get(i)) == 0) {
         Dmsg3(1400, "ACL found %s in %d %s\n", item, acl, (char *)list->get(i));
         return true;
      }
   }
   return false;
}
bool acl_access_ok ( UAContext * ua , int acl , const char * item , int len ) { if ( acl != Where_ACL && ! is_name_valid ( item , NULL ) ) { Dmsg1 ( 1400 , " \n " , item ) ; return false ; } if ( ! ua || ! ua -> cons ) { Dmsg0 ( 1400 , " \n " ) ; return true ; } alist * list = ua -> cons -> ACL_lists [ acl ] ; if ( ! list ) { if ( len == 0 && acl == Where_ACL ) { return true ; } return false ; } if ( list -> size ( ) == 1 && strcasecmp ( " " , ( char * ) list -> get ( 0 ) ) == 0 ) { return true ; } for ( int i = 0 ; i < list -> size ( ) ; i ++ ) { if ( strcasecmp ( item , ( char * ) list -> get ( i ) ) == 0 ) { Dmsg3 ( 1400 , " \n " , item , acl , ( char * ) list -> get ( i ) ) ; return true ; } } return false ; }
This version expects the length of the item which we must check.
This version expects the length of the item which we must check .
/* The resource name contains nasty characters */ /* If no console resource => default console and all is permitted */ /* No cons resource -> root console OK for everything */ /* empty list */ /* Empty list for Where => empty where */ /* List empty, reject everything */ /* Special case *all* gives full access */ /* Search list for item */