Пример #1
0
void didentd_init()
{
  char *x;
  unsigned long id;

  x = env_get("ROOT");
  if (!x)
     strerr_die2x(111,FATAL,"$ROOT not set");
  if (chdir(x) == -1)
    strerr_die4sys(111,FATAL,"unable to chdir to ",x,": ");

  x = env_get("GID");
  if (!x)
    strerr_die2x(111,FATAL,"$GID not set");
  scan_ulong(x,&id);
  if (prot_gid((int) id) == -1)
    strerr_die2sys(111,FATAL,"unable to setgid: ");

  x = env_get("UID");
  if (!x)
    strerr_die2x(111,FATAL,"$UID not set");
  scan_ulong(x,&id);
  if (prot_uid((int) id) == -1)
    strerr_die2sys(111,FATAL,"unable to setuid: ");
}
Пример #2
0
static void do_list(int act)
{
  unsigned int i;
  if (!flaglist || (modsub.s == 0 && remote.s == 0))
    strerr_die2x(100,FATAL,MSG(ERR_NOT_AVAILABLE));
  if (!ismod)
    strerr_die2x(100,FATAL,MSG(ERR_NOT_ALLOWED));
  hdr_subject(MSG(SUB_LIST));
  hdr_ctboundary();
  copy(&qq,"text/top",flagcd);

  if (act == AC_LIST) {
    showsend("list");
    (void) code_qputs("");
    (void) code_qputs(MSG(TXT_LISTMEMBERS));
    (void) code_qputs("\n");
    i = putsubs(workdir,0L,52L,code_subto);
  } else {			/* listn */
    showsend("listn");
    i = putsubs(workdir,0L,52L,dummy_to);
  }
  (void) code_qput("\n  ======> ",11);
  (void) code_qput(strnum,fmt_ulong(strnum,i));
  (void) code_qput("\n",1);
  copybottom(0);
  qmail_to(&qq,mod.s);
}
Пример #3
0
void didentd_init()
{
  /* chroot() to /proc/net/ and switch to $UID:$GID */
  char *x;
  unsigned long id;

  if (chdir("/proc/net/") == -1)
    strerr_die2sys(111,FATAL,"unable to chdir to '/proc/net/': ");
  if (chroot(".") == -1)
    strerr_die2sys(111,FATAL,"unable to chdir to '/proc/net/': ");

  x = env_get("GID");
  if (!x)
    strerr_die2x(111,FATAL,"$GID not set");
  scan_ulong(x,&id);
  if (prot_gid((int) id) == -1)
    strerr_die2sys(111,FATAL,"unable to setgid: ");

  x = env_get("UID");
  if (!x)
    strerr_die2x(111,FATAL,"$UID not set");
  scan_ulong(x,&id);
  if (prot_uid((int) id) == -1)
    strerr_die2sys(111,FATAL,"unable to setuid: ");
}
Пример #4
0
int geton(const char *action)
{
  const char *fl;
  int r;
  unsigned int i;
  unsigned char ch;

  fl = get_from(target.s,action);		/* try to match up */
  r = subscribe(workdir,target.s,1,fl,(*action == ACTION_RC[0]) ? "+mod" : "+",-1);
  if (flagdig == FLD_DENY || flagdig == FLD_ALLOW)
    strerr_die2x(0,INFO,MSG1(ERR_EXTRA_SUB,target.s));
  switch (r) {
    case 1:
	    qmail_puts(&qq,"List-Unsubscribe: <mailto:");	/*rfc2369 */
	    qmail_put(&qq,outlocal.s,outlocal.len);
	    qmail_puts(&qq,"-unsubscribe-");
		/* url-encode since verptarget is controlled by sender */
		/* note &verptarget ends in '\0', hence len - 1! */
	    for (i = 0; i < verptarget.len - 1; i++) {
	      ch = verptarget.s[i];
	      if (str_chr("\"?;<>&/:%+#",ch) < 10 ||
			 (ch <= ' ') || (ch & 0x80)) {
		urlstr[1] = hex[ch / 16];
	        urlstr[2] = hex[ch & 0xf];
		qmail_put(&qq,urlstr,3);
	      } else {
		qmail_put(&qq,verptarget.s + i, 1);
	      }
	    }
	    qmail_puts(&qq,"@");
	    qmail_put(&qq,outhost.s,outhost.len);	/* safe */
	    qmail_puts(&qq,">\n");
	    hdr_subject(MSG(SUB_WELCOME));
            hdr_ctboundary();
	    stralloc_copy(&confirm,&outlocal);
	    stralloc_cats(&confirm,"-unsubscribe-");
	    stralloc_cats(&confirm,verptarget.s);
	    stralloc_append(&confirm,'@');
	    stralloc_cat(&confirm,&outhost);
	    stralloc_0(&confirm);
	    set_cpconfirm(confirm.s,outlocal.len);	/* for !R in copy */
            copy(&qq,"text/top",flagcd);
            copy_act("text/sub-ok");
            break;
    default:
            if (str_start(action,ACTION_TC))
              strerr_die2x(0,INFO,MSG(ERR_SUB_NOP));
	    hdr_subject(MSG(SUB_SUBSCRIBE_NOP));
            hdr_ctboundary();
            copy(&qq,"text/top",flagcd);
            copy_act("text/sub-nop");
            break;
  }
  return r;
}
Пример #5
0
/* 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);
}
Пример #6
0
void main(int argc,char **argv)
{
  char *def;
  int opt;
  int dash;
  
  while ((opt = getopt(argc,argv,"vV")) != opteof)
    switch (opt) {
    case 'v':
    case 'V':
      strerr_die2x(0, "ezmlm-dispatch version: ",auto_version);
    default:
      die_usage();
    }

  if (argv[optind] == 0)
    die_usage();
  wrap_chdir(argv[optind]);
  if (!stralloc_copys(&basedir,argv[optind++])) die_nomem();

  sender = env_get("SENDER");
  if (!sender)
    strerr_die2x(100,FATAL,ERR_NOSENDER);
  def = env_get("DEFAULT");

  if (argv[optind] != 0) {
    wrap_chdir(argv[optind]);
    dispatch(argv[optind],def);
  }
  else if (!def || !*def)
    strerr_die2x(100,FATAL,ERR_NODEFAULT);
  else {
    if (def[str_chr(def,'/')] != 0)
      strerr_die2x(100,FATAL,"Recipient address may not contain '/'");

    if (chdir(def) == 0)
      dispatch(def,0);

    dash = str_len(def);
    for (;;) {
      while (--dash > 0)
	if (def[dash] == '-')
	  break;
      if (dash <= 0)
	break;
      def[dash] = 0;
      if (chdir(def) == 0)
	dispatch(def,def+dash+1);
      def[dash] = '-';
    }
    strerr_die3x(100,FATAL,"Could not match recipient name to any list: ",def);
  }
}
Пример #7
0
/*
void show(const char *desc, stralloc *s)
{
  buffer_puts(buffer_2,desc);
  buffer_puthex(buffer_2,s->s,s->len);
  buffer_putsflush(buffer_2,"\n");
}
*/
int main(int argc, char * argv[])
{
    int r;
    const char* pk0;
    const char* sk0;

    /* Check args */
    pk0 = ((argc<2) ? env_get("NACL_PUBLICKEY_FILE") : argv[1]);
    sk0 = ((argc<3) ? env_get("NACL_SECRETKEY_FILE") : argv[2]);

    if(pk0==0 || sk0==0)
        strerr_die1x(100,"crypto-box: usage: crypto-box [ publickeyfile ] [ secretkeyfile ]");

    /* Read public key */
    if(openreadclose(argv[1],&pk,crypto_box_PUBLICKEYBYTES)<=0)
        strerr_die2sys(111,FATAL,"unable to read public key: ");

    /* Read secret key */
    if(openreadclose(argv[2],&sk,crypto_box_SECRETKEYBYTES)<=0)
        strerr_die2sys(111,FATAL,"unable to read secret key: ");

    /* Create shared key */
    if(crypto_str_box_beforenm(&k,&pk,&sk))
        strerr_die2x(111,FATAL,"failed to create shared-key");

    /* Decrypt each chunk */
    for (;;) {

        /* Read nonce */
        if((r=netstring_read(buffer_0,&n))!=0)
            strerr_die2x(111,FATAL,"failed to read nonce");
        if(n.len==0) break;
        if(n.len!=crypto_box_NONCEBYTES)
            strerr_die2x(111,FATAL,"nonce was incorrect size");

        /* Read cipher */
        if(netstring_read(buffer_0,&c)!=0)
            strerr_die2x(111,FATAL,"failed to read cipher");

        /* Decrypt message */
        if(crypto_str_box_open_afternm(&m,&c,&n,&k)!=0)
            strerr_die2x(111,FATAL,"decryption failed");

        /* Write message */
        if(buffer_put(buffer_1,m.s,m.len)!=0)
            strerr_die2sys(111,FATAL,"failed to output message: ");

    }
    buffer_flush(buffer_1);

    return 0;
}
Пример #8
0
static int _issub(struct subdbinfo *info,
                  const char *table,
                  const char *userhost,
                  stralloc *recorded)
{
    sqlite3_stmt *stmt;
    unsigned int j;
    int res;

    /* SELECT address FROM list WHERE address = 'userhost' AND hash */
    /* BETWEEN 0 AND 52. Without the hash restriction, we'd make it */
    /* even easier to defeat. Just faking sender to the list name would*/
    /* work. Since sender checks for posts are bogus anyway, I don't */
    /* know if it's worth the cost of the "WHERE ...". */

    if (!stralloc_copys(&addr,userhost)) die_nomem();
    j = byte_rchr(addr.s,addr.len,'@');
    if (j == addr.len) return 0;
    case_lowerb(addr.s + j + 1,addr.len - j - 1);

    if (!stralloc_copys(&line,"SELECT address FROM ")) die_nomem();
    if (!stralloc_cat_table(&line,info,table)) die_nomem();
    if (!stralloc_cats(&line," WHERE address LIKE '")) die_nomem();
    if (!stralloc_cat(&line,&addr)) die_nomem();
    if (!stralloc_cats(&line,"'")) die_nomem();
    if (!stralloc_0(&line)) die_nomem();

    if ((stmt = _sqlquery(info, &line)) == NULL)	/* select */
        strerr_die2x(111,FATAL,sqlite3_errmsg((sqlite3*)info->conn));

    /* No data returned in QUERY */
    res = sqlite3_step(stmt);
    if (res != SQLITE_ROW)
    {
        if (res != SQLITE_DONE)
            strerr_die2x(111,FATAL,sqlite3_errmsg((sqlite3*)info->conn));

        sqlite3_finalize(stmt);
        return 0;
    }

    if (recorded)
    {
        if (!stralloc_copyb(recorded, (const char*)sqlite3_column_text(stmt, 0), sqlite3_column_bytes(stmt, 0)))
            die_nomem();
        if (!stralloc_0(recorded)) die_nomem();
    }

    sqlite3_finalize(stmt);
    return 1;
}
Пример #9
0
static void do_log(char *action,unsigned int actlen)
{
  action += actlen;
  if (*action == '.' || *action == '_') ++action;
  if (!flaglist || remote.s == 0)
    strerr_die2x(100,FATAL,MSG(ERR_NOT_AVAILABLE));
  if (!ismod)
    strerr_die2x(100,FATAL,MSG(ERR_NOT_ALLOWED));
  showsend("log");
  hdr_subject((*action == 0) ? MSG(SUB_LOG) : MSG(SUB_LOG_SEARCH));
  hdr_ctboundary();
  searchlog(workdir,action,code_subto);
  copybottom(0);
  qmail_to(&qq,mod.s);
}
Пример #10
0
int passwd_cb(char *buff,int size,int rwflag,void *userdata) {
  if (size < password.len)
    strerr_die2x(111,FATAL,"password too long");

  byte_copy(buff,password.len,password.s);
  return password.len;
}
Пример #11
0
int getoff(const char *action)
{
  int r;

  r = subscribe(workdir,target.s,0,"",(*action == ACTION_WC[0]) ? "-mod" : "-",-1);
  if (flagdig == FLD_DENY || flagdig == FLD_ALLOW)
    strerr_die2x(0,INFO,MSG1(ERR_EXTRA_UNSUB,target.s));
  switch (r) {
			/* no comment for unsubscribe */
    case 1:
	    hdr_subject(MSG(SUB_GOODBYE));
            qmail_puts(&qq,"\n");
            hdr_ctboundary();
            copy(&qq,"text/top",flagcd);
            copy_act("text/unsub-ok");
            break;
    default:
	    hdr_subject(MSG(SUB_UNSUBSCRIBE_NOP));
            hdr_ctboundary();
            copy(&qq,"text/top",flagcd);
            copy_act("text/unsub-nop");
            break;
  }
  return r;
}
Пример #12
0
int main(int argc,char **argv)
{
    int i;

    dns_random_init(seed);

    if (*argv) ++argv;

    while (*argv) {
        if (!stralloc_copys(&fqdn,*argv))
            strerr_die2x(111,FATAL,"out of memory");
        if (dns_ip4(&out,&fqdn) == -1)
            strerr_die4sys(111,FATAL,"unable to find IP address for ",*argv,": ");

        for (i = 0; i + 4 <= out.len; i += 4) {
            buffer_put(buffer_1,str,ip4_fmt(str,out.s + i));
            buffer_puts(buffer_1," ");
        }
        buffer_puts(buffer_1,"\n");

        ++argv;
    }

    buffer_flush(buffer_1);
    _exit(0);
}
Пример #13
0
void f_init(char **script)
{
  int i;
  int fd;

  for (i = 0;script[i];++i)
    ;

  f = (int *) alloc(i * sizeof(*f));
  if (!f) strerr_die2x(111,FATAL,"out of memory");

  for (i = 0;script[i];++i) {
    fd = -1;
    if (script[i][0] == '=') {
      if (fchdir(fdstartdir) == -1)
        strerr_die2sys(111,FATAL,"unable to switch to starting directory: ");
      fd = open_append(script[i] + 1);
      if (fd == -1)
        strerr_die4sys(111,FATAL,"unable to create ",script[i] + 1,": ");
      close(fd);
      fd = open_write(script[i] + 1);
      if (fd == -1)
        strerr_die4sys(111,FATAL,"unable to write ",script[i] + 1,": ");
      coe(fd);
    }
    f[i] = fd;
  }
}
Пример #14
0
int main(int argc, char **argv, char **envp) {
  uint8_t buf[1024];
  cdb_t cdb;
  char *key;
  uint32_t len;
  uint32_t r;
  uint32_t pos;
  uint32_t skip = 0;
  char *skip_str;
  
  if (!*argv || !*++argv)
    usage();
  key = *argv;
  
  skip_str = *++argv;
  if (skip_str) {
    if (sscanf(skip_str, "%" PRIu32, &skip) != strlen(skip_str))
      usage();
  }
  
  /* Initialize the cdb struct using stdin as it's file descriptor. */
  if (cdb_init(&cdb, 0) == -1)
    strerr_die2x(111, FATAL, "failed to initialize cdb");
    
  for (;;) {
    r = cdb_find_next(&cdb, key, strlen(key));
    if (r == -1)
      strerr_die2sys(111, FATAL, "unable to read input: ");
    if (!r)
      _exit(100);
      
    if (!skip)
      break;
    skip--;
  }
  
  /* If there's a record in the cdb file, then the cdb structs dlen property
   * will be set to a non-zero value and it's position will be set to the
   * offset in the file containing the data.  Read the data in chunks and send
   * it to stdout. */
  len = cdb.dlen;
  pos = cdb.dpos;
  while (len > 0) {
    r = sizeof(buf);
    if (r > len)
      r = len;
    if (cdb_read(buf, r, &cdb, pos) == -1)
      strerr_die2sys(111, FATAL, "unable to read input: ");
    if (bio_put(bio_1, buf, r) == -1)
      strerr_die2sys(111, FATAL, "unable to write output: ");
    pos += r;
    len -= r;
  }
  if (bio_flush(bio_1) == -1)
    strerr_die2sys(111, FATAL, "unable to write output: ");
    
  cdb_free(&cdb);
  
  return 0;
}
Пример #15
0
main()
{
  char *x;
  int udp53;

  x = env_get("IP");
  if (!x)
    strerr_die2x(111,fatal,"$IP not set");
  if (!ip4_scan(x,ip))
    strerr_die3x(111,fatal,"unable to parse IP address ",x);

  udp53 = socket_udp();
  if (udp53 == -1)
    strerr_die2sys(111,fatal,"unable to create UDP socket: ");
  if (socket_bind4_reuse(udp53,ip,53) == -1)
    strerr_die2sys(111,fatal,"unable to bind UDP socket: ");

  droproot(fatal);

  initialize();
  
  ndelay_off(udp53);
  socket_tryreservein(udp53,65536);

  for (;;) {
    len = socket_recv4(udp53,buf,sizeof buf,ip,&port);
    if (len < 0) continue;
    if (!doit()) continue;
    if (response_len > 512) response_tc();
    socket_send4(udp53,response,response_len,ip,port);
    /* may block for buffer space; if it fails, too bad */
  }
}
Пример #16
0
/* This routine inserts the cookie into table_cookie. We log arrival of
 * the message (done=0). */
