Mailing List Archive

Not able to understand portion of qmesearch function in qmail-local.c
Friends,

There is this function qmesearch() in qmail-local.c. There is a portion of
the code which sets the environment variable DEFAULT. I presume that this
variable is being set for the program fastforward. What I don't
understand is that if a mail sent to user-anythingdefault and the
file .qmail-anythingdefault exists in ~user the environment
variable DEFAULT is set to "default" by qmail-local

Any idea why this is being done?

void qmesearch(fd,cutable)
int *fd;
int *cutable;
{
int i;
if (!stralloc_copys(&qme,".qmail")) temp_nomem();
if (!stralloc_cats(&qme,dash)) temp_nomem();
if (!stralloc_cat(&qme,&safeext)) temp_nomem();
if (qmeexists(fd,cutable)) {
/*-- THIS IS WHAT I want to understand */
if (safeext.len >= 7) {
i = safeext.len - 7;
if (!byte_diff("default",7,safeext.s + i))
if (i <= str_len(ext)) /* paranoia */
if (!env_put2("DEFAULT",ext + i)) temp_nomem();
}
return;
}

for (i = safeext.len;i >= 0;--i)
if (!i || (safeext.s[i - 1] == '-')) {
if (!stralloc_copys(&qme,".qmail")) temp_nomem();
if (!stralloc_cats(&qme,dash)) temp_nomem();
if (!stralloc_catb(&qme,safeext.s,i)) temp_nomem();
if (!stralloc_cats(&qme,"default")) temp_nomem();
if (qmeexists(fd,cutable)) {
if (i <= str_len(ext)) /* paranoia */
if (!env_put2("DEFAULT",ext + i)) temp_nomem();
return;
}
}
*fd = -1;
}

--
Regards Manvendra - http://www.indimail.org
GPG Pub Key
http://pgp.mit.edu:11371/pks/lookup?op=get&search=0xC7CBC760014D250C
Re: Not able to understand portion of qmesearch function in qmail-local.c [ In reply to ]
fastforward.c:    x = env_get("DEFAULT");

I downloaded fastforward-0.51 and it's right there. Line 325.

On 10/9/22 07:00, Manvendra Bhangui wrote:
> Friends,
>
> There is this function qmesearch() in qmail-local.c. There is a portion of
> the code which sets the environment variable DEFAULT. I presume that this
> variable is being set for the program fastforward. What I don't
> understand is that if a mail sent to user-anythingdefault and the
> file .qmail-anythingdefault exists in ~user the environment
> variable DEFAULT is set to "default" by qmail-local
>
> Any idea why this is being done?
>
> void qmesearch(fd,cutable)
> int *fd;
> int *cutable;
> {
> int i;
> if (!stralloc_copys(&qme,".qmail")) temp_nomem();
> if (!stralloc_cats(&qme,dash)) temp_nomem();
> if (!stralloc_cat(&qme,&safeext)) temp_nomem();
> if (qmeexists(fd,cutable)) {
> /*-- THIS IS WHAT I want to understand */
> if (safeext.len >= 7) {
> i = safeext.len - 7;
> if (!byte_diff("default",7,safeext.s + i))
> if (i <= str_len(ext)) /* paranoia */
> if (!env_put2("DEFAULT",ext + i)) temp_nomem();
> }
> return;
> }
>
> for (i = safeext.len;i >= 0;--i)
> if (!i || (safeext.s[i - 1] == '-')) {
> if (!stralloc_copys(&qme,".qmail")) temp_nomem();
> if (!stralloc_cats(&qme,dash)) temp_nomem();
> if (!stralloc_catb(&qme,safeext.s,i)) temp_nomem();
> if (!stralloc_cats(&qme,"default")) temp_nomem();
> if (qmeexists(fd,cutable)) {
> if (i <= str_len(ext)) /* paranoia */
> if (!env_put2("DEFAULT",ext + i)) temp_nomem();
> return;
> }
> }
> *fd = -1;
> }
>
--
Amelia Bjornsdottir (she, they)
sysadmin umbrellix.net, deputy sysadmin chatspeed.net
jabber: eamon.aka.amy.malik ~on~ umbrellix.net
Re: Not able to understand portion of qmesearch function in qmail-local.c [ In reply to ]
On Sun, 9 Oct 2022 at 12:46, Amelia Bjornsdottir <ellenor@umbrellix.net> wrote:
>
> fastforward.c: x = env_get("DEFAULT");
>
> I downloaded fastforward-0.51 and it's right there. Line 325.
>
I got that part is for fastforward. What I don't understand is the
logic of checking if the extension address ends with the string
"default". The thing is that the string is always a constant and
always set to "default". Also that part of the code in fastforward
gets activated only when the -d option is passed to fastforward.
Re: Not able to understand portion of qmesearch function in qmail-local.c [ In reply to ]
Manvendra Bhangui <mbhangui@gmail.com> wrote:
>
> There is this function qmesearch() in qmail-local.c. There is a portion of
> the code which sets the environment variable DEFAULT. I presume that this
> variable is being set for the program fastforward. What I don't
> understand is that if a mail sent to user-anythingdefault and the
> file .qmail-anythingdefault exists in ~user the environment
> variable DEFAULT is set to "default" by qmail-local
>
> Any idea why this is being done?
>
> void qmesearch(fd,cutable)
> int *fd;
> int *cutable;
> {
> int i;
> if (!stralloc_copys(&qme,".qmail")) temp_nomem();
> if (!stralloc_cats(&qme,dash)) temp_nomem();
> if (!stralloc_cat(&qme,&safeext)) temp_nomem();
> if (qmeexists(fd,cutable)) {
> /*-- THIS IS WHAT I want to understand */
> if (safeext.len >= 7) {
> i = safeext.len - 7;
> if (!byte_diff("default",7,safeext.s + i))
> if (i <= str_len(ext)) /* paranoia */
> if (!env_put2("DEFAULT",ext + i)) temp_nomem();
> }
> return;
> }

I haven't looked too deeply at this, but I think it's checking for a corner
case - specifically where the recipient address includes a literal "default":

localuser-default@domain

If that exists, it short circuits and just returns. Otherwise it goes on to
the normal handling.

Charles
--
--------------------------------------------------------------------------
Charles Cazabon
GPL'ed software available at: http://pyropus.ca/software/
Read http://pyropus.ca/personal/writings/12-steps-to-qmail-list-bliss.html
--------------------------------------------------------------------------
Re: Not able to understand portion of qmesearch function in qmail-local.c [ In reply to ]
On Sun, 9 Oct 2022 at 21:02, Charles Cazabon
<search-web-for-address@pyropus.ca> wrote:

> I haven't looked too deeply at this, but I think it's checking for a corner
> case - specifically where the recipient address includes a literal "default":
>
> localuser-default@domain

I just got a hunch. This is to do with having a corner case of having
a .qmail-default in the /var/qmail/alias directory and having
fastforward in .qmail-default. Deliveries to unknown addresses will
land up here. If fastforward is called, it will see an environment
variable named DEFAULT and will use the recipient default@domain.