4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved.
33 #include <sys/types.h>
36 #include <bsm/audit.h>
37 #include <bsm/audit_record.h>
38 #include <bsm/libbsm.h>
43 static int process_options(int *argc
, char *argv
[], char *names
[]);
45 static int input_mode
; /* audit file source */
46 static int format
= PRF_DEFAULTM
; /* output mode */
48 static char SEPARATOR
[SEP_SIZE
] = ","; /* field separator */
52 * ----------------------------------------------------------------------
53 * praudit - display contents of audit trail file
55 * main() - main control
56 * input: - command line input: praudit -r|s -l -x -ddelim. -c filename(s)
57 * ----------------------------------------------------------------------
61 main(int argc
, char **argv
)
64 char *names
[MAXFILENAMES
];
66 /* Internationalization */
67 (void) setlocale(LC_ALL
, "");
68 (void) textdomain(TEXT_DOMAIN
);
70 * get audit file names
72 if ((retstat
= process_options(&argc
, argv
, names
)) == 0) {
73 if (format
& PRF_XMLM
)
74 print_audit_xml_prolog();
78 * process each audit file
80 if (input_mode
== FILEMODE
) {
81 if (freopen(names
[i
], "r", stdin
) == NULL
) {
82 (void) fprintf(stderr
,
83 gettext("praudit: Cannot associate "
84 "stdin with %s: %s\n"),
85 names
[i
], strerror(errno
));
91 * Call the library routine to format the
92 * audit data from stdin and print to stdout
94 retstat
= print_audit(format
, SEPARATOR
);
96 } while ((++i
< argc
) && retstat
>= 0);
98 if ((retstat
== 0) && (format
& PRF_XMLM
))
99 print_audit_xml_ending();
102 (void) printf(gettext("\nusage: praudit [-r/-s] [-l] [-x] "
103 "[-ddel] [-c] filename...\n"));
105 } else if (retstat
< 0) {
113 * -------------------------------------------------------------------
114 * process_options() - get command line flags and file names
115 * input: - praudit [-r]/[-s] [-l] [-x] [-ddel] [-c] {audit file names}
116 * output: - {audit file names}
117 * globals set: format: RAWM / SHORTM / XML / ONELINE or DEFAULTM
118 * SEPARATOR: default, ",", set here if
120 * NOTE: no changes required here for new audit record format
121 * -------------------------------------------------------------------
124 process_options(int *argc
, char **argv
, char **names
)
126 int c
, returnstat
= 0;
132 while ((c
= getopt(*argc
, argv
, "crslxd:")) != -1) {
135 format
|= PRF_NOCACHE
; /* turn off cache */
138 if (format
& PRF_SHORTM
)
144 if (format
& PRF_RAWM
)
147 format
|= PRF_SHORTM
;
150 format
|= PRF_ONELINE
;
156 if (strlen(optarg
) < sizeof (SEPARATOR
))
157 (void) strlcpy(SEPARATOR
, optarg
,
160 (void) fprintf(stderr
,
161 gettext("praudit: Delimiter too "
162 "long. Using default.\n"));
171 argv
= &argv
[optind
- 1];
174 if (*argc
> MAXFILENAMES
) {
175 (void) fprintf(stderr
, gettext("praudit: Too many file "
182 input_mode
= FILEMODE
;
184 * copy file names from command line
188 } while (--count
> 0);
190 input_mode
= PIPEMODE
;