From 7c1150052b9992cda75b1b91c4cfee88b07291c6 Mon Sep 17 00:00:00 2001 From: SJ Date: Tue, 18 Feb 2014 10:46:23 +0100 Subject: [PATCH] code cleanup --- configure | 7 +---- configure.in | 17 +---------- etc/sphinx.conf.in | 12 ++++++-- init.d/rc.searchd.in | 6 +++- src/config.h | 13 ++------- src/defs.h | 5 ---- src/message.c | 6 ---- src/multitenancy.c | 69 -------------------------------------------- src/piler.c | 19 ------------ src/piler.h | 3 -- src/session.c | 10 ------- util/db-mysql.sql | 6 +++- webui/config.php | 2 +- 13 files changed, 25 insertions(+), 150 deletions(-) delete mode 100644 src/multitenancy.c diff --git a/configure b/configure index e76f6dc8..292215da 100755 --- a/configure +++ b/configure @@ -3647,9 +3647,6 @@ ac_cv_lib_wrap=ac_cv_lib_wrap_main fi - - - # Check whether --enable-tweak-sent-time was given. if test "${enable_tweak_sent_time+set}" = set; then : enableval=$enable_tweak_sent_time; have_tweak_sent_time=$enableval @@ -4516,7 +4513,7 @@ if test "${with_plugin_timeout+set}" = set; then : timeout_binary=`which timeout`" $withval " fi - if test "$withval" = "yes" || $withval = ""; then + if test "$withval" = "yes" || test "$withval" = ""; then echo "please specify the value for plugin-timeout, eg. --with-plugin-timeout=15"; exit; fi @@ -4749,8 +4746,6 @@ if test "$have_psql" = "yes"; then defs="$defs -DNEED_PSQL" fi - - if test z`which pdftotext 2>/dev/null` != "z"; then pdftotext=`which pdftotext` diff --git a/configure.in b/configure.in index a2d8a387..23ae9720 100644 --- a/configure.in +++ b/configure.in @@ -44,7 +44,6 @@ have_zlib="no" have_starttls="no" have_tcpwrappers="no" have_tweak_sent_time="no" -dnl have_multitenancy="no" pdftotext="no" catdoc="no" @@ -129,11 +128,6 @@ if test "$want_tcpwrappers" = "yes"; then fi -dnl AC_ARG_ENABLE(multitenancy, -dnl [ --enable-multitenancy build piler with multitenancy support (!!!EXPERIMENTAL!!!)], have_multitenancy=$enableval, have_multitenancy="no") - - - AC_ARG_ENABLE(tweak-sent-time, [ --tweak-sent-time tweak sent time], have_tweak_sent_time=$enableval, have_tweak_sent_time="no") @@ -267,7 +261,7 @@ AC_ARG_WITH(plugin-timeout, timeout_binary=`which timeout`" $withval " fi - if test "$withval" = "yes" || $withval = ""; then + if test "$withval" = "yes" || test "$withval" = ""; then echo "please specify the value for plugin-timeout, eg. --with-plugin-timeout=15"; exit; fi @@ -462,15 +456,6 @@ if test "$have_psql" = "yes"; then defs="$defs -DNEED_PSQL" fi - -dnl if test "$have_multitenancy" = "yes"; then -dnl echo "multitenancy support: yes" -dnl defs="$defs -DHAVE_MULTITENANCY" -dnl objs="$objs multitenancy.o" -dnl else -dnl echo "multitenancy support: no" -dnl fi - if test z`which pdftotext 2>/dev/null` != "z"; then pdftotext=`which pdftotext` AC_DEFINE_UNQUOTED(HAVE_PDFTOTEXT, "$timeout_binary$pdftotext", [path to pdftotext]) diff --git a/etc/sphinx.conf.in b/etc/sphinx.conf.in index 3e202880..05dbe29d 100644 --- a/etc/sphinx.conf.in +++ b/etc/sphinx.conf.in @@ -11,11 +11,17 @@ source base sql_pass = MYSQL_PASSWORD sql_attr_uint = size - sql_attr_uint = arrived sql_attr_uint = sent - sql_attr_uint = direction - sql_attr_uint = folder sql_attr_uint = attachments +## +## From 0.1.25 these attributes are disabled for an optimized version +## If you have indexed data already, then don't exclude them otherwise +## you have to reindex all your emails +## +## sql_attr_uint = direction +## sql_attr_uint = arrived +## sql_attr_uint = folder + } source delta : base diff --git a/init.d/rc.searchd.in b/init.d/rc.searchd.in index 581b610e..fa03a90f 100644 --- a/init.d/rc.searchd.in +++ b/init.d/rc.searchd.in @@ -20,7 +20,11 @@ PID_NUMBER=`test -f ${PID_FILE} && cat ${PID_FILE}` start() { echo "starting searchd . . ." - su piler -c searchd + if [ `id -u` -eq 0 ]; then + su piler -c searchd + else + searchd + fi } stop() { diff --git a/src/config.h b/src/config.h index 927f64da..87d58d57 100644 --- a/src/config.h +++ b/src/config.h @@ -14,7 +14,7 @@ #define VERSION "0.1.25-master-branch" -#define BUILD 861 +#define BUILD 864 #define HOSTID "mailarchiver" @@ -94,15 +94,8 @@ #define SQL_PREPARED_STMT_GET_DOMAINS "SELECT `domain` FROM `" SQL_DOMAIN_TABLE "`" #define SQL_PREPARED_STMT_GET_META_ID_BY_MESSAGE_ID "SELECT id FROM " SQL_METADATA_TABLE " WHERE message_id=?" #define SQL_PREPARED_STMT_INSERT_INTO_RCPT_TABLE "INSERT INTO " SQL_RECIPIENT_TABLE " (`id`,`to`,`todomain`) VALUES(?,?,?)" - -#ifdef HAVE_MULTITENANCY - #define SQL_PREPARED_STMT_INSERT_INTO_SPHINX_TABLE "INSERT INTO " SQL_SPHINX_TABLE " (`id`, `from`, `to`, `fromdomain`, `todomain`, `subject`, `body`, `arrived`, `sent`, `size`, `direction`, `folder`, `attachments`, `attachment_types`, `customer`) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)" - #define SQL_PREPARED_STMT_INSERT_INTO_META_TABLE "INSERT INTO " SQL_METADATA_TABLE " (`from`,`fromdomain`,`subject`,`spam`,`arrived`,`sent`,`retained`,`size`,`hlen`,`direction`,`attachments`,`piler_id`,`message_id`,`reference`,`digest`,`bodydigest`,`vcode`,`customer`) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)" -#else - #define SQL_PREPARED_STMT_INSERT_INTO_SPHINX_TABLE "INSERT INTO " SQL_SPHINX_TABLE " (`id`, `from`, `to`, `fromdomain`, `todomain`, `subject`, `body`, `arrived`, `sent`, `size`, `direction`, `folder`, `attachments`, `attachment_types`) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)" - #define SQL_PREPARED_STMT_INSERT_INTO_META_TABLE "INSERT INTO " SQL_METADATA_TABLE " (`from`,`fromdomain`,`subject`,`spam`,`arrived`,`sent`,`retained`,`size`,`hlen`,`direction`,`attachments`,`piler_id`,`message_id`,`reference`,`digest`,`bodydigest`,`vcode`) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)" -#endif - +#define SQL_PREPARED_STMT_INSERT_INTO_SPHINX_TABLE "INSERT INTO " SQL_SPHINX_TABLE " (`id`, `from`, `to`, `fromdomain`, `todomain`, `subject`, `body`, `arrived`, `sent`, `size`, `direction`, `folder`, `attachments`, `attachment_types`) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)" +#define SQL_PREPARED_STMT_INSERT_INTO_META_TABLE "INSERT INTO " SQL_METADATA_TABLE " (`from`,`fromdomain`,`subject`,`spam`,`arrived`,`sent`,`retained`,`size`,`hlen`,`direction`,`attachments`,`piler_id`,`message_id`,`reference`,`digest`,`bodydigest`,`vcode`) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)" #define SQL_PREPARED_STMT_INSERT_INTO_ATTACHMENT_TABLE "INSERT INTO " SQL_ATTACHMENT_TABLE " (`piler_id`,`attachment_id`,`sig`,`name`,`type`,`size`,`ptr`) VALUES(?,?,?,?,?,?,?)" #define SQL_PREPARED_STMT_GET_ATTACHMENT_ID_BY_SIGNATURE "SELECT `id` FROM `" SQL_ATTACHMENT_TABLE "` WHERE `sig`=?" #define SQL_PREPARED_STMT_GET_ATTACHMENT_POINTER "SELECT `piler_id`, `attachment_id` FROM " SQL_ATTACHMENT_TABLE " WHERE id=?" diff --git a/src/defs.h b/src/defs.h index 99a23c69..fcac850a 100644 --- a/src/defs.h +++ b/src/defs.h @@ -305,11 +305,6 @@ struct __data { SSL_CTX *ctx; SSL *ssl; - -#ifdef HAVE_MULTITENANCY - struct list *customers; -#endif - }; diff --git a/src/message.c b/src/message.c index fe8ba226..624b7f01 100644 --- a/src/message.c +++ b/src/message.c @@ -50,9 +50,6 @@ int store_index_data(struct session_data *sdata, struct _state *state, struct __ data->sql[data->pos] = (char *)&data->folder; data->type[data->pos] = TYPE_LONG; data->pos++; data->sql[data->pos] = (char *)&state->n_attachments; data->type[data->pos] = TYPE_LONG; data->pos++; data->sql[data->pos] = sdata->attachments; data->type[data->pos] = TYPE_STRING; data->pos++; -#ifdef HAVE_MULTITENANCY - data->sql[data->pos] = (char *)&sdata->customer_id; data->type[data->pos] = TYPE_SHORT; data->pos++; -#endif if(p_exec_query(sdata, data->stmt_insert_into_sphinx_table, data) == OK) rc = OK; @@ -207,9 +204,6 @@ int store_meta_data(struct session_data *sdata, struct _state *state, struct __d data->sql[data->pos] = sdata->digest; data->type[data->pos] = TYPE_STRING; data->pos++; data->sql[data->pos] = sdata->bodydigest; data->type[data->pos] = TYPE_STRING; data->pos++; data->sql[data->pos] = &vcode[0]; data->type[data->pos] = TYPE_STRING; data->pos++; -#ifdef HAVE_MULTITENANCY - data->sql[data->pos] = (char *)&sdata->customer_id; data->type[data->pos] = TYPE_SHORT; data->pos++; -#endif if(p_exec_query(sdata, data->stmt_insert_into_meta_table, data) == ERR){ ret = ERR_EXISTS; diff --git a/src/multitenancy.c b/src/multitenancy.c deleted file mode 100644 index 50b56b54..00000000 --- a/src/multitenancy.c +++ /dev/null @@ -1,69 +0,0 @@ -/* - * multitenancy.c, SJ - */ - -#include -#include -#include -#include -#include -#include - - -void load_customers(struct session_data *sdata, struct __data *data, struct __config *cfg){ - int rc; - char s[SMALLBUFSIZE]; - MYSQL_RES *res; - MYSQL_ROW row; - - data->customers = NULL; - - snprintf(s, sizeof(s)-1, "SELECT `id`, `guid` FROM `%s`", SQL_CUSTOMER_TABLE); - - if(mysql_real_query(&(sdata->mysql), s, strlen(s)) == 0){ - res = mysql_store_result(&(sdata->mysql)); - if(res != NULL){ - while((row = mysql_fetch_row(res))){ - snprintf(s, sizeof(s)-1, "%s@%d", (char*)row[1], atoi(row[0])); - rc = append_list(&(data->customers), s); - if(cfg->verbosity >= _LOG_DEBUG && rc == 1) syslog(LOG_PRIORITY, "adding customer: id: %d, guid: '%s'", atoi(row[0]), row[1]); - if(rc == -1) syslog(LOG_PRIORITY, "error: failed to add customer: id: %d, guid: '%s'", atoi(row[0]), row[1]); - } - - mysql_free_result(res); - } - - } - -} - - -unsigned char get_customer_id_by_rcpt_to_email(char *rcpttoemail, struct __data *data){ - int len; - char *q; - struct list *p; - - q = strchr(rcpttoemail, '@'); - if(!q || strlen(q) < 3) return 0; - - len = strlen(rcpttoemail) - strlen(q) + 1; - if(len < 5) return 0; - - p = data->customers; - - while(p != NULL){ - if(strncasecmp(p->s, rcpttoemail, len) == 0){ - q = strchr(p->s, '@'); - - if(!q || strlen(q) < 2) return 0; - - return atoi(q+1); - } - - p = p->r; - } - - return 0; -} - - diff --git a/src/piler.c b/src/piler.c index 7e3adcd4..22821263 100644 --- a/src/piler.c +++ b/src/piler.c @@ -233,10 +233,6 @@ void p_clean_exit(){ clearhash(data.mydomains); -#ifdef HAVE_MULTITENANCY - free_list(data.customers); -#endif - syslog(LOG_PRIORITY, "%s has been terminated", PROGNAME); unlink(cfg.pidfile); @@ -312,10 +308,6 @@ void initialise_configuration(){ clearhash(data.mydomains); -#ifdef HAVE_MULTITENANCY - free_list(data.customers); -#endif - data.folder = 0; data.recursive_folder_names = 0; @@ -323,10 +315,6 @@ void initialise_configuration(){ initrules(data.archiving_rules); initrules(data.retention_rules); -#ifdef HAVE_MULTITENANCY - data.customers = NULL; -#endif - memset(data.starttls, 0, sizeof(data.starttls)); #ifdef HAVE_STARTTLS @@ -345,10 +333,6 @@ void initialise_configuration(){ load_mydomains(&sdata, &data, &cfg); -#ifdef HAVE_MULTITENANCY - load_customers(&sdata, &data, &cfg); -#endif - if(cfg.server_id > 0) insert_offset(&sdata, cfg.server_id); close_database(&sdata); @@ -397,9 +381,6 @@ int main(int argc, char **argv){ inithash(data.mydomains); initrules(data.archiving_rules); initrules(data.retention_rules); -#ifdef HAVE_MULTITENANCY - data.customers = NULL; -#endif data.ctx = NULL; data.ssl = NULL; diff --git a/src/piler.h b/src/piler.h index 33e143e5..e8b0a3e9 100644 --- a/src/piler.h +++ b/src/piler.h @@ -66,8 +66,5 @@ int retrieve_file_from_archive(char *filename, int mode, char **buffer, FILE *de void load_mydomains(struct session_data *sdata, struct __data *data, struct __config *cfg); int is_email_address_on_my_domains(char *email, struct __data *data); -void load_customers(struct session_data *sdata, struct __data *data, struct __config *cfg); -unsigned char get_customer_id_by_rcpt_to_email(char *rcpttoemail, struct __data *data); - #endif /* _PILER_H */ diff --git a/src/session.c b/src/session.c index f01f15ab..59e52e27 100644 --- a/src/session.c +++ b/src/session.c @@ -199,9 +199,6 @@ int handle_smtp_session(int new_sd, struct __data *data, struct __config *cfg){ extractEmail(sdata.rcptto[i], rcpttoemail); - /* copy default config to enable policy support */ - //memcpy(&my_cfg, cfg, sizeof(struct __config)); - inj = ERR; @@ -421,15 +418,8 @@ AFTER_PERIOD: state = SMTP_STATE_RCPT_TO; - /* check against blackhole addresses */ - extractEmail(buf, rcpttoemail); - #ifdef HAVE_MULTITENANCY - if(sdata.customer_id == 0) sdata.customer_id = get_customer_id_by_rcpt_to_email(rcpttoemail, data); - #endif - - if(sdata.num_of_rcpt_to < MAX_RCPT_TO-1) sdata.num_of_rcpt_to++; diff --git a/util/db-mysql.sql b/util/db-mysql.sql index de6a4ba1..7d4106b1 100644 --- a/util/db-mysql.sql +++ b/util/db-mysql.sql @@ -367,7 +367,11 @@ create table if not exists `ldap` ( `ldap_base_dn` varchar(255) not null, `ldap_bind_dn` varchar(255) not null, `ldap_bind_pw` varchar(255) not null, - `ldap_auditor_member_dn` varchar(255) default null + `ldap_auditor_member_dn` varchar(255) default null, + `ldap_mail_attr` varchar(128) default null, + `ldap_account_objectclass` varchar(128) default null, + `ldap_distributionlist_attr` varchar(128) default null, + `ldap_distributionlist_objectclass` varchar(128) default null ) Engine=InnoDB; diff --git a/webui/config.php b/webui/config.php index d5942314..529032ee 100644 --- a/webui/config.php +++ b/webui/config.php @@ -133,7 +133,7 @@ $config['PASSWORD_CHANGE_ENABLED'] = 0; $config['ENABLE_STATISTICS'] = 1; $config['ENABLE_HISTORY'] = 1; $config['ENABLE_REMOTE_IMAGES'] = '0'; -$config['ENABLE_ON_THE_FLY_VERIFICATION'] = 1; +$config['ENABLE_ON_THE_FLY_VERIFICATION'] = 0; $config['ENABLE_LDAP_IMPORT_FEATURE'] = 0; $config['ENABLE_FOLDER_RESTRICTIONS'] = 0; $config['SEARCH_RESULT_CHECKBOX_CHECKED'] = 0;