Beispiel #1
0
void presub(unsigned long from,unsigned long to,stralloc *subject,
	    int factype,	/* action type (AC_THREAD,AC_GET,AC_DIGEST) */
	    char format)	/* output format type (see idx.h) */
/* Starts within header, outputs "subject" and optional headers, terminates*/
/* header and handles output before table-of-contents                      */
{
  switch(format) {
    case MIME:
    case VIRGIN:
    case NATIVE:
    case MIXED:
        hdr_mime((format == MIXED) ? CTYPE_MULTIPART : CTYPE_DIGEST);
	hdr_add2("Subject: ",subject->s,subject->len);
	hdr_boundary(0);
	hdr_ctype(CTYPE_TEXT);
	hdr_transferenc();	/* content-transfer-enc header if needed */
	break;
    case RFC1153:
        hdr_mime(CTYPE_TEXT);
	hdr_add2("Subject: ",subject->s,subject->len);
	qmail_puts(&qq,"\n");
	flagcd = '\0';	/* We make 8-bit messages, not QP/base64 for rfc1153 */
        break;		/* Since messages themselves aren't encoded */
    }
    if (!stralloc_cats(subject,"\n\n")) die_nomem();
    code_qput(subject->s,subject->len);
    if (format != NATIVE && factype != AC_THREAD && factype != AC_INDEX) {
      strnum[fmt_ulong(strnum,from)] = 0;
      strnum2[fmt_ulong(strnum2,to)] = 0;
      code_qputs(MSG2(TXT_TOP_TOPICS,strnum,strnum2));
    }
}
Beispiel #2
0
static int doit(stralloc *out,int s,char ipremote[16],uint16 portremote,char iplocal[16],uint16 portlocal,unsigned int timeout,uint32 netif)
{
  buffer b;
  char bspace[128];
  char strnum[FMT_ULONG];
  int numcolons;
  char ch;

  if (socket_bind6(s,iplocal,0,netif) == -1) return -1;
  if (timeoutconn6(s,ipremote,113,timeout,netif) == -1) return -1;

  buffer_init(&b,mywrite,s,bspace,sizeof bspace);
  buffer_put(&b,strnum,fmt_ulong(strnum,portremote));
  buffer_put(&b," , ",3);
  buffer_put(&b,strnum,fmt_ulong(strnum,portlocal));
  buffer_put(&b,"\r\n",2);
  if (buffer_flush(&b) == -1) return -1;

  buffer_init(&b,myread,s,bspace,sizeof bspace);
  numcolons = 0;
  for (;;) {
    if (buffer_get(&b,&ch,1) != 1) return -1;
    if ((ch == ' ') || (ch == '\t') || (ch == '\r')) continue;
    if (ch == '\n') return 0;
    if (numcolons < 3) {
      if (ch == ':') ++numcolons;
    }
    else {
      if (!stralloc_append(out,&ch)) return -1;
      if (out->len > 256) return 0;
    }
  }
}
Beispiel #3
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. */
unsigned long sub_sql_putsubs(struct subdbinfo *info,
			      const char *table,
			      unsigned long hash_lo,
			      unsigned long hash_hi,
			      int subwrite()) /* write function. */
{
  void *result;
  unsigned long no = 0L;
  char strnum[FMT_ULONG];

  stralloc_copyb(&params[0],strnum,fmt_ulong(strnum,hash_lo));
  stralloc_copyb(&params[1],strnum,fmt_ulong(strnum,hash_hi));
  make_name(info,table?"_":0,table,0);

  /* main query */
  stralloc_copys(&query,"SELECT address FROM ");
  stralloc_cat(&query,&name);
  stralloc_cats(&query," WHERE ");
  stralloc_cats(&query,sql_putsubs_where_defn);

  result = sql_select(info,&query,2,params);

  no = 0;
  while (sql_fetch_row(info,result,1,&addr)) {
    if (subwrite(addr.s,addr.len) == -1) die_write();
    no++;					/* count for list-list fxn */
  }
  sql_free_result(info,result);
  return no;
}
Beispiel #4
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);
}
Beispiel #5
0
/* Creates an entry for message num and the list listno and code "done".
 * Returns NULL on success, and the error string on error. */
