Skip to content

Commit

Permalink
add user based vlimit feature
Browse files Browse the repository at this point in the history
01. vmoddomain.c: added -H method to configure hash method for domain
02. authindi.c, authpgsql.c, iauth.c, vchkpass.c, sql_getpw.c, vadduser.c, vmoduser.c: handle -1 return code for vget_limits()
03. indimail.h: re-arranged gid bit field masks
04. added print_limits() common function for inquerytest.c, vlimit.c
05. inquery.c, tcplookup.c, ProcessInFifo: Use INFIFODIR #define from inquery.h for infifo
06. inquery.h: define INFIFODIR for infifo
07. limits.c: fetch entry for domain when entry not found for user
08. vadduser.c, vmoduser.c, vsetuserquota.c: removed check for perms_defaultquota
09. vlimit.c: use print_limits() from print_limits.c to print domain limits information
10. vlimit.c: handle both domain and user level records
11. VlimitInLookup.c: return domain level record of user level record not found
12. vlimits.h: added limit_type member to vlimits sructure
13. ProcessInFifo.c: use vget_limits when argument is domain instead of email
  • Loading branch information
mbhangui committed May 28, 2024
1 parent decbc98 commit 7389fab
Show file tree
Hide file tree
Showing 28 changed files with 720 additions and 531 deletions.
1 change: 1 addition & 0 deletions indimail-x/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 155,7 @@ vhostid
vipmap
vlimit
vmoddomain
vmoddomain.1
vmoduser
vmoduser.1
vmoveuserdir
Expand Down
6 changes: 4 additions & 2 deletions indimail-x/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 83,7 @@ include_HEADERS = addaliasdomain.h add_control.h add_domain_assign.h addressToke
pipe_exec.h post_handle.h print_control.h ProcessInFifo.h proxylogin.h \
purge_files.h pwcomp.h PwdInLookup.h qmail_remote.h recalc_quota.h \
RelayInLookup.h relay_select.h RemoteBulkMail.h remove_line.h remove_quotes.h \
renameuser.h runcmmd.h SendWelcomeMail.h \
renameuser.h runcmmd.h SendWelcomeMail.h print_limits.h \
set_mysql_options.h setuserquota.h skip_relay.h \
skip_system_files.h sockwrite.h smtp_port.h spam.h sql_active.h sql_adddomain.h \
sql_adduser.h sql_delaliasdomain.h sql_deldomain.h sql_deluser.h sql_getall.h \
Expand Down Expand Up @@ -111,7 111,7 @@ COMMONSOURCES = addaliasdomain.c add_atrn_map.c add_control.c add_domain_assign.
CreateDomainDirs.c create_table.c dbinfoAdd.c dbinfoDel.c dbinfoSelect.c \
dbinfoUpdate.c dbload.c dec_dir_control.c del_atrn_map.c del_control.c \
del_domain_assign.c deldomain.c del_ip_map.c del_user_assign.c compat.c \
deluser.c delusercntrl.c fappend.c \
deluser.c delusercntrl.c fappend.c print_limits.c \
FifoCreate.c filewrt.c findhost.c findmdahost.c fstabChangeCounters.c \
getactualpath.c get_assign.c getDbLock.c \
get_indimailuidgid.c get_local_hostid.c get_local_ip.c get_localtime.c \
Expand Down Expand Up @@ -640,6 640,8 @@ vadduser.1: vadduser.9
$(editman) vadduser.9 > $@
vdeluser.1: vdeluser.9
$(editman) vdeluser.9 > $@
vmoddomain.1: vmoddomain.9
$(editman) vmoddomain.9 > $@
vrenamedomain.1: vrenamedomain.9
$(editman) vrenamedomain.9 > $@
vrenameuser.1: vrenameuser.9
Expand Down
147 changes: 83 additions & 64 deletions indimail-x/ProcessInFifo.c
Original file line number Diff line number Diff line change
@@ -1,65 1,5 @@
/*
* $Log: ProcessInFifo.c,v $
* Revision 1.20 2024-05-27 22:52:54 05:30 Cprogrammer
* initialize struct vlimits
*
* Revision 1.19 2024-05-17 16:25:48 05:30 mbhangui
* fix discarded-qualifier compiler warnings
*
* Revision 1.18 2023-06-08 17:48:50 05:30 Cprogrammer
* renamed fifo directory from FIFODIR to INFIFODIR.
*
* Revision 1.17 2023-04-09 11:57:57 05:30 Cprogrammer
* skip logging of binary search walk on SIGUSR1 (log only when debug is set)
*
* Revision 1.16 2023-04-08 23:46:28 05:30 Cprogrammer
* modified for qmailmrtg inlookup stats
*
* Revision 1.15 2023-03-20 10:16:03 05:30 Cprogrammer
* standardize getln handling
*
* Revision 1.14 2022-08-04 14:41:01 05:30 Cprogrammer
* fetch scram password
*
* Revision 1.13 2022-07-04 22:23:56 05:30 Cprogrammer
* fixed typo
*
* Revision 1.12 2021-07-28 12:19:56 05:30 Cprogrammer
* shortened display in logs on signal
*
* Revision 1.11 2021-07-27 18:10:43 05:30 Cprogrammer
* use getEnvConfigStr to set default domain
*
* Revision 1.10 2021-06-09 17:04:06 05:30 Cprogrammer
* BUG: Fixed read failing on fifo because of O_NDELAY flag
*
* Revision 1.9 2021-02-07 19:54:52 05:30 Cprogrammer
* respond to TCP/IP request when run under tcpserver
*
* Revision 1.8 2020-10-11 23:13:41 05:30 Cprogrammer
* replace deprecated sys_siglist with strsignal
*
* Revision 1.7 2020-10-01 18:27:59 05:30 Cprogrammer
* Darwin Port
*
* Revision 1.6 2020-09-17 14:48:15 05:30 Cprogrammer
* FreeBSD fix for missing tdestroy
*
* Revision 1.5 2020-04-01 18:57:29 05:30 Cprogrammer
* moved authentication functions to libqmail
*
* Revision 1.4 2019-05-28 17:41:50 05:30 Cprogrammer
* added load_mysql.h for mysql interceptor function prototypes
*
* Revision 1.3 2019-05-02 14:37:54 05:30 Cprogrammer
* added argument to specify a 'where clause'
*
* Revision 1.2 2019-04-22 23:18:33 05:30 Cprogrammer
* replaced exit with _exit
*
* Revision 1.1 2019-04-20 08:27:23 05:30 Cprogrammer
* Initial revision
*
* $Id: ProcessInFifo.c,v 1.21 2024-05-28 19:45:25 05:30 Cprogrammer Exp mbhangui $
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
Expand Down Expand Up @@ -135,9 75,10 @@
#include "get_assign.h"
#include "dbload.h"
#include "FifoCreate.h"
#include "inquery.h"

#ifndef lint
static char sccsid[] = "$Id: ProcessInFifo.c,v 1.20 2024-05-27 22:52:54 05:30 Cprogrammer Exp mbhangui $";
static char sccsid[] = "$Id: ProcessInFifo.c,v 1.21 2024-05-28 19:45:25 05:30 Cprogrammer Exp mbhangui $";
#endif

int user_query_count, relay_query_count, pwd_query_count, alias_query_count;
Expand Down Expand Up @@ -207,7 148,7 @@ getFifo_name()
if (!stralloc_copys(&inFifo, infifo) || !stralloc_0(&inFifo))
die_nomem();
} else {
getEnvConfigStr(&infifo_dir, "INFIFODIR", "/tmp/indimail/inlookup");
getEnvConfigStr(&infifo_dir, "INFIFODIR", INFIFODIR);
if (*infifo_dir == '/') {
if (indimailuid == -1 || indimailgid == -1)
get_indimailuidgid(&indimailuid, &indimailgid);
Expand Down Expand Up @@ -1461,7 1402,18 @@ ProcessInFifo(int instNum)
break;
#ifdef ENABLE_DOMAIN_LIMITS
case LIMIT_QUERY:
if ((status = VlimitInLookup(email, &limits)) == -1)
i = str_rchr(email, '@');
if (!email[i]) {
status = vget_limits(email, &limits);
if (!status)
status = 1;
else
if (status > 0)
status = 0;
} else
status = VlimitInLookup(email, &limits);

if (status == -1)
bytes = -1;
else
if (status) /*- user not found */
Expand Down Expand Up @@ -1521,3 1473,70 @@ ProcessInFifo(int instNum)
signal(SIGPIPE, pstat);
return (1);
}
/*
* $Log: ProcessInFifo.c,v $
* Revision 1.21 2024-05-28 19:45:25 05:30 Cprogrammer
* Use INFIFODIR #define from inquery.h for infifo
* use vget_limits when argument is domain instead of email
*
* Revision 1.20 2024-05-27 22:52:54 05:30 Cprogrammer
* initialize struct vlimits
*
* Revision 1.19 2024-05-17 16:25:48 05:30 mbhangui
* fix discarded-qualifier compiler warnings
*
* Revision 1.18 2023-06-08 17:48:50 05:30 Cprogrammer
* renamed fifo directory from FIFODIR to INFIFODIR.
*
* Revision 1.17 2023-04-09 11:57:57 05:30 Cprogrammer
* skip logging of binary search walk on SIGUSR1 (log only when debug is set)
*
* Revision 1.16 2023-04-08 23:46:28 05:30 Cprogrammer
* modified for qmailmrtg inlookup stats
*
* Revision 1.15 2023-03-20 10:16:03 05:30 Cprogrammer
* standardize getln handling
*
* Revision 1.14 2022-08-04 14:41:01 05:30 Cprogrammer
* fetch scram password
*
* Revision 1.13 2022-07-04 22:23:56 05:30 Cprogrammer
* fixed typo
*
* Revision 1.12 2021-07-28 12:19:56 05:30 Cprogrammer
* shortened display in logs on signal
*
* Revision 1.11 2021-07-27 18:10:43 05:30 Cprogrammer
* use getEnvConfigStr to set default domain
*
* Revision 1.10 2021-06-09 17:04:06 05:30 Cprogrammer
* BUG: Fixed read failing on fifo because of O_NDELAY flag
*
* Revision 1.9 2021-02-07 19:54:52 05:30 Cprogrammer
* respond to TCP/IP request when run under tcpserver
*
* Revision 1.8 2020-10-11 23:13:41 05:30 Cprogrammer
* replace deprecated sys_siglist with strsignal
*
* Revision 1.7 2020-10-01 18:27:59 05:30 Cprogrammer
* Darwin Port
*
* Revision 1.6 2020-09-17 14:48:15 05:30 Cprogrammer
* FreeBSD fix for missing tdestroy
*
* Revision 1.5 2020-04-01 18:57:29 05:30 Cprogrammer
* moved authentication functions to libqmail
*
* Revision 1.4 2019-05-28 17:41:50 05:30 Cprogrammer
* added load_mysql.h for mysql interceptor function prototypes
*
* Revision 1.3 2019-05-02 14:37:54 05:30 Cprogrammer
* added argument to specify a 'where clause'
*
* Revision 1.2 2019-04-22 23:18:33 05:30 Cprogrammer
* replaced exit with _exit
*
* Revision 1.1 2019-04-20 08:27:23 05:30 Cprogrammer
* Initial revision
*
*/
35 changes: 22 additions & 13 deletions indimail-x/VlimitInLookup.c
Original file line number Diff line number Diff line change
@@ -1,5 1,8 @@
/*
* $Log: VlimitInLookup.c,v $
* Revision 1.4 2024-05-28 19:34:57 05:30 Cprogrammer
* return domain level record of user level record not found
*
* Revision 1.3 2024-05-27 22:53:54 05:30 Cprogrammer
* initialize struct vlimits
*
Expand All @@ -15,7 18,7 @@
#endif

#ifndef lint
static char sccsid[] = "$Id: VlimitInLookup.c,v 1.3 2024-05-27 22:53:54 05:30 Cprogrammer Exp mbhangui $";
static char sccsid[] = "$Id: VlimitInLookup.c,v 1.4 2024-05-28 19:34:57 05:30 Cprogrammer Exp mbhangui $";
#endif

#ifdef ENABLE_DOMAIN_LIMITS
Expand All @@ -36,14 39,14 @@ static char sccsid[] = "$Id: VlimitInLookup.c,v 1.3 2024-05-27 22:53:54 05:3
#include "variables.h"
#include "vlimits.h"

static struct vlimits limits = { 0 };

int
VlimitInLookup(const char *email, struct vlimits *lim)
{
static stralloc user = {0}, domain = {0};
const char *real_domain;
#ifdef ENABLE_DOMAIN_LIMITS
struct vlimits limits = { 0 };
#endif
int r;

#ifdef CLUSTERED_SITE
if (sqlOpen_user(email, 1))
Expand All @@ -52,18 55,24 @@ VlimitInLookup(const char *email, struct vlimits *lim)
#endif
{
if(userNotFound)
return(1);
return 1;
else
return(-1);
return -1;
}
parse_email(email, &user, &domain);
if (!(real_domain = get_real_domain(domain.s)))
real_domain = domain.s;
if (vget_limits(real_domain, &limits)) {
strerr_warn3("VlimitInLookup: ", real_domain, ": failed to get domain limits", 0);
return (-1);
if ((r = vget_limits(email, &limits)) == -1) {
strerr_warn3("VlimitInLookup: ", email, ": failed to get domain limits", 0);
return -1;
} else
if (!r) {
parse_email(email, &user, &domain);
if (!(real_domain = get_real_domain(domain.s)))
real_domain = domain.s;
if (vget_limits(real_domain, &limits) == -1) {
strerr_warn3("VlimitInLookup: ", real_domain, ": failed to get domain limits", 0);
return -1;
}
}
*lim = limits;
return (0);
return 0;
}
#endif
11 changes: 7 additions & 4 deletions indimail-x/authindi.c
Original file line number Diff line number Diff line change
@@ -1,5 1,5 @@
/*
* $Id: authindi.c,v 1.20 2024-05-27 22:50:29 05:30 Cprogrammer Exp mbhangui $
* $Id: authindi.c,v 1.21 2024-05-28 19:13:20 05:30 Cprogrammer Exp mbhangui $
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
Expand Down Expand Up @@ -57,7 57,7 @@
#define WARN "authindi: warn: "

#ifndef lint
static char sccsid[] = "$Id: authindi.c,v 1.20 2024-05-27 22:50:29 05:30 Cprogrammer Exp mbhangui $";
static char sccsid[] = "$Id: authindi.c,v 1.21 2024-05-28 19:13:20 05:30 Cprogrammer Exp mbhangui $";
#endif

static stralloc tmpbuf = {0};
Expand Down Expand Up @@ -653,15 653,15 @@ main(int argc, char **argv)
struct vlimits *lmt;
#ifdef QUERY_CACHE
if (!env_get("QUERY_CACHE")) {
if (vget_limits(real_domain, &limits)) {
if (vget_limits(real_domain, &limits) == -1) {
strerr_warn3(FATAL, "unable to get domain limits for for ", real_domain, 0);
failure1(argv, auth_method, service, imapargs, pop3args, authstr, 0);
}
lmt = &limits;
} else
lmt = inquery(LIMIT_QUERY, login, 0);
#else
if (vget_limits(real_domain, &limits)) {
if (vget_limits(real_domain, &limits) == -1) {
strerr_warn3(FATAL, "unable to get domain limits for for ", real_domain, 0);
failure1(argv, auth_method, service, imapargs, pop3args, authstr, 0);
}
Expand All @@ -684,6 684,9 @@ main(int argc, char **argv)

/*
* $Log: authindi.c,v $
* Revision 1.21 2024-05-28 19:13:20 05:30 Cprogrammer
* handle -1 return code for vget_limits()
*
* Revision 1.20 2024-05-27 22:50:29 05:30 Cprogrammer
* initialize struct vlimits
*
Expand Down
15 changes: 9 additions & 6 deletions indimail-x/authpgsql.c
Original file line number Diff line number Diff line change
@@ -1,5 1,8 @@
/*
* $Log: authpgsql.c,v $
* Revision 1.12 2024-05-28 19:14:12 05:30 Cprogrammer
* handle -1 return code for vget_limits()
*
* Revision 1.11 2024-05-27 22:51:10 05:30 Cprogrammer
* initialize struct vlimits
*
Expand Down Expand Up @@ -76,7 79,7 @@
#include "runcmmd.h"

#ifndef lint
static char sccsid[] = "$Id: authpgsql.c,v 1.11 2024-05-27 22:51:10 05:30 Cprogrammer Exp mbhangui $";
static char sccsid[] = "$Id: authpgsql.c,v 1.12 2024-05-28 19:14:12 05:30 Cprogrammer Exp mbhangui $";
#endif

#ifdef HAVE_PGSQL
Expand Down Expand Up @@ -177,10 180,10 @@ pg_getpw(char *user, char *domain)
pwent.pw_shell = IShell.s;
#ifdef ENABLE_DOMAIN_LIMITS
if (env_get("DOMAIN_LIMITS") && !(pwent.pw_gid & V_OVERRIDE)) {
if (!vget_limits(domain, &limits))
pwent.pw_gid |= vlimits_get_flag_mask(&limits);
else
if (vget_limits(domain, &limits) == -1)
return ((struct passwd *) 0);
else
pwent.pw_gid |= vlimits_get_flag_mask(&limits);
}
#endif
return (&pwent);
Expand Down Expand Up @@ -335,7 338,7 @@ main(int argc, char **argv)
struct vlimits *lmt;
#ifdef QUERY_CACHE
if (!env_get("QUERY_CACHE")) {
if (vget_limits(domain.s, &limits)) {
if (vget_limits(domain.s, &limits) == -1) {
strerr_warn2("authpgsql: unable to get domain limits for for ", domain.s, 0);
subprintfe(subfdout, "authpgsql", "454-unable to get domain limits for %s (#4.3.0)\r\n", domain.s);
flush("authpgsql");
Expand All @@ -345,7 348,7 @@ main(int argc, char **argv)
} else
lmt = inquery(LIMIT_QUERY, login, 0);
#else
if (vget_limits(domain.s, &limits)) {
if (vget_limits(domain.s, &limits) == -1) {
strerr_warn2("authpgsql: unable to get domain limits for for ", domain.s, 0);
subprintfe(subfdout, "authpgsql", "454-unable to get domain limits for %s (#4.3.0)\r\n", domain.s);
flush("authpgsql");
Expand Down
15 changes: 15 additions & 0 deletions indimail-x/doc/ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 30,21 @@ Release @version@-@release@ Start 02/05/2024 End XX/XX/XXXX
19. vlimit.c: fixed data types
20. inquerytest: change data type to long
21. vadduser.c: fix .domain_limits path
22. vmoddomain.c: added -H method to configure hash method for domain
23. authindi.c, authpgsql.c, iauth.c, vchkpass.c, sql_getpw.c, vadduser.c,
vmoduser.c: handle -1 return code for vget_limits()
24. indimail.h: re-arranged gid bit field masks
25. added print_limits() common function for inquerytest.c, vlimit.c
26. inquery.c, tcplookup.c, ProcessInFifo: Use INFIFODIR #define from inquery.h for infifo
27. inquery.h: define INFIFODIR for infifo
28. limits.c: fetch entry for domain when entry not found for user
29. vadduser.c, vmoduser.c, vsetuserquota.c: removed check for perms_defaultquota
30. vlimit.c: use print_limits() from print_limits.c to print domain limits
information
31. vlimit.c: handle both domain and user level records
32. VlimitInLookup.c: return domain level record of user level record not found
33. vlimits.h: added limit_type member to vlimits sructure
34. ProcessInFifo.c: use vget_limits when argument is domain instead of email

* Mon Jan 01 2024 09:24:41 0000 Manvendra Bhangui <[email protected]> 3.4.6-1.1%{?dist}
Release 3.4.6-1.1 Start 09/09/2023 End 01/01/2024
Expand Down
Loading

0 comments on commit 7389fab

Please sign in to comment.