示例#1
0
文件: bcron-exec.c 项目: 0xef53/bcron
static void handle_packet(struct connection* c)
{
  str* packet;
  const char* id;
  const char* runas;
  const char* command;
  const char* envstart;
  long slot;
  unsigned int i;
  struct passwd* pw;

  packet = &c->packet;
  id = packet->s;
  if (*id == NUL)
    FAIL(id, "DInvalid ID");

  if ((slot = pick_slot()) < 0)
    FAIL(id, "DCould not allocate a slot");
  wrap_str(str_copys(&slots[slot].id, id));

  if ((i = str_findfirst(packet, NUL) + 1) >= packet->len)
    FAIL(id, "DInvalid packet");
  runas = packet->s + i;
  if (*runas == NUL
      || (pw = getpwnam(runas)) == 0)
    FAIL(id, "DInvalid username");

  if ((i = str_findnext(packet, NUL, i) + 1) >= packet->len)
    FAIL(id, "DInvalid packet");
  command = packet->s + i;

  if ((i = str_findnext(packet, NUL, i) + 1) >= packet->len)
    envstart = 0;
  else {
    envstart = packet->s + i;
    wrap_str(str_catc(packet, 0));
  }

  if (!init_slot(slot, pw))
    FAIL(id, "ZOut of memory");
  start_slot(slot, command, envstart);
}
/* actually do the log entry */
static void dosqlog(void)
{
  str sql;
  str mq, mr, md;
  unsigned int i, ni;

  if(!sqlseq) return;		/* nothing happened */

  str_init(&sql);
  str_init(&mq);
  str_init(&mr);
  str_init(&mflags);
  addflag("greylist", "greylist", 1);
  addflag("sump", "sump", 0);
  addflag("dblhelo", "dblhelo", 0);
  addflag("dblfrom", "dblfrom", 1);
  addflag("badrcpt", "badrcpt", 1);
  addflag("badbatv", "badbatv", 1);
  addflag("rcptrule", "badabuse", 1);

  str_copys(&sql, "update mail set flags='");
  str_cat(&sql, &mflags);
  sqlquote(&qsender, &mq);
  str_cats(&sql, "',mailfrom='");
  str_cat(&sql, &mq);
  /* envelope domain */
  i = str_findfirst(&qsender, '@');
  if(i < qsender.len) {
    str_init(&md);
    str_copyb(&md, qsender.s+i+1, qsender.len-i-1);
    sqlquote(&md, &mq);
    str_cats(&sql, "',envdomain='");
    str_cat(&sql, &mq);
  }
  str_cats(&sql, "' where serial=");
  str_cat(&sql, &sqlseqstr);
  sqlquery(&sql, 0);

  /* now add the recipients */
  for(i = 0; i < qrecips.len ; i = ni+1) {
    ni = str_findnext(&qrecips, 0, i);

    str_copyb(&mr, qrecips.s+i, ni-i);
    sqlquote(&mr, &mq);
    str_copys(&sql,"insert into mailrcpt(serial,rcptto) values(");
    str_cat(&sql, &sqlseqstr);
    str_cats(&sql, ",'");
    str_cat(&sql, &mq);
    str_cats(&sql, "')");
    sqlquery(&sql, 0);
  }
}
示例#3
0
文件: sasl_plain.c 项目: bruceg/cvm
static int response1(struct sasl_state* ss,
		     const str* response, str* challenge)
{
  unsigned i;
  unsigned j;
  if (response->len == 0)
    return SASL_RESP_BAD;
  if ((i = str_findfirst(response, 0)) == (unsigned)-1)
    return SASL_RESP_BAD;
  ++i;
  if ((j = str_findnext(response, 0, i)) == (unsigned)-1)
    return SASL_RESP_BAD;
  ++j;
  if (!str_copyb(&ss->username, response->s + i, j - i - 1))
    return SASL_TEMP_FAIL;
  return sasl_authenticate_plain(ss, response->s+i, response->s+j);
  (void)challenge;
}
示例#4
0
static void handle_auth_plain_response(str* line, ssize_t offset)
{
  int start;
  int end;

  saw_auth_plain = 0;
  if (base64decode(line->s + offset, line->len - offset, &tmpstr)) {
    /* tmpstr should now contain "AUTHORIZATION\0AUTHENTICATION\0PASSWORD" */
    if ((start = str_findfirst(&tmpstr, NUL)) >= 0
	&& (end = str_findnext(&tmpstr, NUL, ++start)) > start) {
      make_username(tmpstr.s + start, end - start, "AUTH PLAIN ");
      str_splice(&tmpstr, start, end - start, &username);
      line->len = offset;
      base64encode(tmpstr.s, tmpstr.len, line);
      str_catb(line, CRLF, 2);
    }
  }
}