DSPラジオ ATS-Miniのfirmwareをアップデートしてみた

aliexpressで安く売ってたATS-Miniの派生品買ってみた

ループアンテナセットで3222円でした。

電源入れた時のfirmware versionは1.0.1と出ていた

バージョンアップできるのか探してみると https://github.com/esp32-si4732/ats-mini を発見

(あとからわかったのだが、最初にインストールされてたのは 同じgithubでも大文字の https://github.com/G8PTN/ATS_MINI/ で、こちらはソースコード非公開だった)

ドキュメントにあるように uv をインストールしてみた

osakanataro@ubuntuserver:~$ curl -LsSf https://astral.sh/uv/install.sh | sh
downloading uv 0.7.2 x86_64-unknown-linux-gnu
no checksums to verify
installing to /home/osakanataro/.local/bin
  uv
  uvx
everything's installed!
osakanataro@ubuntuserver:~$

ATS-MiniをLinuxサーバに接続してみるとデバイスが認識される

osakanataro@ubuntuserver:~$ lsusb
<略>
Bus 002 Device 006: ID 303a:1001 Espressif USB JTAG/serial debug unit
<略>
osakanataro@ubuntuserver:~$ lsusb --tree
<略>
/:  Bus 002.Port 001: Dev 001, Class=root_hub, Driver=xhci_hcd/11p, 480M
<略>
    |__ Port 007: Dev 006, If 0, Class=Communications, Driver=cdc_acm, 12M
    |__ Port 007: Dev 006, If 1, Class=CDC Data, Driver=cdc_acm, 12M
    |__ Port 007: Dev 006, If 2, Class=Vendor Specific Class, Driver=[none], 12M
<略>
osakanataro@ubuntuserver:~$

シリアルポート名が何になっているのかをdmesgの結果から確認

osakanataro@ubuntuserver:~$ sudo dmesg|tail
[sudo] osakanataro のパスワード:
[1695575.346617] usbcore: registered new interface driver cdc_acm
[1695575.346621] cdc_acm: USB Abstract Control Model driver for USB modems and ISDN adapters
[1695776.000954] usb 2-7: USB disconnect, device number 5
[1695849.379292] usb 2-7: new full-speed USB device number 6 using xhci_hcd
[1695849.506664] usb 2-7: New USB device found, idVendor=303a, idProduct=1001, bcdDevice= 1.01
[1695849.506681] usb 2-7: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[1695849.506688] usb 2-7: Product: USB JTAG/serial debug unit
[1695849.506693] usb 2-7: Manufacturer: Espressif
[1695849.506697] usb 2-7: SerialNumber: FC:01:2C:CC:BD:08
[1695849.510971] cdc_acm 2-7:1.0: ttyACM0: USB ACM device
osakanataro@ubuntuserver:~$
osakanataro@ubuntuserver:~$ uvx --from esptool esptool.py --chip esp32s3 --port ttyACM0 --baud 921600 read_flash 0x0 ALL original-flash.bin
      Built esptool==4.8.1
Installed 13 packages in 30ms
esptool.py v4.8.1
Serial port SERIAL_PORT

A fatal error occurred: Could not open ttyACM0, the port is busy or doesn't exist.
([Errno 2] could not open port ttyACM0: [Errno 2] No such file or directory: 'ttyACM0')

Hint: Check if the port is correct and ESP connected

osakanataro@ubuntuserver:~$

あ・・・パス指定

osakanataro@ubuntuserver:~$ uvx --from esptool esptool.py --chip esp32s3 --port /dev/ttyACM0 --baud 921600 read_flash 0x0 ALL original-flash.bin
esptool.py v4.8.1
Serial port /dev/ttyACM0

A fatal error occurred: Could not open /dev/ttyACM0, the port is busy or doesn't exist.
([Errno 13] could not open port /dev/ttyACM0: [Errno 13] Permission denied: '/dev/ttyACM0')

Hint: Try to add user into dialout or uucp group.

osakanataro@ubuntuserver:~$

uv,uvxはユーザディレクトリにインストールされているのでsudoで使えない・・・

osakanataro@ubuntuserver:~$ sudo uvx --from esptool esptool.py --chip esp32s3 --port /dev/ttyACM0 --baud 921600 read_flash 0x0 ALL original-flash.bin
sudo: uvx: コマンドが見つかりません
osakanataro@ubuntuserver:~$

uucpグループとdialoutグループのどちらにも所属させたけどpermission denied

osakanataro@ubuntuserver:~$ sudo usermod -G uucp,dialout osakanataro
[sudo] osakanataro のパスワード:
osakanataro@ubuntuserver:~$ uvx --from esptool esptool.py --chip esp32s3 --port /dev/ttyACM0 --baud 921600 read_flash 0x0 ALL original-flash.bin
esptool.py v4.8.1
Serial port /dev/ttyACM0

A fatal error occurred: Could not open /dev/ttyACM0, the port is busy or doesn't exist.
([Errno 13] could not open port /dev/ttyACM0: [Errno 13] Permission denied: '/dev/ttyACM0')

Hint: Try to add user into dialout or uucp group.

osakanataro@ubuntuserver:~$ ls -l /dev/ttyACM0
crw-rw---- 1 root dialout 166, 0  5月  6 15:54 /dev/ttyACM0
osakanataro@ubuntuserver:~$

んー???

ぐぐると brltty がインストールされている場合に発生することがあるらしいのでアンインストールして再実行

osakanataro@ubuntuserver:~$ dpkg -l|grep tty
ii  brltty                                         6.6-4ubuntu5                             amd64        Access software for a blind person using a braille display
ii  libjetty9-java                                 9.4.53-1                                 all          Java servlet engine and webserver -- core libraries
osakanataro@ubuntuserver:~$
osakanataro@ubuntuserver:~$ dpkg -l|grep brltty
ii  brltty                                         6.6-4ubuntu5                             amd64        Access software for a blind person using a braille display
osakanataro@ubuntuserver:~$ sudo apt remove brltty
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています... 完了
状態情報を読み取っています... 完了
以下のパッケージが自動でインストールされましたが、もう必要とされていません:
  libpcre2-32-0
これを削除するには 'sudo apt autoremove' を利用してください。
以下のパッケージは「削除」されます:
  brltty
アップグレード: 0 個、新規インストール: 0 個、削除: 1 個、保留: 7 個。
この操作後に 10.5 MB のディスク容量が解放されます。
続行しますか? [Y/n] y
(データベースを読み込んでいます ... 現在 278045 個のファイルとディレクトリがインストールされています。)
brltty (6.6-4ubuntu5) を削除しています ...
man-db (2.12.0-4build2) のトリガを処理しています ...
エラー: タイムアウトしました
osakanataro@ubuntuserver:~$ uvx --from esptool esptool.py --chip esp32s3 --port /dev/ttyACM0 --baud 921600 read_flash 0x0 ALL original-flash.bin
esptool.py v4.8.1
Serial port /dev/ttyACM0

A fatal error occurred: Could not open /dev/ttyACM0, the port is busy or doesn't exist.
([Errno 13] could not open port /dev/ttyACM0: [Errno 13] Permission denied: '/dev/ttyACM0')

Hint: Try to add user into dialout or uucp group.

osakanataro@ubuntuserver:~$

違うらしい

再起動したあと再実行すると、あっけなく実行が出来た

osakanataro@ubuntuserver:~$ uvx --from esptool esptool.py --chip esp32s3 --port /dev/ttyACM0 --baud 921600 read_flash 0x0 ALL original-flash.bin
esptool.py v4.8.1
Serial port /dev/ttyACM0
Connecting...
Chip is ESP32-S3 (QFN56) (revision v0.2)
Features: WiFi, BLE, Embedded PSRAM 8MB (AP_3v3)
Crystal is 40MHz
MAC: fc:01:2c:cc:bd:08
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 921600
Changed.
Configuring flash size...
Detected flash size: 16MB
16777216 (100 %)
16777216 (100 %)
Read 16777216 bytes at 0x00000000 in 273.8 seconds (490.2 kbit/s)...
Hard resetting via RTS pin...
osakanataro@ubuntuserver:~$ ls -l original-flash.bin
-rw-rw-r-- 1 osakanataro osakanataro 16777216  5月  6 17:26 original-flash.bin
osakanataro@ubuntuserver:~$

では、続いて、firmwareを書き込み

osakanataro@ubuntuserver:~/ats-mini$ ls ats-mini-v2.14
CHANGELOG.md  ats-mini.ino.bin  ats-mini.ino.bootloader.bin  ats-mini.ino.merged.bin  ats-mini.ino.partitions.bin
osakanataro@ubuntuserver:~/ats-mini$ ls -l ats-mini-v2.14
合計 8712
-rw-r--r-- 1 osakanataro osakanataro   11491  5月  6 12:46 CHANGELOG.md
-rw-r--r-- 1 osakanataro osakanataro  494048  5月  6 12:46 ats-mini.ino.bin
-rw-r--r-- 1 osakanataro osakanataro   20208  5月  6 12:46 ats-mini.ino.bootloader.bin
-rw-r--r-- 1 osakanataro osakanataro 8388608  5月  6 12:46 ats-mini.ino.merged.bin
-rw-r--r-- 1 osakanataro osakanataro    3072  5月  6 12:46 ats-mini.ino.partitions.bin
osakanataro@ubuntuserver:~/ats-mini$ uvx --from esptool esptool.py --chip esp32s3 --port /dev/ttyACM0 --baud 921600 --before default_reset --after hard_reset write_flash  -z --flash_mode keep --flash_freq keep --flash_size keep 0x0 ats-mini-v2.14/ats-mini.ino.merged.bin
esptool.py v4.8.1
Serial port /dev/ttyACM0
Connecting...
Chip is ESP32-S3 (QFN56) (revision v0.2)
Features: WiFi, BLE, Embedded PSRAM 8MB (AP_3v3)
Crystal is 40MHz
MAC: fc:01:2c:cc:bd:08
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 921600
Changed.
Configuring flash size...
Flash will be erased from 0x00000000 to 0x007fffff...
Compressed 8388608 bytes to 299786...
Wrote 8388608 bytes (299786 compressed) at 0x00000000 in 20.2 seconds (effective 3315.7 kbit/s)...

A fatal error occurred: Packet content transfer stopped (received 0 bytes)
osakanataro@ubuntuserver:~/ats-mini$

えっ・・・・失敗?

もう1つある分割ファイルの方で再実行

osakanataro@ubuntuserver:~/ats-mini$ uvx --from esptool esptool.py --chip esp32s3 --port /dev/ttyACM0 --baud 921600 --before default_reset --after hard_reset write_flash  -z --flash_mode keep --flash_freq keep --flash_size keep 0x0 ats-mini-v2.14/ats-mini.ino.bootloader.bin 0x8000 ats-mini-v2.14/ats-mini.ino.partitions.bin 0x10000 ats-mini-v2.14/ats-mini.ino.bin
esptool.py v4.8.1
Serial port /dev/ttyACM0
Connecting...
Chip is ESP32-S3 (QFN56) (revision v0.2)
Features: WiFi, BLE, Embedded PSRAM 8MB (AP_3v3)
Crystal is 40MHz
MAC: fc:01:2c:cc:bd:08
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 921600
Changed.
Configuring flash size...
Flash will be erased from 0x00000000 to 0x00004fff...
Flash will be erased from 0x00008000 to 0x00008fff...
Flash will be erased from 0x00010000 to 0x00088fff...
Compressed 20208 bytes to 13058...
Wrote 20208 bytes (13058 compressed) at 0x00000000 in 0.2 seconds (effective 918.1 kbit/s)...
Hash of data verified.
Compressed 3072 bytes to 146...
Wrote 3072 bytes (146 compressed) at 0x00008000 in 0.0 seconds (effective 1196.3 kbit/s)...
Hash of data verified.
Compressed 494048 bytes to 277050...
Wrote 494048 bytes (277050 compressed) at 0x00010000 in 2.5 seconds (effective 1560.3 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...
osakanataro@ubuntuserver:~/ats-mini$

無事に書き込み完了

FW2.14で起動したことを確認

dovecot / postfix と Active Directory連携時の動作調査手法

dovecot / postfix と Active Directoryを連携させようと設定してみたところ、最初はうまく動かなかった。

この動かない原因をどうやって調べていくか、というのを解説してるものがなく、非常に難儀したのでメモ書きとして残す

dovecot, postfixの現在の設定を確認

RHEL9の場合、 /etc/dovecot および /etc/postfix に設定ファイル群があるが、コメントやサブディレクトリにあるファイルとの結合により、最終的な設定が何になっているのかわかりにくい

「doveconf」および「postconf」を実行することで最終的な設定を確認することができる

また、デフォルト値と異なる部分は何かを「doveconf -n」「postconf -n」を実行することで確認できる。

なお、doveconfの場合、ssh_keyなど一部のパラメータについては「doveconf -P」と-Pオプションをつけないと実際の値が表示されない

dovecotのログ出力を増やす

ログ出力を増やすための設定がいろいろあった(Dovecot Logging)ため、 /etc/dovecot/conf.d/99-debug.conf と1つのファイルにまとめて必要ない場合は /etc/dovecot/conf.d/99-debug._conf と.conf という名前じゃなくすることで無効化できるようにした

[root@mail dovecot]# cat /etc/dovecot/conf.d/99-debug.conf
auth_debug=yes
auth_debug_passwords=yes
auth_verbose=yes
auth_verbose_passwords=yes
verbose_proctitle=yes
verbose_ssl=yes

[root@mail dovecot]#

設定後は「systemctl restart dovecot」で設定を有効にする

なお「doveadm log find」を実行するとdovecotのログがどのファイルに出力されているかを確認することができる

[root@mail dovecot]# doveadm log find
Looking for log files from /var/log
Debug: /var/log/maillog
Info: /var/log/maillog
Warning: /var/log/maillog
Error: /var/log/maillog
Fatal: /var/log/maillog
[root@mail dovecot]#

LDAP検索のログを増やす

dovecotの場合は dovecot本体への auth_verbose=yes 設定だけでLDAPでどういったqueryを投げているかも確認できる

ただ、もっと詳細を確認したい、という場合 /etc/dovecot/dovecot-ldap.conf.ext などのLDAP接続情報を書いたファイルに「debug_level」を追加することでログを増やすこともできる。

dovecot Common LDAP Settings for both auth and sieve
iredmail Turn on debug mode in Dovecot

dovecot標準値は「debug_level=0」。ログを増やす場合は「debug_level=1」、最大量に増やす場合は「debug_level=-1」とする

postfixの場合も同様に LDAP接続情報を書いたファイル /etc/postfix/ldap-mailbox.cf などに「debuglevel」を追加することでログを増やすことができる。

postfix ldap_table – Postfix LDAP client configuration

postfix標準値は「debuglevel=0」。増やす場合は「debuglevel=1」から最大量は「debuglevel=10」とする

postfixのログ出力を増やす

Postfix Debugging Howto に記載があるが正直めんどい

/etc/postfix/master.cf の smtpd起動に関して「-v」オプションか「-D」オプションをつける、という形となる。

とはいえ、postfix/dovecotを組み合わせた場合、ActiveDirectory/LDAP側の処理をdovecot側で行うということもあるので、まずはdovecot側の動作がちゃんとするのを先に確認したほうがよい。

dovecotでの認証確認

dovecotで認証動作を確認する場合、まずは「doveadm auth login ユーザ名」を実行する

[root@mail ~]# doveadm auth login testuser1@adsample.local
Password: <パスワード入力>
passdb: testuser1@adsample.local auth succeeded
extra fields:
  user=testuser1@adsample.local
  uid=1000
  gid=1000
userdb extra fields:
  testuser1@adsample.local
  uid=1000
  gid=1000
  auth_mech=PLAIN
[root@mail ~]#

なお、「doveadm auth login testuser1@adsample.local パスワード」とパスワードをつけて実行すると入力しないで済むので検証時は便利(ログに残るので一時なパスワードにすること)

ただし、このdoveadm auth loginコマンドは模擬的に確認しているだけで、実際にログイン処理は行っていないようで、テストしたユーザのディレクトリがない場合でもディレクトリが作成されない。(ちゃんとログインした場合は自動的に作成される)

ldapsearchコマンドを使った検証

doveadm auth loginコマンドでうまく認証が実行できない場合、 ldapsearchコマンドを使って原因を調査していったりする。

その場合、 /etc/dovecot/conf.d/99-debug.conf の設定を有効にしてから行う。

期待通りに動作していない場合、ログにある下記のような「ldap」「base=~」「filter=~」という記述に注目する

May  2 11:18:59 mail dovecot[959]: auth-worker(1542): Debug: conn unix:auth-worker (pid=1541,uid=97): Server accepted connection (fd=14)
May  2 11:18:59 mail dovecot[959]: auth-worker(1542): Debug: conn unix:auth-worker (pid=1541,uid=97): Sending version handshake
May  2 11:18:59 mail dovecot[959]: auth-worker(1542): Debug: conn unix:auth-worker (pid=1541,uid=97): auth-worker<1>: Handling LIST request
May  2 11:18:59 mail dovecot[959]: auth-worker(1542): Debug: conn unix:auth-worker (pid=1541,uid=97): auth-worker<1>: ldap(): Performing userdb lookup
May  2 11:18:59 mail dovecot[959]: auth-worker(1542): Debug: conn unix:auth-worker (pid=1541,uid=97): auth-worker<1>: ldap: iterate: base=cn=Users,dc=adsample,dc=local scope=subtree filter=(objectClass=posixAccount) fields=uid
May  2 11:18:59 mail dovecot[959]: auth-worker(1542): Debug: conn unix:auth-worker (pid=1541,uid=97): auth-worker<1>: ldap(): Finished userdb lookup
May  2 11:18:59 mail dovecot[959]: auth-worker(1542): Debug: conn unix:auth-worker (pid=1541,uid=97): auth-worker<1>: Finished

上記の場合注目するのは以下の部分

base=cn=Users,dc=adsample,dc=local scope=subtree filter=(objectClass=posixAccount) fields=uid

これをldapsearchコマンドに与える

-bオプションの後ろにbase=の後ろにある「cn=Users,dc=adsample,dc=local」
-sオプションの後ろにscope=の「subtree」
そしてfilterの「objectClass=posixAccount」

ldapsearch -x -H ldaps://192.168.122.10 -D "cn=vmail,cn=Users,dc=adsample,dc=local" -w "パスワード" -b "dc=adsample,dc=local" -s subtree objectClass=posixAccount

この出力結果を確認し、fields=で指定した「uid」という項目があるかを確認します

なければfilterで指定した条件が不適切、ということとなる

fieldsで適切かなぁ、というものが出るまでfilterの条件式の調整と、fieldsで選ぶ項目の調整を行う

doveadmでメールボックスの状態確認

dovecotで認識しているメールボックスの状態を確認する「doveadm mailbox status」コマンド

全ユーザについてとりあえず全ステータスをとる場合はfieldをallにすればいい、というので「doveadm mailbox status -A all ‘*’」を実行してみる

[root@mail ~]# doveadm mailbox status -A all '*'
testuser1@adsample.local Trash messages=0 recent=0 uidnext=2 uidvalidity=1745978754 unseen=0 highestmodseq=5 vsize=0 guid=40b0b82833051c68570600003a0de1d0 firstsaved=never
testuser1@adsample.local INBOX messages=16 recent=0 uidnext=18 uidvalidity=1745978753 unseen=0 highestmodseq=22 vsize=613873 guid=3fa5f40281851168ee0500003a0de1d0 firstsaved=1746666817
testuser2@adsample.local Drafts messages=4 recent=0 uidnext=5 uidvalidity=1745978410 unseen=0 highestmodseq=9 vsize=2313 guid=fe4beb08b4d91268980500003a0de1d0 firstsaved=1746066862
testuser2@adsample.local Sent messages=28 recent=0 uidnext=35 uidvalidity=1745978409 unseen=0 highestmodseq=37 vsize=10545 guid=a28a5e0b7c201268cb0600003a0de1d0 firstsaved=1746018428
testuser2@adsample.local Trash messages=0 recent=0 uidnext=12 uidvalidity=1745978408 unseen=0 highestmodseq=11 vsize=0 guid=ab2c081a361e1268260600003a0de1d0 firstsaved=never
testuser2@adsample.local INBOX messages=9 recent=0 uidnext=15 uidvalidity=1745978407 unseen=0 highestmodseq=33 vsize=10810 guid=7e51333727841168d30500003a0de1d0 firstsaved=1746084330
testuser3@adsample.local INBOX messages=2 recent=2 uidnext=3 uidvalidity=1746166331 unseen=2 highestmodseq=3 vsize=1330 guid=7d83dc163b621468950800003a0de1d0 firstsaved=1746166331
[root@mail ~]#

ん?? vsizeは表示されていない?…マニュアルを再度確認すると -tオプションで messages, recent, unseen, vsizeだけを表示できるとのこと

[root@mail ~]# doveadm mailbox status -A all '*' -t
testuser1@adsample.local messages=16 recent=0 unseen=0 vsize=613873
testuser2@adsample.local messages=41 recent=0 unseen=0 vsize=23668
testuser3@adsample.local messages=2 recent=2 unseen=2 vsize=1330
testuser4@adsample.local messages=0 recent=0 unseen=0 vsize=0
vmail@adsample.local messages=0 recent=0 unseen=0 vsize=0
[root@mail ~]#

messages: メール総数
recent: Recentフラグがついてるメール数(新着メール=まだメールソフトに取り込んでない)
unseen: 未読メール数
vsize: メールの総容量(バイト)

acvite directory連携のdovecotでdoveadm quota get -Aが動かない

dovecot 2.2.19以降で登場した各ユーザのメールフォルダ内にあるindexファイルを使ったquotaを設定しようとした際に発見した出来事です。

doveadm quota get -Aの動作

doveadm quotaのマニュアルを見ると「doveadm quota get -A」を実行すると全ユーザの結果が表示されそうな気がするので実行してみたがされない

[root@mail dovecot]# doveadm quota get -A
Username Quota name Type Value Limit                                                   %
[root@mail dovecot]#

dovecotにdebug系ログ出力を有効にした状態での /var/log/maillog には下記のログ

May  2 11:18:59 mail dovecot[959]: auth: Debug: Loading modules from directory: /usr/lib64/dovecot/auth
May  2 11:18:59 mail dovecot[959]: auth: Debug: Module loaded: /usr/lib64/dovecot/auth/lib20_auth_var_expand_crypt.so
May  2 11:18:59 mail dovecot[959]: auth: Debug: Module loaded: /usr/lib64/dovecot/auth/libdriver_sqlite.so
May  2 11:18:59 mail dovecot[959]: auth: Debug: Loading modules from directory: /usr/lib64/dovecot/auth
May  2 11:18:59 mail dovecot[959]: auth: Debug: Module loaded: /usr/lib64/dovecot/auth/libauthdb_ldap.so
May  2 11:18:59 mail dovecot[959]: auth: Debug: Read auth token secret from /run/dovecot/auth-token-secret.dat
May  2 11:18:59 mail dovecot[959]: auth: Debug: ldap(/etc/dovecot/dovecot-ldap.conf.ext): LDAP initialization took 22 msecs
May  2 11:18:59 mail dovecot[959]: auth: Debug: master in: LIST#0111
May  2 11:18:59 mail dovecot[959]: auth-worker(1542): Debug: Loading modules from directory: /usr/lib64/dovecot/auth
May  2 11:18:59 mail dovecot[959]: auth-worker(1542): Debug: Module loaded: /usr/lib64/dovecot/auth/lib20_auth_var_expand_crypt.so
May  2 11:18:59 mail dovecot[959]: auth-worker(1542): Debug: Module loaded: /usr/lib64/dovecot/auth/libdriver_sqlite.so
May  2 11:18:59 mail dovecot[959]: auth-worker(1542): Debug: Loading modules from directory: /usr/lib64/dovecot/auth
May  2 11:18:59 mail dovecot[959]: auth-worker(1542): Debug: Module loaded: /usr/lib64/dovecot/auth/libauthdb_ldap.so
May  2 11:18:59 mail dovecot[959]: auth-worker(1542): Debug: ldap(/etc/dovecot/dovecot-ldap.conf.ext): LDAP initialization took 14 msecs
May  2 11:18:59 mail dovecot[959]: auth-worker(1542): Debug: conn unix:auth-worker (pid=1541,uid=97): Server accepted connection (fd=14)
May  2 11:18:59 mail dovecot[959]: auth-worker(1542): Debug: conn unix:auth-worker (pid=1541,uid=97): Sending version handshake
May  2 11:18:59 mail dovecot[959]: auth-worker(1542): Debug: conn unix:auth-worker (pid=1541,uid=97): auth-worker<1>: Handling LIST request
May  2 11:18:59 mail dovecot[959]: auth-worker(1542): Debug: conn unix:auth-worker (pid=1541,uid=97): auth-worker<1>: ldap(): Performing userdb lookup
May  2 11:18:59 mail dovecot[959]: auth-worker(1542): Debug: conn unix:auth-worker (pid=1541,uid=97): auth-worker<1>: ldap: iterate: base=cn=Users,dc=adsample,dc=local scope=subtree filter=(objectClass=posixAccount) fields=uid
May  2 11:18:59 mail dovecot[959]: auth-worker(1542): Debug: conn unix:auth-worker (pid=1541,uid=97): auth-worker<1>: ldap(): Finished userdb lookup
May  2 11:18:59 mail dovecot[959]: auth-worker(1542): Debug: conn unix:auth-worker (pid=1541,uid=97): auth-worker<1>: Finished

「objectClass=posixAccount」でフィルターをかけているが、Active DirectoryベースのLDAPサーバ標準では posixAccountは存在していないため、フィルター文字列を変える必要がある、という話である

確認のためldapsearchコマンドで出力がないことを確認

[root@mail dovecot]# ldapsearch -x -H ldaps://192.168.122.10 -D "cn=vmail,cn=Users,dc=adsample,dc=local" -w "パスワード" -b "dc=adsample,dc=local" -s subtree objectClass=posixAccount
# extended LDIF
#
# LDAPv3
# base <dc=adsample,dc=local> with scope subtree
# filter: objectClass=posixAccount
# requesting: ALL
#

# search reference
ref: ldaps://ForestDnsZones.adsample.local/DC=ForestDnsZones,DC=adsample,DC=lo
 cal

# search reference
ref: ldaps://DomainDnsZones.adsample.local/DC=DomainDnsZones,DC=adsample,DC=lo
 cal

# search reference
ref: ldaps://adsample.local/CN=Configuration,DC=adsample,DC=local

# search result
search: 2
result: 0 Success

# numResponses: 4
# numReferences: 3
[root@mail dovecot]#

どこの設定を変えればいいのか調べていくと userdb_ldap_iterate_fieldsuserdb_ldap_iterate_filter で行っているので /etc/dovecot/dovecot-ldap.conf.ext に iterate_filter と iterate_attrs の設定を行う、ということがわかる

うまいことユーザ一覧っぽいのを取得するにはどうすればいいかな、とldapsearchコマンドをこねくり回して「ldapsearch -x -H ldaps://192.168.122.10 -D “cn=vmail,cn=Users,dc=adsample,dc=local” -w “パスワード” -b “dc=adsample,dc=local” -s subtree objectClass=user userPrincipalName」とすればいいかな、というのがわかった。

この結果をもとに、/etc/dovecot/dovecot-ldap.conf.ext に以下を追加してみたところおおむね期待通りの動作となった

iterate_filter=objectClass=user
iterate_attrs=userPrincipalName=user

これは、”objectClass=user”に該当するオブジェクトを表示させたあと、 userPrincipalName の値を dovecot上の user として認識させる、という意味合いの設定となる。

doveadm quota get -Aの実行結果

[root@mail dovecot]# doveadm quota get -A
Username                 Quota name Type    Value Limit                                          %
testuser1@adsample.local User quota STORAGE     9 10240                                          0
testuser1@adsample.local User quota MESSAGE    13     -                                          0
testuser2@adsample.local User quota STORAGE    14 10240                                          0
testuser2@adsample.local User quota MESSAGE    31     -                                          0
testuser3@adsample.local User quota STORAGE     0 10240                                          0
testuser3@adsample.local User quota MESSAGE     0     -                                          0
testuser4@adsample.local User quota STORAGE     0 10240                                          0
testuser4@adsample.local User quota MESSAGE     0     -                                          0
vmail@adsample.local     User quota STORAGE     0 10240                                          0
vmail@adsample.local     User quota MESSAGE     0     -                                          0
[root@mail dovecot]#

/etc/dovecot/conf.d/90-quota.conf を編集し、容量制限を1MBに変更

<略>
plugin {
  # 10MB quota limit
  quota = count:User quota
  quota_rule = *:storage=1M

  # This is required - it uses "virtual sizes" rather than "physical sizes"
  # for quota counting:
  quota_vsizes = yes
}

この状態でメールを送って容量を増やして確認・・・

[root@mail dovecot]# doveadm quota get -A
Username                 Quota name Type    Value Limit                                          %
testuser1@adsample.local User quota STORAGE   895  1024                                         87
testuser1@adsample.local User quota MESSAGE    16     -                                          0
testuser2@adsample.local User quota STORAGE   907  1024                                         88
testuser2@adsample.local User quota MESSAGE    38     -                                          0
testuser3@adsample.local User quota STORAGE     0  1024                                          0
testuser3@adsample.local User quota MESSAGE     0     -                                          0
testuser4@adsample.local User quota STORAGE     0  1024                                          0
testuser4@adsample.local User quota MESSAGE     0     -                                          0
vmail@adsample.local     User quota STORAGE     0  1024                                          0
vmail@adsample.local     User quota MESSAGE     0     -                                          0
[root@mail dovecot]#

postfixとactive directoryを連携させるときのLDA向け設定を検証した

postfix/dovecotを使ったメールサーバを作成する際、そのサーバ上でユーザ向けメールサービスを提供する場合にLDA設定を行う必要がある。

調べると dovecot-lda を使って保存するのがよさそうではある

参考資料
 dovecot側 「Dovecot LDA」「Dovecot LDA Examples」「Dovecot LDA with Postfix

ただ、これをActive Directory/LDAPと連携させる場合の記述についてがいまいちはっきりしない。

ベースとするのは「Dovecot LDA with Postfix」の「Virtual users」にある記述で、/etc/postfix/master.cf に dovecotの記述を追加して、 /etc/postfix/main.cf に dovecot_destination_recipient_limit , virtual_mailbox_domains , virtual_transport の設定を追加する、と読める。

ただ、これだけだとメールを格納する場所について書いてないなぁ、と思いつつ試してみた

その結果、 virtual_transport=dovecot を設定した場合は、 postfix側で “virtual_mailbox_maps= ldap:/etc/postfix/ldap-mailbox.cf”とか”virtual_mailbox_base= /var/vmail”とかの設定を入れて /etc/postfix/ldap-mailbox.cf でLDAPに関する設定を書いたりする必要なく、dovecot側で行ったLDAP連携設定をもとにdovecot側で処理してくれる、ということが分かった

で・・・これの確認をするための副産物として、 virtual_transport=dovecotとしているのに virtual_mailbox_maps= ldap:/etc/postfix/ldap-mailbox.cf とかpostfix側でLDAPを直接見に行くような設定をしてしまうとどうなるの?というのを確認していた(意図せずに・・・

gihyoにあるそろそろLDAPにしてみないか?第15回「FDS+Postfixでメールサーバ管理」と「デージーネットのOSS postLDAPadmin Appendix」を参照しつついろいろ検討

まず、今回、/etc/postfix/master.cf の最下行にdovecotに関する2行を追加した

[root@mail postfix]# tail /etc/postfix/master.cf
#
#scalemail-backend unix -       n       n       -       2       pipe
#  flags=R user=scalemail argv=/usr/lib/scalemail/bin/scalemail-store
#  ${nexthop} ${user} ${extension}
#
#mailman   unix  -       n       n       -       -       pipe
#  flags=FRX user=list argv=/usr/lib/mailman/bin/postfix-to-mailman.py
#  ${nexthop} ${user}
dovecot   unix  -       n       n       -       -       pipe
  flags=DRhu user=vmail:vmail argv=/usr/libexec/dovecot/dovecot-lda -f ${sender} -d ${recipient}
[root@mail postfix]#

そして、/etc/postfix/main.cf には以下を追加した

[root@mail postfix]# tail -10 /etc/postfix/main.cf
#
#
virtual_mailbox_domains = adsample.local
virtual_mailbox_maps= ldap:/etc/postfix/ldap-mailbox.cf
virtual_mailbox_base= /var/vmail
virtual_uid_maps= static:1000
virtual_gid_maps= static:1000
virtual_transport= dovecot
dovecot_destination_recipient_limit = 1

[root@mail postfix]#

で、postfix側のLDAP連携設定は以下とした

[root@mail postfix]# cat /etc/postfix/ldap-mailbox.cf
#server_host=192.168.122.10
server_host=ldaps://192.168.122.10
#server_port=636
#search_base=dc=adsample,dc=local
search_base=cn=Users,dc=adsample,dc=local
scope=sub
#query_filter = (&(objectClass=user)(mail=%s))
query_filter = (&(objectClass=user)(userPrincipalName=%s))
result_attribute = samAccountName
result_filter = /var/mail/%s/Maildir/

bind=yes
bind_dn=vmail@adsample.local
bind_pw=パスワード
version=3
#start_tls=yes
#debuglevel=10
[root@mail postfix]#

とりあえず「debuglevel=10」というのは調査中に有効にしていた値

virtual_mailbox_maps で取得できる情報として期待されているものは メールを保存するディレクトリ名 の模様

コメントとなっている「query_filter = (&(objectClass=user)(mail=%s))」はActive Directoryベースだとmailってないので使わない。ユーザ名のみの場合は「samAccountName=%s」、ドメイン名付きの場合は「userPrincipalName=%s」かな、というところで設定

取得できてるかどうかは「postmap -q ユーザ名 ldap:/~」で確認

[root@mail ~]# postmap -q testuser1@adsample.local ldap:/etc/postfix/ldap-mailbox.cf
/var/mail/testuser1/Maildir/
[root@mail ~]#

想定しているディレクトリ名が出力されればOK

-vオプションをつけると検索内容の詳細が確認できる。

[root@mail ~]# postmap -v -q testuser1@adsample.local ldap:/etc/postfix/ldap-mailbox.cf
postmap: name_mask: all
postmap: inet_addr_local: configured 2 IPv4 addresses
postmap: inet_addr_local: configured 2 IPv6 addresses
postmap: dict_ldap_open: Using LDAP source /etc/postfix/_ldap-mailbox.cf
postmap: cfg_get_str: /etc/postfix/_ldap-mailbox.cf: server_host = ldaps://192.168.122.10
postmap: cfg_get_int: /etc/postfix/_ldap-mailbox.cf: server_port = 389
postmap: cfg_get_int: /etc/postfix/_ldap-mailbox.cf: version = 3
postmap: dict_ldap_open: /etc/postfix/_ldap-mailbox.cf server_host URL is ldaps://192.168.122.10
postmap: cfg_get_str: /etc/postfix/_ldap-mailbox.cf: scope = sub
postmap: cfg_get_str: /etc/postfix/_ldap-mailbox.cf: search_base = cn=Users,dc=adsample,dc=local
postmap: cfg_get_int: /etc/postfix/_ldap-mailbox.cf: timeout = 10
postmap: cfg_get_str: /etc/postfix/_ldap-mailbox.cf: query_filter = (&(objectClass=user)(userPrincipalName=%s))
postmap: cfg_get_str: /etc/postfix/_ldap-mailbox.cf: result_format = <NULL>
postmap: cfg_get_str: /etc/postfix/_ldap-mailbox.cf: result_filter = /var/mail/%s/Maildir/
postmap: cfg_get_str: /etc/postfix/_ldap-mailbox.cf: domain =
postmap: cfg_get_str: /etc/postfix/_ldap-mailbox.cf: terminal_result_attribute =
postmap: cfg_get_str: /etc/postfix/_ldap-mailbox.cf: leaf_result_attribute =
postmap: cfg_get_str: /etc/postfix/_ldap-mailbox.cf: result_attribute = samAccountName
postmap: cfg_get_str: /etc/postfix/_ldap-mailbox.cf: special_result_attribute =
postmap: cfg_get_str: /etc/postfix/_ldap-mailbox.cf: bind = yes
postmap: cfg_get_str: /etc/postfix/_ldap-mailbox.cf: bind_dn = vmail@adsample.local
postmap: cfg_get_str: /etc/postfix/_ldap-mailbox.cf: bind_pw = パスワード
postmap: cfg_get_bool: /etc/postfix/_ldap-mailbox.cf: cache = off
postmap: cfg_get_int: /etc/postfix/_ldap-mailbox.cf: cache_expiry = -1
postmap: cfg_get_int: /etc/postfix/_ldap-mailbox.cf: cache_size = -1
postmap: cfg_get_int: /etc/postfix/_ldap-mailbox.cf: recursion_limit = 1000
postmap: cfg_get_int: /etc/postfix/_ldap-mailbox.cf: expansion_limit = 0
postmap: cfg_get_int: /etc/postfix/_ldap-mailbox.cf: size_limit = 0
postmap: cfg_get_int: /etc/postfix/_ldap-mailbox.cf: dereference = 0
postmap: cfg_get_bool: /etc/postfix/_ldap-mailbox.cf: chase_referrals = off
postmap: cfg_get_bool: /etc/postfix/_ldap-mailbox.cf: start_tls = off
postmap: cfg_get_bool: /etc/postfix/_ldap-mailbox.cf: tls_require_cert = off
postmap: cfg_get_str: /etc/postfix/_ldap-mailbox.cf: tls_ca_cert_file =
postmap: cfg_get_str: /etc/postfix/_ldap-mailbox.cf: tls_ca_cert_dir =
postmap: cfg_get_str: /etc/postfix/_ldap-mailbox.cf: tls_cert =
postmap: cfg_get_str: /etc/postfix/_ldap-mailbox.cf: tls_key =
postmap: cfg_get_str: /etc/postfix/_ldap-mailbox.cf: tls_random_file =
postmap: cfg_get_str: /etc/postfix/_ldap-mailbox.cf: tls_cipher_suite =
postmap: cfg_get_int: /etc/postfix/_ldap-mailbox.cf: debuglevel = 0
postmap: dict_open: ldap:/etc/postfix/_ldap-mailbox.cf
postmap: dict_ldap_lookup: In dict_ldap_lookup
postmap: dict_ldap_lookup: No existing connection for LDAP source /etc/postfix/_ldap-mailbox.cf, reopening
postmap: dict_ldap_connect: Connecting to server ldaps://192.168.122.10
postmap: dict_ldap_connect: Actual Protocol version used is 3.
postmap: dict_ldap_connect: Binding to server ldaps://192.168.122.10 with dn vmail@adsample.local
postmap: dict_ldap_connect: Successful bind to server ldaps://192.168.122.10 with dn vmail@adsample.local
postmap: dict_ldap_connect: Cached connection handle for LDAP source /etc/postfix/_ldap-mailbox.cf
postmap: dict_ldap_lookup: /etc/postfix/_ldap-mailbox.cf: Searching with filter (&(objectClass=user)(userPrincipalName=testuser1@adsample.local))
postmap: dict_ldap_get_values[1]: Search found 1 match(es)
postmap: dict_ldap_get_values[1]: search returned 1 value(s) for requested result attribute sAMAccountName
postmap: dict_ldap_get_values[1]: Leaving dict_ldap_get_values
postmap: dict_ldap_lookup: Search returned /var/mail/testuser1/Maildir/
/var/mail/testuser1/Maildir/
postmap: dict_ldap_close: Closed connection handle for LDAP source /etc/postfix/_ldap-mailbox.cf
[root@mail ~]#

それっぽい動作をすることを確認して、postfixを再起動してみたところ”virtual_transport= dovecot”設定を無視して postfix側でLDAPを見に行くことを確認。(/etc/postfix/ldap-mailbox.cfにdebuglevel=10を設定すると、 /var/log/maillog に詳細ログが出ているので)

どうやら、2025年5月時点では postfix/dovecotでActive Directory連携するときは、postfix側ではLDAP連携をする必要はないようだ(aliasなどをAD側で設定している場合は別)

最終的に行った設定内容

結局のところ「Dovecot LDA with Postfix」の Virutal users記載ベースで/etc/postfix/master.cfの末尾にdovecot用設定2行追加。(元ネタでは /usr/local/libexec以下にあるけどRHEL9では/usr/libexecという違いに注意)

[root@mail ~]# tail /etc/postfix/master.cf
#
#scalemail-backend unix -       n       n       -       2       pipe
#  flags=R user=scalemail argv=/usr/lib/scalemail/bin/scalemail-store
#  ${nexthop} ${user} ${extension}
#
#mailman   unix  -       n       n       -       -       pipe
#  flags=FRX user=list argv=/usr/lib/mailman/bin/postfix-to-mailman.py
#  ${nexthop} ${user}
dovecot   unix  -       n       n       -       -       pipe
  flags=DRhu user=vmail:vmail argv=/usr/libexec/dovecot/dovecot-lda -f ${sender} -d ${recipient}
[root@mail ~]#

/etc/postfix/main.cf に以下を追加

[root@mail ~]# tail -5 /etc/postfix/main.cf
#
virtual_mailbox_domains = adsample.local
virtual_transport= dovecot
dovecot_destination_recipient_limit = 1
[root@mail ~]#

なお、この時にdovecot側のLDAP連携設定は以下となっている。(メールソフト側でIMAP/POP3用に入力するユーザ名をドメイン名付きにしたい場合はuserPrincipalName、ユーザ名のみにしたい場合は samAccountName を使う)

[root@mail ~]# cat /etc/dovecot/dovecot-ldap.conf.ext
dn= cn=vmail,cn=Users,dc=adsample,dc=local
dnpass= パスワード
#pass_filter= (samAccountName=%u)
#user_filter= (samAccountName=%u)
user_filter= (userPrincipalName=%u)
pass_filter= (userPrincipalName=%u)
user_attrs = =uid=1000, =gid=1000
pass_attrs = =uid=1000, =gid=1000

auth_bind=yes
uris=ldaps://192.168.122.10
base= cn=Users,dc=adsample,dc=local
scope=subtree

[root@mail ~]# cat /etc/dovecot/conf.d/auth-ldap.conf.ext
# Authentication for LDAP users. Included from 10-auth.conf.
#
# <doc/wiki/AuthDatabase.LDAP.txt>

passdb {
  driver = ldap

  # Path for LDAP configuration file, see example-config/dovecot-ldap.conf.ext
  args = /etc/dovecot/dovecot-ldap.conf.ext
}

# "prefetch" user database means that the passdb already provided the
# needed information and there's no need to do a separate userdb lookup.
# <doc/wiki/UserDatabase.Prefetch.txt>
#userdb {
#  driver = prefetch
#}

userdb {
  driver = ldap
  args = /etc/dovecot/dovecot-ldap.conf.ext

  # Default fields can be used to specify defaults that LDAP may override
  #default_fields = home=/home/virtual/%u
  default_fields = uid=vmail gid=vmail
}

# If you don't have any user-specific settings, you can avoid the userdb LDAP
# lookup by using userdb static instead of userdb ldap, for example:
# <doc/wiki/UserDatabase.Static.txt>
#userdb {
  #driver = static
  #args = uid=vmail gid=vmail home=/var/vmail/%u
#}
[root@mail ~]#

また /etc/dovecot/conf.d/10-mail.conf に mail_location = maildir:/var/mail/%n/Maildir という設定を追加している。

[root@mail ~]# diff -u /etc/dovecot/conf.d/10-mail.conf.org /etc/dovecot/conf.d/10-mail.conf
--- /etc/dovecot/conf.d/10-mail.conf.org        2025-04-25 03:13:54.044373479 +0900
+++ /etc/dovecot/conf.d/10-mail.conf    2025-04-30 10:59:12.661404241 +0900
@@ -27,7 +27,7 @@
 #
 # <doc/wiki/MailLocation.txt>
 #
-#mail_location =
+mail_location = maildir:/var/mail/%n/Maildir

 # If you need to set multiple mailbox locations or want to change default
 # namespace settings, you can do it by defining namespace sections.
[root@mail ~]#

エラー対処

/var/log/maillog を見てたら下記のようなpermission問題があった

May  1 18:28:19 mail dovecot[924]: auth: Debug: userdb out: USER#0111#011testuser2@adsample.local#011uid=1000#011gid=1000
May  1 18:28:19 mail dovecot[2244]: lda(testuser2@adsample.local)<2244></OWMMLM+E2jECAAAOg3h0A>: msgid=<9da96806-84e5-4f26-9752-acf16b48d4dc@adsample.local>: saved mail to INBOX
May  1 18:28:19 mail postfix/pipe[2238]: AD3C12037F14: to=<testuser2@adsample.local>, orig_to=<testuser2@adosakana.local>, relay=dovecot, delay=0.13, delays=0.02/0/0/0.11, dsn=2.0.0, status=sent (delivered via dovecot service (lda(testuser2@adsample.local): Error: net_connect_unix(/run/dovecot/stats-writer) failed: Permission))
May  1 18:28:19 mail postfix/qmgr[2205]: AD3C12037F14: removed

エラー対処を調べると2019年1月のiredmailフォーラムの「Re: Error: net_connect_unix(/var/run/dovecot/stats-writer) failed」 が出てくる

これだと /etc/dovecot/dovecot.conf に直接追加しているが、 /etc/dovecot/conf.d/に新しいファイルを作って追加することにした

[root@mail conf.d]# vi /etc/dovecot/conf.d/12-stat.conf
[root@mail conf.d]# cat /etc/dovecot/conf.d/12-stat.conf
service stats {
    unix_listener stats-reader {
        user = vmail
        group = vmail
        mode = 0660
    }

    unix_listener stats-writer {
        user = vmail
        group = vmail
        mode = 0660
    }
}
[root@mail conf.d]# systemctl restart dovecot
[root@mail conf.d]#

これで出力されなくなった


メール送信時の細かい設定について

/etc/dovecot/dovecot-ldap.conf.ext と /etc/dovecot/conf.d/auth-ldap.conf.ext のそれぞれでuid/gidに関する設定を入れているが、それぞれの必要性について再検証

というのは、設定してるなかで、片方だけ設定を入れているとmissingログが出てたから両方入れた・・・はずだったんだけど、それって正しいの?という検証

まずは/etc/dovecot/conf.d/99-debug.conf にdebugログ出力設定を書いて 実施

[root@mail ~]# cat /etc/dovecot/conf.d/99-debug.conf
auth_debug=yes
auth_debug_passwords=yes
auth_verbose=yes
auth_verbose_passwords=yes
verbose_proctitle=yes
verbose_ssl=yes

[root@mail ~]#

ケース1

conf.d/auth-ldap.conf.ext に 「default_fields = uid=vmail gid=vmail」
dovecot-ldap.conf.ext で user_atrrs,pass_attrsの設定なし

この時メールを送信すると以下のような”result: uid missing”, “result: homeDirectory missing; uidNumber missing; gidNumber missing”ログがある

May  2 09:45:39 mail dovecot[1564]: auth: Debug: client in: AUTH#0111#011PLAIN#011service=imap#011session=BnUjeBw0hcjAqHoB#011lip=192.168.122.12#011rip=192.168.122.1#011lport=143#011rport=51333
May  2 09:45:39 mail dovecot[1564]: auth: Debug: client passdb out: CONT#0111
May  2 09:45:39 mail dovecot[1564]: auth: Debug: client in: CONT#0111#011AHRlc3R1c2VyMkBhZHNhbXBsZS5sb2NhbABkaWdpdGFsMTIzQSM= (previous base64 data may contain sensitive data)
May  2 09:45:39 mail dovecot[1564]: auth: Debug: ldap(testuser2@adsample.local,192.168.122.1,<BnUjeBw0hcjAqHoB>): Performing passdb lookup
May  2 09:45:39 mail dovecot[1564]: auth: Debug: ldap(testuser2@adsample.local,192.168.122.1,<BnUjeBw0hcjAqHoB>): bind search: base=cn=Users,dc=adsample,dc=local filter=(userPrincipalName=testuser2@adsample.local)
May  2 09:45:39 mail dovecot[1564]: auth: Debug: ldap(testuser2@adsample.local,192.168.122.1,<BnUjeBw0hcjAqHoB>): no fields returned by the server
May  2 09:45:39 mail dovecot[1564]: auth: Debug: ldap(testuser2@adsample.local,192.168.122.1,<BnUjeBw0hcjAqHoB>): result:  uid missing
May  2 09:45:39 mail dovecot[1564]: auth: Debug: ldap(testuser2@adsample.local,192.168.122.1,<BnUjeBw0hcjAqHoB>): Finished passdb lookup
May  2 09:45:39 mail dovecot[1564]: auth: Debug: auth(testuser2@adsample.local,192.168.122.1,<BnUjeBw0hcjAqHoB>): Auth request finished
May  2 09:45:39 mail dovecot[1564]: auth: Debug: client passdb out: OK#0111#011user=testuser2@adsample.local
May  2 09:45:39 mail dovecot[1564]: auth: Debug: master in: REQUEST#0112287206401#0111566#0111#011bef1c5eb0e8a2b05cf297e143bfb1cc6#011session_pid=1569#011request_auth_token
May  2 09:45:39 mail dovecot[1564]: auth: Debug: ldap(testuser2@adsample.local,192.168.122.1,<BnUjeBw0hcjAqHoB>): Performing userdb lookup
May  2 09:45:39 mail dovecot[1564]: auth: Debug: ldap(testuser2@adsample.local,192.168.122.1,<BnUjeBw0hcjAqHoB>): user search: base=cn=Users,dc=adsample,dc=local scope=subtree filter=(userPrincipalName=testuser2@adsample.local) fields=homeDirectory,uidNumber,gidNumber
May  2 09:45:39 mail dovecot[1564]: auth: Debug: ldap(testuser2@adsample.local,192.168.122.1,<BnUjeBw0hcjAqHoB>): no fields returned by the server
May  2 09:45:39 mail dovecot[1564]: auth: Debug: ldap(testuser2@adsample.local,192.168.122.1,<BnUjeBw0hcjAqHoB>): result:  homeDirectory missing; uidNumber missing; gidNumber missing
May  2 09:45:39 mail dovecot[1564]: auth: Debug: ldap(testuser2@adsample.local,192.168.122.1,<BnUjeBw0hcjAqHoB>): Finished userdb lookup
May  2 09:45:39 mail dovecot[1564]: auth: Debug: master userdb out: USER#0112287206401#011testuser2@adsample.local#011uid=1000#011gid=1000#011auth_mech=PLAIN#011auth_token=aaa072efd8fc1ceb4051c9c51b1fdbc9437e7f81

ケース2

conf.d/auth-ldap.conf.ext に default_fields 設定なし
dovecot-ldap.conf.ext で “user_attrs = =uid=1000, =gid=1000″,”pass_attrs = =uid=1000, =gid=1000” 設定あり

この場合、ログに xxx missing が出ない?


May  2 09:54:48 mail dovecot[959]: auth: Debug: client in: CONT#0111#011AHRlc3R1c2VyMkBhZHNhbXBsZS5sb2NhbABkaWdpdGFsMTIzQSM= (previous base64 data may contain sensitive data)
May  2 09:54:48 mail dovecot[959]: auth: Debug: ldap(testuser2@adsample.local,192.168.122.1,<D2PcmBw0S8rAqHoB>): Performing passdb lookup
May  2 09:54:48 mail dovecot[959]: auth: Debug: ldap(testuser2@adsample.local,192.168.122.1,<D2PcmBw0S8rAqHoB>): bind search: base=cn=Users,dc=adsample,dc=local filter=(userPrincipalName=testuser2@adsample.local)
May  2 09:54:48 mail dovecot[959]: auth: Debug: master in: USER#0111#011testuser1@adsample.local#011service=lda
May  2 09:54:48 mail dovecot[959]: auth: Debug: ldap(testuser1@adsample.local): Performing userdb lookup
May  2 09:54:48 mail dovecot[959]: auth: Debug: ldap(testuser1@adsample.local): user search: base=cn=Users,dc=adsample,dc=local scope=subtree filter=(userPrincipalName=testuser1@adsample.local) fields=
May  2 09:54:48 mail dovecot[959]: auth: Debug: ldap(testuser2@adsample.local,192.168.122.1,<D2PcmBw0S8rAqHoB>): result: objectClass=top,top,top,top cn=testuser2 givenName=testuser2 distinguishedName=CN=testuser2,CN=Users,DC=adsample,DC=local instanceType=4 whenCreated=20250417094639.0Z whenChanged=20250430015944.0Z displayName=testuser2 uSNCreated=12616 uSNChanged=40983 name=testuser2 objectGUID=�u&#016$|-E�Z#034\O?�#036 userAccountControl=66048 badPwdCount=0 codePage=0 countryCode=0 badPasswordTime=133893655225944004 lastLogoff=0 lastLogon=133894260848965097 pwdLastSet=133893567990887154 primaryGroupID=513 objectSid=<no values> accountExpires=9223372036854775807 logonCount=16 sAMAccountName=testuser2 sAMAccountType=805306368 userPrincipalName=testuser2@adsample.local objectCategory=CN=Person,CN=Schema,CN=Configuration,DC=adsample,DC=local dSCorePropagationData=20250418015428.0Z,20250418015428.0Z lastLogonTimestamp=133904519848472342; objectGUID,uSNCreated,objectCategory,objectClass,primaryGroupID,cn,givenName,objectSid,sAMAccountType,dSCorePropagationData,userAccountControl,name,codePage,lastLogon,logonCount,countryCode,lastLogoff,uSNChanged,pwdLastSet,distinguishedName,sAMAccountName,whenChanged,userPrincipalName,instanceType,badPwdCount,accountExpires,whenCreated,displayName,badPasswordTime,lastLogonTimestamp unused
May  2 09:54:48 mail dovecot[959]: auth: Debug: ldap(testuser1@adsample.local): result: objectClass=top,top,top,top cn=testuser1 givenName=testuser1 distinguishedName=CN=testuser1,CN=Users,DC=adsample,DC=local instanceType=4 whenCreated=20250417094618.0Z whenChanged=20250425001141.0Z displayName=testuser1 uSNCreated=12609 uSNChanged=36883 name=testuser1 objectGUID=#037��#�!#020F�j#020#010��#011x userAccountControl=66048 badPwdCount=0 codePage=0 countryCode=0 badPasswordTime=133900339076624909 lastLogoff=0 lastLogon=133900339256453379 pwdLastSet=133893567784742554 primaryGroupID=513 objectSid=<no values> accountExpires=9223372036854775807 logonCount=0 sAMAccountName=testuser1 sAMAccountType=805306368 userPrincipalName=testuser1@adsample.local objectCategory=CN=Person,CN=Schema,CN=Configuration,DC=adsample,DC=local dSCorePropagationData=20250418015428.0Z,20250418015428.0Z lastLogonTimestamp=133900135017739905 mail=testuser1@example.com; objectGUID,uSNCreated,objectCategory,objectClass,primaryGroupID,cn,givenName,objectSid,sAMAccountType,dSCorePropagationData,userAccountControl,name,mail,codePage,lastLogon,logonCount,countryCode,lastLogoff,uSNChanged,pwdLastSet,distinguishedName,sAMAccountName,whenChanged,userPrincipalName,instanceType,badPwdCount,accountExpires,whenCreated,displayName,badPasswordTime,lastLogonTimestamp unused
May  2 09:54:48 mail dovecot[959]: auth: Debug: ldap(testuser1@adsample.local): Finished userdb lookup
May  2 09:54:48 mail dovecot[959]: auth: Debug: userdb out: USER#0111#011testuser1@adsample.local#011uid=1000#011gid=1000
May  2 09:54:48 mail dovecot[959]: auth: Debug: ldap(testuser2@adsample.local,192.168.122.1,<D2PcmBw0S8rAqHoB>): Finished passdb lookup
May  2 09:54:48 mail dovecot[959]: auth: Debug: auth(testuser2@adsample.local,192.168.122.1,<D2PcmBw0S8rAqHoB>): Auth request finished
May  2 09:54:48 mail dovecot[959]: auth: Debug: client passdb out: OK#0111#011user=testuser2@adsample.local#011uid=1000#011gid=1000
May  2 09:54:48 mail dovecot[1423]: lda(testuser1@adsample.local)<1423><jFPYJdgXFGiPBQAAOg3h0A>: msgid=<c923fd79-8135-46e3-aa56-afd1a1282ff8@adsample.local>: saved mail to INBOX
May  2 09:54:48 mail postfix/pipe[1422]: 7FF342020373: to=<testuser1@adsample.local>, orig_to=<testuser1@adosakana.local>, relay=dovecot, delay=0.15, delays=0.03/0.01/0/0.12, dsn=2.0.0, status=sent (delivered via dovecot service)
May  2 09:54:48 mail postfix/qmgr[884]: 7FF342020373: removed
May  2 09:54:48 mail dovecot[959]: auth: Debug: master in: REQUEST#0113980787713#0111424#0111#011d2548dbb496c7cf3c62e2637869d2d69#011session_pid=1425#011request_auth_token
May  2 09:54:48 mail dovecot[959]: auth: Debug: ldap(testuser2@adsample.local,192.168.122.1,<D2PcmBw0S8rAqHoB>): Performing userdb lookup
May  2 09:54:48 mail dovecot[959]: auth: Debug: ldap(testuser2@adsample.local,192.168.122.1,<D2PcmBw0S8rAqHoB>): user search: base=cn=Users,dc=adsample,dc=local scope=subtree filter=(userPrincipalName=testuser2@adsample.local) fields=
May  2 09:54:48 mail dovecot[959]: auth: Debug: ldap(testuser2@adsample.local,192.168.122.1,<D2PcmBw0S8rAqHoB>): result: objectClass=top,top,top,top cn=testuser2 givenName=testuser2 distinguishedName=CN=testuser2,CN=Users,DC=adsample,DC=local instanceType=4 whenCreated=20250417094639.0Z whenChanged=20250430015944.0Z displayName=testuser2 uSNCreated=12616 uSNChanged=40983 name=testuser2 objectGUID=�u&#016$|-E�Z#034\O?�#036 userAccountControl=66048 badPwdCount=0 codePage=0 countryCode=0 badPasswordTime=133893655225944004 lastLogoff=0 lastLogon=133894260848965097 pwdLastSet=133893567990887154 primaryGroupID=513 objectSid=<no values> accountExpires=9223372036854775807 logonCount=16 sAMAccountName=testuser2 sAMAccountType=805306368 userPrincipalName=testuser2@adsample.local objectCategory=CN=Person,CN=Schema,CN=Configuration,DC=adsample,DC=local dSCorePropagationData=20250418015428.0Z,20250418015428.0Z lastLogonTimestamp=133904519848472342; objectGUID,uSNCreated,objectCategory,objectClass,primaryGroupID,cn,givenName,objectSid,sAMAccountType,dSCorePropagationData,userAccountControl,name,codePage,lastLogon,logonCount,countryCode,lastLogoff,uSNChanged,pwdLastSet,distinguishedName,sAMAccountName,whenChanged,userPrincipalName,instanceType,badPwdCount,accountExpires,whenCreated,displayName,badPasswordTime,lastLogonTimestamp unused
May  2 09:54:48 mail dovecot[959]: auth: Debug: ldap(testuser2@adsample.local,192.168.122.1,<D2PcmBw0S8rAqHoB>): Finished userdb lookup
May  2 09:54:48 mail dovecot[959]: auth: Debug: master userdb out: USER#0113980787713#011testuser2@adsample.local#011uid=1000#011gid=1000#011auth_mech=PLAIN#011auth_token=68518eb1e5a886522b5dcabaae828704633386c9

missing 出力がない??

そもそも、同じログレベル出力なのに、出力された内容に差がありすぎるんですが・・・

dovecot-ldap.conf.ext に “user_attrs = =uid=1000, =gid=1000″,”pass_attrs = =uid=1000, =gid=1000” を設定するだけでいける?

dovecotをActive Directoryと連携させる(メモ版

設定検証が落ち着いたら最終結果のみの記事を別に作成する予定です


Windows Server 2025のActice Directoryサーバと連携したメールサーバを作って、dovecotでimap/pop3、postfixでsmtpを提供する、という設定を行うこととした。

まずは「Windows Server 2025で作ったActive Directory環境でldapsを使えるようにする」にあるようにActive Directoryサーバをldapsで使えるように設定した。

ただ、調べると、純正Windows ServeverのActice Directoryサーバとldapを使って連携させた場合、userPassword, unixUserPassword, msSFU30Password などのパスワード情報が配布されていないので連携が取れない、的なことが書いてある記事などがあった。

実際 ldapsearchを使って確認してみると取得できたもののなかに含まれていない。これはまずいのでは?といろいろ調べる羽目になった。(なお、最終的には ldapsearchでは取得できないけど dovecotの認証としてActive Directoryで設定したパスワードがそのまま利用できることを確認できました)

# ldapsearch -x -H ldaps://192.168.122.10 -D "cn=vmail,cn=Users,dc=adsample,dc=local" -w "パスワード" -b "cn=Users,dc=adsample,dc=local" samAccountName=testuser1
# extended LDIF
#
# LDAPv3
# base <cn=Users,dc=adsample,dc=local> with scope subtree
# filter: samAccountName=testuser1
# requesting: ALL
#

# testuser1, Users, adsample.local
dn: CN=testuser1,CN=Users,DC=adsample,DC=local
objectClass: top
objectClass: person
objectClass: organizationalPerson
objectClass: user
cn: testuser1
givenName: testuser1
distinguishedName: CN=testuser1,CN=Users,DC=adsample,DC=local
instanceType: 4
whenCreated: 20250417094618.0Z
whenChanged: 20250425001141.0Z
displayName: testuser1
uSNCreated: 12609
uSNChanged: 36883
name: testuser1
objectGUID:: H4j5I6UhEEaDahAIt64JeA==
userAccountControl: 66048
badPwdCount: 0
codePage: 0
countryCode: 0
badPasswordTime: 133900185974014530
lastLogoff: 0
lastLogon: 133900186129696391
pwdLastSet: 133893567784742554
primaryGroupID: 513
objectSid:: AQUAAAAAAAUVAAAArlEnuz4EHgKbAhGoTwQAAA==
accountExpires: 9223372036854775807
logonCount: 0
sAMAccountName: testuser1
sAMAccountType: 805306368
userPrincipalName: testuser1@adsample.local
objectCategory: CN=Person,CN=Schema,CN=Configuration,DC=adsample,DC=local
dSCorePropagationData: 20250418015428.0Z
dSCorePropagationData: 16010101000000.0Z
lastLogonTimestamp: 133900135017739905
mail: testuser1@example.com

# search result
search: 2
result: 0 Success

# numResponses: 2
# numEntries: 1
#

じゃあ、と回避策を探すと sssd を使ってLinux OSごとActive Directoryに参加させて、pam+sssdで認証を行う、という手法がある。この場合、Linux OS上に各アカウントのUIDがsssd経由で自動発行されディレクトリが作られていくことになる。

vmailアカウントで1つにまとめるvirtual boxタイプでやりようがないのかなぁ、と、とりあえず試してみることにした。

まずはRedHatのドキュメント「メールサーバーサービスの設定および維持」にある「1.2. LDAP 認証を使用した Dovecot サーバーのセットアップ」を参考に設定を実施

dovecotインストール

まず、dovecotをインストール

[root@mail ~]# dnf install dovecot
Last metadata expiration check: 0:15:03 ago on Fri Apr 25 02:14:57 2025.
Dependencies resolved.
================================================================================
 Package        Arch    Version                                Repository  Size
================================================================================
Installing:
 dovecot        x86_64  1:2.3.16-14.el9                        appstream  4.7 M
Installing dependencies:
 clucene-core   x86_64  2.3.3.4-42.20130812.e8e3d20git.el9     appstream  585 k
 libexttextcat  x86_64  3.4.5-11.el9                           appstream  209 k
 libicu         x86_64  67.1-9.el9                             baseos     9.6 M
 libstemmer     x86_64  0-18.585svn.el9                        appstream   82 k

Transaction Summary
================================================================================
Install  5 Packages

Total download size: 15 M
Installed size: 53 M
Is this ok [y/N]: y
Downloading Packages:
(1/5): clucene-core-2.3.3.4-42.20130812.e8e3d20 582 kB/s | 585 kB     00:01    A
(2/5): libexttextcat-3.4.5-11.el9.x86_64.rpm    207 kB/s | 209 kB     00:01
(3/5): libstemmer-0-18.585svn.el9.x86_64.rpm    995 kB/s |  82 kB     00:00
(4/5): dovecot-2.3.16-14.el9.x86_64.rpm         1.3 MB/s | 4.7 MB     00:03
(5/5): libicu-67.1-9.el9.x86_64.rpm             1.2 MB/s | 9.6 MB     00:07
--------------------------------------------------------------------------------
Total                                           1.3 MB/s |  15 MB     00:11
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                        1/1
  Installing       : libicu-67.1-9.el9.x86_64                               1/5
  Installing       : libstemmer-0-18.585svn.el9.x86_64                      2/5
  Installing       : libexttextcat-3.4.5-11.el9.x86_64                      3/5
  Installing       : clucene-core-2.3.3.4-42.20130812.e8e3d20git.el9.x86_   4/5
  Running scriptlet: dovecot-1:2.3.16-14.el9.x86_64                         5/5
  Installing       : dovecot-1:2.3.16-14.el9.x86_64                         5/5
  Running scriptlet: dovecot-1:2.3.16-14.el9.x86_64                         5/5
  Verifying        : clucene-core-2.3.3.4-42.20130812.e8e3d20git.el9.x86_   1/5
  Verifying        : dovecot-1:2.3.16-14.el9.x86_64                         2/5
  Verifying        : libexttextcat-3.4.5-11.el9.x86_64                      3/5
  Verifying        : libstemmer-0-18.585svn.el9.x86_64                      4/5
  Verifying        : libicu-67.1-9.el9.x86_64                               5/5

Installed:
  clucene-core-2.3.3.4-42.20130812.e8e3d20git.el9.x86_64
  dovecot-1:2.3.16-14.el9.x86_64
  libexttextcat-3.4.5-11.el9.x86_64
  libicu-67.1-9.el9.x86_64
  libstemmer-0-18.585svn.el9.x86_64

Complete!
[root@mail ~]#

dovecot用自己証明書作成

dovecot用に自己証明書を作成するけど、標準だと有効期限1年なので変更して作成する

まずは/etc/pki/dovecot/dovecot-openssl.cnf に適切なホスト名と管理者メールアドレスを記載する

[root@mail ~]# cat /etc/pki/dovecot/dovecot-openssl.cnf
[ req ]
default_bits = 3072
encrypt_key = yes
distinguished_name = req_dn
x509_extensions = cert_type
prompt = no

[ req_dn ]
# country (2 letter code)
#C=FI

# State or Province Name (full name)
#ST=

# Locality Name (eg. city)
#L=Helsinki

# Organization (eg. company)
#O=Dovecot

# Organizational Unit Name (eg. section)
OU=IMAP server

# Common Name (*.example.com is also possible)
CN=mail.adsample.local

# E-mail contact
emailAddress=postmaster@adsample.local

[ cert_type ]
nsCertType = server
[root@mail ~]#

次に通常はdovecot初回起動時に /usr/share/doc/dovecot/mkcert.sh を実行して自己証明書を作成しているのだが、このスクリプト内で「-days 365」と書かれているから有効期限が1年になっているので、コピーして「-days 3650」などに修正する

[root@mail ~]# cp /usr/share/doc/dovecot/mkcert.sh .
[root@mail ~]# vi mkcert.sh
[root@mail ~]# diff -u /usr/share/doc/dovecot/mkcert.sh mkcert.sh
--- /usr/share/doc/dovecot/mkcert.sh    2024-10-03 05:08:31.000000000 +0900
+++ mkcert.sh   2025-04-25 02:55:09.510440927 +0900
@@ -34,7 +34,7 @@
   exit 1
 fi

-$OPENSSL req -new -x509 -nodes -config $OPENSSLCONFIG -out $CERTFILE -keyout $KEYFILE -days 365 || exit 2
+$OPENSSL req -new -x509 -nodes -config $OPENSSLCONFIG -out $CERTFILE -keyout $KEYFILE -days 3650 || exit 2
 chown root:root $CERTFILE $KEYFILE
 chmod 0600 $CERTFILE $KEYFILE
 echo
[root@mail ~]#

で、修正したmkcert.shを実行して証明書を作成

[root@mail ~]# bash mkcert.sh
/etc/pki/dovecot/certs/dovecot.pem already exists, won't overwrite
[root@mail ~]# rm /etc/pki/dovecot/certs/dovecot.pem
rm: remove regular file '/etc/pki/dovecot/certs/dovecot.pem'? y
[root@mail ~]# rm /etc/pki/dovecot/private/dovecot.pem
rm: remove regular file '/etc/pki/dovecot/private/dovecot.pem'? y
[root@mail ~]# bash mkcert.sh
..+...+......+.....+....+..............+.+.....+.........++++++++++++++++++++++++++++++++++++++++++*..+....+......+........+......+....+............++++++++++++++++++++++++++++++++++++++++++*....+......+.+...+.....+......+...................+......+...+...+.....+...+.+...+.....................+............+.........+.....+.....................+.............+.........+...........+....+.....+.+..............+.......+........+.............+.....+..........+............+.....+..........+...+..+.+.....+.......+..+.+.....+.........+...+.......+..+.+..+..................+.......+..+...+.+....................+.+.........+.....+....+...+...+............+.....+.......+..+......+.......+...+...............+..+...+....+...........+....+........+.+......+........+...............+.......+........................+.........+..+....+......+.........+..+..................+....+......+............+.....+....+........+.......+.....+.+.....+...+......+..........+.........+++++
.........+.+..+....+...+...+...++++++++++++++++++++++++++++++++++++++++++*..........+...+.................+...+...++++++++++++++++++++++++++++++++++++++++++*.......+.....+....+..............+......+.........+.......+...+..+................+.....+.......+..+.........+....+......+..+..................+.........+......+............+.............+..+...+....+...............+...........+..........+.........+...+...+++++
-----

subject=OU=IMAP server, CN=mail.adsample.local, emailAddress=postmaster@adsample.local
SHA1 Fingerprint=DD:2E:9B:1A:6A:84:07:03:EF:6E:7F:D4:7A:03:39:F0:24:FC:0E:2A
[root@mail ~]# 

ファイルが作成され、「openssl x509 -noout -dates -in ファイル名」を実行し有効期限が約10年であることを確認

[root@mail ~]# ls -ltR /etc/pki/dovecot/
/etc/pki/dovecot/:
total 8
drwxr-xr-x. 2 root root  25 Apr 25 02:56 certs
drwxr-xr-x. 2 root root  25 Apr 25 02:56 private
-rw-r--r--. 1 root root 502 Apr 25 02:45 dovecot-openssl.cnf
-rw-r--r--. 1 root root 496 Apr 25 02:45 dovecot-openssl.cnf.org

/etc/pki/dovecot/certs:
total 4
-rw-------. 1 root root 1619 Apr 25 02:56 dovecot.pem

/etc/pki/dovecot/private:
total 4
-rw-------. 1 root root 2484 Apr 25 02:56 dovecot.pem
[root@mail ~]# openssl x509 -noout -dates -in /etc/pki/dovecot/certs/dovecot.pem
notBefore=Apr 24 17:56:04 2025 GMT
notAfter=Apr 22 17:56:04 2035 GMT
[root@mail ~]#

続いてRedHatのページにも記載されているDiffie-Hellmanパラメータファイル作成

[root@mail ~]# openssl dhparam -out /etc/dovecot/dh.pem 4096
Generating DH parameters, 4096 bit long safe prime
.....................................................+........................................................+.........................................................+......................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................+.................................................................................................................+.....................................................................................................................+..........................................+.......................................................+...................................................................................+....................................................................................................................................................................................................................................................................+......................................................+......+..........................................+........................................+..............................................................................................................................................................................+......................................................................................................................................................................................................................................................................................................................................................................................................................................................+.............................................................................................................................................................................................................................................................................+...........................................................................................................................................................+............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................+.......................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................+........................+...............................................+.....................................................................................................................+......................................................................................................................................................................................................................................................................................................................................................................+........................................................................................................................................................................................................................................................+......................................................................................................+.........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................+.......................................................................................................................................................................................................................+.......................................................................................................................................+...................................................................................................................................................................................................................................+....................................................................................................................................................................................................................................................................+...+....................................................................................................................................................................................................................................................+........+........+..................................................................................................................................................................................................................................................................................................................+......................................................+...........................................................................................................................................................................+..............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................+....................................................................+...........+.....................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................+.........................................................................................................................................................................................................................................................................................................................................................+....+........................................................................................................................................................................................................................................................................................................................................+......+...................................................................................................................................................................................................................................................................................................................................................+........................................................................................................................................................................................................................................+............................+...............................................................+.......................................................................................................................................................................................................................................+..............................................................................................................................................................................................................................................+..........................................................................................................................................................................................................+................................................................................+......................................................................................+.........................................................................................................................................+..............................................++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*
[root@mail ~]# ls -l /etc/dovecot/dh.pem
-rw-r--r--. 1 root root 773 Apr 25 03:02 /etc/dovecot/dh.pem
[root@mail ~]#

/etc/dovecot/conf.d/10-ssl.conf に証明書ファイルとDiffie-Hellmanパラメータファイルの登録

ssl_certとssl_keyは標準値のまま
ssl_ca については登録せず
ssl_shのコメントを外す

[root@mail postfix]# cat /etc/dovecot/conf.d/10-ssl.conf
##
## SSL settings
##

# SSL/TLS support: yes, no, required. <doc/wiki/SSL.txt>
# disable plain pop3 and imap, allowed are only pop3+TLS, pop3s, imap+TLS and imaps
# plain imap and pop3 are still allowed for local connections
ssl = no

# PEM encoded X.509 SSL/TLS certificate and private key. They're opened before
# dropping root privileges, so keep the key file unreadable by anyone but
# root. Included doc/mkcert.sh can be used to easily generate self-signed
# certificate, just make sure to update the domains in dovecot-openssl.cnf
ssl_cert = </etc/pki/dovecot/certs/dovecot.pem
ssl_key = </etc/pki/dovecot/private/dovecot.pem

# If key file is password protected, give the password here. Alternatively
# give it when starting dovecot with -p parameter. Since this file is often
# world-readable, you may want to place this setting instead to a different
# root owned 0600 file by using ssl_key_password = <path.
#ssl_key_password =

# PEM encoded trusted certificate authority. Set this only if you intend to use
# ssl_verify_client_cert=yes. The file should contain the CA certificate(s)
# followed by the matching CRL(s). (e.g. ssl_ca = </etc/pki/dovecot/certs/ca.pem)
#ssl_ca =

# Require that CRL check succeeds for client certificates.
#ssl_require_crl = yes

# Directory and/or file for trusted SSL CA certificates. These are used only
# when Dovecot needs to act as an SSL client (e.g. imapc backend or
# submission service). The directory is usually /etc/pki/dovecot/certs in
# Debian-based systems and the file is /etc/pki/tls/cert.pem in
# RedHat-based systems. Note that ssl_client_ca_file isn't recommended with
# large CA bundles, because it leads to excessive memory usage.
#ssl_client_ca_dir =
#ssl_client_ca_file =

# Require valid cert when connecting to a remote server
#ssl_client_require_valid_cert = yes

# Request client to send a certificate. If you also want to require it, set
# auth_ssl_require_client_cert=yes in auth section.
#ssl_verify_client_cert = no

# Which field from certificate to use for username. commonName and
# x500UniqueIdentifier are the usual choices. You'll also need to set
# auth_ssl_username_from_cert=yes.
#ssl_cert_username_field = commonName

# SSL DH parameters
# Generate new params with `openssl dhparam -out /etc/dovecot/dh.pem 4096`
# Or migrate from old ssl-parameters.dat file with the command dovecot
# gives on startup when ssl_dh is unset.
ssl_dh = </etc/dovecot/dh.pem

# Minimum SSL protocol version to use. Potentially recognized values are SSLv3,
# TLSv1, TLSv1.1, TLSv1.2 and TLSv1.3, depending on the OpenSSL version used.
#
# Dovecot also recognizes values ANY and LATEST. ANY matches with any protocol
# version, and LATEST matches with the latest version supported by library.
#ssl_min_protocol = TLSv1.2

# SSL ciphers to use, the default is:
#ssl_cipher_list = ALL:!kRSA:!SRP:!kDHd:!DSS:!aNULL:!eNULL:!EXPORT:!DES:!3DES:!MD5:!PSK:!RC4:!ADH:!LOW@STRENGTH
# To disable non-EC DH, use:
#ssl_cipher_list = ALL:!DH:!kRSA:!SRP:!kDHd:!DSS:!aNULL:!eNULL:!EXPORT:!DES:!3DES:!MD5:!PSK:!RC4:!ADH:!LOW@STRENGTH
ssl_cipher_list = PROFILE=SYSTEM

# Colon separated list of elliptic curves to use. Empty value (the default)
# means use the defaults from the SSL library. P-521:P-384:P-256 would be an
# example of a valid value.
#ssl_curve_list =

# Prefer the server's order of ciphers over client's.
#ssl_prefer_server_ciphers = no

# SSL crypto device to use, for valid values run "openssl engine"
#ssl_crypto_device =

# SSL extra options. Currently supported options are:
#   compression - Enable compression.
#   no_ticket - Disable SSL session tickets.
#ssl_options =
[root@mail postfix]#

また、標準設定のままだとSSLが必須(ssl=required)になっているので、なくてもよい「ssl=yes」に変更します。

[root@mail ~]# vi /etc/dovecot/conf.d/10-ssl.conf
[root@mail ~]# diff -u /etc/dovecot/conf.d/10-ssl.conf.org /etc/dovecot/conf.d/10-ssl.conf
--- /etc/dovecot/conf.d/10-ssl.conf.org 2025-04-25 03:03:27.865411037 +0900
+++ /etc/dovecot/conf.d/10-ssl.conf     2025-04-25 03:28:09.900322146 +0900
@@ -5,7 +5,7 @@
 # SSL/TLS support: yes, no, required. <doc/wiki/SSL.txt>
 # disable plain pop3 and imap, allowed are only pop3+TLS, pop3s, imap+TLS and imaps
 # plain imap and pop3 are still allowed for local connections
-ssl = required
+ssl = yes

 # PEM encoded X.509 SSL/TLS certificate and private key. They're opened before
 # dropping root privileges, so keep the key file unreadable by anyone but
@@ -53,7 +53,7 @@
 # Generate new params with `openssl dhparam -out /etc/dovecot/dh.pem 4096`
 # Or migrate from old ssl-parameters.dat file with the command dovecot
 # gives on startup when ssl_dh is unset.
-#ssl_dh = </etc/dovecot/dh.pem
+ssl_dh = </etc/dovecot/dh.pem

 # Minimum SSL protocol version to use. Potentially recognized values are SSLv3,
 # TLSv1, TLSv1.1, TLSv1.2 and TLSv1.3, depending on the OpenSSL version used.
[root@mail ~]#

メール管理用ユーザ作成

メール管理ユーザとしてRHELドキュメントにあるように「vmail」ユーザを作成

[root@mail ~]# useradd --home-dir /var/mail --shell /usr/sbin/nologin vmail
useradd: warning: the home directory /var/mail already exists.
useradd: Not copying any file from skel directory into it.
[root@mail ~]#

[root@mail ~]# id vmail
uid=1000(vmail) gid=1000(vmail) groups=1000(vmail)
[root@mail ~]#

上記でホームディレクトリを /var/mail で指定しているが、すでに存在しているディレクトリであるため、現存する/var/mailの所有者を変更する。

[root@mail ~]# ls -ld /var/mail
lrwxrwxrwx. 1 root root 10 Oct  3  2024 /var/mail -> spool/mail
[root@mail ~]# ls -ld /var/spool/mail
drwxrwxr-x. 2 root mail 19 Apr 25 03:11 /var/spool/mail
[root@mail ~]#
[root@mail ~]# chown vmail:vmail /var/mail/
[root@mail ~]# chmod 700 /var/mail/
[root@mail ~]# ls -ld /var/mail
lrwxrwxrwx. 1 root root 10 Oct  3  2024 /var/mail -> spool/mail
[root@mail ~]# ls -ld /var/mail/
drwx------. 2 vmail vmail 19 Apr 25 03:11 /var/mail/
[root@mail ~]# ls -ld /var/spool/mail
drwx------. 2 vmail vmail 19 Apr 25 03:11 /var/spool/mail
[root@mail ~]# ls -ld /var/spool/mail/
drwx------. 2 vmail vmail 19 Apr 25 03:11 /var/spool/mail/
[root@mail ~]#

/etc/dovecot/conf.d/10-mail.conf にメール保存先のディレクトリ設定「mail_location = sdbox:/var/mail/%n/」を追加

(なお、sdboxという指定だと dbox Mailbox Formatのsingle-dbox形式、になっていて、maildir形式にしたい場合は maildir と書く必要がありました。あとで”mail_location = maildir:/var/mail/%n/Maildir”に修正しています )

[root@mail ~]# cp /etc/dovecot/conf.d/10-mail.conf /etc/dovecot/conf.d/10-mail.conf.org
[root@mail ~]# vi /etc/dovecot/conf.d/10-mail.conf
[root@mail ~]# diff -u /etc/dovecot/conf.d/10-mail.conf.org /etc/dovecot/conf.d/10-mail.conf
--- /etc/dovecot/conf.d/10-mail.conf.org        2025-04-25 03:13:54.044373479 +0900
+++ /etc/dovecot/conf.d/10-mail.conf    2025-04-25 03:14:17.970372044 +0900
@@ -27,7 +27,7 @@
 #
 # <doc/wiki/MailLocation.txt>
 #
-#mail_location =
+mail_location = sdbox:/var/mail/%n/

 # If you need to set multiple mailbox locations or want to change default
 # namespace settings, you can do it by defining namespace sections.
[root@mail ~]#

LDAPとの連携設定

まずは /etc/dovecot/conf.d/10-auth.conf で auth-system.conf.ext ファイルの読み込みをやめ、 auth-ldap.conf.ext ファイルを読み込む設定に修正

[root@mail ~]# cp /etc/dovecot/conf.d/10-auth.conf /etc/dovecot/conf.d/10-auth.conf.org
[root@mail ~]# vi /etc/dovecot/conf.d/10-auth.conf
[root@mail ~]# diff -u /etc/dovecot/conf.d/10-auth.conf.org /etc/dovecot/conf.d/10-auth.conf
--- /etc/dovecot/conf.d/10-auth.conf.org        2025-04-25 03:15:55.357366203 +0900
+++ /etc/dovecot/conf.d/10-auth.conf    2025-04-25 03:16:28.351364224 +0900
@@ -119,9 +119,9 @@
 #!include auth-deny.conf.ext
 #!include auth-master.conf.ext

-!include auth-system.conf.ext
+#!include auth-system.conf.ext
 #!include auth-sql.conf.ext
-#!include auth-ldap.conf.ext
+!include auth-ldap.conf.ext
 #!include auth-passwdfile.conf.ext
 #!include auth-checkpassword.conf.ext
 #!include auth-static.conf.ext
[root@mail ~]#

/etc/dovecot/conf.d/auth-ldap.conf.ext の userdb について override_fileds 設定を追加します

[root@mail ~]# cp /etc/dovecot/conf.d/auth-ldap.conf.ext /etc/dovecot/conf.d/auth-ldap.conf.ext.org
[root@mail ~]# vi /etc/dovecot/conf.d/auth-ldap.conf.ext
[root@mail ~]# diff -u /etc/dovecot/conf.d/auth-ldap.conf.ext.org /etc/dovecot/conf.d/auth-ldap.conf.ext
--- /etc/dovecot/conf.d/auth-ldap.conf.ext.org  2025-04-25 03:17:04.099362080 +0900
+++ /etc/dovecot/conf.d/auth-ldap.conf.ext      2025-04-25 03:17:39.663359947 +0900
@@ -7,6 +7,7 @@

   # Path for LDAP configuration file, see example-config/dovecot-ldap.conf.ext
   args = /etc/dovecot/dovecot-ldap.conf.ext
+  override_fields = uid=vmail gid=vmail home=/var/mail/%n/
 }

 # "prefetch" user database means that the passdb already provided the
[root@mail ~]#

uidとgidについて、vmailという文字列ではなく、実際のUID/GIDの数値を指定しなければならないかな?と思って両方試してみましたが、どちらでも動作しました。
(「override_fields = uid=1000 gid=1000 home=/var/mail/%n/」でも大丈夫だった)

次に、LDAP検索用ファイル/etc/dovecot/dovecot-ldap.conf.extを新規で作成….が、いろいろあったので、詳しいところは後回しにします。

firewall設定

標準だとポートが開けられていないので、必要に応じて開けます

まず初期状況確認

[root@mail ~]# firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: ens160
  sources:
  services: cockpit dhcpv6-client ssh
  ports:
  protocols:
  forward: yes
  masquerade: no
  forward-ports:
  source-ports:
  icmp-blocks:
  rich rules:
[root@mail ~]#

メール系ポートを開けていきます。この記事はdovecot(imapとpop3)についてなので、imapとpop3について追加します

[root@mail ~]# firewall-cmd --permanent --add-service imaps --add-service imap 
success
[root@mail ~]# firewall-cmd --permanent --add-service pop3 --add-service pop3s
success
[root@mail ~]# firewall-cmd --reload
success
[root@mail ~]#  firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: ens160
  sources:
  services: cockpit dhcpv6-client imap imaps pop3 pop3s ssh
  ports:
  protocols:
  forward: yes
  masquerade: no
  forward-ports:
  source-ports:
  icmp-blocks:
  rich rules:
[root@mail ~]#

dovecotの起動登録

標準だと起動してこないdovecotを起動してくるように設定を入れます

[root@mail ~]# systemctl status dovecot
○ dovecot.service - Dovecot IMAP/POP3 email server
     Loaded: loaded (/usr/lib/systemd/system/dovecot.service; disabled; preset:>
     Active: inactive (dead)
       Docs: man:dovecot(1)
             https://doc.dovecot.org/
[root@mail ~]# systemctl enable --now dovecot
Created symlink /etc/systemd/system/multi-user.target.wants/dovecot.service → /usr/lib/systemd/system/dovecot.service.
[root@mail ~]# systemctl status dovecot
● dovecot.service - Dovecot IMAP/POP3 email server
     Loaded: loaded (/usr/lib/systemd/system/dovecot.service; enabled; preset: >
     Active: active (running) since Fri 2025-04-25 03:24:50 JST; 2s ago
       Docs: man:dovecot(1)
             https://doc.dovecot.org/
    Process: 2180 ExecStartPre=/usr/libexec/dovecot/prestartscript (code=exited>
   Main PID: 2186 (dovecot)
     Status: "v2.3.16 (7e2e900c1a) running"
      Tasks: 4 (limit: 10873)
     Memory: 5.3M
        CPU: 92ms
     CGroup: /system.slice/dovecot.service
             tq2186 /usr/sbin/dovecot -F
             tq2187 dovecot/anvil
             tq2188 dovecot/log
             mq2189 dovecot/config

Apr 25 03:24:50 mail.adsample.local systemd[1]: Starting Dovecot IMAP/POP3 emai>
Apr 25 03:24:50 mail.adsample.local dovecot[2186]: master: Dovecot v2.3.16 (7e2>
Apr 25 03:24:50 mail.adsample.local systemd[1]: Started Dovecot IMAP/POP3 email>
[root@mail ~]#

Active Directoryサーバを利用するのに必要なLDAP設定の調査

RHELのドキュメントに記載されているものは、OpenLDAPサーバを利用した場合の設定で、Windows Serverをベースとした場合、posixAccountに関する情報は標準では提供されていないため利用できません。

このため、Active DirectoryのLDAPで利用できる情報は何かをldapsearchコマンドを実行しながら確認していきます。

とりあえず先に調査した結果、これでいけるな、となったものは以下です

[root@mail ~]# cat /etc/dovecot/dovecot-ldap.conf.ext
# LDAPサーバへの接続に関する設定
uris=ldaps://192.168.122.10
auth_bind=yes
dn= cn=vmail,cn=Users,dc=adsample,dc=local
dnpass= パスワード

# LDAPの検索
base= cn=Users,dc=adsample,dc=local
scope=subtree

# 検索結果に対するフィルター
user_filter= (samAccountName=%u)
pass_filter= (samAccountName=%u)
[root@mail ~]#

各項に関して解説します

接続先のLDAPサーバの指定を「uris=ldaps://サーバ名」で行います

古い資料では「server_host=ホスト名」と「server_port=389」になっていたりしますが、現代は「uris=ldap://サーバ名」か「uris=ldaps://サーバ名」です

2025年現在のLDAPサーバではセキュリティ強化のためユーザ認証を行わないとLDAP上の情報を検索できないようになっています。このため「auth_bind=yes」で、認証を行うようにします。

「dn=」で指定しているのがユーザ検索に使用するActive Directory上のユーザ指定です。今回は「vmail」というユーザを作成していますので、それを指定しています。

続く「dnpass=」は上記ユーザに設定したActive Directoryでのパスワードです。平文でそのまま記載します。

次はLDAPから情報を引っ張ってくるのに使う設定です

Active Directoryでユーザに関する情報は「cn=Users,dc=adsample,dc=local」に入ってるので、それを使用します。

ldapsearchコマンドを使うことでどういった情報が取得できるかを確認することができます。

「-D」のオプションとしてdn=の後ろに入力したもの
「-b」のオプションとしてbase=の後ろに入力したもの

[root@mail ~]#  ldapsearch -x -H ldaps://192.168.122.10 -D "cn=vmail,cn=Users,dc=adsample,dc=local" -w "パスワード" -b "cn=Users,dc=adsample,dc=local" -s subtree
# extended LDIF
#
# LDAPv3
# base <cn=Users,dc=adsample,dc=local> with scope subtree
# filter: (objectclass=*)
# requesting: ALL
#

# Users, adsample.local
dn: CN=Users,DC=adsample,DC=local
objectClass: top
objectClass: container
cn: Users
description: Default container for upgraded user accounts
distinguishedName: CN=Users,DC=adsample,DC=local
instanceType: 4
whenCreated: 20250417093642.0Z
whenChanged: 20250417093642.0Z
uSNCreated: 5672
uSNChanged: 5672
showInAdvancedViewOnly: FALSE
name: Users
objectGUID:: 0+Pn0tolgUSaHrCO7ll4VQ==
systemFlags: -1946157056
objectCategory: CN=Container,CN=Schema,CN=Configuration,DC=adsample,DC=local
isCriticalSystemObject: TRUE
dSCorePropagationData: 20250417093820.0Z
dSCorePropagationData: 16010101000001.0Z

# testuser1, Users, adsample.local
dn: CN=testuser1,CN=Users,DC=adsample,DC=local
objectClass: top
objectClass: person
objectClass: organizationalPerson
objectClass: user
cn: testuser1
givenName: testuser1
distinguishedName: CN=testuser1,CN=Users,DC=adsample,DC=local
instanceType: 4
whenCreated: 20250417094618.0Z
whenChanged: 20250425001141.0Z
displayName: testuser1
uSNCreated: 12609
uSNChanged: 36883
name: testuser1
objectGUID:: H4j5I6UhEEaDahAIt64JeA==
userAccountControl: 66048
badPwdCount: 0
codePage: 0
countryCode: 0
badPasswordTime: 133900339076624909
lastLogoff: 0
lastLogon: 133900339256453379
pwdLastSet: 133893567784742554
primaryGroupID: 513
objectSid:: AQUAAAAAAAUVAAAArlEnuz4EHgKbAhGoTwQAAA==
accountExpires: 9223372036854775807
logonCount: 0
sAMAccountName: testuser1
sAMAccountType: 805306368
userPrincipalName: testuser1@adsample.local
objectCategory: CN=Person,CN=Schema,CN=Configuration,DC=adsample,DC=local
dSCorePropagationData: 20250418015428.0Z
dSCorePropagationData: 16010101000000.0Z
lastLogonTimestamp: 133900135017739905
mail: testuser1@example.com

# testuser2, Users, adsample.local
dn: CN=testuser2,CN=Users,DC=adsample,DC=local
objectClass: top
objectClass: person
objectClass: organizationalPerson
objectClass: user
cn: testuser2
givenName: testuser2
<略>

# search result
search: 2
result: 0 Success

# numResponses: 32
# numEntries: 31
[root@mail ~]#

まあ、たくさんの情報が出てきてしまいます。

これの範囲を狭くするための設定がfilterです

user_filter がユーザ名を検索するときに使うフィルターで、 pass_filter がそのユーザのパスワードを検索する際に使うフィルターです
注意点は、これは検索した結果を狭めるために設定するもので、ユーザ名やパスワードとしてみなす値が何なのかを指定するものではありません。

上の例では「user_filter= (samAccountName=%u)」「pass_filter= (samAccountName=%u)」としています。

%uが imap/pop3でアクセスしたときに入力したユーザ名に置き換えられますので、ユーザがtestuser1でログインしたときに使用されるフィルターは「samAccountName=testuser1」となります。

この時にどのような値が取得できるかをldapsearchで確認するには、以下のように最後にフィルター文字列を指定して実行します。

[root@mail ~]#  ldapsearch -x -H ldaps://192.168.122.10 -D "cn=vmail,cn=Users,dc=adsample,dc=local" -w "パスワード" -b "cn=Users,dc=adsample,dc=local" -s subtree samAccountName=testuser1
# extended LDIF
#
# LDAPv3
# base <cn=Users,dc=adsample,dc=local> with scope subtree
# filter: samAccountName=testuser1
# requesting: ALL
#

# testuser1, Users, adsample.local
dn: CN=testuser1,CN=Users,DC=adsample,DC=local
objectClass: top
objectClass: person
objectClass: organizationalPerson
objectClass: user
cn: testuser1
givenName: testuser1
distinguishedName: CN=testuser1,CN=Users,DC=adsample,DC=local
instanceType: 4
whenCreated: 20250417094618.0Z
whenChanged: 20250425001141.0Z
displayName: testuser1
uSNCreated: 12609
uSNChanged: 36883
name: testuser1
objectGUID:: H4j5I6UhEEaDahAIt64JeA==
userAccountControl: 66048
badPwdCount: 0
codePage: 0
countryCode: 0
badPasswordTime: 133900339076624909
lastLogoff: 0
lastLogon: 133900339256453379
pwdLastSet: 133893567784742554
primaryGroupID: 513
objectSid:: AQUAAAAAAAUVAAAArlEnuz4EHgKbAhGoTwQAAA==
accountExpires: 9223372036854775807
logonCount: 0
sAMAccountName: testuser1
sAMAccountType: 805306368
userPrincipalName: testuser1@adsample.local
objectCategory: CN=Person,CN=Schema,CN=Configuration,DC=adsample,DC=local
dSCorePropagationData: 20250418015428.0Z
dSCorePropagationData: 16010101000000.0Z
lastLogonTimestamp: 133900135017739905
mail: testuser1@example.com

# search result
search: 2
result: 0 Success

# numResponses: 2
# numEntries: 1
[root@mail ~]#

じゃあ、上記ででてきた値のうち、どれをユーザ名やパスワードとして認識させるんだ、という話なんですが、おそらく user_attrs と pass_attrs なんだと思われるのですが、いまいち動作が確認できませんでした。

上で示した設定では ユーザ名を使っていましたが「ユーザ名 @ドメイン名」でログインできるようにする場合は samAccountName ではなく userPrincipalNameを使うことでログインできるようになりました。

[root@mail ~]# cat /etc/dovecot/dovecot-ldap.conf.ext
# LDAPサーバへの接続に関する設定
uris=ldaps://192.168.122.10
auth_bind=yes
dn= cn=vmail,cn=Users,dc=adsample,dc=local
dnpass= パスワード

# LDAPの検索
base= cn=Users,dc=adsample,dc=local
scope=subtree

# 検索結果に対するフィルター
user_filter= (userPrincipalName=%u)
pass_filter= (userPrincipalName=%u)
[root@mail ~]#

で・・・パスワードとして使えるらしい userPassword, unixUserPassword, msSFU30Password  は ldapsearchの出力結果に出てこないのですが、doveadmコマンドで確認してみると、ちゃんとActive Directoryに設定したパスワードで認証が通ることが確認できました。

dovecotの動作確認

dovecotのコマンド「doveadm auth login ユーザ名」で認証がちゃんと動くかという検証ができます。

最初のユーザ名だけでログインできる場合は以下

[root@mail ~]# doveadm auth login testuser1
Password:
passdb: testuser1 auth succeeded
extra fields:
  user=testuser1
userdb extra fields:
  testuser1@adsample.local
  uid=1000
  gid=1000
  home=/var/mail/testuser1/
  auth_mech=PLAIN
  auth_user=testuser1
[root@mail ~]#

ドメイン名付きで設定した場合は以下

[root@mail ~]# doveadm auth login testuser1@adsample.local
Password:
passdb: testuser1@adsample.local auth succeeded
extra fields:
  user=testuser1@adsample.local
userdb extra fields:
  testuser1@adsample.local
  uid=1000
  gid=1000
  home=/var/mail/testuser1/
  auth_mech=PLAIN
[root@mail ~]#

うまく動かなかった場合は、dovecotのログ出力を増やします。

設定のon/offがしやすいように /etc/dovecot/conf.d/99-debug.conf というファイルを新規作成しました。

[root@mail ~]# cat /etc/dovecot/conf.d/99-debug.conf
auth_debug=yes
auth_debug_passwords=yes
auth_verbose=yes
auth_verbose_passwords=yes
verbose_proctitle=yes
verbose_ssl=yes

[root@mail ~]#

この設定の注意点は「auth_debug_passwords=yes」と「auth_verbose_passwords=yes」です。エラー時にパスワードとして入力した文字列がログファイルに記録されてしまうので、取り扱いに注意してください。

例えば、ドメイン名ありでログインしなければならないのにユーザ名のみでログインしようとした場合のエラーとログは以下のようになりました。

[root@mail ~]# doveadm auth login testuser1
Password:
passdb: testuser1 auth failed
extra fields:
  user=testuser1
[root@mail ~]#
[root@mail ~]# tail -f /var/log/maillog
Apr 25 18:47:01 mail dovecot[3326]: auth: Debug: Loading modules from directory: /usr/lib64/dovecot/auth
Apr 25 18:47:01 mail dovecot[3326]: auth: Debug: Module loaded: /usr/lib64/dovecot/auth/lib20_auth_var_expand_crypt.so
Apr 25 18:47:01 mail dovecot[3326]: auth: Debug: Module loaded: /usr/lib64/dovecot/auth/libdriver_sqlite.so
Apr 25 18:47:01 mail dovecot[3326]: auth: Debug: Loading modules from directory: /usr/lib64/dovecot/auth
Apr 25 18:47:01 mail dovecot[3326]: auth: Debug: Module loaded: /usr/lib64/dovecot/auth/libauthdb_ldap.so
Apr 25 18:47:01 mail dovecot[3326]: auth: Debug: Read auth token secret from /run/dovecot/auth-token-secret.dat
Apr 25 18:47:01 mail dovecot[3326]: auth: Debug: ldap(/etc/dovecot/dovecot-ldap.conf.ext): LDAP initialization took 24 msecs
Apr 25 18:47:01 mail dovecot[3326]: auth: Debug: auth client connected (pid=3334)
Apr 25 18:47:01 mail dovecot[3326]: auth: Debug: client in: AUTH#0111#011PLAIN#011service=doveadm#011debug#011resp=dGVzdHVzZXIxAHRlc3R1c2VyMQBkaWdpdGFsMTIzQSM= (previous base64 data may contain sensitive data)
Apr 25 18:47:01 mail dovecot[3326]: auth: Debug: ldap(testuser1): Performing passdb lookup
Apr 25 18:47:01 mail dovecot[3326]: auth: Debug: ldap(testuser1): bind search: base=cn=Users,dc=adsample,dc=local filter=(userPrincipalName=testuser1)
Apr 25 18:47:01 mail dovecot[3326]: auth: Debug: ldap(testuser1): no fields returned by the server
Apr 25 18:47:01 mail dovecot[3326]: auth: ldap(testuser1): unknown user (given password: パスワード)
Apr 25 18:47:01 mail dovecot[3326]: auth: Debug: ldap(testuser1): Finished passdb lookup
Apr 25 18:47:01 mail dovecot[3326]: auth: Debug: auth(testuser1): Auth request finished
Apr 25 18:47:03 mail dovecot[3326]: auth: Debug: client passdb out: FAIL#0111#011user=testuser1

「auth_debug_passwords=yes」と「auth_verbose_passwords=yes」を設定しているのでパスワード文字列が出力されています。

正しくログインできた場合のログは下記のようになります。

[root@mail ~]# tail -f /var/log/maillog
Apr 25 18:49:05 mail dovecot[3326]: auth: Debug: Loading modules from directory: /usr/lib64/dovecot/auth
Apr 25 18:49:05 mail dovecot[3326]: auth: Debug: Module loaded: /usr/lib64/dovecot/auth/lib20_auth_var_expand_crypt.so
Apr 25 18:49:05 mail dovecot[3326]: auth: Debug: Module loaded: /usr/lib64/dovecot/auth/libdriver_sqlite.so
Apr 25 18:49:05 mail dovecot[3326]: auth: Debug: Loading modules from directory: /usr/lib64/dovecot/auth
Apr 25 18:49:05 mail dovecot[3326]: auth: Debug: Module loaded: /usr/lib64/dovecot/auth/libauthdb_ldap.so
Apr 25 18:49:05 mail dovecot[3326]: auth: Debug: Read auth token secret from /run/dovecot/auth-token-secret.dat
Apr 25 18:49:06 mail dovecot[3326]: auth: Debug: ldap(/etc/dovecot/dovecot-ldap.conf.ext): LDAP initialization took 20 msecs
Apr 25 18:49:06 mail dovecot[3326]: auth: Debug: auth client connected (pid=3337)
Apr 25 18:49:06 mail dovecot[3326]: auth: Debug: client in: AUTH#0111#011PLAIN#011service=doveadm#011debug#011resp=dGVzdHVzZXIxQGFkc2FtcGxlLmxvY2FsAHRlc3R1c2VyMUBhZHNhbXBsZS5sb2NhbABkaWdpdGFsMTIzQSM= (previous base64 data may contain sensitive data)
Apr 25 18:49:06 mail dovecot[3326]: auth: Debug: ldap(testuser1@adsample.local): Performing passdb lookup
Apr 25 18:49:06 mail dovecot[3326]: auth: Debug: ldap(testuser1@adsample.local): bind search: base=cn=Users,dc=adsample,dc=local filter=(userPrincipalName=testuser1@adsample.local)
Apr 25 18:49:06 mail dovecot[3326]: auth: Debug: ldap(testuser1@adsample.local): no fields returned by the server
Apr 25 18:49:06 mail dovecot[3326]: auth: Debug: ldap(testuser1@adsample.local): result:  uid missing
Apr 25 18:49:06 mail dovecot[3326]: auth: Debug: ldap(testuser1@adsample.local): Finished passdb lookup
Apr 25 18:49:06 mail dovecot[3326]: auth: Debug: auth(testuser1@adsample.local): Auth request finished
Apr 25 18:49:06 mail dovecot[3326]: auth: Debug: client passdb out: OK#0111#011user=testuser1@adsample.local
Apr 25 18:49:06 mail dovecot[3326]: auth: Debug: master in: REQUEST#0114040032257#0113337#0111#0119908c30ac4ecc1214e5ca9f458d737ff#011session_pid=3337
Apr 25 18:49:06 mail dovecot[3326]: auth: Debug: ldap(testuser1@adsample.local): Performing userdb lookup
Apr 25 18:49:06 mail dovecot[3326]: auth: Debug: ldap(testuser1@adsample.local): user search: base=cn=Users,dc=adsample,dc=local scope=subtree filter=(userPrincipalName=testuser1@adsample.local) fields=homeDirectory,uidNumber,gidNumber
Apr 25 18:49:06 mail dovecot[3326]: auth: Debug: ldap(testuser1@adsample.local): no fields returned by the server
Apr 25 18:49:06 mail dovecot[3326]: auth: Debug: ldap(testuser1@adsample.local): result:  homeDirectory missing; uidNumber missing; gidNumber missing
Apr 25 18:49:06 mail dovecot[3326]: auth: Debug: ldap(testuser1@adsample.local): Finished userdb lookup
Apr 25 18:49:06 mail dovecot[3326]: auth: Debug: master userdb out: USER#0114040032257#011testuser1@adsample.local#011uid=1000#011gid=1000#011home=/var/mail/testuser1/#011auth_mech=PLAIN

で、/var/mail がどのようになっているかを確認すると、まだ何もない

[root@mail ~]# ls -l /var/mail/
total 0
[root@mail ~]#

telnetコマンドでPOP3ログインを手動で実施してみる

[root@mail ~]# telnet localhost 110
Trying ::1...
Connected to localhost.
Escape character is '^]'.
+OK Dovecot ready.
user testuser1
+OK
pass パスワード
+OK Logged in.
quit
+OK Logging out.
Connection closed by foreign host.
[root@mail ~]# 

/var/mail/にディレクトリが作成された

[root@mail ~]# ls -l /var/mail/
total 0
drwx------. 3 vmail vmail 116 Apr 25  2025 testuser1
[root@mail ~]#

ただ、mbox形式で作成されていた

[root@mail ~]# ls -ltR /var/mail/testuser1/
/var/mail/testuser1/:
total 8
-rw-------. 1 vmail vmail 452 Apr 25  2025 dovecot.list.index.log
-rw-------. 1 vmail vmail   8 Apr 25  2025 dovecot-uidvalidity
-r--r--r--. 1 vmail vmail   0 Apr 25  2025 dovecot-uidvalidity.680b65c4
drwx------. 3 vmail vmail  19 Apr 25  2025 mailboxes

/var/mail/testuser1/mailboxes:
total 0
drwx------. 3 vmail vmail 24 Apr 25  2025 INBOX

/var/mail/testuser1/mailboxes/INBOX:
total 0
drwx------. 2 vmail vmail 31 Apr 25  2025 dbox-Mails

/var/mail/testuser1/mailboxes/INBOX/dbox-Mails:
total 4
-rw-------. 1 vmail vmail 224 Apr 25  2025 dovecot.index.log
[root@mail ~]#

maildir形式への変更

設定をみなおしてみると、RedHat手順の中で /etc/dovecot/conf.d/10-mail.conf に mail_location パラメータで 「sdbox:~」としていたところが dbox Mailbox Formatのsingle-dbox形式での保存という設定という意味だった。

設定を「mail_location = maildir:/var/mail/%n/Maildir」に変更

[root@mail dovecot]# diff -u /etc/dovecot/conf.d/10-mail.conf.org /etc/dovecot/conf.d/10-mail.conf
--- /etc/dovecot/conf.d/10-mail.conf.org        2025-04-25 03:13:54.044373479 +0900
+++ /etc/dovecot/conf.d/10-mail.conf    2025-04-30 10:59:12.661404241 +0900
@@ -27,7 +27,7 @@
 #
 # <doc/wiki/MailLocation.txt>
 #
-#mail_location =
+mail_location = maildir:/var/mail/%n/Maildir

 # If you need to set multiple mailbox locations or want to change default
 # namespace settings, you can do it by defining namespace sections.
[root@mail dovecot]# systemctl restart dovecot
[root@mail dovecot]#

とりあえずsdbox設定で作られたメールディレクトリを削除

[root@mail dovecot]# ls /var/mail/testuser2/
dovecot-uidvalidity           dovecot.list.index.log
dovecot-uidvalidity.680b6784  mailboxes
[root@mail dovecot]# rm -rf /var/mail/testuser2/
[root@mail dovecot]# ls -l /var/mail/testuser2/
ls: cannot access '/var/mail/testuser2/': No such file or directory
[root@mail dovecot]# 

認証テストとpop3ログインテストを実施

[root@mail dovecot]# doveadm auth login testuser2@adsample.local
Password: パスワード
passdb: testuser2@adsample.local auth succeeded
extra fields:
  user=testuser2@adsample.local
userdb extra fields:
  testuser2@adsample.local
  uid=1000
  gid=1000
  home=/var/mail/testuser2/
  auth_mech=PLAIN
[root@mail dovecot]# ls -l /var/mail/testuser2/
ls: cannot access '/var/mail/testuser2/': No such file or directory
[root@mail dovecot]# telnet localhost 110
Trying ::1...
Connected to localhost.
Escape character is '^]'.
+OK Dovecot ready.
user testuser2@adsample.local
+OK
pass パスワード
+OK Logged in.
quit
+OK Logging out.
Connection closed by foreign host.
[root@mail dovecot]# 

pop3ログイン後に maildir形式で作成されていることを確認

[root@mail dovecot]# ls -l /var/mail/testuser2/
total 4
drwx------. 5 vmail vmail 4096 Apr 30 11:00 Maildir
[root@mail dovecot]# ls -l /var/mail/testuser2/Maildir/
total 16
drwx------. 2 vmail vmail   6 Apr 30 11:00 cur
-rw-------. 1 vmail vmail  51 Apr 30 11:00 dovecot-uidlist
-rw-------. 1 vmail vmail   8 Apr 30 11:00 dovecot-uidvalidity
-r--r--r--. 1 vmail vmail   0 Apr 30 11:00 dovecot-uidvalidity.68118427
-rw-------. 1 vmail vmail 320 Apr 30 11:00 dovecot.index.log
-rw-------. 1 vmail vmail 452 Apr 30 11:00 dovecot.list.index.log
-rw-------. 1 vmail vmail   0 Apr 30 11:00 maildirfolder
drwx------. 2 vmail vmail   6 Apr 30 11:00 new
drwx------. 2 vmail vmail   6 Apr 30 11:00 tmp
[root@mail dovecot]#

ちなみに testuser1のほうはmailboxesディレクトリなどを残したままmaildirでログインしなおしてみたところ両方のディレクトリが残った状態となりました。

[root@mail dovecot]# ls -l /var/mail/
total 0
drwx------. 3 vmail vmail 116 Apr 25 19:36 testuser1
drwx------. 3 vmail vmail  21 Apr 30 11:00 testuser2
[root@mail dovecot]# ls -l /var/mail/testuser1
total 8
-rw-------. 1 vmail vmail   8 Apr 25 19:36 dovecot-uidvalidity
-r--r--r--. 1 vmail vmail   0 Apr 25 19:36 dovecot-uidvalidity.680b65c4
-rw-------. 1 vmail vmail 452 Apr 25 19:36 dovecot.list.index.log
drwx------. 3 vmail vmail  19 Apr 25 19:36 mailboxes
[root@mail dovecot]# telnet localhost 110
Trying ::1...
Connected to localhost.
Escape character is '^]'.
+OK Dovecot ready.
user testuser1@adsample.local
+OK
pass パスワード
+OK Logged in.
quit
+OK Logging out.
Connection closed by foreign host.
[root@mail dovecot]# ls -l /var/mail/testuser1
total 12
drwx------. 5 vmail vmail 4096 Apr 30 11:05 Maildir
-rw-------. 1 vmail vmail    8 Apr 25 19:36 dovecot-uidvalidity
-r--r--r--. 1 vmail vmail    0 Apr 25 19:36 dovecot-uidvalidity.680b65c4
-rw-------. 1 vmail vmail  452 Apr 25 19:36 dovecot.list.index.log
drwx------. 3 vmail vmail   19 Apr 25 19:36 mailboxes
[root@mail dovecot]#