Ejemplo n.º 1
0
list_node* get_into_env(variable_t* var)
{
   variable_t* env_var;

   env_var = new(variable_t);
   env_var->name = var->name;
   env_var->type = var->type;

   switch(var->type)
   {
      case VAR_LIT_SET:
         env_var->literal = NULL;
         break;

      case VAR_PATH_SET:
         env_var->pathlist = NULL;
         break;

      case VAR_PATH_ADD:
         env_var->pathlist = make_pathlist(getenv(var->name));
         break;

      default:
         break;
   }

   return(add_to_tail(the_environment, env_var));
}
Ejemplo n.º 2
0
static PyObject *
catbox_run(PyObject *self, PyObject *args, PyObject *kwargs)
{
	static char *kwlist[] = {
		"function",
		"writable_paths",
		"network",
		"logger",
		NULL
	};
	PyObject *ret;
	PyObject *paths = NULL;
	PyObject *net = NULL;
	struct trace_context ctx;

	memset(&ctx, 0, sizeof(struct trace_context));

	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|OOO", kwlist, &ctx.func, &paths, &net, &ctx.logger))
		return NULL;

	if (PyCallable_Check(ctx.func) == 0) {
		PyErr_SetString(PyExc_TypeError, "First argument should be a callable function");
		return NULL;
	}

	if (ctx.logger && PyCallable_Check(ctx.logger) == 0) {
		PyErr_SetString(PyExc_TypeError, "Logger should be a callable function");
		return NULL;
	}

	if (paths) {
		ctx.pathlist = make_pathlist(paths);
		if (!ctx.pathlist) return NULL;
	}

	if (net == NULL || PyObject_IsTrue(net))
		ctx.network_allowed = 1;
	else
		ctx.network_allowed = 0;

	catbox_retval_init(&ctx);

	// setup is complete, run sandbox
	ret = catbox_core_run(&ctx);

	if (ctx.pathlist) {
		free_pathlist(ctx.pathlist);
	}

	return ret;
}
Ejemplo n.º 3
0
variable_t* update_var(variable_t* evar, variable_t* vvar)
{
   linked_list* testlist;

   switch (vvar->type)
   {
      case VAR_LIT_SET:
         evar->literal = vvar->literal;
         evar->type = VAR_LIT_SET;
         break;

      case VAR_PATH_SET:
         evar->pathlist = vvar->pathlist;
         evar->type = VAR_PATH_SET;
         break;

      case VAR_PATH_ADD:
         switch (evar->type)
         {
            case VAR_LIT_SET:
               evar->pathlist = merge_paths(make_pathlist(evar->literal),
                                            vvar->pathlist);
               break;

            case VAR_PATH_SET:
            case VAR_PATH_ADD:
               evar->pathlist = merge_paths(evar->pathlist, vvar->pathlist);
               break;

            default:
               break;
         }
         evar->type = VAR_PATH_ADD;
         break;
         
      case VAR_PATH_TESTSET:
         testlist = test_paths(vvar->pathlist);
         if (head(testlist))
         {
            evar->pathlist = testlist;
         }
         else
         {
            evar->pathlist = NULL;
         }
         evar->type = VAR_PATH_SET;
         break;

      case VAR_PATH_TESTADD:
         switch (evar->type)
         {
            case VAR_LIT_SET:
               evar->pathlist = merge_paths(make_pathlist(evar->literal),
                                            test_paths(vvar->pathlist));
               break;

            case VAR_PATH_SET:
            case VAR_PATH_ADD:
               evar->pathlist = merge_paths(evar->pathlist, test_paths(vvar->pathlist));
               break;
               
            default:
               break;
         }
         evar->type = VAR_PATH_ADD;
         break;

      default:
         break;
   }

   return(evar);
}