Servidor de Email no Iomega Ix2-200 Cloud Edition


Primeiramente gostaria de salientar que não sou o autor principal do conteúdo deste artigo. A minha intenção é de mostrar o que outros autores tem realizado (referenciando links para o conteúdo original) neste blog até como um guia pessoal para uso próprio e ainda compartilhar minhas anotações e pequenas modificações que realizo no conteúdo, desejando que possa ajudar mais alguém em algum lugar.
First and foremost, I take no credit for any of this post’s content. I am really just taking what others have done (which I have links to bellow) and am putting it on my blog for a personal reference and hopefully the small changes that I made to their guides will help someone somewhere.

Primeiramente acesse o equipamento com uma sessão SSH.

Ative esta opção no site do seu equipamento na página abaixo:

Utilizando o putty ou terminal do linux: 
ssh root@192.168.1.13

Usuário: root
Senha: soho + a senha do admin

Instale os aplicativos optware com o comando ipkg, configurando do seguinte forma ((já vem pré instalado):
cat <<EOF > /etc/ipkg.conf
src cross http://ipkg.nslu2-linux.org/feeds/optware/cs08q1armel/cross/unstable
src native http://ipkg.nslu2-linux.org/feeds/optware/cs08q1armel/native/unstable
EOF

Atualize com o comando:
ipkg update

Liste as opções com o comando:
ipkg list

Ou acesse os sites:

E instale o que quiser com o comando abaixo:
ipkg install <nome do app>

O pacote que trata do servidor de email imap é o pacote abaixo:
Package: cyrus-imapd 
Version: 2.2.12-15 
Depends: openssl, libdb, cyrus-sasl, e2fsprogs, perl 
Suggests: cyrus-imapd-doc, 
Section: util 
Architecture: arm 
Maintainer: Matthias Appel <private_tweety@gmx.net> 
MD5Sum: 30dd4c1cd354e33433dc4216e757e998 
Size: 6999875 
Filename: cyrus-imapd_2.2.12-15_arm.ipk 
Source: ftp://ftp.andrew.cmu.edu/pub/cyrus-mail/cyrus-imapd-2.2.12.tar.gz 
Description: The Carnegie Mellon University Cyrus IMAP Server


Ou ainda:
Package: dovecot 
Version: 1.2.0.beta1-2 
Depends: openssl 
Conflicts: cyrus-imapd, imap 
Section: net 
Architecture: arm 
Maintainer: Marcel Nijenhof <nslu2@pion.xs4all.nl> 
MD5Sum: 17e268256ae46f25cecac74a973cc37e 
Size: 2905999 
Filename: dovecot_1.2.0.beta1-2_arm.ipk 
Source: http://dovecot.org/releases/1.2/beta/dovecot-1.2.beta1.tar.gz 
Description: Dovecot secure IMAP server

Vamos tentar configurar o dovecot
ipkg install dovecot

Installing dovecot (1.2.0.beta1-2) to root...
Downloading http://ipkg.nslu2-linux.org/feeds/optware/cs08q1armel/cross/unstable/dovecot_1.2.0.beta1-2_arm.ipk
Installing openssl (0.9.8p-1) to root...
Downloading http://ipkg.nslu2-linux.org/feeds/optware/cs08q1armel/cross/unstable/openssl_0.9.8p-1_arm.ipk
Configuring dovecot
chown: invalid group: `admin:administrators'
chown: invalid group: `admin:guest'
Error: Login user doesn't exist: guest
Fatal: Invalid configuration in /opt/etc/dovecot/dovecot.conf
postinst script returned status 89
ERROR: dovecot.postinst returned 89
Configuring openssl
Successfully terminated.

Crie um compartilhamento com o nome Server e execute:
mkdir
/mnt/pools/A/A0/Server/vmail
mkdir /mnt/pools/A/A0/Server/vmail/localhost
chown -R 500:500 /mnt/pools/A/A0/Server/vmail

Testar:
chown -R 500:users /mnt/pools/A/A0/Server/vmail
chmod 770 -R /mnt/pools/A/A0/Server/vmail

Existe uma falha no arquivo de instalação localizado em: /opt/ipkg/info/dovecot.postinst
Para corrigir precisa executar os comandos abaixo.

sed -i -e 's/ user = admin/ user = root/' /opt/etc/dovecot/dovecot.conf
sed -i -e 's/login_user = guest/login_user = nobody/' /opt/etc/dovecot/dovecot.conf
mkdir -p /opt/var/run/dovecot/login
chown root:root /opt/var/run/dovecot
chmod 700 /opt/var/run/dovecot
chown root:users /opt/var/run/dovecot/login
chmod 750 /opt/var/run/dovecot/login
/opt/etc/init.d/S90dovecot start

Ajuste as configurações do arquivo /opt/etc/dovecot/dovecot.conf
/opt/etc/init.d/S90dovecot stop
cp /opt/etc/dovecot/dovecot.conf /opt/etc/dovecot/dovecot.conf.original
tee /opt/etc/dovecot/dovecot.conf <<EOF
## Dovecot configuration file
# If you're in a hurry, see http://wiki.dovecot.org/QuickConfiguration
protocols = imap imaps
disable_plaintext_auth = no
ssl_disable = yes
ssl = no
login_user = nobody
mail_location =maildir:/mnt/pools/A/A0/Server/vmail/localhost/%u/Maildir
protocol imap {
}
protocol pop3 {
}
protocol lda {
  postmaster_address = postmaster@storage
}
auth default {
  mechanisms = plain
  passdb shadow {
  }
  userdb passwd {
    args = blocking=no
  }
  user = root
}
EOF
/opt/etc/init.d/S90dovecot start

Visualização das configurações do Dovecot:
dovecot -n       
# 1.2.beta1: /opt/etc/dovecot/dovecot.conf
# OS: Linux 2.6.31.8 armv5tel Debian 5.0.8 
ssl: no
disable_plaintext_auth: no
login_dir: /opt/var/run/dovecot/login
login_executable: /opt/libexec/dovecot/imap-login
login_user: nobody
mail_location: maildir:/mnt/pools/A/A0/Server/vmail/localhost/%u/Maildir
auth default:
  verbose: yes
  debug: yes
  debug_passwords: yes
  passdb:
    driver: shadow
  userdb:
    driver: passwd
    args: blocking=no

Antes de utilizar o servidor de email com um usuário do sistema voce deve criar uma senha para o mesmo com o comando:
passwd username

Ajuste o arquivo original de instalação do dovecot comentando todo seu conteúdo da seguinte forma:
: << --COMMENTS BLOCK--

all content here

--COMMENTS BLOCK--

E execute novamente:
ipkg install dovecot



To test IMAP connection you may use telnet as follow:

telnet imap.example.com imap
a1 LOGIN MyUsername MyPassword
a2 LIST "" "*"
a3 EXAMINE INBOX
a4 FETCH 1 BODY[]
a5 LOGOUT



Para tornar o dovecot um serviço que se inicia automaticamente quando o NAS for reiniciado, precisa alterar a imagem original da seguinte forma:

mknod -m0660 /dev/loop3 b 7 3
chown root.disk /dev/loop3
mkdir /tmp/apps
mount -o loop /boot/images/apps /tmp/apps
cp /tmp/apps/usr/local/cfg/sohoProcs.xml /tmp/apps/usr/local/cfg/sohoProcs.xml.original
nano /tmp/apps/usr/local/cfg/sohoProcs.xml

Inclua um novo <Program> dentro de <Group Level=”1″>:
<Program Name="init-opt.sh" Path="/opt/etc/init-opt.sh"> 
       <SysOption Restart="-1"/> 
</Program>
 
umount /tmp/apps 
rm /dev/loop3

Crie o script abaixo:

tee /opt/etc/init-opt.sh <<EOF
#!/bin/sh
rm /opt/var/log/boot
if [ -d /opt/etc/init.d ]; then
for f in /opt/etc/init.d/S* ; do
#[ -x $f ] && $f start
$f start | tee -a /opt/var/log/boot
done
fi
EOF
chmod +x /opt/etc/init-opt.sh
mkdir /opt/var/log




Segue abaixo tentativa frustada de configurar o Cyrus...
Infelizmente não funciona.

Instale com o comando abaixo:
ipkg install cyrus-imapd

Installing cyrus-imapd (2.2.12-15) to root...
Downloading http://ipkg.nslu2-linux.org/feeds/optware/cs08q1armel/cross/unstable/cyrus-imapd_2.2.12-15_arm.ipk
package cyrus-imapd suggests installing cyrus-imapd-doc
Installing openssl (0.9.8p-1) to root...
Downloading http://ipkg.nslu2-linux.org/feeds/optware/cs08q1armel/cross/unstable/openssl_0.9.8p-1_arm.ipk
Installing libdb (4.2.52-3) to root...
Downloading http://ipkg.nslu2-linux.org/feeds/optware/cs08q1armel/cross/unstable/libdb_4.2.52-3_arm.ipk
Installing cyrus-sasl (2.1.23-2) to root...
Downloading http://ipkg.nslu2-linux.org/feeds/optware/cs08q1armel/cross/unstable/cyrus-sasl_2.1.23-2_arm.ipk
Installing cyrus-sasl-libs (2.1.23-2) to root...
Downloading http://ipkg.nslu2-linux.org/feeds/optware/cs08q1armel/cross/unstable/cyrus-sasl-libs_2.1.23-2_arm.ipk
Installing psmisc (22.13-1) to root...
Downloading http://ipkg.nslu2-linux.org/feeds/optware/cs08q1armel/cross/unstable/psmisc_22.13-1_arm.ipk
Installing ncurses (5.7-1) to root...
Downloading http://ipkg.nslu2-linux.org/feeds/optware/cs08q1armel/cross/unstable/ncurses_5.7-1_arm.ipk
Installing e2fsprogs (1.41.14-1) to root...
Downloading http://ipkg.nslu2-linux.org/feeds/optware/cs08q1armel/cross/unstable/e2fsprogs_1.41.14-1_arm.ipk
Installing e2fslibs (1.41.14-1) to root...
Downloading http://ipkg.nslu2-linux.org/feeds/optware/cs08q1armel/cross/unstable/e2fslibs_1.41.14-1_arm.ipk
Installing perl (5.10.0-6) to root...
Downloading http://ipkg.nslu2-linux.org/feeds/optware/cs08q1armel/cross/unstable/perl_5.10.0-6_arm.ipk
Installing gdbm (1.8.3-2) to root...
Downloading http://ipkg.nslu2-linux.org/feeds/optware/cs08q1armel/cross/unstable/gdbm_1.8.3-2_arm.ipk
Configuring cyrus-imapd
adding new service(s) ... failed
set saslpasswd2 for user 'mail' ... listusers failed
failed
changing permission ...
/bin/chown: cannot access `/opt/etc/sasl2': No such file or directory
/bin/chmod: cannot access `/opt/etc/sasl2': No such file or directory
/bin/chown: invalid group: `mail:mail'
/bin/chown: invalid group: `mail:mail'
/bin/chown: invalid group: `mail:mail'
/bin/chown: invalid group: `mail:mail'
/bin/chown: invalid group: `mail:mail'
/bin/chown: invalid group: `mail:mail'
/bin/chown: invalid group: `mail:mail'
/bin/chown: invalid group: `mail:mail'

You may want to update your Perl modules first:
        $ cpan
        > install Bundle::CPAN
        > install HTTP::Date

Please read the man-pages and docs carefully,
        $ less /opt/share/docs/cyrus-imapd/README
        $ man cyrus_master
        $ lynx /opt/share/docs/cyrus-imapd/html/index.html

then configure cyrus-imapd,
        $ vi /opt/etc/cyrus.conf
        $ vi /opt/etc/imapd.conf

create users with cyradm
        $ cyradm -u mail localhost

and start the server
        $ /opt/etc/init.d/S59cyrus-imapd

Configuring cyrus-sasl

Please read the man page of saslauthd and
check settings in /opt/etc/init.d/S52saslauthd

If you dislike the link /usr/lib/sasl2 -> /opt/lib/sasl2
then you may want to set SASL_PATH instead

(re)starting service saslauthd
/opt/etc/init.d/S52saslauthd: line 5: /opt/bin/pidof: No such file or directory
Configuring cyrus-sasl-libs
Configuring e2fslibs
Configuring e2fsprogs
//opt/ipkg/info/e2fsprogs.postinst: line 2: /opt/bin/update-alternatives: No such file or directory
//opt/ipkg/info/e2fsprogs.postinst: line 3: /opt/bin/update-alternatives: No such file or directory
//opt/ipkg/info/e2fsprogs.postinst: line 4: /opt/bin/update-alternatives: No such file or directory
postinst script returned status 127
ERROR: e2fsprogs.postinst returned 127
Configuring gdbm
Configuring libdb
Configuring ncurses
//opt/ipkg/info/ncurses.postinst: line 2: /opt/bin/update-alternatives: No such file or directory
postinst script returned status 127
ERROR: ncurses.postinst returned 127
Configuring openssl
Configuring perl
Configuring psmisc
//opt/ipkg/info/psmisc.postinst: line 2: /opt/bin/update-alternatives: No such file or directory
//opt/ipkg/info/psmisc.postinst: line 3: /opt/bin/update-alternatives: No such file or directory
postinst script returned status 127
ERROR: psmisc.postinst returned 127
Successfully terminated.

Comandos para corrigir os problemas apresentados:

Inclua os serviços necessários no arquivo /etc/services
nano /etc/services
# start of cyrus-imapd services
imsp 406/tcp
acap 674/tcp
sieve 2000/tcp
lmtp 2003/tcp
fud 4201/udp
# end of cyrus-imapd services

Verifique se os serviços abaixo estão habilitados e desabilite o pop3 (se quiser):
#pop3 110/tcp pop-3 # POP version 3
#pop3 110/udp pop-3
imap 143/tcp imap2 # Interim Mail Access Proto v2
imap 143/udp imap2
imap3 220/tcp # Interactive Mail Access
imap3 220/udp # Protocol v3

Inclua ":/opt/bin:/opt/sbin" ao path do arquivo /etc/profile
nano /etc/profile
# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
# and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).

if [ "`id -u`" -eq 0 ]; then
  PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/bin:/opt/sbin"
else
  PATH="/usr/local/bin:/usr/bin:/bin:/usr/games:/opt/bin:/opt/sbin"
fi

if [ "$PS1" ]; then
  if [ "$BASH" ]; then
    PS1='\u@\h:\w\$ '
  else
    if [ "`id -u`" -eq 0 ]; then
      PS1='# '
    else
      PS1='$ '
    fi
  fi
fi

export PATH

umask 022
if [ -e ~/.bashrc ];then
        . ~/.bashrc
fi

Crie um link da seguinte forma:
cd /opt/bin
ln -s /usr/bin/update-alternatives

Crie um grupo para o mail :
addgroup --gid 8 mail

Faça /mnt/apps/usr ser passível de escrita para rodar os programas de instalação:
mkdir /mnt/pools/A/A0/tmp
cp -a /mnt/apps/usr/* /mnt/pools/A/A0/tmp/
mount --bind /mnt/pools/A/A0/tmp /mnt/apps/usr

Inclua um link temporário:
cd /mnt/pools/A/A0/tmp/lib
mkdir /opt/lib/ipkg
ln -s /opt/lib/ipkg

Reinstale os programas:
ipkg -force-reinstall install e2fsprogs ncurses psmisc findutils
ipkg -force-reinstall install cyrus-sasl

Crie uma senha com o comando abaixo:
/opt/sbin/saslpasswd2 mail

Configuring cyrus-sasl

Please read the man page of saslauthd and
check settings in /opt/etc/init.d/S52saslauthd

If you dislike the link /usr/lib/sasl2 -> /opt/lib/sasl2
then you may want to set SASL_PATH instead

Desfaça o mapeamento falso:
umount /mnt/apps/usr

Se aparecer Device is Busy voce pode:
umount -l /mnt/apps/usr

Execute (não deu certo mas rodei o comando abaixo):
cpan
install Bundle::CPAN
install HTTP::Date

Reinstale o cyrus:
ipkg -force-reinstall install perl cyrus-imapd postfix termcap

Reinstalling perl (5.10.0-6) on root...
Downloading http://ipkg.nslu2-linux.org/feeds/optware/cs08q1armel/cross/unstable/perl_5.10.0-6_arm.ipk
Reinstalling cyrus-imapd (2.2.12-15) on root...
Downloading http://ipkg.nslu2-linux.org/feeds/optware/cs08q1armel/cross/unstable/cyrus-imapd_2.2.12-15_arm.ipk
package cyrus-imapd suggests installing cyrus-imapd-doc
conffile_has_been_modified: conffile /opt/etc/cyrus.conf has no md5sum
conffile_has_been_modified: conffile /opt/etc/imapd.conf has no md5sum
conffile_has_been_modified: conffile /opt/etc/init.d/S59cyrus-imapd has no md5sum
Reinstalling postfix (2.3.19-1) on root...
Downloading http://ipkg.nslu2-linux.org/feeds/optware/cs08q1armel/cross/unstable/postfix_2.3.19-1_arm.ipk
package postfix suggests installing postfix-doc
conffile_has_been_modified: conffile /opt/etc/aliases has no md5sum
conffile_has_been_modified: conffile /opt/etc/postfix/main.cf has no md5sum
conffile_has_been_modified: conffile /opt/etc/postfix/master.cf has no md5sum
conffile_has_been_modified: conffile /opt/lib/sasl2/smtpd.conf has no md5sum
conffile_has_been_modified: conffile /opt/etc/init.d/S69postfix has no md5sum
Reinstalling termcap (1.3.1-2) on root...
Downloading http://ipkg.nslu2-linux.org/feeds/optware/cs08q1armel/cross/unstable/termcap_1.3.1-2_arm.ipk
Configuring cyrus-imapd
adding new service(s) ... failed
set saslpasswd2 for user 'mail' ...
Password:
Again (for verification):
changing permission ...


You may want to update your Perl modules first:
$ cpan
> install Bundle::CPAN
> install HTTP::Date


Please read the man-pages and docs carefully,
$ less /opt/share/docs/cyrus-imapd/README
$ man cyrus_master
$ lynx /opt/share/docs/cyrus-imapd/html/index.html


then configure cyrus-imapd,
$ vi /opt/etc/cyrus.conf
$ vi /opt/etc/imapd.conf


create users with cyradm
$ cyradm -u mail localhost


and start the server
$ /opt/etc/init.d/S59cyrus-imapd


Configuring perl
Configuring postfix
creating new user(s) and group(s) ...
-> backup /etc/group.postfix-save ceated
-> new group maildrop created
-> maildrop:x:69:
changing permissions of /opt/var/spool/postfix/* ... ok
changing permissions of /opt/sbin/post* ... ok


Please read the man-pages and docs carefully,
$ ipkg install postfix-doc
$ less /opt/share/doc/postfix/readme/BASIC_CONFIGURATION_README


then configure postfix,
$ vi /opt/etc/postfix/main.cf
$ vi /opt/etc/aliasas
$ newaliasas


and start the server
$ /opt/etc/init.d/S69postfix


Configuring termcap
Successfully terminated.



TODO: testar e configurar o servidor de email

Veja com o comando abaixo se o diretório "/opt/lib/perl5/5.10.0"  consta na variável @INC:
perl -e "print join(\"\n\", @INC);"

export PERL5LIB=/opt/lib/perl5/5.10.0:/opt/lib/perl5/site_perl/5.10.0/arm-linux
perl -V

A variável INC tem que conter o diretório abaixo:
@INC /opt/lib/perl5/5.10.0

Crie MailBox para cada usuário do sistema:
cyradm --user mail localhost
> cm user.aarvati
> cm "user.aarvati.Buy &- Sell"
> cm user.aarvati.Drafts
> cm user.aarvati.Outbox
> cm user.aarvati.Sent
> cm user.aarvati.Trash
> cm user.aaravti.Ham
> cm user.aarvati.Spam
> lm
> quit

if at some later point you have DBERRORs? in your log, you can try to fix it like this:
 create your mailboxes anew with cyradm and cm user.xxx and use reconstruct
# su -s /bin/bash -l mail
# /opt/libexec/cyrus/bin/reconstruct

Comments