Disable imap/pop3 for a particular user
Posted by adminApr 29
Edit /etc/dovecot.conf, find:
mechanisms = plain
Add after:
passdb passwd-file {
args = /etc/dovecot-deny.%Ls
deny = yes
}
Now use the following script to disable IMAP (or POP3 (replace IMAP with POP3 in the script)) access (usage: ./script allow/deny usename):
#!/bin/sh
#
# Script used to deny IMAP access for a particular usershow_help()
{
echo “IMAP allow/deny script.”;
echo “”;
echo “Usage: $0 allow/deny username”;
echo “”;
}if [ $# -eq 2 ]; then
echo “Using $2.”
else
show_help;
exit 1;
fiIMAPDENY=/etc/dovecot-deny.imap
OS=`uname`;
if [ $1 = "allow" ]; then
OPTION=allow
else
OPTION=deny
fiUSER=$2
if [ ${OPTION} = "allow" ]; then
if [ "`grep -c \"${USER}\" ${IMAPDENY}`" = "0" ]; then
echo “User ${USER} is already allowed.”;
exit 1;
fi
fiif [ ${OPTION} = "deny" ]; then
if [ "`grep -c \"${USER}\" ${IMAPDENY}`" = "1" ]; then
echo “User ${USER} is already denied.”;
exit 1;
fi
fiif [ ! -d /home/${USER} ]; then
echo “User ${USER} does not exist.”
exit 1;
fiif [ ${OPTION} = "allow" ]; then
perl -pi -e “s/${USER}\n//g” ${IMAPDENY}
fiif [ ${OPTION} = "deny" ]; then
echo “$USER” >> ${IMAPDENY}
fi
exit 0;
One comment
You must be logged in to post a comment.