Example #1
0
/*
 * Create a unique temporary file in maildir/tmp, return fd and full
 * path to file in *path_out, or -1 on errors (in which case *path_out
 * is not touched).
 */
static int
maildir_mktemp (const void *ctx, const char *maildir, char **path_out)
{
    char *filename, *path;
    int fd;

    do {
	filename = tempfilename (ctx);
	if (! filename)
	    return -1;

	path = talloc_asprintf (ctx, "%s/tmp/%s", maildir, filename);
	if (! path) {
	    fprintf (stderr, "Error: %s\n", strerror (ENOMEM));
	    return -1;
	}

	fd = open (path, O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, 0600);
    } while (fd == -1 && errno == EEXIST);

    if (fd == -1) {
	fprintf (stderr, "Error: open '%s': %s\n", path, strerror (errno));
	return -1;
    }

    *path_out = path;

    return fd;
}
Example #2
0
int main(int argc, char *argv[])
{
	UINT32 bufsize;
	void *buffer;
	int listnum;
	int result;

	/* first argument is the directory */
	if (argc < 4)
	{
		fprintf(stderr, "Usage:\nregrep <template> <outputdir> <summary1> [<summary2> [<summary3> ...]]\n");
		return 1;
	}
	std::string tempfilename(argv[1]);
	std::string dirname(argv[2]);
	list_count = argc - 3;

	/* read the template file into an astring */
	std::string tempheader;
	if (util::core_file::load(tempfilename.c_str(), &buffer, bufsize) == osd_file::error::NONE)
	{
		tempheader.assign((const char *)buffer, bufsize);
		osd_free(buffer);
	}

	/* verify the template */
	if (tempheader.length() == 0)
	{
		fprintf(stderr, "Unable to read template file\n");
		return 1;
	}
	result = tempheader.find("<!--CONTENT-->");
	if (result == -1)
	{
		fprintf(stderr, "Template is missing a <!--CONTENT--> marker\n");
		return 1;
	}
	std::string tempfooter(tempheader);
	tempfooter = tempfooter.substr(result + 14);
	tempfooter = tempheader.substr(0, result);

	/* loop over arguments and read the files */
	for (listnum = 0; listnum < list_count; listnum++)
	{
		result = read_summary_log(argv[listnum + 3], listnum);
		if (result != 0)
			return result;
	}

	/* output the summary */
	output_report(dirname, tempheader, tempfooter, sort_file_list());
	return 0;
}
Example #3
0
// is this a scan bypass URL? i.e. a "magic" URL for retrieving a previously scanned file
bool HTTPHeader::isScanBypassURL(String * url, const char *magic, const char *clientip)
{
	if ((*url).length() <= 45)
		return false;  // Too short, can't be a bypass

	if (!(*url).contains("GSBYPASS="******"URL GSBYPASS found checking..." << std::endl;
#endif

	String url_left((*url).before("GSBYPASS="******"GSBYPASS="******"URL: " << url_left << ", HASH: " << url_hash << std::endl;
#endif

	// format is:
	// GSBYPASS=hash(ip+url+tempfilename+mime+disposition+secret)
	// &N=tempfilename&M=mimetype&D=dispos

	String tempfilename(url_right.after("&N="));
	String tempfilemime(tempfilename.after("&M="));
	String tempfiledis(tempfilemime.after("&D="));
	tempfilemime = tempfilemime.before("&D=");
	tempfilename = tempfilename.before("&M=");

	String tohash(clientip + url_left + tempfilename + tempfilemime + tempfiledis + magic);
	String hashed(tohash.md5());

#ifdef DGDEBUG
	std::cout << "checking hash: " << clientip << " " << url_left << " " << tempfilename << " " << " " << tempfilemime << " " << tempfiledis << " " << magic << " " << hashed << std::endl;
#endif

	if (hashed == url_hash) {
		return true;
	}
#ifdef DGDEBUG
	std::cout << "URL GSBYPASS HASH mismatch" << std::endl;
#endif

	return false;
}