Exemplo n.º 1
0
Arquivo: hash.c Projeto: SySof/sysof
void hash_compare(hash dict, hash text, int show_missing) {
    for(int i = 0; i < HASHLEN; i++) {
        hash_elem* elem = text[i];
        if(elem == NULL) {
            continue;
        }
        while(elem->next != NULL) {
            if(show_missing) {
                if (!hash_contains_string(dict, elem->sa)) {
                    stralloc_0(&(elem->sa));
                    printf("%s\n", elem->sa.s);
                }
            } else {
                if (hash_contains_string(dict, elem->sa)) {
                    stralloc_0(&(elem->sa));
                    printf("%s\n", elem->sa.s);
                }
            }
            elem = elem->next;
        }
        if(show_missing) {
            if (!hash_contains_string(dict, elem->sa)) {
                stralloc_0(&(elem->sa));
                printf("%s\n", elem->sa.s);
            }
        } else {
            if (hash_contains_string(dict, elem->sa)) {
                stralloc_0(&(elem->sa));
                printf("%s\n", elem->sa.s);
            }
        }
    }
}
Exemplo n.º 2
0
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;
}
Exemplo n.º 3
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;
}
Exemplo n.º 4
0
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);
}
Exemplo n.º 5
0
static int
pls_reader(playlist* pl) {
  int ret;
    static playlist_entry entry;
  buffer* inbuf = pl->ptr;
  stralloc line;
  stralloc_init(&line);
  if(( ret = buffer_getline_sa(inbuf, &line))) {
    size_t index2, index;
    index2 = index = 0;
    while(line.len > 1 &&
          (line.s[line.len - 1] == '\r' || line.s[line.len - 1] == '\n'))
      line.len--;
    stralloc_0(&line);
    if(!str_diffn(&line.s[index], "Number", 6)) {
    } else if(line.s[index] == '[') {
    } else if((index2 = str_chr(&line.s[index], '=')) > 0) {
      unsigned long trackno = 0;
      index = index2;
      index2++;
      do { index--; } while(isdigit(line.s[index]) && index > 0);
      scan_ulong(&line.s[index], &trackno);
      if(!str_diffn(&line.s[index], "File", 4)) {
        stralloc_copys(&entry.path, &line.s[index2]);
        stralloc_0(&entry.path);
      } else if(!str_diffn(&line.s[index], "Title", 5)) {
        stralloc_copys(&entry.title, &line.s[index2]);
        stralloc_0(&entry.title);
      } else if(!str_diffn(&line.s[index], "Length", 6)) {
        unsigned long len;
        scan_ulong(&line.s[index2], &len);
        entry.length = len;
      }
      /*
      uint32 index = 8;
      index += scan_ulong(&line.s[index], &len);
      entry.length = len;
      index++;
      stralloc_copys(&entry.title, &line.s[index]);
      stralloc_0(&entry.title);
      */
    } else {
      /*
      stralloc_copy(&entry.path, &line);
      stralloc_0(&entry.path);
      if(pl->callback) {
      pl->callback(pl, &entry.title, &entry.path, entry.length);
      }*/
    }
  }
  return ret;
}
Exemplo n.º 6
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;
}
Exemplo n.º 7
0
int
qldap_ctrl_login(void)
{
	if (control_rldef(&ldap_login, "control/ldaplogin", 0, "") == -1)
		return -1;
	if (!stralloc_0(&ldap_login)) return -1;
	logit(64, "init_ldap: control/ldaplogin: %s\n", ldap_login.s);

	if (control_rldef(&ldap_password, "control/ldappassword", 0, "") == -1)
		return -1;
	if (!stralloc_0(&ldap_password)) return -1;
	logit(64, "init_ldap: control/ldappassword: %s\n", ldap_password.s);

	return 0;
}
Exemplo n.º 8
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;
}
Exemplo n.º 9
0
char *get_name(FILE *f)
{
	int c;
	stralloc name = {0};
	char *strp;
	char d;

	/* consume leading whitespace */
	do {
		c = fgetc(f);	
	} while(isspace(c));
	ungetc(c, f);

	/* append non-whitespace chars */
	while (1) {
		c = fgetc(f);
		if (c < 0 || isspace(c)) {
			stralloc_0(&name);
			strp = strdup(name.s);
			stralloc_free(&name);
			return strp;
		}
		d = c;
		stralloc_append(&name, &d);
	}
}
Exemplo n.º 10
0
int
qldap_get_dotmode(qldap *q, stralloc *dm)
{
	int	r;

	/* get and check the status of the account */
	r = qldap_get_attr(q, LDAP_DOTMODE, &ldap_attr, SINGLE_VALUE);
	if (r == NOSUCH) {
		if (!stralloc_copy(dm, &dotmode)) return ERRNO;
		return OK;
	}
	if (r != OK)
		return r;

	if (!case_diffs(DOTMODE_LDAPONLY, ldap_attr.s)) {
		if (!stralloc_copys(dm, DOTMODE_LDAPONLY)) return ERRNO;
	} else if (!str_diff(DOTMODE_LDAPWITHPROG, ldap_attr.s)) {
		if (!stralloc_copys(dm, DOTMODE_LDAPWITHPROG)) return ERRNO;
	} else if (!str_diff(DOTMODE_DOTONLY, ldap_attr.s)) {
		if (!stralloc_copys(dm, DOTMODE_DOTONLY)) return ERRNO;
	} else if (!str_diff(DOTMODE_BOTH, ldap_attr.s)) {
		if (!stralloc_copys(dm, DOTMODE_BOTH)) return ERRNO;
	} else if (!str_diff(DOTMODE_NONE, ldap_attr.s)) {
		if (!stralloc_copys(dm, DOTMODE_NONE)) return ERRNO;
	} else {
		return ILLVAL;
	}
	if (!stralloc_0(dm)) return ERRNO;
	return OK;
}
Exemplo n.º 11
0
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 ;
}
Exemplo n.º 12
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;
}
Exemplo n.º 13
0
void main(int argc,char **argv)
{
  int fdlock;
  unsigned long delay;
  (void) umask(022);
  sig_pipeignore();
  when = now();

  getconfopt(argc,argv,options,1,0);
  if (flagreturn < 0)
    /* default to returning timed-out messages */
    flagreturn = !getconf_isset("noreturnposts");

  getconf_line(&modtime,"modtime",0);
  if (!stralloc_0(&modtime)) die_nomem();
  scan_ulong(modtime.s,&delay);
  if (!delay) delay = DELAY_DEFAULT;
  else if (delay < DELAY_MIN) delay = DELAY_MIN;
  else if (delay > DELAY_MAX) delay = DELAY_MAX;
  older = (unsigned long) when - 3600L * delay;	/* delay is in hours */

  fdlock = lockfile("mod/lock");

  dodir("mod/pending/",flagreturn);
  dodir("mod/accepted/",0);
  dodir("mod/rejected/",0);
  dodir("mod/unconfirmed/",0);
  _exit(0);
}
Exemplo n.º 14
0
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;
}
Exemplo n.º 15
0
void to_owner(void)
{
	stralloc_copy(&owner,&outlocal);
	stralloc_cats(&owner,"-owner@");
	stralloc_cat(&owner,&outhost);
	stralloc_0(&owner);
	qmail_to(&qq,owner.s);
}
Exemplo n.º 16
0
/* take an username and create a filename from it by 
   prepending datadir, return it in \0 terminated tmpname */
