diff options
author | Sebastian Wiedenroth <wiedi@frubar.net> | 2018-03-24 00:03:22 +0000 |
---|---|---|
committer | Robert Mustacchi <rm@joyent.com> | 2018-05-31 21:01:29 +0000 |
commit | e911f24978ffe03577079badeef02cfc5e9aa296 (patch) | |
tree | ade9104e8232d35dd6d4ebc430773364c080e326 | |
parent | 7a7d534ff7d637c8673694e0ec835c590a6697e5 (diff) | |
download | illumos-joyent-e911f24978ffe03577079badeef02cfc5e9aa296.tar.gz |
9556 logadm timestamps should not leak into the configfile
Reviewed by: Toomas Soome <tsoome@me.com>
Reviewed by: Andy Fiddaman <af@citrus-it.net>
Approved by: Robert Mustacchi <rm@joyent.com>
-rw-r--r-- | usr/src/cmd/logadm/conf.c | 18 | ||||
-rw-r--r-- | usr/src/cmd/logadm/lut.c | 4 | ||||
-rw-r--r-- | 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 <stdio.h> #include <strings.h> #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 + +} |