Commit 1c79c7fb authored by Claudemir Todo Bom's avatar Claudemir Todo Bom

* use stored procedures to check passwords and update lastread field

parent 829cb747
Pipeline #263 passed with stage
in 1 minute and 26 seconds
#!/bin/bash
cat /etc/default/wwmail | sed -e 's/: /=/g' > /tmp/wwmail.$$.tmp
source /tmp/wwmail.$$.tmp
rm /tmp/wwmail.$$.tmp
echo "UPDATE users SET lastread = now() WHERE address = '${USER}'" | /usr/bin/mysql -h ${WW_ISP_HOST} -p${WW_ISP_PASS} -r -N -u${WW_ISP_USER} ${WW_ISP_DB}
# Finally execute the imap/pop3 binary. If you use both, you'll need two scripts.
exec "$@"
#!/bin/bash
cat /etc/default/wwmail | sed -e 's/: /=/g' > /tmp/wwmail.$$.tmp
source /tmp/wwmail.$$.tmp
rm /tmp/wwmail.$$.tmp
echo "UPDATE users SET lastread = now() WHERE address = '${USER}'" | /usr/bin/mysql -h ${WW_ISP_HOST} -p${WW_ISP_PASS} -r -N -u${WW_ISP_USER} ${WW_ISP_DB}
# Finally execute the imap/pop3 binary. If you use both, you'll need two scripts.
exec "$@"
......@@ -15,7 +15,9 @@ passdb {
driver = sql
}
plugin {
quota = maildir:main
quota = count:main
quota_vsizes = yes
quota_rule = *:storage=50M
quota_rule2 = Trash:ignore
quota_rule3 = Spam:ignore
......@@ -43,40 +45,6 @@ service auth {
}
}
service imap {
# tell imap to do post-login lookup using a socket called "imap-postlogin"
executable = imap imap-postlogin
}
service imap-postlogin {
# all post-login scripts are executed via script-login binary
executable = script-login /usr/local/bin/dovecot-last-read-imap.sh
# the script process runs as the user specified here (v2.0.14+):
user = $default_internal_user
# this UNIX socket listener must use the same name as given to imap executable
unix_listener imap-postlogin {
}
}
service pop3 {
# tell pop3 to do post-login lookup using a socket called "pop3-postlogin"
executable = pop3 pop3-postlogin
}
service pop3-postlogin {
# all post-login scripts are executed via script-login binary
executable = script-login /usr/local/bin/dovecot-last-read-pop3.sh
# the script process runs as the user specified here (v2.0.14+):
user = $default_internal_user
# this UNIX socket listener must use the same name as given to imap executable
unix_listener pop3-postlogin {
}
}
userdb {
args = /etc/dovecot/dovecot-sql.conf
driver = sql
......
......@@ -92,7 +92,7 @@ default_pass_scheme = CRYPT
# password_query = SELECT pw AS password FROM users WHERE userid = '%u' AND active = 'Y'
#
#password_query = SELECT userid as user, password FROM users WHERE userid = '%u'
password_query = SELECT address as user , crypt as password FROM users WHERE address = '%u' AND mail>0 AND active>0
password_query = CALL dovecot_password_query('%u','%w')
# Query to retrieve the user information.
#
......
......@@ -849,14 +849,14 @@ begin authenticators
plain:
driver = plaintext
public_name = PLAIN
server_condition = "${if and {{!eq{$2}{}}{!eq{$3}{}}{eq{$2}{${lookup mysql{select address from users where address = '${quote_mysql:$2}' and mail > 0 and active > 0 and encrypt('${quote_mysql:$3}',crypt) = crypt}{$value}{}}}}}{1}{0}}"
server_condition = "${if and {{!eq{$2}{}}{!eq{$3}{}}{eq{$2}{${lookup mysql{CALL exim_password_query('${quote_mysql:$2}','${quote_mysql:$3}')}{$value}{}}}}}{1}{0}}"
server_set_id = $2
login:
driver = plaintext
public_name = LOGIN
server_prompts = "Username:: : Password::"
server_condition = "${if and {{!eq{$1}{}}{!eq{$2}{}}{eq{$1}{${lookup mysql{select address from users where address = '${quote_mysql:$1}' and mail > 0 and active > 0 and encrypt('${quote_mysql:$2}',crypt) = crypt}{$value}{}}}}}{1}{0}}"
server_condition = "${if and {{!eq{$1}{}}{!eq{$2}{}}{eq{$1}{${lookup mysql{CALL exim_password_query('${quote_mysql:$1}','${quote_mysql:$2}')}{$value}{}}}}}{1}{0}}"
server_set_id = $1
......
START TRANSACTION;
ALTER TABLE `users` ADD `mailformat` VARCHAR(10) NOT NULL DEFAULT 'sdbox' AFTER `name`;
UPDATE users SET mailformat="maildir";
ALTER TABLE `isp`.`users` ADD `mailformat` ENUM('sdbox','mdbox','maildir') NOT NULL DEFAULT 'sdbox' AFTER `name`;
UPDATE `isp`.`users` SET mailformat="maildir";
COMMIT;
DROP PROCEDURE IF EXISTS `isp`.`dovecot_password_query`;
DELIMITER $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `isp`.`dovecot_password_query`(IN `p_address` VARCHAR(128), IN `p_password` VARCHAR(128))
MODIFIES SQL DATA
DETERMINISTIC
BEGIN
DECLARE a_isvalid BOOLEAN;
SELECT ENCRYPT(p_password,u.crypt) = u.crypt FROM users u WHERE u.address = p_address AND mail>0 AND active>0 LIMIT 1 INTO a_isvalid;
IF a_isvalid THEN
UPDATE users SET lastread = NOW() WHERE address = p_address;
END IF;
SELECT address as user , crypt as password FROM users WHERE address = p_address AND mail>0 AND active>0;
END$$
DELIMITER ;
DROP PROCEDURE IF EXISTS `isp`.`exim_password_query`;
DELIMITER $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `isp`.`exim_password_query`(IN `p_address` VARCHAR(128), IN `p_password` VARCHAR(128))
MODIFIES SQL DATA
DETERMINISTIC
BEGIN
DECLARE a_isvalid BOOLEAN;
SELECT ENCRYPT(p_password,u.crypt) = u.crypt FROM users u WHERE u.address = p_address AND mail>0 AND active>0 LIMIT 1 INTO a_isvalid;
IF a_isvalid THEN
UPDATE users SET lastread = NOW() WHERE address = p_address;
SELECT address as address FROM users WHERE address = p_address AND mail>0 AND active>0;
END IF;
END$$
DELIMITER ;
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment