Exemplo n.º 1
0
/*   check executable cmd*/
static char *
alloc_executable_name(char ** env[], char ** argv[], const char * cmd)
{
	char * bin = NULL;
	char * interp = NULL;
	char * interp_arg = NULL;
	const char * path;

	path = callsystem_getenv(env, "PATH");
	if(!path)
	{
		CALLSYSTEM_CHILD_ERROR("PATH not set");
		return NULL;
	}

	bin = find_in_path(cmd, path);

	if(!bin)
		goto cmd_not_useable;

	/* access can't check for execute permission on win32. */
	if(access(bin, R_OK) < 0)
		goto cmd_not_useable;

	/* on unix we'd be done but to support #! we now need to discover if we have
	 * a an intrepreter script. If we do then jigger the argv and bin */
	if(is_interpreter(bin, &interp, &interp_arg) == -1)
		goto cmd_not_useable;

	if(interp != NULL)
	{
		/* re-apply search to interpreter(might be missing .exe etc) */
		char *tmp = interp;
		interp = find_in_path(interp, path);
		free(tmp);

		if(!interp || access(interp, R_OK) < 0)
			goto cmd_not_useable;

		callsystem_argv_pushfront(argv, bin);
		free(bin);
		bin = interp;

		/* my BSD man page says one optional arg is allowed on the #! line */
		if(interp_arg != NULL)
		{
			callsystem_argv_pushfront(argv, bin);
			free(interp_arg);
		}
	}

	return bin;
cmd_not_useable:
	CALLSYSTEM_CHILD_ERROR("cmd not executable");
	return NULL;
}
Exemplo n.º 2
0
int guess_fileconverter()
{
    int i;
    for (i = 0; fileconverters[i][0]; i++) {
        if (find_in_path(fileconverters[i][0], getenv("PATH"), NULL)) {
            strlcpy(fileconverter, fileconverters[i][1], PATH_MAX);
            return 1;
        }
    }
    return 0;
}
Exemplo n.º 3
0
int main(int argc, char *argv[])
{
  int ncmxs = 0;
  int i, j;
  char **new_argv;

  if (strstr(argv[0], "ld_ocaml")) {
      for (i = 1; i < argc; i++) {
          int len = strlen(argv[i]);
          if(len > 5 && !strcmp(argv[i] + len - 5, ".cmxs"))
              ncmxs++;
          else
              break;
      }

      /* overallocate for convenience, it's ok */
      new_argv = malloc(argc * sizeof(char *));
      ld_cmxs_to_load = malloc((ncmxs + 1) * sizeof(char *));
      for(i = ncmxs, j = 0; i <= argc; ) /* <= to copy final NULL */
          new_argv[j++] = argv[i] ? strdup(argv[i++]) : argv[i++];
      for(i = 1, j = 0; i <= ncmxs; )
          ld_cmxs_to_load[j++] = argv[i++];
      ld_cmxs_to_load[ncmxs] = NULL;
  } else {
      /* append .cmxs to argv[0] after PATH expansion if needed,
       * load that cmxs, don't modify argv */
      char *cmxs, *tmp;

      tmp = chop_extension(argv[0]);
      cmxs = malloc(strlen(tmp) + 5 + 1);
      sprintf(cmxs, "%s.cmxs", tmp);
      free(tmp);

      new_argv = argv;

      ld_cmxs_to_load = malloc(2 * sizeof(char *));
      ld_cmxs_to_load[0] = strstr(cmxs, "/") ? cmxs : find_in_path(cmxs);
      ld_cmxs_to_load[1] = NULL;
      if(!ld_cmxs_to_load[0]) {
          fprintf(stderr, "Could not find %s in PATH.\n", cmxs);
          exit(1);
      }
  }


  /* Initialize Caml code */
  caml_main(new_argv);
  return 0;
}
Exemplo n.º 4
0
void rnn_parsefile (struct rnndb *db, char *file_orig) {
	int i;
	char *fname;
	const char *rnn_path = getenv("RNN_PATH");

	if (!rnn_path)
		rnn_path = RNN_DEF_PATH;

	FILE *file = find_in_path(file_orig, rnn_path, &fname);
	if (!file) {
		fprintf (stderr, "%s: couldn't find database file. Please set the env var RNN_PATH.\n", file_orig);
		db->estatus = 1;
		return;
	}
	fclose(file);

	for (i = 0; i < db->filesnum; i++)
		if (!strcmp(db->files[i], fname))
			return;
		
	ADDARRAY(db->files, fname);
	xmlDocPtr doc = xmlParseFile(fname);
	if (!doc) {
		fprintf (stderr, "%s: couldn't open database file. Please set the env var RNN_PATH.\n", fname);
		db->estatus = 1;
		return;
	}
	xmlNode *root = doc->children;
	while (root) {
		if (root->type != XML_ELEMENT_NODE) {
		} else if (strcmp(root->name, "database")) {
			fprintf (stderr, "%s:%d: wrong top-level tag <%s>\n", fname, root->line, root->name);
			db->estatus = 1;
		} else {
			xmlNode *chain = root->children;
			while (chain) {
				if (chain->type != XML_ELEMENT_NODE) {
				} else if (!trytop(db, fname, chain) && !trydoc(db, fname, chain)) {
					fprintf (stderr, "%s:%d: wrong tag in database: <%s>\n", fname, chain->line, chain->name);
					db->estatus = 1;
				}
				chain = chain->next;
			}
		}
		root = root->next;
	}
	xmlFreeDoc(doc);
}
Exemplo n.º 5
0
tree_cell *
nasl_find_in_path (lex_ctxt * lexic)
{
  tree_cell *retc;
  char *cmd;

  cmd = get_str_var_by_num (lexic, 0);
  if (cmd == NULL)
    {
      nasl_perror (lexic, "find_in_path() usage: cmd\n");
      return NULL;
    }

  retc = alloc_typed_cell (CONST_INT);
  retc->x.i_val = (find_in_path (cmd, 0) != NULL);
  return retc;
}
Exemplo n.º 6
0
static int which_in_path(char *filename)
{
  struct string_list *list;

  // If they gave us a path, don't worry about $PATH or -a

  if (strchr(filename, '/')) {
    // Confirm it has the executable bit set, and it's not a directory.
    if (!access(filename, X_OK)) {
      struct stat st;

      if (!stat(filename, &st) && S_ISREG(st.st_mode)) {
        puts(filename);
        return 0;
      }
      return 1;
    }
  }

  // Search $PATH for matches.
  list = find_in_path(getenv("PATH"), filename);
  if (!list) return 1;

  // Print out matches
  while (list) {
    if (!access(list->str, X_OK)) {
      puts(list->str);
      // If we should stop at one match, do so
      if (!toys.optflags) {
        llist_traverse(list, free);
        break;
      }
    }
    free(llist_pop(&list));
  }

  return 0;
}
Exemplo n.º 7
0
int open_google_earth()
{
    char *kml_filename = appendExt(curr->filename, ".kml");

    char *basename = get_basename(curr->filename);
    char *dirname = get_dirname(curr->filename);

    char *arg;
    if (strlen(dirname)==0) {
        char *tmpdir = g_get_current_dir();
        dirname = escapify(tmpdir);
        arg = MALLOC(sizeof(char)*(strlen(dirname)+strlen(kml_filename)+20));
        sprintf(arg, "%s/%s", dirname, kml_filename);
        //free(tmpdir);
    }
    else {
        arg = STRDUP(kml_filename);
    }

    char *png_file = appendExt(arg, ".png");

    printf("png file: %s\n", png_file);
    printf("Temporary kml file: %s\n", arg);

    FILE *kml_file = fopen(arg, "w");
    if (!kml_file)
    {
        asfPrintWarning("Couldn't open kml file!\n");        
        return FALSE;
    }

    dbf_header_t *dbf;
    int nAttr, nCoords;
    double *lat, *lon, center_lat, center_lon;
    char configFile[255], *name;
    meta_parameters *meta;

    sprintf(configFile, "%s/convert2vector.config", get_asf_share_dir());
    c2v_config *cfg = read_c2v_config(configFile);

    kml_header(kml_file);

    meta = meta2vector(curr->filename, &dbf, &nAttr, &lat, &lon, &nCoords);
    //meta_parameters *meta = curr->meta;
    if (meta && meta->general &&
        meta_is_valid_double(meta->general->center_latitude) &&
        meta_is_valid_double(meta->general->center_longitude))
    {
        pixbuf2png(pixbuf_small, png_file);
        //kml_entry_with_overlay(kml_file, meta, basename, png_file, dirname);
        name = get_basename(kml_filename);
        center_lat = meta->general->center_latitude;
        center_lon = meta->general->center_longitude;
        write_kml_placemark(kml_file, name, center_lat, center_lon, png_file, 
          dbf, nAttr, lat, lon, nCoords, cfg);
        FREE(lat);
        FREE(lon);
        FREE(dbf);
    }
    else
    {
        asfPrintWarning(
            "Failed, metadata doesn't contain valid lat/lon info.\n");
        return FALSE;
    }

    kml_footer(kml_file);
    fclose(kml_file);

    gchar *ge;

    printf("kml: %s\n", kml_filename);
    printf("dir: %s\n", dirname);

#ifdef win32
    char path[1024];
    FindExecutable((LPCTSTR)kml_filename, (LPCTSTR)dirname, (LPTSTR)path);
    ge = escapify(path);
    printf("Path to google earth: %s\n", ge);
    
    asfSystem("\"%s\" \"%s\"", ge, arg);
#else
    ge = find_in_path("googleearth");
    if (!ge)
    {
       message_box("Couldn't find googleearth! Is it installed?");
       return FALSE;
    }

    int pid = fork();
    if (pid == 0) {
        asfSystem("\"%s\" \"%s\"", ge, arg);
        //unlink(kml_filename);
        exit(EXIT_SUCCESS);
    }
#endif

    free(kml_filename);
    free(basename);
    free(dirname);
    free(arg);

    return TRUE;
}
Exemplo n.º 8
0
/* finds a valid editor for sudo edit or "sudo vi" */
char * find_editor(int nfiles, char * const files[], char **argv_out[])
{
    char *cp;
    char **ep;
    char **nargv;
    char *editor;
    char *editor_path;
    int ac;
    int i;
    int nargc;
    int wasblank;

    /* Lookup EDITOR in user's environment. */
    editor = _PATH_VI;
    for (ep = plugin_state.envp; *ep != NULL; ep++) {
        if (strncmp(*ep, "EDITOR=", 7) == 0) {
            editor = *ep + 7;
            break;
        }
    }

    editor = strdup(editor);
    if (editor == NULL) {
        sudo_log(SUDO_CONV_ERROR_MSG, "unable to allocate memory\n");
        return NULL;
    }

    /*
     * Split editor into an argument vector; editor is reused (do not free).
     * The EDITOR environment variables may contain command
     * line args so look for those and alloc space for them too.
     */
    nargc = 1;
    for (wasblank = 0, cp = editor; *cp != '\0'; cp++) {

        if (isblank((unsigned char) *cp)) {
            wasblank = 1;
        }
        else if (wasblank) {
            wasblank = 0;
            nargc++;
        }
    }

    /* If we can't find the editor in the user's PATH, give up. */
    cp = strtok(editor, " \t");
    if (cp == NULL ||
            (editor_path = find_in_path(editor, plugin_state.envp)) == NULL) {
        return NULL;
    }

    nargv = (char **) malloc((nargc + 1 + nfiles + 1) * sizeof(char *));
    if (nargv == NULL) {
        sudo_log(SUDO_CONV_ERROR_MSG, "unable to allocate memory\n");
        return NULL;
    }

    for (ac = 0; cp != NULL && ac < nargc; ac++) {
        nargv[ac] = cp;
        cp = strtok(NULL, " \t");
    }
    nargv[ac++] = "--";
    for (i = 0; i < nfiles; )
        nargv[ac++] = files[i++];
    nargv[ac] = NULL;

    *argv_out = nargv;
    return editor_path;
}
Exemplo n.º 9
0
/*
 * Plugin policy check function.
 * The check_policy function is called by sudo to determine
 * whether the user is allowed to run the specified commands.
 */
