HPlogo Sendmail 8.13.3 Programmer's Guide: HP-UX 11i v1 and HP-UX 11i v2 > Chapter 2 Milter APIs

Data Access APIs

» 

Technical documentation

Complete book in PDF

 » Table of Contents

You can call the data access APIs from within the filter-defined callbacks to access information about the current connection or message.

Following are the data access APIs:

  • smfi_getsymval()

  • smfi_getpriv()

  • smfi_setpriv()

  • smfi_setreply()

  • smfi_setmlreply()

The following sections discuss the data access functions in detail.

The smfi_getsymval() API

You can use the smfi_getsymval() API to get the value of a Sendmail macro. The macros that are defined depend on when smfi_getsymval() is called. You can call smfi_getsymval() from any of the xxfi_* callbacks.

The declaration of smfi_getsymval() is as follows:

#include <libmilter/mfapi.h>
char* smfi_getsymval(
         SMFICTX *ctx,
         char *symname
);

Table 2-1 “The xxfi_flags Field Values” lists the Sendmail macros that you can use with the xxfi_* callbacks.

Table 2-2 Sendmail Macros

xxfi_* CallbacksSendmail Macros
xxfi_connect()daemon_name, if_name, if_addr, j, _
xxfi_helo()tls_version, cipher, cipher_bits, cert_subject, cert_issuer
xxfi_envfrom()i, auth_type, auth_authen, auth_ssf, auth_author, mail_mailer, mail_host, mail_addr
xxfi_envrcpt()rcpt_mailer, rcpt_host, rcpt_addr

 

All macros specified with the xxfi_connect() and xxfi_helo() callbacks are active from the point they are received until the end of the connection. All macros specified with the callback xxfi_envfrom() are active from the point they are received until the end of the message. All macros specified with the callbacks xxfi_envrcpt() are active for each recipient.

You can use the confMILTER_MACROS_* options in the Sendmail .mc file to change the macro list. Depending on when Sendmail sets the macros, you can determine the scope of these macros.

Arguments

You must call smfi_getsymval() with the following argument:

ctx

Specifies a opaque context structure.

symname

Denotes the name of a Sendmail macro. You can optionally enclose single letter macros and long macro names in braces (“{“ and “}”), similar to the macros in the sendmail.cf file.

Return Value

smfi_getsymval() returns the value of the given macro as a null-terminated string or a NULL value if the macro is not defined.

The smfi_getpriv() API

You can use the smfi_getpriv() API to get the connection-specific data pointer for a connection. You can call smfi_getpriv() in any of the xxfi_* callbacks.

The declaration of smfi_getpriv() is as follows:

#include <libmilter/mfapi.h>
void* smfi_getpriv(
          SMFICTX *ctx
);

Argument

You must call smfi_getpriv() with the argument ctx, which specifies an opaque context structure.

Return Value

smfi_getpriv() returns the private data pointer stored by an earlier call to the smfi_setpriv() API, or NULL if none has been set.

The smfi_setpriv() API

You can use smfi_setpriv() to set the private data pointer for a connection. You can call smfi_setpriv() in any of the xxfi_* callbacks.

The declaration of smfi_setpriv() is as follows:

#include <libmilter/mfapi.h>
int smfi_setpriv(
       SMFICTX *ctx,
       void *privatedata
);

Only one private data pointer is available per connection; multiple calls to smfi_setpriv() with different values result in loss of previous values. Before a filter terminates, it must release the private data and set the pointer to NULL.

Arguments

You must call smfi_setpriv() with the following arguments:

ctx

Specifies the opaque context structure.

privatedata

Denotes a pointer to private data. This value is returned by subsequent calls to the smfi_getpriv() API using ctx.

Return Values

smfi_setpriv() returns MI_FAILURE if ctx is an invalid context structure. smfi_setpriv() returns MI_SUCCESS on success.

The smfi_setreply() API

You can use the smfi_setreply() API to set the default SMTP error reply code. Only 4xx and 5xx replies are accepted. You can call smfi_setreply() from any of the xxfi_* callbacks other than the xxfi_connect() callback. smfi_setreply() directly sets the SMTP error reply code for a connection. If subsequent error occurs because of an action taken by the filter, analyze the error code to identify the problem.

The declaration of smfi_setreply() is as follows:

#include <libmilter/mfapi.h>
int smfi_setreply(
         SMFICTX *ctx,
         char *rcode,
         char *xcode,
         char *message
);