void sub_sql_tagmsg(struct subdbinfo *info,
		    unsigned long msgnum,	/* number of this message */
		    const char *hashout,	/* previously calculated hash */
		    unsigned long bodysize,
		    unsigned long chunk)
{
  const char *ret;
  char strnum[FMT_ULONG];

  if (chunk >= 53L) chunk = 0L;	/* sanity */

  /* INSERT INTO table_cookie (msgnum,tai,cookie,bodysize,chunk) VALUES (...) */
  /* (we may have tried message before, but failed to complete, so */
  /* ER_DUP_ENTRY is ok) */
  stralloc_copys(&query,"INSERT INTO ");
  stralloc_cats(&query,info->base_table);
  stralloc_cats(&query,"_cookie (msgnum,tai,cookie,bodysize,chunk) VALUES ");
  stralloc_cats(&query,sql_tagmsg_values_defn);
  stralloc_copyb(&params[0],strnum,fmt_ulong(strnum,msgnum));
  stralloc_copyb(&params[1],hashout,COOKIE);
  stralloc_copyb(&params[2],strnum,fmt_ulong(strnum,bodysize));
  stralloc_copyb(&params[3],strnum,fmt_ulong(strnum,chunk));

  sql_exec(info,&query,4,params); /* ignore dups */

  if (! (ret = logmsg(msgnum,0L,0L,1)))
    return;			/* log done=1*/
  if (*ret) strerr_die2x(111,FATAL,ret);
}
Пример #17
0
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);
  }
}
Пример #18
0
/* 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);
}
Пример #19
0
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);
}
Пример #20
0
void startup(const char *dir)
{
  if (dir == 0)
    die_usage();

  if (dir[0] != '/')
    strerr_die2x(100,FATAL,ERR_SLASH);

  wrap_chdir(dir);
}
Пример #21
0
int rijndaelDecrypt_cbc(char *c, unsigned int l, stralloc *p)
{
  unsigned int n;

  /* if ciphertext is not a multiple of 128 Bits we have a problem */
  if(l % 16 != 0) // XXX: fixme
    strerr_die2x(111, FATAL, "input data is not 128 Bit aligned");    
  if(l < 32)      // XXX: fixme
    strerr_die2x(111, FATAL, "input data is < 32 bytes");    
  
  for(n = 16; n < l; n += 16)
    {
      stralloc_catb(p, &c[n], 16); 
      rijndaelDecrypt(&p->s[p->len-16]);
      byte_Ixor(&p->s[p->len-16], &c[n-16], 16);
    }

  return p->len;
} 
Пример #22
0
int mailprog(const char *s)
{
    int r;

    if ((child = wrap_fork()) == 0)
      wrap_execsh(s);
    /* parent */
    switch((r = wrap_waitpid(child))) {
      /* 100 perm error, 111 temp, 99 dom ok */
      /* 0 rec ok, others bounce */
      case 0: case 99: case 100: break;
      case 111:					/* temp error */
        strerr_die2x(111,FATAL,MSG(ERR_CHILD_TEMP));
      default:
        strerr_die2x(100,FATAL,MSG(ERR_REJECT));	/* other errors => bounce */
    }
    if (seek_begin(0) == -1)			/* rewind */
      strerr_die2sys(111,FATAL,MSG(ERR_SEEK_INPUT));
    return r;
}
Пример #23
0
/* Outputs all addresses in the table through subwrite. subwrite must be
 * a function returning >=0 on success, -1 on error, and taking
 * arguments (char* string, unsigned int length). It will be called once
 * per address and should take care of newline or whatever needed for
 * the output form. */
