If someone wants to try … Make sure you have libmilter installed.
Compile and run:

c99 -Wall nosetsymlist.c -lmilter -o nosetsymlist
./nosetsymlist

Enable in /etc/postfix/main.cf with:

smtpd_milters = inet:localhost:3000

Then both requested macros, _ and {client_port}, are *not* available
during connect. If I request these macros in /etc/postfix/main.cf with

milter_connect_macros = _ {client_port}

then they *are* available and do get printed. Either smfi_setsymlist
doesn’t do anything, or – perhaps more likely – I’m making a mistake!
Very grateful for any hints.


#include <stdio.h>
#include <assert.h>
#include "libmilter/mfapi.h"

sfsistat test_negotiate(
    SMFICTX *ctx,
    unsigned long f0, unsigned long f1, unsigned long f2, unsigned long f3,
    unsigned long *pf0, unsigned long *pf1, unsigned long *pf2, unsigned long 
*pf3
) {
    *pf0 = *pf1 = *pf2 = *pf3 = 0;

    int status = smfi_setsymlist(ctx, SMFIM_CONNECT, "_ {client_port}");
    assert(status == MI_SUCCESS);

    return SMFIS_CONTINUE;
}

sfsistat test_connect(SMFICTX *ctx, char *hostname, struct sockaddr *hostaddr) {
    char *_macro = smfi_getsymval(ctx, "_");
    printf("_: %s\n", _macro == NULL ? "NULL" : _macro);

    char *cpmacro = smfi_getsymval(ctx, "{client_port}");
    printf("{client_port}: %s\n", cpmacro == NULL ? "NULL" : cpmacro);

    return SMFIS_CONTINUE;
}

int main() {
    int connstatus = smfi_setconn("inet:3000@localhost");
    assert(connstatus == MI_SUCCESS);

    int regstatus = smfi_register((struct smfiDesc) {
        .xxfi_name = "nosetsymlist",
        .xxfi_version = SMFI_VERSION,
        .xxfi_connect = test_connect,
        .xxfi_negotiate = test_negotiate,
    });
    assert(regstatus == MI_SUCCESS);

    return smfi_main();
}

Reply via email to