Following are some points to consider regarding smfi_setreply():

  • Values passed to smfi_setreply() are not checked for standards compliance.

  • The message parameter must contain only printable characters; other characters can result in undefined behavior. For example, CR or LR causes the call to fail, a single % (percentage) character causes the text to be ignored (if a % is required in a string, use %% similar to the usage in printf (3)).

  • If the reply code (rcode) is 4XX but SMFI-REJECT is used for the message, the custom reply is not used.

    Similarly, if the reply code (rcode) is 5XX code but SMFI_TEMPFAIL is used for the message, the custom reply is not used.

    NOTE: An error is not returned to the Milter program in neither of the previous two instances; libmilter silently ignores the reply code.

    For details on reply codes and their meanings, see RFC 821 (SIMPLE MAIL TRANSFER PROTOCOL) or 2821 (Simple Mail Transfer Protocol) and RFC 1893 (Enhanced Mail System Status Codes) or 2034 (SMTP Service Extension for Returning Enhanced Error Codes).

  • If the Milter program returns SMFI_TEMPFAIL and sets the reply code to 421, the SMTP server terminates the SMTP session with a 421 error code.

Arguments

You must call smfi_setreply() with the following arguments:

ctx

Specifies an opaque context structure.

rcode

Specifies a 3-digit (RFC 821 or RFC 2821) SMTP reply code as a null terminated string. You must not assign rcode to NULL, and rcode must be a valid 4XX or 5XX reply code.

xcode

Specifies an extended (RFC 1893 or RFC 2034) reply code. If xcode is NULL, the extended code is not used. xcode must conform to RFC 1893 or RFC 2034.

message

Specifies the text part of the SMTP reply. If the message is NULL, an empty message is used.

Return Value

smfi_setreply() fails because of the following reasons and returns MI_FAILURE:

  • The rcode argument or xcode argument is invalid.

  • A memory-allocation failure occurs.

smfi_setreply() returns MI_SUCCESS on success.

The smfi_setmlreply() API

You can use the smfi_setmlreply() API to set the default SMTP error reply code to a multi-line response. You can set only 4xx and 5xx reply codes.

You can call smfi_setmlreply() from any of the xxfi_* callbacks except the xxfi_connect() callback. smfi_setmlreply() directly sets the SMTP error reply code for a connection to the given lines after xcode. You must terminate the list of arguments that you pass to smfi_setmlreply() with a NULL value. The error code is used on subsequent error replies resulting from actions taken by the filter program.

The declaration of smfi_setmlreply() is as follows:

#include <libmilter/mfapi.h>
int smfi_setmlreply(
        SMFICTX *ctx,
        char *rcode,
        char *xcode,
        ...
);

Following are some points to consider regarding smfi_setmlreply():

  • Values passed to smfi_setmlreply() are not checked for standards compliance.

  • The message parameter must contain only printable characters; other characters can result in a undefined behavior. For example, CR or LR causes the call to fail, a single % (percentage) character causes the text to be ignored (if a % is required in a string, use %% similar to the usage in printf (3)).

  • If the reply code (rcode) is 4XX but SMFI-REJECT is used for the message, the custom reply is not used.

    Similarly, if the reply code (rcode) is 5XX code but SMFI_TEMPFAIL is used for the message, the custom reply is not used.

    NOTE: An error is not returned to the Milter program in neither of the previous two cases; libmilter silently ignores the reply code.

    For details about reply codes and their meanings, see RFC 821 or 2821, and RFC 1893 or RFC 2034.

  • If the Milter program returns SMFI_TEMPFAIL and sets the reply code to 421, the SMTP server terminates the SMTP session with a 421 error code.

Arguments

You must call smfi_setmlreply() with the following argument:

ctx

Specifies an opaque context structure.

rcode

Specifies the 3-digit SMTP reply code as specified in RFC 821 (Simple Mail Transfer Protocol) or 2821 (Simple Mail Transfer Protocol). rcode is a null-terminated string and must be a valid 4XX or 5XX reply code. You must not set rcode to a NULL value.

xcode

Specifies the extended reply code as specified in RFC 1893 (Enhanced Mail System Status Codes) or 2034 (SMTP Service Extension for Returning Enhanced Error Codes). If xcode is NULL, an extended code is not used; otherwise, xcode must conform to RFC 1893 or RFC 2034.

...

Specifies the remaining arguments, that are single lines of text (upto 32 arguments), which is used as the text part of the SMTP reply. The list must be NULL terminated.

Return Values

smfi_setmlreply() fails because of the following reasons and returns MI_FAILURE:

  • The rcode or xcode argument is invalid.

  • A memory-allocation failure occurs.

  • A text line contains a carriage return (CR) or line feed (LF).

  • The length of any text is more than the MAXREPLYLEN (980) value.

  • The reply contains more than 32 lines of text.

smfi_setmlreply() returns MI_SUCCESS on success.