Esempio n. 1
0
time_t CheckIfAlreadySeen(const char *Facility,
			  StrBuf *guid,
			  time_t now,
			  time_t antiexpire,
			  eCheckType cType,
			  long ccid,
			  long ioid)
{
	time_t InDBTimeStamp = 0;
	struct UseTable ut;
	struct cdbdata *cdbut;

	if (cType != eWrite)
	{
		SEEN_syslog(LOG_DEBUG, "Loading [%s]", ChrPtr(guid));
		cdbut = cdb_fetch(CDB_USETABLE, SKEY(guid));
		if ((cdbut != NULL) && (cdbut->ptr != NULL)) {
			memcpy(&ut, cdbut->ptr,
			       ((cdbut->len > sizeof(struct UseTable)) ?
				sizeof(struct UseTable) : cdbut->len));
			InDBTimeStamp = now - ut.ut_timestamp;

			if (InDBTimeStamp < antiexpire)
			{
				SEEN_syslog(LOG_DEBUG, "Found - Not expired %ld < %ld", InDBTimeStamp, antiexpire);
				cdb_free(cdbut);
				return InDBTimeStamp;
			}
			else
			{
				SEEN_syslog(LOG_DEBUG, "Found - Expired. %ld >= %ld", InDBTimeStamp, antiexpire);
				cdb_free(cdbut);
			}
		}
		else
		{
			if (cdbut) cdb_free(cdbut);

			SEENM_syslog(LOG_DEBUG, "not Found");
		}

		if (cType == eCheckExist)
			return InDBTimeStamp;
	}

	memcpy(ut.ut_msgid, SKEY(guid));
	ut.ut_timestamp = now;

	SEENM_syslog(LOG_DEBUG, "Saving new Timestamp");
	/* rewrite the record anyway, to update the timestamp */
	cdb_store(CDB_USETABLE,
		  SKEY(guid),
		  &ut, sizeof(struct UseTable) );

	SEENM_syslog(LOG_DEBUG, "Done Saving");
	return InDBTimeStamp;
}
Esempio n. 2
0
void cdbb_close_read(struct cdbb *a)
{
	if (a->r->fd > 0)
		close(a->r->fd);
	cdb_free(a->r);
	free(a->r);
}
Esempio n. 3
0
int respond(char *q,char qtype[2],char ip[4])
{
  int fd;
  int r;
  char key[6];

  tai_now(&now);
  fd = open_read("data.cdb");
  if (fd == -1) return 0;
  cdb_init(&c,fd);

  byte_zero(clientloc,2);
  key[0] = 0;
  key[1] = '%';
  byte_copy(key + 2,4,ip);
  r = cdb_find(&c,key,6);
  if (!r) r = cdb_find(&c,key,5);
  if (!r) r = cdb_find(&c,key,4);
  if (!r) r = cdb_find(&c,key,3);
  if (!r) r = cdb_find(&c,key,2);
  if (r == -1) return 0;
  if (r && (cdb_datalen(&c) == 2))
    if (cdb_read(&c,clientloc,2,cdb_datapos(&c)) == -1) return 0;

  r = doit(q,qtype);

  cdb_free(&c);
  close(fd);
  return r;
}
Esempio n. 4
0
/*
 * List the OpenIDs associated with the currently logged in account
 */
void cmd_oidl(char *argbuf) {
	struct cdbdata *cdboi;
	long usernum = 0L;

	if (CtdlGetConfigInt("c_disable_newu"))
	{
		cprintf("%d this system does not support openid.\n",
			ERROR + CMD_NOT_SUPPORTED);
		return;
	}
	if (CtdlAccessCheck(ac_logged_in)) return;

	cdb_rewind(CDB_OPENID);
	cprintf("%d Associated OpenIDs:\n", LISTING_FOLLOWS);

	while (cdboi = cdb_next_item(CDB_OPENID), cdboi != NULL) {
		if (cdboi->len > sizeof(long)) {
			memcpy(&usernum, cdboi->ptr, sizeof(long));
			if (usernum == CC->user.usernum) {
				cprintf("%s\n", cdboi->ptr + sizeof(long));
			}
		}
		cdb_free(cdboi);
	}
	cprintf("000\n");
}
Esempio n. 5
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;
}
Esempio n. 6
0
/*
 * List ALL OpenIDs in the database
 */
