Exemplo n.º 1
0
int restore_dir(struct asfd *asfd, struct sbuf *sb,
	const char *dname, enum action act, struct cntr *cntr,
	enum protocol protocol)
{
	int ret=0;
	char *rpath=NULL;
	if(act==ACTION_RESTORE)
	{
		if(build_path(dname, "", &rpath, NULL))
		{
			ret=warn_and_interrupt(asfd, sb, cntr, protocol,
				"build path failed: %s", dname);
			goto end;
		}
		else if(is_dir_lstat(rpath)<=0)
		{
			if(mkdir(rpath, 0777))
			{
				ret=warn_and_interrupt(asfd, sb, cntr, protocol,
					"mkdir error: %s", strerror(errno));
				goto end;
			}
		}
		attribs_set(asfd, rpath, &(sb->statp), sb->winattr, cntr);
		if(!ret) cntr_add(cntr, sb->path.cmd, 1);
	}
	else cntr_add(cntr, sb->path.cmd, 1);
end:
	free_w(&rpath);
	return ret;
}
Exemplo n.º 2
0
int restore_dir(struct asfd *asfd,
	struct sbuf *sb, const char *dname, enum action act, struct conf **confs)
{
	int ret=0;
	char *rpath=NULL;
	if(act==ACTION_RESTORE)
	{
		if(build_path(dname, "", &rpath, NULL))
		{
			ret=warn_and_interrupt(asfd, sb, confs,
				"build path failed: %s", dname);
			goto end;
		}
		else if(!is_dir_lstat(rpath))
		{
			if(mkdir(rpath, 0777))
			{
				ret=warn_and_interrupt(asfd, sb, confs,
					"mkdir error: %s", strerror(errno));
				goto end;
			}
		}
		attribs_set(asfd, rpath, &(sb->statp), sb->winattr, confs);
		if(!ret) cntr_add(get_cntr(confs[OPT_CNTR]), sb->path.cmd, 1);
	}
	else cntr_add(get_cntr(confs[OPT_CNTR]), sb->path.cmd, 1);
end:
	if(rpath) free(rpath);
	return ret;
}
Exemplo n.º 3
0
int is_dir(const char *path, struct dirent *d)
{
#ifdef _DIRENT_HAVE_D_TYPE
	// Faster evaluation on most systems.
	switch(d->d_type)
	{
		case DT_DIR:
			return 1;
		case DT_UNKNOWN:
			break;
		default:
			return 0;
	}
#endif
	return is_dir_lstat(path);
}
Exemplo n.º 4
0
static int restore_dir(struct asfd *asfd, struct sbuf *sb,
                       const char *dname, enum action act, struct conf *conf)
{
    int ret=0;
    char *rpath=NULL;
    if(act==ACTION_RESTORE)
    {
        if(build_path(dname, "", &rpath, NULL))
        {
            char msg[256]="";
            // failed - do a warning
            snprintf(msg, sizeof(msg),
                     "build path failed: %s", dname);
            if(restore_interrupt(asfd, sb, msg, conf))
                ret=-1;
            goto end;
        }
        else if(!is_dir_lstat(rpath))
        {
            if(mkdir(rpath, 0777))
            {
                char msg[256]="";
                snprintf(msg, sizeof(msg), "mkdir error: %s",
                         strerror(errno));
                // failed - do a warning
                if(restore_interrupt(asfd, sb, msg, conf))
                    ret=-1;
                goto end;
            }
        }
        attribs_set(asfd, rpath, &(sb->statp), sb->winattr, conf);
        if(!ret) cntr_add(conf->cntr, sb->path.cmd, 1);
    }
    else cntr_add(conf->cntr, sb->path.cmd, 1);
end:
    if(rpath) free(rpath);
    return ret;
}
Exemplo n.º 5
0
Arquivo: ca.c Projeto: Kalimeiro/burp
static int burp_ca_init(struct conf *conf, const char *ca_dir)
{
	int a=0;
	const char *args[15];
	char linktarget[1024]="";

	if(is_dir_lstat(ca_dir)) return 0;

	setup_stuff_done++;

	logp("Initialising %s\n", ca_dir);
	logp("Running '%s --init --ca %s --dir %s --config %s'\n",
		conf->ca_burp_ca, conf->ca_name, ca_dir, conf->ca_conf);
	args[a++]=conf->ca_burp_ca;
	args[a++]="--init";
	args[a++]="--ca";
	args[a++]=conf->ca_name;
	args[a++]="--dir";
	args[a++]=ca_dir;
	args[a++]="--config";
	args[a++]=conf->ca_conf;
	args[a++]=NULL;
	if(run_script(NULL /* no async yet */, args, NULL, conf, 1 /* wait */,
		0, 0 /* do not use logp - stupid openssl prints lots of dots
		        one at a time with no way to turn it off */))
	{
		logp("Error running %s\n", conf->ca_burp_ca);
		return -1;
	}

	logp("Generating server key and cert signing request\n");
	logp("Running '%s --key --request --name %s --dir %s --config %s'\n",
		conf->ca_burp_ca, conf->ca_server_name, ca_dir, conf->ca_conf);
	a=0;
	args[a++]=conf->ca_burp_ca;
	args[a++]="--key";
	args[a++]="--request";
	args[a++]="--name";
	args[a++]=conf->ca_server_name;
	args[a++]="--dir";
	args[a++]=ca_dir;
	args[a++]="--config";
	args[a++]=conf->ca_conf;
	args[a++]=NULL;
	if(run_script(NULL /* no async yet */, args, NULL, conf, 1 /* wait */,
		0, 0 /* do not use logp - stupid openssl prints lots of dots
		        one at a time with no way to turn it off */))
	{
		logp("Error running %s\n", conf->ca_burp_ca);
		return -1;
	}

	logp("Signing request\n");
	logp("Running '%s --sign --ca %s --name %s --batch --dir %s --config %s'\n",
		conf->ca_burp_ca, conf->ca_name, conf->ca_server_name, ca_dir, conf->ca_conf);
	a=0;
	args[a++]=conf->ca_burp_ca;
	args[a++]="--sign";
	args[a++]="--ca";
	args[a++]=conf->ca_name;
	args[a++]="--name";
	args[a++]=conf->ca_server_name;
	args[a++]="--batch";
	args[a++]="--dir";
	args[a++]=ca_dir;
	args[a++]="--config";
	args[a++]=conf->ca_conf;
	args[a++]=NULL;
	if(run_script(NULL /* no async yet */, args, NULL, conf, 1 /* wait */,
		0, 0 /* do not use logp - stupid openssl prints lots of dots
		        one at a time with no way to turn it off */))
	{
		logp("Error running %s\n", conf->ca_burp_ca);
		return -1;
	}

	snprintf(linktarget, sizeof(linktarget), "%s/CA_%s.crt",
		ca_dir, conf->ca_name);
	if(strcmp(linktarget, conf->ssl_cert_ca))
	{
		remove_file(conf->ssl_cert_ca);
		if(symlink_file(linktarget, conf->ssl_cert_ca)) return -1;
	}

	snprintf(linktarget, sizeof(linktarget), "%s/%s.crt",
		ca_dir, conf->ca_server_name);
	if(strcmp(linktarget, conf->ssl_cert))
	{
		remove_file(conf->ssl_cert);
		if(symlink_file(linktarget, conf->ssl_cert)) return -1;
	}

	snprintf(linktarget, sizeof(linktarget), "%s/%s.key",
		ca_dir, conf->ca_server_name);
	if(strcmp(linktarget, conf->ssl_key))
	{
		remove_file(conf->ssl_key);
		if(symlink_file(linktarget, conf->ssl_key)) return -1;
	}

	return 0;
}