const char *sub_sql_logmsg(struct subdbinfo *info,
			   unsigned long num,
			   unsigned long listno,
			   unsigned long subs,
			   int done)
{
  char *s;
  char strnum[FMT_ULONG];

  stralloc_copys(&query,"INSERT INTO ");
  stralloc_cats(&query,info->base_table);
  stralloc_cats(&query,"_mlog (msgnum,listno,subs,done) VALUES ");
  stralloc_cats(&query,sql_logmsg_values_defn);
  stralloc_copyb(&params[0],strnum,fmt_ulong(strnum,num));
  stralloc_copyb(&params[1],strnum,fmt_ulong(strnum,listno));
  stralloc_copyb(&params[2],strnum,fmt_ulong(strnum,subs));
  s = strnum;
  if (done < 0) {
    done = - done;
    *s++ = '-';
  }
  s[fmt_uint(s,done)] = 0;
  stralloc_copys(&params[3],s);

  sql_exec(info,&query,4,params); /* ignore dups */
  return 0;
}
void printstatus(void)
{
  if (verbosity < 2) return;
  strnum[fmt_ulong(strnum,numchildren)] = 0;
  strnum2[fmt_ulong(strnum2,limit)] = 0;
  strerr_warn4("sslserver: status: ",strnum,"/",strnum2,0);
}
Beispiel #7
0
void write_ulong(unsigned long num,unsigned long cum,unsigned long dat,
		 const char *fn,const char *fnn)
