LD_PRELOAD + Postfix problems

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
16 messages Options
Reply | Threaded
Open this post in threaded view
|

LD_PRELOAD + Postfix problems

infaga03
Hello everybody:

I'm trying to modify some functions on postfix source and then preload
them by using LD_PRELOAD. To get it work, I've modified
/etc/postfix/postfix-script as follows:

[...]

overlay)
    export LD_LIBRARY_PATH=./:/usr/local/lib/:$LD_LIBRARY_PATH
    export LD_PRELOAD=/home/antonio/libpostfixMOD.so:$LD_PRELOAD

//The rest of text is a start command copy.
[...]

I think export is being executed because there's an 'echo' command working
good. Some tries before, ld.so returned some errors because there was some
problems with the compiled library or his path. Now, there's no error
messages but the modified library code isn't executing. On the other hand,
original postfix source code is being executed normally.

I would be really grateful if you could help me. Any ideas or suggestion
would be welcome. Many thanks in advance,

Antonio G. Artime

Reply | Threaded
Open this post in threaded view
|

Re: LD_PRELOAD + Postfix problems

Wietse Venema
Reply | Threaded
Open this post in threaded view
|

Re: LD_PRELOAD + Postfix problems

infaga03
Thank you. I try that some days ago but it didn't work.

I'll retry it!

Antonio G. Artime

Reply | Threaded
Open this post in threaded view
|

Re: LD_PRELOAD + Postfix problems

Wietse Venema
[hidden email]:
> Thank you. I try that some days ago but it didn't work.

It works only if you understand its limitations.

The import_environment feature executes AFTER the run-time linker
completes execution. Therefore, import_environment cannot affect
the run-time linker performance for the process itself.

Import_environment can, however, affect the run-time linker
performance of CHILD processes.

        Wietse

> I'll retry it!
>
> Antonio G. Artime
>
>
>

Reply | Threaded
Open this post in threaded view
|

Re: LD_PRELOAD + Postfix problems

infaga03
> [hidden email]:
>> Thank you. I try that some days ago but it didn't work.
>
> It works only if you understand its limitations.
>
> The import_environment feature executes AFTER the run-time linker
> completes execution. Therefore, import_environment cannot affect
> the run-time linker performance for the process itself.
>
> Import_environment can, however, affect the run-time linker
> performance of CHILD processes.
>
> Wietse
>
>> I'll retry it!
>>
>> Antonio G. Artime
>>
>>
>>
>
>

Ok, so... I've added these lines on my 'main.cf':

import_environment = MAIL_CONFIG MAIL_DEBUG MAIL_LOGTAG TZ XAUTHORITY
DISPLAY LANG=C LD_PRELOAD=/home/antonio/libpostfixMOD.so

export_environment = TZ MAIL_CONFIG LANG
LD_PRELOAD=/home/antonio/libpostfixMOD.so

, postfix reload; and postfix stills working as always.

I'm a student and I'm a little confused... So, if I want this modified
function working; should I do a fork() ???? Sorry. There isn't another
way?

Thank you again!

Antonio G. Artime

Reply | Threaded
Open this post in threaded view
|

Re: LD_PRELOAD + Postfix problems

Wietse Venema
[hidden email]:
> , postfix reload; and postfix stills working as always.

Show actual evidence of behavior that does not change, and show
actual evidence based on which it should have changed.

        Wietse
Reply | Threaded
Open this post in threaded view
|

Re: LD_PRELOAD + Postfix problems

infaga03
> [hidden email]:
>> , postfix reload; and postfix stills working as always.
>
> Show actual evidence of behavior that does not change, and show
> actual evidence based on which it should have changed.
>
> Wietse
>

It's easy. On my modified library, I modify recipient_list_add(...)
function. It's always called when you send a mail, and the code works
because I tried it before modifying and compiling postfix itself, and not
like a dynamic library. The first step I do is print on /var/log/syslog
with msg_info(""); and the text isn't showed on syslog.

Wietse, using import_environment and export_environment like I do should
work?

Thank you a lot!

Antonio G. Artime

Reply | Threaded
Open this post in threaded view
|

Re: LD_PRELOAD + Postfix problems

Wietse Venema
[hidden email]:

> > [hidden email]:
> >> , postfix reload; and postfix stills working as always.
> >
> > Show actual evidence of behavior that does not change, and show
> > actual evidence based on which it should have changed.
> >
> > Wietse
> >
>
> It's easy. On my modified library, I modify recipient_list_add(...)
> function. It's always called when you send a mail, and the code works
> because I tried it before modifying and compiling postfix itself, and not
> like a dynamic library. The first step I do is print on /var/log/syslog
> with msg_info(""); and the text isn't showed on syslog.

I asked for actual evidence. I did not ask for a description of
the evidence.

        Wietse
Reply | Threaded
Open this post in threaded view
|

