/* * 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; }
int mboxkey_merge(const char *tmpfile, const char *tgtfile) { int r = 0; struct db *tmp = NULL, *tgt = NULL; struct mboxkey_merge_rock rock; /* xxx does this need to be CYRUSDB_CREATE? */ r = cyrusdb_open(DB, tmpfile, CYRUSDB_CREATE, &tmp); if(r) goto done; r = cyrusdb_open(DB, tgtfile, CYRUSDB_CREATE, &tgt); if(r) goto done; rock.db = tgt; rock.tid = NULL; r = cyrusdb_foreach(tmp, "", 0, NULL, mboxkey_merge_cb, &rock, &rock.tid); if(r) cyrusdb_abort(rock.db, rock.tid); else cyrusdb_commit(rock.db, rock.tid); done: if(tgt) cyrusdb_close(tgt); if(tmp) cyrusdb_close(tmp); return r; }
/* * Abort the outstanding quota transaction */ EXPORTED void quota_abort(struct txn **tid) { if (tid && *tid) { if (cyrusdb_abort(qdb, *tid)) { syslog(LOG_ERR, "IOERROR: aborting quota: %m"); } *tid = NULL; } }
static void abortcurrent(struct mboxkey *s) { if (s && s->tid) { int r = cyrusdb_abort(s->db, s->tid); if (r) { syslog(LOG_ERR, "DBERROR: error aborting txn: %s", cyrusdb_strerror(r)); } s->tid = NULL; } }
/* * Add an entry to the deny DB. Message 'msg' may be NULL, resulting * in a default message being used. Service name 'service' may be NULL, * resulting in all services being blocked for the user. The username * 'user' is a required argument. Returns an IMAP error code or 0 on * success. */ EXPORTED int denydb_set(const char *user, const char *service, const char *msg) { struct txn *txn = NULL; struct buf data = BUF_INITIALIZER; int r = 0; if (!denydb) { r = IMAP_INTERNAL; goto out; } if (!service) service = "*"; if (!user || strchr(service, '\t')) { /* the service field may not contain a TAB, it's the field separator */ r = IMAP_INVALID_IDENTIFIER; goto out; } /* compose the record */ buf_printf(&data, "%u\t", USERDENY_VERSION); buf_appendcstr(&data, service); buf_putc(&data, '\t'); buf_appendcstr(&data, (msg ? msg : default_message)); /* write the record */ do { r = cyrusdb_store(denydb, user, strlen(user), data.s, data.len, &txn); } while (r == CYRUSDB_AGAIN); if (r) { syslog(LOG_ERR, "IOERROR: couldn't store denydb record for %s: %s", user, cyrusdb_strerror(r)); r = IMAP_IOERROR; } out: if (txn) { if (r) cyrusdb_abort(denydb, txn); else cyrusdb_commit(denydb, txn); } buf_free(&data); return r; }