/* write num to "fnn" add ':' & cum if cum <>0, then move "fnn" to "fn" */
{
  int fd;

  fd = open_trunc(fnn);
  if (fd == -1)
     strerr_die2sys(111,FATAL,MSG1(ERR_CREATE,fnn));
  substdio_fdbuf(&ssnum,write,fd,numbuf,sizeof(numbuf));
  if (substdio_put(&ssnum,strnum,fmt_ulong(strnum,num)) == -1)
     strerr_die2sys(111,FATAL,MSG1(ERR_WRITE,fnn));
  if (substdio_puts(&ssnum,":") == -1)
     strerr_die2sys(111,FATAL,MSG1(ERR_WRITE,fnn));
  if (substdio_put(&ssnum,strnum,fmt_ulong(strnum,cum)) == -1)
     strerr_die2sys(111,FATAL,MSG1(ERR_WRITE,fnn));
  if (dat) {
    if (substdio_puts(&ssnum,":") == -1)
       strerr_die2sys(111,FATAL,MSG1(ERR_WRITE,fnn));
    if (substdio_put(&ssnum,strnum,fmt_ulong(strnum,dat)) == -1)
       strerr_die2sys(111,FATAL,MSG1(ERR_WRITE,fnn));
  }
  if (substdio_puts(&ssnum,"\n") == -1)
     strerr_die2sys(111,FATAL,MSG1(ERR_WRITE,fnn));
  if (substdio_flush(&ssnum) == -1)
     strerr_die2sys(111,FATAL,MSG1(ERR_FLUSH,fnn));
  if (fsync(fd) == -1)
     strerr_die2sys(111,FATAL,MSG1(ERR_SYNC,fnn));
  if (close(fd) == -1)
     strerr_die2sys(111,FATAL,MSG1(ERR_CLOSE,fnn));
  wrap_rename(fnn,fn);
}
Beispiel #8
0
int main(int argc,const char *const *argv,const char *const *envp)
{
  struct passwd *pw;
  const char *account;
  char strnum[FMT_ULONG];

  account = *++argv;
  if (!account || !*++argv)
    usage();

  pw = getpwnam(account);
  if (!pw)
    strerr_die3x(111,FATAL,"unknown account ",account);

  if (!pathexec_env("HOME",pw->pw_dir)) nomem();
  if (!pathexec_env("SHELL",pw->pw_shell)) nomem();
  if (!pathexec_env("USER",pw->pw_name)) nomem();
  strnum[fmt_ulong(strnum,pw->pw_gid)] = 0;
  if (!pathexec_env("GID",strnum)) nomem();
  strnum[fmt_ulong(strnum,pw->pw_uid)] = 0;
  if (!pathexec_env("UID",strnum)) nomem();

  if (chdir(pw->pw_dir) != 0)
    strerr_die3sys(111,FATAL,"unable to chdir to ", pw->pw_dir);
  if (prot_gid(pw->pw_gid) == -1)
    strerr_die2sys(111,FATAL,"unable to setgid");
  if (prot_gids(pw->pw_name, pw->pw_gid) == -1)
    strerr_die2sys(111,FATAL,"unable to initgroups");
  if (prot_uid(pw->pw_uid) == -1)
    strerr_die2sys(111,FATAL,"unable to setuid");

  pathexec_run(*argv,argv,envp);
  strerr_die3sys(111,FATAL,"unable to run ",*argv);
}
Beispiel #9
0
unsigned int io_debugstring(int64 s,char* buf,unsigned int bufsize) {
  struct timeval tv;
  unsigned int i;
  io_entry* e;
  gettimeofday(&tv,NULL);
  e=iarray_get(&io_fds,s);
  if (!e) return 0;
  if (bufsize<100) return 0;
  i=fmt_str(buf,"first_readable ");
  i+=fmt_long(buf+i,first_readable);
  i+=fmt_str(buf+i,", first_writeable ");
  i+=fmt_long(buf+i,first_writeable);
#ifdef HAVE_SIGIO
  i+=fmt_str(buf+i,", alt_firstread ");
  i+=fmt_long(buf+i,alt_firstread);
  i+=fmt_str(buf+i,", alt_firstwrite ");
  i+=fmt_long(buf+i,alt_firstwrite);
#endif
  i+=fmt_str(buf+i,"\n");

  i+=fmt_str(buf+i,"fd # ");
  i+=fmt_ulong(buf+i,s);
  i+=fmt_str(buf+i,": ");
  if (bufsize-i<100) return 0;
  i+=fmt_str(buf+i,"timeout ");
  i+=fmt_long(buf+i,e->timeout.sec.x-4611686018427387914ULL-tv.tv_sec);
  i+=fmt_str(buf+i,".");
  i+=fmt_ulong(buf+i,e->timeout.nano);
  i+=fmt_str(buf+i," ");
  if (bufsize-i<100) return 0;
  if (e->wantread) i+=fmt_str(buf+i,"wr ");
  if (e->wantwrite) i+=fmt_str(buf+i,"ww ");
  if (e->canread) i+=fmt_str(buf+i,"cr ");
  if (e->canwrite) i+=fmt_str(buf+i,"cw ");
  if (e->nonblock) i+=fmt_str(buf+i,"nb ");
  if (!e->inuse) i+=fmt_str(buf+i,"!inuse ");
  if (e->kernelwantread) i+=fmt_str(buf+i,"kwr ");
  if (e->kernelwantwrite) i+=fmt_str(buf+i,"kww ");
  if (e->epolladded) i+=fmt_str(buf+i,"ea ");
  if (e->mmapped) {
    i+=fmt_str(buf+i,"mmap(");
    i+=fmt_xlong(buf+i,(unsigned long)e->mmapped);
    i+=fmt_str(buf+i,",");
    i+=fmt_xlong(buf+i,(unsigned long)e->maplen);
    i+=fmt_str(buf+i,"@");
    i+=fmt_xlonglong(buf+i,(unsigned long)e->mapofs);
  }
  if (bufsize-i<100) return 0;
  i+=fmt_str(buf+i,"next_read ");
  i+=fmt_long(buf+i,e->next_read);
  i+=fmt_str(buf+i," next_write ");
  i+=fmt_long(buf+i,e->next_write);
  i+=fmt_str(buf+i," cookie ");
  i+=fmt_xlonglong(buf+i,(unsigned long)e->cookie);
  buf[i]=0;
  return i;
}
Beispiel #10
0
/* 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;
}
Beispiel #11
0
static void showstatus(const char status[19], int r)
{
  const char *x;
  struct tai when;
  struct tai now;

  pid = (unsigned char) status[15];
  pid <<= 8; pid += (unsigned char) status[14];
  pid <<= 8; pid += (unsigned char) status[13];
  pid <<= 8; pid += (unsigned char) status[12];

  paused = status[16];
  want = status[17];
  statusflag = status[18];

  tai_unpack(status,&when);
  tai_now(&now);
  if (tai_less(&now,&when)) when = now;
  tai_sub(&when,&now,&when);

  if (pid) {
    buffer_puts(&b,"up (pid ");
    buffer_put(&b,strnum,fmt_ulong(strnum,pid));
    buffer_puts(&b,") ");
  }
  else
    buffer_puts(&b,"down ");

  buffer_put(&b,strnum,fmt_ulong(strnum,tai_approx(&when)));
  buffer_puts(&b," seconds");

  if (pid && !normallyup)
    buffer_puts(&b,", normally down");
  if (!pid && normallyup)
    buffer_puts(&b,", normally up");
  if (pid && paused)
    buffer_puts(&b,", paused");
  if (!pid && (want == 'u'))
    buffer_puts(&b,", want up");
  if (pid && (want == 'd'))
    buffer_puts(&b,", want down");
  if (r > 18) {
    switch (statusflag) {
    case svstatus_stopped: x = ", stopped"; break;
    case svstatus_starting: x = ", starting"; break;
    case svstatus_started: x = ", started"; break;
    case svstatus_running: x = ", running"; break;
    case svstatus_stopping: x = ", stopping"; break;
    case svstatus_failed: x=", failed"; break;
    default: x = ", status unknown";
    }
    if (x)
      buffer_puts(&b,x);
  }
}
void sigchld(void) {
  int wstat;
  int pid;
 
  while ((pid = wait_nohang(&wstat)) > 0) {
    if (verbosity >= 2) {
      strnum[fmt_ulong(strnum,pid)] = 0;
      strnum2[fmt_ulong(strnum2,wstat)] = 0;
      strerr_warn4("sslserver: end ",strnum," status ",strnum2,0);
    }
    if (numchildren) --numchildren; printstatus();
  }
}
Beispiel #13
0
unsigned int ip4_fmt(char *s,const char ip[4])
{
  unsigned int len;
  unsigned int i;

  len = 0;
  i = fmt_ulong(s,(unsigned long) (unsigned char) ip[0]); len += i; if (s) s += i;
  if (s) *s++ = '.'; ++len;
  i = fmt_ulong(s,(unsigned long) (unsigned char) ip[1]); len += i; if (s) s += i;
  if (s) *s++ = '.'; ++len;
  i = fmt_ulong(s,(unsigned long) (unsigned char) ip[2]); len += i; if (s) s += i;
  if (s) *s++ = '.'; ++len;
  i = fmt_ulong(s,(unsigned long) (unsigned char) ip[3]); len += i; if (s) s += i;
  return len;
}
Beispiel #14
0
static void put_num(unsigned int num){
    unsigned int i;
    char strnum[FMT_ULONG];
    i = fmt_ulong(strnum, num);
    put(strnum, i);
    return;
}
Beispiel #15
0
size_t fmt_escapecharxml(char* dest,uint32_t ch) {
  char a[FMT_LONG], b[FMT_XLONG];
  const char* s;
  size_t i,j;
  switch (ch) {
  case '&': s="&amp;"; goto string;
  case '<': s="&lt;"; goto string;
  case '>': s="&gt;"; goto string;
  case '\'': s="&apos;"; goto string;
  case '"': s="&quot;"; goto string;
  default:
    a[i=fmt_ulong(a,ch)]=0;
    b[0]='x';
    b[j=fmt_xlong(b+1,ch)+1]=0;
    s=a;
    if (i>j) { s=b; i=j; }
    if (dest) {
      dest[0]='&';
      dest[1]='#';
      byte_copy(dest+2,i,s);
      dest[i+2]=';';
    }
    return i+3;
  }
string:
  return fmt_str(dest,s);
}
int ip_vhost(struct http_data* h) {
  char* y;
  int i;

  /* construct artificial Host header from IP */
  y=alloca(IP6_FMT+7);
  i=fmt_ip6c(y,h->myip);
  i+=fmt_str(y+i,":");
  i+=fmt_ulong(y+i,h->myport);
  y[i]=0;

