示例#1
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);
}
示例#2
0
int httpdate(stralloc *sa,struct tai *t)
{
  struct caltime ct;
  int i;

  caltime_utc(&ct,t,&i,(int *) 0);

  if (i < 0) i = 0;
  if (i > 6) i = 6;
  if (!stralloc_copys(sa,weekday[i])) return 0;
  if (!stralloc_catuint0(sa,ct.date.day,2)) return 0;
  i = ct.date.month - 1;
  if (i < 0) i = 0;
  if (i > 11) i = 11;
  if (!stralloc_cats(sa,month[i])) return 0;
  if (!stralloc_catuint0(sa,ct.date.year,0)) return 0;
  if (!stralloc_cats(sa," ")) return 0;
  if (!stralloc_catuint0(sa,ct.hour,2)) return 0;
  if (!stralloc_cats(sa,":")) return 0;
  if (!stralloc_catuint0(sa,ct.minute,2)) return 0;
  if (!stralloc_cats(sa,":")) return 0;
  if (!stralloc_catuint0(sa,ct.second,2)) return 0;
  if (!stralloc_cats(sa," GMT")) return 0;

  return 1;
}
示例#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;
}
static char *set_workdir(char *action)
{
  if (case_starts(action,"digest")) {			/* digest */
    action += 6;
    stralloc_cats(&outlocal,"-digest");
    workdir = "digest";
    flagdig = FLD_DIGEST;
  } else if (case_starts(action,ACTION_ALLOW)) {	/* allow */
    action += str_len(ACTION_ALLOW);
    stralloc_append(&outlocal,'-');
    stralloc_cats(&outlocal,ACTION_ALLOW);
    workdir = "allow";
    flagdig = FLD_ALLOW;
  } else if (case_starts(action,ACTION_DENY)) {		/* deny */
    action += str_len(ACTION_DENY);
    stralloc_append(&outlocal,'-');
    stralloc_cats(&outlocal,ACTION_DENY);
    workdir = "deny";
    flagdig = FLD_DENY;
  }
  else {
    workdir = ".";
    flagdig = 0;
  }

  if (flagdig)				/* zap '-' after db specifier */
    if (*(action++) != '-') die_badaddr();

  return action;
}
示例#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;
}
示例#6
0
static const char *remove_table(struct subdbinfo *info,
                                const char *suffix1,
                                const char *suffix2)
{
    sqlite3_stmt *stmt;
    int res;

    if (table_exists(info,suffix1,suffix2) == 0)
        return 0;

    if (!stralloc_copys(&line,"DROP TABLE ")) die_nomem();
    if (!stralloc_cats(&line,info->base_table)) die_nomem();
    if (!stralloc_cats(&line,suffix1)) die_nomem();
    if (!stralloc_cats(&line,suffix2)) die_nomem();
    if (!stralloc_0(&line)) die_nomem();

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

    res = sqlite3_step(stmt);
    sqlite3_finalize(stmt);

    if (res != SQLITE_DONE)
        return sqlite3_errmsg((sqlite3*)info->conn);
    return 0;
}
示例#7
0
文件: log.c 项目: bruceg/ezmlm-idx
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;
}
示例#8
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;
}
示例#9
0
static void make_name(struct subdbinfo *info,
		      const char *suffix1,
		      const char *suffix2,
		      int terminate)
{
  stralloc_copys(&name,info->base_table);
  if (suffix1) stralloc_cats(&name,suffix1);
  if (suffix2) stralloc_cats(&name,suffix2);
  if (terminate) stralloc_0(&name);
}
示例#10
0
int write_fifodir(char *dirname, stralloc *sa, void (*oaw_func)(char *, stralloc *))
{
  DIR *dir = NULL;
  stralloc name = {0};
  struct dirent *x = NULL;
  static struct stat st;

  /* read directory */
  dir = opendir(dirname);
  if(dir == NULL)
    {
      strerr_warn3("can't opendir() ", dirname, ": ", &strerr_sys);
      return -1;
    }

  while (x = readdir(dir))
    {
      if(x == NULL)
	{
	  strerr_warn3("can't readdir() ", dirname, ": ", &strerr_sys);
	  if(name.a) 
	    stralloc_free(&name);
	  return -1;
	}

      /* Ignore everything starting with a . */
      if(x->d_name[0] != '.')
	{ 
	  stralloc_copys(&name, dirname);
	  stralloc_cats(&name, "/");
	  stralloc_cats(&name, x->d_name);
	  stralloc_0(&name);

	  if(stat(name.s, &st) == -1)
	    {
	      strerr_warn2("can't stat ", name.s, &strerr_sys);
	    }

	  if(S_ISFIFO(st.st_mode))
	    {
	      oaw_func(name.s, sa);
	    }
	  else
	    {
	      buffer_puts(buffer_2, "ddnsd: warning: ");
	      buffer_puts(buffer_2, name.s);
	      buffer_puts(buffer_2, " is no fifo, ignoring\n");
	      buffer_flush(buffer_2);
	    }
	}
    }
  closedir(dir);  

  return 0;
}
示例#11
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;
}
示例#12
0
int pathexec_env(const char *s,const char *t)
{
  if (!s) return 1;
  if (!stralloc_copys(&tmp,s)) return 0;
  if (t) {
    if (!stralloc_cats(&tmp,"=")) return 0;
    if (!stralloc_cats(&tmp,t)) return 0;
  }
  if (!stralloc_0(&tmp)) return 0;
  return stralloc_cat(&plus,&tmp);
}
示例#13
0
static int stralloc_cat_table(stralloc *s,
                              const struct subdbinfo *info,
                              const char *table)
{
    if (!stralloc_cats(s,info->base_table)) return 0;
    if (table) {
        if (!stralloc_append(s,"_")) return 0;
        if (!stralloc_cats(s,table)) return 0;
    }
    return 1;
}
示例#14
0
int
env_addmodif(stralloc* sa, const char* s, const char* t) {
  size_t oldlen = sa->len;
  if(!s)
    return 1;
  if(!stralloc_cats(sa, s))
    return 0;
  if((t && (!stralloc_catb(sa, "=", 1) || !stralloc_cats(sa, t))) || !stralloc_0(sa)) {
    sa->len = oldlen;
    return 0;
  }
  return 1;
}
示例#15
0
/*
 * generate the search command for a given manual;
 * return a stralloc with the command string */