void cmd_oida(char *argbuf) {
	struct cdbdata *cdboi;
	long usernum;
	struct ctdluser usbuf;

	if (CtdlGetConfigInt("c_disable_newu"))
	{
		cprintf("%d this system does not support openid.\n",
			ERROR + CMD_NOT_SUPPORTED);
		return;
	}
	if (CtdlAccessCheck(ac_aide)) return;
	cdb_rewind(CDB_OPENID);
	cprintf("%d List of all OpenIDs in the database:\n", LISTING_FOLLOWS);

	while (cdboi = cdb_next_item(CDB_OPENID), cdboi != NULL) {
		if (cdboi->len > sizeof(long)) {
			memcpy(&usernum, cdboi->ptr, sizeof(long));
			if (CtdlGetUserByNumber(&usbuf, usernum) != 0) {
				usbuf.fullname[0] = 0;
			} 
			cprintf("%s|%ld|%s\n",
				cdboi->ptr + sizeof(long),
				usernum,
				usbuf.fullname
			);
		}
		cdb_free(cdboi);
	}
	cprintf("000\n");
}
Esempio n. 7
0
int rules(void (*callback)(char *,unsigned int),int fd,char *ip,char *host,char *info)
{
  int r;
  cdb_init(&c,fd);
  r = doit(callback,ip,host,info);
  cdb_free(&c);
  return r;
}
Esempio n. 8
0
static void dict_cdbq_close(DICT *dict)
{
    DICT_CDBQ *dict_cdbq = (DICT_CDBQ *) dict;

    cdb_free(&dict_cdbq->cdb);
    close(dict->stat_fd);
    if (dict->fold_buf)
	vstring_free(dict->fold_buf);
    dict_free(dict);
}
Esempio n. 9
0
/*
 * Purge the use table of old entries.
 *
 */
int PurgeUseTable(StrBuf *ErrMsg) {
	int purged = 0;
	struct cdbdata *cdbut;
	struct UseTable ut;
	struct UPurgeList *ul = NULL;
	struct UPurgeList *uptr; 

	/* Phase 1: traverse through the table, discovering old records... */
	if (CheckTDAPVeto(CDB_USETABLE, ErrMsg))
	{
		syslog(LOG_DEBUG, "Purge use table: VETO!");
		return 0;
	}

	syslog(LOG_DEBUG, "Purge use table: phase 1");
	cdb_rewind(CDB_USETABLE);
	while(cdbut = cdb_next_item(CDB_USETABLE), cdbut != NULL) {

		/*
		 * TODODRW: change this to create a new function time_t cdb_get_timestamp( struct cdbdata *)
		 * this will release this file from the serv_network.h
		 * Maybe it could be a macro that extracts and casts the reult
		 */
		if (cdbut->len > sizeof(struct UseTable))
			memcpy(&ut, cdbut->ptr, sizeof(struct UseTable));
		else {
			memset(&ut, 0, sizeof(struct UseTable));
			memcpy(&ut, cdbut->ptr, cdbut->len);
		}
		cdb_free(cdbut);

		if ( (time(NULL) - ut.ut_timestamp) > USETABLE_RETAIN ) {
			uptr = (struct UPurgeList *) malloc(sizeof(struct UPurgeList));
			if (uptr != NULL) {
				uptr->next = ul;
				safestrncpy(uptr->up_key, ut.ut_msgid, sizeof uptr->up_key);
				ul = uptr;
			}
			++purged;
		}

	}

	/* Phase 2: delete the records */
	syslog(LOG_DEBUG, "Purge use table: phase 2");
	while (ul != NULL) {
		cdb_delete(CDB_USETABLE, ul->up_key, strlen(ul->up_key));
		uptr = ul->next;
		free(ul);
		ul = uptr;
	}

	syslog(LOG_DEBUG, "Purge use table: finished (purged %d records)", purged);
	return(purged);
}
Esempio n. 10
0
static void checkpart_deinit(UDF_INIT *iid)
{
	struct _info *info = (struct _info *)iid->ptr;

	cdb_free(&info->cdb);
	close(info->fd);

	fprintf(stderr, "%s\n", info->msg);
	free(info->msg);
	free(info->reason);
	free(iid->ptr);
}
Esempio n. 11
0
SDB_VISIBLE void sdb_free (Sdb* s) {
	if (!s) return;
	cdb_free (&s->db);
	if (s->lock)
		sdb_unlock (sdb_lockfile (s->dir));
	ls_free (s->ns);
	ht_free (s->ht);
	if (s->fd != -1)
		close (s->fd);
	free (s->ndump);
	free (s->dir);
	free (s);
}
Esempio n. 12
0
int respond(char *q,char qtype[2],char ip[4])
{
    int fd;
    int result;

    fd = open_read("data.cdb");
    if (fd == -1) return 0;
    cdb_init(&c,fd);
    result = doit(q,qtype,ip);
    cdb_free(&c);
    close(fd);
    return result;
}
/* Given a file descriptor of an open directory (or AT_FDCWD), CDB->fd,
   try to open the CDB->fd-relative directory, DIR.  If the open succeeds,
   update CDB->fd with the resulting descriptor, close the incoming file
   descriptor, and return zero.  Upon failure, return -1 and set errno.  */
