Download raw body.
smtpd: better default syslog tag for filters
Hello,
Martijn van Duren <openbsd+tech@list.imperialat.at> wrote:
> EHLO,
>
> While reasonable for my initial testing, having the tag be set to the
> name of the processor, instead of the name of the command might be
> a better default choice. This also shaves of a bit of code.
>
> OK?
makes sense, and it's nicer than now, okay op@
> martijn@
>
> diff /usr/src
> path + /usr/src
> commit - a9b792a8dce6145cbe526f847ad0f84cf9afd558
> blob - 02313181cc00765d3a2051ab92cd81ca15114961
> file + usr.sbin/smtpd/parse.y
> --- usr.sbin/smtpd/parse.y
> +++ usr.sbin/smtpd/parse.y
> @@ -454,7 +454,7 @@ PROC STRING STRING {
> processor->command = $3;
> } proc_params {
> if (!processor->tag)
> - processor->tag = processor_maketag(processor->command);
> + processor->tag = processor_maketag($2);
> dict_set(conf->sc_filter_processes_dict, $2, processor);
> processor = NULL;
> }
> @@ -1956,7 +1956,7 @@ FILTER STRING PROC_EXEC STRING {
> dict_set(conf->sc_filters_dict, $2, filter_config);
> } proc_params {
> if (!processor->tag)
> - processor->tag = processor_maketag(processor->command);
> + processor->tag = processor_maketag(filter_config->proc);
> dict_set(conf->sc_filter_processes_dict, filter_config->proc, processor);
> processor = NULL;
> filter_config = NULL;
> @@ -3685,22 +3685,16 @@ config_lo_mask_source(struct listen_opts *lo) {
>
> /* Best effort. If it's ugly: use the tag parameter */
> static const char *
> -processor_maketag(const char *cmd)
> +processor_maketag(const char *name)
> {
> - char path[PATH_MAX];
> - int i, j;
> - char *tag;
> + char tag[TAG_MAX + 1];
> + size_t i, j;
>
> - strlcpy(path, cmd, sizeof(path));
> - for (i = 0; path[i] != '\0' && !isspace(path[i]); i++)
> - continue;
> - path[i] = '\0';
> - tag = basename(path);
> - for (i = j = 0; tag[j] != '\0'; j++) {
> - if (isalpha(tag[j]))
> - tag[i++] = tag[j];
> + for (i = j = 0; name[i] != '\0' && j < sizeof(tag) - 1; i++) {
> + if (isalnum(name[i]))
> + tag[j++] = name[i];
> }
> - tag[i] = '\0';
> + tag[j] = '\0';
>
> - return xstrndup(tag, TAG_MAX);
> + return xstrdup(tag);
> }
> commit - a9b792a8dce6145cbe526f847ad0f84cf9afd558
> blob - 1cdaf067c5585ca69bb19baf72014d29adfe6747
> file + usr.sbin/smtpd/smtpd.conf.5
> --- usr.sbin/smtpd/smtpd.conf.5
> +++ usr.sbin/smtpd/smtpd.conf.5
> @@ -915,8 +915,7 @@ with which all log messages of this processor are writ
> .Ar tag
> is limited to 32 letters.
> The default is a best effort representation of the
> -.Ar command
> -name.
> +.Ar proc-name .
> .El
> .It Ic queue Cm compression
> Store queue files in a compressed format.
> commit - a9b792a8dce6145cbe526f847ad0f84cf9afd558
> blob - 3574db4c03d611801672016b1d0d4314746802cf
> file + usr.sbin/smtpd/smtpd.h
> --- usr.sbin/smtpd/smtpd.h
> +++ usr.sbin/smtpd/smtpd.h
> @@ -1712,7 +1712,6 @@ int xasprintf(char **, const char *, ...)
> void *xmalloc(size_t);
> void *xcalloc(size_t, size_t);
> char *xstrdup(const char *);
> -char *xstrndup(const char *, size_t);
> void *xmemdup(const void *, size_t);
> char *strip(char *);
> int io_xprint(struct io *, const char *);
> commit - a9b792a8dce6145cbe526f847ad0f84cf9afd558
> blob - ee4520d863e2434f5d047ec24be1716f05cf20c9
> file + usr.sbin/smtpd/util.c
> --- usr.sbin/smtpd/util.c
> +++ usr.sbin/smtpd/util.c
> @@ -76,17 +76,6 @@ xstrdup(const char *str)
> return (r);
> }
>
> -char *
> -xstrndup(const char *str, size_t maxlen)
> -{
> - char *r;
> -
> - if ((r = strndup(str, maxlen)) == NULL)
> - fatal("strdup");
> -
> - return (r);
> -}
> -
> void *
> xmemdup(const void *ptr, size_t size)
> {
smtpd: better default syslog tag for filters