#ifdef __MINGW32__
//  printf("chdir(\"%s\") -> %d\n",origdir,chdir(origdir));
  chdir(origdir);
#else
  fchdir(origdir);
#endif
  if (virtual_hosts>=0) {
    if (chdir(y)==-1)
      if (chdir("default")==-1)
	if (virtual_hosts==1) {
	  h->hdrbuf="425 no such virtual host.\r\n";
	  return -1;
	}
  }
  return 0;
}
Beispiel #17
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;
}
Beispiel #18
0
void logaddr(const char *subdir,const char *event,
	     const char *addr,const char *comment)
{
  char ch;
  int fd;

  stralloc_copyb(&line,num,fmt_ulong(num,(unsigned long) now()));
  stralloc_cats(&line," ");
  stralloc_cats(&line,event);
  stralloc_cats(&line," ");
  while ((ch = *addr++) != 0) {
    if ((ch < 33) || (ch > 126)) ch = '?';
    stralloc_append(&line,ch);
  }
  if (comment && *comment) {
    stralloc_cats(&line," ");
    while ((ch = *comment++) != 0) {
      if (ch == '\t')
        ch = ' ';
      else 
        if ((ch < 32) || (ch > 126)) ch = '?';
      stralloc_append(&line,ch);
    }
  }
  stralloc_cats(&line,"\n");

  makepath(&fn,subdir,"/Log",0);
  fd = open_append(fn.s);
  if (fd == -1) return;
  substdio_fdbuf(&ss,write,fd,NULL,0);
  substdio_putflush(&ss,line.s,line.len);
  close(fd);
  return;
}
Beispiel #19
0
void snap_dump(char *filename, stralloc *sa)
{
  dAVLCursor c;
  dAVLNode *node;
  char strip[IP6_FMT];
  char strnum[FMT_ULONG];
  int fd;

  fd = open_trunc("filename");  
  if(fd == -1)
    strerr_warn1(ARGV0 "warning: unable to open for tcp.tmp for writing", &strerr_sys);
  
  buffer_init(&wb, write, fd, wbspace, sizeof wbspace);

  node = dAVLFirst(&c, t);
  while(node)
    {
      buffer_put(&wb, strnum, fmt_ulong(strnum, node->key));
      buffer_puts(&wb, ",");
      buffer_put(&wb, strip, ip4_fmt(strip, node->ip4));
      buffer_puts(&wb, ",");
      buffer_put(&wb, strip, ip6_fmt(strip, node->ip6));
      buffer_puts(&wb, ",LOC\n");
      
      node = dAVLNext(&c);
    }
 
  buffer_flush(&wb);
  close(fd);
}
Beispiel #20
0
static enum ud_tree_walk_stat
rt_tag_link_ext (struct udoc *ud, struct udr_ctx *rc)
{
    char cnum[FMT_ULONG];
    const struct ud_node *node = rc->uc_tree_ctx->utc_state->utc_node;
    struct ud_ref *ref;
    struct buffer *buf = &rc->uc_out->uoc_buffer;
    unsigned long index;
    unsigned long max;

    /* urls are numbered, so a linear search is necessary to work out the url id */
    /* XXX: this is not ideal... */
    max = ud_oht_size (&ud->ud_link_exts);
    for (index = 0; index < max; ++index) {
        ud_assert (ud_oht_get_index (&ud->ud_link_exts, index, (void *) &ref));
        if (node == ref->ur_node) {
            buffer_puts (buf, "\\from[url_");
            buffer_put (buf, cnum, fmt_ulong (cnum, index));
            buffer_puts (buf, "]");
            return 1;
        }
    }

    return 1;
}
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);
}
Beispiel #22
0
static enum ud_tree_walk_stat
x_tag_link (struct udoc *ud, struct udr_ctx *render_ctx)
{
  char cnum[FMT_ULONG];
  struct buffer *out = &render_ctx->uc_out->uoc_buffer;
  const struct ud_node *cur_node = render_ctx->uc_tree_ctx->utc_state->utc_node;
  const char *ref_link;
  const char *ref_text;
  unsigned long dummy;
  unsigned long ref_len;
  const struct ud_ref *ref;
  const struct ud_part *part;

  ref_link = cur_node->un_next->un_data.un_str;
  ref_text = (cur_node->un_next->un_next) ?
    cur_node->un_next->un_next->un_data.un_str : ref_link;
  ref_len = str_len (ref_link);

  ud_assert (ud_oht_get (&ud->ud_ref_names, ref_link, ref_len, (void *) &ref, &dummy));
  ud_assert (part = ud_part_get (ud, ref->ur_part_index));

  /* only link to file if splitting */
  buffer_puts (out, "<a href=\"");
  if (ud->ud_opts.ud_split_thresh) {
    cnum[fmt_ulong (cnum, part->up_file)] = 0;
    buffer_puts3 (out, cnum, ".", render_ctx->uc_render->ur_data.ur_suffix);
  }

  buffer_puts5 (out, "#r_", ref_link, "\">", ref_text, "</a>");
  return UD_TREE_OK;
}
Beispiel #23
0
int main(int argc,char **argv,char **envp)
{
  int piin[2];
  int piout[2];

  pid[fmt_ulong(pid,getpid())] = 0;

  if (argc < 2)
    strerr_die1x(100,"recordio: usage: recordio program [ arg ... ]");

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

  switch(fork()) {
    case -1:
      strerr_die2sys(111,FATAL,"unable to fork: ");
    case 0:
      sig_ignore(sig_pipe);
      close(piin[0]);
      close(piout[1]);
      doit(piin[1],piout[0]);
  }

  close(piin[1]);
  close(piout[0]);
  if (fd_move(0,piin[0]) == -1)
    strerr_die2sys(111,FATAL,"unable to move descriptors: ");
  if (fd_move(1,piout[1]) == -1)
    strerr_die2sys(111,FATAL,"unable to move descriptors: ");

  pathexec_run(argv[1],argv + 1,envp);
  strerr_die4sys(111,FATAL,"unable to run ",argv[1],": ");
}
Beispiel #24
0
void sig_child_handler() {
  int wstat;
  int i;

  while ((i =wait_nohang(&wstat)) > 0) {
    if (phccmax) ipsvd_phcc_rem(i);
    if (cnum) cnum--;
    if (verbose) {
      bufnum[fmt_ulong(bufnum, i)] =0;
      out(INFO); out("end "); out(bufnum); out(" exit ");
      bufnum[fmt_ulong(bufnum, (unsigned long)wait_exitcode(wstat))] =0;
      out(bufnum); flush("\n");
    }
  }
  if (verbose) connection_status();
}
Beispiel #25
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);
}
Beispiel #26
0
/* Checks the hash against the cookie table. If it matches, returns NULL,
 * else returns "". If error, returns error string. */
