]> granicus.if.org Git - sudo/commitdiff
Add syslog_maxlen to control the max size of syslog messages.
authorTodd C. Miller <Todd.Miller@courtesan.com>
Tue, 18 Oct 2016 21:51:47 +0000 (15:51 -0600)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Tue, 18 Oct 2016 21:51:47 +0000 (15:51 -0600)
doc/sudoers.cat
doc/sudoers.man.in
doc/sudoers.mdoc.in
plugins/sudoers/def_data.c
plugins/sudoers/def_data.h
plugins/sudoers/def_data.in
plugins/sudoers/defaults.c
plugins/sudoers/logging.c

index b02168aa742a9ff283dfd9997fd212af20fb0b4c..435d95001112eb1cbc90ddb975968fe04b18df9d 100644 (file)
@@ -1642,6 +1642,23 @@ S\bSU\bUD\bDO\bOE\bER\bRS\bS O\bOP\bPT\bTI\bIO\bON\bNS\bS
                        See _\bs_\by_\bs_\bl_\bo_\bg_\b__\bb_\ba_\bd_\bp_\br_\bi for the list of supported syslog
                        priorities.
 
+     syslog_maxlen     On many systems, syslog(3) has a relatively small log
+                       buffer.  IETF RFC 5424 states that syslog servers must
+                       support messages of at least 480 bytes and should
+                       support messages up to 2048 bytes.  By default, s\bsu\bud\bdo\boe\ber\brs\bs
+                       creates log messages up to 980 bytes which corresponds
+                       to the historic BSD syslog implementation which used a
+                       1024 byte buffer to store the message, date, hostname
+                       and program name.  To prevent syslog messages from
+                       being truncated, s\bsu\bud\bdo\boe\ber\brs\bs will split up log messages
+                       that are larger than _\bs_\by_\bs_\bl_\bo_\bg_\b__\bm_\ba_\bx_\bl_\be_\bn bytes.  When a
+                       message is split, additional parts will include the
+                       string ``(command continued)'' after the user name and
+                       before the continued command line arguments.
+
+                       This setting is only supported by version 1.8.19 or
+                       higher.
+
      sudoers_locale    Locale to use when parsing the sudoers file, logging
                        commands, and sending email.  Note that changing the
                        locale may affect how sudoers is interpreted.  Defaults
@@ -2027,15 +2044,13 @@ L\bLO\bOG\bG F\bFO\bOR\bRM\bMA\bAT\bT
 
    N\bNo\bot\bte\bes\bs o\bon\bn l\blo\bog\bgg\bgi\bin\bng\bg v\bvi\bia\ba s\bsy\bys\bsl\blo\bog\bg
      By default, s\bsu\bud\bdo\boe\ber\brs\bs logs messages via syslog(3).  The _\bd_\ba_\bt_\be, _\bh_\bo_\bs_\bt_\bn_\ba_\bm_\be, and
-     _\bp_\br_\bo_\bg_\bn_\ba_\bm_\be fields are added by the syslog daemon, not s\bsu\bud\bdo\boe\ber\brs\bs itself.  As
-     such, they may vary in format on different systems.
+     _\bp_\br_\bo_\bg_\bn_\ba_\bm_\be fields are added by the system's s\bsy\bys\bsl\blo\bog\bg() function, not s\bsu\bud\bdo\boe\ber\brs\bs
+     itself.  As such, they may vary in format on different systems.
 
-     On most systems, syslog(3) has a relatively small log buffer.  To prevent
-     the command line arguments from being truncated, s\bsu\bud\bdo\boe\ber\brs\bs will split up
-     log messages that are larger than 960 characters (not including the date,
-     hostname, and the string ``sudo'').  When a message is split, additional
-     parts will include the string ``(command continued)'' after the user name
-     and before the continued command line arguments.
+     The maximum size of syslog messages varies from system to system.  The
+     _\bs_\by_\bs_\bl_\bo_\bg_\b__\bm_\ba_\bx_\bl_\be_\bn setting can be used to change the maximum syslog message
+     size from the default value of 980 bytes.  For more information, see the
+     description of _\bs_\by_\bs_\bl_\bo_\bg_\b__\bm_\ba_\bx_\bl_\be_\bn.
 
    N\bNo\bot\bte\bes\bs o\bon\bn l\blo\bog\bgg\bgi\bin\bng\bg t\bto\bo a\ba f\bfi\bil\ble\be
      If the _\bl_\bo_\bg_\bf_\bi_\bl_\be option is set, s\bsu\bud\bdo\boe\ber\brs\bs will log to a local file, such as
@@ -2592,4 +2607,4 @@ D\bDI\bIS\bSC\bCL\bLA\bAI\bIM\bME\bER\bR
      file distributed with s\bsu\bud\bdo\bo or https://www.sudo.ws/license.html for
      complete details.
 
