Beispiel #1
0
static int merge_env_file_push(
                const char *filename, unsigned line,
                const char *key, char *value,
                void *userdata,
                int *n_pushed) {

        char ***env = userdata;
        char *expanded_value;

        assert(env);

        if (!value) {
                log_error("%s:%u: invalid syntax (around \"%s\"), ignoring.", strna(filename), line, key);
                return 0;
        }

        if (!env_name_is_valid(key)) {
                log_error("%s:%u: invalid variable name \"%s\", ignoring.", strna(filename), line, key);
                free(value);
                return 0;
        }

        expanded_value = replace_env(value, *env,
                                     REPLACE_ENV_USE_ENVIRONMENT|
                                     REPLACE_ENV_ALLOW_BRACELESS|
                                     REPLACE_ENV_ALLOW_EXTENDED);
        if (!expanded_value)
                return -ENOMEM;

        free_and_replace(value, expanded_value);

        return load_env_file_push(filename, line, key, value, env, n_pushed);
}
Beispiel #2
0
char	*build_cmd(char **env, char *cmd, int lret)
{
	char	*tmp;

	cmd = sup_replace(cmd);
	cmd = ft_strcut(cmd, ' ');
	if (env && *env)
	{
		tmp = ft_strdup(cmd);
		free(cmd);
		cmd = replace_env(env, tmp, lret);
		free(tmp);
	}
	return (cmd);
}
Beispiel #3
0
void		reset_OLDPATH(char *oldpwd)
{
	char	*path;
	int		i;
	char	new_pwd[BUFF_SIZE];
	int		pos;

	pos = 0;
	i = -1;	
	path = "OLDPWD=";
	ft_strcpy(new_pwd, path);
	ft_strcat(new_pwd, oldpwd);
	while (saved_env[++i] != 0)
	{
		if ((ft_strncmp(saved_env[i], new_pwd, ft_indexof(new_pwd, '='))) == 0)
		   saved_env[i] = replace_env(&pos, new_pwd, saved_env[i]);	
	}
}
Beispiel #4
0
environment_t *set_env(struct sip_msg *msg)
{
	struct hf_wrapper *hf_list;
	environment_t *backup_env;

	/* parse all so that we can pass all header fields to script */
	if (parse_headers(msg, HDR_EOH, 0)==-1) {
		LOG(L_ERR, "ERROR: set_env: parsing failed\n");
		return 0;
	}

	hf_list=0;
	/* create a temporary structure with ordered header fields
	 * and create environment variables out of it */
	if (!build_hf_struct(msg, &hf_list)) {
		LOG(L_ERR, "ERROR: set_env: build_hf_struct failed\n");
		return 0;
	}
	if (!append_fixed_vars(msg, &hf_list)) {
		LOG(L_ERR, "ERROR: ser_env: append_fixed_vars failed\n");
		goto error01;
	}
	/* create now the strings for environment variables */
	if (!create_vars(hf_list, 0)) {
		LOG(L_ERR, "ERROR: set_env: create_vars failed\n");
		goto error00;
	}
	/* install the variables in current environment */
	backup_env=replace_env(hf_list);
	if (!backup_env) {
		LOG(L_ERR, "ERROR: set_env: replace_env failed\n");
		goto error00;
	}
	/* release the ordered HF structure -- we only need the vars now */
	release_hf_struct(hf_list);
	return backup_env;

error00:
	release_vars(hf_list); /* release variables */
error01:
	release_hf_struct(hf_list); /* release temporary ordered HF struct */
	return 0;
}
Beispiel #5
0
char		*clear_path(char *path)
{
	char	*pwd;
	char	*res;

	pwd = getenvline("PWD=");
	if (!pwd)
		pwd = getcwd(pwd, 0);
	if (path[0] == '/')
	{
		replace_env("PWD", "PWD=", "/");
		res = path;
		ft_strdel(&pwd);
	}
	else
	{
		res = concatenate(path, pwd);
		ft_strdel(&path);
	}
	return (res);
}