cmd5checkpwでログ吐き
qmailでsmtp認証をしたいと思ってごにょごにょしていたのだが,daemontoolsを使わないでも認証時のログを残したいと思いcmd5checkpwに認証ログをはいてもらうようにしてみた.
cmd5checkpw-syslog.patch
diff -u cmd5checkpw-0.22.old/main.c cmd5checkpw-0.22/main.c --- cmd5checkpw-0.22.old/main.c 2000-10-09 18:07:21.000000000 +0900 +++ cmd5checkpw-0.22/main.c 2006-10-03 12:20:14.000000000 +0900 @@ -4,14 +4,27 @@ #include <errno.h> #include <pwd.h> #include <stdio.h> +#include <envz.h> #include <unistd.h> +#include <syslog.h> #define LINE_MAX 256 -#define SMTP_PASSWD_FILE "/etc/poppasswd" +#define SMTP_PASSWD_FILE "/etc/smtppasswd" +#define SYSLOG_IDENT "submissiond" char up[513]; int uplen; static char hextab[]="0123456789abcdef"; +void syslog_entry(int accepted, const unsigned char *login, const unsigned char *ip, const unsigned char *auth){ + openlog(SYSLOG_IDENT, LOG_NOWAIT | LOG_PID, LOG_MAIL); + if(accepted){ + syslog(LOG_WARNING, "[%s]: [%s]Authentication Failure; User:%s", ip, auth, login); + }else{ + syslog(LOG_INFO, "[%s]: [%s]Authentication Success; User:%s", ip, auth, login); + } + closelog(); +} + int doit(unsigned char *testlogin, unsigned char *challenge, unsigned char *response) { static char line[LINE_MAX + 1]; @@ -56,14 +69,19 @@ return(strcmp(digascii,response) && strcmp(password,challenge)); } -void main(int argc,char **argv) +void main(int argc,char **argv, char *envp[]) { char *login; char *response; char *challenge; + char *ip; + char *auth; + int r; int i; + int j; int accepted; + int env_len = 0; if (!argv[1]) _exit(2); @@ -89,6 +107,17 @@ response = up + i; accepted=doit(login,challenge,response); + + for(j=0; envp[j] != NULL; j++) + env_len += strlen(envp[j]) + 1; + + ip = envz_get(*envp, env_len, "TCPREMOTEIP"); + if(!ip) ip = "unknown"; + + auth = envz_get(*envp, env_len, "AUTH"); + if(!auth) auth = "unknown"; + + syslog_entry(accepted, login, ip, auth); for (i = 0;i < sizeof(up);++i) up[i] = 0;
ないよりはましか・・・#daemontools使えって感じかな