Exemplo n.º 1
0
/*
 * Remove a deny DB record; this has the effect of allowing the given
 * user access to all services.  Returns an IMAP error code or 0 on
 * success.  It is not an error to remove an non-existant record.
 */
EXPORTED int denydb_delete(const char *user)
{
    struct txn *txn = NULL;
    int r = 0;

    if (!denydb) return 0;

    if (!user) return r;

    /* remove the record */
    do {
	r = cyrusdb_delete(denydb,
			   user, strlen(user),
			   &txn, /*force*/1);
    } while (r == CYRUSDB_AGAIN);

    if (r) {
	syslog(LOG_ERR, "IOERROR: couldn't delete denydb record for %s: %s",
			user, cyrusdb_strerror(r));
	r = IMAP_IOERROR;
    }

    if (txn) {
	if (r) cyrusdb_abort(denydb, txn);
	else cyrusdb_commit(denydb, txn);
    }
    return r;
}
Exemplo n.º 2
0
int mboxkey_write(struct mboxkey *mboxkeydb, const char *mailbox,
		  const char *mboxkey, size_t mboxkeylen)
{
    int r;

    assert(mboxkeydb && mailbox);
/*    assert(mboxkeydb->tid);*/

    if (MBOXKEY_DEBUG) {
	syslog(LOG_DEBUG, "mboxkey_db: mboxkey_write(%s, %s, %s)", 
	       mboxkeydb->user, mailbox, mboxkey ? "KEY" : "NIL");
    }

    if (!mboxkey) {
	r = cyrusdb_delete(mboxkeydb->db, mailbox, strlen(mailbox),
		       &mboxkeydb->tid, 1);
    }
    else {
	unsigned short version = MBOXKEY_VERSION, s;
	int datalen = sizeof(s) + mboxkeylen;
	char *data = xmalloc(datalen);

	s = htons(version);
	memcpy(data, &s, sizeof(s));
	memcpy(data+sizeof(s), mboxkey, mboxkeylen);

	r = cyrusdb_store(mboxkeydb->db, mailbox, strlen(mailbox),
		      data, datalen, &mboxkeydb->tid);
	free(data);
    }

    switch (r) {
    case CYRUSDB_OK:
	break;
    case CYRUSDB_IOERROR:
	r = IMAP_AGAIN;
	break;
    default:
	syslog(LOG_ERR, "DBERROR: error updating database: %s", 
	       cyrusdb_strerror(r));
	r = IMAP_IOERROR;
	break;
    }

    return r;
}
Exemplo n.º 3
0
int seen_delete_mailbox(const char *userid, struct mailbox *mailbox)
{
    int r;
    struct seen *seendb = NULL;
    const char *uniqueid = mailbox->uniqueid;

    if (SEEN_DEBUG) {
	syslog(LOG_DEBUG, "seen_db: seen_delete_mailbox(%s, %s)", 
	       userid, uniqueid);
    }

    /* noop */
    if (!userid)
	return 0;

    r = seen_open(userid, SEEN_SILENT, &seendb);
    if (!r) r = cyrusdb_delete(seendb->db, uniqueid, strlen(uniqueid),
			   &seendb->tid, 1);
    seen_close(&seendb);

    return r;
}
Exemplo n.º 4
0
/*
 * Remove the quota root 'quota'
 */
