Skip to content

Commit

Permalink
updated indimail-virtualdomains
Browse files Browse the repository at this point in the history
1. vrenamedomain.c: Fixed typo in error message
2. is_alias_domain.c: fixed soft link resolved name
3. host_in_locals.c: fixed typo in error message
4. get_real_domain.c, deldomain.c, del_control.c: refactored code
5. add testindimail-virtual test script
  • Loading branch information
mbhangui committed Mar 25, 2023
1 parent 89b6ac8 commit 53d8782
Show file tree
Hide file tree
Showing 8 changed files with 1,620 additions and 294 deletions.
134 changes: 54 additions & 80 deletions indimail-x/del_control.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
/*
* $Log: del_control.c,v $
* Revision 1.3 2023-03-25 14:15:26+05:30 Cprogrammer
* refactored code
*
* Revision 1.2 2020-04-01 18:54:20+05:30 Cprogrammer
* moved authentication functions to libqmail
*
Expand All @@ -21,13 +24,15 @@
#include <stralloc.h>
#include <strerr.h>
#include <getEnvConfig.h>
#include <error.h>
#include <str.h>
#endif
#include "variables.h"
#include "remove_line.h"
#include "compile_morercpthosts.h"

#ifndef lint
static char sccsid[] = "$Id: del_control.c,v 1.2 2020-04-01 18:54:20+05:30 Cprogrammer Exp mbhangui $";
static char sccsid[] = "$Id: del_control.c,v 1.3 2023-03-25 14:15:26+05:30 Cprogrammer Exp mbhangui $";
#endif

static void
Expand All @@ -45,7 +50,9 @@ del_control(char *domain)
{
static stralloc filename = {0}, tmp = {0};
char *sysconfdir, *controldir;
int i, status = 0, relative;
int i, status = 0, relative, len;
char **ptr;
char *fn[] = {"rcpthosts", "etrnhosts", "chkrcptdomains", "virtualdomains", 0};

getEnvConfigStr(&sysconfdir, "SYSCONFDIR", SYSCONFDIR);
getEnvConfigStr(&controldir, "CONTROLDIR", CONTROLDIR);
Expand All @@ -54,93 +61,56 @@ del_control(char *domain)
if (!stralloc_copys(&filename, sysconfdir) ||
!stralloc_append(&filename, "/") ||
!stralloc_cats(&filename, controldir) ||
!stralloc_catb(&filename, "/rcpthosts", 10) ||
!stralloc_0(&filename))
!stralloc_append(&filename, "/"))
die_nomem();
} else {
if (!stralloc_copys(&filename, controldir) ||
!stralloc_catb(&filename, "/rcpthosts", 10) ||
!stralloc_0(&filename))
!stralloc_append(&filename, "/"))
die_nomem();
}
status = remove_line(domain, filename.s, 0, INDIMAIL_QMAIL_MODE);
if (status < 1) { /*- if no lines found or if remove_line returned error */
if (relative) {
if (!stralloc_copys(&filename, sysconfdir) ||
!stralloc_append(&filename, "/") ||
!stralloc_cats(&filename, controldir) ||
!stralloc_catb(&filename, "/morercpthosts", 14) ||
!stralloc_0(&filename))
die_nomem();
} else {
if (!stralloc_copys(&filename, controldir) ||
!stralloc_catb(&filename, "/morercpthosts", 14) ||
!stralloc_0(&filename))
die_nomem();
len = filename.len;
for (ptr = fn; *ptr; ptr++) {
if (!stralloc_cats(&filename, *ptr) ||
!stralloc_0(&filename))
die_nomem();
if (access(filename.s, F_OK)) {
if (errno != error_noent)
strerr_warn3("del_control: ", filename.s, ": ", &strerr_sys);
filename.len = len; /*- restore original length */
continue;
}
/* at least one matching line found */
if ((i = remove_line(domain, filename.s, 0, INDIMAIL_QMAIL_MODE)) > 0) {
struct stat statbuf;
if (!stat(filename.s, &statbuf)) {
if (statbuf.st_size == 0) {
unlink(filename.s);
filename.len--;
if (!stralloc_catb(&filename, ".cdb", 4))
die_nomem();
else
if (!stralloc_0(&filename))
die_nomem();
unlink(filename.s);
} else
compile_morercpthosts();
status = remove_line(domain, filename.s, 1, INDIMAIL_QMAIL_MODE);
if (!str_diffn(*ptr, "rcpthosts", 10) && status < 1) { /*- remove from morercpthosts */
/*- if no lines found or if remove_line returned error */
if (!stralloc_catb(&filename, "morercpthosts\0", 14) )
die_nomem();
if (access(filename.s, F_OK)) {
if (errno != error_noent)
strerr_warn3("del_control: ", filename.s, ": ", &strerr_sys);
} else {
if ((i = remove_line(domain, filename.s, 0, INDIMAIL_QMAIL_MODE)) > 0) {
/* at least one matching line found */
struct stat statbuf;
if (!stat(filename.s, &statbuf)) {
if (statbuf.st_size == 0) {
unlink(filename.s);
filename.len--;
if (!stralloc_catb(&filename, ".cdb\0", 5))
die_nomem();
unlink(filename.s);
} else
compile_morercpthosts();
}
}
if (i == -1)
status = i;
}
}
if (i == -1)
status = i;
}
if (relative) {
if (!stralloc_copys(&filename, sysconfdir) ||
!stralloc_append(&filename, "/") ||
!stralloc_cats(&filename, controldir) ||
!stralloc_catb(&filename, "/etrnhosts", 10) ||
!stralloc_0(&filename))
die_nomem();
} else {
if (!stralloc_copys(&filename, controldir) ||
!stralloc_catb(&filename, "/etrnhosts", 10) ||
!stralloc_0(&filename))
die_nomem();
}
if (!access(filename.s, F_OK) && remove_line(domain, filename.s, 0, INDIMAIL_QMAIL_MODE) == -1)
status = -1;
if (relative) {
if (!stralloc_copys(&filename, sysconfdir) ||
!stralloc_append(&filename, "/") ||
!stralloc_cats(&filename, controldir) ||
!stralloc_catb(&filename, "/chkrcptdomains", 15) ||
!stralloc_0(&filename))
die_nomem();
} else {
if (!stralloc_copys(&filename, controldir) ||
!stralloc_catb(&filename, "/chkrcptdomains", 15) ||
!stralloc_0(&filename))
die_nomem();
}
if (!access(filename.s, F_OK) && remove_line(domain, filename.s, 0, INDIMAIL_QMAIL_MODE) == -1)
status = -1;
if (relative) {
if (!stralloc_copys(&filename, sysconfdir) ||
!stralloc_append(&filename, "/") ||
!stralloc_cats(&filename, controldir) ||
!stralloc_catb(&filename, "/virtualdomains", 15) ||
!stralloc_0(&filename))
die_nomem();
} else {
if (!stralloc_copys(&filename, controldir) ||
!stralloc_catb(&filename, "/virtualdomains", 15) ||
!stralloc_0(&filename))
die_nomem();
filename.len = len; /*- restore original length */
}

if (!stralloc_catb(&filename, "virtualdomains\0", 15) )
die_nomem();
if (use_etrn == 2) {
if (!stralloc_copys(&tmp, domain) ||
!stralloc_catb(&tmp, ":autoturn-", 10) ||
Expand All @@ -153,6 +123,10 @@ del_control(char *domain)
!stralloc_0(&tmp))
die_nomem();
}
if (access(filename.s, F_OK)) {
if (errno != error_noent)
status = -1;
} else
if (remove_line(tmp.s, filename.s, 0, INDIMAIL_QMAIL_MODE) == -1)
status = -1;
return (status);
Expand Down
24 changes: 13 additions & 11 deletions indimail-x/deldomain.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* $Log: deldomain.c,v $
* Revision 1.5 2023-03-23 22:04:58+05:30 Cprogrammer
* Revision 1.5 2023-03-25 14:32:08+05:30 Cprogrammer
* multiple bug fixes
*
* Revision 1.4 2023-03-20 09:57:24+05:30 Cprogrammer
Expand Down Expand Up @@ -58,7 +58,7 @@
#include "common.h"

#ifndef lint
static char sccsid[] = "$Id: deldomain.c,v 1.5 2023-03-23 22:04:58+05:30 Cprogrammer Exp mbhangui $";
static char sccsid[] = "$Id: deldomain.c,v 1.5 2023-03-25 14:32:08+05:30 Cprogrammer Exp mbhangui $";
#endif

static void
Expand Down Expand Up @@ -176,12 +176,13 @@ deldomain(char *domain)
if (!stralloc_copy(&tmpbuf, &Dir) ||
!stralloc_catb(&tmpbuf, "/.base_path", 11) || !stralloc_0(&tmpbuf))
die_nomem();
if ((fd = open_read(tmpbuf.s)) == -1 && errno != error_noent) {
strerr_warn3("deldomain: read: ", tmpbuf.s, ": ", &strerr_sys);
return (-1);
}
BasePath.len = 0;
if (fd > -1) {
if ((fd = open_read(tmpbuf.s)) == -1) {
if (errno != error_noent) {
strerr_warn3("deldomain: read: ", tmpbuf.s, ": ", &strerr_sys);
return (-1);
}
} else {
BasePath.len = 0;
substdio_fdbuf(&ssin, read, fd, inbuf, sizeof(inbuf));
if (getln(&ssin, &line, &match, '\n') == -1) {
strerr_warn3("deldomain: read: ", tmpbuf.s, ": ", &strerr_sys);
Expand Down Expand Up @@ -211,9 +212,10 @@ deldomain(char *domain)
if (remove_alias_domain(domain, tmpbuf.s))
return -1;
} else {
if ((fd = open_read(tmpbuf.s)) == -1 && errno != error_noent)
strerr_die3sys(111, "deldomain: ", tmpbuf.s, ": ");
if (fd > -1) {
if ((fd = open_read(tmpbuf.s)) == -1) {
if (errno != error_noent)
strerr_die3sys(111, "deldomain: ", tmpbuf.s, ": ");
} else {
if (verbose) {
out("deldomain", "Removing domains aliased to ");
out("deldomain", domain);
Expand Down
11 changes: 9 additions & 2 deletions indimail-x/doc/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
* XXX XXX XX XXXX XX:XX:XX +0000 Manvendra Bhangui <@email@> @version@-@release@%{?dist}
Release 3.4.3-1.1 Start 13/02/2023 End XX/XX/XXXX
* Sat Mar 25 2024 08:40:00 +0000 Manvendra Bhangui <indimail-virtualdomains@indimailorg> 3.4.3-1.1%{?dist}
Release 3.4.3-1.1 Start 13/02/2023 End 25/03/2023
======= Release Highlights ================================================
o Test script testindimail-virtual tests essential indimail commands
===========================================================================
- 13/02/2023
01. indimail.spec: added qcerts supplementary group for apache for roundcube
access to certs
Expand Down Expand Up @@ -61,6 +64,10 @@ Release 3.4.3-1.1 Start 13/02/2023 End XX/XX/XXXX
child.
32. vmoveuser.c, indimail.spec, variables.c, perm_list.in,
indimail-permissions.*: vmoveuser command renamed to vmoveuserdir
- 25/03/2023
33. del_control.c, get_real_domain.c: refactored code
34. is_alias_domain: fixed soft link resolved name
35. add testindimail-virtual test script

* Tue Jan 31 2023 03:32:40 +0000 Manvendra Bhangui <indimail-virtualdomains@indimail.org> 3.4.2-1.1%{?dist}
Release 3.4.2-1.1 Start 08/09/2022 End 31/01/2023
Expand Down

0 comments on commit 53d8782

Please sign in to comment.