static int
cdb_advance_fd (struct cd_buf *cdb, char const *dir)
{
  int new_fd = openat (cdb->fd, dir,
		       O_RDONLY | O_DIRECTORY | O_NOCTTY | O_NONBLOCK);
  if (new_fd < 0)
    return -1;

  cdb_free (cdb);
  cdb->fd = new_fd;

  return 0;
}
Esempio n. 14
0
/*
 * Purge the EUID Index of old records.
 *
 */
int PurgeEuidIndexTable(void) {
	int purged = 0;
	struct cdbdata *cdbei;
	struct EPurgeList *el = NULL;
	struct EPurgeList *eptr; 
	long msgnum;
	struct CtdlMessage *msg = NULL;

	/* Phase 1: traverse through the table, discovering old records... */
	syslog(LOG_DEBUG, "Purge EUID index: phase 1");
	cdb_rewind(CDB_EUIDINDEX);
	while(cdbei = cdb_next_item(CDB_EUIDINDEX), cdbei != NULL) {

		memcpy(&msgnum, cdbei->ptr, sizeof(long));

		msg = CtdlFetchMessage(msgnum, 0);
		if (msg != NULL) {
			CM_Free(msg);	/* it still exists, so do nothing */
		}
		else {
			eptr = (struct EPurgeList *) malloc(sizeof(struct EPurgeList));
			if (eptr != NULL) {
				eptr->next = el;
				eptr->ep_keylen = cdbei->len - sizeof(long);
				eptr->ep_key = malloc(cdbei->len);
				memcpy(eptr->ep_key, &cdbei->ptr[sizeof(long)], eptr->ep_keylen);
				el = eptr;
			}
			++purged;
		}

	       cdb_free(cdbei);

	}

	/* Phase 2: delete the records */
	syslog(LOG_DEBUG, "Purge euid index: phase 2");
	while (el != NULL) {
		cdb_delete(CDB_EUIDINDEX, el->ep_key, el->ep_keylen);
		free(el->ep_key);
		eptr = el->next;
		free(el);
		el = eptr;
	}

	syslog(LOG_DEBUG, "Purge euid index: finished (purged %d records)", purged);
	return(purged);
}
Esempio n. 15
0
//
// Utility function to fetch the current list of message numbers in a room
//
struct nntp_msglist nntp_fetch_msglist(struct ctdlroom *qrbuf) {
	struct nntp_msglist nm;
	struct cdbdata *cdbfr;