int  policy_check(int argc, char * const argv[],
                  char *env_add[], char **command_info_out[],
                  char **argv_out[], char **user_env_out[])
{
    char *command;
    pam_handle_t *pamh;
    char *pam_user;
    char *pam_action;
    int pam_ret = PAM_AUTHTOK_ERR;
    int sudo_ret = SSS_SUDO_FAILED;
    struct sudo_result_contents * sudo_result = NULL;

    if (!argc || argv[0] == NULL) {
        sudo_log(SUDO_CONV_ERROR_MSG, "no command specified\n");
        return FALSE;
    }


    command = find_in_path(argv[0], plugin_state.envp);
    if (command == NULL) {
        sudo_log(SUDO_CONV_ERROR_MSG, "%s: command not found\n", argv[0]);
        return FALSE;
    }

    /* If "sudo vi" is run, auto-convert to sudoedit.  */
    if (strcmp(command, _PATH_VI) == 0)
        use_sudoedit = TRUE;

    if (use_sudoedit) {
        /* Rebuild argv using editor */
        command = find_editor(argc - 1, argv + 1, argv_out);
        if (command == NULL) {
            sudo_log(SUDO_CONV_ERROR_MSG, "unable to find valid editor\n");
            return ERROR;
        }
        use_sudoedit = TRUE;
    } else {
        /* No changes needd to argv */
        *argv_out = (char **)argv;
    }

    /* No changes to envp */
    *user_env_out = plugin_state.envp;

    /* Space for authentication */

    pam_action = strdup("auth");
    pam_user = user_information.username;

    sudo_log(SUDO_CONV_INFO_MSG, "\nCalling PAM with action: %s\nuser: %s\n", pam_action,pam_user);
    pam_ret = pam_start(SSS_SUDO_PAM_SERVICE, pam_user, &conv, &pamh);

    if (pam_ret != PAM_SUCCESS) {
        fprintf(stderr, "pam_start failed: %s\n", pam_strerror(pamh, pam_ret));
        return 0;
    }

    pam_ret = pam_authenticate(pamh, PAM_DISALLOW_NULL_AUTHTOK);
    switch(pam_ret) {
    case PAM_ABORT:
        fprintf(stderr, "pam_authenticate - aborted: %s\n", pam_strerror(pamh, pam_ret));
        pam_end(pamh, pam_ret);
        return 0;

    case PAM_AUTH_ERR:
        fprintf(stderr, "pam_authenticate - error: %s\n", pam_strerror(pamh, pam_ret));
        pam_end(pamh, pam_ret);
        return 0;

    case PAM_SUCCESS:
        fprintf(stdout, "pam_authenticate - success: %s\n", pam_strerror(pamh, pam_ret));
        break;

    case PAM_CRED_INSUFFICIENT:
        fprintf(stderr, "pam_authenticate - crendential not sufficient: %s\n", pam_strerror(pamh, pam_ret));
        pam_end(pamh, pam_ret);
        return 0;

    case PAM_AUTHINFO_UNAVAIL:
        fprintf(stderr, "pam_authenticate - authentication information not available: %s\n", pam_strerror(pamh, pam_ret));
        pam_end(pamh, pam_ret);
        return 0;

    case PAM_USER_UNKNOWN:
        fprintf(stderr, "pam_authenticate - check the user specified : %s\n", pam_strerror(pamh, pam_ret));
        pam_end(pamh, pam_ret);
        return 0;

    case PAM_MAXTRIES:
        fprintf(stderr, "pam_authenticate - maximum tries over : %s\n", pam_strerror(pamh, pam_ret));
        pam_end(pamh, pam_ret);
        return 0;

    default:
        fprintf(stderr, "pam_authenticate - unknown error : %s\n", pam_strerror(pamh, pam_ret));
        pam_end(pamh, pam_ret);
        return 0;

    }

    /* pam is success :) */
    pam_end(pamh, pam_ret);

    msg.fq_command = command;
    msg.command = (char **) argv;
    msg.command_count = argc;

    if(pam_ret == PAM_SUCCESS) {
        sudo_ret = send_and_receive(&sudo_result);
        if(sudo_ret != SSS_SUDO_SUCCESS){
            sudo_ret = SSS_SUDO_FAILED;
            free(pam_action);
            goto done;
        }
    }
    else{
        sudo_ret = SSS_SUDO_FAILED;
        free(pam_action);
        goto done;
    }

    free(pam_action);
    /* Setup command info. */
    *command_info_out = build_command_info(command);
    if (*command_info_out == NULL) {
        sudo_log(SUDO_CONV_ERROR_MSG, "out of memory\n");
        return ERROR;
    }
    *user_env_out = msg.user_env;/*sudo_result->env_array*/;

    done:
    if(sudo_ret==SSS_SUDO_SUCCESS){
        free_all();
        return SUDO_ALLOW_CMD_EXECUTION;
    }
    sudo_log(SUDO_CONV_ERROR_MSG,
             "User %s is not allowed run command %s on this Host machine( '%s' ) as user %s\n",
             user_information.username,
             msg.fq_command,
             msg.network_addrs,
             msg.runas_user );
    free_all();
    return SUDO_DENY_CMD_EXECUTION;
}
Exemplo n.º 10
0
void init_cups(list_t *arglist, dstr_t *filelist, jobparams_t *job)
{
    char path [1024] = "";
    char cups_jobid [128];
    char cups_user [128];
    char cups_jobtitle [128];
    char cups_copies [128];
    int cups_options_len;
    char *cups_options;
    char cups_filename [256];
    char texttopspath[PATH_MAX];

    if (getenv("CUPS_FONTPATH"))
        strcpy(path, getenv("CUPS_FONTPATH"));
    else if (getenv("CUPS_DATADIR")) {
        strcpy(path, getenv("CUPS_DATADIR"));
        strcat(path, "/fonts");
    }
    if (getenv("GS_LIB")) {
        strcat(path, ":");
        strcat(path, getenv("GS_LIB"));
    }
    setenv("GS_LIB", path, 1);

    /* Get all command line parameters */
    strncpy_omit(cups_jobid, arglist_get(arglist, 0), 128, omit_shellescapes);
    strncpy_omit(cups_user, arglist_get(arglist, 1), 128, omit_shellescapes);
    strncpy_omit(cups_jobtitle, arglist_get(arglist, 2), 128, omit_shellescapes);
    strncpy_omit(cups_copies, arglist_get(arglist, 3), 128, omit_shellescapes);

    cups_options_len = strlen(arglist_get(arglist, 4));
    cups_options = malloc(cups_options_len + 1);
    strncpy_omit(cups_options, arglist_get(arglist, 4), cups_options_len + 1, omit_shellescapes);

    /* Common job parameters */
    strcpy(job->id, cups_jobid);
    strcpy(job->title, cups_jobtitle);
    strcpy(job->user, cups_user);
    strcpy(job->copies, cups_copies);
    dstrcatf(job->optstr, " %s", cups_options);

    /* Check for and handle inputfile vs stdin */
    if (list_item_count(arglist) > 4) {
        strncpy_omit(cups_filename, arglist_get(arglist, 5), 256, omit_shellescapes);
        if (cups_filename[0] != '-') {
            /* We get input from a file */
            dstrcatf(filelist, "%s ", cups_filename);
            _log("Getting input from file %s\n", cups_filename);
        }
    }

    accounting_prolog = accounting_prolog_code;

    /* On which queue are we printing?
       CUPS gives the PPD file the same name as the printer queue,
       so we can get the queue name from the name of the PPD file. */
    file_basename(job->printer, job->ppdfile, 256);

    /* Use cups' texttops if no fileconverter is set
     * Apply "pstops" when having used a file converter under CUPS, so CUPS
     * can stuff the default settings into the PostScript output of the file
     * converter (so all CUPS settings get also applied when one prints the
     * documentation pages (all other files we get already converted to
     * PostScript by CUPS). */
    if (isempty(fileconverter)) {
        if (find_in_path("texttops", cupsfilterpath, texttopspath)) {
            snprintf(fileconverter, PATH_MAX, "%s/texttops '%s' '%s' '%s' '%s' "
                    "page-top=36 page-bottom=36 page-left=36 page-right=36 "
                    "nolandscape cpi=12 lpi=7 columns=1 wrap %s'"
                    "| %s/pstops  '%s' '%s' '%s' '%s' '%s'",
                    texttopspath, cups_jobid, cups_user, cups_jobtitle, cups_copies, cups_options,
                    texttopspath, cups_jobid, cups_user, cups_jobtitle, cups_copies, cups_options);
        }
    }

    free(cups_options);
}
Exemplo n.º 11
0
Arquivo: vu8.cpp Projeto: OrenMe/vu8
int main(int argc, char *argv[]) {
    po::options_description desc("allowed options");

    std::string libPath;
    typedef std::vector<std::string> scripts_t;
    scripts_t scripts;

    po::positional_options_description positionals;
    positionals.add("script", -1);
    desc.add_options()
        ("help,h", "print this help message.")
        ("script,s", po::value(&scripts), "script to run.")
        ("library-path,l", po::value(&libPath), "path containing plugin libraries.")
        ;

    po::variables_map vm;
    try {
        po::store(po::command_line_parser(argc, argv)
            .options(desc).positional(positionals).run(), vm);
    }
    catch (po::invalid_option_value& e) {
        std::cerr << e.what() << std::endl;
        return 1;
    }
    catch (po::multiple_occurrences& e) {
        usage(desc);
        std::cerr << "multiple occurences of same option" << std::endl;
        return 1;
    }
    catch (po::unknown_option& e) {
        usage(desc);
        std::cerr << e.what() << std::endl;
        return 1;
    }

    if (vm.count("help")) {
        usage(desc);
        return 1;
    }

    po::notify(vm);

    if (libPath.empty()) {
        std::string root = find_in_path(argv[0]);
        boost::filesystem::path libPtr(root);
        libPtr = libPtr.parent_path();
        if (libPtr.has_parent_path()) {
            libPath = libPtr.parent_path().string();
            libPath.append("/lib");
        }
        else {
            libPath = "../lib";
        }
    }

    if (scripts.empty()) {
        std::cerr << "must supply at least one script\n";
        usage(desc);
        return 1;
    }

    try {
        Context ctxt(libPath);
        for (scripts_t::const_iterator it = scripts.begin();
             it != scripts.end(); ++it)
        { ctxt.RunFile(it->c_str()); }
    }
    catch (std::runtime_error const& e) {
        std::cerr << e.what() << std::endl;
        return 1;
    }

    v8::V8::Dispose();
    return 0;
}
Exemplo n.º 12
0
int main(int argc, char *argv[]) {
    char buf[PATH_MAX];
    char calling_link[PATH_MAX];
    char program_to_launch[PATH_MAX];
    char origin[PATH_MAX];
    char profile_bin_dir[PATH_MAX];
    char *s;
    int i;
    line = 0;

    s = getenv("HDIST_LAUNCHER_DEBUG");
    debug = (s != NULL && strcmp(s, "1") == 0);


    if (strstr(argv[0], "/") == NULL) {
        /* Launched through PATH lookup */
        if (find_in_path(argv[0], getenv("PATH"), calling_link, PATH_MAX) != 0) return -1;
    } else {
        hit_strlcpy(calling_link, argv[0], PATH_MAX);
    }


    /* Find calling link */
    if (debug) fprintf(stderr, "%sstart='%s'\n", debug_header, calling_link);
    if (follow_links(calling_link, profile_bin_dir, PATH_MAX) != 0) { line = __LINE__; goto error; }
    if (calling_link[0] == '\0') {
        help();
        return 0;
    }
    if (debug) fprintf(stderr, "%scaller=%s\n", debug_header, calling_link);
    if (debug) fprintf(stderr, "%sPROFILE_BIN_DIR=%s\n", debug_header, profile_bin_dir);

    if (profile_bin_dir[0] == '\0') {
        hit_strlcpy(profile_bin_dir, "__NA__", PATH_MAX);
    }

    /* Open ${calling_link}.link and read the contents */
    if (hit_strlcpy(buf, calling_link, PATH_MAX) >= PATH_MAX) { line = __LINE__; goto error; }
    if (hit_strlcat(buf, ".link", PATH_MAX) >= PATH_MAX) { line = __LINE__; goto error; }
    if (resolve_link_in_textfile(buf, program_to_launch, PATH_MAX) != 0) {
        if (errno != ENOENT) goto error;
        /* ${calling_link}.link not found, use ${calling_link}.real */
        if (hit_strlcpy(program_to_launch, calling_link, PATH_MAX) >= PATH_MAX) { line = __LINE__; goto error; }
        if (hit_strlcat(program_to_launch, ".real", PATH_MAX) >= PATH_MAX) { line = __LINE__; goto error; }
    }

    /* Find ${ORIGIN}; we need to resolve realpath() of program to launch */
    if (realpath(program_to_launch, origin) == NULL) {
        hit_strlcpy(origin, "__NA__", PATH_MAX);
    } else {
        splitpath(origin, &s);
        if (s == origin) {
            fprintf(stderr, "%sASSERTION FAILED, LINE %d\n", debug_header, __LINE__);
            return 127;
        }
    }
    
    if (debug) fprintf(stderr, "%sORIGIN=%s\n", debug_header, origin);

    if (debug) fprintf(stderr, "%sprogram=%s\n", debug_header, program_to_launch);
    if (attempt_shebang_launch(program_to_launch, origin, profile_bin_dir, argc, argv) == -1) {
        if (errno == ENOENT) {
            fprintf(stderr, "launcher:Unable to launch '%s' (%s)", program_to_launch, strerror(errno));
            return 127;
        }
        goto error;
    }
    /* shebang not present */
    /* substitute argv[0] with caller */
    argv[0] = calling_link;
    if (debug){
      fprintf(stderr, "%sprogram_to_launch=%s\n", debug_header, program_to_launch);
      for (i=0;i<argc;i++){
	fprintf(stderr, "%sargv[%d]=%s\n", debug_header, i,argv[i]);
      }
    }
    execv(program_to_launch, argv);
    fprintf(stderr, "launcher:Unable to launch '%s' (%s)\n", program_to_launch,
            strerror(errno));
    return 127;
    goto error;

 error:
    fprintf(stderr, "%s:%d:%s:\n", __FILE__, line, strerror(errno));
    return 127;

}
Exemplo n.º 13
0
// Using a number of different methods, find a python installation to use
// for our dynamic loading.
int DynPy_FindPython()
{
	get_python_length();
	return find_in_env() || find_in_path() || find_in_registry();
}
Exemplo n.º 14
0
/** @todo Supspects to glib replacements, all path related stuff. */
tree_cell *
nasl_pread (lex_ctxt * lexic)
{
  tree_cell *retc = NULL, *a;
  anon_nasl_var *v;
  nasl_array *av;
  int i, j, n, sz, sz2, cd, nice;
  char **args = NULL, *cmd, *str, *str2, buf[8192];
  FILE *fp;
  char cwd[MAXPATHLEN], newdir[MAXPATHLEN];

  if (pid != 0)
    {
      nasl_perror (lexic, "nasl_pread is not reentrant!\n");
      return NULL;
    }

  a = get_variable_by_name (lexic, "argv");
  cmd = get_str_local_var_by_name (lexic, "cmd");
  if (cmd == NULL || a == NULL || (v = a->x.ref_val) == NULL)
    {
      nasl_perror (lexic, "pread() usage: cmd:..., argv:...\n");
      return NULL;
    }

  nice = get_int_local_var_by_name (lexic, "nice", 0);

  if (v->var_type == VAR2_ARRAY)
    av = &v->v.v_arr;
  else
    {
      nasl_perror (lexic, "pread: argv element must be an array (0x%x)\n",
                   v->var_type);
      return NULL;
    }

  cd = get_int_local_var_by_name (lexic, "cd", 0);

  cwd[0] = '\0';
  if (cd)
    {
      char *p;

      if (cmd[0] == '/')
        {
          strncpy (newdir, cmd, sizeof (newdir) - 1);   /* Flawfinder: ignore
                                                           (\0-termination taken
                                                           care of) */
          p = strrchr (newdir, '/');
          if (p != newdir)
            *p = '\0';
        }
      else
        {
          p = find_in_path (cmd, 0);
          if (p != NULL)
            strncpy (newdir, p, sizeof (newdir) - 1);   /* Flawfinder: ignore
                                                           (\0-termination taken
                                                           care of) */
          else
            {
              nasl_perror (lexic, "pread: '%s' not found in $PATH\n", cmd);
              return NULL;
            }

        }
      newdir[sizeof (newdir) - 1] = '\0';

      if (getcwd (cwd, sizeof (cwd)) == NULL)
        {
          nasl_perror (lexic, "pread(): getcwd: %s\n", strerror (errno));
          *cwd = '\0';
        }

      if (chdir (newdir) < 0)
        {
          nasl_perror (lexic, "pread: could not chdir to %s\n", newdir);
          return NULL;
        }
      if (cmd[0] != '/' && strlen (newdir) + strlen (cmd) + 1 < sizeof (newdir))
        {
          strcat (newdir, "/"); /* Flawfinder: ignore (if-command above checks
                                   for size) */
          strcat (newdir, cmd); /* Flawfinder: ignore (if-command above checks
                                   for size) */
          cmd = newdir;
        }
    }

  if (av->hash_elt != NULL)
    nasl_perror (lexic, "pread: named elements in 'cmd' are ignored!\n");
  n = av->max_idx;
  args = emalloc (sizeof (char **) * (n + 2));  /* Last arg is NULL */
  for (j = 0, i = 0; i < n; i++)
    {
      str = (char *) var2str (av->num_elt[i]);
      if (str != NULL)
        args[j++] = estrdup (str);
    }
  args[j++] = NULL;

  old_sig_t = signal (SIGTERM, sig_h);
  old_sig_i = signal (SIGINT, sig_h);
  old_sig_c = signal (SIGCHLD, sig_c);

  fp = openvas_popen4 ((const char *) cmd, args, &pid, nice);

  for (i = 0; i < n; i++)
    efree (&args[i]);
  efree (&args);

  if (fp != NULL)
    {
      sz = 0;
      str = emalloc (1);

      errno = 0;
      while ((n = fread (buf, 1, sizeof (buf), fp)) > 0 || errno == EINTR)      /* && kill(pid, 0) >= 0) */
        {
          if (errno == EINTR)
            {
              errno = 0;
              continue;
            }
          sz2 = sz + n;
          str2 = erealloc (str, sz2);
          if (str2 == NULL)
            {
              nasl_perror (lexic, "nasl_pread: erealloc failed\n");
              break;
            }
          str = str2;
          memcpy (str + sz, buf, n);
          sz = sz2;
        }
      if (ferror (fp) && errno != EINTR)
        nasl_perror (lexic, "nasl_pread: fread(): %s\n", strerror (errno));

      (void) openvas_pclose (fp, pid);
      pid = 0;

      if (*cwd != '\0')
        if (chdir (cwd) < 0)
          nasl_perror (lexic, "pread(): chdir(%s): %s\n", cwd,
                       strerror (errno));

      retc = alloc_typed_cell (CONST_DATA);
      retc->x.str_val = str;
      retc->size = sz;
    }

  signal (SIGINT, old_sig_i);
  signal (SIGTERM, old_sig_t);
  signal (SIGCHLD, old_sig_c);

  return retc;
}
Exemplo n.º 15
0
int open_google_earth()
{
    char *kml_filename = appendExt(curr->filename, ".kml");

    char *basename = get_basename(curr->filename);
    char *dirname = get_dirname(curr->filename);

    char *arg;
    if (strlen(dirname)==0) {
        char *tmpdir = g_get_current_dir();
        dirname = escapify(tmpdir);
        arg = MALLOC(sizeof(char)*(strlen(dirname)+strlen(kml_filename)+20));
        sprintf(arg, "%s/%s", dirname, kml_filename);
        //free(tmpdir);
    }
    else {
        arg = STRDUP(kml_filename);
    }

    char *png_file = appendExt(arg, ".png");

    printf("png file: %s\n", png_file);
    printf("Temporary kml file: %s\n", arg);

    FILE *kml_file = fopen(arg, "w");
    if (!kml_file)
    {
        asfPrintWarning("Couldn't open kml file!\n");        
        return FALSE;
    }

    kml_header(kml_file);

    meta_parameters *meta = curr->meta;
    if (meta && meta->general &&
        meta_is_valid_double(meta->general->center_latitude) &&
        meta_is_valid_double(meta->general->center_longitude))
    {
        pixbuf2png(pixbuf_small, png_file);
        kml_entry_with_overlay(kml_file, meta, basename, png_file, dirname);
    }
    else
    {
        asfPrintWarning(
            "Failed, metadata doesn't contain valid lat/lon info.\n");
        return FALSE;
    }

    kml_footer(kml_file);
    fclose(kml_file);

    gchar *ge;

    printf("kml: %s\n", kml_filename);
    printf("dir: %s\n", dirname);

#ifdef win32
    char path[1024];
    FindExecutable((LPCTSTR)kml_filename, (LPCTSTR)dirname, (LPTSTR)path);
    ge = escapify(path);
    printf("Path to google earth: %s\n", ge);
    
    asfSystem("\"%s\" \"%s\"", ge, arg);
#else
    ge = find_in_path("googleearth");
    if (!ge)
    {
       message_box("Couldn't find googleearth! Is it installed?");
       return FALSE;
    }

    int pid = fork();
    if (pid == 0) {
        asfSystem("\"%s\" \"%s\"", ge, arg);
        //unlink(kml_filename);
        exit(EXIT_SUCCESS);
    }
#endif

    free(kml_filename);
    free(basename);
    free(dirname);
    free(arg);

    return TRUE;
}
Exemplo n.º 16
0
char *discover_system_java_home(void)
{
#ifdef WIN32
	HKEY key;
	HRESULT result;
	const char *key_root = "SOFTWARE\\JavaSoft\\Java Development Kit";
	struct string *string;
	char buffer[PATH_MAX];
	DWORD valuelen = sizeof(buffer);

	result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, key_root, 0, KEY_READ, &key);
	if (ERROR_SUCCESS != result)
		return NULL;
	result = RegQueryValueEx(key, "CurrentVersion", NULL, NULL, (LPBYTE)buffer, &valuelen);
	RegCloseKey(key);
	if (ERROR_SUCCESS != result)
{ error(get_win_error());
		return NULL;
}
	string = string_initf("%s\\%s", key_root, buffer);
	result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, string->buffer, 0, KEY_READ, &key);
	if (ERROR_SUCCESS != result)
		return NULL;
	valuelen = sizeof(buffer);
	result = RegQueryValueEx(key, "JavaHome", NULL, NULL, (LPBYTE)buffer, &valuelen);
	RegCloseKey(key);
	if (ERROR_SUCCESS != result)
		return NULL;
	return strdup(buffer);