EXPORTED int quota_deleteroot(const char *quotaroot)
{
    int r;

    if (!quotaroot || !*quotaroot)
        return IMAP_QUOTAROOT_NONEXISTENT;

    r = cyrusdb_delete(qdb, quotaroot, strlen(quotaroot), NULL, 0);

    switch (r) {
    case CYRUSDB_OK:
    case CYRUSDB_NOTFOUND:  /* shouldn't happen anyway */
        return 0;

    case CYRUSDB_AGAIN:
        return IMAP_AGAIN;

    default:
        syslog(LOG_ERR, "DBERROR: error deleting quotaroot %s: %s",
               quotaroot, cyrusdb_strerror(r));
        return IMAP_IOERROR;
    }
}
Exemplo n.º 5
0
int main(int argc, char *argv[])
{
    int iter;
    int seed;
    int i;
    char *key;
    char *val;
    struct db *db;
    int r;
    struct txn *txn;
    const char *data;
    int datalen;
    struct timeval t1, t2;
    int initsize;

    if (argc > 1) {
	iter = atoi(argv[1]);
    } else {
      printf("%s [iterations] [rndseed] [initsize]\n", argv[0]);
      printf("if iterations is negative, run forever and report every -iter\n");
      exit(1);
    }
    TRY(DB->init(".", 0));

    if (argc > 2) {
	srand(atoi(argv[2]));
    }

    TRY(cyrusdb_open(DB, "scratch", &db));

    if (cyrusdb_consistent) {
	TRY(cyrusdb_consistent(db));
    }

    if (argc > 3) {
      initsize = atoi(argv[3]);
      
      txn = NULL;
      for (i = 0; i < initsize; i++) {
	/* generate a random key */
	key = genrand(10 + (rand() % 10));
	
	/* generate a random value */
	val = genrand(10 + (rand() % 100));
	
	TRY(cyrusdb_store(db, key, strlen(key), val, strlen(val), &txn));
      }

      TRY(cyrusdb_commit(db, txn));
      if (cyrusdb_consistent) {
	TRY(cyrusdb_consistent(db));
      }
    }

    printf("starting...\n");

    /* repeat for ever if iter < 0 */
    for (i = 0; iter > 0 ? (i < iter) : 1; i++) {
	int oper = rand() % 10;

	if (i > 0 && iter < 0 && ((i % -iter) == 0)) {
	  do_report();
	}

	switch (oper) {
	case 0:
	    /* do an ADD */
	    
	    if (verbose) printf("A");

	    /* insert it */
	    gettimeofday(&t1, NULL);

	    /* generate a random key */
	    key = genrand(10 + (rand() % 10));

	    /* generate a random value */
	    val = genrand(10 + (rand() % 100));

	    txn = NULL;
	    TRY(cyrusdb_store(db, key, strlen(key), val, strlen(val), &txn));
	    TRY(cyrusdb_commit(db, txn));
	    gettimeofday(&t2, NULL);

	    ADDDIFF(t_add, t1, t2);
	    c_add++;

	    free(key);
	    free(val);

	    break;

	case 1: /* do a modify */
	    if (verbose) printf("M");

	    gettimeofday(&t1, NULL);

	    /* pick a random victim */
	    count = 0;
	    victim = NULL;
	    txn = NULL;
	    TRY(cyrusdb_foreach(db, NULL, 0, &countem, NULL, NULL, &txn));
	    
	    if (count == 0) continue;

	    TRY(cyrusdb_foreach(db, NULL, 0, &findvictim, NULL, NULL, &txn));

	    assert(victim != NULL);

	    /* generate a random value */
	    val = genrand(10 + (rand() % 100));
	    
	    /* do an add */
	    TRY(cyrusdb_store(db, victim, strlen(victim), val, strlen(val), &txn));
	    free(val);

	    TRY(cyrusdb_commit(db, txn));
	    free(victim); victim = NULL;

	    gettimeofday(&t2, NULL);

	    ADDDIFF(t_mod, t1, t2);
	    c_mod++;

	    break;

	case 2: /* do a delete */
	    if (verbose) printf("D");

	    gettimeofday(&t1, NULL);

	    /* pick a random victim */
	    count = 0;
	    victim = NULL;
	    txn = NULL;
	    TRY(cyrusdb_foreach(db, NULL, 0, &countem, NULL, NULL, &txn));
	    
	    if (count == 0) continue;

	    TRY(cyrusdb_foreach(db, NULL, 0, &findvictim, NULL, NULL, &txn));
	    assert(victim != NULL);

	    /* delete it */
	    TRY(cyrusdb_delete(db, victim, strlen(victim), &txn, 0));

	    TRY(cyrusdb_commit(db, txn));
	    free(victim); victim = NULL;

	    gettimeofday(&t2, NULL);

	    ADDDIFF(t_del, t1, t2);
	    c_del++;

	    break;
	    
	default:
	    /* do a "read" */
	    if (verbose) printf("R");

	    gettimeofday(&t1, NULL);

	    /* generate a random key */
	    key = genrand(10 + (rand() % 10));

	    txn = NULL;
	    TRY(cyrusdb_fetch(db, key, strlen(key), &data, &datalen, &txn));
	    TRY(cyrusdb_commit(db, txn));

	    gettimeofday(&t2, NULL);

	    ADDDIFF(t_find, t1, t2);
	    c_find++;

	    free(key);
	}

	fflush(stdout);

#if 0
	/* run the consistency function, if any */
	if (cyrusdb_consistent) {
	    TRY(cyrusdb_consistent(db));
	}
#endif
    }

    TRY(cyrusdb_close(db));
    TRY(DB->done());

    do_report();
    return 0;
}