void getmess() { int match; if (slurpclose(0,&message,1024) == -1) die_read(); strnum[fmt_uint(strnum,message.len)] = 0; if (!stralloc_copys(&beforemessage,strnum)) nomem(); if (!stralloc_cats(&beforemessage,":")) nomem(); if (!stralloc_copys(&aftermessage,",")) nomem(); if (getln(&envelope,&line,&match,'\0') == -1) die_read(); if (!match) die_format(); if (line.len < 2) die_format(); if (line.s[0] != 'F') die_format(); strnum[fmt_uint(strnum,line.len - 2)] = 0; if (!stralloc_cats(&aftermessage,strnum)) nomem(); if (!stralloc_cats(&aftermessage,":")) nomem(); if (!stralloc_catb(&aftermessage,line.s + 1,line.len - 2)) nomem(); if (!stralloc_cats(&aftermessage,",")) nomem(); for (;;) { if (getln(&envelope,&line,&match,'\0') == -1) die_read(); if (!match) die_format(); if (line.len < 2) break; if (line.s[0] != 'T') die_format(); strnum[fmt_uint(strnum,line.len - 2)] = 0; if (!stralloc_cats(&aftermessage,strnum)) nomem(); if (!stralloc_cats(&aftermessage,":")) nomem(); if (!stralloc_catb(&aftermessage,line.s + 1,line.len - 2)) nomem(); if (!stralloc_cats(&aftermessage,",")) nomem(); } }
static void do_get(const char *action) { unsigned long u; struct stat st; char ch; int r; unsigned int pos; int fd; if (!flagget) strerr_die2x(100,FATAL,MSG(ERR_NOT_AVAILABLE)); hdr_subject(MSG(SUB_GET_MSG)); hdr_ctboundary(); copy(&qq,"text/top",flagcd); pos = str_len(ACTION_GET); if (!case_starts(action,ACTION_GET)) pos = str_len(ALT_GET); if (action[pos] == '.' || action [pos] == '_') pos++; scan_ulong(action + pos,&u); stralloc_copys(&line,"archive/"); stralloc_catb(&line,strnum,fmt_ulong(strnum,u / 100)); stralloc_cats(&line,"/"); stralloc_catb(&line,strnum,fmt_uint0(strnum,(unsigned int) (u % 100),2)); stralloc_0(&line); fd = open_read(line.s); if (fd == -1) if (errno != error_noent) strerr_die2sys(111,FATAL,MSG1(ERR_OPEN,line.s)); else copy_act("text/get-bad"); else { if (fstat(fd,&st) == -1) copy_act("text/get-bad"); else if (!(st.st_mode & 0100)) copy_act("text/get-bad"); else { showsend("get"); substdio_fdbuf(&sstext,read,fd,textbuf,sizeof(textbuf)); qmail_puts(&qq,"> "); for (;;) { r = substdio_get(&sstext,&ch,1); if (r == -1) strerr_die2sys(111,FATAL,MSG1(ERR_READ,line.s)); if (r == 0) break; qmail_put(&qq,&ch,1); if (ch == '\n') qmail_puts(&qq,"> "); } qmail_puts(&qq,"\n"); } close(fd); } copybottom(0); qmail_to(&qq,target.s); }
static void make_num(stralloc* out, size_t num, size_t width) { char fmt[FMT_ULONG + 1]; size_t sz = fmt_ulonglong(fmt, num); ssize_t n = width - sz; while(n-- > 0) { stralloc_catb(out, " ", 1); } stralloc_catb(out, fmt, sz); }
static int env_str(const char *env,const char *val) { if (envsa) { return env_val(env,val,str_len(val)); if (!stralloc_cats(envsa,env)) return 0; if (!stralloc_catb(envsa,"=",1)) return 0; if (!stralloc_catb(envsa,val,str_len(val) + 1)) return 0; return 1; } return pathexec_env(env,val); }
/* Checks the hash against the cookie table. If it matches, returns NULL, * else returns "". If error, returns error string. */ static const char *_checktag (struct subdbinfo *info, unsigned long num, /* message number */ unsigned long listno, /* bottom of range => slave */ const char *action, const char *seed, const char *hash) /* cookie */ { sqlite3_stmt *stmt; int res; /* SELECT msgnum FROM table_cookie WHERE msgnum=num and cookie='hash' */ /* succeeds only is everything correct. 'hash' is quoted since it is */ /* potentially hostile. */ if (listno) { /* only for slaves */ if (!stralloc_copys(&line,"SELECT listno FROM ")) die_nomem(); if (!stralloc_cats(&line,info->base_table)) die_nomem(); if (!stralloc_cats(&line,"_mlog WHERE listno=")) die_nomem(); if (!stralloc_catb(&line,strnum,fmt_ulong(strnum,listno))) die_nomem(); if (!stralloc_cats(&line," AND msgnum=")) die_nomem(); if (!stralloc_catb(&line,strnum,fmt_ulong(strnum,num))) die_nomem(); if (!stralloc_cats(&line," AND done > 3")) die_nomem(); if (!stralloc_0(&line)) die_nomem(); if ((stmt = _sqlquery(info, &line)) == NULL) return sqlite3_errmsg((sqlite3*)info->conn); /* query */ res = sqlite3_step(stmt); sqlite3_finalize(stmt); /* free res */ if (res == SQLITE_ROW) return ""; /*already done */ else if (res != SQLITE_DONE) return sqlite3_errmsg((sqlite3*)info->conn); } if (!stralloc_copys(&line,"SELECT msgnum FROM ")) die_nomem(); if (!stralloc_cats(&line,info->base_table)) die_nomem(); if (!stralloc_cats(&line,"_cookie WHERE msgnum=")) die_nomem(); if (!stralloc_catb(&line,strnum,fmt_ulong(strnum,num))) die_nomem(); if (!stralloc_cats(&line," and cookie='")) die_nomem(); if (!stralloc_catb(&line,strnum,fmt_str(strnum,hash))) die_nomem(); if (!stralloc_cats(&line,"'")) die_nomem(); if (!stralloc_0(&line)) die_nomem(); if ((stmt = _sqlquery(info, &line)) == NULL) /* select */ return sqlite3_errmsg((sqlite3*)info->conn); res = sqlite3_step(stmt); sqlite3_finalize(stmt); /* free res */ if (res == SQLITE_DONE) return ""; /* eof => query ok, but null result*/ else if (res != SQLITE_ROW) return sqlite3_errmsg((sqlite3*)info->conn); /* some error occurred */ return (char *)0; /* success! cookie matches */ (void)action; (void)seed; }
int string_quote (stralloc *sa, char const *s, unsigned int len) { unsigned int base = sa->len ; int wasnull = !sa->s ; if (!stralloc_catb(sa, "\"", 1)) return 0 ; if (!string_quote_nodelim(sa, s, len) || !stralloc_catb(sa, "\"", 1)) { if (wasnull) stralloc_free(sa) ; else sa->len = base ; return 0 ; } return 1 ; }
static int env_val(const char *env,const char *val,int len) { if (envsa) { if (!stralloc_cats(envsa,env)) return 0; if (!stralloc_catb(envsa,"=",1)) return 0; if (!stralloc_catb(envsa,val,len)) return 0; if (!stralloc_0(envsa)) return 0; return 1; } if (!stralloc_copyb(&etemp,val,len)) return 0; if (!stralloc_0(&etemp)) return 0; return pathexec_env(env,etemp.s); }
/* Searches the subscriber log and outputs via subwrite(s,len) any entry * that matches search. A '_' is search is a wildcard. Any other * non-alphanum/'.' char is replaced by a '_'. */ static void _searchlog(struct subdbinfo *info, const char *table, char *search, /* search string */ int subwrite()) /* output fxn */ { sqlite3_stmt *stmt; int res; datetime_sec when; struct datetime dt; char date[DATE822FMT]; /* SELECT (*) FROM list_slog WHERE fromline LIKE '%search%' OR address */ /* LIKE '%search%' ORDER BY tai; */ /* The '*' is formatted to look like the output of the non-mysql version */ /* This requires reading the entire table, since search fields are not */ /* indexed, but this is a rare query and time is not of the essence. */ if (!stralloc_copys(&line,"SELECT tai, edir||etype||' '||address||' '||fromline" " FROM ")) die_nomem(); if (!stralloc_cat_table(&line,info,table)) die_nomem(); if (!stralloc_cats(&line,"_slog")) die_nomem(); if (*search) { /* We can afford to wait for LIKE '%xx%' */ if (!stralloc_cats(&line," WHERE fromline LIKE '%")) die_nomem(); if (!stralloc_cats(&line,search)) die_nomem(); if (!stralloc_cats(&line,"%' OR address LIKE '%")) die_nomem(); if (!stralloc_cats(&line,search)) die_nomem(); if (!stralloc_cats(&line,"%'")) die_nomem(); } /* ordering by tai which is an index */ if (!stralloc_cats(&line," ORDER by tai")) die_nomem(); if (!stralloc_0(&line)) die_nomem(); if ((stmt = _sqlquery(info, &line)) == NULL) strerr_die2x(111,FATAL,sqlite3_errmsg((sqlite3*)info->conn)); while ((res = sqlite3_step(stmt)) != SQLITE_DONE) { if (res != SQLITE_ROW) strerr_die2x(111,FATAL,sqlite3_errmsg((sqlite3*)info->conn)); (void)scan_ulong((const char*)sqlite3_column_text(stmt,0),&when); datetime_tai(&dt,when); if (!stralloc_copyb(&line,date,date822fmt(date,&dt)-1)) die_nomem(); if (!stralloc_cats(&line,": ")) die_nomem(); if (!stralloc_catb(&line,strnum,fmt_ulong(strnum,when))) die_nomem(); if (!stralloc_cats(&line," ")) die_nomem(); if (!stralloc_catb(&line, (const char*)sqlite3_column_text(stmt,1), sqlite3_column_bytes(stmt,1))) die_nomem(); if (subwrite(line.s,line.len) == -1) die_write(); } sqlite3_finalize(stmt); }
int ftrig1_make (ftrig1 *f, char const *path) { ftrig1 ff = FTRIG1_ZERO ; unsigned int pathlen = str_len(path) ; int e = 0 ; char tmp[pathlen + 46 + FTRIG1_PREFIXLEN] ; byte_copy(tmp, pathlen, path) ; tmp[pathlen] = '/' ; tmp[pathlen+1] = '.' ; byte_copy(tmp + pathlen + 2, FTRIG1_PREFIXLEN, FTRIG1_PREFIX) ; tmp[pathlen + 2 + FTRIG1_PREFIXLEN] = ':' ; if (!timestamp(tmp + pathlen + 3 + FTRIG1_PREFIXLEN)) return 0 ; tmp[pathlen + 28 + FTRIG1_PREFIXLEN] = ':' ; if (random_name(tmp + pathlen + 29 + FTRIG1_PREFIXLEN, 16) < 16) return 0 ; tmp[pathlen + 45 + FTRIG1_PREFIXLEN] = 0 ; { mode_t m = umask(0) ; if (fifo_make(tmp, S_IRUSR|S_IWUSR|S_IWGRP|S_IWOTH) == -1) { umask(m) ; return 0 ; } umask(m) ; } if (!stralloc_catb(&ff.name, tmp, pathlen+1)) { e = errno ; goto err0 ; } if (!stralloc_catb(&ff.name, tmp + pathlen + 2, FTRIG1_PREFIXLEN + 44)) { e = errno ; goto err1 ; } ff.fd = open_read(tmp) ; if (ff.fd == -1) { e = errno ; goto err1 ; } ff.fdw = open_write(tmp) ; if (ff.fdw == -1) { e = errno ; goto err2 ; } if (rename(tmp, ff.name.s) == -1) goto err3 ; *f = ff ; return 1 ; err3: e = errno ; fd_close(ff.fdw) ; err2: fd_close(ff.fd) ; err1: stralloc_free(&ff.name) ; err0: unlink(tmp) ; errno = e ; return 0 ; }
int dns_ip6_4mapped(stralloc *out,stralloc *fqdn) { stralloc tmp={0}; int i; int result=dns_ip4(&tmp,fqdn); if (result==0) { for (i = 0;i + 4 <= tmp.len;i += 4) { stralloc_catb(out,(char *)V4mappedprefix,12); stralloc_catb(out,tmp.s + i,4); } alloc_free(tmp.s); return 0; } return -1; }
int dns_domain_todot_cat(stralloc *out,const char *d) { char ch; char ch2; unsigned char ch3; char buf[4]; if (!*d) return stralloc_append(out,"."); for (;;) { ch = *d++; while (ch--) { ch2 = *d++; if ((ch2 >= 'A') && (ch2 <= 'Z')) ch2 = (char)(ch2 + 32); if (((ch2 >= 'a') && (ch2 <= 'z')) || ((ch2 >= '0') && (ch2 <= '9')) || (ch2 == '-') || (ch2 == '_')) { if (!stralloc_append(out,&ch2)) return 0; } else { ch3 = (unsigned char)ch2; buf[3] = (char)('0' + (ch3 & 7)); ch3 >>= 3; buf[2] = (char)('0' + (ch3 & 7)); ch3 >>= 3; buf[1] = (char)('0' + (ch3 & 7)); buf[0] = '\\'; if (!stralloc_catb(out,buf,4)) return 0; } } if (!*d) return 1; if (!stralloc_append(out,".")) return 0; } }
int tdlookup_init(void) { char *x; char ch; int i; int j; int k; x = env_get("LAME_A"); if (x) if (!ip4_scan(x,lameip)) byte_zero(lameip,4); x = env_get("LAME_MX"); if (x) if (!dns_domain_fromdot(&lamemx,x,str_len(x))) return 0; x = env_get("LAME_TXT"); if (x) { i = 0; j = str_len(x); while (i < j) { k = j - i; if (k > 255) k = 255; ch = k; if (!stralloc_append(&lametxt,&ch)) return 0; if (!stralloc_catb(&lametxt,x + i,k)) return 0; i += k; } } return 1; }
int stralloc_copyb(stralloc *r, const void *xv, long long xlen) { if (!r) { errno = EINVAL; return 0; } r->len = 0; return stralloc_catb(r, xv, xlen); }
void doname(stralloc *sa) { static char *d; dpos = dns_packet_getname(data,dlen,dpos,&d); if (!dpos) die_cdbread(); if (!stralloc_catb(sa,d,dns_domain_length(d))) nomem(); }
int main (int argc, char const *const *argv) { stralloc sa = STRALLOC_ZERO ; unsigned int n = 8 ; PROG = "s6-uniquename" ; { subgetopt_t l = SUBGETOPT_ZERO ; for (;;) { register int opt = subgetopt_r(argc, argv, "n:", &l) ; if (opt == -1) break ; switch (opt) { case 'n' : if (!uint0_scan(l.arg, &n)) usage() ; break ; default : usage() ; } } argc -= l.ind ; argv += l.ind ; } if (argc < 1) usage() ; if (!stralloc_cats(&sa, argv[0])) strerr_diefu1sys(111, "stralloc_cats") ; if ((n ? random_sauniquename(&sa, n) : sauniquename(&sa)) < 0) strerr_diefu1sys(111, "make unique name") ; if (!stralloc_catb(&sa, "\n", 1)) strerr_diefu1sys(111, "stralloc_cats") ; if (allwrite(1, sa.s, sa.len) < sa.len) strerr_diefu1sys(111, "write to stdout") ; return 0 ; }
int dns_ip4_packet(stralloc *out,const char *buf,unsigned int len) { unsigned int pos; char header[12]; uint16 numanswers; uint16 datalen; if (!stralloc_copys(out,"")) return -1; pos = dns_packet_copy(buf,len,0,header,12); if (!pos) return -1; uint16_unpack_big(header + 6,&numanswers); pos = dns_packet_skipname(buf,len,pos); if (!pos) return -1; pos += 4; while (numanswers--) { pos = dns_packet_skipname(buf,len,pos); if (!pos) return -1; pos = dns_packet_copy(buf,len,pos,header,10); if (!pos) return -1; uint16_unpack_big(header + 8,&datalen); if (byte_equal(header,2,DNS_T_A)) if (byte_equal(header + 2,2,DNS_C_IN)) if (datalen == 4) { if (!dns_packet_copy(buf,len,pos,header,4)) return -1; if (!stralloc_catb(out,header,4)) return -1; } pos += datalen; } dns_sortip(out->s,out->len); return 0; }
int dateline(stralloc *dt, unsigned long d) /* converts yyyymm from unsigned long d to text dt */ { const char *mo; switch (d % 100) { case 1: mo = "January"; break; case 2: mo = "February"; break; case 3: mo = "March"; break; case 4: mo = "April"; break; case 5: mo = "May"; break; case 6: mo = "June"; break; case 7: mo = "July"; break; case 8: mo = "August"; break; case 9: mo = "September"; break; case 10: mo = "October"; break; case 11: mo = "November"; break; case 12: mo = "December"; break; case 0: mo = "????"; break; default: cgierr("I don't know any month > 12", "",""); } if (!stralloc_copys(dt,mo)) return -1; if (!stralloc_cats(dt," ")) return -1; if ((d/100)) { if (!stralloc_catb(dt,strnum,fmt_ulong(strnum,d/100))) return -1; } else if (!stralloc_cats(dt,"????")) return 0; return 1; }
int dns_mx_packet(stralloc *out,const char *buf,unsigned int len) { unsigned int pos; char header[12]; char pref[2]; uint16 numanswers; uint16 datalen; if (!stralloc_copys(out,"")) return -1; pos = dns_packet_copy(buf,len,0,header,12); if (!pos) return -1; uint16_unpack_big(header + 6,&numanswers); pos = dns_packet_skipname(buf,len,pos); if (!pos) return -1; pos += 4; while (numanswers--) { pos = dns_packet_skipname(buf,len,pos); if (!pos) return -1; pos = dns_packet_copy(buf,len,pos,header,10); if (!pos) return -1; uint16_unpack_big(header + 8,&datalen); if (byte_equal(header,2,DNS_T_MX)) if (byte_equal(header + 2,2,DNS_C_IN)) { if (!dns_packet_copy(buf,len,pos,pref,2)) return -1; if (!dns_packet_getname(buf,len,pos + 2,&q)) return -1; if (!stralloc_catb(out,pref,2)) return -1; if (!dns_domain_todot_cat(out,q)) return -1; if (!stralloc_0(out)) return -1; } pos += datalen; } return 0; }
static int decode_srs(const char *s) { /* Format: [email protected] */ /* Format: [email protected] */ char sep; int at; int sep1; int sep2; if ((sep = *s++) == 0) return 0; if (s[at = str_rchr(s,'@')] == 0) return 0; for (sep2 = at - 1; sep2 > 1 && s[sep2] != '='; sep2--) ; /* s+sep2 = "=USER@..." */ for (sep1 = sep2 - 1; sep1 > 1 && s[sep1] != '='; sep1--) ; /* s+sep1 = "=DOMAIN=USER@..." */ if (sep2 <= 0) return 0; ++sep1; ++sep2; if (!stralloc_copyb(&realsender,s+sep2,at-sep2)) die_nomem(); if (!stralloc_append(&realsender,"@")) die_nomem(); if (!stralloc_catb(&realsender,s+sep1,sep2-sep1-1)) die_nomem(); if (!stralloc_0(&realsender)) die_nomem(); return 1; }
void mkauthhash(const char *s,unsigned int len,char *h) /* This is a string that should be the same for all messages from a given */ /* author. Doesn't have to be the real rfc822 address. We look for a '@' */ /* and grab everything up to the next '>', ' ', or ';'. We go back the same */ /* way, then take everything up to the '@' or the first '-'. The latter */ /* avoids problems with posters that band their addresses. */ { unsigned int i,j,k,l; char ch; j = k = l = 0; i = byte_rchr(s,len,'@'); if (i < len) { /* if not then i=sa->len, j=k=l=0 */ j = i; while (++j < len) { /* if not found, then j=sa->len */ ch = s[j]; if (ch == '>' || ch == ' ' || ch == ';') break; } k = i; while (k > 0) { /* k <= i */ ch = s[--k]; if (ch == '<' || ch == ' ' || ch == ';') break; } l = k; /* k <= l <= i; */ while (l < i && s[l] != '-') ++l; if (!stralloc_copyb(&dummy,s + k, l - k)) die_nomem(); if (!stralloc_catb(&dummy,s + i, j - i)) die_nomem(); makehash(dummy.s,dummy.len,h); } else /* use entire line if no '@' found */ makehash(s,len,h); }
int main (int argc, char const *const *argv) { stralloc sa = STRALLOC_ZERO ; int nl = 1 ; PROG = "s6-dirname" ; { subgetopt_t l = SUBGETOPT_ZERO ; for (;;) { register int opt = subgetopt_r(argc, argv, "n", &l) ; if (opt == -1) break ; switch (opt) { case 'n' : nl = 0 ; break ; default : strerr_dieusage(100, USAGE) ; } } argc -= l.ind ; argv += l.ind ; } if (!argc) strerr_dieusage(100, USAGE) ; if (!sadirname(&sa, argv[0], str_len(argv[0]))) strerr_diefu2sys(111, "get dirname of ", argv[0]) ; if (nl && !stralloc_catb(&sa, "\n", 1)) strerr_diefu2sys(111, "get dirname of ", argv[0]) ; if (allwrite(1, sa.s, sa.len) < sa.len) strerr_diefu1sys(111, "write to stdout") ; return 0 ; }
static int enable_service (const char *name, intptr_t from_next) { int offset; int r; int i; if (*name == '/') cur_name = name + byte_rchr (name, strlen (name), '/') + 1; else cur_name = name; if (!from_next) { /* check if it was already added to be done next (via auto-enable), in * which case we need to remove it. * We do this instead of simply skipping it and having it done later * because: * - if there's a folder here, we want to use it as config folder * - in upgrade mode, the auto-added are treated differently, so * anything specified needs to be treated now (even w/out folder) */ for (i = 0; i < genalloc_len (int, &ga_next); ++i) if (str_equal (cur_name, names.s + list_get (&ga_next, i))) { offset = list_get (&ga_next, i); ga_remove (int, &ga_next, i); goto process; } offset = names.len; stralloc_catb (&names, cur_name, strlen (cur_name) + 1); }
/* This routine inserts the cookie into table_cookie. We log arrival of * the message (done=0). */ static void _tagmsg(struct subdbinfo *info, unsigned long msgnum, /* number of this message */ const char *hashout, /* previously calculated hash */ unsigned long bodysize, unsigned long chunk) { sqlite3_stmt *stmt; const char *ret; int res; if (chunk >= 53L) chunk = 0L; /* sanity */ /* INSERT INTO table_cookie (msgnum,cookie) VALUES (num,cookie) */ /* (we may have tried message before, but failed to complete, so */ /* ER_DUP_ENTRY is ok) */ if (!stralloc_copys(&line,"INSERT INTO ")) die_nomem(); if (!stralloc_cats(&line,info->base_table)) die_nomem(); if (!stralloc_cats(&line,"_cookie (msgnum,tai,cookie,bodysize,chunk) VALUES (")) die_nomem(); if (!stralloc_catb(&line,strnum,fmt_ulong(strnum,msgnum))) die_nomem(); if (!stralloc_cats(&line,",")) die_nomem(); if (!stralloc_catb(&line,strnum,fmt_ulong(strnum,now()))) die_nomem(); if (!stralloc_cats(&line,",'")) die_nomem(); if (!stralloc_catb(&line,hashout,COOKIE)) die_nomem(); if (!stralloc_cats(&line,"',")) die_nomem(); if (!stralloc_catb(&line,strnum,fmt_ulong(strnum,bodysize))) die_nomem(); if (!stralloc_cats(&line,",")) die_nomem(); if (!stralloc_catb(&line,strnum,fmt_ulong(strnum,chunk))) die_nomem(); if (!stralloc_cats(&line,")")) die_nomem(); if (!stralloc_0(&line)) die_nomem(); if ((stmt = _sqlquery(info, &line)) == NULL) strerr_die2x(111,FATAL,sqlite3_errmsg((sqlite3*)info->conn)); res = sqlite3_step(stmt); sqlite3_finalize(stmt); if (res != SQLITE_DONE) { if (res != SQLITE_CONSTRAINT) /* ignore dups */ strerr_die2x(111,FATAL,sqlite3_errmsg((sqlite3*)info->conn)); /* cookie query */ } if (! (ret = logmsg(msgnum,0L,0L,1))) return; /* log done=1*/ if (*ret) strerr_die2x(111,FATAL,ret); }
void doheaders(void) { int flaggoodfield,match; if (act == AC_DIGEST) copy(&qq,"headeradd",'H'); hdr_add2s("Mailing-List: ",MSG(TXT_MAILING_LIST)); if (listid.len > 0) hdr_add2("List-ID: ",listid.s,listid.len); hdr_datemsgid(when); hdr_from("-help"); if (!stralloc_copys(&mydtline,"Delivered-To: responder for ")) die_nomem(); if (!stralloc_catb(&mydtline,outlocal.s,outlocal.len)) die_nomem(); if (!stralloc_cats(&mydtline,"@")) die_nomem(); if (!stralloc_catb(&mydtline,outhost.s,outhost.len)) die_nomem(); if (!stralloc_cats(&mydtline,"\n")) die_nomem(); qmail_put(&qq,mydtline.s,mydtline.len); flaggoodfield = 0; if (act != AC_DIGEST) for (;;) { if (getln(&ssin,&line,&match,'\n') == -1) strerr_die2sys(111,FATAL,MSG(ERR_READ_INPUT)); if (!match) break; if (line.len == 1) break; if ((line.s[0] != ' ') && (line.s[0] != '\t')) { flaggoodfield = 0; if (case_startb(line.s,line.len,"mailing-list:")) { if (flageditor) /* we may be running from a sublist */ flaggoodfield = 0; else strerr_die2x(100,FATAL,MSG(ERR_MAILING_LIST)); } if (line.len == mydtline.len) if (byte_equal(line.s,line.len,mydtline.s)) strerr_die2x(100,FATAL,MSG(ERR_LOOPING)); if (case_startb(line.s,line.len,"delivered-to:")) flaggoodfield = 1; if (case_startb(line.s,line.len,"received:")) flaggoodfield = 1; } if (flaggoodfield) qmail_put(&qq,line.s,line.len); } }
int dns_domain_prependb2(char **out, const char *d, const char *s1, unsigned int n1, const char *s2, unsigned int n2) { static stralloc sa; if (!stralloc_copyb(&sa, s1, n1)) return 0; if (s2 && n2) if (!stralloc_catb(&sa, s2, n2)) return 0; if (!dns_domain_todot_cat(&sa, d)) return 0; if (!dns_domain_fromdot(out, sa.s, sa.len)) return 0; return 1; }
int aa_add_name (const char *name) { int offset = aa_names.len; if (!stralloc_catb (&aa_names, name, strlen (name) + 1)) return -1; return offset; }
int main(int argc, const char ** argv ) { cmd = (char*) *argv++; --argc; section = (char*) *argv++; --argc; manual = (char*) *argv++; --argc; stralloc tempCMD1 = {0}; tempCMD1 = generateSearchCMD( manual,tempCMD1); int fd[2]; pipe(fd); int status; pid_t child; if ( (child = fork() ) < 0 ) { return 0; } else if( child == 0 ) { dup2(fd[1],1); close(fd[0]); close(fd[1]); system(tempCMD1.s); stralloc_free(&tempCMD1); exit(255); } else { stralloc tempCMD2 = {0}; ssize_t nbytes; char buff[64]; close(fd[1]); while(( nbytes = read(fd[0] , buff , sizeof buff )) > 0 ) { stralloc_catb( &tempCMD2 , buff , nbytes ); }; stralloc temp = {0}; stralloc_copys( &temp , cmdCAT ); stralloc_cat( &temp , &tempCMD2 ); char *t = temp.s; printManual(t); stralloc_free(&tempCMD2); stralloc_free(&temp); } close(fd[0]); close(fd[1]); wait(&status); return 0; }
/* Creates an entry for message num and the list listno and code "done". * Returns NULL on success, and the error string on error. */ static const char *_logmsg(struct subdbinfo *info, unsigned long num, unsigned long listno, unsigned long subs, int done) { sqlite3_stmt *stmt; int res; if (!stralloc_copys(&logline,"INSERT INTO ")) die_nomem(); if (!stralloc_cats(&logline,info->base_table)) die_nomem(); if (!stralloc_cats(&logline,"_mlog (msgnum,listno,tai,subs,done) VALUES (")) die_nomem(); if (!stralloc_catb(&logline,strnum,fmt_ulong(strnum,num))) die_nomem(); if (!stralloc_cats(&logline,",")) die_nomem(); if (!stralloc_catb(&logline,strnum,fmt_ulong(strnum,listno))) die_nomem(); if (!stralloc_cats(&line,",")) die_nomem(); if (!stralloc_catb(&line,strnum,fmt_ulong(strnum,now()))) die_nomem(); if (!stralloc_cats(&line,",'")) die_nomem(); if (!stralloc_catb(&logline,strnum,fmt_ulong(strnum,subs))) die_nomem(); if (!stralloc_cats(&logline,",")) die_nomem(); if (done < 0) { done = - done; if (!stralloc_append(&logline,"-")) die_nomem(); } if (!stralloc_catb(&logline,strnum,fmt_uint(strnum,done))) die_nomem(); if (!stralloc_append(&logline,")")) die_nomem(); if (!stralloc_0(&logline)) die_nomem(); if ((stmt = _sqlquery(info, &logline)) == NULL) /* log query */ return sqlite3_errmsg((sqlite3*)info->conn); res = sqlite3_step(stmt); sqlite3_finalize(stmt); if (res != SQLITE_DONE) { if (res != SQLITE_CONSTRAINT) /* ignore dups */ return sqlite3_errmsg((sqlite3*)info->conn); } return 0; }
int s6dns_message_parse_answer_a (s6dns_message_rr_t const *rr, char const *packet, unsigned int packetlen, unsigned int pos, unsigned int section, void *stuff) { if ((section == 2) && (rr->rtype == S6DNS_T_A) && (rr->rdlength == 4)) { stralloc *data = stuff ; if (!stralloc_catb(data, packet+pos, 4)) return -1 ; } (void)packetlen ; return 1 ; }
static int init2(DIR *dir) { direntry *d; const char *fqdn; static char *q; static stralloc text; char servers[64]; int serverslen; int i; int j; for (;;) { errno = 0; d = readdir(dir); if (!d) { if (errno) return 0; return 1; } if (d->d_name[0] != '.') { if (openreadclose(d->d_name,&text,32) != 1) return 0; if (!stralloc_append(&text,"\n")) return 0; fqdn = d->d_name; if (str_equal(fqdn,"@")) fqdn = "."; if (!dns_domain_fromdot(&q,fqdn,str_len(fqdn))) return 0; serverslen = 0; j = 0; for (i = 0;i < text.len;++i) if (text.s[i] == '\n') { if (serverslen <= 60) if (ip4_scan(text.s + j,servers + serverslen)) serverslen += 4; j = i + 1; } byte_zero(servers + serverslen,64 - serverslen); if (!stralloc_catb(&data,q,dns_domain_length(q))) return 0; if (!stralloc_catb(&data,servers,64)) return 0; } } }