Skip to content

Commit

Permalink
9556 logadm timestamps should not leak into the configfile
Browse files Browse the repository at this point in the history
Reviewed by: Toomas Soome <tsoome@me.com>
Reviewed by: Andy Fiddaman <af@citrus-it.net>
Approved by: Robert Mustacchi <rm@joyent.com>
  • Loading branch information
wiedi authored and rmustacc committed May 31, 2018
1 parent 7a7d534 commit e911f24
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 10 deletions.
18 changes: 14 additions & 4 deletions usr/src/cmd/logadm/conf.c
Expand Up @@ -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
*/

/*
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 }

Expand Down Expand Up @@ -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) {
Expand All @@ -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)
Expand Down
4 changes: 0 additions & 4 deletions usr/src/cmd/logadm/lut.c
Expand Up @@ -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"
Expand Down Expand Up @@ -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));
}
Expand Down
86 changes: 84 additions & 2 deletions usr/src/cmd/logadm/tester
Expand Up @@ -90,7 +90,9 @@ umask 002;
"logadm18",
"logadm19",
"logadm20",
"logadm21"
"logadm21",
"logadm22",
"logadm23"
);

use Getopt::Std;
Expand Down Expand Up @@ -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
}

0 comments on commit e911f24

Please sign in to comment.