示例#1
0
static void
addToFileblob(const line_t *line, void *arg)
{
    fileblob *fb = (fileblob *)arg;

    if(line) {
        const char *l = lineGetData(line);

        fileblobAddData(fb, (const unsigned char *)l, strlen(l));
    }
    fileblobAddData(fb, (const unsigned char *)"\n", 1);
}
示例#2
0
文件: blob.c 项目: nsxz/clamav-devel
void
fileblobPartialSet(fileblob *fb, const char *fullname, const char *arg)
{
    UNUSEDPARAM(arg);

    if(fb->b.name)
        return;

    assert(fullname != NULL);

    cli_dbgmsg("fileblobPartialSet: saving to %s\n", fullname);

    fb->fd = open(fullname, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY|O_EXCL, 0600);
    if(fb->fd < 0) {
        cli_errmsg("fileblobPartialSet: unable to create file: %s\n",fullname);
        return;
    }
    fb->fp = fdopen(fb->fd, "wb");

    if(fb->fp == NULL) {
        cli_errmsg("fileblobSetFilename: fdopen failed\n");
        close(fb->fd);
        return;
    }
    blobSetFilename(&fb->b, fb->ctx ? fb->ctx->engine->tmpdir : NULL, fullname);
    if(fb->b.data)
        if(fileblobAddData(fb, fb->b.data, fb->b.len) == 0) {
            free(fb->b.data);
            fb->b.data = NULL;
            fb->b.len = fb->b.size = 0;
            fb->isNotEmpty = 1;
        }
    fb->fullname = cli_strdup(fullname);
}
示例#3
0
/*
 * Save the uuencoded part of the file as it is read in since there's no need
 * to include it in the parse tree. Saves memory and parse time.
 * Return < 0 for failure
 */
int
uudecodeFile(message *m, const char *firstline, const char *dir, fmap_t *map, size_t *at)
{
	fileblob *fb;
	char buffer[RFC2821LENGTH + 1];
	char *filename = cli_strtok(firstline, 2, " ");

	if(filename == NULL)
		return -1;

	fb = fileblobCreate();
	if(fb == NULL) {
		free(filename);
		return -1;
	}

	fileblobSetFilename(fb, dir, filename);
	cli_dbgmsg("uudecode %s\n", filename);
	free(filename);

	while(fmap_gets(map, buffer, at, sizeof(buffer) - 1)) {
		unsigned char data[1024];
		const unsigned char *uptr;
		size_t len;

		cli_chomp(buffer);
		if(strcasecmp(buffer, "end") == 0)
			break;
		if(buffer[0] == '\0')
			break;

		uptr = decodeLine(m, UUENCODE, buffer, data, sizeof(data));
		if(uptr == NULL)
			break;

		len = (size_t)(uptr - data);
		if((len > 62) || (len == 0))
			break;

		if(fileblobAddData(fb, data, len) < 0)
			break;
	}

	fileblobDestroy(fb);

	return 1;
}
示例#4
0
文件: blob.c 项目: nsxz/clamav-devel
void
fileblobSetFilename(fileblob *fb, const char *dir, const char *filename)
{
    char *fullname;

    if(fb->b.name)
        return;

    assert(filename != NULL);
    assert(dir != NULL);

    blobSetFilename(&fb->b, dir, filename);

    /*
     * Reload the filename, it may be different from the one we've
     * asked for, e.g. '/'s taken out
     */
    filename = blobGetFilename(&fb->b);

    assert(filename != NULL);

    if (cli_gentempfd(dir, &fullname, &fb->fd)!=CL_SUCCESS) return;

    cli_dbgmsg("fileblobSetFilename: file %s saved to %s\n", filename, fullname);

    fb->fp = fdopen(fb->fd, "wb");

    if(fb->fp == NULL) {
        cli_errmsg("fileblobSetFilename: fdopen failed\n");
        close(fb->fd);
        free(fullname);
        return;
    }
    if(fb->b.data)
        if(fileblobAddData(fb, fb->b.data, fb->b.len) == 0) {
            free(fb->b.data);
            fb->b.data = NULL;
            fb->b.len = fb->b.size = 0;
            fb->isNotEmpty = 1;
        }
    fb->fullname = fullname;
}
示例#5
0
static int
tnef_attachment(fmap_t *map, off_t *pos, uint16_t type, uint16_t tag, int32_t length, const char *dir, fileblob **fbref, off_t fsize)
{
	uint32_t todo;
	uint16_t i16;
	off_t offset;
	char *string;

	cli_dbgmsg("attachment tag 0x%x, type 0x%x, length %d\n", tag, type,
		(int)length);

	offset = *pos;

	switch(tag) {
		case attATTACHTITLE:
			if(length <= 0)
				return -1;
			string = cli_malloc(length + 1);
			if(string == NULL) {
                cli_errmsg("tnef_attachment: Unable to allocate memory for string\n");
				return -1;
            }
			if(fmap_readn(map, string, *pos, (uint32_t)length) != (uint32_t)length) {
				free(string);
				return -1;
			}
			(*pos) += (uint32_t)length;
			string[length] = '\0';
			cli_dbgmsg("TNEF filename %s\n", string);
			if(*fbref == NULL) {
				*fbref = fileblobCreate();
				if(*fbref == NULL) {
					free(string);
					return -1;
				}
			}
			fileblobSetFilename(*fbref, dir, string);
			free(string);
			break;
		case attATTACHDATA:
			if(*fbref == NULL) {
				*fbref = fileblobCreate();
				if(*fbref == NULL)
					return -1;
			}
			todo = length;
			while(todo) {
			    unsigned char buf[BUFSIZ];
			    int32_t got = fmap_readn(map, buf, *pos, MIN(sizeof(buf), todo));
			    if (got <= 0)
				break;
			    (*pos) += got;

			    fileblobAddData(*fbref, buf, got);
			    todo -= got;
			}
			break;
		default:
			cli_dbgmsg("TNEF - unsupported attachment tag 0x%x type 0x%d length %d\n",
				tag, type, (int)length);
			break;
	}

	/*cli_dbgmsg("%lu %lu\n", (long)(offset + length), ftell(fp));*/

	if(!CLI_ISCONTAINED2(0, fsize, (off_t)offset, (off_t)length)) {
		cli_dbgmsg("TNEF: Incorrect length field in tnef_attachment\n");
		return -1;
	}
	(*pos) = (long)(offset + length);	/* shouldn't be needed */

	(*pos) += 2;

	return 0;
}