/**
 * Check for permission to call an external command
 *
 * @param activity  The activity we're running on
 * @param address
 * @param command
 * @param result    The returned result.
 * @param condition
 *
 * @return true if the security manager handled this call, false otherwise.
 */
bool SecurityManager::checkCommand(Activity *activity, RexxString *address, RexxString *command, ProtectedObject &result, ProtectedObject &condition)
{
    // no method here
    if (manager == OREF_NULL)
    {
        return false;
    }
    DirectoryClass *securityArgs = new_directory();
    ProtectedObject p(securityArgs);
    // add the command and the accress target
    securityArgs->put(command, GlobalNames::COMMAND);
    securityArgs->put(address, GlobalNames::ADDRESS);
    // if the manager handled this, we need to decode the return stuff
    if (callSecurityManager(GlobalNames::COMMAND, securityArgs))
    {
        result = securityArgs->get(GlobalNames::RC);
        // if no return code received, use a zero code
        if (result.isNull())
        {
            result = IntegerZero;
        }
        // failure indicated?  Need to raise a failure condition
        if (securityArgs->get(GlobalNames::FAILURE) != OREF_NULL)
        {
            // raise the condition when things are done
            condition = activity->createConditionObject(GlobalNames::FAILURE, result, command, OREF_NULL, OREF_NULL);
        }
        // same for an error condition
        else if (securityArgs->get(GlobalNames::ERRORNAME) != OREF_NULL)
        {
            // raise the condition when things are done
            condition = activity->createConditionObject(GlobalNames::ERRORNAME, result, command, OREF_NULL, OREF_NULL);
        }
        return true;
    }

    return false;       // not handled
}
示例#2
0
static int test_filepathstatic(void)
{
   filepath_static_t fpath;
   const char*       F;
   cstring_t         workpath   = cstring_INIT;
   directory_t*      workdir    = 0;
   char              fullpath[sys_path_MAXSIZE];

   // prepare
   TEST(0 == new_directory(&workdir, "", 0));
   TEST(0 == path_directory(workdir, &(wbuffer_t) wbuffer_INIT_CSTRING(&workpath)));
   adaptsize_cstring(&workpath);

   // TEST init_filepathstatic: workdir == 0 && filename == 0
   memset(&fpath, 255, sizeof(fpath));
   init_filepathstatic(&fpath, 0, 0);
   TEST(0 == fpath.workdir[0]);
   TEST(0 != fpath.filename);
   TEST(0 == fpath.filename[0]);

   // TEST init_filepathstatic: workdir == 0
   memset(&fpath, 255, sizeof(fpath));
   F = "test-filename";
   init_filepathstatic(&fpath, 0, F);
   TEST(0 == fpath.workdir[0]);
   TEST(F == fpath.filename);

   // TEST init_filepathstatic: filename == 0
   memset(&fpath, 255, sizeof(fpath));
   init_filepathstatic(&fpath, workdir, 0);
   TEST('/' == fpath.workdir[size_cstring(&workpath)]);
   TEST(0 == fpath.workdir[size_cstring(&workpath)+1]);
   TEST(0 == memcmp(fpath.workdir, str_cstring(&workpath), size_cstring(&workpath)));
   TEST(0 != fpath.filename);
   TEST(0 == fpath.filename[0]);

   // TEST init_filepathstatic: filename[0] != '/'
   memset(&fpath, 255, sizeof(fpath));
   F = "test-filename";
   init_filepathstatic(&fpath, workdir, F);
   TEST('/' == fpath.workdir[size_cstring(&workpath)]);
   TEST(0 == fpath.workdir[size_cstring(&workpath)+1]);
   TEST(0 == memcmp(fpath.workdir, str_cstring(&workpath), size_cstring(&workpath)));
   TEST(F == fpath.filename);

   // TEST init_filepathstatic: absolute filename (filename[0] == '/')
   memset(&fpath, 255, sizeof(fpath));
   F = "/tmp/test-filename";
   init_filepathstatic(&fpath, workdir, F);
   TEST(0 == fpath.workdir[0]);
   TEST(F == fpath.filename);

   // TEST init_filepathstatic: ERROR
   init_testerrortimer(&s_filepathstatic_errtimer, 1, ENOENT);
   F = "test-filename";
   init_filepathstatic(&fpath, workdir, F);
   TEST(0 == strcmp("???ERR/", fpath.workdir));
   TEST(F == fpath.filename);

   // TEST STRPARAM_filepathstatic
   F = "test-filename";
   init_filepathstatic(&fpath, workdir, F);
   memset(fullpath, 255, sizeof(fullpath));
   snprintf(fullpath, sizeof(fullpath), "%s%s", STRPARAM_filepathstatic(&fpath));
   TEST(0 == strncmp(fullpath, str_cstring(&workpath), size_cstring(&workpath)));
   TEST('/' == fullpath[size_cstring(&workpath)]);
   TEST(0 == strcmp(fullpath + size_cstring(&workpath) + 1, F));

   // unprepare
   TEST(0 == free_cstring(&workpath));
   TEST(0 == delete_directory(&workdir));

   return 0;
ONERR:
   free_cstring(&workpath);
   delete_directory(&workdir);
   return EINVAL;
}
示例#3
0
文件: cephfs-fd.c 项目: debfx/bareos
/*
 * Create a parent directory using the cephfs API.
 *
 * We don't use cephfs_mkdirs as we want to keep track which
 * directories got created by us.
 */
static inline bool cephfs_makedirs(plugin_ctx *p_ctx, const char *directory)
{
   char *bp;
   struct stat st;
   bool retval = false;
   POOL_MEM new_directory(PM_FNAME);

   pm_strcpy(new_directory, directory);

   /*
    * See if the parent exists.
    */
   bp = strrchr(new_directory.c_str(), '/');
   if (bp) {
      /*
       * See if we reached the root.
       */
      if (bp == new_directory.c_str()) {
         /*
          * Create the directory.
          */
         if (ceph_mkdir(p_ctx->cmount, directory, 0750) == 0) {
            if (!p_ctx->path_list) {
               p_ctx->path_list = path_list_init();
            }
            path_list_add(p_ctx->path_list, strlen(directory), directory);
            retval = true;
         }
      } else {
         *bp = '\0';

         if (ceph_lstat(p_ctx->cmount, new_directory.c_str(), &st) != 0) {
            switch (errno) {
            case ENOENT:
               /*
                * Make sure our parent exists.
                */
               retval = cephfs_makedirs(p_ctx, new_directory.c_str());
               if (!retval) {
                  return false;
               }

               /*
                * Create the directory.
                */
               if (ceph_mkdir(p_ctx->cmount, directory, 0750) == 0) {
                  if (!p_ctx->path_list) {
                     p_ctx->path_list = path_list_init();
                  }
                  path_list_add(p_ctx->path_list, strlen(directory), directory);
                  retval = true;
               }
               break;
            default:
               break;
            }
         } else {
            retval = true;
         }
      }
   }

   return retval;
}