Skip to content

Commit

Permalink
refactor qmulti.c
Browse files Browse the repository at this point in the history
1. do_scan.c, generic.c, getqueue.c, mailfilter.c, qhpsi.c,
   qmail-qmqpc.c: replace hard-coded exit values with constants from qmail.h
2. qmulti.c: unset env variables queue_env, QUEUEPROG to prevent recursion
3. qmulti.c: refactored code to handle qmail-queue consistently
  • Loading branch information
mbhangui committed Oct 28, 2023
1 parent 4827b2e commit 9919455
Show file tree
Hide file tree
Showing 17 changed files with 701 additions and 678 deletions.
21 changes: 10 additions & 11 deletions indimail-mta-x/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ load qhpsi.o auto_qmail.o get_uid.o auto_uids.o
./load qhpsi auto_qmail.o get_uid.o auto_uids.o \
-ldl $(QMAILLIB)

qhpsi.o: compile qhpsi.c auto_qmail.h auto_uids.h
qhpsi.o: compile qhpsi.c auto_qmail.h auto_uids.h qmail.h
./compile qhpsi.c

qscanq: load qscanq.o auto_uids.o get_uid.o \
Expand Down Expand Up @@ -871,7 +871,8 @@ conf-servicedir
custom_error.o: compile custom_error.c qmail.h
./compile custom_error.c
getqueue.o: \
compile getqueue.c getqueue.h haslibrt.h custom_error.h conf-queue
compile getqueue.c getqueue.h haslibrt.h custom_error.h \
qmail.h conf-queue
./compile `grep -h -v "^#" conf-queue` getqueue.c

qscanq-stdin: load qscanq-stdin.o auto_qmail.o \
Expand All @@ -894,7 +895,7 @@ do_ripmime.o: compile do_ripmime.c exitcodes.h
./compile do_ripmime.c

do_scan.o: compile do_scan.c exitcodes.h qregex.h control.h \
variables.h auto_control.h
variables.h auto_control.h qmail.h
./compile do_scan.c

auto_ripmime_cmd.c: auto-strarr conf-ripmime-cmd
Expand Down Expand Up @@ -1073,9 +1074,10 @@ variables.o set_environment.o auto_qmail.o auto_prefix.o srs.lib
set_environment.o $(static_option) $(QMAILLIB) \
-L../libsrs2-x/libsrs2/.libs `cat srs.lib` $(dynamic_option)

qmail-inject.8: qmail-inject.9 conf-prefix conf-sysconfdir
qmail-inject.8: qmail-inject.9 conf-prefix conf-qmail conf-sysconfdir
cat qmail-inject.9 \
| sed s}PREFIX}"`head -1 conf-prefix`"}g \
| sed s}HOME}"`head -1 conf-qmail`"}g \
| sed s}@controldir\@}"`head -1 conf-sysconfdir`/control"}g \
> qmail-inject.8

Expand Down Expand Up @@ -1257,8 +1259,8 @@ auto_control.o socket.lib

qmail-qmqpc.o: \
compile qmail-qmqpc.c auto_control.h slurpclose.h ip.h \
timeoutconn.h control.h variables.h \
haveip6.h socket.h conf-ip
timeoutconn.h control.h variables.h qmail.h socket.h \
haveip6.h conf-ip
./compile `grep -h -v "^#" conf-ip` qmail-qmqpc.c

qmail-qmqpd: \
Expand Down Expand Up @@ -1326,10 +1328,7 @@ compile qmail-multi.c qmulti.h qmail.h mailfilter.h conf-queue

qmail-multi.8: \
qmail-multi.9 conf-prefix conf-qmail
cat qmail-multi.9 \
| sed s}QMAILHOME}"`head -1 conf-qmail`"}g \
| sed s}PREFIX}"`head -1 conf-prefix`"}g \
> qmail-multi.8
$(edit) qmail-multi.9 > qmail-multi.8

qmail-spamfilter: load qmail-spamfilter.o qmulti.o \
auto_prefix.o auto_qmail.o auto_control.o control.o \
Expand Down Expand Up @@ -3286,7 +3285,7 @@ sortedtest: load sortedtest.o sorted.o
sortedtest.o: compile sortedtest.c sorted.h
./compile sortedtest.c