#else
	const char *java_executable = find_in_path(get_java_command(), 0);

#ifdef __APPLE__
	int len = strlen(java_executable);
	if (len > 14 && !suffixcmp(java_executable, len, "/Commands/java")) {
		/*
		 * Containing folder is not a JRE or JDK, it's an Apple Framework. Bah!
		 * For example, the path:
		 *
		 *     /System/Library/Frameworks/JavaVM.framework/Versions/A/Commands
		 *
		 * does not actually contain a proper JRE. It is merely a Framework
		 * for the current version of Apple Java on the system.
		 *
		 * Unfortunately, on OS X, /usr/bin/java is typically symlinked to
		 * /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java,
		 * with Current symlinked to A, resulting in a failure of this PATH-based
		 * strategy to find the actual JRE. So we simply give up in that case.
		 */
		if (debug)
			error("Ignoring Apple Framework java executable: '%s'", java_executable);
		return NULL;
	}
#endif

	if (java_executable) {
		char *path = strdup(java_executable);
		const char *suffixes[] = {
			"java", "\\", "/", "bin", "\\", "/", NULL
		};
		int len = strlen(path), i;
		for (i = 0; suffixes[i]; i++)
			if (!suffixcmp(path, len, suffixes[i])) {
				len -= strlen(suffixes[i]);
				path[len] = '\0';
			}
		return path;
	}
	return NULL;
#endif
}