const char *sub_sql_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 */
{
  void *result;
  char strnum[FMT_ULONG];

  /* SELECT msgnum FROM table_cookie WHERE msgnum=num and cookie='hash' */
  /* succeeds only is everything correct. */
  if (listno) {			/* only for slaves */
    stralloc_copyb(&params[0],strnum,fmt_ulong(strnum,listno));
    stralloc_copyb(&params[1],strnum,fmt_ulong(strnum,num));
    stralloc_copys(&query,"SELECT listno FROM ");
    stralloc_cats(&query,info->base_table);
    stralloc_cats(&query,"_mlog WHERE ");
    stralloc_cats(&query,sql_checktag_listno_where_defn);

    result = sql_select(info,&query,2,params);
    if (sql_fetch_row(info,result,1,params)) {
      sql_free_result(info,result);
      return "";		/* already done */
    }
    /* no result */
    sql_free_result(info,result);
  }

  stralloc_copyb(&params[0],strnum,fmt_ulong(strnum,num));
  stralloc_copyb(&params[1],hash,COOKIE);

  stralloc_copys(&query,"SELECT msgnum FROM ");
  stralloc_cats(&query,info->base_table);
  stralloc_cats(&query,"_cookie WHERE ");
  stralloc_cats(&query,sql_checktag_msgnum_where_defn);

  result = sql_select(info,&query,2,params);
  if (!sql_fetch_row(info,result,1,params)) {
    sql_free_result(info,result);
    return "";			/* not parent => perm error */
  }
  sql_free_result(info,result);	/* success! cookie matches */
  return (char *)0;
  (void)action;
  (void)seed;
}
Beispiel #27
0
void numwrite(void)
{
  int fd;
  int i;

  i = fmt_ulong(strnum,msgnum);
  strnum[i++] = ':';
  i += fmt_ulong(strnum+i,cumsize);
  strnum[i++] = '\n';

  if ((fd = open_trunc("numnew")) == -1
      || write(fd, strnum, i) != i
      || fsync(fd) == -1
      || close(fd) == -1)
    strerr_die2sys(111,FATAL,MSG1(ERR_CREATE,"numnew"));
  wrap_rename("numnew","num");
}
Beispiel #28
0
static enum ud_tree_walk_stat
rt_file_init (struct udoc *ud, struct udr_ctx *rc)
{
    char cnum[FMT_ULONG];
    unsigned long index;
    unsigned long max;
    struct ud_ref *ref;
    const struct ud_node *node;
    struct buffer *buf = &rc->uc_out->uoc_buffer;

    /* udoc preamble */
    buffer_puts (buf, "% udoc preamble\n");
    buffer_puts (buf, tex_header);
    buffer_puts (buf, "\n");

    /* output \useURL list */
    buffer_puts (buf, "% urls\n");
    max = ud_oht_size (&ud->ud_link_exts);
    for (index = 0; index < max; ++index) {
        ud_assert (ud_oht_get_index (&ud->ud_link_exts, index, (void *) &ref));
        node = ref->ur_node->un_next;
        buffer_puts (buf, "\\useURL[url_");
        buffer_put (buf, cnum, fmt_ulong (cnum, index));
        buffer_puts3 (buf, "][", node->un_data.un_str, "][][");
        if (node->un_next)
            buffer_puts2 (buf, node->un_next->un_data.un_str, "]\n");
        else
            buffer_puts2 (buf, node->un_data.un_str, "]\n");
    }
    buffer_puts (buf, "\n");

    /* output styles */
    buffer_puts (buf, "% styles\n");
    max = ud_oht_size (&ud->ud_styles);
    for (index = 0; index < max; ++index) {
        ud_assert (ud_oht_get_index (&ud->ud_styles, index, (void *) &ref));
        if (!udr_print_file (ud, rc, ref->ur_node->un_next->un_data.un_str, 0, 0))
            return UD_TREE_FAIL;
    }

    buffer_puts (buf, "\n");
    buffer_puts (buf, "\\starttext\n");

    /* optional header */
    buffer_puts (buf, "% render-header\n");
    if (ud->ud_render_header)
        if (!udr_print_file (ud, rc, ud->ud_render_header, 0, 0))
            return UD_TREE_FAIL;

    /* document title */
    if (rc->uc_part->up_title) {
        buffer_puts (buf, "\\chapter{");
        buffer_puts2 (buf, rc->uc_part->up_title, "}\n");
    }

    return UD_TREE_OK;
}
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);
}
Beispiel #30
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;
}