	cdbfr = cdb_fetch(CDB_MSGLISTS, &qrbuf->QRnumber, sizeof(long));
	if (cdbfr != NULL) {
		nm.msgnums = (long*)cdbfr->ptr;
		cdbfr->ptr = NULL;
		nm.num_msgs = cdbfr->len / sizeof(long);
		cdbfr->len = 0;
		cdb_free(cdbfr);
	} else {
		nm.num_msgs = 0;
		nm.msgnums = NULL;
	}
	return(nm);
}
Esempio n. 16
0
void cdb_init(struct cdb *c,int fd)
{
  struct stat st;
  char *x;

  cdb_free(c);
  cdb_findstart(c);
  c->fd = fd;

  if (fstat(fd,&st) == 0) {
    x = mmap(0,st.st_size,PROT_READ,MAP_SHARED,fd,0);
    if (x + 1) {
      c->size = st.st_size;
      c->map = x;
    }
  }
}
Esempio n. 17
0
/*
 * Attach an OpenID to a Citadel account
 */
int attach_openid(struct ctdluser *who, StrBuf *claimed_id)
{
	struct cdbdata *cdboi;
	long fetched_usernum;
	char *data;
	int data_len;
	char buf[2048];

	if (!who) return(1);
	if (StrLength(claimed_id)==0) return(1);

	/* Check to see if this OpenID is already in the database */

	cdboi = cdb_fetch(CDB_OPENID, ChrPtr(claimed_id), StrLength(claimed_id));
	if (cdboi != NULL) {
		memcpy(&fetched_usernum, cdboi->ptr, sizeof(long));
		cdb_free(cdboi);

		if (fetched_usernum == who->usernum) {
			syslog(LOG_INFO, "%s already associated; no action is taken", ChrPtr(claimed_id));
			return(0);
		}
		else {
			syslog(LOG_INFO, "%s already belongs to another user", ChrPtr(claimed_id));
			return(3);
		}
	}

	/* Not already in the database, so attach it now */

	data_len = sizeof(long) + StrLength(claimed_id) + 1;
	data = malloc(data_len);

	memcpy(data, &who->usernum, sizeof(long));
	memcpy(&data[sizeof(long)], ChrPtr(claimed_id), StrLength(claimed_id) + 1);

	cdb_store(CDB_OPENID, ChrPtr(claimed_id), StrLength(claimed_id), data, data_len);
	free(data);

	snprintf(buf, sizeof buf, "User <%s> (#%ld) has claimed the OpenID URL %s\n",
		 who->fullname, who->usernum, ChrPtr(claimed_id));
	CtdlAideMessage(buf, "OpenID claim");
	syslog(LOG_INFO, "%s", buf);
	return(0);
}
Esempio n. 18
0
/*
 * callback to get highest room number when rebuilding control file
 */