generic.o: compile generic.c
generic.o: compile generic.c qmail.h
./compile generic.c

relaytest.o: compile relaytest.c
Expand Down
136 changes: 72 additions & 64 deletions indimail-mta-x/do_scan.c
Original file line number Diff line number Diff line change
@@ -1,63 +1,5 @@
/*
* $Log: do_scan.c,v $
* Revision 1.19 2021-08-29 23:27:08+05:30 Cprogrammer
* define functions as noreturn
*
* Revision 1.18 2021-06-15 11:32:24+05:30 Cprogrammer
* remove creation of link for /etc/indimail/control in scanq directory
*
* Revision 1.17 2021-06-09 19:34:19+05:30 Cprogrammer
* added makeargs.h
*
* Revision 1.16 2020-04-01 16:13:35+05:30 Cprogrammer
* added header for makeargs() function
*
* Revision 1.15 2018-05-18 17:39:05+05:30 Cprogrammer
* BUG - break out of loop if file extension matches a line in badext
*
* Revision 1.14 2018-05-11 14:37:51+05:30 Cprogrammer
* BUG - fixed prohibited extensions scanning
*
* Revision 1.13 2016-05-17 19:44:58+05:30 Cprogrammer
* use auto_control, set by conf-control to set control directory
*
* Revision 1.12 2009-05-01 10:38:48+05:30 Cprogrammer
* change for errstr argument to address_match()
*
* Revision 1.11 2009-04-29 21:03:17+05:30 Cprogrammer
* check address_match() for failure
*
* Revision 1.10 2009-04-29 08:59:07+05:30 Cprogrammer
* change for cdb argument to address_match()
*
* Revision 1.9 2009-04-29 08:24:03+05:30 Cprogrammer
* change for address_match() function
*
* Revision 1.8 2008-08-03 18:25:33+05:30 Cprogrammer
* use proper proto
*
* Revision 1.7 2007-12-20 13:54:42+05:30 Cprogrammer
* removed compilation warning
*
* Revision 1.6 2005-02-18 17:54:30+05:30 Cprogrammer
* Facility to specify name of scanned file by %s in SCANCMD env variable
*
* Revision 1.5 2004-10-22 20:24:40+05:30 Cprogrammer
* added RCS id
*
* Revision 1.4 2004-09-27 15:30:26+05:30 Cprogrammer
* moved env_unset("VIRUSCHECK") to qmail-multi.c
*
* Revision 1.3 2004-09-23 22:54:44+05:30 Cprogrammer
* corrected problem with permissions
*
* Revision 1.2 2004-09-22 22:24:55+05:30 Cprogrammer
* added SCANCMD to select virus scanner
* add code to reject bad attachments
*
* Revision 1.1 2004-09-20 11:08:52+05:30 Cprogrammer
* Initial revision
*
* $Id: do_scan.c,v 1.20 2023-10-27 16:10:57+05:30 Cprogrammer Exp mbhangui $
*/
#include <sys/types.h>
#include <unistd.h>
Expand All @@ -71,6 +13,7 @@
#include <str.h>
#include <makeargs.h>
#include <noreturn.h>
#include "qmail.h"
#include "control.h"
#include "qregex.h"
#include "exitcodes.h"
Expand All @@ -90,13 +33,13 @@ static stralloc brp = { 0 };
no_return void
die_nomem()
{
_exit(51);
_exit(QQ_OUT_OF_MEMORY);
}

no_return void
die_control()
{
_exit(55);
_exit(QQ_CONFIG_ERR);
}

