May 31, 2007
Postfix + sasl + MySQL
Mar 09, 2007
MySQLでアカウント管理(1)コンパイル
MySQL とlibnss-mysqlを組み合わせることでLinuxのアカウント管理ができるようになります
MySQL-5.0.36 libnss-mysql-1.5 の組み合わせで作ってみました
MySQL ./configure --prefix=/usr --exec-prefix=/usr --libexecdir=/usr/sbin --datadi r=/usr/share --sysconfdir=/etc/mysql --localstatedir=/var/lib/mysql --includedir =/usr/include --infodir=/usr/share/info --mandir=/usr/share/man --enable-shared --enable-static --enable-local-infile --with-unix-socket-path=/var/run/mysqld/my sqld.sock --with-mysqld-user=mysql --without-openssl --with-yassl --without-docs --without-bench --with-extra-charsets=all --without-innodb --without-embedded-s erver --without-ndb-sci --without-ndb-test --with-charset=utf8
libnss-mysql ./configure --prefix=/usr --sysconfdir=/etc/libnss --with-mysql=/usr
Debian上でpostfixでsaslを設定
目標 saslauthd を使わないで管理 BarklayDBはsaslpasswd2 -c ユーザID で /etc/sasldb2 が出来上がる chown postfix:sasl /etc/sasldb2 ln /etc/sasldb2 /var/spool/postfix/etc/sasldb2 でpostfix のchroot で動くディレクトリにハードリンクしておく
/etc/postfix/sasl ディレクトリにsmtpd.conf pwcheck_method: auxprop を記述することで上記BarklayDBで管理したsaslが可能になる。
さてここからMySQLの管理にするための設定 /etc/postfix/sasl ディレクトリにsmtpd.conf pwcheck_method: auxprop pwcheck_method: auxprop auxprop_plugin: sql allowanonymouslogin: no allowplaintext: yes mech_list: cram-md5 plain login sql_engine: mysql sql_user: sqluser ←任意 sql_passwd: saslsqlpass ←任意 sql_database: sasldb ←任意 sql_hostnames: localhost ←問題はココでした sql_select: SELECT
%pFROM user_table WHERE username = '%u' and realm = '%r' sql_verbose: yesと記述 データベースは mysqladmin create sasldb データベース作成 mysql sasldbとしてデータベースクライアント起動 CREATE TABLE
user_table(Noint(11) NOT NULL auto_increment,usernamevarchar(128) NOT NULL,realmvarchar(128) NOT NULL,userPasswordvarchar(128) default NULL,cmusaslsecretPLAINvarchar(128) default NULL,cmusaslsecretCRAM-MD5varchar(128) default NULL, PRIMARY KEY (No) ) ENGINE=MyISAM;insert
user_tablevalues (NULL,'testuser','testpass','testpass','testpass');とすることでpostfixにアクセスしてauth cram-md5 などして ユーザ認証できるはずなんですが、落とし穴がありました。 /etc/hosts には localhost があってきちんと認識してます。 でも、postfixのchroot環境ではこの限りでは無かったわけで warning: SASL authentication failure: no secret in database とmail.warn に記録されてます。 /var/spool/postfix/etc/hosts にもlocalhostは記述していたのですが、やはりうまくいきませんでした。 結局smtpd.confの記述を sql_hostnames: localhost ↓ sql_hostnames: 127.0.0.1 とすることで解決
これを見つける結果につながったのはsmtpd.conf に log_level: 5 とした時/var/log/auth.log に sql plugin try and connect to a host sql plugin trying to open db 'sasldb' on host 'localhost' sql plugin could not connect to host localhost sql plugin couldn't connect to any host と出てきたからでした。