void control_find_highest(struct ctdlroom *qrbuf, void *data)
{
	struct ctdlroom room;
	struct cdbdata *cdbfr;
	long *msglist;
	int num_msgs=0;
	int c;
	int room_fixed = 0;
	int message_fixed = 0;
	
	if (qrbuf->QRnumber > CitControl.MMnextroom)
	{
		CitControl.MMnextroom = qrbuf->QRnumber;
		room_fixed = 1;
	}
		
	CtdlGetRoom (&room, qrbuf->QRname);
	
	/* Load the message list */
	cdbfr = cdb_fetch(CDB_MSGLISTS, &room.QRnumber, sizeof(long));
	if (cdbfr != NULL) {
		msglist = (long *) cdbfr->ptr;
		num_msgs = cdbfr->len / sizeof(long);
	} else {
		return;	/* No messages at all?  No further action. */
	}

	if (num_msgs>0)
	{
		for (c=0; c<num_msgs; c++)
		{
			if (msglist[c] > CitControl.MMhighest)
			{
				CitControl.MMhighest = msglist[c];
				message_fixed = 1;
			}
		}
	}
	cdb_free(cdbfr);
	if (room_fixed)
		syslog(LOG_INFO, "Control record checking....Fixed room counter\n");
	if (message_fixed)
		syslog(LOG_INFO, "Control record checking....Fixed message count\n");
	return;
}
Esempio n. 19
0
static void
cdbo_dealloc(CdbObject *self) {  /* del(cdb_o) */

  if (self->name_py != NULL) {

    /* if cdb_o.name is not None:  we open()d it ourselves, so close it */
    if (PyString_Check(self->name_py))
      close(self->c.fd);

    Py_DECREF(self->name_py);
  }

  Py_XDECREF(self->getkey);

  cdb_free(&self->c);

  PyObject_DEL(self);
}
Esempio n. 20
0
/*
 * Get Next Unregistered User
 */
void cmd_gnur(char *argbuf)
{
	struct cdbdata *cdbus;
	struct ctdluser usbuf;

	if (CtdlAccessCheck(ac_aide)) {
		return;
	}

	if ((CtdlGetConfigInt("MMflags") & MM_VALID) == 0) {
		cprintf("%d There are no unvalidated users.\n", CIT_OK);
		return;
	}

	/* There are unvalidated users.  Traverse the user database,
	 * and return the first user we find that needs validation.
	 */
	cdb_rewind(CDB_USERS);
	while (cdbus = cdb_next_item(CDB_USERS), cdbus != NULL) {
		memset(&usbuf, 0, sizeof(struct ctdluser));
		memcpy(&usbuf, cdbus->ptr,
		       ((cdbus->len > sizeof(struct ctdluser)) ?
			sizeof(struct ctdluser) : cdbus->len));
		cdb_free(cdbus);
		if ((usbuf.flags & US_NEEDVALID)
		    && (usbuf.axlevel > AxDeleted)) {
			cprintf("%d %s\n", MORE_DATA, usbuf.fullname);
			cdb_close_cursor(CDB_USERS);
			return;
		}
	}

	/* If we get to this point, there are no more unvalidated users.
	 * Therefore we clear the "users need validation" flag.
	 */

	begin_critical_section(S_CONTROL);
	int flags;
	flags = CtdlGetConfigInt("MMflags");
	flags = flags & (~MM_VALID);
	CtdlSetConfigInt("MMflags", flags);
	end_critical_section(S_CONTROL);
	cprintf("%d *** End of registration.\n", CIT_OK);
}
Esempio n. 21
0
/*
 * Purge OpenID assocations for missing users (theoretically this will never delete anything)
 */
