static void writeobject(int num, int gen) { fz_error error; fz_obj *obj; fz_obj *type; error = pdf_loadobject(&obj, xref, num, gen); if (error) die(error); /* skip ObjStm and XRef objects */ if (fz_isdict(obj)) { type = fz_dictgets(obj, "Type"); if (fz_isname(type) && !strcmp(fz_toname(type), "ObjStm")) { uselist[num] = 0; fz_dropobj(obj); return; } if (fz_isname(type) && !strcmp(fz_toname(type), "XRef")) { uselist[num] = 0; fz_dropobj(obj); return; } } if (!pdf_isstream(xref, num, gen)) { fprintf(out, "%d %d obj\n", num, gen); fz_fprintobj(out, obj, !doexpand); fprintf(out, "endobj\n\n"); } else { if (doexpand && !pdf_isjpximage(obj)) expandstream(obj, num, gen); else copystream(obj, num, gen); } fz_dropobj(obj); }
static void writeobject(int num, int gen) { fz_obj *obj; fz_obj *type; obj = pdf_load_object(xref, num, gen); /* skip ObjStm and XRef objects */ if (fz_is_dict(obj)) { type = fz_dict_gets(obj, "Type"); if (fz_is_name(type) && !strcmp(fz_to_name(type), "ObjStm")) { uselist[num] = 0; fz_drop_obj(obj); return; } if (fz_is_name(type) && !strcmp(fz_to_name(type), "XRef")) { uselist[num] = 0; fz_drop_obj(obj); return; } } if (!pdf_is_stream(xref, num, gen)) { fprintf(out, "%d %d obj\n", num, gen); fz_fprint_obj(out, obj, doexpand == 0); fprintf(out, "endobj\n\n"); } else { int dontexpand = 0; if (doexpand != 0 && doexpand != expand_all) { fz_obj *o; if ((o = fz_dict_gets(obj, "Type"), !strcmp(fz_to_name(o), "XObject")) && (o = fz_dict_gets(obj, "Subtype"), !strcmp(fz_to_name(o), "Image"))) dontexpand = !(doexpand & expand_images); if (o = fz_dict_gets(obj, "Type"), !strcmp(fz_to_name(o), "Font")) dontexpand = !(doexpand & expand_fonts); if (o = fz_dict_gets(obj, "Type"), !strcmp(fz_to_name(o), "FontDescriptor")) dontexpand = !(doexpand & expand_fonts); if ((o = fz_dict_gets(obj, "Length1")) != NULL) dontexpand = !(doexpand & expand_fonts); if ((o = fz_dict_gets(obj, "Length2")) != NULL) dontexpand = !(doexpand & expand_fonts); if ((o = fz_dict_gets(obj, "Length3")) != NULL) dontexpand = !(doexpand & expand_fonts); if (o = fz_dict_gets(obj, "Subtype"), !strcmp(fz_to_name(o), "Type1C")) dontexpand = !(doexpand & expand_fonts); if (o = fz_dict_gets(obj, "Subtype"), !strcmp(fz_to_name(o), "CIDFontType0C")) dontexpand = !(doexpand & expand_fonts); } if (doexpand && !dontexpand && !pdf_is_jpx_image(ctx, obj)) expandstream(obj, num, gen); else copystream(obj, num, gen); } fz_drop_obj(obj); }
/* Routine creates dead.letter */ void mkdead() { static char pn[] = "mkdead"; int aret; char *dotdead = &dead[1]; gid_t egid = getegid(); struct stat st; malf = (FILE *)NULL; /* Make certain that there's something to copy. */ if (!tmpf) return; /* Try to create dead letter in current directory or in home directory */ umask(umsave); setgid(getgid()); if ((aret = legal(dotdead)) && stat(dotdead, &st) == 0) malf = fopen(dotdead, "a"); if ((malf == NULL) || (aret == 0)) { /* try to create in $HOME */ if((hmdead = malloc(strlen(home) + strlen(dead) + 1)) == NULL) { fprintf(stderr, "%s: Can't malloc\n",program); Dout(pn, 0, "Cannot malloc.\n"); goto out; } cat(hmdead, home, dead); if ((aret=legal(hmdead)) && !(stat(hmdead, &st) < 0 && errno == EOVERFLOW)) malf = fopen(hmdead, "a"); if ((malf == NULL) || (aret == 0)) { fprintf(stderr, "%s: Cannot create %s\n", program,dotdead); Dout(pn, 0, "Cannot create %s\n", dotdead); out: fclose(tmpf); error = E_FILE; Dout(pn, 0, "error set to %d\n", error); umask(7); setegid(egid); return; } else { chmod(hmdead, DEADPERM); fprintf(stderr,"%s: Mail saved in %s\n",program,hmdead); } } else { chmod(dotdead, DEADPERM); fprintf(stderr,"%s: Mail saved in %s\n",program,dotdead); } /* Copy letter into dead letter box */ umask(7); aret = fseek(tmpf,0L,0); if (aret) errmsg(E_DEAD,""); if (!copystream(tmpf, malf)) errmsg(E_DEAD,""); fclose(malf); setegid(egid); }
static const response* message_end(int fd) { const char* hostname; const char* tmp; ipv4port cmdport; ipv4addr ips[MAX_IPS]; int ip_count; int i; int offset; int result; struct timeval tv; int sock; unsigned long timeout; unsigned long connect_timeout; unsigned long send_timeout; unsigned long maxsize; ibuf netin; obuf netout; struct stat st; if ((hostname = session_getenv("CLAMAV_HOST")) != 0 || (hostname = session_getenv("CLAMD_HOST")) != 0) { if (fstat(fd, &st) != 0) return &resp_internal; /* For simplicity, this plugin just sends a single chunk, but each * chunk is limited to 2^32 bytes by the protocol. */ if (st.st_size > 0xffffffffLL) { warn1("ClamAV scanning skipped: message larger than chunk size"); return 0; } if ((tmp = session_getenv("CLAMAV_MAXSIZE")) != 0 && (maxsize = strtoul(tmp, (char**)&tmp, 10)) != 0 && *tmp == 0) { if (st.st_size > (ssize_t)maxsize){ warn1("ClamAV scanning skipped: message larger than maximum"); return 0; } } if (((tmp = session_getenv("CLAMAV_PORT")) == 0 && (tmp = session_getenv("CLAMD_PORT")) == 0) || (cmdport = strtoul(tmp, (char**)&tmp, 10)) == 0 || *tmp != 0) cmdport = 3310; if (((tmp = session_getenv("CLAMAV_TIMEOUT")) == 0 && (tmp = session_getenv("CLAMD_TIMEOUT")) == 0) || (timeout = strtoul(tmp, (char**)&tmp, 10)) == 0 || *tmp != 0) timeout = 5000; if ((tmp = session_getenv("CLAMAV_CONNECT_TIMEOUT")) == 0 || (connect_timeout = strtoul(tmp, (char**)&tmp, 10)) == 0 || *tmp != 0) connect_timeout = timeout; if ((tmp = session_getenv("CLAMAV_SEND_TIMEOUT")) == 0 || (send_timeout = strtoul(tmp, (char**)&tmp, 10)) == 0 || *tmp != 0) send_timeout = timeout; if ((ip_count = resolve_ipv4name_n(hostname, ips, MAX_IPS)) <= 0) return &resp_no_hostname; gettimeofday(&tv, 0); offset = (tv.tv_sec ^ tv.tv_usec) % ip_count; for (i = 0; i < ip_count; ++i) { const ipv4addr* addr = &ips[(i + offset) % ip_count]; if (lseek(fd, 0, SEEK_SET) != 0) return &resp_internal; if ((sock = try_connect(addr, cmdport, connect_timeout)) < 0) continue; if (obuf_init(&netout, sock, 0, 0, 0)) { netout.io.timeout = send_timeout; result = obuf_puts(&netout, "nINSTREAM\n") && copystream(fd, st.st_size, &netout) && obuf_close(&netout); obuf_close(&netout); if (result) { if (ibuf_init(&netin, sock, 0, IOBUF_NEEDSCLOSE, 0)) { netin.io.timeout = timeout; result = ibuf_getstr(&netin, &line, LF); ibuf_close(&netin); sock = -1; if (result) { if (memcmp(line.s, "stream: ", 8) == 0) { str_lcut(&line, 8); str_rstrip(&line); if (str_diffs(&line, "OK") == 0) return 0; str_splices(&line, 0, 0, "5.7.0 Virus scan failed: "); resp_virus.message = line.s; return &resp_virus; } } } } } if (sock >= 0) close(sock); } } return &resp_no_scan; }