static unsigned long _putsubs(struct subdbinfo *info,
                              const char *table,
                              unsigned long hash_lo,
                              unsigned long hash_hi,
                              int subwrite())		/* write function. */
{
    unsigned long no = 0L;
    sqlite3_stmt *stmt;
    int res;
    int length;
    const char *row;

    /* main query */
    if (!stralloc_copys(&line,"SELECT address FROM "))
        die_nomem();
    if (!stralloc_cat_table(&line,info,table)) die_nomem();
    if (!stralloc_cats(&line," WHERE hash BETWEEN ")) die_nomem();
    if (!stralloc_catb(&line,strnum,fmt_ulong(strnum,hash_lo)))
        die_nomem();
    if (!stralloc_cats(&line," AND ")) die_nomem();
    if (!stralloc_catb(&line,strnum,fmt_ulong(strnum,hash_hi)))
        die_nomem();
    if (!stralloc_0(&line)) die_nomem();

    if ((stmt = _sqlquery(info, &line)) == NULL)
        strerr_die2x(111,FATAL,sqlite3_errmsg((sqlite3*)info->conn));

    no = 0;
    while ((res = sqlite3_step(stmt)) != SQLITE_DONE) {
        if (res != SQLITE_ROW)
            strerr_die2x(111,FATAL,sqlite3_errmsg((sqlite3*)info->conn));
        /* this is safe even if someone messes with the address field def */
        length = sqlite3_column_bytes(stmt, 0);
        row = (const char*)sqlite3_column_text(stmt, 0);
        if (subwrite(row,length) == -1) die_write();
        no++;					/* count for list-list fxn */
    }

    sqlite3_finalize(stmt);
    return no;
}
Пример #24
0
void main(int argc,char **argv)
{
  char *def;
  int dash;
  
  optind = getconfopt(argc,argv,options,0,0);
  if (argv[optind] == 0)
    die_usage();
  if (!stralloc_copys(&basedir,argv[optind++])) die_nomem();

  sender = get_sender();
  if (!sender)
    strerr_die2x(100,FATAL,MSG(ERR_NOSENDER));
  def = env_get("DEFAULT");

  if (argv[optind] != 0) {
    dispatch(argv[optind],def);
    strerr_die3x(100,FATAL,"Not a directory: ",path.s);
  }
  else if (!def || !*def)
    strerr_die2x(100,FATAL,MSG(ERR_NODEFAULT));
  else {
    if (def[str_chr(def,'/')] != 0)
      strerr_die2x(100,FATAL,"Recipient address may not contain '/'");

    dispatch(def,0);

    dash = str_len(def);
    for (;;) {
      while (--dash > 0)
	if (def[dash] == '-')
	  break;
      if (dash <= 0)
	break;
      def[dash] = 0;
      dispatch(def,def+dash+1);
      def[dash] = '-';
    }
    strerr_die3x(100,FATAL,"Could not match recipient name to any list: ",def);
  }
}
Пример #25
0
void get(char *buf,unsigned int len)
{
  int r;
  while (len > 0) {
	 r = buffer_get(buffer_0,buf,len);
	 if (r == -1) die_read();
	 if (r == 0)
		strerr_die2x(111,FATAL,"unable to read input: truncated file");
	 pos += r;
	 buf += r;
	 len -= r;
  }
}
Пример #26
0
int main(int argc,char *argv[])
{
  const char* dir;
  int fd;
  int match;
  unsigned long msgsize = 0L;
  int opt;
  
  while ((opt = getopt(argc,argv,"vV")) != opteof) {
    switch(opt) {
    case 'v':
    case 'V':
      strerr_die2x(0, "ezmlm-import version: ",auto_version);
    default:
      die_usage();
    }
  }

  if (argc - optind != 2)
    die_usage();

  if ((fd = open_read(argv[optind+1])) == -1)
    strerr_die4sys(111,FATAL,ERR_OPEN,argv[optind+1],": ");
  substdio_fdbuf(&ssin,read,fd,inputbuf,sizeof inputbuf);

  startup(dir = argv[optind]);
  lockfile("lock");

  getconf_ulong2(&msgnum,&cumsize,"num",0,dir);
  
  fd = 0;
  while (getln(&ssin,&line,&match,'\n') == 0 && match) {
    if (line.len > 5
	&& byte_diff(line.s,5,"From ") == 0) {
      if (fd > 0) {
	if (substdio_flush(&ssarchive) == -1
	    || fchmod(fd,MODE_ARCHIVE|0700) == -1
	    || close(fd) == -1)
	  strerr_die4sys(111,FATAL,ERR_WRITE,fnaf.s,": ");
	fd = 0;
      }
      ++msgnum;
      cumsize += (msgsize + 128L) >> 8;
      msgsize = 0L;
      fd = openone(msgnum);
    }
    else if (fd > 0) {
      substdio_put(&ssarchive,line.s,line.len);
      msgsize += line.len;
    }
  }
Пример #27
0
void zapnonsub(const char *szerr)
/* fatal error if flagsubonly is set and sender is not a subscriber */
/* expects the current dir to be the list dir. Error is szerr */
/* added check for undefined sender as a precaution */
{
  if (sender && *sender) {	/* "no sender" is not a subscriber */
    if (!flagsubonly)
      return;
    if (issub(0,sender,0))
      return;		/* subscriber */
    if (issub("digest",sender,0))
      return;		/* digest subscriber */
    if (issub("allow",sender,0))
      return;		/* allow addresses */
  }
  strerr_die2x(100,FATAL,MSG1(ERR_SUBSCRIBER_CAN,szerr));
}
Пример #28
0
void c_init(char **script)
{
  int i;
  struct cyclog *d;
  char *processor;
  unsigned long num;
  unsigned long size;

  cnum = 0;
  for (i = 0;script[i];++i)
    if ((script[i][0] == '.') || (script[i][0] == '/'))
      ++cnum;

  c = (struct cyclog *) alloc(cnum * sizeof(*c));
  if (!c) strerr_die2x(111,FATAL,"out of memory");

  d = c;
  processor = 0;
  num = 10;
  size = 99999;

  for (i = 0;script[i];++i)
    if (script[i][0] == 's') {
      scan_ulong(script[i] + 1,&size);
      if (size < 4096) size = 4096;
      if (size > 16777215) size = 16777215;
    }
    else if (script[i][0] == 'n') {
      scan_ulong(script[i] + 1,&num);
      if (num < 2) num = 2;
    }
    else if (script[i][0] == '!') {
      processor = script[i] + 1;
    }
    else if ((script[i][0] == '.') || (script[i][0] == '/')) {
      d->num = num;
      d->size = size;
      d->processor = processor;
      d->dir = script[i];
      buffer_init(&d->ss,c_write,d - c,d->buf,sizeof d->buf);
      restart(d);
      ++d;
    }
}
Пример #29
0
int main(int argc,const char * const *argv,const char * const *envp)
{
  char ch;
  int wstat;
  int pi[2];
  int i;
  int ignored;

  if (!argv[1])
    strerr_die1x(100,"fghack: usage: fghack child");

  if (pipe(pi) == -1)
    strerr_die2sys(111,FATAL,"unable to create pipe: ");

  switch(pid = fork()) {
    case -1:
      strerr_die2sys(111,FATAL,"unable to fork: ");
    case 0:
      close(pi[0]);
      for (i = 0;i < 30;++i)
        ignored = dup(pi[1]);
      pathexec_run(argv[1],argv + 1,envp);
      strerr_die4sys(111,FATAL,"unable to run ",argv[1],": ");
  }

  close(pi[1]);

  for (;;) {
    i = buffer_unixread(pi[0],&ch,1);
    if ((i == -1) && (errno == error_intr)) continue;
    if (i == 1) continue;
    break;
  }

  if (wait_pid(&wstat,pid) == -1)
    strerr_die2sys(111,FATAL,"wait failed: ");
  if (wait_crashed(wstat))
    strerr_die2x(111,FATAL,"child crashed");
  _exit(wait_exitcode(wstat));
}
Пример #30
0
void axfrcheck(char *q)
{
  int i;
  int j;

  if (!axfr) return;

  i = j = 0;
  for (;;) {
    if (!axfr[i] || (axfr[i] == '/')) {
      if (i > j) {
        if (!dns_domain_fromdot(&axfrok,axfr + j,i - j)) nomem();
        if (dns_domain_equal(q,axfrok)) return;
      }
      j = i + 1;
    }
    if (!axfr[i]) break;
    ++i;
  }

  strerr_die2x(111,FATAL,"disallowed zone transfer request");
}