diff options
author | aaron <aaron@7b491191-dbf0-0310-aff6-d879d4d69008> | 2007-04-09 04:51:45 +0000 |
---|---|---|
committer | aaron <aaron@7b491191-dbf0-0310-aff6-d879d4d69008> | 2007-04-09 04:51:45 +0000 |
commit | b659820e9d3277919451092d47cf7994f6721557 (patch) | |
tree | 0eb40bf225d21f0d150e086a7f6bedf8c3f7539b | |
parent | 8cd7f8c0b52191621ff550e81bf2b6cdf9304825 (diff) |
* check_dbmail_deliver.c dbmail-user.c lmtp.c user.c imap4.h db.c
modules/authsql.c modules/authldap.c modules/sortsieve.c quota.c
debug.h acl.c imapcommands.c dsn.c pipe.c dm_base64.c dbmail-message.c
check_dbmail_db.c sievecmd.c dbmail-imapsession.c main.c timsieve.c
memblock.c misc.c:
Changed all instances of dm_free, dm_malloc, dm_strdup to g_free,
g_new0 or g_malloc, g_strdup, respectively.
git-svn-id: https://svn.ic-s.nl/svn/dbmail/branches/dbmail_2_2_branch@2511 7b491191-dbf0-0310-aff6-d879d4d69008
-rw-r--r-- | ChangeLog | 10 | ||||
-rw-r--r-- | acl.c | 8 | ||||
-rw-r--r-- | check_dbmail_db.c | 2 | ||||
-rw-r--r-- | check_dbmail_deliver.c | 12 | ||||
-rw-r--r-- | db.c | 120 | ||||
-rw-r--r-- | dbmail-imapsession.c | 16 | ||||
-rw-r--r-- | dbmail-message.c | 6 | ||||
-rw-r--r-- | dbmail-user.c | 6 | ||||
-rw-r--r-- | debug.h | 24 | ||||
-rw-r--r-- | dm_base64.c | 2 | ||||
-rw-r--r-- | dsn.c | 18 | ||||
-rw-r--r-- | imap4.h | 2 | ||||
-rw-r--r-- | imapcommands.c | 32 | ||||
-rw-r--r-- | lmtp.c | 10 | ||||
-rw-r--r-- | main.c | 12 | ||||
-rw-r--r-- | memblock.c | 16 | ||||
-rw-r--r-- | misc.c | 8 | ||||
-rw-r--r-- | modules/authldap.c | 96 | ||||
-rw-r--r-- | modules/authsql.c | 59 | ||||
-rw-r--r-- | modules/sortsieve.c | 16 | ||||
-rw-r--r-- | pipe.c | 16 | ||||
-rw-r--r-- | quota.c | 20 | ||||
-rw-r--r-- | sievecmd.c | 26 | ||||
-rw-r--r-- | timsieve.c | 26 | ||||
-rw-r--r-- | user.c | 2 |
25 files changed, 265 insertions, 300 deletions
@@ -1,3 +1,13 @@ +2007-04-08 Aaron Stone <aaron@serendipity.cx> + + * check_dbmail_deliver.c dbmail-user.c lmtp.c user.c imap4.h db.c + modules/authsql.c modules/authldap.c modules/sortsieve.c quota.c + debug.h acl.c imapcommands.c dsn.c pipe.c dm_base64.c dbmail-message.c + check_dbmail_db.c sievecmd.c dbmail-imapsession.c main.c timsieve.c + memblock.c misc.c: + Changed all instances of dm_free, dm_malloc, dm_strdup to g_free, + g_new0 or g_malloc, g_strdup, respectively. + 2007-04-07 Aaron Stone <aaron@serendipity.cx> * pool.h, pool.c, lmtp.c, pop3.c, timsieve.c, imapcommands.c, @@ -225,11 +225,11 @@ char *acl_get_acl(u64_t mboxid) if (dm_list_nodeadd(&identifier_list, username, strlen(username) + 1) == NULL) { TRACE(TRACE_ERROR, "error adding username to list"); dm_list_free(&identifier_list.start); - dm_free(username); + g_free(username); return NULL; } - dm_free(username); + g_free(username); TRACE(TRACE_DEBUG, "before looping identifiers!"); @@ -253,7 +253,7 @@ char *acl_get_acl(u64_t mboxid) identifier = (char *) identifier_elm->data; if (acl_get_rightsstring_identifier(identifier, mboxid, rightsstring) < 0) { dm_list_free(&identifier_list.start); - dm_free(acl_string); + g_free(acl_string); return NULL; } TRACE(TRACE_DEBUG, "%s", rightsstring); @@ -299,7 +299,7 @@ char *acl_myrights(u64_t userid, u64_t mboxid) if (acl_get_rightsstring(userid, mboxid, rightsstring) < 0) { TRACE(TRACE_ERROR, "error getting rightsstring."); - dm_free(rightsstring); + g_free(rightsstring); return NULL; } diff --git a/check_dbmail_db.c b/check_dbmail_db.c index ad6d1e0d..2be04d54 100644 --- a/check_dbmail_db.c +++ b/check_dbmail_db.c @@ -809,7 +809,7 @@ START_TEST(test_db_imap_utf7_like) fail_unless(strcmp(result, getthese[i])==0, "Failed to make db_imap_utf7_like string for [%s]", trythese[i]); - dm_free(result); + g_free(result); } } END_TEST diff --git a/check_dbmail_deliver.c b/check_dbmail_deliver.c index dbe338c5..ef22d983 100644 --- a/check_dbmail_deliver.c +++ b/check_dbmail_deliver.c @@ -528,7 +528,7 @@ START_TEST(test_auth_get_userid) fail_unless(strlen(username)>3,"auth_get_userid failed"); auth_user_exists(username, &testidnr); fail_unless(testidnr==user_idnr,"auth_get_userid: auth_user_exists returned wrong idnr"); - dm_free(username); + g_free(username); } END_TEST @@ -920,7 +920,7 @@ START_TEST(test_find_bounded) "find_bounded is broken. " "Should be success: %s", newaddress); - dm_free(newaddress); + g_free(newaddress); } END_TEST @@ -936,7 +936,7 @@ START_TEST(test_zap_between_both) "zap_between is both broken. " "Should be success: %s", newaddress); - dm_free(newaddress); + g_free(newaddress); } END_TEST @@ -952,7 +952,7 @@ START_TEST(test_zap_between_left) "zap_between is left broken. " "Should be suc@cess: %s", newaddress); - dm_free(newaddress); + g_free(newaddress); } END_TEST @@ -968,7 +968,7 @@ START_TEST(test_zap_between_right) "zap_between is right broken. " "Should be suc+cess: %s", newaddress); - dm_free(newaddress); + g_free(newaddress); } END_TEST @@ -984,7 +984,7 @@ START_TEST(test_zap_between_center) "zap_between is center broken. " "Should be suc+@cess: %s", newaddress); - dm_free(newaddress); + g_free(newaddress); } END_TEST @@ -553,7 +553,7 @@ int db_get_sievescript_byname(u64_t user_idnr, char *scriptname, char **script) "SELECT script FROM %ssievescripts WHERE " "owner_idnr = %llu AND name = '%s'", DBPFX,user_idnr,escaped_scriptname); - dm_free(escaped_scriptname); + g_free(escaped_scriptname); if (db_query(query) == -1) { TRACE(TRACE_ERROR, "error getting sievescript by name"); @@ -574,7 +574,7 @@ int db_get_sievescript_byname(u64_t user_idnr, char *scriptname, char **script) return DM_EQUERY; } - *script = dm_strdup(query_result); + *script = g_strdup(query_result); db_free_result(); return DM_SUCCESS; @@ -606,7 +606,7 @@ int db_check_sievescript_active_byname(u64_t user_idnr, const char *scriptname) "owner_idnr = %llu AND active = 1 AND name = '%s'", DBPFX, user_idnr, name); - dm_free(name); + g_free(name); } else { snprintf(query, DEF_QUERYSIZE, "SELECT name FROM %ssievescripts WHERE " @@ -652,7 +652,7 @@ int db_get_sievescript_active(u64_t user_idnr, char **scriptname) n = db_num_rows(); if (n > 0) { - *scriptname = dm_strdup(db_get_result(0, 0)); + *scriptname = g_strdup(db_get_result(0, 0)); } db_free_result(); @@ -681,7 +681,7 @@ int db_get_sievescript_listall(u64_t user_idnr, struct dm_list *scriptlist) for (i = 0, n = db_num_rows(); i < n; i++) { struct ssinfo info; - info.name = dm_strdup(db_get_result(i, 0)); + info.name = g_strdup(db_get_result(i, 0)); info.active = db_get_result_int(i, 1); dm_list_nodeadd(scriptlist, &info, sizeof(struct ssinfo)); @@ -716,8 +716,8 @@ int db_rename_sievescript(u64_t user_idnr, char *scriptname, char *newname) if (db_query(query) == -1 ) { db_rollback_transaction(); - dm_free(escaped_scriptname); - dm_free(escaped_newname); + g_free(escaped_scriptname); + g_free(escaped_newname); return DM_EQUERY; } @@ -731,8 +731,8 @@ int db_rename_sievescript(u64_t user_idnr, char *scriptname, char *newname) if (db_query(query) == -1 ) { db_rollback_transaction(); - dm_free(escaped_scriptname); - dm_free(escaped_newname); + g_free(escaped_scriptname); + g_free(escaped_newname); return DM_EQUERY; } } @@ -742,8 +742,8 @@ int db_rename_sievescript(u64_t user_idnr, char *scriptname, char *newname) "UPDATE %ssievescripts SET name = '%s', active = %d " "WHERE owner_idnr = %llu AND name = '%s'", DBPFX,escaped_newname,active,user_idnr,escaped_scriptname); - dm_free(escaped_scriptname); - dm_free(escaped_newname); + g_free(escaped_scriptname); + g_free(escaped_newname); if (db_query(query) == -1) { TRACE(TRACE_ERROR, "error replacing sievescript '%s' " @@ -777,7 +777,7 @@ int db_add_sievescript(u64_t user_idnr, char *scriptname, char *script) if (db_query(query) == -1 ) { db_rollback_transaction(); - dm_free(escaped_scriptname); + g_free(escaped_scriptname); return DM_EQUERY; } @@ -790,7 +790,7 @@ int db_add_sievescript(u64_t user_idnr, char *scriptname, char *script) if (db_query(query) == -1 ) { db_rollback_transaction(); - dm_free(escaped_scriptname); + g_free(escaped_scriptname); return DM_EQUERY; } } @@ -810,17 +810,17 @@ int db_add_sievescript(u64_t user_idnr, char *scriptname, char *script) snprintf(&escaped_query[esclen + startlen], maxesclen - esclen - startlen, "', 0)"); - dm_free(escaped_scriptname); + g_free(escaped_scriptname); if (db_query(escaped_query) == -1) { TRACE(TRACE_ERROR, "error adding sievescript '%s' " "for user_idnr [%llu]" , scriptname, user_idnr); db_rollback_transaction(); - dm_free(escaped_query); + g_free(escaped_query); return DM_EQUERY; } - dm_free(escaped_query); + g_free(escaped_query); db_commit_transaction(); return DM_SUCCESS; @@ -838,7 +838,7 @@ int db_deactivate_sievescript(u64_t user_idnr, char *scriptname) "UPDATE %ssievescripts set active = 0 " "where owner_idnr = %llu and name = '%s'", DBPFX,user_idnr,escaped_scriptname); - dm_free(escaped_scriptname); + g_free(escaped_scriptname); if (db_query(query) == -1) { TRACE(TRACE_ERROR, "error deactivating sievescript '%s' " @@ -868,7 +868,7 @@ int db_activate_sievescript(u64_t user_idnr, char *scriptname) TRACE(TRACE_ERROR, "error activating sievescript '%s' " "for user_idnr [%llu]" , scriptname, user_idnr); - dm_free(escaped_scriptname); + g_free(escaped_scriptname); db_rollback_transaction(); return DM_EQUERY; } @@ -877,7 +877,7 @@ int db_activate_sievescript(u64_t user_idnr, char *scriptname) "UPDATE %ssievescripts SET active = 1 " "WHERE owner_idnr = %llu AND name = '%s'", DBPFX,user_idnr,escaped_scriptname); - dm_free(escaped_scriptname); + g_free(escaped_scriptname); if (db_query(query) == -1) { TRACE(TRACE_ERROR, "error activating sievescript '%s' " @@ -903,7 +903,7 @@ int db_delete_sievescript(u64_t user_idnr, char *scriptname) "DELETE FROM %ssievescripts " "WHERE owner_idnr = %llu AND name = '%s'", DBPFX,user_idnr,escaped_scriptname); - dm_free(escaped_scriptname); + g_free(escaped_scriptname); if (db_query(query) == -1) { TRACE(TRACE_ERROR, "error deleting sievescript '%s' " @@ -962,7 +962,7 @@ int db_get_notify_address(u64_t user_idnr, char **notify_address) if (db_num_rows() > 0) { query_result = db_get_result(0, 0); if (query_result && strlen(query_result) > 0) { - *notify_address = dm_strdup(query_result); + *notify_address = g_strdup(query_result); TRACE(TRACE_DEBUG, "found address [%s]", *notify_address); } } @@ -994,7 +994,7 @@ int db_get_reply_body(u64_t user_idnr, char **reply_body) if (db_num_rows() > 0) { query_result = db_get_result(0, 0); if (query_result && strlen(query_result) > 0) { - *reply_body = dm_strdup(query_result); + *reply_body = g_strdup(query_result); TRACE(TRACE_DEBUG, "found reply_body [%s]", *reply_body); } } @@ -1076,7 +1076,7 @@ int db_insert_physmessage_with_internal_date(timestring_t internal_date, snprintf(query, DEF_QUERYSIZE, "INSERT INTO %sphysmessage (messagesize, internal_date) " "VALUES (0, %s)", DBPFX,to_date_str); - dm_free(to_date_str); + g_free(to_date_str); } else { snprintf(query, DEF_QUERYSIZE, "INSERT INTO %sphysmessage (messagesize, internal_date) " @@ -1201,7 +1201,7 @@ int db_insert_message_block_physmessage(const char *block, block_size, physmessage_id); if (db_query(escaped_query) == DM_EQUERY) { - dm_free(escaped_query); + g_free(escaped_query); return DM_EQUERY; } @@ -1303,7 +1303,7 @@ int db_count_iplog(const char *lasttokeep, u64_t *affected_rows) escaped_lasttokeep = dm_stresc(lasttokeep); snprintf(query, DEF_QUERYSIZE, "SELECT * FROM %spbsp WHERE since < '%s'", DBPFX, escaped_lasttokeep); - dm_free(escaped_lasttokeep); + g_free(escaped_lasttokeep); if (db_query(query) == -1) { TRACE(TRACE_ERROR, "error executing query"); @@ -2019,11 +2019,11 @@ static int mailbox_empty(u64_t mailbox_idnr) /* delete every message in the mailbox */ for (i = 0; i < n; i++) { if (db_delete_message(message_idnrs[i]) == -1) { - dm_free(message_idnrs); + g_free(message_idnrs); return DM_EQUERY; } } - dm_free(message_idnrs); + g_free(message_idnrs); return DM_SUCCESS; } @@ -2106,12 +2106,12 @@ int db_send_message_lines(void *fstream, u64_t message_idnr, long lines, int no_ /* always send all headers */ raw = get_crlf_encoded_dots(hdr); ci_write((FILE *)fstream, "%s", raw); - dm_free(hdr); - dm_free(raw); + g_free(hdr); + g_free(raw); /* send requested body lines */ raw = get_crlf_encoded_dots(buf); - dm_free(buf); + g_free(buf); s = g_string_new(raw); if (lines > 0) { @@ -2122,7 +2122,7 @@ int db_send_message_lines(void *fstream, u64_t message_idnr, long lines, int no_ } s = g_string_truncate(s,pos); } - dm_free(raw); + g_free(raw); if (pos > 0 || lines < 0) ci_write((FILE *)fstream, "%s", s->str); @@ -2365,7 +2365,7 @@ int db_deleted_purge(u64_t * affected_rows) for (i = 0; i < *affected_rows; i++) { if (db_delete_message(message_idnrs[i]) == -1) { TRACE(TRACE_ERROR, "error deleting message"); - dm_free(message_idnrs); + g_free(message_idnrs); return DM_EQUERY; } } @@ -2572,7 +2572,7 @@ static int db_findmailbox_owner(const char *name, u64_t owner_idnr, "SELECT mailbox_idnr FROM %smailboxes " "WHERE %s AND owner_idnr=%llu", DBPFX, mailbox_like, owner_idnr); - dm_free(mailbox_like); + g_free(mailbox_like); if (db_query(query) == -1) { TRACE(TRACE_ERROR, "could not select mailbox '%s'", name); @@ -2731,7 +2731,7 @@ static int mailboxes_by_regex(u64_t user_idnr, int only_subscribed, const char * if (*nr_mailboxes == 0) { /* none exist, none matched */ - dm_free(tmp_mailboxes); + g_free(tmp_mailboxes); return DM_SUCCESS; } @@ -3011,7 +3011,7 @@ int db_imap_split_mailbox(const char *mailbox, u64_t owner_idnr, g_strfreev(chunks); g_free(username); - dm_free(cpy); + g_free(cpy); return DM_SUCCESS; @@ -3034,7 +3034,7 @@ egeneral: g_list_free(*mailboxes); g_strfreev(chunks); g_free(username); - dm_free(cpy); + g_free(cpy); return ret; } @@ -3230,7 +3230,7 @@ int db_createmailbox(const char * name, u64_t owner_idnr, u64_t * mailbox_idnr) " VALUES ('%s', %llu, 1, 1, 1, 1, 1, 1, %d)",DBPFX, escaped_simple_name, owner_idnr, IMAPPERM_READWRITE); - dm_free(escaped_simple_name); + g_free(escaped_simple_name); if ((result = db_query(query)) == DM_EQUERY) { TRACE(TRACE_ERROR, "could not create mailbox"); @@ -3359,7 +3359,7 @@ int db_listmailboxchildren(u64_t mailbox_idnr, u64_t user_idnr, "SELECT mailbox_idnr FROM %smailboxes WHERE %s" " AND owner_idnr = %llu",DBPFX, mailbox_like, user_idnr); - dm_free(mailbox_like); + g_free(mailbox_like); } else snprintf(query, DEF_QUERYSIZE, @@ -3700,7 +3700,7 @@ int db_getmailboxname(u64_t mailbox_idnr, u64_t user_idnr, char *name) *name = '\0'; return DM_SUCCESS; } - tmp_name = dm_strdup(query_result); + tmp_name = g_strdup(query_result); db_free_result(); tmp_fq_name = mailbox_add_namespace(tmp_name, owner_idnr, user_idnr); @@ -3713,7 +3713,7 @@ int db_getmailboxname(u64_t mailbox_idnr, u64_t user_idnr, char *name) tmp_fq_name_len = IMAP_MAX_MAILBOX_NAMELEN - 1; strncpy(name, tmp_fq_name, tmp_fq_name_len); name[tmp_fq_name_len] = '\0'; - dm_free(tmp_name); + g_free(tmp_name); g_free(tmp_fq_name); return DM_SUCCESS; } @@ -3732,7 +3732,7 @@ int db_setmailboxname(u64_t mailbox_idnr, const char *name) "WHERE mailbox_idnr = %llu", DBPFX, escaped_name, mailbox_idnr); - dm_free(escaped_name); + g_free(escaped_name); if (db_query(query) == -1) { TRACE(TRACE_ERROR, "could not set name"); @@ -4522,7 +4522,7 @@ int db_usermap_resolve(clientinfo_t *ci, const char *username, char *real_userna "ORDER BY sock_allow, sock_deny", DBPFX, escaped_username); - dm_free(escaped_username); + g_free(escaped_username); if (db_query(query) == -1) { TRACE(TRACE_ERROR, "could not select usermap"); @@ -4607,7 +4607,7 @@ int db_user_exists(const char *username, u64_t * user_idnr) "SELECT user_idnr FROM %susers WHERE lower(userid) = lower('%s')", DBPFX, escaped_username); - dm_free(escaped_username); + g_free(escaped_username); if (db_query(query) == -1) { TRACE(TRACE_ERROR, "could not select user information"); @@ -4645,7 +4645,7 @@ int db_user_create(const char *username, const char *password, const char *encty /* first check to see if this user already exists */ snprintf(query, DEF_QUERYSIZE, "SELECT * FROM %susers WHERE userid = '%s'",DBPFX, escaped_username); - dm_free(escaped_username); + g_free(escaped_username); if (db_query(query) == -1) return DM_EQUERY; @@ -4682,8 +4682,8 @@ int db_user_create(const char *username, const char *password, const char *encty DBPFX,escaped_username,*user_idnr, escaped_password,clientid, maxmail, enctype ? enctype : "", db_get_sql(SQL_CURRENT_TIMESTAMP)); } - dm_free(escaped_username); - dm_free(escaped_password); + g_free(escaped_username); + g_free(escaped_password); if (db_query(query) == -1) { TRACE(TRACE_ERROR, "query for adding user failed"); @@ -4723,7 +4723,7 @@ int db_user_delete(const char * username) escaped_username = dm_stresc(username); snprintf(query, DEF_QUERYSIZE, "DELETE FROM %susers WHERE userid = '%s'", DBPFX, escaped_username); - dm_free(escaped_username); + g_free(escaped_username); if (db_query(query) == -1) { /* query failed */ @@ -4744,7 +4744,7 @@ int db_user_rename(u64_t user_idnr, const char *new_name) escaped_new_name = dm_stresc(new_name); snprintf(query, DEF_QUERYSIZE, "UPDATE %susers SET userid = '%s' WHERE user_idnr=%llu", DBPFX, escaped_new_name, user_idnr); - dm_free(escaped_new_name); + g_free(escaped_new_name); if (db_query(query) == -1) { TRACE(TRACE_ERROR, "could not change name for user [%llu]", user_idnr); @@ -4814,9 +4814,9 @@ int db_replycache_register(const char *to, const char *from, const char *handle) DBPFX, escaped_to, escaped_from, escaped_handle); if (db_query(query) < 0) { - dm_free(escaped_to); - dm_free(escaped_from); - dm_free(escaped_handle); + g_free(escaped_to); + g_free(escaped_from); + g_free(escaped_handle); return DM_EQUERY; } @@ -4837,9 +4837,9 @@ int db_replycache_register(const char *to, const char *from, const char *handle) db_free_result(); - dm_free(escaped_to); - dm_free(escaped_from); - dm_free(escaped_handle); + g_free(escaped_to); + g_free(escaped_from); + g_free(escaped_handle); if (db_query(query)== -1) return DM_EQUERY; @@ -4865,9 +4865,9 @@ int db_replycache_unregister(const char *to, const char *from, const char *handl "AND handle = '%s' ", DBPFX, escaped_to, escaped_from, escaped_handle); - dm_free(escaped_to); - dm_free(escaped_from); - dm_free(escaped_handle); + g_free(escaped_to); + g_free(escaped_from); + g_free(escaped_handle); if (db_query(query) < 0) return DM_EQUERY; @@ -4901,9 +4901,9 @@ int db_replycache_validate(const char *to, const char *from, DBPFX, escaped_to, escaped_from, escaped_handle, tmp->str); g_string_free(tmp, TRUE); - dm_free(escaped_to); - dm_free(escaped_from); - dm_free(escaped_handle); + g_free(escaped_to); + g_free(escaped_from); + g_free(escaped_handle); if (db_query(query) < 0) return DM_EQUERY; diff --git a/dbmail-imapsession.c b/dbmail-imapsession.c index e59db24b..cfc97ee6 100644 --- a/dbmail-imapsession.c +++ b/dbmail-imapsession.c @@ -647,7 +647,7 @@ GTree * dbmail_imap_session_get_msginfo(struct ImapSession *self, GTree *ids) "ORDER BY message_idnr ASC",to_char_str,DBPFX,DBPFX, *lo, *hi, ud->mailbox.uid, MESSAGE_STATUS_NEW, MESSAGE_STATUS_SEEN); - dm_free(to_char_str); + g_free(to_char_str); if (db_query(query) == -1) { TRACE(TRACE_ERROR, "could not select message"); @@ -1482,9 +1482,9 @@ int dbmail_imap_session_prompt(struct ImapSession * self, char * prompt, char * fflush(self->ci->tx); if ( (dbmail_imap_session_readln(self, buf) <= 0) ) { - dm_free(buf); - dm_free(prompt64); - dm_free(promptcat); + g_free(buf); + g_free(prompt64); + g_free(promptcat); return -1; } @@ -1500,9 +1500,9 @@ int dbmail_imap_session_prompt(struct ImapSession * self, char * prompt, char * return -1; } - dm_free(buf); - dm_free(prompt64); - dm_free(promptcat); + g_free(buf); + g_free(prompt64); + g_free(promptcat); return 0; } @@ -2042,7 +2042,7 @@ static void free_args(struct ImapSession *self) { int i; for (i = 0; i < MAX_ARGS && self->args[i]; i++) - dm_free(self->args[i]); + g_free(self->args[i]); self->args_idx = 0; } diff --git a/dbmail-message.c b/dbmail-message.c index 24b0453b..0f291c34 100644 --- a/dbmail-message.c +++ b/dbmail-message.c @@ -33,8 +33,6 @@ extern db_param_t _db_params; #define MESSAGE_MAX_LINE_SIZE 1024 -static int dm_errno = 0; - #define DBMAIL_TEMPMBOX "INBOX" #define THIS_MODULE "message" @@ -211,7 +209,7 @@ void dbmail_message_free(struct DbmailMessage *self) g_tree_destroy(self->header_value); self->id=0; - dm_free(self); + g_free(self); } @@ -985,8 +983,6 @@ static gboolean _header_cache(const char UNUSED *key, const char *header, gpoint unsigned i; gboolean isaddr = 0; - dm_errno = 0; - /* skip headernames with spaces like From_ */ if (strchr(header, ' ')) return FALSE; diff --git a/dbmail-user.c b/dbmail-user.c index dbeeda04..bf91c4a0 100644 --- a/dbmail-user.c +++ b/dbmail-user.c @@ -207,7 +207,7 @@ int mkpassword(const char * const user, const char * const passwd, md5str = dm_md5((unsigned char *)passwd); null_strncpy(pw, md5str, 49); *enctype = "md5sum"; - dm_free(md5str); + g_free(md5str); break; case MD5_DIGEST_RAW: null_strncpy(pw, passwd, 49); @@ -218,7 +218,7 @@ int mkpassword(const char * const user, const char * const passwd, md5str = dm_md5_base64((unsigned char *)passwd); null_strncpy(pw, md5str, 49); *enctype = "md5base64"; - dm_free(md5str); + g_free(md5str); } break; case MD5_BASE64_RAW: @@ -259,7 +259,7 @@ int mkpassword(const char * const user, const char * const passwd, } /* Pass this out of the function. */ - *password = dm_strdup(pw); + *password = g_strdup(pw); return result; } @@ -27,11 +27,6 @@ #include "dbmail.h" -#ifdef USE_GC -#define GC_DEBUG -#include <gc/gc.h> -#endif - typedef enum { TRACE_FATAL = 0, TRACE_ERROR, @@ -55,23 +50,6 @@ typedef enum { #endif -#ifdef USE_GC - -#define dm_malloc(s) GC_MALLOC(s) -#define dm_free(p) GC_FREE(p) -#define dm_calloc(n,p) GC_MALLOC((n) * (p)) -#define dm_realloc(n,p) GC_REALLOC((n),(p)) - -#else - -#define dm_malloc(s) g_malloc(s) -#define dm_free(p) g_free(p) -#define dm_calloc(n,p) g_malloc0(n,p) -#define dm_realloc(n,p) g_realloc(n,p) - -#endif - - #define TRACE(level, fmt...) trace(level, THIS_MODULE, __FILE__, __func__, __LINE__, fmt) void trace(trace_t level, const char * module, const char * file, const char * function, @@ -79,6 +57,4 @@ void trace(trace_t level, const char * module, void configure_debug(trace_t trace_syslog, trace_t trace_stderr); -#define dm_strdup(s) g_strdup(s) - #endif diff --git a/dm_base64.c b/dm_base64.c index a8f5dd69..49791ec3 100644 --- a/dm_base64.c +++ b/dm_base64.c @@ -145,7 +145,7 @@ char **base64_decodev(char *str) /* Copy each nul terminated string to the array. */ for (i = j = n = 0; i <= decodelen; i++) { if (decoded[i] == '\0') { - ret[n] = dm_strdup(decoded + j); + ret[n] = g_strdup(decoded + j); j = i + 1; n++; } @@ -200,12 +200,12 @@ int dsnuser_init(deliver_to_user_t * dsnuser) dsnuser->mailbox = NULL; dsnuser->source = BOX_NONE; - dsnuser->userids = (struct dm_list *) dm_malloc(sizeof(struct dm_list)); + dsnuser->userids = g_new0(struct dm_list, 1); if (dsnuser->userids == NULL) return -1; - dsnuser->forwards = (struct dm_list *) dm_malloc(sizeof(struct dm_list)); + dsnuser->forwards = g_new0(struct dm_list, 1); if (dsnuser->forwards == NULL) { - dm_free(dsnuser->userids); + g_free(dsnuser->userids); return -1; } @@ -290,7 +290,7 @@ static int address_has_alias_mailbox(deliver_to_user_t *delivery) delivery->forwards, 0); TRACE(TRACE_DEBUG, "user [%s] found total of [%d] aliases", newaddress, alias_count); - dm_free(newaddress); + g_free(newaddress); if (alias_count > 0) return 1; @@ -317,26 +317,26 @@ static int address_is_username_mailbox(deliver_to_user_t *delivery) if (user_exists < 0) { /* An error occurred. */ TRACE(TRACE_ERROR, "error checking user [%s]", newaddress); - dm_free(newaddress); + g_free(newaddress); return -1; } if (user_exists == 0) { /* User does not exist. */ TRACE(TRACE_INFO, "username not found [%s]", newaddress); - dm_free(newaddress); + g_free(newaddress); return 0; } if (dm_list_nodeadd(delivery->userids, &userid, sizeof(u64_t)) == 0) { TRACE(TRACE_ERROR, "out of memory"); - dm_free(newaddress); + g_free(newaddress); return -1; } TRACE(TRACE_DEBUG, "added user [%s] id [%llu] to delivery list", newaddress, userid); - dm_free(newaddress); + g_free(newaddress); return 1; } @@ -442,7 +442,7 @@ static int address_is_domain_catchall(deliver_to_user_t *delivery) static int address_is_userpart_catchall(deliver_to_user_t *delivery) { - char *userpart = dm_strdup(delivery->address); + char *userpart = g_strdup(delivery->address); char *userpartcut; int userpart_count; @@ -37,7 +37,7 @@ /* max number of retries when synchronizing mailbox with dbase */ #define MAX_RETRIES 20 -#define null_free(p) { dm_free(p); p = NULL; } +#define null_free(p) { g_free(p); p = NULL; } diff --git a/imapcommands.c b/imapcommands.c index 7f3836fb..70ad9978 100644 --- a/imapcommands.c +++ b/imapcommands.c @@ -385,12 +385,12 @@ int _ic_delete(struct ImapSession *self) result = db_isselectable(mboxid); if (result == 0) { dbmail_imap_session_printf(self, "%s NO mailbox is non-selectable\r\n", self->tag); - dm_free(children); + g_free(children); return 1; } if (result == -1) { dbmail_imap_session_printf(self, "* BYE internal dbase error\r\n"); - dm_free(children); + g_free(children); return -1; /* fatal */ } @@ -401,7 +401,7 @@ int _ic_delete(struct ImapSession *self) if (result == -1) { dbmail_imap_session_printf(self, "* BYE internal dbase error\r\n"); - dm_free(children); + g_free(children); return -1; /* fatal */ } @@ -411,7 +411,7 @@ int _ic_delete(struct ImapSession *self) /* ok done */ dbmail_imap_session_printf(self, "%s OK DELETE completed\r\n", self->tag); - dm_free(children); + g_free(children); return 0; } @@ -554,7 +554,7 @@ int _ic_rename(struct ImapSession *self) result = db_getmailboxname(children[i], ud->userid, name); if (result == -1) { dbmail_imap_session_printf(self, "* BYE internal dbase error\r\n"); - dm_free(children); + g_free(children); return -1; } @@ -562,7 +562,7 @@ int _ic_rename(struct ImapSession *self) /* strange error, let's say its fatal */ TRACE(TRACE_ERROR, "mailbox names appear to be corrupted"); dbmail_imap_session_printf(self, "* BYE internal error regarding mailbox names\r\n"); - dm_free(children); + g_free(children); return -1; } @@ -571,13 +571,13 @@ int _ic_rename(struct ImapSession *self) result = db_setmailboxname(children[i], newname); if (result == -1) { dbmail_imap_session_printf(self, "* BYE internal dbase error\r\n"); - dm_free(children); + g_free(children); return -1; } } if (children) - dm_free(children); + g_free(children); /* now replace name */ result = db_setmailboxname(mboxid, self->args[1]); @@ -709,7 +709,7 @@ int _ic_list(struct ImapSession *self) result = db_findmailbox_by_regex(ud->userid, pattern, &children, &nchildren, list_is_lsub); if (result == -1) { dbmail_imap_session_printf(self, "* BYE internal dbase error\r\n"); - dm_free(children); + g_free(children); g_free(pattern); return -1; } @@ -717,7 +717,7 @@ int _ic_list(struct ImapSession *self) if (result == 1) { dbmail_imap_session_printf(self, "%s BAD invalid pattern specified\r\n", self->tag); - dm_free(children); + g_free(children); g_free(pattern); return 1; } @@ -750,10 +750,10 @@ int _ic_list(struct ImapSession *self) if (children) - dm_free(children); + g_free(children); g_free(pattern); - dm_free(mb); + g_free(mb); dbmail_imap_session_printf(self, "%s OK %s completed\r\n", self->tag, thisname); return 0; @@ -1233,7 +1233,7 @@ int _ic_expunge(struct ImapSession *self) } if (msgids) - dm_free(msgids); + g_free(msgids); msgids = NULL; dbmail_imap_session_printf(self, "%s OK EXPUNGE completed\r\n", self->tag); @@ -2025,7 +2025,7 @@ int _ic_getacl(struct ImapSession *self) } dbmail_imap_session_printf(self, "* ACL \"%s\" %s\r\n", self->args[self->args_idx], acl_string); - dm_free(acl_string); + g_free(acl_string); dbmail_imap_session_printf(self, "%s OK GETACL completed\r\n", self->tag); return 0; } @@ -2072,7 +2072,7 @@ int _ic_listrights(struct ImapSession *self) dbmail_imap_session_printf(self, "* LISTRIGHTS \"%s\" %s %s\r\n", self->args[self->args_idx], self->args[self->args_idx+1], listrights_string); dbmail_imap_session_printf(self, "%s OK LISTRIGHTS completed\r\n", self->tag); - dm_free(listrights_string); + g_free(listrights_string); return 0; } @@ -2105,7 +2105,7 @@ int _ic_myrights(struct ImapSession *self) dbmail_imap_session_printf(self, "* MYRIGHTS \"%s\" %s\r\n", self->args[self->args_idx], myrights_string); - dm_free(myrights_string); + g_free(myrights_string); dbmail_imap_session_printf(self, "%s OK MYRIGHTS complete\r\n", self->tag); return 0; } @@ -125,7 +125,7 @@ int lmtp_handle_connection(clientinfo_t * ci) gethostname(myhostname, 64); myhostname[63] = 0; /* make sure string is terminated */ - buffer = (char *) dm_malloc(INCOMING_BUFFER_SIZE * sizeof(char)); + buffer = g_new0(char, INCOMING_BUFFER_SIZE); if (!buffer) { TRACE(TRACE_MESSAGE, "Could not allocate buffer"); @@ -138,7 +138,7 @@ int lmtp_handle_connection(clientinfo_t * ci) fflush(ci->tx); } else { TRACE(TRACE_MESSAGE, "TX stream is null!"); - dm_free(buffer); + g_free(buffer); return 0; } @@ -166,7 +166,7 @@ int lmtp_handle_connection(clientinfo_t * ci) if (alarm_occured) { alarm_occured = 0; client_close(); - dm_free(buffer); + g_free(buffer); return 0; } } while (ferror(ci->rx) && errno == EINTR); @@ -192,7 +192,7 @@ int lmtp_handle_connection(clientinfo_t * ci) /* memory cleanup */ lmtp_reset(&session); - dm_free(buffer); + g_free(buffer); buffer = NULL; /* reset timers */ @@ -460,7 +460,7 @@ int lmtp(void *stream, void *instream, char *buffer, child_reg_connected_user(tmpaddr); } if (tmpaddr != NULL) - dm_free(tmpaddr); + g_free(tmpaddr); } return 1; } @@ -153,14 +153,14 @@ int main(int argc, char *argv[]) TRACE(TRACE_INFO, "using RETURN_PATH for bounces"); /* Add argument onto the returnpath list. */ - returnpath = dm_strdup(optarg); + returnpath = g_strdup(optarg); break; case 'u': TRACE(TRACE_INFO, "using SPECIAL_DELIVERY to usernames"); dsnuser_init(&dsnuser); - dsnuser.address = dm_strdup(optarg); + dsnuser.address = g_strdup(optarg); dsnuser.source = BOX_COMMANDLINE; /* Add argument onto the users list. */ @@ -176,7 +176,7 @@ int main(int argc, char *argv[]) TRACE(TRACE_INFO, "using SPECIAL_DELIVERY to email addresses"); dsnuser_init(&dsnuser); - dsnuser.address = dm_strdup(optarg); + dsnuser.address = g_strdup(optarg); dsnuser.source = BOX_COMMANDLINE; /* Add argument onto the users list. */ @@ -303,7 +303,7 @@ int main(int argc, char *argv[]) userlist = g_list_first(userlist); while (1) { dsnuser_init(&dsnuser); - dsnuser.address = dm_strdup((char *) userlist->data); + dsnuser.address = g_strdup((char *) userlist->data); if (! dm_list_nodeadd(&dsnusers, &dsnuser, sizeof(deliver_to_user_t))) { TRACE(TRACE_ERROR,"out of memory in dm_list_nodeadd"); @@ -321,7 +321,7 @@ int main(int argc, char *argv[]) TRACE(TRACE_DEBUG, "setting mailbox for all deliveries to [%s]", deliver_to_mailbox); /* Loop through the dsnusers list, setting the destination mailbox. */ for (tmp = dm_list_getstart(&dsnusers); tmp != NULL; tmp = tmp->nextnode) { - ((deliver_to_user_t *)tmp->data)->mailbox = dm_strdup(deliver_to_mailbox); + ((deliver_to_user_t *)tmp->data)->mailbox = g_strdup(deliver_to_mailbox); if (brute_force) { ((deliver_to_user_t *)tmp->data)->source = BOX_BRUTEFORCE; } else { @@ -383,7 +383,7 @@ int main(int argc, char *argv[]) dbmail_message_free(msg); dsnuser_free_list(&dsnusers); dm_list_free(&users.start); - dm_free(returnpath); + g_free(returnpath); g_list_foreach(userlist, (GFunc)g_free, NULL); g_list_free(userlist); @@ -52,19 +52,17 @@ int __m_blkadd(MEM * m); */ MEM *mopen() { - MEM *mp = (MEM *) dm_malloc(sizeof(MEM)); + MEM *mp = g_new0(MEM, 1); if (!mp) { __m_errno = M_NOMEM; return NULL; } - memset(mp, 0, sizeof(*mp)); - - mp->firstblk = (memblock_t *) dm_malloc(sizeof(memblock_t)); + mp->firstblk = g_new0(memblock_t, 1); if (!mp->firstblk) { __m_errno = M_NOMEM; - dm_free(mp); + g_free(mp); return NULL; } @@ -99,11 +97,11 @@ void mclose(MEM ** m) tmp = (*m)->firstblk; while (tmp) { next = tmp->nextblk; /* save address */ - dm_free(tmp); + g_free(tmp); tmp = next; } - dm_free(*m); + g_free(*m); *m = NULL; return; @@ -404,7 +402,7 @@ void mreset(MEM * m) while (tmp) { next = tmp->nextblk; /* save address */ - dm_free(tmp); + g_free(tmp); tmp = next; m->nblocks--; } @@ -432,7 +430,7 @@ int __m_blkadd(MEM * m) return 0; } - newblk = (memblock_t *) dm_malloc(sizeof(memblock_t)); + newblk = g_new0(memblock_t, 1); if (!newblk) { __m_errno = M_NOMEM; return 0; @@ -109,7 +109,7 @@ void create_unique_id(char *target, u64_t message_idnr) md5_str = dm_md5((unsigned char *)target); snprintf(target, UID_SIZE, "%s", md5_str); TRACE(TRACE_DEBUG, "created: %s", target); - dm_free(md5_str); + g_free(md5_str); g_free(a_message_idnr); g_free(a_rand); } @@ -154,7 +154,7 @@ char *mailbox_add_namespace(const char *mailbox_name, u64_t owner_idnr, else g_string_printf(t, "%s%s%s%s%s", NAMESPACE_USER, MAILBOX_SEPARATOR, owner, MAILBOX_SEPARATOR, mailbox_name); - dm_free(owner); + g_free(owner); fq = t->str; g_string_free(t,FALSE); @@ -289,7 +289,7 @@ int read_from_stream(FILE * instream, char **m_buf, int maxlen) /* Allocate a zero length string on length 0. */ if (maxlen == 0) { - *m_buf = dm_strdup(""); + *m_buf = g_strdup(""); return 0; } @@ -362,7 +362,7 @@ int find_bounded(const char * const value, char left, char right, tmpleft++; tmplen = tmpright - tmpleft; - *retchar = dm_malloc(sizeof(char) * (tmplen + 1)); + *retchar = g_new0(char, tmplen + 1); if (*retchar == NULL) { *retchar = NULL; *retsize = 0; diff --git a/modules/authldap.c b/modules/authldap.c index 095342da..f8963973 100644 --- a/modules/authldap.c +++ b/modules/authldap.c @@ -35,7 +35,6 @@ extern char *configFile; static LDAP *_ldap_conn = NULL; -LDAPMod **_ldap_mod; LDAPMessage *_ldap_res; LDAPMessage *_ldap_msg; int _ldap_err; @@ -717,7 +716,7 @@ int auth_check_userid(u64_t user_idnr) TRACE(TRACE_DEBUG, "didn't find user_idnr [%llu]", user_idnr); } - dm_free(returnid); + g_free(returnid); return ret; } @@ -927,16 +926,13 @@ int auth_adduser(const char *username, const char *password, const char *enctype UNUSED, u64_t clientid, u64_t maxmail, u64_t * user_idnr) { - int i, j, result; - /*int ret; unused variable */ - int NUM_MODS = 9; + int i = 0, result; GString *nid = g_string_new(""); GString *cid = g_string_new(""); GString *maxm = g_string_new(""); u64_t newidnr = dm_ldap_get_freeid(_ldap_cfg.field_nid); - g_string_printf(nid,"%llu", newidnr); g_string_printf(cid,"%llu",clientid); g_string_printf(maxm,"%llu",maxmail); @@ -950,80 +946,64 @@ int auth_adduser(const char *username, const char *password, field_t mail_type = "mail"; field_t obj_type = "objectClass"; - + GString *t=g_string_new(""); assert(user_idnr != NULL); *user_idnr = 0; - /* Construct the array of LDAPMod structures representing the attributes */ - if (! (_ldap_mod = (LDAPMod **) dm_malloc((NUM_MODS + 1) * sizeof(LDAPMod *)))) { - TRACE(TRACE_ERROR, "Cannot allocate memory for mods array"); - return -1; - } - - for (i = 0; i < NUM_MODS; i++) { - if (! (_ldap_mod[i] = (LDAPMod *) dm_malloc(sizeof(LDAPMod)))) { - TRACE(TRACE_ERROR, "Cannot allocate memory for mods element %d", i); - for (j = 0; j < (i - 1); j++) - dm_free(_ldap_mod[j]); - dm_free(_ldap_mod); - return -1; - } - } - g_string_printf(t,"%s=%s,%s", _ldap_cfg.cn_string, username, _ldap_cfg.base_dn); _ldap_dn=g_strdup(t->str); g_string_free(t,TRUE); TRACE(TRACE_DEBUG, "Adding user with DN of [%s]", _ldap_dn); - i = 0; - _ldap_mod[i]->mod_op = LDAP_MOD_ADD; - _ldap_mod[i]->mod_type = obj_type; - _ldap_mod[i]->mod_values = obj_values; + LDAPMod *mods[10], mod_obj_type, mod_field_passwd, mod_mail_type, + mod_field_uid, mod_field_cid, mod_field_maxmail, mod_field_nid; + + + mod_obj_type.mod_op = LDAP_MOD_ADD; + mod_obj_type.mod_type = obj_type; + mod_obj_type.mod_values = obj_values; + mods[i++] = &mod_obj_type; if (strlen(_ldap_cfg.field_passwd) > 0) { - i++; - _ldap_mod[i]->mod_op = LDAP_MOD_ADD; - _ldap_mod[i]->mod_type = _ldap_cfg.field_passwd; - _ldap_mod[i]->mod_values = pw_values; + mod_field_passwd.mod_op = LDAP_MOD_ADD; + mod_field_passwd.mod_type = _ldap_cfg.field_passwd; + mod_field_passwd.mod_values = pw_values; + mods[i++] = &mod_field_passwd; } - i++; - _ldap_mod[i]->mod_op = LDAP_MOD_ADD; - _ldap_mod[i]->mod_type = mail_type; - _ldap_mod[i]->mod_values = uid_values; + mod_mail_type.mod_op = LDAP_MOD_ADD; + mod_mail_type.mod_type = mail_type; + mod_mail_type.mod_values = uid_values; + mods[i++] = &mod_mail_type; - i++; - _ldap_mod[i]->mod_op = LDAP_MOD_ADD; - _ldap_mod[i]->mod_type = _ldap_cfg.field_uid; - _ldap_mod[i]->mod_values = uid_values; + mod_field_uid.mod_op = LDAP_MOD_ADD; + mod_field_uid.mod_type = _ldap_cfg.field_uid; + mod_field_uid.mod_values = uid_values; + mods[i++] = &mod_field_uid; - i++; - _ldap_mod[i]->mod_op = LDAP_MOD_ADD; - _ldap_mod[i]->mod_type = _ldap_cfg.field_cid; - _ldap_mod[i]->mod_values = cid_values; + mod_field_cid.mod_op = LDAP_MOD_ADD; + mod_field_cid.mod_type = _ldap_cfg.field_cid; + mod_field_cid.mod_values = cid_values; + mods[i++] = &mod_field_cid; - i++; - _ldap_mod[i]->mod_op = LDAP_MOD_ADD; - _ldap_mod[i]->mod_type = _ldap_cfg.field_maxmail; - _ldap_mod[i]->mod_values = max_values; + mod_field_maxmail.mod_op = LDAP_MOD_ADD; + mod_field_maxmail.mod_type = _ldap_cfg.field_maxmail; + mod_field_maxmail.mod_values = max_values; + mods[i++] = &mod_field_maxmail; - i++; - _ldap_mod[i]->mod_op = LDAP_MOD_ADD; - _ldap_mod[i]->mod_type = _ldap_cfg.field_nid; - _ldap_mod[i]->mod_values = nid_values; + mod_field_nid.mod_op = LDAP_MOD_ADD; + mod_field_nid.mod_type = _ldap_cfg.field_nid; + mod_field_nid.mod_values = nid_values; + mods[i++] = &mod_field_nid; - i++; - _ldap_mod[i] = NULL; + mods[i++] = NULL; - _ldap_err = ldap_add_s(_ldap_conn, _ldap_dn, _ldap_mod); + _ldap_err = ldap_add_s(_ldap_conn, _ldap_dn, mods); g_strfreev(obj_values); - for (i = 0; i < NUM_MODS; i++) - dm_free(_ldap_mod[i]); - dm_free(_ldap_mod); ldap_memfree(_ldap_dn); if (_ldap_err) { @@ -1478,7 +1458,7 @@ static int forward_exists(const char *alias, const char *deliver_to) g_free(objectfilter); - dm_free(dn); + g_free(dn); g_string_free(t,TRUE); g_list_foreach(l,(GFunc)g_free,NULL); diff --git a/modules/authsql.c b/modules/authsql.c index 0c07d391..6a61967c 100644 --- a/modules/authsql.c +++ b/modules/authsql.c @@ -218,7 +218,7 @@ int auth_check_user_ext(const char *username, struct dm_list *userids, struct dm TRACE(TRACE_DEBUG, "checking user [%s] in alias table", username); - if (!(escaped_username = (char *) dm_malloc(strlen(username) * 2 + 1))) { + if (!(escaped_username = g_new0(char, strlen(username) * 2 + 1))) { TRACE(TRACE_ERROR, "out of memory allocating escaped username"); return -1; } @@ -231,7 +231,7 @@ int auth_check_user_ext(const char *username, struct dm_list *userids, struct dm "AND lower(alias) <> lower(deliver_to)", DBPFX, escaped_username); - dm_free(escaped_username); + g_free(escaped_username); TRACE(TRACE_DEBUG, "checks [%d]", checks); @@ -431,7 +431,7 @@ int auth_validate(clientinfo_t *ci, char *username, char *password, u64_t * user /* redundant statement: query_result = db_get_result(0, 1); */ md5str = dm_md5((unsigned char *)password); is_validated = (strncmp(md5str, query_result, 32) == 0) ? 1 : 0; - dm_free(md5str); + g_free(md5str); } else { TRACE(TRACE_DEBUG, "validating using MD5 hash comparison"); strncpy(salt, query_result, 12); @@ -446,13 +446,13 @@ int auth_validate(clientinfo_t *ci, char *username, char *password, u64_t * user query_result = db_get_result(0, 1); md5str = dm_md5((unsigned char *)password); is_validated = (strncmp(md5str, query_result, 32) == 0) ? 1 : 0; - dm_free(md5str); + g_free(md5str); } else if (strcasecmp(query_result, "md5base64") == 0) { TRACE(TRACE_DEBUG, "validating using MD5 digest base64 comparison"); query_result = db_get_result(0, 1); md5str = dm_md5_base64((unsigned char *)password); is_validated = (strncmp(md5str, query_result, 32) == 0) ? 1 : 0; - dm_free(md5str); + g_free(md5str); } if (is_validated) { @@ -510,8 +510,8 @@ u64_t auth_md5_validate(clientinfo_t *ci UNUSED, char *username, user_idnr = (query_result) ? strtoull(query_result, NULL, 10) : 0; db_free_result(); - dm_free(md5_apop_we); - dm_free(checkstring); + g_free(md5_apop_we); + g_free(checkstring); db_user_log_login(user_idnr); return user_idnr; @@ -520,8 +520,8 @@ u64_t auth_md5_validate(clientinfo_t *ci UNUSED, char *username, TRACE(TRACE_MESSAGE, "user [%s] could not be validated", username); db_free_result(); - dm_free(md5_apop_we); - dm_free(checkstring); + g_free(md5_apop_we); + g_free(checkstring); return 0; } @@ -548,8 +548,7 @@ char *auth_get_userid(u64_t user_idnr) query_result = db_get_result(0, 0); if (query_result) { TRACE(TRACE_DEBUG, "query_result = %s", query_result); - if (!(returnid = - (char *) dm_malloc(strlen(query_result) + 1))) { + if (!(returnid = g_new0(char, strlen(query_result) + 1))) { TRACE(TRACE_ERROR, "out of memory"); db_free_result(); return NULL; @@ -603,7 +602,7 @@ int auth_get_users_from_clientid(u64_t client_id, u64_t ** user_ids, return -1; } *num_users = db_num_rows(); - *user_ids = (u64_t *) dm_malloc(*num_users * sizeof(u64_t)); + *user_ids = g_new0(u64_t, *num_users); if (*user_ids == NULL) { TRACE(TRACE_ERROR, "error allocating memory, probably out of memory"); db_free_result(); @@ -621,7 +620,7 @@ int auth_addalias(u64_t user_idnr, const char *alias, u64_t clientid) { char *escaped_alias; - if (!(escaped_alias = (char *) dm_malloc(strlen(alias) * 2 + 1))) { + if (!(escaped_alias = g_new0(char, strlen(alias) * 2 + 1))) { TRACE(TRACE_ERROR, "out of memory allocating escaped alias"); return -1; } @@ -637,14 +636,14 @@ int auth_addalias(u64_t user_idnr, const char *alias, u64_t clientid) if (__auth_query(__auth_query_data) == -1) { /* query failed */ TRACE(TRACE_ERROR, "query for searching alias failed"); - dm_free(escaped_alias); + g_free(escaped_alias); return -1; } if (db_num_rows() > 0) { TRACE(TRACE_INFO, "alias [%s] for user [%llu] already exists", escaped_alias, user_idnr); - dm_free(escaped_alias); + g_free(escaped_alias); db_free_result(); return 1; } @@ -654,7 +653,7 @@ int auth_addalias(u64_t user_idnr, const char *alias, u64_t clientid) "INSERT INTO %saliases (alias,deliver_to,client_idnr) " "VALUES ('%s',%llu,%llu)",DBPFX, escaped_alias, user_idnr, clientid); - dm_free(escaped_alias); + g_free(escaped_alias); if (db_query(__auth_query_data) == -1) { /* query failed */ @@ -670,12 +669,12 @@ int auth_addalias_ext(const char *alias, char *escaped_alias; char *escaped_deliver_to; - if (!(escaped_alias = (char *) dm_malloc(strlen(alias) * 2 + 1))) { + if (!(escaped_alias = g_new0(char, strlen(alias) * 2 + 1))) { TRACE(TRACE_ERROR, "out of memory allocating escaped alias"); return -1; } - if (!(escaped_deliver_to = (char *) dm_malloc(strlen(deliver_to) * 2 + 1))) { + if (!(escaped_deliver_to = g_new0(char, strlen(deliver_to) * 2 + 1))) { TRACE(TRACE_ERROR, "out of memory allocating escaped deliver_to"); return -1; } @@ -703,16 +702,16 @@ int auth_addalias_ext(const char *alias, if (__auth_query(__auth_query_data) == -1) { /* query failed */ TRACE(TRACE_ERROR, "query for searching alias failed"); - dm_free(escaped_alias); - dm_free(escaped_deliver_to); + g_free(escaped_alias); + g_free(escaped_deliver_to); return -1; } if (db_num_rows() > 0) { TRACE(TRACE_INFO, "alias [%s] --> [%s] already exists", alias, deliver_to); - dm_free(escaped_alias); - dm_free(escaped_deliver_to); + g_free(escaped_alias); + g_free(escaped_deliver_to); db_free_result(); return 1; } @@ -721,8 +720,8 @@ int auth_addalias_ext(const char *alias, snprintf(__auth_query_data, DEF_QUERYSIZE, "INSERT INTO %saliases (alias,deliver_to,client_idnr) " "VALUES ('%s','%s',%llu)",DBPFX, escaped_alias, escaped_deliver_to, clientid); - dm_free(escaped_alias); - dm_free(escaped_deliver_to); + g_free(escaped_alias); + g_free(escaped_deliver_to); if (__auth_query(__auth_query_data) == -1) { /* query failed */ @@ -736,7 +735,7 @@ int auth_removealias(u64_t user_idnr, const char *alias) { char *escaped_alias; - if (!(escaped_alias = (char *) dm_malloc(strlen(alias) * 2 + 1))) { + if (!(escaped_alias = g_new0(char, strlen(alias) * 2 + 1))) { TRACE(TRACE_ERROR, "out of memory allocating escaped alias"); return -1; } @@ -746,7 +745,7 @@ int auth_removealias(u64_t user_idnr, const char *alias) snprintf(__auth_query_data, DEF_QUERYSIZE, "DELETE FROM %saliases WHERE deliver_to=%llu " "AND lower(alias) = lower('%s')",DBPFX, user_idnr, escaped_alias); - dm_free(escaped_alias); + g_free(escaped_alias); if (__auth_query(__auth_query_data) == -1) { /* query failed */ @@ -761,12 +760,12 @@ int auth_removealias_ext(const char *alias, const char *deliver_to) char *escaped_alias; char *escaped_deliver_to; - if (!(escaped_alias = (char *) dm_malloc(strlen(alias) * 2 + 1))) { + if (!(escaped_alias = g_new0(char, strlen(alias) * 2 + 1))) { TRACE(TRACE_ERROR, "out of memory allocating escaped alias"); return -1; } - if (!(escaped_deliver_to = (char *) dm_malloc(strlen(deliver_to) * 2 + 1))) { + if (!(escaped_deliver_to = g_new0(char, strlen(deliver_to) * 2 + 1))) { TRACE(TRACE_ERROR, "out of memory allocating escaped deliver_to"); return -1; } @@ -777,8 +776,8 @@ int auth_removealias_ext(const char *alias, const char *deliver_to) snprintf(__auth_query_data, DEF_QUERYSIZE, "DELETE FROM %saliases WHERE lower(deliver_to) = lower('%s') " "AND lower(alias) = lower('%s')",DBPFX, deliver_to, alias); - dm_free(escaped_alias); - dm_free(escaped_deliver_to); + g_free(escaped_alias); + g_free(escaped_deliver_to); if (db_query(__auth_query_data) == -1) { /* query failed */ diff --git a/modules/sortsieve.c b/modules/sortsieve.c index 50adf706..550757e5 100644 --- a/modules/sortsieve.c +++ b/modules/sortsieve.c @@ -149,7 +149,7 @@ int sort_vacation(sieve2_context_t *s, void *my) } if (md5_handle) - dm_free(md5_handle); + g_free(md5_handle); m->result->cancelkeep = 0; return SIEVE2_OK; @@ -529,7 +529,7 @@ static int sort_teardown(sieve2_context_t **s2c, dm_list_free(&sort_context->freelist.start); if (sort_context) { - dm_free(sort_context); + g_free(sort_context); } res = sieve2_free(&sieve2_context); @@ -603,7 +603,7 @@ static int sort_startup(sieve2_context_t **s2c, } } - sort_context = dm_malloc(sizeof(struct sort_context)); + sort_context = g_new0(struct sort_context, 1); if (!sort_context) { sort_teardown(&sieve2_context, &sort_context); return DM_EGENERAL; @@ -651,7 +651,7 @@ const char * sort_listextensions(void) /* So we'll make our own copy. */ if (extensions) - extensions = dm_strdup(extensions); + extensions = g_strdup(extensions); /* If this fails, then we don't care about the * memory leak, because the program has to bomb out. @@ -700,7 +700,7 @@ sort_result_t *sort_validate(u64_t user_idnr, char *scriptname) freesieve: if (sort_context->s_buf) - dm_free(sort_context->s_buf); + g_free(sort_context->s_buf); if (exitnull) result = NULL; @@ -773,9 +773,9 @@ sort_result_t *sort_process(u64_t user_idnr, struct DbmailMessage *message) freesieve: if (sort_context->s_buf) - dm_free(sort_context->s_buf); + g_free(sort_context->s_buf); if (sort_context->script) - dm_free(sort_context->script); + g_free(sort_context->script); if (exitnull) result = NULL; @@ -796,7 +796,7 @@ void sort_free_result(sort_result_t *result) g_string_free(result->errormsg, TRUE); if (result->rejectmsg != NULL) g_string_free(result->rejectmsg, TRUE); - dm_free(result); + g_free(result); } int sort_get_cancelkeep(sort_result_t *result) @@ -126,13 +126,13 @@ static int send_mail(struct DbmailMessage *message, return 1; } if (parse_and_escape(from, &escaped_from) < 0) { - dm_free(escaped_to); + g_free(escaped_to); TRACE(TRACE_MESSAGE, "could not prepare 'from' address."); return 1; } sendmail_command = g_strconcat(sendmail, " -f ", escaped_from, " ", escaped_to, NULL); - dm_free(escaped_to); - dm_free(escaped_from); + g_free(escaped_to); + g_free(escaped_from); if (!sendmail_command) { TRACE(TRACE_ERROR, "out of memory calling g_strconcat"); return -1; @@ -395,7 +395,7 @@ static int send_reply(struct DbmailMessage *message, const char *body) db_replycache_register(to, escaped_send_address, "replycache"); } - dm_free(newsubject); + g_free(newsubject); dbmail_message_free(new_message); return 0; @@ -439,10 +439,10 @@ static int execute_auto_ran(struct DbmailMessage *message, u64_t useridnr) TRACE(TRACE_DEBUG, "sending notifcation to [%s]", notify_address); if (send_notification(message, notify_address) < 0) { TRACE(TRACE_ERROR, "error in call to send_notification."); - dm_free(notify_address); + g_free(notify_address); return -1; } - dm_free(notify_address); + g_free(notify_address); } } } @@ -458,10 +458,10 @@ static int execute_auto_ran(struct DbmailMessage *message, u64_t useridnr) else { if (send_reply(message, reply_body) < 0) { TRACE(TRACE_ERROR, "error in call to send_reply"); - dm_free(reply_body); + g_free(reply_body); return -1; } - dm_free(reply_body); + g_free(reply_body); } } @@ -30,9 +30,15 @@ quota_t *quota_alloc(int n_resources) { quota_t *quota; - quota = - dm_malloc(sizeof(quota_t) + - n_resources * sizeof(resource_limit_t)); + /* We're allocating enough memory off the end of the quota + * structure to accomodate an array of resource_limit structs. + * This is the declaration: + * resource_limit_t resource[0]; + * it's a pretty cool abuse of C to alloc more memory off the end of + * this array and access it way out of bounds into that extra memory! + */ + quota = g_malloc(sizeof(quota_t) + n_resources * sizeof(resource_limit_t)); + if (quota != NULL) { quota->root = NULL; quota->n_resources = n_resources; @@ -65,16 +71,16 @@ void quota_set_resource_limit(quota_t * quota, int resource_idx, */ int quota_set_root(quota_t * quota, char *root) { - dm_free(quota->root); - quota->root = dm_strdup(root); + g_free(quota->root); + quota->root = g_strdup(root); return (quota->root == NULL); } /* Free a quota structure. */ void quota_free(quota_t * quota) { - dm_free(quota->root); - dm_free(quota); + g_free(quota->root); + g_free(quota); } @@ -89,18 +89,18 @@ int main(int argc, char *argv[]) act = opt; if (!script_name) { - script_name = dm_strdup(optarg); + script_name = g_strdup(optarg); } else if (!script_source) { - script_source = dm_strdup(optarg); + script_source = g_strdup(optarg); } break; case 'c': if (optarg) - script_name = dm_strdup(optarg); + script_name = g_strdup(optarg); act = opt; break; case 'u': - user_name = dm_strdup(optarg); + user_name = g_strdup(optarg); break; case 'l': if (act != 0) @@ -184,7 +184,7 @@ int main(int argc, char *argv[]) qprintf("Opening connection to database...\n"); if (db_connect() != 0) { qerrorf("Failed. Could not connect to database (check log)\n"); - dm_free(user_name); + g_free(user_name); return -1; } @@ -192,7 +192,7 @@ int main(int argc, char *argv[]) qprintf("Opening connection to authentication...\n"); if (auth_connect() != 0) { qerrorf("Failed. Could not connect to authentication (check log)\n"); - dm_free(user_name); + g_free(user_name); return -1; } @@ -237,9 +237,9 @@ int main(int argc, char *argv[]) } mainend: - dm_free(user_name); - dm_free(script_name); - dm_free(script_source); + g_free(user_name); + g_free(script_name); + g_free(script_source); db_disconnect(); auth_disconnect(); config_free(); @@ -322,9 +322,9 @@ int do_cat(u64_t user_idnr, char *name) printf("%s", buf); - dm_free(buf); + g_free(buf); if (!name) - dm_free(scriptname); + g_free(scriptname); return 0; } @@ -372,7 +372,7 @@ int do_insert(u64_t user_idnr, char *name, char *source) /* Check if the script is valid */ res = db_add_sievescript(user_idnr, "@!temp-script!@", buf); - dm_free(buf); + g_free(buf); if (res != 0) { qerrorf("Error inserting temporary script into the database!\n"); return -1; @@ -462,7 +462,7 @@ int do_list(u64_t user_idnr) printf(" - "); printf("%s\n", info->name); - dm_free(info->name); + g_free(info->name); tmp = tmp->nextnode; } @@ -80,7 +80,7 @@ int tims_handle_connection(clientinfo_t * ci) if (! ci->tx) { TRACE(TRACE_MESSAGE, "TX stream is null!"); - dm_free(buffer); + g_free(buffer); return 0; } @@ -104,7 +104,7 @@ int tims_handle_connection(clientinfo_t * ci) if (alarm_occured) { alarm_occured = 0; client_close(); - dm_free(buffer); + g_free(buffer); return 0; } } while (ferror(ci->rx) && errno == EINTR); @@ -137,7 +137,7 @@ int tims_handle_connection(clientinfo_t * ci) } /* memory cleanup */ - dm_free(buffer); + g_free(buffer); buffer = NULL; /* reset timers */ @@ -276,7 +276,7 @@ int tims(clientinfo_t *ci, char *buffer, PopSession_t * session) strncpy(tmpcharlen, tmpleft, (10 < tmplen ? 10 : tmplen)); tmpcharlen[(10 < tmplen ? 10 : tmplen)] = '\0'; - dm_free(tmpleft); + g_free(tmpleft); authlen = strtoull(tmpcharlen, NULL, 10); if (authlen >= UINT_MAX) { @@ -317,8 +317,8 @@ int tims(clientinfo_t *ci, char *buffer, PopSession_t * session) ci_write((FILE *) stream, "OK\r\n"); session->state = AUTH; session->useridnr = useridnr; - session->username = dm_strdup(tmp64[1]); - session->password = dm_strdup(tmp64[2]); + session->username = g_strdup(tmp64[1]); + session->password = g_strdup(tmp64[2]); child_reg_connected_user(session->username); } else { ci_write((FILE *) stream, "NO \"Username or password incorrect.\"\r\n"); @@ -361,7 +361,7 @@ int tims(clientinfo_t *ci, char *buffer, PopSession_t * session) strncpy(scriptname, tmpleft, (MAX_SIEVE_SCRIPTNAME < tmplen ? MAX_SIEVE_SCRIPTNAME : tmplen)); /* Of course, be sure to NULL terminate, because strncpy() likely won't */ scriptname[(MAX_SIEVE_SCRIPTNAME < tmplen ? MAX_SIEVE_SCRIPTNAME : tmplen)] = '\0'; - dm_free(tmpleft); + g_free(tmpleft); /* Offset from the previous match to make sure not to pull * the "length" from a script with a malicious name */ @@ -378,7 +378,7 @@ int tims(clientinfo_t *ci, char *buffer, PopSession_t * session) strncpy(tmpcharlen, tmpleft, (10 < tmplen ? 10 : tmplen)); tmpcharlen[(10 < tmplen ? 10 : tmplen)] = '\0'; - dm_free(tmpleft); + g_free(tmpleft); scriptlen = strtoull(tmpcharlen, NULL, 10); TRACE(TRACE_INFO, "Client sending script of length [%llu]", scriptlen); @@ -456,7 +456,7 @@ int tims(clientinfo_t *ci, char *buffer, PopSession_t * session) strncpy(scriptname, tmpleft, (MAX_SIEVE_SCRIPTNAME < tmplen ? MAX_SIEVE_SCRIPTNAME : tmplen)); /* Of course, be sure to NULL terminate, because strncpy() likely won't */ scriptname[(MAX_SIEVE_SCRIPTNAME < tmplen ? MAX_SIEVE_SCRIPTNAME : tmplen)] = '\0'; - dm_free(tmpleft); + g_free(tmpleft); ret = db_activate_sievescript(session->useridnr, scriptname); if (ret == -3) { @@ -475,7 +475,7 @@ int tims(clientinfo_t *ci, char *buffer, PopSession_t * session) ci_write((FILE *) stream, "OK \"No scripts are active at this time.\"\r\n"); } else { ret = db_deactivate_sievescript(session->useridnr, scriptname); - dm_free(scriptname); + g_free(scriptname); if (ret == -3) { ci_write((FILE *)stream, "NO \"Active script does not exist.\"\r\n"); return -1; @@ -512,7 +512,7 @@ int tims(clientinfo_t *ci, char *buffer, PopSession_t * session) strncpy(scriptname, tmpleft, (MAX_SIEVE_SCRIPTNAME < tmplen ? MAX_SIEVE_SCRIPTNAME : tmplen)); /* Of course, be sure to NULL terminate, because strncpy() likely won't */ scriptname[(MAX_SIEVE_SCRIPTNAME < tmplen ? MAX_SIEVE_SCRIPTNAME : tmplen)] = '\0'; - dm_free(tmpleft); + g_free(tmpleft); ret = db_get_sievescript_byname(session->useridnr, scriptname, &script); if (ret == -3) { @@ -549,7 +549,7 @@ int tims(clientinfo_t *ci, char *buffer, PopSession_t * session) strncpy(scriptname, tmpleft, (MAX_SIEVE_SCRIPTNAME < tmplen ? MAX_SIEVE_SCRIPTNAME : tmplen)); /* Of course, be sure to NULL terminate, because strncpy() likely won't */ scriptname[(MAX_SIEVE_SCRIPTNAME < tmplen ? MAX_SIEVE_SCRIPTNAME : tmplen)] = '\0'; - dm_free(tmpleft); + g_free(tmpleft); ret = db_delete_sievescript(session->useridnr, scriptname); if (ret == -3) { @@ -613,7 +613,7 @@ int tims(clientinfo_t *ci, char *buffer, PopSession_t * session) if (sort_result) sort_free_result(sort_result); if (f_buf) - dm_free(f_buf); + g_free(f_buf); return 1; } @@ -366,7 +366,7 @@ int main(int argc, char *argv[]) if (pw[len-1] == '\n') pw[len-1] = '\0'; /* fgets guarantees a nul terminated string. */ - passwd = dm_strdup(pw); + passwd = g_strdup(pw); /* Restore the previous terminal state (with echo back on). */ tcsetattr(fileno(stdin), TCSANOW, &oldattr); |