Example #1
0
File: find.c Project: pkdevbox/burp
void find_files_free(FF_PKT **ff)
{
	linkhash_free();
	free_v((void **)ff);
}
Example #2
0
File: find.c Project: pkdevbox/burp
static int process_entries_in_directory(struct asfd *asfd, struct dirent **nl,
	int count, char **link, size_t len, size_t *link_len,
	struct conf **confs, FF_PKT *ff_pkt, dev_t our_device)
{
	int m=0;
	int ret=0;
	for(m=0; m<count; m++)
	{
		size_t i;
		char *p=NULL;
		char *q=NULL;

		p=nl[m]->d_name;

		if(strlen(p)+len>=*link_len)
		{
			*link_len=len+strlen(p)+1;
			if(!(*link=(char *)
			  realloc_w(*link, (*link_len)+1, __func__)))
				return -1;
		}
		q=(*link)+len;
		for(i=0; i<strlen(nl[m]->d_name); i++)
			*q++=*p++;
		*q=0;
		ff_pkt->flen=i;

		if(file_is_included_no_incext(confs, *link))
		{
			ret=find_files(asfd, ff_pkt,
				confs, *link, our_device, false /*top_level*/);
		}
		else
		{
			struct strlist *x;
			// Excluded, but there might be a subdirectory that is
			// included.
			for(x=get_strlist(confs[OPT_INCEXCDIR]); x; x=x->next)
			{
				if(x->flag
				  && is_subdir(*link, x->path))
				{
					struct strlist *y;
					if((ret=find_files(asfd, ff_pkt,
						confs, x->path,
						our_device, false)))
							break;
					// Now need to skip subdirectories of
					// the thing that we just stuck in
					// find_one_file(), or we might get
					// some things backed up twice.
					for(y=x->next; y; y=y->next)
						if(y->next
						 && is_subdir(x->path, y->path))
							y=y->next;
				}
			}
		}
		free_v((void **)&(nl[m]));
		if(ret) break;
	}
	return ret;
}
Example #3
0
File: find.c Project: pkdevbox/burp
static int found_directory(struct asfd *asfd,
	FF_PKT *ff_pkt, struct conf **confs,
	char *fname, dev_t parent_device, bool top_level)
{
	int ret=-1;
	char *link=NULL;
	size_t link_len;
	size_t len;
	int nbret=0;
	int count=0;
	dev_t our_device;
	struct dirent **nl=NULL;

	our_device=ff_pkt->statp.st_dev;

	if((nbret=nobackup_directory(get_strlist(confs[OPT_NOBACKUP]),
		ff_pkt->fname)))
	{
		if(nbret<0) goto end; // Error.
		ret=0; // Do not back it up.
		goto end;
	}

	/* Build a canonical directory name with a trailing slash in link var */
	len=strlen(fname);
	link_len=len+200;
	if(!(link=(char *)malloc_w(link_len+2, __func__)))
		goto end;
	snprintf(link, link_len, "%s", fname);

	/* Strip all trailing slashes */
	while(len >= 1 && IsPathSeparator(link[len - 1])) len--;
	/* add back one */
	link[len++]='/';
	link[len]=0;

	ff_pkt->link=link;
	ff_pkt->type=FT_DIR;

#if defined(HAVE_WIN32)
	windows_reparse_point_fiddling(ff_pkt);
#endif

	if(send_file_w(asfd, ff_pkt, top_level, confs))
		goto end;
	if(ff_pkt->type==FT_REPARSE || ff_pkt->type==FT_JUNCTION)
	{
		// Ignore.
		ret=0;
		goto end;
	}

	if(top_level
	  || (parent_device!=ff_pkt->statp.st_dev
#if defined(HAVE_WIN32)
		|| ff_pkt->statp.st_rdev==WIN32_MOUNT_POINT
#endif
		))
	{
		if(fstype_excluded(asfd, confs, ff_pkt->fname))
		{
			ret=send_file_w(asfd, ff_pkt, top_level, confs);
			goto end;
		}
		if(!top_level && !fs_change_is_allowed(confs, ff_pkt->fname))
		{
			ff_pkt->type=FT_NOFSCHG;
			// Just backup the directory and return.
			ret=send_file_w(asfd, ff_pkt, top_level, confs);
			goto end;
		}
	}

	ff_pkt->link=ff_pkt->fname;

	errno=0;
	switch(entries_in_directory_alphasort(fname,
		&nl, &count, get_int(confs[OPT_ATIME])))
	{
		case 0: break;
		case 1:
			ff_pkt->type=FT_NOOPEN;
			ret=send_file_w(asfd, ff_pkt, top_level, confs);
		default:
			goto end;
	}

	if(nl)
	{
		if(process_entries_in_directory(asfd, nl, count,
			&link, len, &link_len, confs, ff_pkt, our_device))
				goto end;
	}
	ret=0;
end:
	free_w(&link);
	free_v((void **)&nl);
	return ret;
}
Example #4
0
void scores_free(struct scores **scores)
{
	if(!scores) return;
	scores_free_content(*scores);
	free_v((void **)scores);
}
Example #5
0
File: iobuf.c Project: Lacoste/burp
void iobuf_free(struct iobuf **iobuf)
{
	if(!iobuf || !*iobuf) return;
	iobuf_free_content(*iobuf);
	free_v((void **)iobuf);
}
Example #6
0
static int do_recursive_delete(const char *d, const char *file, uint8_t delfiles, int32_t name_max)
{
	int ret=RECDEL_ERROR;
	DIR *dirp=NULL;
	struct dirent *entry=NULL;
	struct dirent *result;
	struct stat statp;
	char *directory=NULL;
	char *fullpath=NULL;

	if(!file)
	{
		if(!(directory=prepend_s(d, ""))) goto end;
	}
	else if(!(directory=prepend_s(d, file)))
	{
		log_out_of_memory(__func__);
		goto end;
	}

	if(lstat(directory, &statp))
	{
		// path does not exist.
		ret=RECDEL_OK;
		goto end;
	}

	if(!(dirp=opendir(directory)))
	{
		logp("opendir %s: %s\n", directory, strerror(errno));
		goto end;
	}

	if(!(entry=(struct dirent *)
		malloc_w(sizeof(struct dirent)+name_max+100, __func__)))
			goto end;

	while(1)
	{
		if(readdir_r(dirp, entry, &result) || !result)
		{
			// Got to the end of the directory.
			ret=RECDEL_OK;
			break;
		}

		if(entry->d_ino==0
		  || !strcmp(entry->d_name, ".")
		  || !strcmp(entry->d_name, ".."))
			continue;
		free_w(&fullpath);
		if(!(fullpath=prepend_s(directory, entry->d_name)))
			goto end;

		if(is_dir(fullpath, entry))
		{
			int r;
			if((r=do_recursive_delete(directory, entry->d_name,
				delfiles, name_max))==RECDEL_ERROR)
					goto end;
			// do not overwrite ret with OK if it previously
			// had ENTRIES_REMAINING
			if(r==RECDEL_ENTRIES_REMAINING) ret=r;
		}
		else if(delfiles)
		{
			if(unlink(fullpath))
			{
				logp("unlink %s: %s\n",
					fullpath, strerror(errno));
				ret=RECDEL_ENTRIES_REMAINING;
			}
		}
		else
		{
			ret=RECDEL_ENTRIES_REMAINING;
		}
	}

	if(ret==RECDEL_OK && rmdir(directory))
	{
		logp("rmdir %s: %s\n", directory, strerror(errno));
		ret=RECDEL_ERROR;
	}
end:
	if(dirp) closedir(dirp);
	free_w(&fullpath);
	free_w(&directory);
	free_v((void **)&entry);
	return ret;
}
Example #7
0
static void file_free(struct file **file)
{
	if(!file || !*file) return;
	file_free_content(*file);
	free_v((void **)file);
}
Example #8
0
void fdirs_free(struct fdirs **fdirs)
{
	if(!fdirs || !*fdirs) return;
	fdirs_free_content(*fdirs);
	free_v((void **)fdirs);
}
Example #9
0
File: bu.c Project: Lacoste/burp
void bu_free(struct bu **bu)
{
	if(!bu || !*bu) return;
	bu_free_content(*bu);
	free_v((void **)bu);
}
Example #10
0
void cstat_free(struct cstat **cstat)
{
	if(!cstat || !*cstat) return;
	cstat_free_content(*cstat);
	free_v((void **)cstat);
}
Example #11
0
File: msg.c Project: vanElden/burp
int transfer_gzfile_inl(struct asfd *asfd,
	struct sbuf *sb, const char *path, BFILE *bfd,
	uint64_t *rcvd, uint64_t *sent,
	const char *encpassword, int enccompressed,
	struct cntr *cntr, char **metadata)
{
	int quit=0;
	int ret=-1;
	uint8_t out[ZCHUNK];
	int doutlen=0;
	//uint8_t doutbuf[1000+EVP_MAX_BLOCK_LENGTH];
	uint8_t doutbuf[ZCHUNK-EVP_MAX_BLOCK_LENGTH];
	struct iobuf *rbuf=asfd->rbuf;