int PurgeStaleOpenIDassociations(void) {
	struct cdbdata *cdboi;
	struct ctdluser usbuf;
	HashList *keys = NULL;
	HashPos *HashPos;
	char *deleteme = NULL;
	long len;
	void *Value;
	const char *Key;
	int num_deleted = 0;
	long usernum = 0L;

	keys = NewHash(1, NULL);
	if (!keys) return(0);


	cdb_rewind(CDB_OPENID);
	while (cdboi = cdb_next_item(CDB_OPENID), cdboi != NULL) {
		if (cdboi->len > sizeof(long)) {
			memcpy(&usernum, cdboi->ptr, sizeof(long));
			if (CtdlGetUserByNumber(&usbuf, usernum) != 0) {
				deleteme = strdup(cdboi->ptr + sizeof(long)),
				Put(keys, deleteme, strlen(deleteme), deleteme, NULL);
			}
		}
		cdb_free(cdboi);
	}

	/* Go through the hash list, deleting keys we stored in it */

	HashPos = GetNewHashPos(keys, 0);
	while (GetNextHashPos(keys, HashPos, &len, &Key, &Value)!=0)
	{
		syslog(LOG_DEBUG, "Deleting associated OpenID <%s>",  (char*)Value);
		cdb_delete(CDB_OPENID, Value, strlen(Value));
		/* note: don't free(Value) -- deleting the hash list will handle this for us */
		++num_deleted;
	}
	DeleteHashPos(&HashPos);
	DeleteHash(&keys);
	return num_deleted;
}
Esempio n. 22
0
int checks(char *key, char *buf)
{
    struct cdb cdb;
    struct cdb_find cdbf;
    int fd;
    char *data;
    unsigned keylen = strlen(key), datalen, vpos;

    if (((fd = open(DB, O_RDONLY)) == -1) ||
            (cdb_init(&cdb, fd) != 0)) {
        printf("Can't open database: %s\n", strerror(errno));
        return (-1);
    }


    if (cdb_findinit(&cdbf, &cdb, key, keylen) <= 0) {
        return (-1);
    }

    while (cdb_findnext(&cdbf) > 0) {
        char *pattern, *subject;
        int m;

        vpos = cdb_datapos(&cdb);
        datalen = cdb_datalen(&cdb);
        data = malloc(datalen + 1);
        cdb_read(&cdb, data, datalen, vpos);
        data[datalen] = '\0';

        pattern = data;
        subject = buf;
        m = match(pattern, subject);
        printf("*** match %s  ", m ? "TRUE " : "false");
        printf("%s\n", data);

        free(data);
    }

    cdb_free(&cdb);
    close(fd);
    return (0);
}
Esempio n. 23
0
int find_client_loc(char loc[2],const char ip[16])
{
  int r, fd;
  char key[32+3];
  static struct cdb c;

  fd = open_read("data.cdb");
  if (fd == -1) return 0;
  cdb_init(&c,fd);

  byte_zero(loc,2);
  key[0] = 0;
  key[1] = '%';
  if (byte_equal(ip,12,V4mappedprefix)) {
    key[2] = 'f';
    byte_copy(key + 3,4,ip+12);
    r = cdb_find(&c,key,7);
    if (!r) r = cdb_find(&c,key,6);
    if (!r) r = cdb_find(&c,key,5);
    if (!r) r = cdb_find(&c,key,4);
    if (!r) r = cdb_find(&c,key,3);
    if (r == -1) return 0;
    if (r && (cdb_datalen(&c) == 2))
      if (cdb_read(&c,loc,2,cdb_datapos(&c)) == -1) return 0;
  } else {
    unsigned int n;
    key[2] = 's';
    ip6_fmt_flat(key+3,ip);
    for (n=19; n>3; --n) {
      r = cdb_find(&c,key,n);
      if (r) break;
    }
    if (r == -1) return 0;
    if (r && (cdb_datalen(&c) == 2))
      if (cdb_read(&c,loc,2,cdb_datapos(&c)) == -1) return 0;
  }

  cdb_free(&c);
  close(fd);
  return r;
}
Esempio n. 24
0
/// Finalizes shopping data structures.
void
shop_fini(void)
{
    CCS rmap;

    // Remove the roadmap file.
    if ((rmap = prop_get_str(P_ROADMAPFILE))) {
	if (!prop_is_true(P_LEAVE_ROADMAP)) {
	    if (unlink(rmap)) {
		putil_syserr(0, rmap);
	    } else {
		vb_printf(VB_SHOP, "REMOVED ROADMAP FILE %s", rmap);
	    }
	}
	prop_unset(P_ROADMAPFILE, 0);
    }

    if (ShopCDB) {
	cdb_free(ShopCDB);
	ShopCDB = NULL;
    }
}
Esempio n. 25
0
void cmd_whok(char *cmdbuf)
{
	struct ctdluser temp;
	struct cdbdata *cdbus;
	int ra;

	cprintf("%d Who knows room:\n", LISTING_FOLLOWS);
	cdb_rewind(CDB_USERS);
	while (cdbus = cdb_next_item(CDB_USERS), cdbus != NULL) {
		memset(&temp, 0, sizeof temp);
		memcpy(&temp, cdbus->ptr, sizeof temp);
		cdb_free(cdbus);

		CtdlRoomAccess(&CC->room, &temp, &ra, NULL);
		if ((!IsEmptyStr(temp.fullname)) && 
		    (CC->room.QRflags & QR_INUSE) &&
		    (ra & UA_KNOWN)
			)
			cprintf("%s\n", temp.fullname);
	}
	cprintf("000\n");
}
Esempio n. 26
0
/*
 * Detach an OpenID from the currently logged in account
 */
