From e911f24978ffe03577079badeef02cfc5e9aa296 Mon Sep 17 00:00:00 2001 From: Sebastian Wiedenroth Date: Sat, 24 Mar 2018 00:03:22 +0000 Subject: [PATCH] 9556 logadm timestamps should not leak into the configfile Reviewed by: Toomas Soome Reviewed by: Andy Fiddaman Approved by: Robert Mustacchi --- usr/src/cmd/logadm/conf.c | 18 +++++++--- usr/src/cmd/logadm/lut.c | 4 --- usr/src/cmd/logadm/tester | 86 +++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 98 insertions(+), 10 deletions(-) diff --git a/usr/src/cmd/logadm/conf.c b/usr/src/cmd/logadm/conf.c index aa877d3dd2..25bcc4f63d 100644 --- a/usr/src/cmd/logadm/conf.c +++ b/usr/src/cmd/logadm/conf.c @@ -22,6 +22,7 @@ /* * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright 2013, Joyent, Inc. All rights reserved. + * Copyright 2018 Sebastian Wiedenroth */ /* @@ -82,6 +83,7 @@ struct confinfo { }; #define CONFF_DELETED 1 /* entry should be deleted on write back */ +#define CONFF_TSONLY 2 /* entry should only be in timestamps file */ static struct confinfo *Confinfo; /* the entries in the config file */ static struct confinfo *Confinfolast; /* end of list */ @@ -178,6 +180,7 @@ conf_scan(const char *fname, char *buf, int buflen, int timescan) { int ret = 1; int lineno = 0; + int flags = 0; char *line; char *eline; char *ebuf; @@ -298,7 +301,11 @@ conf_scan(const char *fname, char *buf, int buflen, int timescan) * the case where the logname is not the same as * the log file name. */ - fillconflist(lineno, entry, opts, comment, 0); + flags = 0; + if (cp == NULL) + flags = CONFF_TSONLY; + fillconflist(lineno, entry, opts, comment, + flags); } LOCAL_ERR_END } @@ -655,9 +662,6 @@ conf_print(FILE *cstream, FILE *tstream) if (cp->cf_flags & CONFF_DELETED) continue; if (cp->cf_entry) { - opts_printword(cp->cf_entry, cstream); - if (cp->cf_opts) - opts_print(cp->cf_opts, cstream, exclude_opts); /* output timestamps to tstream */ if (tstream != NULL && (timestamp = opts_optarg(cp->cf_opts, "P")) != NULL) { @@ -666,6 +670,12 @@ conf_print(FILE *cstream, FILE *tstream) opts_printword(timestamp, tstream); (void) fprintf(tstream, "\n"); } + if (cp->cf_flags & CONFF_TSONLY) + continue; + + opts_printword(cp->cf_entry, cstream); + if (cp->cf_opts) + opts_print(cp->cf_opts, cstream, exclude_opts); } if (cp->cf_com) { if (cp->cf_entry) diff --git a/usr/src/cmd/logadm/lut.c b/usr/src/cmd/logadm/lut.c index 090c47054d..419d27a903 100644 --- a/usr/src/cmd/logadm/lut.c +++ b/usr/src/cmd/logadm/lut.c @@ -38,8 +38,6 @@ * was needed by logadm for options processing. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #include #include #include "err.h" @@ -170,8 +168,6 @@ lut_free(struct lut *root, void (*callback)(void *rhs)) void printer(const char *lhs, void *rhs, void *arg) { - struct lut *root = (struct lut *)arg; - printf("<%s> <%s> (<%s>)\n", lhs, (char *)rhs, (char *)lut_lookup(arg, lhs)); } diff --git a/usr/src/cmd/logadm/tester b/usr/src/cmd/logadm/tester index b65d13d155..89dd978448 100644 --- a/usr/src/cmd/logadm/tester +++ b/usr/src/cmd/logadm/tester @@ -90,7 +90,9 @@ umask 002; "logadm18", "logadm19", "logadm20", - "logadm21" + "logadm21", + "logadm22", + "logadm23" ); use Getopt::Std; @@ -2128,7 +2130,87 @@ EOF set_file('runtest', <<"EOF"); # test "logadm21" $envsetup -$bindir/logadm -f logadm.conf 2>std.err +$bindir/logadm -f logadm.conf -F /dev/null 2>std.err exit 0 EOF } + +############################################################################# +# +# logadm22 - test for keeping timestamps in timestamps file on -w +# +############################################################################# + +sub logadm22 { + set_file('logadm.conf', <<'EOF'); +wildcard_test -A 3d dir1/*.log +regular_test -A 3d dir2/test.log +EOF + +set_file('logadm.conf.expect', <<'EOF'); +wildcard_test -A 3d dir1/*.log +regular_test -A 3d dir2/test.log +dir3/test.log -A 3d +EOF + + set_file('logadm.timestamps', <<'EOF'); +# This file holds internal data for logadm(1M). +# Do not edit. +dir1/foo.log -P 'Thu Nov 1 16:56:42 2001' +dir2/test.log -P 'Thu Nov 1 16:56:42 2001' +EOF + system("/bin/cp logadm.timestamps logadm.timestamps.expect"); + + set_file('checktest', <<'EOF'); +[ -s std.err ] && { cat std.err; exit 1; } +/bin/diff logadm.conf.expect logadm.conf || exit 1 +/bin/diff logadm.timestamps.expect logadm.timestamps || exit 1 +EOF + + set_file('runtest', <<"EOF"); +# test "logadm22" +$envsetup +$bindir/logadm -f logadm.conf -F logadm.timestamps -w dir3/test.log -A 3d 2>std.err +exit 0 +EOF + +} + +############################################################################# +# +# logadm23 - test for keeping timestamps in timestamps file on -r +# +############################################################################# + +sub logadm23 { + set_file('logadm.conf', <<'EOF'); +wildcard_test -A 3d dir1/*.log +regular_test -A 3d dir2/test.log +EOF + +set_file('logadm.conf.expect', <<'EOF'); +wildcard_test -A 3d dir1/*.log +EOF + + set_file('logadm.timestamps', <<'EOF'); +# This file holds internal data for logadm(1M). +# Do not edit. +dir1/foo.log -P 'Thu Nov 1 16:56:42 2001' +dir2/test.log -P 'Thu Nov 1 16:56:42 2001' +EOF + system("/bin/cp logadm.timestamps logadm.timestamps.expect"); + + set_file('checktest', <<'EOF'); +[ -s std.err ] && { cat std.err; exit 1; } +/bin/diff logadm.conf.expect logadm.conf || exit 1 +/bin/diff logadm.timestamps.expect logadm.timestamps || exit 1 +EOF + + set_file('runtest', <<"EOF"); +# test "logadm23" +$envsetup +$bindir/logadm -f logadm.conf -F logadm.timestamps -r regular_test 2>std.err +exit 0 +EOF + +} -- 2.11.4.GIT