void create_datafilename(stralloc *tmpname, stralloc *username)
{
  /* create the filename in our datastructure */
  if(!stralloc_copys(tmpname, datadir)) die_nomem();
  if(!stralloc_cats(tmpname, "/")) die_nomem();
  if(!stralloc_cat(tmpname, username)) die_nomem();
  if(!stralloc_0(tmpname)) die_nomem();
}
Exemplo n.º 17
0
void pop3_user(char *arg)
{
  if (!*arg) { err_syntax(); return; }
  okay();
  seenuser = 1;
  if (!stralloc_copys(&username,arg)) die_nomem(); 
  if (!stralloc_0(&username)) die_nomem(); 
}
Exemplo n.º 18
0
static int open_template(stralloc *fn)
{
  int fd;
  struct stat st;
  stralloc_0(fn);
  if (stat(fn->s,&st) == -1)
    strerr_die2sys(111,FATAL,MSG1(ERR_STAT,fn->s));
  if (S_ISDIR(st.st_mode)) {
    --fn->len;
    stralloc_cats(fn,TXT_EZMLMRC);
    stralloc_0(fn);
  }
  if ((fd = open_read(fn->s)) == -1) {
    if (errno != error_noent)
      strerr_die2sys(111,FATAL,MSG1(ERR_OPEN,fn->s));
    else
      strerr_die3x(100,FATAL,template.s,MSG(ERR_NOEXIST));
Exemplo n.º 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);
}
Exemplo n.º 20
0
static const char *makepath(const char *fn)
{
  if (!stralloc_copy(&path,&basedir)) die_nomem();
  if (fn) {
    if (!stralloc_append(&path,"/")) die_nomem();
    if (!stralloc_cats(&path,fn)) die_nomem();
  }
  if (!stralloc_0(&path)) die_nomem();
  return path.s;
}
Exemplo n.º 21
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);
}
Exemplo n.º 22
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;
}
Exemplo n.º 23
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;
}
Exemplo n.º 24
0
int
filter_end(stralloc *filter)
{
	if (objectclass.s != (char *)0 && objectclass.len != 0)
		if (!stralloc_cats(filter, ")"))
			return 0;

	if (!stralloc_0(filter))
		return 0;
	return 1;
}
Exemplo n.º 25
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);
}
Exemplo n.º 26
0
/* open connection to the SQL server, if it isn't already open. */
static const char *_opensub(struct subdbinfo *info)
{
  if (!(sqlite3*)info->conn) {
    stralloc_copys(&line,info->db);
    stralloc_cats(&line,".db");
    stralloc_0(&line);
    if (sqlite3_open_v2(line.s, (sqlite3**)&info->conn, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL) != SQLITE_OK)
	return sqlite3_errmsg((sqlite3*)info->conn); /* init */
  }
  return (char *) 0;
}
Exemplo n.º 27
0
char *dirname (char *s)
{
  static stralloc dirname_sa = STRALLOC_ZERO ;
  static char dot0[2] = "." ;
  char *dot = dot0 ;
  if (!s) return dot ;
  dirname_sa.len = 0 ;
  if (!sadirname(&dirname_sa, s, str_len(s))) return 0 ;
  if (!stralloc_0(&dirname_sa)) return 0 ;
  return dirname_sa.s ;
}
Exemplo n.º 28
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);
}
Exemplo n.º 29
0
int control_readfile(stralloc *sa,char *fn,int flagme)
{
  buffer b;
  int fd;
  int match;

  if (!stralloc_copys(sa,"")) return -1;

  fd = open_read(fn);
  if (fd == -1)
  {
    if (errno == ENOENT)
    {
      if (flagme && meok)
      {
        if (!stralloc_copy(sa,&me)) return -1;
        if (!stralloc_0(sa)) return -1;
        return 1;
      }
      return 0;
    }
    return -1;
  }

  buffer_init(&b,read,fd,inbuf,sizeof(inbuf));

  for (;;)
  {
    if (getln(&b,&line,&match,'\n') == -1) break;
    if (!match && !line.len) { close(fd); return 1; }
    striptrailingwhitespace(&line);
    if (!stralloc_0(&line)) break;
    if (line.s[0])
      if (line.s[0] != '#')
        if (!stralloc_cat(sa,&line)) break;
    if (!match) { close(fd); return 1; }
  }
  close(fd);
  return -1;
}
Exemplo n.º 30
0
int checkfile(const char *fn)
/* looks for DIR/mod/{pending|rejected|accept}/fn.*/
/* Returns:                                       */
/*          1 found in pending                    */
/*          0 not found                           */
/*         -1 found in accepted                   */
/*         -2 found in rejected                   */
/* Handles errors.                                */
/* ALSO: if found, fnmsg contains the o-terminated*/
/* file name.                                     */
{
  
  if (!stralloc_copys(&fnmsg,"mod/pending/")) die_nomem();
  if (!stralloc_cats(&fnmsg,fn)) die_nomem();
  if (!stralloc_0(&fnmsg)) die_nomem();
  if (stat(fnmsg.s,&st) == -1) {
    if (errno != error_noent)
      strerr_die2sys(111,FATAL,MSG1(ERR_STAT,fnmsg.s));
  } else
      return 1;

  if (!stralloc_copys(&fnmsg,"mod/accepted/")) die_nomem();
  if (!stralloc_cats(&fnmsg,fn)) die_nomem();
  if (!stralloc_0(&fnmsg)) die_nomem();
  if (stat(fnmsg.s,&st) == -1) {
    if (errno != error_noent)
      strerr_die2sys(111,FATAL,MSG1(ERR_STAT,fnmsg.s));
  } else
      return -1;

  if (!stralloc_copys(&fnmsg,"mod/rejected/")) die_nomem();
  if (!stralloc_cats(&fnmsg,fn)) die_nomem();
  if (!stralloc_0(&fnmsg)) die_nomem();
  if (stat(fnmsg.s,&st) == -1) {
    if (errno != error_noent)
      strerr_die2sys(111,FATAL,MSG1(ERR_STAT,fnmsg.s));
  } else
      return -2;
  return 0;
}