char *path_simplifier(char *path) { int i; int len; t_path *path_list; i = 0; path_list = NULL; while (path[i]) { len = 0; while (path[i] && path[i] == '/') i++; while (path[i + len] && path[i + len] != '/') len++; add_path(&path_list, ft_strsub(path, i, len)); i += len; } remove_dot(&path_list); remove_dotdot(&path_list, path_list); free(path); path = rebuild_path(path_list); free_pathlist(path_list); return (path); }
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; }
int main (int argc, char *argv[]) { #ifdef HAVE_ICONV char *locale_charset; #endif int status = OK; program_name = base_name (argv[0]); if (STREQ (program_name, APROPOS_NAME)) { am_apropos = 1; argp_program_version = "apropos " PACKAGE_VERSION; } else { struct argp_option *optionp; am_apropos = 0; argp_program_version = "whatis " PACKAGE_VERSION; for (optionp = (struct argp_option *) whatis_argp.options; optionp->name || optionp->key || optionp->arg || optionp->flags || optionp->doc || optionp->group; ++optionp) { if (!optionp->name) continue; if (STREQ (optionp->name, "exact") || STREQ (optionp->name, "and")) optionp->flags |= OPTION_HIDDEN; } } init_debug (); pipeline_install_post_fork (pop_all_cleanups); init_locale (); internal_locale = setlocale (LC_MESSAGES, NULL); /* Use LANGUAGE only when LC_MESSAGES locale category is * neither "C" nor "POSIX". */ if (internal_locale && strcmp (internal_locale, "C") && strcmp (internal_locale, "POSIX")) multiple_locale = getenv ("LANGUAGE"); internal_locale = xstrdup (internal_locale ? internal_locale : "C"); if (argp_parse (am_apropos ? &apropos_argp : &whatis_argp, argc, argv, 0, 0, 0)) exit (FAIL); read_config_file (user_config_file != NULL); /* close this locale and reinitialise if a new locale was issued as an argument or in $MANOPT */ if (locale) { free (internal_locale); internal_locale = setlocale (LC_ALL, locale); if (internal_locale) internal_locale = xstrdup (internal_locale); else internal_locale = xstrdup (locale); debug ("main(): locale = %s, internal_locale = %s\n", locale, internal_locale); if (internal_locale) { setenv ("LANGUAGE", internal_locale, 1); locale_changed (); multiple_locale = NULL; } } /* sort out the internal manpath */ if (manp == NULL) manp = locale_manpath (get_manpath (alt_systems)); else free (get_manpath (NULL)); create_pathlist (manp, manpathlist); display_seen = hashtable_create (&null_hashtable_free); #ifdef HAVE_ICONV locale_charset = xasprintf ("%s//IGNORE", get_locale_charset ()); conv_to_locale = iconv_open (locale_charset, "UTF-8"); free (locale_charset); #endif /* HAVE_ICONV */ if (regex_opt) { int i; preg = XNMALLOC (num_keywords, regex_t); for (i = 0; i < num_keywords; ++i) xregcomp (&preg[i], keywords[i], REG_EXTENDED | REG_NOSUB | REG_ICASE); } if (!search ((const char **) keywords, num_keywords)) status = NOT_FOUND; if (regex_opt) { int i; for (i = 0; i < num_keywords; ++i) regfree (&preg[i]); free (preg); } #ifdef HAVE_ICONV if (conv_to_locale != (iconv_t) -1) iconv_close (conv_to_locale); #endif /* HAVE_ICONV */ hashtable_free (display_seen); free_pathlist (manpathlist); free (manp); free (internal_locale); free (program_name); exit (status); }