Re: LD_PRELOAD + Postfix problems

infaga03
> [hidden email]:
>> > [hidden email]:
>> >> , postfix reload; and postfix stills working as always.
>> >
>> > Show actual evidence of behavior that does not change, and show
>> > actual evidence based on which it should have changed.
>> >
>> > Wietse
>> >
>>
>> It's easy. On my modified library, I modify recipient_list_add(...)
>> function. It's always called when you send a mail, and the code works
>> because I tried it before modifying and compiling postfix itself, and
>> not
>> like a dynamic library. The first step I do is print on /var/log/syslog
>> with msg_info(""); and the text isn't showed on syslog.
>
> I asked for actual evidence. I did not ask for a description of
> the evidence.
>
> Wietse
>


MODIFIED RECIPIENT_LIST.C
=========================

void    recipient_list_add(RECIPIENT_LIST *list, long offset,
                                   const char *dsn_orcpt, int dsn_notify,
                                   const char *orig_rcpt, const char *rcpt)
{
    int     new_avail;

        //MODIFIED SOURCE

        char **host; int  *port;
        char * userName;
        //Here we filter the RECIPIENT ADDRESS and we do a lookup by using P2P
daemon.
        userName = strtok(rcpt,"@");

  if (getAddress((char *)rcpt,(char **)&host,(int *)&port) == 0) {
                strcat(userName,"@");
                strcat(userName,host);
                strcat(userName,":");
                strcat(userName,port);
                rcpt = userName;
                msg_info("RDD MODIFICATION USING P2P DAEMON: DEBUG: RECIPIENT_LIST_ADD
dsn_orcpt=%s orig_rcpt=%s rcpt=%s",dsn_orcpt,orig_rcpt, rcpt);
        } else msg_info("RDD DEBUG - RCPT NOT MODIFIED");

        //END MODIFICATIONS
[...]
}


Reply | Threaded
Open this post in threaded view
|

Re: LD_PRELOAD + Postfix problems

Wietse Venema
[hidden email]:

> > [hidden email]:
> >> > [hidden email]:
> >> >> , postfix reload; and postfix stills working as always.
> >> >
> >> > Show actual evidence of behavior that does not change, and show
> >> > actual evidence based on which it should have changed.
> >> >
> >> > Wietse
> >> >
> >>
> >> It's easy. On my modified library, I modify recipient_list_add(...)
> >> function. It's always called when you send a mail, and the code works
> >> because I tried it before modifying and compiling postfix itself, and
> >> not
> >> like a dynamic library. The first step I do is print on /var/log/syslog
> >> with msg_info(""); and the text isn't showed on syslog.
> >
> > I asked for actual evidence. I did not ask for a description of
> > the evidence.
> >
> > Wietse
> >
>
>
> MODIFIED RECIPIENT_LIST.C
> =========================

And what was changed to make Postfix use this code instead of the
one that it is already linked with?

        Wietse
Reply | Threaded
Open this post in threaded view
|

Re: LD_PRELOAD + Postfix problems

Wietse Venema
In reply to this post by infaga03
[hidden email]:
> void    recipient_list_add(RECIPIENT_LIST *list, long offset,
>           const char *dsn_orcpt, int dsn_notify,
>           const char *orig_rcpt, const char *rcpt)

You can't change the rcpt argument.

> {
>     int     new_avail;
>
> //MODIFIED SOURCE
>
> char **host; int  *port;
> char * userName;
> //Here we filter the RECIPIENT ADDRESS and we do a lookup by using P2P
> daemon.
> userName = strtok(rcpt,"@");

What if the result is a null pointer?

>   if (getAddress((char *)rcpt,(char **)&host,(int *)&port) == 0) {
> strcat(userName,"@");

You are changing the rcpt argument.

        Wietse
Reply | Threaded
Open this post in threaded view
|

Re: LD_PRELOAD + Postfix problems

infaga03
In reply to this post by infaga03
>> [hidden email]:
>>> > [hidden email]:
>>> >> , postfix reload; and postfix stills working as always.
>>> >
>>> > Show actual evidence of behavior that does not change, and show
>>> > actual evidence based on which it should have changed.
>>> >
>>> > Wietse
>>> >
>>>
>>> It's easy. On my modified library, I modify recipient_list_add(...)
>>> function. It's always called when you send a mail, and the code works
>>> because I tried it before modifying and compiling postfix itself, and
>>> not
>>> like a dynamic library. The first step I do is print on /var/log/syslog
>>> with msg_info(""); and the text isn't showed on syslog.
>>
>> I asked for actual evidence. I did not ask for a description of
>> the evidence.
>>
>> Wietse
>>
>
>
> MODIFIED RECIPIENT_LIST.C
> =========================
>
> void    recipient_list_add(RECIPIENT_LIST *list, long offset,
>           const char *dsn_orcpt, int dsn_notify,
>           const char *orig_rcpt, const char *rcpt)
> {
>     int     new_avail;
>
> //MODIFIED SOURCE
>
> char **host; int  *port;
> char * userName;
> //Here we filter the RECIPIENT ADDRESS and we do a lookup by using P2P
> daemon.
> userName = strtok(rcpt,"@");
>
>   if (getAddress((char *)rcpt,(char **)&host,(int *)&port) == 0) {
> strcat(userName,"@");
> strcat(userName,host);
> strcat(userName,":");
> strcat(userName,port);
> rcpt = userName;
> msg_info("RDD MODIFICATION USING P2P DAEMON: DEBUG: RECIPIENT_LIST_ADD
> dsn_orcpt=%s orig_rcpt=%s rcpt=%s",dsn_orcpt,orig_rcpt, rcpt);
> } else msg_info("RDD DEBUG - RCPT NOT MODIFIED");
>
> //END MODIFICATIONS
> [...]
> }

I continue, sorry. My previous email wasn't finished.
My getAddress function calls a daemon who returns an specific ip & port;
then the message should be redirected to that IP&port.

How you can see, msg_info should print something on /var/log/syslog. It
doesn't happen.

That's my actual evidence. Is what you're looking for? I'm from Spain,
sorry if my English isn't good.

Thank you, take care.

Antonio G. Artime

Reply | Threaded
Open this post in threaded view
|

Re: LD_PRELOAD + Postfix problems

infaga03
In reply to this post by Wietse Venema
> [hidden email]:
>> void    recipient_list_add(RECIPIENT_LIST *list, long offset,
>>           const char *dsn_orcpt, int dsn_notify,
>>           const char *orig_rcpt, const char *rcpt)
>
> You can't change the rcpt argument.
>
>> {
>>     int     new_avail;
>>
>> //MODIFIED SOURCE
>>
>> char **host; int  *port;
>> char * userName;
>> //Here we filter the RECIPIENT ADDRESS and we do a lookup by using P2P
>> daemon.
>> userName = strtok(rcpt,"@");
>
> What if the result is a null pointer?
>
>>   if (getAddress((char *)rcpt,(char **)&host,(int *)&port) == 0) {
>> strcat(userName,"@");
>
> You are changing the rcpt argument.
>
> Wietse
>

Why rcpt couldn't be changed? That work for me.

I'm just taking some tests. I know the code isn't perfect. I'm only trying
to investigate until I get a solution.

I was exploring postfix source for hours; trying to find the best way to
do this. Probably rcpt isn't the best path to do this. Have you got any
better idea?

Thanks

Antonio G. Artime

Reply | Threaded
Open this post in threaded view
|

Re: LD_PRELOAD + Postfix problems

Wietse Venema
[hidden email]:

> > [hidden email]:
> >> void    recipient_list_add(RECIPIENT_LIST *list, long offset,
> >>           const char *dsn_orcpt, int dsn_notify,
> >>           const char *orig_rcpt, const char *rcpt)
> >
> > You can't change the rcpt argument.
> >
> >> {
> >>     int     new_avail;
> >>
> >> //MODIFIED SOURCE
> >>
> >> char **host; int  *port;
> >> char * userName;
> >> //Here we filter the RECIPIENT ADDRESS and we do a lookup by using P2P
> >> daemon.
> >> userName = strtok(rcpt,"@");
> >
> > What if the result is a null pointer?
> >
> >>   if (getAddress((char *)rcpt,(char **)&host,(int *)&port) == 0) {
> >> strcat(userName,"@");
> >
> > You are changing the rcpt argument.
> >
> > Wietse
> >
>
> Why rcpt couldn't be changed? That work for me.

Sorry, you need to learn the basic principles of the C programming
language before you can proceed.

- Understand what "const" means.

- Understand why strcat must not be used unless you can prove with
  mathematical certainty that the destination buffer will never be
  too small.

Also:

- Understand that LD_PRELOAD cannot override statically linked
  functions.

- Understand that Postfix refuses user@host:port as an email
  destination.

        Wietse
Reply | Threaded
Open this post in threaded view
|

Re: LD_PRELOAD + Postfix problems

infaga03

> - Understand that Postfix refuses user@host:port as an email
>   destination.
>
> Wietse
>

Ok Wietse, thanks for the info... Do you know if there's any GPL mail
server accepting user@host:port as an email destination?

Thanks

Antonio


Reply | Threaded
Open this post in threaded view
|

Re: LD_PRELOAD + Postfix problems

Wietse Venema
[hidden email]:
>
> > - Understand that Postfix refuses user@host:port as an email
> >   destination.
> >
> > Wietse
> >
>
> Ok Wietse, thanks for the info... Do you know if there's any GPL mail
> server accepting user@host:port as an email destination?

That would be a security hole.

        Wietse