	z_stream zstrm;

	EVP_CIPHER_CTX *enc_ctx=NULL;

	// Checksum stuff
	//MD5_CTX md5;
	//uint8_t checksum[MD5_DIGEST_LENGTH];

#ifdef HAVE_WIN32
	if(sb && sb->path.cmd==CMD_EFS_FILE)
		return transfer_efs_in(asfd, bfd, rcvd, sent, cntr);
#endif

	//if(!MD5_Init(&md5))
	//{
	//	logp("MD5_Init() failed");
	//	return -1;
	//}

	zstrm.zalloc=Z_NULL;
	zstrm.zfree=Z_NULL;
	zstrm.opaque=Z_NULL;
	zstrm.avail_in=0;
	zstrm.next_in=Z_NULL;

	if(inflateInit2(&zstrm, (15+16)))
	{
		logp("unable to init inflate\n");
		return -1;
	}

	if(encpassword && !(enc_ctx=enc_setup(0, encpassword)))
	{
		inflateEnd(&zstrm);
		return -1;
	}

	while(!quit)
	{
		iobuf_free_content(rbuf);
		if(asfd->read(asfd))
		{
			if(enc_ctx)
			{
				EVP_CIPHER_CTX_cleanup(enc_ctx);
				free_v((void **)&enc_ctx);
			}
			inflateEnd(&zstrm);
			return -1;
		}
		(*rcvd)+=rbuf->len;

		//logp("transfer in: %c:%s\n", rbuf->cmd, rbuf->buf);
		switch(rbuf->cmd)
		{
			case CMD_APPEND: // append
				if(!bfd && !metadata)
				{
					logp("given append, but no file or metadata to write to\n");
					asfd->write_str(asfd, CMD_ERROR,
					  "append with no file or metadata");
					quit++; ret=-1;
				}
				else
				{
					size_t lentouse;
					uint8_t *buftouse=NULL;
/*
					if(!MD5_Update(&md5, rbuf->buf, rbuf->len))
					{
						logp("MD5 update enc error\n");
						quit++; ret=-1;
						break;
					}
*/
					// If doing decryption, it needs
					// to be done before uncompressing.
					if(enc_ctx)
					{
					  // updating our checksum needs to
					  // be done first
/*
					  if(!MD5_Update(&md5, rbuf->buf, rbuf->len))
					  {
						logp("MD5 update enc error\n");
						quit++; ret=-1;
						break;
					  }
					  else 
*/
					  if(!EVP_CipherUpdate(enc_ctx,
						doutbuf, &doutlen,
						(uint8_t *)rbuf->buf,
						rbuf->len))
					  {
						logp("Decryption error\n");
						quit++; ret=-1;
					  	break;
					  }
					  if(!doutlen) break;
					  lentouse=(size_t)doutlen;
					  buftouse=doutbuf;
					}
					else
					{
					  lentouse=rbuf->len;
					  buftouse=(uint8_t *)rbuf->buf;
					}
					//logp("want to write: %d\n", zstrm.avail_in);

					if(do_inflate(asfd, &zstrm, bfd, out,
						buftouse, lentouse, metadata,
						encpassword,
						enccompressed,
						sent))
					{
						ret=-1; quit++;
						break;
					}
				}
				break;
			case CMD_END_FILE: // finish up
				if(enc_ctx)
				{
					if(!EVP_CipherFinal_ex(enc_ctx,
						doutbuf, &doutlen))
					{
						logp("Decryption failure at the end.\n");
						ret=-1; quit++;
						break;
					}
					if(doutlen && do_inflate(asfd,
					  &zstrm, bfd,
					  out, doutbuf, (size_t)doutlen,
					  metadata, encpassword,
					  enccompressed, sent))
					{
						ret=-1; quit++;
						break;
					}
				}
/*
				if(MD5_Final(checksum, &md5))
				{
					char *oldsum=NULL;
					const char *newsum=NULL;

					if((oldsum=strchr(buf, ':')))
					{
						oldsum++;
						newsum=bytes_to_md5str(checksum);
						// log if the checksum differed
						if(strcmp(newsum, oldsum))
							logw(asfd, cntr, "md5sum for '%s' did not match! (%s!=%s)\n", path, newsum, oldsum);
					}
				}
				else
				{
					logp("MD5_Final() failed\n");
				}
*/
				quit++;
				ret=0;
				break;
			case CMD_MESSAGE:
			case CMD_WARNING:
				log_recvd(rbuf, cntr, 0);
				break;
			default:
				iobuf_log_unexpected(rbuf, __func__);
				quit++;
				ret=-1;
				break;
		}
	}
	inflateEnd(&zstrm);
	if(enc_ctx)
	{
		EVP_CIPHER_CTX_cleanup(enc_ctx);
		free_v((void **)&enc_ctx);
	}