void cmd_oidd(char *argbuf) {
	struct cdbdata *cdboi;
	char id_to_detach[1024];
	int this_is_mine = 0;
	long usernum = 0L;

	if (CtdlGetConfigInt("c_disable_newu"))
	{
		cprintf("%d this system does not support openid.\n",
			ERROR + CMD_NOT_SUPPORTED);
		return;
	}
	if (CtdlAccessCheck(ac_logged_in)) return;
	extract_token(id_to_detach, argbuf, 0, '|', sizeof id_to_detach);
	if (IsEmptyStr(id_to_detach)) {
		cprintf("%d An empty OpenID URL is not allowed.\n", ERROR + ILLEGAL_VALUE);
	}

	cdb_rewind(CDB_OPENID);
	while (cdboi = cdb_next_item(CDB_OPENID), cdboi != NULL) {
		if (cdboi->len > sizeof(long)) {
			memcpy(&usernum, cdboi->ptr, sizeof(long));
			if (usernum == CC->user.usernum) {
				this_is_mine = 1;
			}
		}
		cdb_free(cdboi);
	}

	if (!this_is_mine) {
		cprintf("%d That OpenID was not found or not associated with your account.\n",
			ERROR + ILLEGAL_VALUE);
		return;
	}

	cdb_delete(CDB_OPENID, id_to_detach, strlen(id_to_detach));
	cprintf("%d %s detached from your account.\n", CIT_OK, id_to_detach);
}
Esempio n. 27
0
int respond(char *q,char qtype[2],char ip[4])
{
  static struct tai cdb_valid = { 0 };
  static int fd = -1;
  struct tai one_second;
  int r;
  char key[6];

  tai_now(&now);

  if (tai_less(&cdb_valid, &now)) {
    if (fd != -1) {
      cdb_free(&c);
      close(fd);
    }
    fd = open_read("data.cdb");
    if (fd == -1) return 0;
    cdb_init(&c,fd);
    tai_uint(&one_second, 1);
    tai_add(&cdb_valid, &now, &one_second);
  }
  byte_zero(clientloc,2);
  key[0] = 0;
  key[1] = '%';
  byte_copy(key + 2,4,ip);
  r = cdb_find(&c,key,6);
  if (!r) r = cdb_find(&c,key,5);
  if (!r) r = cdb_find(&c,key,4);
  if (!r) r = cdb_find(&c,key,3);
  if (!r) r = cdb_find(&c,key,2);
  if (r == -1) return 0;
  if (r && (cdb_datalen(&c) == 2))
    if (cdb_read(&c,clientloc,2,cdb_datapos(&c)) == -1) return 0;

  r = doit(q,qtype);

  return r;
}
Esempio n. 28
0
/*
 * Look up an Internet e-mail address in the directory.
 * On success: returns 0, and Citadel address stored in 'target'
 * On failure: returns nonzero
 */
