Пример #1
0
rs_filebuf_t *rs_filebuf_new(struct asfd *asfd,
	BFILE *bfd, struct fzp *fzp, int fd,
	size_t buf_len, size_t data_len, struct cntr *cntr)
{
	rs_filebuf_t *pf=NULL;
	if(!(pf=(struct rs_filebuf *)calloc_w(1,
		sizeof(struct rs_filebuf), __func__))) return NULL;

	if(!(pf->buf=(char *)calloc_w(1, buf_len, __func__)))
		goto error;
	pf->buf_len=buf_len;
	pf->fzp=fzp;
	pf->fd=fd;
	pf->bfd=bfd;
	pf->bytes=0;
	pf->data_len=data_len;
	if(data_len>0)
		pf->do_known_byte_count=1;
	else
		pf->do_known_byte_count=0;
	pf->cntr=cntr;
	if(!MD5_Init(&(pf->md5)))
	{
		logp("MD5_Init() failed\n");
		goto error;
	}
	pf->asfd=asfd;
	return pf;
error:
	rs_filebuf_free(&pf);
	return NULL;
}
Пример #2
0
struct win *win_alloc(struct rconf *rconf)
{
	struct win *win=NULL;
	if(!(win=(struct win *)calloc_w(1, sizeof(struct win), __func__))
	  || !(win->data=(unsigned char *)calloc_w(
		1, sizeof(unsigned char)*rconf->win_size, __func__)))
			win_free(&win);
	return win;
}
Пример #3
0
struct win *win_alloc(struct rconf *rconf)
{
	struct win *win=NULL;
	if((win=(struct win *)calloc_w(1, sizeof(struct win), __func__))
	  && (win->data=(char *)calloc_w(1, sizeof(char)*rconf->win, __func__)))
		return win;
	win_free(win);
	return NULL;
}
Пример #4
0
int manio_init_write_dindex(struct manio *manio, const char *dir)
{
	int i=0;
	if(!(manio->dindex_dir=strdup_w(dir, __func__))
	  || !(manio->dindex_sort=
		(char **)calloc_w(MANIFEST_SIG_MAX, sizeof(char*), __func__)))
			return -1;
	for(i=0; i<MANIFEST_SIG_MAX; i++)
		if(!(manio->dindex_sort[i]=
			(char *)calloc_w(1, MSAVE_PATH_LEN+1, __func__)))
				return -1;
	return 0;
}
Пример #5
0
int manio_init_write_hooks(struct manio *manio,
	const char *base_dir, const char *dir)
{
	int i=0;
	if(!(manio->base_dir=strdup_w(base_dir, __func__))
	  || !(manio->hook_dir=strdup_w(dir, __func__))
	  || !(manio->hook_sort=
		(char **)calloc_w(MANIFEST_SIG_MAX, sizeof(char*), __func__)))
			return -1;
	for(i=0; i<MANIFEST_SIG_MAX; i++)
		if(!(manio->hook_sort[i]=
			(char *)calloc_w(1, WEAK_STR_LEN, __func__)))
				return -1;
	return 0;
}
Пример #6
0
// Initialize the find files "global" variables
FF_PKT *find_files_init(void)
{
	FF_PKT *ff;

	if(!(ff=(FF_PKT *)calloc_w(1, sizeof(FF_PKT), __func__))
	  || !(linkhash=(f_link **)
		calloc_w(1, LINK_HASHTABLE_SIZE*sizeof(f_link *), __func__)))
			return NULL;

	// Get system path and filename maximum lengths.
	init_max(&path_max, _PC_PATH_MAX);
	init_max(&name_max, _PC_NAME_MAX);

	return ff;
}
Пример #7
0
int linkhash_init(void)
{
	if(!(linkhash=(f_link **)
		calloc_w(1, LINK_HASHTABLE_SIZE*sizeof(f_link *), __func__)))
			return -1;
	return 0;
}
Пример #8
0
// Initialize the find files "global" variables
FF_PKT *find_files_init(void)
{
	FF_PKT *ff;

	if(!(ff=(FF_PKT *)calloc_w(1, sizeof(FF_PKT), __func__))
	  || !(linkhash=(f_link **)
		calloc_w(1, LINK_HASHTABLE_SIZE*sizeof(f_link *), __func__)))
			return NULL;

	// Get system path and filename maximum lengths.
	// FIX THIS: maybe this should be done every time a file system is
	// crossed?
	init_fs_max(NULL);

	return ff;
}
Пример #9
0
Файл: rblk.c Проект: grke/burp
static struct rblk *rblk_alloc(void)
{
	struct rblk *rblk;
	rblk=(struct rblk *)calloc_w(1, sizeof(struct rblk), __func__);
	if(rblk)
		rblk_mem+=sizeof(struct rblk);
	return rblk;
}
Пример #10
0
struct protocol1 *sbuf_protocol1_alloc(void)
{
	struct protocol1 *p;
	if((p=(struct protocol1 *)calloc_w(1,
		sizeof(struct protocol1), __func__)))
			sbuf_protocol1_init(p);
	return p;
}
Пример #11
0
struct async *async_alloc(void)
{
	struct async *as;
	if(!(as=(struct async *)calloc_w(1, sizeof(struct async), __func__)))
		return NULL;
	as->init=async_init;
	return as;
}
Пример #12
0
static int init_write_dindex(struct manio *manio, const char *dir)
{
	if(!(manio->dindex_dir=strdup_w(dir, __func__))
	  || !(manio->dindex_sort=(uint64_t *)calloc_w(MANIFEST_SIG_MAX,
		sizeof(uint64_t), __func__)))
			return -1;
	return 0;
}
Пример #13
0
struct iobuf *iobuf_alloc(void)
{
	struct iobuf *iobuf;
	if(!(iobuf=(struct iobuf *)calloc_w(1, sizeof(struct iobuf), __func__)))
		return NULL;
	iobuf_init(iobuf);
	return iobuf;
}
Пример #14
0
struct dpth *dpth_alloc(const char *base_path)
{
        struct dpth *dpth=NULL;
        if((dpth=(struct dpth *)calloc_w(1, sizeof(struct dpth), __func__))
	  && (dpth->base_path=strdup_w(base_path, __func__)))
		return dpth;
	dpth_free(&dpth);
	return NULL;
}
Пример #15
0
struct protocol2 *sbuf_protocol2_alloc(void)
{
	struct protocol2 *protocol2;
	if(!(protocol2=(struct protocol2 *)
		calloc_w(1, sizeof(struct protocol2), __func__)))
			return NULL;
	bfile_setup_funcs(&protocol2->bfd);
	return protocol2;
}
Пример #16
0
static int init_write_hooks(struct manio *manio,
	const char *hook_dir, const char *rmanifest)
{
	if(!(manio->hook_dir=strdup_w(hook_dir, __func__))
	  || !(manio->rmanifest=strdup_w(rmanifest, __func__))
	  || !(manio->hook_sort=(uint64_t *)calloc_w(MANIFEST_SIG_MAX,
		sizeof(uint64_t), __func__)))
			return -1;
	return 0;
}
Пример #17
0
static struct dpth_lock *dpth_lock_alloc(const char *save_path)
{
        struct dpth_lock *dpth_lock;
        if(!(dpth_lock=(struct dpth_lock *)
		calloc_w(1, sizeof(struct dpth_lock), __func__)))
			return NULL;
	snprintf(dpth_lock->save_path, sizeof(dpth_lock->save_path),
		"%s", save_path);
        return dpth_lock;
}
Пример #18
0
struct blk *blk_alloc_with_data(uint32_t max_data_length)
{
	struct blk *blk=NULL;
	if(!(blk=blk_alloc())) return NULL;
	if((blk->data=(char *)
	  calloc_w(1, sizeof(char)*max_data_length, __func__)))
		return blk;
	blk_free(&blk);
	return NULL;
}
Пример #19
0
Файл: cntr.c Проект: jkniiv/burp
int add_cntr_ent(struct cntr *cntr, int versions,
	char cmd, const char *field, const char *label)
{
	struct cntr_ent *cenew=NULL;
	if((!cntr->ent
	  && !(cntr->ent=(struct cntr_ent **)
	    calloc_w(1, CNTR_ENT_SIZE*sizeof(struct cntr_ent **), __func__)))
	  || !(cenew=(struct cntr_ent *)
	    calloc_w(1, sizeof(struct cntr_ent), __func__))
	  || !(cenew->field=strdup_w(field, __func__))
	  || !(cenew->label=strdup_w(label, __func__)))
		goto error;
	cenew->versions=versions;
	cntr->ent[(uint8_t)cmd]=cenew;
	cntr->cmd_order[cntr->colen++]=cmd;
	return 0;
error:
	cntr_ent_free(cenew);
	return -1;
}
Пример #20
0
// Initialize the find files "global" variables
FF_PKT *find_files_init(
	int callback(struct asfd *asfd, FF_PKT *ff, struct conf **confs))
{
	FF_PKT *ff;

	if(!(ff=(FF_PKT *)calloc_w(1, sizeof(FF_PKT), __func__))
	  || linkhash_init())
		return NULL;
	send_file=callback;

	return ff;
}
Пример #21
0
int get_xattr(struct asfd *asfd, const char *path,
	char **xattrtext, size_t *xlen, struct cntr *cntr)
{
	int ret=0;
	ssize_t len;
	int have_acl=0;
	char *toappend=NULL;
	char *xattrlist=NULL;
	ssize_t totallen=0;

	if((len=llistxattr(path, NULL, 0))<0)
	{
		logw(asfd, cntr, "could not llistxattr '%s': %zd %s\n",
			path, len, strerror(errno));
		goto end; // Carry on.
	}
	if(!(xattrlist=(char *)calloc_w(1, len, __func__)))
	{
		ret=-1;
		goto end;
	}
	if((len=llistxattr(path, xattrlist, len))<0)
	{
		logw(asfd, cntr, "could not llistxattr '%s': %zd %s\n",
			path, len, strerror(errno));
		goto end; // Carry on.
	}

	if(xattrtext && *xattrtext)
	{
		// Already have some meta text, which means that some
		// ACLs were set.
		have_acl++;
	}

	if(get_toappend(asfd, path, &toappend, xattrlist, len, &totallen,
		have_acl, cntr))
	{
		ret=-1;
		goto end;
	}

	if(toappend)
		ret=append_to_extrameta(toappend, META_XATTR,
			xattrtext, xlen, totallen);
end:
	free_w(&toappend);
	free_w(&xattrlist);
	return ret;
}
Пример #22
0
static struct strlist *strlist_alloc(const char *path, long flag)
{
	struct strlist *slnew=NULL;
	if(!path)
	{
		logp("%s called with NULL path!\n", __func__);
		return NULL;
	}
	if(!(slnew=(struct strlist *)
		calloc_w(1, sizeof(struct strlist), __func__))
	  || !(slnew->path=strdup_w(path, __func__)))
		return NULL;
	slnew->flag=flag;
	return slnew;
}
Пример #23
0
int rblk_retrieve_data(const char *datpath, struct blk *blk)
{
    static char fulldatpath[256]="";
    static struct rblk *rblks=NULL;
    char *cp;
    unsigned int datno;
    struct rblk *rblk;

    snprintf(fulldatpath, sizeof(fulldatpath),
             "%s/%s", datpath, bytes_to_savepathstr_with_sig(blk->savepath));

//printf("x: %s\n", fulldatpath);
    if(!(cp=strrchr(fulldatpath, '/')))
    {
        logp("Could not parse data path: %s\n", fulldatpath);
        return -1;
    }
    *cp=0;
    cp++;
    datno=strtoul(cp, NULL, 16);
//printf("y: %s\n", fulldatpath);

    if(!rblks
            && !(rblks=(struct rblk *)
                       calloc_w(RBLK_MAX, sizeof(struct rblk), __func__)))
        return -1;

    if(!(rblk=get_rblk(rblks, fulldatpath)))
    {
        return -1;
    }

//	printf("lookup: %s (%s)\n", fulldatpath, cp);
    if(datno>rblk->readbuflen)
    {
        logp("dat index %d is greater than readbuflen: %d\n",
             datno, rblk->readbuflen);
        return -1;
    }
    blk->data=rblk->readbuf[datno].buf;
    blk->length=rblk->readbuf[datno].len;
//	printf("length: %d\n", blk->length);

    return 0;
}
Пример #24
0
static int add_cntr_ent(struct cntr *cntr, int flags,
	char cmd, const char *field, const char *label)
{
	struct cntr_ent *cenew=NULL;
	if(!(cenew=(struct cntr_ent *)
	    calloc_w(1, sizeof(struct cntr_ent), __func__))
	  || !(cenew->field=strdup_w(field, __func__))
	  || !(cenew->label=strdup_w(label, __func__)))
		goto error;
	cenew->flags=flags;

	if(cntr->list) cenew->next=cntr->list;
	cntr->list=cenew;

	cntr->ent[(uint8_t)cmd]=cenew;
	return 0;
error:
	cntr_ent_free(cenew);
	return -1;
}
Пример #25
0
struct sbuf *sbuf_alloc(enum protocol protocol)
{
	struct sbuf *sb;
	if(!(sb=(struct sbuf *)calloc_w(1, sizeof(struct sbuf), __func__)))
		return NULL;
	iobuf_init(&sb->path);
	iobuf_init(&sb->attr);
	sb->attr.cmd=CMD_ATTRIBS;
	iobuf_init(&sb->link);
	iobuf_init(&sb->endfile);
	sb->compression=-1;
	if(protocol==PROTO_1)
	{
		if(!(sb->protocol1=sbuf_protocol1_alloc())) return NULL;
	}
	else
	{
		if(!(sb->protocol2=sbuf_protocol2_alloc())) return NULL;
	}
	return sb;
}
Пример #26
0
EVP_CIPHER_CTX *enc_setup(int encrypt, const char *encryption_password)
{
	EVP_CIPHER_CTX *ctx=NULL;
	// Declare enc_iv with individual characters so that the weird last
	// character can be specified as a hex number in order to prevent
	// compilation warnings on Macs.
	uint8_t enc_iv[]={'[', 'l', 'k', 'd', '.', '$', 'G', 0xa3, '\0'};

	if(!encryption_password)
	{
		logp("No encryption password in %s()\n", __func__);
		goto error;
	}

	if(!(ctx=(EVP_CIPHER_CTX *)
		calloc_w(1, sizeof(EVP_CIPHER_CTX), __func__)))
			goto error;

	// Don't set key or IV because we will modify the parameters.
	EVP_CIPHER_CTX_init(ctx);
	if(!(EVP_CipherInit_ex(ctx, EVP_bf_cbc(), NULL, NULL, NULL, encrypt)))
	{
		logp("EVP_CipherInit_ex failed\n");
		goto error;
	}
	EVP_CIPHER_CTX_set_key_length(ctx, strlen(encryption_password));
	// We finished modifying parameters so now we can set key and IV

	if(!EVP_CipherInit_ex(ctx, NULL, NULL,
		(uint8_t *)encryption_password,
		enc_iv, encrypt))
	{
		logp("Second EVP_CipherInit_ex failed\n");
		goto error;
	}
	return ctx;
error:
	free_v((void **)&ctx);
	return NULL;
}
Пример #27
0
Файл: cntr.c Проект: jkniiv/burp
int cntr_init(struct cntr *cntr, const char *cname)
{
	if(!cname)
	{
		logp("%s called with no client name\n", __func__);
		return -1;
	}
	cntr->start=time(NULL);

	if(
	     add_cntr_ent(cntr, CNTR_VER_ALL|CNTR_TABULATE,
		CMD_FILE, "files", "Files")
	  || add_cntr_ent(cntr, CNTR_VER_ALL|CNTR_TABULATE,
		CMD_ENC_FILE, "files_encrypted", "Files (encrypted)")
	  || add_cntr_ent(cntr, CNTR_VER_ALL|CNTR_TABULATE,
		CMD_METADATA, "meta_data", "Meta data")
	  || add_cntr_ent(cntr, CNTR_VER_ALL|CNTR_TABULATE,
		CMD_ENC_METADATA, "meta_data_encrypted", "Meta data (enc)")
	  || add_cntr_ent(cntr, CNTR_VER_ALL|CNTR_TABULATE,
		CMD_DIRECTORY, "directories", "Directories")
	  || add_cntr_ent(cntr, CNTR_VER_ALL|CNTR_TABULATE,
		CMD_HARD_LINK, "soft_links", "Hard links")
	  || add_cntr_ent(cntr, CNTR_VER_ALL|CNTR_TABULATE,
		CMD_SOFT_LINK, "hard_links", "Soft links")
	  || add_cntr_ent(cntr, CNTR_VER_ALL|CNTR_TABULATE,
		CMD_SPECIAL, "special_files", "Special files")
	  || add_cntr_ent(cntr, CNTR_VER_2_4|CNTR_TABULATE,
		CMD_VSS, "vss_headers", "VSS headers")
	  || add_cntr_ent(cntr, CNTR_VER_2_4|CNTR_TABULATE,
		CMD_ENC_VSS, "vss_headers_encrypted", "VSS headers (enc)")
	  || add_cntr_ent(cntr, CNTR_VER_2_4|CNTR_TABULATE,
		CMD_VSS_T, "vss_footers", "VSS footers")
	  || add_cntr_ent(cntr, CNTR_VER_2_4|CNTR_TABULATE,
		CMD_ENC_VSS_T, "vss_footers_encrypted", "VSS footers (enc)")
	  || add_cntr_ent(cntr, CNTR_VER_4|CNTR_TABULATE,
		CMD_EFS_FILE, "efs_files", "EFS files")
	  || add_cntr_ent(cntr, CNTR_VER_4|CNTR_TABULATE,
		CMD_DATA, "blocks", "Blocks")
	  || add_cntr_ent(cntr, CNTR_VER_4|CNTR_TABULATE,
		CMD_ERROR, "errors", "Errors")
	  || add_cntr_ent(cntr, CNTR_VER_ALL,
		CMD_TOTAL, "total", "Total")
	  || add_cntr_ent(cntr, CNTR_VER_2_4|CNTR_TABULATE,
		CMD_GRAND_TOTAL, "grand_total", "Grand total")
	  || add_cntr_ent(cntr, CNTR_VER_ALL|CNTR_SINGLE_FIELD,
		CMD_WARNING, "warnings", "Warnings")
	  || add_cntr_ent(cntr, CNTR_VER_ALL|CNTR_SINGLE_FIELD,
		CMD_BYTES_ESTIMATED, "bytes_estimated", "Bytes nstimated")
	  || add_cntr_ent(cntr, CNTR_VER_ALL|CNTR_SINGLE_FIELD,
		CMD_BYTES, "bytes", "Bytes")
	  || add_cntr_ent(cntr, CNTR_VER_ALL|CNTR_SINGLE_FIELD,
		CMD_BYTES_RECV, "bytes_received", "Bytes received")
	  || add_cntr_ent(cntr, CNTR_VER_ALL|CNTR_SINGLE_FIELD,
		CMD_BYTES_SENT, "bytes_sent", "Bytes sent")
	)
		return -1;

	cntr->status_max_len=calc_max_status_len(cntr, cname);
	if(!(cntr->status=(char *)calloc_w(1, cntr->status_max_len, __func__))
	  || !(cntr->cname=strdup_w(cname, __func__)))
		return -1;

	return 0;
}
Пример #28
0
Файл: cntr.c Проект: jkniiv/burp
struct cntr *cntr_alloc(void)
{
	return (struct cntr *)calloc_w(1, sizeof(struct cntr), __func__);
}
Пример #29
0
static man_off_t *man_off_t_alloc(void)
{
	return (man_off_t *)calloc_w(1, sizeof(man_off_t), __func__);
}
Пример #30
0
static struct manio *manio_alloc(void)
{
	return (struct manio *)calloc_w(1, sizeof(struct manio), __func__);
}