Hello all,
Although i am not very well at writing c code, i have created patch that checks if user has available quota during chkuser check.
Works perfect for me.
Please review and if you find it useful, include for next release.
All suggestions and corrections are always welcome.
Patches are included as an attachment and also available at
http://www.ahmetyazici.org/qv/qmail-chkuserx.patch http://www.ahmetyazici.org/qv/vpopmail-5.4.5.patch
Thank you.
Ahmet YAZICI
--- edited-netqmail-1.05/qmail-smtpd.c.orig 2004-07-06 09:35:34.000000000 +0300 +++ edited-netqmail-1.05/qmail-smtpd.c 2004-07-06 11:38:34.000000000 +0300 @@ -119,6 +119,8 @@ int err_authabrt() { out("501 auth exchange canceled (#5.0.0)\r\n"); return -1; } int err_input() { out("501 malformed auth input (#5.5.4)\r\n"); return -1; } void err_authfail() { out("535 authentication failed (#5.7.1)\r\n"); } +void err_realrcpt() { out("550 sorry, no mailbox here by that name (#5.1.1 - chkusrx)\r\n"); } +void err_quotawarn() { out("454 sorry, user is over quota. (#4.3.0 - chkusrx)\r\n"); } stralloc greeting = {0}; @@ -319,7 +321,6 @@ return 0; } -void err_realrcpt() { out("550 sorry, no mailbox here by that name (#5.1.1 - chkusr)\r\n"); } int realrcpt_check() { @@ -341,8 +342,6 @@ /* if not local rcpthost we cannot control mailbox */ - if (!addrallowed()) { return 1; } - /* Set up our variables */ /* Search the '@' character */ @@ -432,18 +431,26 @@ ++count; } } - } - if (user_passwd != NULL) { - - /* If user exists check if he has BOUNCE_MAIL flag set */ - if (user_passwd->pw_gid & BOUNCE_MAIL) - retstat = 0; - else - retstat = 1; - break; - } + } + if (user_passwd != NULL) { + if (user_passwd->pw_gid & BOUNCE_MAIL) { + retstat = 0; + } else { + + char axv13[300]; + snprintf(axv13,300, "%s/Maildir/", user_passwd->pw_dir); + if (strncmp(user_passwd->pw_shell, "NOQUOTA", 2) != 0 ) { + if (user_over_maildirquota_local(axv13,format_maildirquota(user_passwd->pw_shell)) == 1){ + retstat = 2; + break; + } + } + return 1; + break; + } + } case 2: /* Check for aliases/forwards - valias*/ @@ -494,13 +501,13 @@ break; } } - + /* * Add this code if another case is following - if (retstat == 1) - break; + if (retstat == 1) + break; */ - + } /* end switch */ return retstat; @@ -605,8 +612,18 @@ if (!stralloc_0(&addr)) die_nomem(); } else - if (!addrallowed()) { err_nogateway(); return; } - if (!realrcpt_check()) { err_realrcpt(); return; } + if (!addrallowed()) { err_nogateway(); return; } + + int chkuser_x; + chkuser_x = realrcpt_check(); + if (!chkuser_x) { + err_realrcpt(); + return; + } else if (chkuser_x == 2 ) { + err_quotawarn(); + return; + } + if (!stralloc_cats(&rcptto,"T")) die_nomem(); if (!stralloc_cats(&rcptto,addr.s)) die_nomem(); if (!stralloc_0(&rcptto)) die_nomem(); @@ -1240,3 +1257,4 @@ if (commands(&ssin,&smtpcommands) == 0) die_read(); die_nomem(); } +
diff -Nur vpopmail-5.4.5/maildirquota.c edited-vpopmail-5.4.5/maildirquota.c --- vpopmail-5.4.5/maildirquota.c 2003-12-19 07:16:36.000000000 +0200 +++ edited-vpopmail-5.4.5/maildirquota.c 2004-07-06 09:20:42.000000000 +0300 @@ -276,6 +276,22 @@ return(ret_value); } +int user_over_maildirquota_local( const char *dir, const char *q) +{ +int quotafd; +int ret_value; + + if (maildir_checkquota(dir, "afd, q,1,1) && errno != EAGAIN) + { + if (quotafd >= 0) close(quotafd); + ret_value = 1; + } else { + ret_value = 0; + } + + return(ret_value); +} + void add_warningsize_to_quota( const char *dir, const char *q) { struct stat stat_buf; diff -Nur vpopmail-5.4.5/maildirquota.h edited-vpopmail-5.4.5/maildirquota.h --- vpopmail-5.4.5/maildirquota.h 2003-10-20 21:59:57.000000000 +0300 +++ edited-vpopmail-5.4.5/maildirquota.h 2004-07-06 09:20:11.000000000 +0300 @@ -16,6 +16,7 @@ int readuserquota(const char* dir, long *sizep, int *cntp); int domain_over_maildirquota(const char *userdir); int user_over_maildirquota(const char *dir, const char *quota); +int user_over_maildirquota_local(const char *dir, const char *quota); void add_warningsize_to_quota( const char *dir, const char *quota); int vmaildir_readquota(const char *dir, const char *quota);