17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5a7746f66Stz204579 * Common Development and Distribution License (the "License"). 6a7746f66Stz204579 * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22a7746f66Stz204579 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate /* 277c478bd9Sstevel@tonic-gate * File name: praudit.h 287c478bd9Sstevel@tonic-gate * praudit.c defines, globals 297c478bd9Sstevel@tonic-gate */ 307c478bd9Sstevel@tonic-gate 317c478bd9Sstevel@tonic-gate #ifndef _PRAUDIT_H 327c478bd9Sstevel@tonic-gate #define _PRAUDIT_H 337c478bd9Sstevel@tonic-gate 347c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 357c478bd9Sstevel@tonic-gate 367c478bd9Sstevel@tonic-gate #ifdef __cplusplus 377c478bd9Sstevel@tonic-gate extern "C" { 387c478bd9Sstevel@tonic-gate #endif 397c478bd9Sstevel@tonic-gate 407c478bd9Sstevel@tonic-gate /* DEFINES */ 417c478bd9Sstevel@tonic-gate 427c478bd9Sstevel@tonic-gate /* 437c478bd9Sstevel@tonic-gate * output value types 447c478bd9Sstevel@tonic-gate */ 457c478bd9Sstevel@tonic-gate #define PRA_INT32 0 467c478bd9Sstevel@tonic-gate #define PRA_UINT32 1 477c478bd9Sstevel@tonic-gate #define PRA_INT64 2 487c478bd9Sstevel@tonic-gate #define PRA_UINT64 3 497c478bd9Sstevel@tonic-gate #define PRA_SHORT 4 507c478bd9Sstevel@tonic-gate #define PRA_USHORT 5 517c478bd9Sstevel@tonic-gate #define PRA_CHAR 6 527c478bd9Sstevel@tonic-gate #define PRA_UCHAR 7 537c478bd9Sstevel@tonic-gate #define PRA_STRING 8 547c478bd9Sstevel@tonic-gate #define PRA_HEX32 9 557c478bd9Sstevel@tonic-gate #define PRA_HEX64 10 567c478bd9Sstevel@tonic-gate #define PRA_SHEX 11 577c478bd9Sstevel@tonic-gate #define PRA_OCT 12 587c478bd9Sstevel@tonic-gate #define PRA_BYTE 13 597c478bd9Sstevel@tonic-gate #define PRA_OUTREC 14 607c478bd9Sstevel@tonic-gate #define PRA_LOCT 15 617c478bd9Sstevel@tonic-gate 627c478bd9Sstevel@tonic-gate /* 637c478bd9Sstevel@tonic-gate * Formatting flags 647c478bd9Sstevel@tonic-gate */ 657c478bd9Sstevel@tonic-gate #define PRF_DEFAULTM 0x0000 /* Default mode */ 667c478bd9Sstevel@tonic-gate #define PRF_RAWM 0x0001 /* Raw mode */ 677c478bd9Sstevel@tonic-gate #define PRF_SHORTM 0x0002 /* Short mode */ 687c478bd9Sstevel@tonic-gate #define PRF_XMLM 0x0004 /* XML format */ 697c478bd9Sstevel@tonic-gate #define PRF_ONELINE 0x0008 /* one-line output */ 707c478bd9Sstevel@tonic-gate #define PRF_NOCACHE 0x0010 /* don't cache event names */ 717c478bd9Sstevel@tonic-gate 727c478bd9Sstevel@tonic-gate /* 737c478bd9Sstevel@tonic-gate * source of audit data (data_mode) 747c478bd9Sstevel@tonic-gate */ 757c478bd9Sstevel@tonic-gate #define FILEMODE 1 767c478bd9Sstevel@tonic-gate #define PIPEMODE 2 777c478bd9Sstevel@tonic-gate #define BUFMODE 3 787c478bd9Sstevel@tonic-gate 797c478bd9Sstevel@tonic-gate /* 807c478bd9Sstevel@tonic-gate * max. number of audit file names entered on command line 817c478bd9Sstevel@tonic-gate */ 827c478bd9Sstevel@tonic-gate #define MAXFILENAMES 100 837c478bd9Sstevel@tonic-gate 847c478bd9Sstevel@tonic-gate /* 857c478bd9Sstevel@tonic-gate * max. size of file name 867c478bd9Sstevel@tonic-gate */ 877c478bd9Sstevel@tonic-gate #define MAXFILELEN MAXPATHLEN+MAXNAMLEN+1 887c478bd9Sstevel@tonic-gate 897c478bd9Sstevel@tonic-gate /* 907c478bd9Sstevel@tonic-gate * used to store value to be output 917c478bd9Sstevel@tonic-gate */ 927c478bd9Sstevel@tonic-gate typedef union u_tag { 937c478bd9Sstevel@tonic-gate int32_t int32_val; 947c478bd9Sstevel@tonic-gate uint32_t uint32_val; 957c478bd9Sstevel@tonic-gate int64_t int64_val; 967c478bd9Sstevel@tonic-gate uint64_t uint64_val; 977c478bd9Sstevel@tonic-gate short short_val; 987c478bd9Sstevel@tonic-gate ushort_t ushort_val; 997c478bd9Sstevel@tonic-gate char char_val; 1007c478bd9Sstevel@tonic-gate char uchar_val; 1017c478bd9Sstevel@tonic-gate char *string_val; 1027c478bd9Sstevel@tonic-gate } u_tag_t; 1037c478bd9Sstevel@tonic-gate typedef struct u_val { 1047c478bd9Sstevel@tonic-gate int uvaltype; 1057c478bd9Sstevel@tonic-gate u_tag_t tag; 1067c478bd9Sstevel@tonic-gate } uval_t; 1077c478bd9Sstevel@tonic-gate #define int32_val tag.int32_val 1087c478bd9Sstevel@tonic-gate #define uint32_val tag.uint32_val 1097c478bd9Sstevel@tonic-gate #define int64_val tag.int64_val 1107c478bd9Sstevel@tonic-gate #define uint64_val tag.uint64_val 1117c478bd9Sstevel@tonic-gate #define short_val tag.short_val 1127c478bd9Sstevel@tonic-gate #define ushort_val tag.ushort_val 1137c478bd9Sstevel@tonic-gate #define char_val tag.char_val 1147c478bd9Sstevel@tonic-gate #define uchar_val tag.uchar_val 1157c478bd9Sstevel@tonic-gate #define string_val tag.string_val 1167c478bd9Sstevel@tonic-gate 1177c478bd9Sstevel@tonic-gate 1187c478bd9Sstevel@tonic-gate /* 1197c478bd9Sstevel@tonic-gate * Strings and things for xml prolog & ending printing. 1207c478bd9Sstevel@tonic-gate */ 1217c478bd9Sstevel@tonic-gate #define prolog1 "<?xml version='1.0' encoding='UTF-8' ?>\n" 1227c478bd9Sstevel@tonic-gate #define prolog2 "\n<!DOCTYPE audit PUBLIC " \ 1237c478bd9Sstevel@tonic-gate "'-//Sun Microsystems, Inc.//DTD Audit V1//EN' " \ 1247c478bd9Sstevel@tonic-gate "'file:///usr/share/lib/xml/dtd/adt_record.dtd.1'>\n\n" 1257c478bd9Sstevel@tonic-gate #define prolog_xsl "<?xml-stylesheet type='text/xsl' " \ 1267c478bd9Sstevel@tonic-gate "href='file:///usr/share/lib/xml/style/adt_record.xsl.1' ?>\n" 1277c478bd9Sstevel@tonic-gate 1287c478bd9Sstevel@tonic-gate /* Special main element: */ 1297c478bd9Sstevel@tonic-gate #define xml_start "<audit>" 1307c478bd9Sstevel@tonic-gate #define xml_ending "\n</audit>\n" 1317c478bd9Sstevel@tonic-gate 1327c478bd9Sstevel@tonic-gate #define xml_prolog_len (sizeof (prolog1) + sizeof (prolog2) + \ 1337c478bd9Sstevel@tonic-gate sizeof (prolog_xsl) + sizeof (xml_start) + 1) 1347c478bd9Sstevel@tonic-gate #define xml_end_len (sizeof (xml_ending) + 1) 1357c478bd9Sstevel@tonic-gate 1367c478bd9Sstevel@tonic-gate /* 1377c478bd9Sstevel@tonic-gate * used to save context for print_audit and related functions. 1387c478bd9Sstevel@tonic-gate */ 1397c478bd9Sstevel@tonic-gate 1407c478bd9Sstevel@tonic-gate #define SEP_SIZE 4 1417c478bd9Sstevel@tonic-gate 1427c478bd9Sstevel@tonic-gate struct pr_context { 1437c478bd9Sstevel@tonic-gate int format; 1447c478bd9Sstevel@tonic-gate int data_mode; 1457c478bd9Sstevel@tonic-gate char SEPARATOR[SEP_SIZE]; /* field separator */ 1467c478bd9Sstevel@tonic-gate signed char tokenid; /* initial token ID */ 1477c478bd9Sstevel@tonic-gate adr_t *audit_adr; /* audit record */ 1487c478bd9Sstevel@tonic-gate adrf_t *audit_adrf; /* audit record, file mode */ 1497c478bd9Sstevel@tonic-gate int audit_rec_len; 1507c478bd9Sstevel@tonic-gate char *audit_rec_start; 1517c478bd9Sstevel@tonic-gate 1527c478bd9Sstevel@tonic-gate char *inbuf_start; 1537c478bd9Sstevel@tonic-gate char *inbuf_last; /* ptr to byte after latest completed */ 1547c478bd9Sstevel@tonic-gate /* header or file token in the input */ 1557c478bd9Sstevel@tonic-gate int inbuf_totalsize; 1567c478bd9Sstevel@tonic-gate char *outbuf_p; 1577c478bd9Sstevel@tonic-gate char *outbuf_start; 1587c478bd9Sstevel@tonic-gate char *outbuf_last; /* ptr to byte after latest completed */ 1597c478bd9Sstevel@tonic-gate /* header or file token in the output */ 1607c478bd9Sstevel@tonic-gate int outbuf_remain_len; 1617c478bd9Sstevel@tonic-gate 1627c478bd9Sstevel@tonic-gate int pending_flag; /* open of extended tag not completed */ 1637c478bd9Sstevel@tonic-gate int current_rec; /* id of current record */ 1647c478bd9Sstevel@tonic-gate }; 1657c478bd9Sstevel@tonic-gate typedef struct pr_context pr_context_t; 1667c478bd9Sstevel@tonic-gate 1677c478bd9Sstevel@tonic-gate 1687c478bd9Sstevel@tonic-gate extern void init_tokens(void); 1697c478bd9Sstevel@tonic-gate 1707c478bd9Sstevel@tonic-gate extern int open_tag(pr_context_t *context, int); 1717c478bd9Sstevel@tonic-gate extern int finish_open_tag(pr_context_t *context); 1727c478bd9Sstevel@tonic-gate extern int check_close_rec(pr_context_t *context, int); 1737c478bd9Sstevel@tonic-gate extern int close_tag(pr_context_t *context, int); 1747c478bd9Sstevel@tonic-gate extern int process_tag(pr_context_t *context, int, int, int); 1757c478bd9Sstevel@tonic-gate 1767c478bd9Sstevel@tonic-gate extern int is_file_token(int); 1777c478bd9Sstevel@tonic-gate extern int is_header_token(int); 1787c478bd9Sstevel@tonic-gate extern int is_token(int); 1797c478bd9Sstevel@tonic-gate extern int do_newline(pr_context_t *context, int); 1807c478bd9Sstevel@tonic-gate 1817c478bd9Sstevel@tonic-gate extern char *bu2string(char basic_unit); 1827c478bd9Sstevel@tonic-gate extern int convert_char_to_string(char printmode, char c, char *p); 1837c478bd9Sstevel@tonic-gate extern int convert_int32_to_string(char printmode, int32_t c, char *p); 1847c478bd9Sstevel@tonic-gate extern int convert_int64_to_string(char printmode, int64_t c, char *p); 1857c478bd9Sstevel@tonic-gate extern int convert_short_to_string(char printmode, short c, char *p); 1867c478bd9Sstevel@tonic-gate extern int findfieldwidth(char basicunit, char howtoprint); 1877c478bd9Sstevel@tonic-gate extern void get_Hname(uint32_t addr, char *buf, size_t buflen); 1887c478bd9Sstevel@tonic-gate extern void get_Hname_ex(uint32_t *addr, char *buf, size_t buflen); 1897c478bd9Sstevel@tonic-gate extern char *hexconvert(char *c, int size, int chunk); 1907c478bd9Sstevel@tonic-gate extern char *htp2string(char print_sugg); 1917c478bd9Sstevel@tonic-gate extern int pa_print(pr_context_t *context, uval_t *uval, int flag); 1927c478bd9Sstevel@tonic-gate extern int pa_reclen(pr_context_t *context, int status); 1937c478bd9Sstevel@tonic-gate extern int pa_file_string(pr_context_t *context, int status, int flag); 1947c478bd9Sstevel@tonic-gate extern int pa_adr_int32(pr_context_t *context, int status, int flag); 1957c478bd9Sstevel@tonic-gate extern int pa_adr_int64(pr_context_t *context, int status, int flag); 1967c478bd9Sstevel@tonic-gate extern int pa_utime32(pr_context_t *context, int status, int flag); 1977c478bd9Sstevel@tonic-gate extern int pa_ntime32(pr_context_t *context, int status, int flag); 1987c478bd9Sstevel@tonic-gate extern int pa_utime64(pr_context_t *context, int status, int flag); 1997c478bd9Sstevel@tonic-gate extern int pa_ntime64(pr_context_t *context, int status, int flag); 2007c478bd9Sstevel@tonic-gate extern int pa_adr_string(pr_context_t *context, int status, int flag); 2017c478bd9Sstevel@tonic-gate extern int pa_adr_u_int32(pr_context_t *context, int status, int flag); 2027c478bd9Sstevel@tonic-gate extern int pa_adr_u_int64(pr_context_t *context, int status, int flag); 2037c478bd9Sstevel@tonic-gate extern int pa_adr_byte(pr_context_t *context, int status, int flag); 2047c478bd9Sstevel@tonic-gate extern int pa_event_type(pr_context_t *context, int status, int flag); 2057c478bd9Sstevel@tonic-gate extern int pa_event_modifier(pr_context_t *context, int status, int flag); 2067c478bd9Sstevel@tonic-gate extern int pa_adr_int32hex(pr_context_t *context, int status, int flag); 2077c478bd9Sstevel@tonic-gate extern int pa_adr_int64hex(pr_context_t *context, int status, int flag); 2087c478bd9Sstevel@tonic-gate extern int pa_pw_uid(pr_context_t *context, int status, int flag); 2097c478bd9Sstevel@tonic-gate extern int pa_gr_uid(pr_context_t *context, int status, int flag); 2107c478bd9Sstevel@tonic-gate extern int pa_pw_uid_gr_gid(pr_context_t *context, int status, int flag); 211a7746f66Stz204579 extern int pa_ace(pr_context_t *context, int status, int flag); 2127c478bd9Sstevel@tonic-gate extern int pa_hostname(pr_context_t *context, int status, int flag); 2137c478bd9Sstevel@tonic-gate extern int pa_hostname_ex(pr_context_t *context, int status, int flag); 2147c478bd9Sstevel@tonic-gate extern int pa_hostname_so(pr_context_t *context, int status, int flag); 2157c478bd9Sstevel@tonic-gate extern int pa_adr_u_short(pr_context_t *context, int status, int flag); 2167c478bd9Sstevel@tonic-gate extern int pa_tid32(pr_context_t *context, int status, int flag); 2177c478bd9Sstevel@tonic-gate extern int pa_tid64(pr_context_t *context, int status, int flag); 2187c478bd9Sstevel@tonic-gate extern int pa_tid32_ex(pr_context_t *context, int status, int flag); 2197c478bd9Sstevel@tonic-gate extern int pa_tid64_ex(pr_context_t *context, int status, int flag); 2207c478bd9Sstevel@tonic-gate extern int pa_adr_charhex(pr_context_t *context, int status, int flag); 2217c478bd9Sstevel@tonic-gate extern int pa_adr_short(pr_context_t *context, int status, int flag); 2227c478bd9Sstevel@tonic-gate extern int pa_adr_shorthex(pr_context_t *context, int status, int flag); 2237c478bd9Sstevel@tonic-gate extern int pa_mode(pr_context_t *context, int status, int flag); 2247c478bd9Sstevel@tonic-gate extern int pa_cmd(pr_context_t *context, int status, int flag); 2257c478bd9Sstevel@tonic-gate extern int pa_string(pr_context_t *context, int status, int flag); 2267c478bd9Sstevel@tonic-gate extern int pa_liaison(pr_context_t *context, int status, int flag); 2277c478bd9Sstevel@tonic-gate extern int pa_xgeneric(pr_context_t *context); 2287c478bd9Sstevel@tonic-gate extern int pa_xid(pr_context_t *context, int status, int flag); 2297c478bd9Sstevel@tonic-gate extern void pa_error(const uchar_t err, char *buf, size_t buflen); 230*f72effdeSgww extern void pa_retval(const uchar_t, const int32_t, char *, size_t); 2317c478bd9Sstevel@tonic-gate extern int pa_ip_addr(pr_context_t *context, int status, int flag); 2327c478bd9Sstevel@tonic-gate extern int pr_adr_char(pr_context_t *context, char *cp, int count); 2337c478bd9Sstevel@tonic-gate extern int pr_adr_short(pr_context_t *context, short *sp, int count); 2347c478bd9Sstevel@tonic-gate extern int pr_adr_int32(pr_context_t *context, int32_t *lp, int count); 2357c478bd9Sstevel@tonic-gate extern int pr_adr_int64(pr_context_t *context, int64_t *lp, int count); 2367c478bd9Sstevel@tonic-gate extern int pr_adr_u_int32(pr_context_t *context, uint32_t *cp, int count); 2377c478bd9Sstevel@tonic-gate extern int pr_adr_u_char(pr_context_t *context, uchar_t *cp, int count); 2387c478bd9Sstevel@tonic-gate extern int pr_adr_u_int64(pr_context_t *context, uint64_t *lp, int count); 2397c478bd9Sstevel@tonic-gate extern int pr_adr_u_short(pr_context_t *context, ushort_t *sp, int count); 2407c478bd9Sstevel@tonic-gate extern int pr_putchar(pr_context_t *context, char); 2417c478bd9Sstevel@tonic-gate extern int pr_printf(pr_context_t *context, const char *format, ...); 2427c478bd9Sstevel@tonic-gate extern int pr_input_remaining(pr_context_t *context, size_t size); 2437c478bd9Sstevel@tonic-gate 2447c478bd9Sstevel@tonic-gate /* 2457c478bd9Sstevel@tonic-gate * Functions that format audit data 2467c478bd9Sstevel@tonic-gate */ 2477c478bd9Sstevel@tonic-gate extern int print_audit(const int, const char *); 2487c478bd9Sstevel@tonic-gate extern int print_audit_buf(char **, int *, char **, int *, const int, 2497c478bd9Sstevel@tonic-gate const char *); 2507c478bd9Sstevel@tonic-gate extern void print_audit_xml_prolog(void); 2517c478bd9Sstevel@tonic-gate extern void print_audit_xml_ending(void); 2527c478bd9Sstevel@tonic-gate extern int print_audit_xml_prolog_buf(char *out_buf, 2537c478bd9Sstevel@tonic-gate const int out_buf_len); 2547c478bd9Sstevel@tonic-gate extern int print_audit_xml_ending_buf(char *out_buf, 2557c478bd9Sstevel@tonic-gate const int out_buf_len); 2567c478bd9Sstevel@tonic-gate 2577c478bd9Sstevel@tonic-gate 2587c478bd9Sstevel@tonic-gate #ifdef __cplusplus 2597c478bd9Sstevel@tonic-gate } 2607c478bd9Sstevel@tonic-gate #endif 2617c478bd9Sstevel@tonic-gate 2627c478bd9Sstevel@tonic-gate #endif /* _PRAUDIT_H */ 263