diff --git a/indimail-x/add_control.c b/indimail-x/add_control.c index 26654f137..cc43b4164 100644 --- a/indimail-x/add_control.c +++ b/indimail-x/add_control.c @@ -134,7 +134,7 @@ add_control(char *domain, char *target) if (remove_line(domain, filename.s, 0, INDIMAIL_QMAIL_MODE) == -1) return (-1); if (use_etrn) { - /*- Add to etrndomains file and remove duplicates and set mode */ + /*- Add to etrnhosts file and remove duplicates and set mode */ if (relative) { if (!stralloc_copys(&filename, sysconfdir) || !stralloc_append(&filename, "/") || diff --git a/indimail-x/add_domain_assign.c b/indimail-x/add_domain_assign.c index e353cff35..07cd24c69 100644 --- a/indimail-x/add_domain_assign.c +++ b/indimail-x/add_domain_assign.c @@ -1,5 +1,8 @@ /* * $Log: add_domain_assign.c,v $ + * Revision 1.5 2023-12-03 15:38:52+05:30 Cprogrammer + * use same logic for ETRN, ATRN domains + * * Revision 1.4 2023-03-22 07:59:53+05:30 Cprogrammer * BUG - set uid, gid variables before creating assign file * @@ -36,7 +39,7 @@ #include "variables.h" #ifndef lint -static char sccsid[] = "$Id: add_domain_assign.c,v 1.4 2023-03-22 07:59:53+05:30 Cprogrammer Exp mbhangui $"; +static char sccsid[] = "$Id: add_domain_assign.c,v 1.5 2023-12-03 15:38:52+05:30 Cprogrammer Exp mbhangui $"; #endif static void @@ -80,11 +83,11 @@ add_domain_assign(char *domain, char *domain_base_dir, uid_t uid, gid_t gid) return (-1); } } - if (use_etrn == 2 && !get_assign("autoturn", 0, 0, 0)) { + if (use_etrn && !get_assign("autoturn", 0, 0, 0)) { get_indimailuidgid(&indimailuid, &indimailgid); strnum1[i = fmt_ulong(strnum1, indimailuid)] = 0; strnum2[j = fmt_ulong(strnum2, indimailgid)] = 0; - if (!stralloc_copyb(&tmpstr, "+autoturn-:indimail:", 20) || + if (!stralloc_copyb(&tmpstr, "+autoturn-:autoturn:", 20) || !stralloc_catb(&tmpstr, strnum1, i) || !stralloc_append(&tmpstr, ":") || !stralloc_catb(&tmpstr, strnum2, j) || @@ -98,29 +101,28 @@ add_domain_assign(char *domain, char *domain_base_dir, uid_t uid, gid_t gid) return (-1); if (!OptimizeAddDomain) update_newu(); - } else { - strnum1[i = fmt_ulong(strnum1, uid)] = 0; - strnum2[j = fmt_ulong(strnum2, gid)] = 0; - if (!stralloc_copyb(&tmpstr, "+", 1) || - !stralloc_cats(&tmpstr, domain) || - !stralloc_catb(&tmpstr, "-:", 2) || - !stralloc_cats(&tmpstr, domain) || - !stralloc_append(&tmpstr, ":") || - !stralloc_catb(&tmpstr, strnum1, i) || - !stralloc_append(&tmpstr, ":") || - !stralloc_catb(&tmpstr, strnum2, j) || - !stralloc_append(&tmpstr, ":") || - !stralloc_cats(&tmpstr, domain_base_dir) || - !stralloc_catb(&tmpstr, use_etrn ? "/" : "/domains/", use_etrn ? 1 : 9) || - !stralloc_cats(&tmpstr, domain) || - !stralloc_catb(&tmpstr, ":-::", 4) || - !stralloc_0(&tmpstr)) - die_nomem(); - if (update_file(filename.s, tmpstr.s, INDIMAIL_QMAIL_MODE)) - return (-1); - /*- compile the assign file */ - if (!OptimizeAddDomain) - update_newu(); } + strnum1[i = fmt_ulong(strnum1, uid)] = 0; + strnum2[j = fmt_ulong(strnum2, gid)] = 0; + if (!stralloc_copyb(&tmpstr, "+", 1) || + !stralloc_cats(&tmpstr, domain) || + !stralloc_catb(&tmpstr, "-:", 2) || + !stralloc_cats(&tmpstr, domain) || + !stralloc_append(&tmpstr, ":") || + !stralloc_catb(&tmpstr, strnum1, i) || + !stralloc_append(&tmpstr, ":") || + !stralloc_catb(&tmpstr, strnum2, j) || + !stralloc_append(&tmpstr, ":") || + !stralloc_cats(&tmpstr, domain_base_dir) || + !stralloc_catb(&tmpstr, use_etrn ? "/" : "/domains/", use_etrn ? 1 : 9) || + !stralloc_cats(&tmpstr, domain) || + !stralloc_catb(&tmpstr, ":-::", 4) || + !stralloc_0(&tmpstr)) + die_nomem(); + if (update_file(filename.s, tmpstr.s, INDIMAIL_QMAIL_MODE)) + return (-1); + /*- compile the assign file */ + if (!OptimizeAddDomain) + update_newu(); return(0); } diff --git a/indimail-x/del_control.c b/indimail-x/del_control.c index 56409a396..adfe82c73 100644 --- a/indimail-x/del_control.c +++ b/indimail-x/del_control.c @@ -1,5 +1,8 @@ /* * $Log: del_control.c,v $ + * Revision 1.4 2023-12-03 16:10:48+05:30 Cprogrammer + * use same logic for ETRN, ATRN domains + * * Revision 1.3 2023-03-25 14:15:26+05:30 Cprogrammer * refactored code * @@ -32,7 +35,7 @@ #include "compile_morercpthosts.h" #ifndef lint -static char sccsid[] = "$Id: del_control.c,v 1.3 2023-03-25 14:15:26+05:30 Cprogrammer Exp mbhangui $"; +static char sccsid[] = "$Id: del_control.c,v 1.4 2023-12-03 16:10:48+05:30 Cprogrammer Exp mbhangui $"; #endif static void @@ -111,7 +114,7 @@ del_control(char *domain) if (!stralloc_catb(&filename, "virtualdomains\0", 15) ) die_nomem(); - if (use_etrn == 2) { + if (use_etrn) { if (!stralloc_copys(&tmp, domain) || !stralloc_catb(&tmp, ":autoturn-", 10) || !stralloc_0(&tmp)) @@ -127,7 +130,7 @@ del_control(char *domain) if (errno != error_noent) status = -1; } else - if (remove_line(tmp.s, filename.s, 0, INDIMAIL_QMAIL_MODE) == -1) + if (remove_line_p(tmp.s, filename.s, 0, INDIMAIL_QMAIL_MODE) == -1) status = -1; return (status); } diff --git a/indimail-x/deldomain.c b/indimail-x/deldomain.c index d65eac63d..3f0e6938c 100644 --- a/indimail-x/deldomain.c +++ b/indimail-x/deldomain.c @@ -1,5 +1,8 @@ /* * $Log: deldomain.c,v $ + * Revision 1.6 2023-12-03 15:40:29+05:30 Cprogrammer + * use same logic for ETRN, ATRN domains + * * Revision 1.5 2023-03-25 14:32:08+05:30 Cprogrammer * multiple bug fixes * @@ -58,7 +61,7 @@ #include "common.h" #ifndef lint -static char sccsid[] = "$Id: deldomain.c,v 1.5 2023-03-25 14:32:08+05:30 Cprogrammer Exp mbhangui $"; +static char sccsid[] = "$Id: deldomain.c,v 1.6 2023-12-03 15:40:29+05:30 Cprogrammer Exp mbhangui $"; #endif static void @@ -130,13 +133,13 @@ deldomain(char *domain) return (-1); } lowerit(domain); - if (use_etrn == 2) { + if (use_etrn) { if (!(ptr = autoturn_dir(domain))) { - strerr_warn3("deldomain: domain ", domain, " does not exist", 0); + strerr_warn3("deldomain: autoturn domain ", domain, " does not exist", 0); return (-1); } else if (!(tmpstr = get_assign("autoturn", 0, &uid, &gid))) { - strerr_warn3("deldomain: domain ", domain, " does not exist: No entry for autoturn in assign", 0); + strerr_warn3("deldomain: autoturn domain ", domain, " does not exist: No entry for autoturn in assign", 0); return (-1); } if (!stralloc_copys(&tmpbuf, tmpstr) || diff --git a/indimail-x/doc/ChangeLog b/indimail-x/doc/ChangeLog index 180b218f5..8a490b442 100644 --- a/indimail-x/doc/ChangeLog +++ b/indimail-x/doc/ChangeLog @@ -23,6 +23,15 @@ Release @version@-@release@ Start XX/XX/XXXX End --/--/---- 10. iadddomain.c: fix .qmail-default for etrn, atrn domains 11. vadddomain.c: do post handle when creating etrn, atrn domains 12. vadddomain_handle.in: handle etrn/atrn domain creation +- 03/12/2023 +13. add_domain_assign.c, del_control.c, deldomain.c, iadddomain.c: use same + logic for ETRN, ATRN domains +14. vadddomain.c: exit early for post_handle for ETRN, ATRN domains +15. vadddomain_handle.in: fix for ETRN, ATRN domains +16. vdeldomain.c: use entry for autoturn in users/assign for ETRN, ATRN + domains +17. remove_line.c: Added function remove_line_p() to remove line on partial + match * Fri Sep 08 2023 12:47:55 +0000 Manvendra Bhangui 3.4.5-1.1%{?dist} Release 3.4.5-1.1 Start 25/04/2023 End 08/09/2023 diff --git a/indimail-x/iadddomain.c b/indimail-x/iadddomain.c index c22656b2b..07342b645 100644 --- a/indimail-x/iadddomain.c +++ b/indimail-x/iadddomain.c @@ -1,5 +1,5 @@ /* - * $Id: iadddomain.c,v 1.3 2023-11-26 19:52:49+05:30 Cprogrammer Exp mbhangui $ + * $Id: iadddomain.c,v 1.4 2023-12-03 15:41:05+05:30 Cprogrammer Exp mbhangui $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -45,7 +45,7 @@ #include "vdelfiles.h" #ifndef lint -static char sccsid[] = "$Id: iadddomain.c,v 1.3 2023-11-26 19:52:49+05:30 Cprogrammer Exp mbhangui $"; +static char sccsid[] = "$Id: iadddomain.c,v 1.4 2023-12-03 15:41:05+05:30 Cprogrammer Exp mbhangui $"; #endif static void @@ -152,10 +152,16 @@ iadddomain(char *domain, char *ipaddr, char *dir, uid_t uid, gid_t gid, int chk_ if (use_etrn == 1) { if (!stralloc_copys(&tmpbuf, dir) || !stralloc_append(&tmpbuf, "/") || + !stralloc_catb(&tmpbuf, "/.qmail-", 8) || !stralloc_cats(&tmpbuf, domain) || - !stralloc_catb(&tmpbuf, "/.qmail-default", 15) || + !stralloc_catb(&tmpbuf, "-default", 8) || !stralloc_0(&tmpbuf)) die_nomem(); + i = str_len(dir); + for (ptr = tmpbuf.s + i + 8; *ptr; ptr++) { + if (*ptr == '.') + *ptr = ':'; + } } else if (use_etrn == 2) { if (!stralloc_copys(&tmpbuf, dir) || @@ -168,8 +174,7 @@ iadddomain(char *domain, char *ipaddr, char *dir, uid_t uid, gid_t gid, int chk_ if (*ptr == '.') *ptr = ':'; } - } else - if (!use_etrn) { + } else { if (!stralloc_copys(&tmpbuf, dir) || !stralloc_catb(&tmpbuf, "/domains/", 9) || !stralloc_cats(&tmpbuf, domain) || @@ -238,15 +243,16 @@ iadddomain(char *domain, char *ipaddr, char *dir, uid_t uid, gid_t gid, int chk_ strerr_warn7("adddomain: chown(", tmpbuf.s, ", ", strnum1, ", ", strnum2, "): ", &strerr_sys); return (-1); } - if (add_domain_assign(domain, dir, uid, gid)) + if (!use_etrn && add_domain_assign(domain, dir, uid, gid)) return (-1); - if (!use_etrn || use_etrn == 1) { + if (!use_etrn) { if (add_control(domain, domain)) return (-1); } else - if (use_etrn == 2) { + if (use_etrn) { if (!stralloc_copyb(&tmpbuf, "autoturn-", 9) || - !stralloc_cats(&tmpbuf, ipaddr) || !stralloc_0(&tmpbuf)) + !stralloc_cats(&tmpbuf, use_etrn == 1 ? domain : ipaddr) || + !stralloc_0(&tmpbuf)) die_nomem(); if (add_control(domain, tmpbuf.s)) return (-1); @@ -287,6 +293,9 @@ iadddomain(char *domain, char *ipaddr, char *dir, uid_t uid, gid_t gid, int chk_ /* * $Log: iadddomain.c,v $ + * Revision 1.4 2023-12-03 15:41:05+05:30 Cprogrammer + * use same logic for ETRN, ATRN domains + * * Revision 1.3 2023-11-26 19:52:49+05:30 Cprogrammer * fix .qmail-default for etrn, atrn domains * diff --git a/indimail-x/remove_line.c b/indimail-x/remove_line.c index 0015f9398..e37bd8c3d 100644 --- a/indimail-x/remove_line.c +++ b/indimail-x/remove_line.c @@ -1,5 +1,8 @@ /* * $Log: remove_line.c,v $ + * Revision 1.2 2023-12-03 16:09:24+05:30 Cprogrammer + * new function remove_line_p() for partial match + * * Revision 1.1 2019-04-18 08:36:17+05:30 Cprogrammer * Initial revision * @@ -35,7 +38,7 @@ #include "dblock.h" #ifndef lint -static char sccsid[] = "$Id: remove_line.c,v 1.1 2019-04-18 08:36:17+05:30 Cprogrammer Exp mbhangui $"; +static char sccsid[] = "$Id: remove_line.c,v 1.2 2023-12-03 16:09:24+05:30 Cprogrammer Exp mbhangui $"; #endif static void @@ -44,7 +47,6 @@ die_nomem() strerr_warn1("remove_line: out of memory", 0); _exit(111); } - /* * Generic remove a line from a file utility * input: template to search for @@ -55,13 +57,13 @@ die_nomem() * 1 if match found */ int -remove_line(char *template, char *filename, int once_only, mode_t mode) +remove_line_int(char *template, char *filename, int once_only, mode_t mode, int partial) { struct substdio ssin, ssout; static stralloc fname = {0}, line = {0}; struct stat statbuf; char inbuf[4096], outbuf[4096]; - int fd1, fd2, match, found; + int fd1, fd2, match, found, tlen; #ifdef FILE_LOCKING int lockfd; #endif @@ -107,6 +109,8 @@ remove_line(char *template, char *filename, int once_only, mode_t mode) substdio_fdbuf(&ssin, read, fd1, inbuf, sizeof(inbuf)); substdio_fdbuf(&ssout, write, fd2, outbuf, sizeof(outbuf)); /*- pound away on the files run the search algorithm */ + if (partial) + tlen = str_len(template); for (found = 0;;) { if (getln(&ssin, &line, &match, '\n') == -1) { strerr_warn3("remove_line: read: ", filename, ": ", &strerr_sys); @@ -129,7 +133,7 @@ remove_line(char *template, char *filename, int once_only, mode_t mode) } continue; } - if (str_diffn(line.s, template, line.len - 1)) { + if (str_diffn(line.s, template, partial ? tlen : line.len - 1)) { if (substdio_put(&ssout, line.s, line.len)) { strerr_warn3("remove_line: write error: ", fname.s, ": ", &strerr_sys); close(fd2); @@ -163,3 +167,15 @@ remove_line(char *template, char *filename, int once_only, mode_t mode) */ return (found); } + +int +remove_line(char *template, char *filename, int once_only, mode_t mode) +{ + return (remove_line_int(template, filename, once_only, mode, 0)); +} + +int +remove_line_p(char *template, char *filename, int once_only, mode_t mode) +{ + return (remove_line_int(template, filename, once_only, mode, 1)); +} diff --git a/indimail-x/remove_line.h b/indimail-x/remove_line.h index 5251c5264..76d328ad7 100644 --- a/indimail-x/remove_line.h +++ b/indimail-x/remove_line.h @@ -1,5 +1,8 @@ /* * $Log: remove_line.h,v $ + * Revision 1.2 2023-12-03 16:09:37+05:30 Cprogrammer + * added new function remove_line_p() for partial match + * * Revision 1.1 2019-04-13 23:39:27+05:30 Cprogrammer * remove_line.h * @@ -14,5 +17,6 @@ #endif int remove_line(char *, char *, int, mode_t mode); +int remove_line_p(char *, char *, int, mode_t mode); #endif diff --git a/indimail-x/vadddomain.9 b/indimail-x/vadddomain.9 index 970f4a8ea..cb521bd18 100644 --- a/indimail-x/vadddomain.9 +++ b/indimail-x/vadddomain.9 @@ -133,11 +133,12 @@ sets the domain to use vfilter mechanism for mail filtering .TP \fB\-t\fR -Enable ETRN/ATRN support for the domain +Enable ETRN/ATRN support for the domain. This requires you to authenticate +and use \fBvatrn\fR(1) to configure access. .TP \fB\-T\fR \fIip_address\fR -Enable AUTOTURN Support from the IP ip_address +Enable ETRN, AUTOTURN Support from the IP \fIip_address\fR .TP \fB\-e\fR diff --git a/indimail-x/vadddomain.c b/indimail-x/vadddomain.c index 9345f8431..6981b8f37 100644 --- a/indimail-x/vadddomain.c +++ b/indimail-x/vadddomain.c @@ -1,5 +1,5 @@ /* - * $Id: vadddomain.c,v 1.18 2023-11-26 19:53:52+05:30 Cprogrammer Exp mbhangui $ + * $Id: vadddomain.c,v 1.19 2023-12-03 15:43:17+05:30 Cprogrammer Exp mbhangui $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -73,7 +73,7 @@ #include "get_hashmethod.h" #ifndef lint -static char rcsid[] = "$Id: vadddomain.c,v 1.18 2023-11-26 19:53:52+05:30 Cprogrammer Exp mbhangui $"; +static char rcsid[] = "$Id: vadddomain.c,v 1.19 2023-12-03 15:43:17+05:30 Cprogrammer Exp mbhangui $"; #endif #define WARN "vadddomain: warning: " @@ -106,7 +106,7 @@ static char *usage = " -g gid - sets the gid to use for this domain\n" " -f - sets the Domain with VFILTER capability\n" " -t - sets the Domain for ETRN/ATRN\n" - " -T ipaddr - sets the Domain for AUTOTURN from IP ipaddr\n" + " -T ipaddr - sets the Domain for ETRN/AUTOTURN from IP ipaddr\n" " -O - optimize adding, for bulk adds set this for all\n" " except the last one\n" " -r len - generate a random password of length=len\n" @@ -552,6 +552,8 @@ main(int argc, char **argv) iclose(); return (err); } + if (use_etrn) + return (do_posthandle(argc, argv)); if (users_per_level) { s = dbuf; s += (i = fmt_uint(s, (unsigned int) users_per_level)); @@ -606,8 +608,6 @@ main(int argc, char **argv) LoadDbInfo_TXT(&total); } #endif - if (use_etrn) - return (do_posthandle(argc, argv)); if (bounceEmail) { if (bounceEmail[i = str_chr(bounceEmail, '@')] || *bounceEmail == '/') { if (!stralloc_copyb(&tmp2, "| ", 2) || !stralloc_cats(&tmp2, PREFIX) || @@ -724,6 +724,9 @@ main(int argc, char **argv) /* * $Log: vadddomain.c,v $ + * Revision 1.19 2023-12-03 15:43:17+05:30 Cprogrammer + * exit early for post_handle for ETRN, ATRN domains + * * Revision 1.18 2023-11-26 19:53:52+05:30 Cprogrammer * do post handle when creating etrn, atrn domains * diff --git a/indimail-x/vadddomain_handle.in b/indimail-x/vadddomain_handle.in index 359e53fb8..d8a9b1e16 100644 --- a/indimail-x/vadddomain_handle.in +++ b/indimail-x/vadddomain_handle.in @@ -1,6 +1,6 @@ #!/bin/sh # -# $Id: vadddomain_handle.in,v 2.26 2023-11-26 19:55:28+05:30 Cprogrammer Exp mbhangui $ +# $Id: vadddomain_handle.in,v 2.27 2023-12-03 15:43:38+05:30 Cprogrammer Exp mbhangui $ domaindir=@domaindir@ use_etrn=0 @@ -64,10 +64,11 @@ do echo "Sending SIGHUP to $line" @prefix@/bin/svc -h $line done -# print domain information -@prefix@/bin/vdominfo $domain if [ $use_etrn -eq 0 ] ; then + # print domain information + @prefix@/bin/vdominfo $domain + # create user for bogofilter echo "Creating standard users for spam filter (bogofilter)" for i in ham spam register-ham register-spam @@ -107,8 +108,14 @@ if [ $use_etrn -eq 0 ] ; then else echo "Domain Directory content" # display domain directory - /bin/ls -dl $domaindir/autoturn/$domain - /bin/ls -al $domaindir/autoturn/$domain + if [ -d $domaindir/autoturn/$domain ] ; then + /bin/ls -dl $domaindir/autoturn/$domain + /bin/ls -al $domaindir/autoturn/$domain + else + d=$(grep $domain: $controldir/virtualdomains | cut -d: -f2 | sed 's/autoturn-//') + /bin/ls -dl $domaindir/autoturn/$d + /bin/ls -al $domaindir/autoturn/$d + fi echo fi @@ -146,6 +153,9 @@ fi exit 0 # # $Log: vadddomain_handle.in,v $ +# Revision 2.27 2023-12-03 15:43:38+05:30 Cprogrammer +# fix for ETRN, ATRN domains +# # Revision 2.26 2023-11-26 19:55:28+05:30 Cprogrammer # handle etrn/atrn domain creation # diff --git a/indimail-x/vdeldomain.c b/indimail-x/vdeldomain.c index 83e6a1950..8648f79a3 100644 --- a/indimail-x/vdeldomain.c +++ b/indimail-x/vdeldomain.c @@ -1,5 +1,8 @@ /* * $Log: vdeldomain.c,v $ + * Revision 1.7 2023-12-03 15:44:34+05:30 Cprogrammer + * use entry for autoturn in users/assign for ETRN, ATRN domains + * * Revision 1.6 2023-03-22 10:42:23+05:30 Cprogrammer * run POST_HANDLE program (if set) with domain user uid/gid * @@ -62,7 +65,7 @@ #include "get_assign.h" #ifndef lint -static char sccsid[] = "$Id: vdeldomain.c,v 1.6 2023-03-22 10:42:23+05:30 Cprogrammer Exp mbhangui $"; +static char sccsid[] = "$Id: vdeldomain.c,v 1.7 2023-12-03 15:44:34+05:30 Cprogrammer Exp mbhangui $"; #endif static char *usage = @@ -94,7 +97,7 @@ get_options(int argc, char **argv, stralloc *Domain, int *mcd_remove) verbose = 1; break; case 'T': - use_etrn = 2; + use_etrn = 1; break; case 'c': *mcd_remove = 1; @@ -132,8 +135,12 @@ main(int argc, char **argv) if (get_options(argc, argv, &Domain, &mcd_remove)) return (0); - if (!(ptr = get_assign(Domain.s, 0, &domainuid, &domaingid))) - strerr_die4x(1, WARN, "domain ", Domain.s, " does not exist"); + if (use_etrn) + ptr = get_assign("autoturn", 0, &domainuid, &domaingid); + else + ptr = get_assign(Domain.s, 0, &domainuid, &domaingid); + if (!ptr) + strerr_die4x(1, WARN, use_etrn ? "autoturn domain " : "domain ", Domain.s, " does not exist"); if (!domainuid) strerr_die4x(100, WARN, "domain ", Domain.s, " with uid 0"); uid = getuid();