stralloc generateSearchCMD( char *manual , stralloc temp )
{  
    stralloc_cats( &temp, findCMD );            // append "/usr/bin/find "
    //stralloc_cats( &temp, searchDIR_1 );        // append "/usr/local/share/man "
    //stralloc_cats( &temp, searchDIR_2 );        // append "/usr/man "
    stralloc_cats( &temp, searchDIR_3 );        // append "/usr/share/man "
    stralloc_cats( &temp, findOption);          // append "-name "
    stralloc_cats( &temp, manual );             // append "[uncrustify]"
    stralloc_cats( &temp, findAppendix );       // append ".* "
    //stralloc_cats( &temp, ignoreError);         // append "2>/dev/null"
    //stralloc_cats( &temp, topResult );          // append "| head -1"
    return temp;
}
示例#16
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;
}
static int makeuniquename (stralloc *sa, char const *path, char const *magic)
{
  unsigned int base = sa->len ;
  int wasnull = !sa->s ;
  if (!stralloc_cats(sa, path)) return 0 ;
  if (!stralloc_cats(sa, magic)) goto err ;
  if (random_sauniquename(sa, 8) == -1) goto err ;
  if (!stralloc_0(sa)) goto err ;
  return 1 ;

err:
  if (wasnull) stralloc_free(sa) ; else sa->len = base ;
  return 0 ;
}
示例#18
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);
}
示例#19
0
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 ;
}
示例#20
0
文件: sender.c 项目: abh/ezmlm-idx
static int decode_prvs(const char *s)
{
  /* The BATV standard says the user part should have the format
   * "tag-type=tag-val=loc-core" where "loc-core" is the original local
   * address, but all the examples I could find in actual use had the
   * last two parts reversed.  What a mess.  So, I have to check if
   * either the first or second part is a valid prvs tag, and use the
   * other one. */
  int at;
  int sep;
  if (s[at = str_rchr(s,'@')] == 0)
    return 0;
  /* Format: [email protected] */
  for (sep = 5; sep < at && s[sep] != '='; ++sep)
    ;
  if (sep >= at)
    return 0;
  if (is_prvs_tag(s+5,sep-5)) {
    if (!stralloc_copys(&realsender,s+sep+1)) die_nomem();
    if (!stralloc_0(&realsender)) die_nomem();
    return 1;
  }
  /* Format: [email protected] */
  for (sep = at - 1; sep > 5 && s[sep] != '='; --sep)
    ;
  if (is_prvs_tag(s + sep + 1, at - sep - 1)) {
    if (!stralloc_copyb(&realsender,s+5,sep-5)) die_nomem();
    if (!stralloc_cats(&realsender,s+at)) die_nomem();
    if (!stralloc_0(&realsender)) die_nomem();
    return 1;
  }
  return 0;
}
示例#21
0
static int doit(stralloc *work,const char *rule)
{
  char ch;
  unsigned int colon;
  unsigned int prefixlen;

  ch = *rule++;
  if ((ch != '?') && (ch != '=') && (ch != '*') && (ch != '-')) return 1;
  colon = str_chr(rule,':');
  if (!rule[colon]) return 1;

  if (work->len < colon) return 1;
  prefixlen = work->len - colon;
  if ((ch == '=') && prefixlen) return 1;
  if (case_diffb(rule,colon,work->s + prefixlen)) return 1;
  if (ch == '?') {
    if (byte_chr(work->s,prefixlen,'.') < prefixlen) return 1;
    if (byte_chr(work->s,prefixlen,':') < prefixlen) return 1;
    if (byte_chr(work->s,prefixlen,'[') < prefixlen) return 1;
    if (byte_chr(work->s,prefixlen,']') < prefixlen) return 1;
  }

  work->len = prefixlen;
  if (ch == '-') work->len = 0;
  return stralloc_cats(work,rule + colon + 1);
}
示例#22
0
int stralloc_copys(stralloc *r, const void *xv) {

    if (!r) { errno = EINVAL; return 0; }

    r->len = 0;
    return stralloc_cats(r, xv);
}
示例#23
0
static const char *create_table(struct subdbinfo *info,
				const char *suffix1,
				const char *suffix2,
				const char *definition)
{
  make_name(info,suffix1,suffix2,1);
  if (sql_table_exists(info,name.s) > 0)
    return 0;
  stralloc_copys(&query,"CREATE TABLE ");
  stralloc_cats(&query,name.s);
  stralloc_cats(&query," (");
  stralloc_cats(&query,definition);
  stralloc_cats(&query,")");
  stralloc_0(&query);
  return sql_create_table(info,query.s);
}
示例#24
0
int
filter_start(stralloc *filter)
{
	if (!stralloc_copys(filter, ""))
		return 0;
	if (objectclass.s != (char *)0 && objectclass.len != 0) {
		/* (&(objectclass=...)%searchfilter%) */
		if (!stralloc_copys(filter, "(&(") ||
		    !stralloc_cats(filter, LDAP_OBJECTCLASS) ||
		    !stralloc_cats(filter, "=") ||
		    !stralloc_cat(filter, &objectclass) ||
		    !stralloc_cats(filter, ")"))
			return 0;
	}
	return 1;
}
int absolutepath (stralloc *sa, const char *path)
{
  int r = 1 ;
  if (!path) r = stralloc_copys(sa, "/") ;
  else if (path[0] == '/') r = stralloc_copys(sa, path) ;
  else
  {
    unsigned int n = 0 ;
    for (;;)
    {
      n += 1024 ;
      if (!stralloc_ready(sa, n))
      {
        r = 0 ;
        break ;
      }
      if (getcwd(sa->s, n)) break ;
      if (errno != ENOMEM)
      {
        r = 0 ;
        break ;
      }
    }
    sa->len = str_len(sa->s) ;
    if (r) r = stralloc_append(sa, "/") && stralloc_cats(sa, path) ;
    if (!r) stralloc_free(sa) ;
  }
  return r ? stralloc_0(sa) : 0 ;
}
示例#26
0
int sql_table_exists(struct subdbinfo *info,
		     const char *name)
{
  MYSQL_RES *result;

  stralloc_copys(&line,"SELECT 0 FROM ");
  stralloc_cats(&line,name);
  stralloc_cats(&line," LIMIT 1");
  stralloc_0(&line);
  if (mysql_real_query((MYSQL*)info->conn,line.s,line.len) == 0) {
    if ((result = mysql_use_result((MYSQL*)info->conn)) != 0)
      mysql_free_result(result);
    return 1;
  }
  return (mysql_errno((MYSQL*)info->conn) == ER_BAD_TABLE_ERROR) ? 0 : -1;
}
示例#27
0
static void dispatch(const char *dir,const char *def)
     /* Hand off control to one of the command files in the list directory. */
{
  if (!is_dir(dir))
    return;
  if (!stralloc_append(&basedir,"/")) die_nomem();
  if (!stralloc_cats(&basedir,dir)) die_nomem();
  /* FIXME: set up $EXT $EXT2 $EXT3 $EXT4 ?  Is it feasable? */
  if (def == 0 || *def == 0)
    execute("editor",0);
  else if (str_diff(def,"owner") == 0)
    execute("owner",0);
  else if (str_diff(def,"digest-owner") == 0)
    execute("owner",0);
  else {
    try_dispatch(def,"digest-return-",14,"digest/bouncer");
    try_dispatch(def,"return-",7,"bouncer");
    try_dispatch(def,"confirm-",8,"confirmer");
    try_dispatch(def,"discard-",8,"confirmer");
    try_dispatch(def,"accept-",7,"moderator");
    try_dispatch(def,"reject-",7,"moderator");
    /* If nothing else matches, call the manager. */
    execute("manager",def);
  }
}
示例#28
0
文件: ezmlm-get.c 项目: abh/ezmlm-idx
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));
    }
}
示例#29
0
static int
it_loops_dms (direntry *d, void *data)
{
    stralloc **sas = data;
    int i;
    size_t l;

    if (d->d_type != DT_BLK)
        return 0;

    if (!str_diffn (d->d_name, "loop", 4) && d->d_name[4] >= '0' && d->d_name[4] <= '9')
        i = 0;
    else if (!str_diffn (d->d_name, "dm-", 3))
        i = 1;
    else
        return 0;

    l = sas[i]->len;
    if (!stralloc_cats (sas[i], "/dev/") || !stralloc_cats (sas[i], d->d_name)
            || !stralloc_0 (sas[i]))
        aa_strerr_diefu1sys (2, "stralloc_catb");

    /* /dev/loop* always exists, let's find the actual ones */
    if (i == 0)
    {
        int fd;

        fd = open_read (sas[i]->s + l);
        if (fd < 0)
            sas[i]->len = l;
        else
        {
            struct loop_info64 info;
            int r;

            /* make sure it is one/in use; we get ENXIO when not */
            r = ioctl (fd, LOOP_GET_STATUS64, &info);
            if (r < 0)
                /* treat all errors the same though */
                sas[i]->len = l;

            fd_close (fd);
        }
    }

    return 0;
}
示例#30
0
文件: ezmlm-get.c 项目: abh/ezmlm-idx
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);
  }
}