int auth_change_password(uint64_t user_idnr, const char *new_pass, const char *enctype) { C c; S s; volatile int t = FALSE; const char *encoding = enctype?enctype:""; if (strlen(new_pass) > 128) { TRACE(TRACE_ERR, "new password length is insane"); return -1; } c = db_con_get(); TRY s = db_stmt_prepare(c, "UPDATE %susers SET passwd = ?, encryption_type = ? WHERE user_idnr=?", DBPFX); db_stmt_set_str(s, 1, new_pass); db_stmt_set_str(s, 2, encoding); db_stmt_set_u64(s, 3, user_idnr); db_stmt_exec(s); t = TRUE; CATCH(SQLException) LOG_SQLERROR; t = DM_EQUERY; FINALLY db_con_close(c); END_TRY; return t; }
static long long int _update_recent(volatile GList *slices, uint64_t seq) { INIT_QUERY; Connection_T c; volatile long long int count = 0; if (! (slices = g_list_first(slices))) return count; c = db_con_get(); TRY db_begin_transaction(c); while (slices) { Connection_execute(c, "UPDATE %smessages SET recent_flag = 0, seq = %" PRIu64 " WHERE recent_flag = 1 AND seq < %" PRIu64 " AND message_idnr IN (%s)", DBPFX, seq, seq, (gchar *)slices->data); count += Connection_rowsChanged(c); if (! g_list_next(slices)) break; slices = g_list_next(slices); } db_commit_transaction(c); CATCH(SQLException) LOG_SQLERROR; count = DM_EQUERY; db_rollback_transaction(c); FINALLY db_con_close(c); g_list_destroy(slices); END_TRY; return count; }
/* Delete message from mailbox if it is Trash and the message date less then passed date */ int do_erase_old(int days, char * mbtrash_name) { Connection_T c; PreparedStatement_T s; ResultSet_T r; char expire [DEF_FRAGSIZE]; memset(expire,0,sizeof(expire)); snprintf(expire, DEF_FRAGSIZE-1, db_get_sql(SQL_EXPIRE), days); c = db_con_get(); s = db_stmt_prepare(c,"SELECT msg.message_idnr FROM %smessages msg " "JOIN %sphysmessage phys ON msg.physmessage_id = phys.id " "JOIN %smailboxes mb ON msg.mailbox_idnr = mb.mailbox_idnr " "WHERE mb.name = ? AND msg.status < %d " "AND phys.internal_date < %s ", DBPFX, DBPFX, DBPFX, MESSAGE_STATUS_DELETE, expire); db_stmt_set_str(s, 1, mbtrash_name); TRY r = db_stmt_query(s); while(db_result_next(r)) { uint64_t id = db_result_get_u64(r, 0); qprintf("Deleting message id(%" PRIu64 ")\n", id); db_set_message_status(id,MESSAGE_STATUS_PURGE); } CATCH(SQLException) LOG_SQLERROR; return -1; FINALLY db_con_close(c); END_TRY; return 0; }
int dm_sievescript_activate(uint64_t user_idnr, char *scriptname) { Connection_T c; PreparedStatement_T s; volatile gboolean t = FALSE; assert(scriptname); c = db_con_get(); TRY db_begin_transaction(c); s = db_stmt_prepare(c,"UPDATE %ssievescripts SET active = 0 WHERE owner_idnr = ? ", DBPFX); db_stmt_set_u64(s, 1, user_idnr); db_stmt_exec(s); db_con_clear(c); s = db_stmt_prepare(c,"UPDATE %ssievescripts SET active = 1 WHERE owner_idnr = ? AND name = ?", DBPFX); db_stmt_set_u64(s, 1, user_idnr); db_stmt_set_str(s, 2, scriptname); db_stmt_exec(s); db_commit_transaction(c); t = TRUE; CATCH(SQLException) LOG_SQLERROR; db_rollback_transaction(c); FINALLY db_con_close(c); END_TRY; return t; }
static GList *user_get_deliver_to(const char *username) { INIT_QUERY; C c; R r; S s; GList *d = NULL; snprintf(query, DEF_QUERYSIZE-1, "SELECT deliver_to FROM %saliases " "WHERE lower(alias) = lower(?) " "AND lower(alias) <> lower(deliver_to)", DBPFX); c = db_con_get(); TRY s = db_stmt_prepare(c, query); db_stmt_set_str(s, 1, username); r = db_stmt_query(s); while (db_result_next(r)) d = g_list_prepend(d, g_strdup(db_result_get(r,0))); CATCH(SQLException) LOG_SQLERROR; FINALLY db_con_close(c); END_TRY; return d; }
int dm_sievescript_isactive_byname(uint64_t user_idnr, const char *scriptname) { Connection_T c; ResultSet_T r; PreparedStatement_T s; volatile int t = TRUE; c = db_con_get(); TRY if (scriptname) { s = db_stmt_prepare(c, "SELECT name FROM %ssievescripts WHERE owner_idnr = ? AND active = 1 AND name = ?", DBPFX); db_stmt_set_u64(s, 1, user_idnr); db_stmt_set_str(s, 2, scriptname); } else { s = db_stmt_prepare(c, "SELECT name FROM %ssievescripts WHERE owner_idnr = ? AND active = 1", DBPFX); db_stmt_set_u64(s, 1, user_idnr); } r = db_stmt_query(s); if (! db_result_next(r)) t = FALSE; CATCH(SQLException) LOG_SQLERROR; t = DM_EQUERY; FINALLY db_con_close(c); END_TRY; return t; }
/* Move message to Trash if the message is in INBOX mailbox and date less then passed date. */ int do_move_old (int days, char * mbinbox_name, char * mbtrash_name) { Connection_T c; ResultSet_T r; ResultSet_T r1; PreparedStatement_T s; PreparedStatement_T s1; int skip = 1; char expire [DEF_FRAGSIZE]; uint64_t mailbox_to; uint64_t mailbox_from; memset(expire,0,sizeof(expire)); snprintf(expire, DEF_FRAGSIZE-1, db_get_sql(SQL_EXPIRE), days); c = db_con_get(); s = db_stmt_prepare(c,"SELECT msg.message_idnr, mb.owner_idnr, mb.mailbox_idnr FROM %smessages msg " "JOIN %sphysmessage phys ON msg.physmessage_id = phys.id " "JOIN %smailboxes mb ON msg.mailbox_idnr = mb.mailbox_idnr " "WHERE mb.name = ? AND msg.status < %d " "AND phys.internal_date < %s", DBPFX, DBPFX, DBPFX, MESSAGE_STATUS_DELETE, expire); s1 = db_stmt_prepare(c, "SELECT mailbox_idnr FROM %smailboxes WHERE owner_idnr = ? AND name = ?", DBPFX); db_stmt_set_str(s, 1, mbinbox_name); TRY r = db_stmt_query(s); while (db_result_next(r)) { skip = 1; uint64_t id = db_result_get_u64(r, 0); uint64_t user_id = db_result_get_u64(r, 1); mailbox_from = db_result_get_u64(r, 2); db_stmt_set_u64(s1,1,user_id); db_stmt_set_str(s1,2,mbtrash_name); r1 = db_stmt_query(s1); if (db_result_next(r1)) { mailbox_to = db_result_get_u64(r1, 0); skip = 0; } if (!skip) { db_move_message(id, mailbox_to); db_mailbox_seq_update(mailbox_to, 0); db_mailbox_seq_update(mailbox_from, 0); } else { qprintf("User(%" PRIu64 ") doesn't has mailbox(%s)\n", user_id, mbtrash_name); } } CATCH(SQLException) LOG_SQLERROR; return -1; FINALLY db_con_close(c); END_TRY; return 0; }
int MailboxState_getAcl(T M, uint64_t userid, struct ACLMap *map) { int i; volatile int t = DM_SUCCESS; gboolean gotrow = FALSE; uint64_t anyone; Connection_T c; ResultSet_T r; PreparedStatement_T s; g_return_val_if_fail(MailboxState_getId(M),DM_EGENERAL); if (! (auth_user_exists(DBMAIL_ACL_ANYONE_USER, &anyone))) return DM_EQUERY; c = db_con_get(); TRY s = db_stmt_prepare(c, "SELECT lookup_flag,read_flag,seen_flag," "write_flag,insert_flag,post_flag," "create_flag,delete_flag,deleted_flag,expunge_flag,administer_flag " "FROM %sacl " "WHERE mailbox_id = ? AND user_id = ?",DBPFX); db_stmt_set_u64(s, 1, MailboxState_getId(M)); db_stmt_set_u64(s, 2, userid); r = db_stmt_query(s); if (! db_result_next(r)) { /* else check the 'anyone' user */ db_stmt_set_u64(s, 2, anyone); r = db_stmt_query(s); if (db_result_next(r)) gotrow = TRUE; } else { gotrow = TRUE; } if (gotrow) { i = 0; map->lookup_flag = db_result_get_bool(r,i++); map->read_flag = db_result_get_bool(r,i++); map->seen_flag = db_result_get_bool(r,i++); map->write_flag = db_result_get_bool(r,i++); map->insert_flag = db_result_get_bool(r,i++); map->post_flag = db_result_get_bool(r,i++); map->create_flag = db_result_get_bool(r,i++); map->delete_flag = db_result_get_bool(r,i++); map->deleted_flag = db_result_get_bool(r,i++); map->expunge_flag = db_result_get_bool(r,i++); map->administer_flag = db_result_get_bool(r,i++); } CATCH(SQLException) LOG_SQLERROR; t = DM_EQUERY; FINALLY db_con_close(c); END_TRY; return t; }
int dm_sievescript_rename(uint64_t user_idnr, char *scriptname, char *newname) { int active = 0; Connection_T c; ResultSet_T r; PreparedStatement_T s; volatile int t = FALSE; assert(scriptname); /* * According to the draft RFC, a script with the same * name as an existing script should *atomically* replace it. */ c = db_con_get(); TRY db_begin_transaction(c); s = db_stmt_prepare(c,"SELECT active FROM %ssievescripts WHERE owner_idnr = ? AND name = ?", DBPFX); db_stmt_set_u64(s,1, user_idnr); db_stmt_set_str(s,2, newname); r = db_stmt_query(s); if (db_result_next(r)) { active = db_result_get_int(r,0); db_con_clear(c); s = db_stmt_prepare(c, "DELETE FROM %ssievescripts WHERE owner_idnr = ? AND name = ?", DBPFX); db_stmt_set_u64(s, 1, user_idnr); db_stmt_set_str(s, 2, newname); db_stmt_exec(s); } db_con_clear(c); s = db_stmt_prepare(c, "UPDATE %ssievescripts SET name = ?, active = ? WHERE owner_idnr = ? AND name = ?", DBPFX); db_stmt_set_str(s, 1, newname); db_stmt_set_int(s, 2, active); db_stmt_set_u64(s, 3, user_idnr); db_stmt_set_str(s, 4, scriptname); db_stmt_exec(s); t = db_commit_transaction(c); CATCH(SQLException) LOG_SQLERROR; t = DM_EQUERY; db_rollback_transaction(c); FINALLY db_con_close(c); END_TRY; return t; }
unsigned MailboxState_getPermission(T M) { if (! M->permission) { Connection_T c = db_con_get(); TRY db_getmailbox_permission(M, c); CATCH(SQLException) LOG_SQLERROR; FINALLY db_con_close(c); END_TRY; } return M->permission; }
uint64_t MailboxState_getSeq(T M) { if (! M->seq) { Connection_T c = db_con_get(); TRY db_getmailbox_seq(M, c); CATCH(SQLException) LOG_SQLERROR; FINALLY db_con_close(c); END_TRY; } return M->seq; }
int do_migrate(int migrate_limit) { C c; R r; int id = 0; int count = 0; DbmailMessage *m; qprintf ("Mirgrate legacy 2.2.x messageblks to mimeparts...\n"); if (!yes_to_all) { qprintf ("\tmigration skipped. Use -y option to perform mirgration.\n"); return 0; } qprintf ("Preparing to migrate %d physmessages.\n", migrate_limit); c = db_con_get(); TRY r = db_query(c, "SELECT DISTINCT(physmessage_id) FROM %smessageblks LIMIT %d", DBPFX, migrate_limit); qprintf ("Migrating %d physmessages...\n", migrate_limit); while (db_result_next(r)) { count++; id = db_result_get_u64(r,0); m = dbmail_message_new(); m = dbmail_message_retrieve(m, id, DBMAIL_MESSAGE_FILTER_FULL); if(!dm_message_store(m)) { if(verbose) qprintf ("%d ",id); db_update("DELETE FROM %smessageblks WHERE physmessage_id = %d", DBPFX, id); } else { if(!verbose) qprintf ("migrating physmessage_id: %d\n",id); qprintf ("failed\n"); return -1; } dbmail_message_free(m); } CATCH(SQLException) LOG_SQLERROR; return -1; FINALLY db_con_close(c); END_TRY; qprintf ("Migration complete. Migrated %d physmessages.\n", count); return 0; }
int MailboxState_info(T M) { volatile int t = DM_SUCCESS; Connection_T c = db_con_get(); TRY db_begin_transaction(c); db_getmailbox_info(M, c); CATCH(SQLException) LOG_SQLERROR; t = DM_EQUERY; FINALLY db_commit_transaction(c); db_con_close(c); END_TRY; return t; }
int dm_sievescript_add(uint64_t user_idnr, char *scriptname, char *script) { Connection_T c; ResultSet_T r; PreparedStatement_T s; volatile int t = FALSE; assert(scriptname); c = db_con_get(); TRY db_begin_transaction(c); s = db_stmt_prepare(c,"SELECT COUNT(*) FROM %ssievescripts WHERE owner_idnr = ? AND name = ?", DBPFX); db_stmt_set_u64(s, 1, user_idnr); db_stmt_set_str(s, 2, scriptname); r = db_stmt_query(s); if (db_result_next(r)) { db_con_clear(c); s = db_stmt_prepare(c,"DELETE FROM %ssievescripts WHERE owner_idnr = ? AND name = ?", DBPFX); db_stmt_set_u64(s, 1, user_idnr); db_stmt_set_str(s, 2, scriptname); db_stmt_exec(s); } db_con_clear(c); s = db_stmt_prepare(c,"INSERT INTO %ssievescripts (owner_idnr, name, script, active) VALUES (?,?,?,1)", DBPFX); db_stmt_set_u64(s, 1, user_idnr); db_stmt_set_str(s, 2, scriptname); db_stmt_set_blob(s, 3, script, strlen(script)); db_stmt_exec(s); t = db_commit_transaction(c); CATCH(SQLException) LOG_SQLERROR; db_rollback_transaction(c); t = DM_EQUERY; FINALLY db_con_close(c); END_TRY; return t; }
GList * auth_get_known_users(void) { GList * users = NULL; C c; R r; c = db_con_get(); TRY r = db_query(c, "SELECT userid FROM %susers ORDER BY userid",DBPFX); while (db_result_next(r)) users = g_list_append(users, g_strdup(db_result_get(r, 0))); CATCH(SQLException) LOG_SQLERROR; FINALLY db_con_close(c); END_TRY; return users; }
GList * auth_get_known_aliases(void) { GList * aliases = NULL; C c; R r; c = db_con_get(); TRY r = db_query(c,"SELECT alias FROM %saliases ORDER BY alias",DBPFX); while (db_result_next(r)) aliases = g_list_append(aliases, g_strdup(db_result_get(r,0))); CATCH(SQLException) LOG_SQLERROR; FINALLY db_con_close(c); END_TRY; return aliases; }
static int db_count_deleted(u64_t * rows) { C c; R r; volatile int t = TRUE; assert(rows != NULL); *rows = 0; c = db_con_get(); TRY r = db_query(c, "SELECT COUNT(*) FROM %smessages WHERE status = %d", DBPFX, MESSAGE_STATUS_DELETE); if (db_result_next(r)) *rows = db_result_get_int(r,0); CATCH(SQLException) LOG_SQLERROR; t = DM_EQUERY; FINALLY db_con_close(c); END_TRY; return t; }
char *auth_getencryption(uint64_t user_idnr) { char *res = NULL; C c; R r; assert(user_idnr > 0); c = db_con_get(); TRY r = db_query(c, "SELECT encryption_type FROM %susers WHERE user_idnr = %" PRIu64 "",DBPFX, user_idnr); if (db_result_next(r)) res = g_strdup(db_result_get(r,0)); CATCH(SQLException) LOG_SQLERROR; FINALLY db_con_close(c); END_TRY; return res; }
int do_migrate(int migrate_limit) { Connection_T c; ResultSet_T r; int id = 0; volatile int count = 0; DbmailMessage *m; qprintf ("Migrate legacy 2.2.x messageblks to mimeparts...\n"); if (!yes_to_all) { qprintf ("\tmigration skipped. Use -y option to perform migration.\n"); return 0; } qprintf ("Preparing to migrate up to %d physmessages.\n", migrate_limit); c = db_con_get(); TRY db_begin_transaction(c); r = db_query(c, "SELECT DISTINCT(physmessage_id) FROM %smessageblks LIMIT %d", DBPFX, migrate_limit); while (db_result_next(r)) { count++; id = db_result_get_u64(r,0); m = dbmail_message_new(NULL); m = dbmail_message_retrieve(m, id); if(! dm_message_store(m)) { if(verbose) qprintf ("%d ",id); db_update("DELETE FROM %smessageblks WHERE physmessage_id = %d", DBPFX, id); } dbmail_message_free(m); } db_commit_transaction(c); CATCH(SQLException) LOG_SQLERROR; db_rollback_transaction(c); return -1; FINALLY db_con_close(c); END_TRY; qprintf ("Migration complete. Migrated %d physmessages.\n", count); return 0; }
int auth_getmaxmailsize(uint64_t user_idnr, uint64_t * maxmail_size) { assert(maxmail_size != NULL); *maxmail_size = 0; C c; R r; int t = TRUE; c = db_con_get(); TRY r = db_query(c, "SELECT maxmail_size FROM %susers WHERE user_idnr = %" PRIu64 "",DBPFX, user_idnr); if (db_result_next(r)) *maxmail_size = db_result_get_u64(r,0); CATCH(SQLException) LOG_SQLERROR; t = DM_EQUERY; FINALLY db_con_close(c); END_TRY; return t; }
int auth_getclientid(uint64_t user_idnr, uint64_t * client_idnr) { assert(client_idnr != NULL); *client_idnr = 0; C c; R r; int t = TRUE; c = db_con_get(); TRY r = db_query(c, "SELECT client_idnr FROM %susers WHERE user_idnr = %" PRIu64 "",DBPFX, user_idnr); if (db_result_next(r)) *client_idnr = db_result_get_u64(r,0); CATCH(SQLException) LOG_SQLERROR; t = DM_EQUERY; FINALLY db_con_close(c); END_TRY; return t; }
int dm_sievescript_delete(uint64_t user_idnr, char *scriptname) { Connection_T c; PreparedStatement_T s; volatile gboolean t = FALSE; assert(scriptname); c = db_con_get(); TRY s = db_stmt_prepare(c,"DELETE FROM %ssievescripts WHERE owner_idnr = ? AND name = ?", DBPFX); db_stmt_set_u64(s, 1, user_idnr); db_stmt_set_str(s, 2, scriptname); db_stmt_exec(s); t = TRUE; CATCH(SQLException) LOG_SQLERROR; FINALLY db_con_close(c); END_TRY; return t; }
static int db_deleted_count(u64_t * rows) { C c; R r; volatile int t = FALSE; assert(rows); *rows = 0; c = db_con_get(); r = db_query(c, "SELECT COUNT(*) FROM %smessages WHERE status=%d", DBPFX, MESSAGE_STATUS_PURGE); TRY if (db_result_next(r)) { *rows = db_result_get_int(r,0); t = TRUE; } CATCH(SQLException) LOG_SQLERROR; FINALLY db_con_close(c); END_TRY; return t; }
T MailboxState_new(Mempool_T pool, uint64_t id) { T M; Connection_T c; volatile int t = DM_SUCCESS; gboolean freepool = FALSE; if (! pool) { pool = mempool_open(); freepool = TRUE; } M = mempool_pop(pool, sizeof(*M)); M->pool = pool; M->freepool = freepool; if (! id) return M; M->id = id; M->recent_queue = g_tree_new((GCompareFunc)ucmp); M->keywords = g_tree_new_full((GCompareDataFunc)_compare_data,NULL,g_free,NULL); c = db_con_get(); TRY db_begin_transaction(c); // we need read-committed isolation state_load_metadata(M, c); state_load_messages(M, c); CATCH(SQLException) LOG_SQLERROR; t = DM_EQUERY; FINALLY db_commit_transaction(c); db_con_close(c); END_TRY; if (t == DM_EQUERY) { TRACE(TRACE_ERR, "Error opening mailbox"); MailboxState_free(&M); } return M; }
int dm_sievescript_get(uint64_t user_idnr, char **scriptname) { Connection_T c; ResultSet_T r; volatile int t = FALSE; assert(scriptname); *scriptname = NULL; c = db_con_get(); TRY r = db_query(c, "SELECT name from %ssievescripts where owner_idnr = %" PRIu64 " and active = 1", DBPFX, user_idnr); if (db_result_next(r)) *scriptname = g_strdup(db_result_get(r,0)); CATCH(SQLException) LOG_SQLERROR; t = DM_EQUERY; FINALLY db_con_close(c); END_TRY; return t; }
int dm_sievescript_list(uint64_t user_idnr, GList **scriptlist) { Connection_T c; ResultSet_T r; volatile int t = FALSE; c = db_con_get(); TRY r = db_query(c,"SELECT name,active FROM %ssievescripts WHERE owner_idnr = %" PRIu64 "", DBPFX,user_idnr); while (db_result_next(r)) { sievescript_info *info = g_new0(sievescript_info,1); strncpy(info->name, db_result_get(r,0), sizeof(info->name)-1); info->active = db_result_get_int(r,1); *(GList **)scriptlist = g_list_prepend(*(GList **)scriptlist, info); } CATCH(SQLException) LOG_SQLERROR; t = DM_EQUERY; FINALLY db_con_close(c); END_TRY; return t; }
static int db_count_replycache(timestring_t lasttokeep, u64_t *rows) { C c; R r; volatile int t = FALSE; field_t to_date_str; assert(rows != NULL); *rows = 0; char2date_str(lasttokeep, &to_date_str); c = db_con_get(); TRY r = db_query(c, "SELECT COUNT(*) FROM %sreplycache WHERE lastseen < %s", DBPFX, to_date_str); if (db_result_next(r)) *rows = db_result_get_u64(r,0); CATCH(SQLException) LOG_SQLERROR; t = DM_EQUERY; FINALLY db_con_close(c); END_TRY; return t; }
static int db_count_iplog(TimeString_T lasttokeep, uint64_t *rows) { Connection_T c; ResultSet_T r; volatile int t = DM_SUCCESS; Field_T to_date_str; assert(rows != NULL); *rows = 0; char2date_str(lasttokeep, &to_date_str); c = db_con_get(); TRY r = db_query(c, "SELECT COUNT(*) FROM %spbsp WHERE since < %s", DBPFX, to_date_str); if (db_result_next(r)) *rows = db_result_get_u64(r,0); CATCH(SQLException) LOG_SQLERROR; t = DM_EQUERY; FINALLY db_con_close(c); END_TRY; return t; }
int dm_sievescript_getbyname(uint64_t user_idnr, char *scriptname, char **script) { Connection_T c; ResultSet_T r; PreparedStatement_T s; volatile int t = FALSE; assert(scriptname); c = db_con_get(); TRY s = db_stmt_prepare(c, "SELECT script FROM %ssievescripts WHERE owner_idnr = ? AND name = ?", DBPFX); db_stmt_set_u64(s, 1, user_idnr); db_stmt_set_str(s, 2, scriptname); r = db_stmt_query(s); if (db_result_next(r)) *script = g_strdup(db_result_get(r,0)); CATCH(SQLException) LOG_SQLERROR; t = DM_EQUERY; FINALLY db_con_close(c); END_TRY; return t; }
int MailboxState_hasPermission(T M, uint64_t userid, const char *right_flag) { PreparedStatement_T stmt; Connection_T c; ResultSet_T r; volatile int result = FALSE; volatile bool owner_acl = false; uint64_t owner_id, mboxid; mboxid = MailboxState_getId(M); TRACE(TRACE_DEBUG, "checking ACL [%s] for user [%" PRIu64 "] on mailbox [%" PRIu64 "]", right_flag, userid, mboxid); /* If we don't know who owns the mailbox, look it up. */ owner_id = MailboxState_getOwner(M); if (! owner_id) { result = db_get_mailbox_owner(mboxid, &owner_id); MailboxState_setOwner(M, owner_id); if (! (result > 0)) return result; } if (owner_id == userid) { c = db_con_get(); TRY stmt = db_stmt_prepare(c, "SELECT * FROM %sacl WHERE " "user_id = ? AND mailbox_id = ?", DBPFX); db_stmt_set_u64(stmt, 1, userid); db_stmt_set_u64(stmt, 2, mboxid); r = db_stmt_query(stmt); if (db_result_next(r)) owner_acl = true; CATCH(SQLException) LOG_SQLERROR; result = DM_EQUERY; FINALLY db_con_close(c); END_TRY; if (! owner_acl) { TRACE(TRACE_DEBUG, "mailbox [%" PRIu64 "] is owned by user [%" PRIu64 "]" "and no ACL in place. Giving all rights", mboxid, userid); return 1; } else { TRACE(TRACE_DEBUG, "mailbox [%" PRIu64 "] is owned by user [%" PRIu64 "]" "but ACL in place. Restricted access for owner.", mboxid, userid); } } result = FALSE; c = db_con_get(); TRY stmt = db_stmt_prepare(c, "SELECT * FROM %sacl WHERE " "user_id = ? AND mailbox_id = ? AND %s = 1", DBPFX, right_flag); db_stmt_set_u64(stmt, 1, userid); db_stmt_set_u64(stmt, 2, mboxid); r = db_stmt_query(stmt); if (db_result_next(r)) result = TRUE; CATCH(SQLException) LOG_SQLERROR; result = DM_EQUERY; FINALLY db_con_close(c); END_TRY; return result; }