	iobuf_free_content(rbuf);
	if(ret) logp("transfer file returning: %d\n", ret);
	return ret;
}
Example #12
0
void async_free(struct async **as)
{
	if(!as || !*as) return;
	free_v((void **)as);
}
Example #13
0
static int main_loop(struct async *as, enum action act, struct conf **confs)
{
	int ret=-1;
	char *client=NULL;
	int count=0;
	struct asfd *asfd=NULL;
	struct asfd *sfd=as->asfd; // Server asfd.
	int reqdone=0;
	struct sel *sel=NULL;
	const char *orig_client=get_string(confs[OPT_ORIG_CLIENT]);

	if(!(sel=(struct sel *)calloc_w(1, sizeof(struct sel), __func__)))
		goto error;
	sel->page=PAGE_CLIENT_LIST;

	if(orig_client && !client)
	{
		client=strdup_w(orig_client, __func__);
		sel->page=PAGE_BACKUP_LIST;
	}

	while(1)
	{
		if(need_status(sel) && !reqdone)
		{
			char *req=NULL;
			if(sel->page>PAGE_CLIENT_LIST)
			{
				if(client) req=client;
				else if(sel->client) req=sel->client->name;
			}
			if(request_status(sfd,
				req, sel, confs)) goto error;
			if(act==ACTION_STATUS_SNAPSHOT)
				reqdone=1;
		}

		if(as->read_write(as))
		{
			// FIX THIS - an exception is thrown when the console
			// is resized.
/*
			if(sfd->want_to_remove)
			{
				sfd->want_to_remove=0;
				continue;
			}
*/
			logp("Exiting main loop\n");
			goto error;
		}

		for(asfd=as->asfd; asfd; asfd=asfd->next)
			while(asfd->rbuf->buf)
		{
			switch(parse_data(asfd, sel, count))
			{
				case 0: break;
				case 1: goto end;
				default: goto error;
			}
			iobuf_free_content(asfd->rbuf);
			if(asfd->parse_readbuf(asfd))
				goto error;
		}

		if(!sel->client) sel->client=sel->clist;
		if(!sel->backup && sel->client) sel->backup=sel->client->bu;

#ifdef HAVE_NCURSES_H
		if(act==ACTION_STATUS
		  && update_screen(sel, confs))
			goto error;
		refresh();
#endif

		if(act==ACTION_STATUS_SNAPSHOT
		  && sel->gotfirstresponse)
		{
			if(update_screen(sel, confs))
				goto error;
			// FIX THIS - should probably set up stdout with an
			// asfd.
			printf("\n");
			break;
		}
	}

end:
	ret=0;
error:
	// FIX THIS: should probably be freeing a bunch of stuff here.
	free_v((void **)&sel);
	return ret;
}
Example #14
0
static void scores_free_content(struct scores *scores)
{
	if(!scores) return;
	free_v((void **)&scores->scores);
}
Example #15
0
File: blk.c Project: EmisFR/burp
void blk_free(struct blk **blk)
{
	if(!blk || !*blk) return;
	blk_free_content(*blk);
	free_v((void **)blk);
}
Example #16
0
void dpth_free(struct dpth **dpth)
{
	if(!dpth || !*dpth) return;
	free_w(&((*dpth)->base_path));
	free_v((void **)dpth);
}
Example #17
0
void candidate_free(struct candidate **c)
{
	if(!c) return;
	candidate_free_content(*c);
	free_v((void **)c);
}
void init_particles(double l, double rc, double dt, double temp, Ensemble *c_ens, Ensemble *p_ens)
{
    int		i, j, n, close_flag = 0;
    double	rxij, ryij, rijsq, crx0, cry0, *vx, *vy;
    double  *rx0, *ry0, *rx, *ry, *fx, *fy;
    double  int_max, vms;
    unsigned int    rnd[2];
    FILE	*fpr;
    
    rx0 = p_ens->rx;
    ry0 = p_ens->ry;
    fx = p_ens->fx;
    fy = p_ens->fy;
    rx = c_ens->rx;
    ry = c_ens->ry;
    n = c_ens->number;
    
    if ((fpr = fopen("/dev/urandom", "rb")) == NULL) {
        fprintf(stderr, "File '/dev/urandom' not open.\n");
        exit(3);
    }

    if (sizeof(int) == 8)
        int_max = (double)((unsigned int)0xffffffffffffffff) + 1.0;
    else if (sizeof(int) == 4)
        int_max = (double)((unsigned int)0xffffffff) + 1.0;
    else
        exit(20);

    i = 0;
    while (i < n) {
        fread(rnd, sizeof(int), 2, fpr);
        crx0 = l * (rnd[0] / int_max - 0.5);
        cry0 = l * (rnd[1] / int_max - 0.5);
        if (i != 0) {
            for (close_flag = 0, j = 0; j < i; j++) {
                rxij = crx0 - rx0[j];
                ryij = cry0 - ry0[j];
                rxij -= round(rxij / l) * l;
                ryij -= round(ryij / l) * l;
                rijsq = rxij * rxij + ryij * ryij;
                if (rijsq < 1.0) {
                    close_flag = 1;
                    break;
                }
            }
        }
        if (i == 0 || close_flag == 0) {
            rx0[i] = crx0;
            ry0[i] = cry0;
            i++;
        }
    }

    double	hsq2, cc0, cc10, cc11;

    hsq2 = dt * dt / 2.0;
    cc0 = 1.0 / p_ens->mass;
    
    alloc_v(n, &vx, &vy);
    
    vms = 0.0;
    for (i = 0; i < n; i++) {
        fread(rnd, sizeof(int), 2, fpr);
        cc10 = sqrt(-2.0 * temp * cc0 * log(rnd[0] / int_max));
        cc11 = 2.0 * PI * rnd[1] / int_max;
        vx[i] = cc10 * cos(cc11);
        vy[i] = cc10 * sin(cc11);
        vms += vx[i] * vx[i] + vy[i] * vy[i];
    }
    c_ens->v2Mean = p_ens->v2Mean = vms / n;

    mom_correct(n, vx, vy);
    force(p_ens, l, rc);

    for (i = 0; i < n; i++) {
        rx[i] = rx0[i] + dt * vx[i] + hsq2 * fx[i] * cc0;
        ry[i] = ry0[i] + dt * vy[i] + hsq2 * fy[i] * cc0;
    }

    free_v(vx, vy);
    fclose(fpr);
}
Example #19
0
static void mystruct_free(struct mystruct **mystruct)
{
	if(!mystruct || !*mystruct) return;
	mystruct_free_content(*mystruct);
	free_v((void **)mystruct);
}
Example #20
0
void regex_free(regex_t **regex)
{
	if(!regex || !*regex) return;
        regfree(*regex);
	free_v((void **)regex);
}
Example #21
0
void rs_filebuf_free(rs_filebuf_t **fb) 
{
	if(!fb || !*fb) return;
	free_w(&((*fb)->buf));
        free_v((void **)fb);
}
Example #22
0
void asfd_mock_teardown(struct ioevent_list *user_reads,
	struct ioevent_list *user_writes)
{
	free_v((void **)&user_reads->ioevent);
	free_v((void **)&user_writes->ioevent);
}