OSEC

Neohapsis is currently accepting applications for employment. For more information, please visit our website www.neohapsis.com or email hr@neohapsis.com
 
From: Oles' Hnatkevych (gnutfc.kiev.ua)
Date: Wed Jan 02 2002 - 03:29:54 CST

  • Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

    Hello,

      My mail is intended mainly for postfix developers/hackers.

      There's a simple way to make separate message size limit
      depending on the sender/recipient address. I've made some
      changes to the smtpd daemon sources, and it works for me.
      However I do not know are they correct or not, and
      if it is a good idea, I believe many postfix users would
      want to make use of this feature when it will be included
      in the main source tree properly and correctly. And I would
      like to know your comments about the feature and the way
      I've implemented it.

      Looking a bit through the sources I found that the best
      way to do it is by implementing new rule to the access
      tables, so with "OK" and "RELAY" (which is the same to smtpd)
      we have a new records with "SIZE=xxx", where xxx is the
      size in kylobytes. The changes to the smtpd sources are:

      File smtpd.h contains a definition of the record SMTPD_STATE,
      and idea is to use a new field "state->var_message_limit"
      in the record instead of the global "var_message_limit".
      It defaults to the global variable, and is initialized
      by smtpd_state_init() function, and is updated when
      the search is made in function check_table_result() in
      smtpd_check.c.

      However there are some caveats about that. The RCPT command
      is processed after MAIL command. So the SIZE=xxx for recipient
      address will override the size for the sender address. More,
      to use the restriction on recipient addresses,
      "smtpd_delay_reject = no" has to be present in main.cf.

      ... are there any other MTA's that can make mail size restrictions
      depending on sender/recipient?

      The summary patch follows:
      
    ----------------------//-------------------------
    *** smtpd.c Thu Nov 15 16:52:50 2001
    --- /home/gnut/posfix-patch/smtpd.c Wed Jan 2 11:19:52 2002
    ***************
    *** 439,447 ****
          state->protocol = "ESMTP";
          smtpd_chat_reply(state, "250-%s", var_myhostname);
          smtpd_chat_reply(state, "250-PIPELINING");
    ! if (var_message_limit)
            smtpd_chat_reply(state, "250-SIZE %lu",
    ! (unsigned long) var_message_limit); /* XXX */
          else
            smtpd_chat_reply(state, "250-SIZE");
          smtpd_chat_reply(state, "250-ETRN");
    --- 439,447 ----
          state->protocol = "ESMTP";
          smtpd_chat_reply(state, "250-%s", var_myhostname);
          smtpd_chat_reply(state, "250-PIPELINING");
    ! if (state->var_message_limit)
            smtpd_chat_reply(state, "250-SIZE %lu",
    ! (unsigned long) state->var_message_limit); /* XXX */
          else
            smtpd_chat_reply(state, "250-SIZE");
          smtpd_chat_reply(state, "250-ETRN");
    ***************
    *** 791,796 ****
    --- 791,802 ----
                return (-1);
            }
          }
    + if ((SMTPD_STAND_ALONE(state) || var_smtpd_delay_reject == 0)
    + && (err = smtpd_check_size(state, state->msg_size)) != 0) {
    + smtpd_chat_reply(state, "%s", err);
    + return (-1);
    + }
    +
      
          /*
           * Store the recipient. Remember the first one.
    *** smtpd.h Wed Jan 2 11:20:11 2002
    --- /home/gnut/posfix-patch/smtpd.h Wed Jan 2 11:19:52 2002
    ***************
    *** 66,71 ****
    --- 66,72 ----
          char *where;
          int recursion;
          off_t msg_size;
    + off_t var_message_limit;
          int junk_cmds;
      #ifdef USE_SASL_AUTH
          char *sasl_mechanism_list;
    *** smtpd_check.c Tue Jul 31 17:26:41 2001
    --- /home/gnut/posfix-patch/smtpd_check.c Wed Jan 2 11:19:52 2002
    ***************
    *** 1290,1295 ****
    --- 1290,1306 ----
          if (strcasecmp(value, "OK") == 0 || strcasecmp(value, "RELAY") == 0)
            return (SMTPD_CHECK_OK);
      
    + if (strncasecmp(value, "SIZE=",5) == 0) {
    + char * value_size = mystrdup(value+5);
    + if ((state->var_message_limit = off_cvt_string(value + 5)) < 0) {
    + state->var_message_limit = var_message_limit;
    + } else {
    + state->var_message_limit *= 1024;
    + }
    + return (SMTPD_CHECK_OK);
    + }
    +
          /*
           * Unfortunately, maps must be declared ahead of time so they can be
           * opened before we go to jail. We could insist that the RHS can only
    ***************
    *** 2161,2167 ****
           */
      #define BLOCKS(x) ((x) / fsbuf.block_size)
      
    ! if (var_message_limit > 0 && size > var_message_limit) {
            (void) smtpd_check_reject(state, MAIL_ERROR_POLICY,
                                      "552 Message size exceeds fixed limit");
            return (STR(error_text));
    --- 2172,2178 ----
           */
      #define BLOCKS(x) ((x) / fsbuf.block_size)
      
    ! if (state->var_message_limit > 0 && size > state->var_message_limit) {
            (void) smtpd_check_reject(state, MAIL_ERROR_POLICY,
                                      "552 Message size exceeds fixed limit");
            return (STR(error_text));
    *** smtpd_state.c Sat Nov 25 03:03:09 2000
    --- /home/gnut/posfix-patch/smtpd_state.c Wed Jan 2 11:19:52 2002
    ***************
    *** 90,95 ****
    --- 90,96 ----
          state->where = SMTPD_AFTER_CONNECT;
          state->recursion = 0;
          state->msg_size = 0;
    + state->var_message_limit = var_message_limit;
          state->junk_cmds = 0;
      
      #ifdef USE_SASL_AUTH
    ----------------------//-------------------------

    With best wishes, Oles' Hnatkevych, http://gnut.kiev.ua, gnutfc.kiev.ua

    -
    To unsubscribe, send mail to majordomopostfix.org with content
    (not subject): unsubscribe postfix-users