int CtdlDirectoryLookup(char *target, char *internet_addr, size_t targbuflen) {
	struct cdbdata *cdbrec;
	char key[SIZ];

	/* Dump it in there unchanged, just for kicks */
	safestrncpy(target, internet_addr, targbuflen);

	/* Only do lookups for addresses with hostnames in them */
	if (num_tokens(internet_addr, '@') != 2) return(-1);

	/* Only do lookups for domains in the directory */
	if (IsDirectory(internet_addr, 0) == 0) return(-1);

	directory_key(key, internet_addr);
	cdbrec = cdb_fetch(CDB_DIRECTORY, key, strlen(key) );
	if (cdbrec != NULL) {
		safestrncpy(target, cdbrec->ptr, targbuflen);
		cdb_free(cdbrec);
		return(0);
	}

	return(-1);
}
Esempio n. 29
0
/*
 * If a user account exists which is associated with the Claimed ID, log it in and return zero.
 * Otherwise it returns nonzero.
 */
int login_via_openid(StrBuf *claimed_id)
{
	struct cdbdata *cdboi;
	long usernum = 0;

	cdboi = cdb_fetch(CDB_OPENID, ChrPtr(claimed_id), StrLength(claimed_id));
	if (cdboi == NULL) {
		return(-1);
	}

	memcpy(&usernum, cdboi->ptr, sizeof(long));
	cdb_free(cdboi);

	if (!CtdlGetUserByNumber(&CC->user, usernum)) {
		/* Now become the user we just created */
		safestrncpy(CC->curr_user, CC->user.fullname, sizeof CC->curr_user);
		do_login();
		return(0);
	}
	else {
		memset(&CC->user, 0, sizeof(struct ctdluser));
		return(-1);
	}
}
int
chdir_long (char *dir)
{
  int e = chdir (dir);
  if (e == 0 || errno != ENAMETOOLONG)
    return e;

  {
    size_t len = strlen (dir);
    char *dir_end = dir + len;
    struct cd_buf cdb;
    size_t n_leading_slash;

    cdb_init (&cdb);

    /* If DIR is the empty string, then the chdir above
       must have failed and set errno to ENOENT.  */
    assert (0 < len);
    assert (PATH_MAX <= len);

    /* Count leading slashes.  */
    n_leading_slash = strspn (dir, "/");

    /* Handle any leading slashes as well as any name that matches
       the regular expression, m!^//hostname[/]*! .  Handling this
       prefix separately usually results in a single additional
       cdb_advance_fd call, but it's worthwhile, since it makes the
       code in the following loop cleaner.  */
    if (n_leading_slash == 2)
      {
	int err;
	/* Find next slash.
	   We already know that dir[2] is neither a slash nor '\0'.  */
	char *slash = memchr (dir + 3, '/', dir_end - (dir + 3));
	if (slash == NULL)
	  {
	    errno = ENAMETOOLONG;
	    return -1;
	  }
	*slash = '\0';
	err = cdb_advance_fd (&cdb, dir);
	*slash = '/';
	if (err != 0)
	  goto Fail;
	dir = find_non_slash (slash + 1);
      }
    else if (n_leading_slash)
      {
	if (cdb_advance_fd (&cdb, "/") != 0)
	  goto Fail;
	dir += n_leading_slash;
      }

    assert (*dir != '/');
    assert (dir <= dir_end);

    while (PATH_MAX <= dir_end - dir)
      {
	int err;
	/* Find a slash that is PATH_MAX or fewer bytes away from dir.
	   I.e. see if there is a slash that will give us a name of
	   length PATH_MAX-1 or less.  */
	char *slash = memrchr (dir, '/', PATH_MAX);
	if (slash == NULL)
	  {
	    errno = ENAMETOOLONG;
	    return -1;
	  }

	*slash = '\0';
	assert (slash - dir < PATH_MAX);
	err = cdb_advance_fd (&cdb, dir);
	*slash = '/';
	if (err != 0)
	  goto Fail;

	dir = find_non_slash (slash + 1);
      }

    if (dir < dir_end)
      {
	if (cdb_advance_fd (&cdb, dir) != 0)
	  goto Fail;
      }

    if (cdb_fchdir (&cdb) != 0)
      goto Fail;

    cdb_free (&cdb);
    return 0;

   Fail:
    {
      int saved_errno = errno;
      cdb_free (&cdb);
      errno = saved_errno;
      return -1;
    }
  }
}