1*7c478bd9Sstevel@tonic-gate/*
2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate *
4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate * with the License.
8*7c478bd9Sstevel@tonic-gate *
9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate *
14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate *
20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate */
22*7c478bd9Sstevel@tonic-gate/*
23*7c478bd9Sstevel@tonic-gate * Copyright 2002 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate */
26*7c478bd9Sstevel@tonic-gate
27*7c478bd9Sstevel@tonic-gateThis describes some private interfaces currently provided by praudit.
28*7c478bd9Sstevel@tonic-gateIn the future these may be provided by libbsm instead.  Note that
29*7c478bd9Sstevel@tonic-gatethese interfaces are MT-Safe.
30*7c478bd9Sstevel@tonic-gate
31*7c478bd9Sstevel@tonic-gate
32*7c478bd9Sstevel@tonic-gateNAME
33*7c478bd9Sstevel@tonic-gate     print_audit, print_audit_buf  -  format and print audit trail data
34*7c478bd9Sstevel@tonic-gate     print_audit_xml_prolog,
35*7c478bd9Sstevel@tonic-gate     print_audit_xml_ending,
36*7c478bd9Sstevel@tonic-gate     print_audit_xml_prolog_buf,
37*7c478bd9Sstevel@tonic-gate     print_audit_xml_ending_buf    - print audit XML prolog and ending
38*7c478bd9Sstevel@tonic-gate
39*7c478bd9Sstevel@tonic-gateSYNOPSIS
40*7c478bd9Sstevel@tonic-gate     int print_audit(const int flags, const char *separator);
41*7c478bd9Sstevel@tonic-gate
42*7c478bd9Sstevel@tonic-gate     int print_audit_buf(char **in_buf, int *in_buf_len, char **out_buf,
43*7c478bd9Sstevel@tonic-gate	int *out_buf_len, const int flags, const char *separator);
44*7c478bd9Sstevel@tonic-gate
45*7c478bd9Sstevel@tonic-gate     void print_audit_xml_prolog(void);
46*7c478bd9Sstevel@tonic-gate     void print_audit_xml_ending(void);
47*7c478bd9Sstevel@tonic-gate     int print_audit_xml_prolog_buf(char *out_buf, const int out_buf_len);
48*7c478bd9Sstevel@tonic-gate     int print_audit_xml_ending_buf(char *out_buf, const int out_buf_len);
49*7c478bd9Sstevel@tonic-gate
50*7c478bd9Sstevel@tonic-gateDESCRIPTION
51*7c478bd9Sstevel@tonic-gate     print_audit() formats binary audit data from stdin and prints in
52*7c478bd9Sstevel@tonic-gate     ASCII on stdout. print_audit_buf() formats binary audit data from
53*7c478bd9Sstevel@tonic-gate     in_buf and copies in ASCII to out_buf, terminating with a null
54*7c478bd9Sstevel@tonic-gate     byte.
55*7c478bd9Sstevel@tonic-gate
56*7c478bd9Sstevel@tonic-gate     print_audit_xml_prolog and print_audit_xml_prolog_buf will print
57*7c478bd9Sstevel@tonic-gate     only the audit XML prolog. The XML, prolog includes identification
58*7c478bd9Sstevel@tonic-gate     of the DTD which is used to parse the XML, and also identifies the
59*7c478bd9Sstevel@tonic-gate     stylesheet which is used to view the XML conveniently (for example
60*7c478bd9Sstevel@tonic-gate     in a browser which supports these features).
61*7c478bd9Sstevel@tonic-gate
62*7c478bd9Sstevel@tonic-gate     print_audit_xml_ending and print_audit_xml_ending_buf print only
63*7c478bd9Sstevel@tonic-gate     the XML ending which completes the audit XML.
64*7c478bd9Sstevel@tonic-gate
65*7c478bd9Sstevel@tonic-gatePARAMETERS
66*7c478bd9Sstevel@tonic-gate     flags - specifies the types of formatting to be done:
67*7c478bd9Sstevel@tonic-gate
68*7c478bd9Sstevel@tonic-gate     PRF_DEFAULTM
69*7c478bd9Sstevel@tonic-gate	   Default formatting.  By default, times, user  and  group  IDs
70*7c478bd9Sstevel@tonic-gate	   (UIDs and GIDs, respectively) are converted to their ASCII
71*7c478bd9Sstevel@tonic-gate	   representation. Record type and  event fields  are converted
72*7c478bd9Sstevel@tonic-gate	   to their  ASCII representation. If any other flags are
73*7c478bd9Sstevel@tonic-gate	   specified they will override this flag.
74*7c478bd9Sstevel@tonic-gate
75*7c478bd9Sstevel@tonic-gate     PRF_RAWM
76*7c478bd9Sstevel@tonic-gate           Print records in their raw form. Times,   UIDs,  GIDs,
77*7c478bd9Sstevel@tonic-gate           record  types,  and  events are displayed as integers.
78*7c478bd9Sstevel@tonic-gate           This value and PRF_SHORTM are exclusive. If  both
79*7c478bd9Sstevel@tonic-gate           are used, no processing is done and EINVAL is returned.
80*7c478bd9Sstevel@tonic-gate
81*7c478bd9Sstevel@tonic-gate     PRF_SHORTM
82*7c478bd9Sstevel@tonic-gate           Print records in their short form. All numeric  fields
83*7c478bd9Sstevel@tonic-gate           are  converted to ASCII and displayed. The short ASCII
84*7c478bd9Sstevel@tonic-gate           representations for the record type and  event  fields
85*7c478bd9Sstevel@tonic-gate           are   used.   This  value an PRF_RAWM are exclusive. If
86*7c478bd9Sstevel@tonic-gate	   both are used, no processing is done and EINVAL is returned.
87*7c478bd9Sstevel@tonic-gate
88*7c478bd9Sstevel@tonic-gate     PRF_XMLM
89*7c478bd9Sstevel@tonic-gate           Print records in XML format. "tags" are included in the
90*7c478bd9Sstevel@tonic-gate           output to identify tokens and fields within tokens.
91*7c478bd9Sstevel@tonic-gate	   Output will not include an XML prolog or ending which
92*7c478bd9Sstevel@tonic-gate           are required to from complete, valid XML. The various
93*7c478bd9Sstevel@tonic-gate           print XML prolog and ending functions described here
94*7c478bd9Sstevel@tonic-gate           must be used separately from print_audit and print_audit_buf
95*7c478bd9Sstevel@tonic-gate           to accomplish that.
96*7c478bd9Sstevel@tonic-gate
97*7c478bd9Sstevel@tonic-gate     PRF_ONELINE
98*7c478bd9Sstevel@tonic-gate           Prints one line per record. The record type and  event
99*7c478bd9Sstevel@tonic-gate           fields  are  always  converted  to  their  short ASCII
100*7c478bd9Sstevel@tonic-gate           representation as is done for the -s option.
101*7c478bd9Sstevel@tonic-gate
102*7c478bd9Sstevel@tonic-gate
103*7c478bd9Sstevel@tonic-gate     separator -
104*7c478bd9Sstevel@tonic-gate	if non-NULL, this is used as the field delimiter instead of the
105*7c478bd9Sstevel@tonic-gate	default delimiter, which is the comma.  The maximum size of a
106*7c478bd9Sstevel@tonic-gate	delimiter is three characters (not counting the required
107*7c478bd9Sstevel@tonic-gate	null-terminator).  Note that the delimiter is not meaningful
108*7c478bd9Sstevel@tonic-gate	and this parameter is ignored when flags specifies XML format.
109*7c478bd9Sstevel@tonic-gate
110*7c478bd9Sstevel@tonic-gate     in_buf, in_buf_len,
111*7c478bd9Sstevel@tonic-gate     out_buf, out_buf_len  -
112*7c478bd9Sstevel@tonic-gate	pointers to the start of input and output buffers and their lengths.
113*7c478bd9Sstevel@tonic-gate	See Return Values for details about how these are used.
114*7c478bd9Sstevel@tonic-gate
115*7c478bd9Sstevel@tonic-gate
116*7c478bd9Sstevel@tonic-gateRETURN VALUES
117*7c478bd9Sstevel@tonic-gate     print_audit() and print_audit_buf() return:
118*7c478bd9Sstevel@tonic-gate     0     on success.
119*7c478bd9Sstevel@tonic-gate     -1    on failure and set errno to indicate the error:
120*7c478bd9Sstevel@tonic-gate
121*7c478bd9Sstevel@tonic-gate     EINVAL - invalid input flags, delimiter, or error parsing the
122*7c478bd9Sstevel@tonic-gate	      binary audit data.
123*7c478bd9Sstevel@tonic-gate
124*7c478bd9Sstevel@tonic-gate     ENOSPC - output buffer too small.
125*7c478bd9Sstevel@tonic-gate
126*7c478bd9Sstevel@tonic-gate     EIO    - input exhausted before end of an audit record.
127*7c478bd9Sstevel@tonic-gate
128*7c478bd9Sstevel@tonic-gate     EPERM  - internal or other unexpected error.
129*7c478bd9Sstevel@tonic-gate
130*7c478bd9Sstevel@tonic-gate     Partial results may also be returned for these errors.
131*7c478bd9Sstevel@tonic-gate
132*7c478bd9Sstevel@tonic-gate
133*7c478bd9Sstevel@tonic-gate     The following parameters are always returned:
134*7c478bd9Sstevel@tonic-gate
135*7c478bd9Sstevel@tonic-gate     out_buf_len -
136*7c478bd9Sstevel@tonic-gate
137*7c478bd9Sstevel@tonic-gate     updated to reflect size of output successfully produced. If
138*7c478bd9Sstevel@tonic-gate     non-zero, this will include the single terminating null byte.
139*7c478bd9Sstevel@tonic-gate
140*7c478bd9Sstevel@tonic-gate
141*7c478bd9Sstevel@tonic-gate     Upon return of partial results, these parameters will also be
142*7c478bd9Sstevel@tonic-gate     updated to reflect status (up to the end of the last completed
143*7c478bd9Sstevel@tonic-gate     audit record from the input):
144*7c478bd9Sstevel@tonic-gate
145*7c478bd9Sstevel@tonic-gate     in_buf, in_buf_len -
146*7c478bd9Sstevel@tonic-gate
147*7c478bd9Sstevel@tonic-gate     updated to reflect amount of input successfully consumed.  in_buf
148*7c478bd9Sstevel@tonic-gate     will point to the next byte which has not been processed.
149*7c478bd9Sstevel@tonic-gate     in_buf_len will be set to the remaining size from this address to
150*7c478bd9Sstevel@tonic-gate     the end of the original buffer.
151*7c478bd9Sstevel@tonic-gate
152*7c478bd9Sstevel@tonic-gate
153*7c478bd9Sstevel@tonic-gate     print_audit_xml_prolog_buf and print_audit_xml_ending_buf return:
154*7c478bd9Sstevel@tonic-gate     0     on success.
155*7c478bd9Sstevel@tonic-gate     -1    on failure and set errno to indicate the error:
156*7c478bd9Sstevel@tonic-gate
157*7c478bd9Sstevel@tonic-gate     ENOSPC - output buffer too small.
158*7c478bd9Sstevel@tonic-gate
159*7c478bd9Sstevel@tonic-gate
160*7c478bd9Sstevel@tonic-gateEXAMPLES
161*7c478bd9Sstevel@tonic-gate       The following code fragment takes audit input from stdin, and
162*7c478bd9Sstevel@tonic-gate       will print on stdout complete XML including a prolog:
163*7c478bd9Sstevel@tonic-gate
164*7c478bd9Sstevel@tonic-gate	print_audit_xml_prolog();
165*7c478bd9Sstevel@tonic-gate
166*7c478bd9Sstevel@tonic-gate	/*
167*7c478bd9Sstevel@tonic-gate	 * Format audit data from stdin and print to stdout.
168*7c478bd9Sstevel@tonic-gate	 */
169*7c478bd9Sstevel@tonic-gate	retstat = print_audit(PRF_XMLM | PRF_ONELINE, NULL);
170*7c478bd9Sstevel@tonic-gate
171*7c478bd9Sstevel@tonic-gate	if (retstat == 0)
172*7c478bd9Sstevel@tonic-gate		print_audit_xml_ending();
173*7c478bd9Sstevel@tonic-gate
174*7c478bd9Sstevel@tonic-gate
175