no_return void
Expand All @@ -117,7 +60,7 @@ scan_badattachments(char *dir_name)
if (!dir_name || !*dir_name)
return (0);
if (!(dir = opendir(dir_name)))
die(61);
die(QQ_CHDIR);
if ((extok = control_readfile(&ext, (x = env_get("BADEXT")) && *x ? x : "badext", 0)) == -1)
die_control();
if (extok && !constmap_init(&mapext, ext.s, ext.len, 0))
Expand Down Expand Up @@ -200,7 +143,7 @@ do_scan()
close(1); /*- Don't let it fiddle with envelope */
if ((ptr = env_get("SCANCMD"))) {
if (!(scancmd = makeargs(ptr)))
_exit(51);
_exit(QQ_OUT_OF_MEMORY);
for (i = 1;scancmd[i];i++) {
if (!str_diffn(scancmd[i], "%s", 2))
scancmd[i] = ".";
Expand Down Expand Up @@ -236,9 +179,74 @@ do_scan()
void
getversion_do_scan_c()
{
static char *x = "$Id: do_scan.c,v 1.19 2021-08-29 23:27:08+05:30 Cprogrammer Exp mbhangui $";
static char *x = "$Id: do_scan.c,v 1.20 2023-10-27 16:10:57+05:30 Cprogrammer Exp mbhangui $";

x = sccsidmakeargsh;
x++;
}
#endif

/*
* $Log: do_scan.c,v $
* Revision 1.20 2023-10-27 16:10:57+05:30 Cprogrammer
* replace hard-coded exit values with constants from qmail.h
*
* Revision 1.19 2021-08-29 23:27:08+05:30 Cprogrammer
* define functions as noreturn
*
* Revision 1.18 2021-06-15 11:32:24+05:30 Cprogrammer
* remove creation of link for /etc/indimail/control in scanq directory
*
* Revision 1.17 2021-06-09 19:34:19+05:30 Cprogrammer
* added makeargs.h
*
* Revision 1.16 2020-04-01 16:13:35+05:30 Cprogrammer
* added header for makeargs() function
*
* Revision 1.15 2018-05-18 17:39:05+05:30 Cprogrammer
* BUG - break out of loop if file extension matches a line in badext
*
* Revision 1.14 2018-05-11 14:37:51+05:30 Cprogrammer
* BUG - fixed prohibited extensions scanning
*
* Revision 1.13 2016-05-17 19:44:58+05:30 Cprogrammer
* use auto_control, set by conf-control to set control directory
*
* Revision 1.12 2009-05-01 10:38:48+05:30 Cprogrammer
* change for errstr argument to address_match()
*
* Revision 1.11 2009-04-29 21:03:17+05:30 Cprogrammer
* check address_match() for failure
*
* Revision 1.10 2009-04-29 08:59:07+05:30 Cprogrammer
* change for cdb argument to address_match()
*
* Revision 1.9 2009-04-29 08:24:03+05:30 Cprogrammer
* change for address_match() function
*
* Revision 1.8 2008-08-03 18:25:33+05:30 Cprogrammer
* use proper proto
*
* Revision 1.7 2007-12-20 13:54:42+05:30 Cprogrammer
* removed compilation warning
*
* Revision 1.6 2005-02-18 17:54:30+05:30 Cprogrammer
* Facility to specify name of scanned file by %s in SCANCMD env variable
*
* Revision 1.5 2004-10-22 20:24:40+05:30 Cprogrammer
* added RCS id
*
* Revision 1.4 2004-09-27 15:30:26+05:30 Cprogrammer
* moved env_unset("VIRUSCHECK") to qmail-multi.c
*
* Revision 1.3 2004-09-23 22:54:44+05:30 Cprogrammer
* corrected problem with permissions
*
* Revision 1.2 2004-09-22 22:24:55+05:30 Cprogrammer
* added SCANCMD to select virus scanner
* add code to reject bad attachments
*
* Revision 1.1 2004-09-20 11:08:52+05:30 Cprogrammer
* Initial revision
*
*/
7 changes: 6 additions & 1 deletion indimail-mta-x/doc/ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@ Release 3.0.6-1.1 Start 25/10/2023 End XX/XX/XXXX
08. create_services.in: added --setuser-priv option for slowq service
09. autoresponder.c, indimail-spamfilter.c: rewind descriptor 0 regardless of
MAKE_SEEKABLE setting
- 25/10/2023
- 26/10/2023
10. qmail-spamfilter.c: added HAMEXITCODE, UNSUREEXITCODE
11. qmail-spamfilter.c: Fixed working of globalspamredirect + REJECTSPAM
- 27/10/2023
12. do_scan.c, generic.c, getqueue.c, mailfilter.c, qhpsi.c,
qmail-qmqpc.c: replace hard-coded exit values with constants from qmail.h
13. qmulti.c: unset env variables queue_env, QUEUEPROG to prevent recursion
14. qmulti.c: refactored code to handle qmail-queue consistently

* Tue Oct 17 2023 18:34:04 +0000 Manvendra Bhangui <indimail-mta@indimail.org> 3.0.5-1.1%{?dist}
Release 3.0.5-1.1 Start 11/09/2023 End 17/10/2023
Expand Down
58 changes: 33 additions & 25 deletions indimail-mta-x/generic.c
Original file line number Diff line number Diff line change
@@ -1,30 +1,13 @@
/*
* $Log: generic.c,v $
* Revision 1.6 2021-08-29 23:27:08+05:30 Cprogrammer
* define functions as noreturn
*
* Revision 1.5 2021-06-15 11:36:51+05:30 Cprogrammer
* moved makeargs.h to libqmail
*
* Revision 1.4 2020-04-01 16:13:40+05:30 Cprogrammer
* added header for makeargs() function
*
* Revision 1.3 2009-04-30 16:14:55+05:30 Cprogrammer
* removed hasindimail.h
*
* Revision 1.2 2007-12-20 12:44:08+05:30 Cprogrammer
* removed compiler warning
*
* Revision 1.1 2005-06-15 22:11:23+05:30 Cprogrammer
* Initial revision
*
* $Id: generic.c,v 1.7 2023-10-27 16:11:04+05:30 Cprogrammer Exp mbhangui $
*/
#include <unistd.h>
#include <str.h>
#include <env.h>
#include <wait.h>
#include <makeargs.h>
#include <noreturn.h>
#include "qmail.h"

extern char *auto_scancmd[];

Expand All @@ -40,11 +23,11 @@ virusscan(char *messfn)
switch (child = fork())
{
case -1:
_exit(121);
_exit(QQ_FORK_ERR);
case 0:
if ((ptr = env_get("SCANCMD"))) {
if (!(argv = makeargs(ptr)))
_exit(51);
_exit(QQ_OUT_OF_MEMORY);
} else
argv = auto_scancmd;
if (!argv[1]) {
Expand All @@ -60,22 +43,47 @@ virusscan(char *messfn)
execvp(*argv, argv);
else
execv(*argv, argv);
_exit(75);
_exit(QQ_EXEC_FAILED);
}
if (wait_pid(&wstat, child) == -1)
_exit(122);
_exit(QQ_WAITPID_SURPRISE);
if (wait_crashed(wstat))
_exit(123);
_exit(QQ_CRASHED);
_exit(wait_exitcode(wstat));
}

#ifndef lint
void
getversion_generic_c()
{
static char *x = "$Id: generic.c,v 1.6 2021-08-29 23:27:08+05:30 Cprogrammer Exp mbhangui $";
static char *x = "$Id: generic.c,v 1.7 2023-10-27 16:11:04+05:30 Cprogrammer Exp mbhangui $";

x = sccsidmakeargsh;
x++;
}
#endif

/*
* $Log: generic.c,v $
* Revision 1.7 2023-10-27 16:11:04+05:30 Cprogrammer
* replace hard-coded exit values with constants from qmail.h
*
* Revision 1.6 2021-08-29 23:27:08+05:30 Cprogrammer
* define functions as noreturn
*
* Revision 1.5 2021-06-15 11:36:51+05:30 Cprogrammer
* moved makeargs.h to libqmail
*
* Revision 1.4 2020-04-01 16:13:40+05:30 Cprogrammer
* added header for makeargs() function
*
* Revision 1.3 2009-04-30 16:14:55+05:30 Cprogrammer
* removed hasindimail.h
*
* Revision 1.2 2007-12-20 12:44:08+05:30 Cprogrammer
* removed compiler warning
*
* Revision 1.1 2005-06-15 22:11:23+05:30 Cprogrammer
* Initial revision
*
*/
Loading

0 comments on commit 9919455

Please sign in to comment.