-Sudo 1.8.18                     August 31, 2016                    Sudo 1.8.18
+Sudo 1.8.18                    October 18, 2016                    Sudo 1.8.18
index e00cc064c59c02e0f684272ea8b78cd945341826..f83d5d65062c2d3d71c842f793776e08b579e0a2 100644 (file)
@@ -21,7 +21,7 @@
 .\" Agency (DARPA) and Air Force Research Laboratory, Air Force
 .\" Materiel Command, USAF, under agreement number F39502-99-1-0512.
 .\"
-.TH "SUDOERS" "5" "August 31, 2016" "Sudo @PACKAGE_VERSION@" "File Formats Manual"
+.TH "SUDOERS" "5" "October 18, 2016" "Sudo @PACKAGE_VERSION@" "File Formats Manual"
 .nh
 .if n .ad l
 .SH "NAME"
@@ -3367,6 +3367,28 @@ See
 \fIsyslog_badpri\fR
 for the list of supported syslog priorities.
 .TP 18n
+syslog_maxlen
+On many systems,
+syslog(3)
+has a relatively small log buffer.
+IETF RFC 5424 states that syslog servers must support messages of
+at least 480 bytes and should support messages up to 2048 bytes.
+By default,
+\fBsudoers\fR
+creates log messages up to 980 bytes which corresponds to the
+historic BSD syslog implementation which used a 1024 byte buffer
+to store the message, date, hostname and program name.
+To prevent syslog messages from being truncated,
+\fBsudoers\fR
+will split up log messages that are larger than
+\fIsyslog_maxlen\fR
+bytes.
+When a message is split, additional parts will include the string
+\(Lq(command continued)\(Rq
+after the user name and before the continued command line arguments.
+.sp
+This setting is only supported by version 1.8.19 or higher.
+.TP 18n
 sudoers_locale
 Locale to use when parsing the sudoers file, logging commands, and
 sending email.
@@ -4121,22 +4143,20 @@ The
 \fIhostname\fR,
 and
 \fIprogname\fR
-fields are added by the syslog daemon, not
+fields are added by the system's
+\fBsyslog\fR()
+function, not
 \fBsudoers\fR
 itself.
 As such, they may vary in format on different systems.
 .PP
-On most systems,
-syslog(3)
-has a relatively small log buffer.
-To prevent the command line arguments from being truncated,
-\fBsudoers\fR
-will split up log messages that are larger than 960 characters
-(not including the date, hostname, and the string
-\(Lqsudo\(Rq).
-When a message is split, additional parts will include the string
-\(Lq(command continued)\(Rq
-after the user name and before the continued command line arguments.
+The maximum size of syslog messages varies from system to system.
+The
+\fIsyslog_maxlen\fR
+setting can be used to change the maximum syslog message size
+from the default value of 980 bytes.
+For more information, see the description of
+\fIsyslog_maxlen\fR.
 .SS "Notes on logging to a file"
 If the
 \fIlogfile\fR
index da20c82b883d4eae38eb0a7d38f2cedb2016a34d..b8405ddae0404e68bff5f28eeb1854ba9015e556 100644 (file)
@@ -19,7 +19,7 @@
 .\" Agency (DARPA) and Air Force Research Laboratory, Air Force
 .\" Materiel Command, USAF, under agreement number F39502-99-1-0512.
 .\"
-.Dd August 31, 2016
+.Dd October 18, 2016
 .Dt SUDOERS @mansectform@
 .Os Sudo @PACKAGE_VERSION@
 .Sh NAME
@@ -3145,6 +3145,27 @@ Defaults to
 See
 .Em syslog_badpri
 for the list of supported syslog priorities.
+.It syslog_maxlen
+On many systems,
+.Xr syslog 3
+has a relatively small log buffer.
+IETF RFC 5424 states that syslog servers must support messages of
+at least 480 bytes and should support messages up to 2048 bytes.
+By default,
+.Nm
+creates log messages up to 980 bytes which corresponds to the
+historic BSD syslog implementation which used a 1024 byte buffer
+to store the message, date, hostname and program name.
+To prevent syslog messages from being truncated,
+.Nm
+will split up log messages that are larger than
+.Em syslog_maxlen
+bytes.
+When a message is split, additional parts will include the string
+.Dq Pq command continued
+after the user name and before the continued command line arguments.
+.Pp
+This setting is only supported by version 1.8.19 or higher.
 .It sudoers_locale
 Locale to use when parsing the sudoers file, logging commands, and
 sending email.
@@ -3824,22 +3845,20 @@ The
 .Em hostname ,
 and
 .Em progname
-fields are added by the syslog daemon, not
-.Nm sudoers
+fields are added by the system's
+.Fn syslog
+function, not
+.Nm
 itself.
 As such, they may vary in format on different systems.
 .Pp
-On most systems,
-.Xr syslog 3
-has a relatively small log buffer.
-To prevent the command line arguments from being truncated,
-.Nm
-will split up log messages that are larger than 960 characters
-(not including the date, hostname, and the string
-.Dq sudo ) .
-When a message is split, additional parts will include the string
-.Dq Pq command continued
-after the user name and before the continued command line arguments.
+The maximum size of syslog messages varies from system to system.
+The
+.Em syslog_maxlen
+setting can be used to change the maximum syslog message size
+from the default value of 980 bytes.
+For more information, see the description of
+.Em syslog_maxlen .
 .Ss Notes on logging to a file
 If the
 .Em logfile
index b433a7fe9eac33264882e543591d4222a4b8ced5..ec749637ae88e493e30848f43cc901acd0c95409 100644 (file)
@@ -418,6 +418,10 @@ struct sudo_defs_types sudo_defs_table[] = {
        "match_group_by_gid", T_FLAG,
        N_("Resolve groups in sudoers and match on the group ID, not the name"),
        NULL,
+    }, {
+       "syslog_maxlen", T_UINT,
+       N_("Log entries larger than this value will be split into multiple syslog messages"),
+       NULL,
     }, {
        NULL, 0, NULL
     }
index 3032cdee6141e79cb557e22849d5b893e3238aa3..d16c17ccb2f1a2fd405c0402e014586427c4176b 100644 (file)
 #define def_ignore_logfile_errors (sudo_defs_table[I_IGNORE_LOGFILE_ERRORS].sd_un.flag)
 #define I_MATCH_GROUP_BY_GID    98
 #define def_match_group_by_gid  (sudo_defs_table[I_MATCH_GROUP_BY_GID].sd_un.flag)
+#define I_SYSLOG_MAXLEN         99
+#define def_syslog_maxlen       (sudo_defs_table[I_SYSLOG_MAXLEN].sd_un.uival)
 
 enum def_tuple {
        never,
index bc23912735a06e0138a722bb9146db5e532b71a9..1190fefed407aa3ed1892d829cf43bfa540a81c1 100644 (file)
@@ -310,3 +310,6 @@ ignore_logfile_errors
 match_group_by_gid
        T_FLAG
        "Resolve groups in sudoers and match on the group ID, not the name"
+syslog_maxlen
+       T_UINT
+       "Log entries larger than this value will be split into multiple syslog messages"
index 487791798225a7a85d8dad7c480f5268033bb8ee..6ee93d3d757bfdd0e76bcb6f85b1ff76e4daa0fb 100644 (file)
@@ -559,6 +559,7 @@ init_defaults(void)
        goto oom;
     def_set_utmp = true;
     def_pam_setcred = true;
+    def_syslog_maxlen = MAXSYSLOGLEN;
 
     /* Reset the locale. */
     if (!firsttime) {
index e741f38dcab40493b29263adb8a87c8d5717dbae..64bd794e0b49254363ad5f8a53458b915e342836 100644 (file)
@@ -72,14 +72,18 @@ static char *new_logline(const char *, int);
 static void
 mysyslog(int pri, const char *fmt, ...)
 {
-    char buf[MAXSYSLOGLEN+1];
+    char *buf;
     va_list ap;
     debug_decl(mysyslog, SUDOERS_DEBUG_LOGGING)
 
     va_start(ap, fmt);
     openlog("sudo", 0, def_syslog);
-    vsnprintf(buf, sizeof(buf), fmt, ap);
-    syslog(pri, "%s", buf);
+    if (vasprintf(&buf, fmt, ap) == -1) {
+       sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
+    } else {
+       syslog(pri, "%s", buf);
+       free(buf);
+    }
     va_end(ap);
     closelog();
     debug_return;
@@ -87,7 +91,7 @@ mysyslog(int pri, const char *fmt, ...)
 
 /*
  * Log a message to syslog, pre-pending the username and splitting the
- * message into parts if it is longer than MAXSYSLOGLEN.
+ * message into parts if it is longer than syslog_maxlen.
  */
 static void
 do_syslog(int pri, char *msg)
@@ -104,7 +108,7 @@ do_syslog(int pri, char *msg)
      * Log the full line, breaking into multiple syslog(3) calls if necessary
      */
     fmt = _("%8s : %s");
-    maxlen = MAXSYSLOGLEN - (strlen(fmt) - 5 + strlen(user_name));
+    maxlen = def_syslog_maxlen - (strlen(fmt) - 5 + strlen(user_name));
     for (p = msg; *p != '\0'; ) {
        len = strlen(p);
        if (len > maxlen) {
@@ -132,7 +136,7 @@ do_syslog(int pri, char *msg)
            p += len;
        }
        fmt = _("%8s : (command continued) %s");
-       maxlen = MAXSYSLOGLEN - (strlen(fmt) - 5 + strlen(user_name));
+       maxlen = def_syslog_maxlen - (strlen(fmt) - 5 + strlen(user_name));
     }
 
     sudoers_setlocale(oldlocale, NULL);