xref: /onnv-gate/usr/src/cmd/fs.d/nfs/nfslog/nfslog_elf.c (revision 1610:3436e82414c8)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*1610Sthurlow  * Common Development and Distribution License (the "License").
6*1610Sthurlow  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*1610Sthurlow  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
270Sstevel@tonic-gate 
280Sstevel@tonic-gate /*
290Sstevel@tonic-gate  * nfs log - read buffer file and print structs in user-readable form
300Sstevel@tonic-gate  */
310Sstevel@tonic-gate 
320Sstevel@tonic-gate #define	_REENTRANT
330Sstevel@tonic-gate 
340Sstevel@tonic-gate #include <ctype.h>
350Sstevel@tonic-gate #include <stdio.h>
360Sstevel@tonic-gate #include <stdlib.h>
370Sstevel@tonic-gate #include <stddef.h>
380Sstevel@tonic-gate #include <string.h>
390Sstevel@tonic-gate #include <strings.h>
400Sstevel@tonic-gate #include <time.h>
410Sstevel@tonic-gate #include <fcntl.h>
420Sstevel@tonic-gate #include <unistd.h>
430Sstevel@tonic-gate #include <signal.h>
440Sstevel@tonic-gate #include <sys/types.h>
450Sstevel@tonic-gate #include <sys/stat.h>
460Sstevel@tonic-gate #include <sys/param.h>
470Sstevel@tonic-gate #include <sys/utsname.h>
480Sstevel@tonic-gate #include <errno.h>
490Sstevel@tonic-gate #include <time.h>
500Sstevel@tonic-gate #include <limits.h>
510Sstevel@tonic-gate #include <libintl.h>
520Sstevel@tonic-gate #include <pwd.h>
530Sstevel@tonic-gate #include <netdb.h>
540Sstevel@tonic-gate #include <syslog.h>
550Sstevel@tonic-gate #include <rpc/rpc.h>
560Sstevel@tonic-gate #include <netconfig.h>
570Sstevel@tonic-gate #include <netdir.h>
580Sstevel@tonic-gate #include <nfs/nfs_sec.h>
590Sstevel@tonic-gate #include <nfs/export.h>
600Sstevel@tonic-gate #include <rpc/auth.h>
610Sstevel@tonic-gate #include <rpc/svc.h>
620Sstevel@tonic-gate #include <rpc/xdr.h>
630Sstevel@tonic-gate #include <rpc/clnt.h>
640Sstevel@tonic-gate #include <nfs/nfs.h>
650Sstevel@tonic-gate #include <nfs/nfs_log.h>
660Sstevel@tonic-gate #include "fhtab.h"
670Sstevel@tonic-gate #include "nfslogd.h"
680Sstevel@tonic-gate 
690Sstevel@tonic-gate static char	empty_name[4] = "-";
700Sstevel@tonic-gate 
710Sstevel@tonic-gate static char ftype3_names[NF3FIFO + 1][20] = {
720Sstevel@tonic-gate 	"\"none\"", "\"file\"", "\"dir\"", "\"blk device\"",
730Sstevel@tonic-gate 	"\"chr device\"", "\"link\"", "\"socket\"", "\"fifo\""
740Sstevel@tonic-gate };
750Sstevel@tonic-gate 
760Sstevel@tonic-gate #define	NFSL_FTYPE3(ftype)						\
770Sstevel@tonic-gate 	((((ftype) >= 0) && ((ftype) <= NF3FIFO)) ?			\
780Sstevel@tonic-gate 	ftype3_names[ftype] : empty_name)
790Sstevel@tonic-gate 
800Sstevel@tonic-gate static char createmode3_names[EXCLUSIVE + 1][20] = {
810Sstevel@tonic-gate 	"\"unchecked", "\"guarded\"", "\"exclusive\""
820Sstevel@tonic-gate };
830Sstevel@tonic-gate 
840Sstevel@tonic-gate #define	NFSL_CREATEMODE3(createmode)					\
850Sstevel@tonic-gate 	((((createmode) >= 0) && ((createmode) <= EXCLUSIVE)) ?		\
860Sstevel@tonic-gate 	createmode3_names[createmode] : empty_name)
870Sstevel@tonic-gate 
880Sstevel@tonic-gate static char	auth_flavor_name[RPCSEC_GSS + 1][20] = {
890Sstevel@tonic-gate 	"\"auth_null\"", "\"auth_unix\"", "\"auth_short\"", "\"auth_des\"",
900Sstevel@tonic-gate 	"\"auth_kerb\"", "\"none\"", "\"rpcsec_gss\""
910Sstevel@tonic-gate };
920Sstevel@tonic-gate 
930Sstevel@tonic-gate #define	NFSL_AUTH_FLAVOR_PRINT(auth_flavor)				\
940Sstevel@tonic-gate 	(((auth_flavor) <= RPCSEC_GSS) ?				\
950Sstevel@tonic-gate 	auth_flavor_name[auth_flavor] : empty_name)
960Sstevel@tonic-gate 
970Sstevel@tonic-gate #define	NFSL_ERR_CNT		31	/* Actual err numbers */
980Sstevel@tonic-gate 
990Sstevel@tonic-gate /*
1000Sstevel@tonic-gate  * Two arrays - one short ints containing err codes, the other the strings
1010Sstevel@tonic-gate  * (merged codes for both v2 and v3
1020Sstevel@tonic-gate  */
1030Sstevel@tonic-gate static char	nfsl_status_name[NFSL_ERR_CNT][30] = {
1040Sstevel@tonic-gate 	"\"ok\"", "\"perm\"", "\"noent\"", "\"io\"",
1050Sstevel@tonic-gate 	"\"nxio\"", "\"access\"", "\"exist\"", "\"xdev\"",
1060Sstevel@tonic-gate 	"\"nodev\"", "\"notdir\"", "\"isdir\"", "\"inval\"",
1070Sstevel@tonic-gate 	"\"fbig\"", "\"nospc\"", "\"rofs\"", "\"mlink\"",
1080Sstevel@tonic-gate 	"\"notsupp\"", "\"nametoolong\"", "\"notempty\"", "\"dquot\"",
1090Sstevel@tonic-gate 	"\"stale\"", "\"remote\"", "\"wflush\"", "\"badhandle\"",
1100Sstevel@tonic-gate 	"\"not_sync\"", "\"bad_cookie\"", "\"notsupp\"", "\"toosmall\"",
1110Sstevel@tonic-gate 	"\"serverfault\"", "\"badtype\"", "\"jukebox\"",
1120Sstevel@tonic-gate };
1130Sstevel@tonic-gate 
1140Sstevel@tonic-gate static short	nfsl_status[NFSL_ERR_CNT] = {
1150Sstevel@tonic-gate 	0, 1, 2, 5, 6, 13, 17, 18,
1160Sstevel@tonic-gate 	19, 20, 21, 22, 27, 28, 30, 31,
1170Sstevel@tonic-gate 	45, 63, 66, 69, 70, 71, 99, 10001,
1180Sstevel@tonic-gate 	10002, 10003, 10004, 10005, 10006, 10007, 10008
1190Sstevel@tonic-gate };
1200Sstevel@tonic-gate 
1210Sstevel@tonic-gate /* list of open elf files */
1220Sstevel@tonic-gate static struct nfsl_log_file	*elf_file_list = NULL;
1230Sstevel@tonic-gate 
1240Sstevel@tonic-gate /* Imported functions */
1250Sstevel@tonic-gate extern void bcopy(const void *s1, void *s2, size_t n);
1260Sstevel@tonic-gate 
1270Sstevel@tonic-gate /* Static functions */
1280Sstevel@tonic-gate static void nfsl_log_file_free(struct nfsl_log_file *elfrec);
1290Sstevel@tonic-gate static void nfsl_log_file_add(struct nfsl_log_file *elfrec,
1300Sstevel@tonic-gate 	struct nfsl_log_file **elf_listp);
1310Sstevel@tonic-gate static struct nfsl_log_file *nfsl_log_file_find(struct nfsl_log_file *elfrec,
1320Sstevel@tonic-gate 	struct nfsl_log_file *elf_list);
1330Sstevel@tonic-gate static struct nfsl_log_file *nfsl_log_file_del(struct nfsl_log_file *elfrec,
1340Sstevel@tonic-gate 	struct nfsl_log_file **elf_listp);
1350Sstevel@tonic-gate 
1360Sstevel@tonic-gate static char *nfsl_get_time(time_t tt);
1370Sstevel@tonic-gate static char *nfsl_get_date(time_t tt);
1380Sstevel@tonic-gate static char *nfsl_get_date_nq(time_t tt);
1390Sstevel@tonic-gate static int nfsl_write_elfbuf(struct nfsl_log_file *elfrec);
1400Sstevel@tonic-gate static void nfsl_ipaddr_print(struct nfsl_log_file *, struct netbuf *);
1410Sstevel@tonic-gate static void nfsl_elf_record_header_print(struct nfsl_log_file *,
1420Sstevel@tonic-gate 		nfslog_record_header *, char *, char *,
1430Sstevel@tonic-gate 		struct nfsl_proc_disp *, char *);
1440Sstevel@tonic-gate static void nfsl_elf_buffer_header_print(struct nfsl_log_file *,
1450Sstevel@tonic-gate 		nfslog_buffer_header *);
1460Sstevel@tonic-gate static struct nfsl_proc_disp *nfsl_find_elf_dispatch(
1470Sstevel@tonic-gate 		nfslog_request_record *, char **);
1480Sstevel@tonic-gate static void nfsl_elf_rpc_print(struct nfsl_log_file *,
1490Sstevel@tonic-gate 		nfslog_request_record *, struct nfsl_proc_disp *,
1500Sstevel@tonic-gate 		char *, char *, char *);
1510Sstevel@tonic-gate static void nfslog_size3_print(struct nfsl_log_file *, set_size3 *);
1520Sstevel@tonic-gate 
1530Sstevel@tonic-gate static void nfslog_null_args(struct nfsl_log_file *, caddr_t *);
1540Sstevel@tonic-gate static void nfslog_null_res(struct nfsl_log_file *, caddr_t *);
1550Sstevel@tonic-gate 
1560Sstevel@tonic-gate 
1570Sstevel@tonic-gate /*
1580Sstevel@tonic-gate  * NFS VERSION 2
1590Sstevel@tonic-gate  */
1600Sstevel@tonic-gate 
1610Sstevel@tonic-gate /* Functions for elf print of the arguments */
1620Sstevel@tonic-gate static void nfslog_fhandle_print(struct nfsl_log_file *, fhandle_t *);
1630Sstevel@tonic-gate static void nfslog_diropargs_print(struct nfsl_log_file *, nfslog_diropargs *);
1640Sstevel@tonic-gate static void nfslog_setattrargs_print(struct nfsl_log_file *,
1650Sstevel@tonic-gate 	nfslog_setattrargs *);
1660Sstevel@tonic-gate static void nfslog_sattr_print(struct nfsl_log_file *,
1670Sstevel@tonic-gate 	nfslog_sattr *);
1680Sstevel@tonic-gate static void nfslog_nfsreadargs_print(struct nfsl_log_file *,
1690Sstevel@tonic-gate 	nfslog_nfsreadargs *);
1700Sstevel@tonic-gate static void nfslog_writeargs_print(struct nfsl_log_file *,
1710Sstevel@tonic-gate 	nfslog_writeargs *);
1720Sstevel@tonic-gate static void nfslog_writeresult_print(struct nfsl_log_file *,
1730Sstevel@tonic-gate 	nfslog_writeresult *, bool_t);
1740Sstevel@tonic-gate static void nfslog_creatargs_print(struct nfsl_log_file *,
1750Sstevel@tonic-gate 	nfslog_createargs *);
1760Sstevel@tonic-gate static void nfslog_rddirargs_print(struct nfsl_log_file *, nfslog_rddirargs *);
1770Sstevel@tonic-gate static void nfslog_linkargs_print(struct nfsl_log_file *, nfslog_linkargs *);
1780Sstevel@tonic-gate static void nfslog_rnmargs_print(struct nfsl_log_file *, nfslog_rnmargs *);
1790Sstevel@tonic-gate static void nfslog_symlinkargs_print(struct nfsl_log_file *,
1800Sstevel@tonic-gate 	nfslog_symlinkargs *);
1810Sstevel@tonic-gate 
1820Sstevel@tonic-gate static void nfslog_sharefsargs_print(struct nfsl_log_file *,
1830Sstevel@tonic-gate 	nfslog_sharefsargs *);
1840Sstevel@tonic-gate static void nfslog_getfhargs_print(struct nfsl_log_file *,
1850Sstevel@tonic-gate 	nfslog_getfhargs *);
1860Sstevel@tonic-gate 
1870Sstevel@tonic-gate /* Functions for elf print of the response */
1880Sstevel@tonic-gate static void nfslog_nfsstat_print(struct nfsl_log_file *, enum nfsstat *,
1890Sstevel@tonic-gate 	bool_t);
1900Sstevel@tonic-gate static void nfslog_diropres_print(struct nfsl_log_file *, nfslog_diropres *,
1910Sstevel@tonic-gate 	bool_t);
1920Sstevel@tonic-gate static void nfslog_rdlnres_print(struct nfsl_log_file *, nfslog_rdlnres *,
1930Sstevel@tonic-gate 	bool_t);
1940Sstevel@tonic-gate static void nfslog_rdresult_print(struct nfsl_log_file *,
1950Sstevel@tonic-gate 	nfslog_rdresult *, bool_t);
1960Sstevel@tonic-gate static void nfslog_rddirres_print(struct nfsl_log_file *, nfslog_rddirres *,
1970Sstevel@tonic-gate 	bool_t);
1980Sstevel@tonic-gate 
1990Sstevel@tonic-gate /*
2000Sstevel@tonic-gate  * NFS VERSION 3
2010Sstevel@tonic-gate  */
2020Sstevel@tonic-gate 
2030Sstevel@tonic-gate /* Functions for elf print of the arguments */
2040Sstevel@tonic-gate static void nfslog_fh3_print(struct nfsl_log_file *, nfs_fh3 *);
2050Sstevel@tonic-gate static void nfslog_diropargs3_print(struct nfsl_log_file *,
2060Sstevel@tonic-gate 	nfslog_diropargs3 *);
2070Sstevel@tonic-gate static void nfslog_SETATTR3args_print(struct nfsl_log_file *,
2080Sstevel@tonic-gate 	nfslog_SETATTR3args *);
2090Sstevel@tonic-gate static void nfslog_READ3args_print(struct nfsl_log_file *, nfslog_READ3args *);
2100Sstevel@tonic-gate static void nfslog_WRITE3args_print(struct nfsl_log_file *,
2110Sstevel@tonic-gate 	nfslog_WRITE3args *);
2120Sstevel@tonic-gate static void nfslog_CREATE3args_print(struct nfsl_log_file *,
2130Sstevel@tonic-gate 	nfslog_CREATE3args *);
2140Sstevel@tonic-gate static void nfslog_MKDIR3args_print(struct nfsl_log_file *,
2150Sstevel@tonic-gate 	nfslog_MKDIR3args *);
2160Sstevel@tonic-gate static void nfslog_SYMLINK3args_print(struct nfsl_log_file *,
2170Sstevel@tonic-gate 	nfslog_SYMLINK3args *);
2180Sstevel@tonic-gate static void nfslog_MKNOD3args_print(struct nfsl_log_file *,
2190Sstevel@tonic-gate 	nfslog_MKNOD3args *);
2200Sstevel@tonic-gate static void nfslog_REMOVE3args_print(struct nfsl_log_file *,
2210Sstevel@tonic-gate 	nfslog_REMOVE3args *);
2220Sstevel@tonic-gate static void nfslog_RMDIR3args_print(struct nfsl_log_file *,
2230Sstevel@tonic-gate 	nfslog_RMDIR3args *);
2240Sstevel@tonic-gate static void nfslog_RENAME3args_print(struct nfsl_log_file *,
2250Sstevel@tonic-gate 	nfslog_RENAME3args *);
2260Sstevel@tonic-gate static void nfslog_LINK3args_print(struct nfsl_log_file *,
2270Sstevel@tonic-gate 	nfslog_LINK3args *);
2280Sstevel@tonic-gate static void nfslog_COMMIT3args_print(struct nfsl_log_file *,
2290Sstevel@tonic-gate 	nfslog_COMMIT3args *);
2300Sstevel@tonic-gate static void nfslog_READDIRPLUS3args_print(struct nfsl_log_file *,
2310Sstevel@tonic-gate 	nfslog_READDIRPLUS3args *);
2320Sstevel@tonic-gate 
2330Sstevel@tonic-gate /* Functions for elf print of the response */
2340Sstevel@tonic-gate static void nfslog_nfsstat3_print(struct nfsl_log_file *,
2350Sstevel@tonic-gate 	nfsstat3 *, bool_t);
2360Sstevel@tonic-gate static void nfslog_LOOKUP3res_print(struct nfsl_log_file *,
2370Sstevel@tonic-gate 	nfslog_LOOKUP3res *, bool_t);
2380Sstevel@tonic-gate static void nfslog_READLINK3res_print(struct nfsl_log_file *,
2390Sstevel@tonic-gate 	nfslog_READLINK3res *, bool_t);
2400Sstevel@tonic-gate static void nfslog_READ3res_print(struct nfsl_log_file *,
2410Sstevel@tonic-gate 	nfslog_READ3res *, bool_t);
2420Sstevel@tonic-gate static void nfslog_WRITE3res_print(struct nfsl_log_file *,
2430Sstevel@tonic-gate 	nfslog_WRITE3res *, bool_t);
2440Sstevel@tonic-gate static void nfslog_CREATE3res_print(struct nfsl_log_file *,
2450Sstevel@tonic-gate 	nfslog_CREATE3res *, bool_t);
2460Sstevel@tonic-gate static void nfslog_MKDIR3res_print(struct nfsl_log_file *,
2470Sstevel@tonic-gate 	nfslog_MKDIR3res *, bool_t);
2480Sstevel@tonic-gate static void nfslog_SYMLINK3res_print(struct nfsl_log_file *,
2490Sstevel@tonic-gate 	nfslog_SYMLINK3res *, bool_t);
2500Sstevel@tonic-gate static void nfslog_MKNOD3res_print(struct nfsl_log_file *,
2510Sstevel@tonic-gate 	nfslog_MKNOD3res *, bool_t);
2520Sstevel@tonic-gate static void nfslog_READDIRPLUS3res_print(struct nfsl_log_file *,
2530Sstevel@tonic-gate 	nfslog_READDIRPLUS3res *, bool_t);
2540Sstevel@tonic-gate 
2550Sstevel@tonic-gate extern int debug;
2560Sstevel@tonic-gate static bool_t nfsl_print_fh = FALSE;		/* print file handles? */
2570Sstevel@tonic-gate 
2580Sstevel@tonic-gate #define	DFLT_BUFFERSIZE		8192
2590Sstevel@tonic-gate #define	DFLT_OVFSIZE		3072	/* Maximum logged or buffered size */
2600Sstevel@tonic-gate 
2610Sstevel@tonic-gate static char hostname[MAXHOSTNAMELEN];	/* name of host */
2620Sstevel@tonic-gate 
2630Sstevel@tonic-gate 
2640Sstevel@tonic-gate /*
2650Sstevel@tonic-gate  * Define the actions taken per prog/vers/proc:
2660Sstevel@tonic-gate  *
2670Sstevel@tonic-gate  * In some cases, the nl types are the same as the nfs types and a simple
2680Sstevel@tonic-gate  * bcopy should suffice. Rather that define tens of identical procedures,
2690Sstevel@tonic-gate  * simply define these to bcopy. Similarly this takes care of different
2700Sstevel@tonic-gate  * procs that use same parameter struct.
2710Sstevel@tonic-gate  */
2720Sstevel@tonic-gate 
2730Sstevel@tonic-gate static struct nfsl_proc_disp nfsl_elf_proc_v2[] = {
2740Sstevel@tonic-gate 	/*
2750Sstevel@tonic-gate 	 * NFS VERSION 2
2760Sstevel@tonic-gate 	 */
2770Sstevel@tonic-gate 
2780Sstevel@tonic-gate 	/* RFS_NULL = 0 */
2790Sstevel@tonic-gate 	{nfslog_null_args, nfslog_null_res, "\"null\""},
2800Sstevel@tonic-gate 
2810Sstevel@tonic-gate 	/* RFS_GETATTR = 1 */
2820Sstevel@tonic-gate 	{nfslog_fhandle_print, nfslog_nfsstat_print, "\"getattr\""},
2830Sstevel@tonic-gate 
2840Sstevel@tonic-gate 	/* RFS_SETATTR = 2 */
2850Sstevel@tonic-gate 	{nfslog_setattrargs_print, nfslog_nfsstat_print, "\"setattr\""},
2860Sstevel@tonic-gate 
2870Sstevel@tonic-gate 	/* RFS_ROOT = 3 *** NO LONGER SUPPORTED *** */
2880Sstevel@tonic-gate 	{nfslog_null_args, nfslog_null_res, "\"root\""},
2890Sstevel@tonic-gate 
2900Sstevel@tonic-gate 	/* RFS_LOOKUP = 4 */
2910Sstevel@tonic-gate 	{nfslog_diropargs_print, nfslog_diropres_print, "\"lookup\""},
2920Sstevel@tonic-gate 
2930Sstevel@tonic-gate 	/* RFS_READLINK = 5 */
2940Sstevel@tonic-gate 	{nfslog_fhandle_print, nfslog_rdlnres_print, "\"readlink\""},
2950Sstevel@tonic-gate 
2960Sstevel@tonic-gate 	/* RFS_READ = 6 */
2970Sstevel@tonic-gate 	{nfslog_nfsreadargs_print, nfslog_rdresult_print, "\"read\""},
2980Sstevel@tonic-gate 
2990Sstevel@tonic-gate 	/* RFS_WRITECACHE = 7 *** NO LONGER SUPPORTED *** */
3000Sstevel@tonic-gate 	{nfslog_null_args, nfslog_null_res, "\"writecache\""},
3010Sstevel@tonic-gate 
3020Sstevel@tonic-gate 	/* RFS_WRITE = 8 */
3030Sstevel@tonic-gate 	{nfslog_writeargs_print, nfslog_writeresult_print, "\"write\""},
3040Sstevel@tonic-gate 
3050Sstevel@tonic-gate 	/* RFS_CREATE = 9 */
3060Sstevel@tonic-gate 	{nfslog_creatargs_print, nfslog_diropres_print, "\"create\""},
3070Sstevel@tonic-gate 
3080Sstevel@tonic-gate 	/* RFS_REMOVE = 10 */
3090Sstevel@tonic-gate 	{nfslog_diropargs_print, nfslog_nfsstat_print, "\"remove\""},
3100Sstevel@tonic-gate 
3110Sstevel@tonic-gate 	/* RFS_RENAME = 11 */
3120Sstevel@tonic-gate 	{nfslog_rnmargs_print, nfslog_nfsstat_print, "\"rename\""},
3130Sstevel@tonic-gate 
3140Sstevel@tonic-gate 	/* RFS_LINK = 12 */
3150Sstevel@tonic-gate 	{nfslog_linkargs_print, nfslog_nfsstat_print, "\"link\""},
3160Sstevel@tonic-gate 
3170Sstevel@tonic-gate 	/* RFS_SYMLINK = 13 */
3180Sstevel@tonic-gate 	{nfslog_symlinkargs_print, nfslog_nfsstat_print, "\"symlink\""},
3190Sstevel@tonic-gate 
3200Sstevel@tonic-gate 	/* RFS_MKDIR = 14 */
3210Sstevel@tonic-gate 	{nfslog_creatargs_print, nfslog_diropres_print, "\"mkdir\""},
3220Sstevel@tonic-gate 
3230Sstevel@tonic-gate 	/* RFS_RMDIR = 15 */
3240Sstevel@tonic-gate 	{nfslog_diropargs_print, nfslog_nfsstat_print, "\"rmdir\""},
3250Sstevel@tonic-gate 
3260Sstevel@tonic-gate 	/* RFS_READDIR = 16 */
3270Sstevel@tonic-gate 	{nfslog_rddirargs_print, nfslog_rddirres_print, "\"readdir\""},
3280Sstevel@tonic-gate 
3290Sstevel@tonic-gate 	/* RFS_STATFS = 17 */
3300Sstevel@tonic-gate 	{nfslog_fhandle_print, nfslog_nfsstat_print, "\"statfs\""},
3310Sstevel@tonic-gate };
3320Sstevel@tonic-gate 
3330Sstevel@tonic-gate 
3340Sstevel@tonic-gate /*
3350Sstevel@tonic-gate  * NFS VERSION 3
3360Sstevel@tonic-gate  */
3370Sstevel@tonic-gate 
3380Sstevel@tonic-gate static struct nfsl_proc_disp nfsl_elf_proc_v3[] = {
3390Sstevel@tonic-gate 
3400Sstevel@tonic-gate 	/* NFSPROC3_NULL = 0 */
3410Sstevel@tonic-gate 	{nfslog_null_args, nfslog_null_res, "\"null\""},
3420Sstevel@tonic-gate 
3430Sstevel@tonic-gate 	/* NFSPROC3_GETATTR = 1 */
3440Sstevel@tonic-gate 	{nfslog_fh3_print, nfslog_nfsstat3_print, "\"getattr\""},
3450Sstevel@tonic-gate 
3460Sstevel@tonic-gate 	/* NFSPROC3_SETATTR = 2 */
3470Sstevel@tonic-gate 	{nfslog_SETATTR3args_print, nfslog_nfsstat3_print, "\"setattr\""},
3480Sstevel@tonic-gate 
3490Sstevel@tonic-gate 	/* NFSPROC3_LOOKUP = 3 */
3500Sstevel@tonic-gate 	{nfslog_diropargs3_print, nfslog_LOOKUP3res_print, "\"lookup\""},
3510Sstevel@tonic-gate 
3520Sstevel@tonic-gate 	/* NFSPROC3_ACCESS = 4 */
3530Sstevel@tonic-gate 	{nfslog_fh3_print, nfslog_nfsstat3_print, "\"access\""},
3540Sstevel@tonic-gate 
3550Sstevel@tonic-gate 	/* NFSPROC3_READLINK = 5 */
3560Sstevel@tonic-gate 	{nfslog_fh3_print, nfslog_READLINK3res_print, "\"readlink\""},
3570Sstevel@tonic-gate 
3580Sstevel@tonic-gate 	/* NFSPROC3_READ = 6 */
3590Sstevel@tonic-gate 	{nfslog_READ3args_print, nfslog_READ3res_print, "\"read\""},
3600Sstevel@tonic-gate 
3610Sstevel@tonic-gate 	/* NFSPROC3_WRITE = 7 */
3620Sstevel@tonic-gate 	{nfslog_WRITE3args_print, nfslog_WRITE3res_print, "\"write\""},
3630Sstevel@tonic-gate 
3640Sstevel@tonic-gate 	/* NFSPROC3_CREATE = 8 */
3650Sstevel@tonic-gate 	{nfslog_CREATE3args_print, nfslog_CREATE3res_print, "\"create\""},
3660Sstevel@tonic-gate 
3670Sstevel@tonic-gate 	/* NFSPROC3_MKDIR = 9 */
3680Sstevel@tonic-gate 	{nfslog_MKDIR3args_print, nfslog_MKDIR3res_print, "\"mkdir\""},
3690Sstevel@tonic-gate 
3700Sstevel@tonic-gate 	/* NFSPROC3_SYMLINK = 10 */
3710Sstevel@tonic-gate 	{nfslog_SYMLINK3args_print, nfslog_SYMLINK3res_print, "\"symlink\""},
3720Sstevel@tonic-gate 
3730Sstevel@tonic-gate 	/* NFSPROC3_MKNOD = 11 */
3740Sstevel@tonic-gate 	{nfslog_MKNOD3args_print, nfslog_MKNOD3res_print, "\"mknod\""},
3750Sstevel@tonic-gate 
3760Sstevel@tonic-gate 	/* NFSPROC3_REMOVE = 12 */
3770Sstevel@tonic-gate 	{nfslog_REMOVE3args_print, nfslog_nfsstat3_print, "\"remove\""},
3780Sstevel@tonic-gate 
3790Sstevel@tonic-gate 	/* NFSPROC3_RMDIR = 13 */
3800Sstevel@tonic-gate 	{nfslog_RMDIR3args_print, nfslog_nfsstat3_print, "\"rmdir\""},
3810Sstevel@tonic-gate 
3820Sstevel@tonic-gate 	/* NFSPROC3_RENAME = 14 */
3830Sstevel@tonic-gate 	{nfslog_RENAME3args_print, nfslog_nfsstat3_print, "\"rename\""},
3840Sstevel@tonic-gate 
3850Sstevel@tonic-gate 	/* NFSPROC3_LINK = 15 */
3860Sstevel@tonic-gate 	{nfslog_LINK3args_print, nfslog_nfsstat3_print, "\"link\""},
3870Sstevel@tonic-gate 
3880Sstevel@tonic-gate 	/* NFSPROC3_READDIR = 16 */
3890Sstevel@tonic-gate 	{nfslog_fh3_print, nfslog_nfsstat3_print, "\"readdir\""},
3900Sstevel@tonic-gate 
3910Sstevel@tonic-gate 	/* NFSPROC3_READDIRPLUS = 17 */
3920Sstevel@tonic-gate 	{nfslog_READDIRPLUS3args_print, nfslog_READDIRPLUS3res_print,
3930Sstevel@tonic-gate 		"\"readdirplus\""},
3940Sstevel@tonic-gate 
3950Sstevel@tonic-gate 	/* NFSPROC3_FSSTAT = 18 */
3960Sstevel@tonic-gate 	{nfslog_fh3_print, nfslog_nfsstat3_print, "\"fsstat\""},
3970Sstevel@tonic-gate 
3980Sstevel@tonic-gate 	/* NFSPROC3_FSINFO = 19 */
3990Sstevel@tonic-gate 	{nfslog_fh3_print, nfslog_nfsstat3_print, "\"fsinfo\""},
4000Sstevel@tonic-gate 
4010Sstevel@tonic-gate 	/* NFSPROC3_PATHCONF = 20 */
4020Sstevel@tonic-gate 	{nfslog_fh3_print, nfslog_nfsstat3_print, "\"pathconf\""},
4030Sstevel@tonic-gate 
4040Sstevel@tonic-gate 	/* NFSPROC3_COMMIT = 21 */
4050Sstevel@tonic-gate 	{nfslog_COMMIT3args_print, nfslog_nfsstat3_print, "\"commit\""},
4060Sstevel@tonic-gate };
4070Sstevel@tonic-gate 
4080Sstevel@tonic-gate /*
4090Sstevel@tonic-gate  * NFSLOG VERSION 1
4100Sstevel@tonic-gate  */
4110Sstevel@tonic-gate 
4120Sstevel@tonic-gate static struct nfsl_proc_disp nfsl_log_elf_proc_v1[] = {
4130Sstevel@tonic-gate 
4140Sstevel@tonic-gate 	/* NFSLOG_NULL = 0 */
4150Sstevel@tonic-gate 	{nfslog_null_args, nfslog_null_res, "\"null\""},
4160Sstevel@tonic-gate 
4170Sstevel@tonic-gate 	/* NFSLOG_SHARE = 1 */
4180Sstevel@tonic-gate 	{nfslog_sharefsargs_print, nfslog_nfsstat_print, "\"log_share\""},
4190Sstevel@tonic-gate 
4200Sstevel@tonic-gate 	/* NFSLOG_UNSHARE = 2 */
4210Sstevel@tonic-gate 	{nfslog_sharefsargs_print, nfslog_nfsstat_print, "\"log_unshare\""},
4220Sstevel@tonic-gate 
4230Sstevel@tonic-gate 	/* NFSLOG_LOOKUP = 3 */
4240Sstevel@tonic-gate 	{nfslog_diropargs3_print, nfslog_LOOKUP3res_print, "\"lookup\""},
4250Sstevel@tonic-gate 
4260Sstevel@tonic-gate 	/* NFSLOG_GETFH = 4 */
4270Sstevel@tonic-gate 	{nfslog_getfhargs_print, nfslog_nfsstat_print, "\"log_getfh\""},
4280Sstevel@tonic-gate };
4290Sstevel@tonic-gate 
4300Sstevel@tonic-gate static struct nfsl_vers_disp nfsl_elf_vers_disptable[] = {
4310Sstevel@tonic-gate 	{sizeof (nfsl_elf_proc_v2) / sizeof (nfsl_elf_proc_v2[0]),
4320Sstevel@tonic-gate 	    nfsl_elf_proc_v2},
4330Sstevel@tonic-gate 	{sizeof (nfsl_elf_proc_v3) / sizeof (nfsl_elf_proc_v3[0]),
4340Sstevel@tonic-gate 	    nfsl_elf_proc_v3},
4350Sstevel@tonic-gate };
4360Sstevel@tonic-gate 
4370Sstevel@tonic-gate static struct nfsl_vers_disp nfsl_log_elf_vers_disptable[] = {
4380Sstevel@tonic-gate 	{sizeof (nfsl_log_elf_proc_v1) / sizeof (nfsl_log_elf_proc_v1[0]),
4390Sstevel@tonic-gate 	    nfsl_log_elf_proc_v1},
4400Sstevel@tonic-gate };
4410Sstevel@tonic-gate 
4420Sstevel@tonic-gate static struct nfsl_prog_disp nfsl_elf_dispatch_table[] = {
4430Sstevel@tonic-gate 	{NFS_PROGRAM,
4440Sstevel@tonic-gate 	    NFS_VERSMIN,
4450Sstevel@tonic-gate 	    sizeof (nfsl_elf_vers_disptable) /
4460Sstevel@tonic-gate 		sizeof (nfsl_elf_vers_disptable[0]),
4470Sstevel@tonic-gate 	    nfsl_elf_vers_disptable, "nfs"},
4480Sstevel@tonic-gate 	{NFSLOG_PROGRAM,
4490Sstevel@tonic-gate 	    NFSLOG_VERSMIN,
4500Sstevel@tonic-gate 	    sizeof (nfsl_log_elf_vers_disptable) /
4510Sstevel@tonic-gate 		sizeof (nfsl_log_elf_vers_disptable[0]),
4520Sstevel@tonic-gate 	    nfsl_log_elf_vers_disptable, "nfslog"},
4530Sstevel@tonic-gate };
4540Sstevel@tonic-gate 
4550Sstevel@tonic-gate static int	nfsl_elf_dispatch_table_arglen =
4560Sstevel@tonic-gate 			sizeof (nfsl_elf_dispatch_table) /
4570Sstevel@tonic-gate 			sizeof (nfsl_elf_dispatch_table[0]);
4580Sstevel@tonic-gate 
4590Sstevel@tonic-gate static char *
nfslog_get_status(short status)4600Sstevel@tonic-gate nfslog_get_status(short status)
4610Sstevel@tonic-gate {
4620Sstevel@tonic-gate 	int	low, mid, high;
4630Sstevel@tonic-gate 	short	errstat;
4640Sstevel@tonic-gate 
4650Sstevel@tonic-gate 	/* Usually status is 0... */
4660Sstevel@tonic-gate 	if (status == 0)
4670Sstevel@tonic-gate 		return (nfsl_status_name[0]);
4680Sstevel@tonic-gate 
4690Sstevel@tonic-gate 	low = 0;
4700Sstevel@tonic-gate 	high = NFSL_ERR_CNT;
4710Sstevel@tonic-gate 	mid = NFSL_ERR_CNT / 2;
4720Sstevel@tonic-gate 	/* binary search for status string */
4730Sstevel@tonic-gate 	while (((errstat = nfsl_status[mid]) != status) && (low < mid) &&
4740Sstevel@tonic-gate 		(mid < high)) {
4750Sstevel@tonic-gate 		if (errstat > status) {	/* search bottom half */
4760Sstevel@tonic-gate 			high = mid;
4770Sstevel@tonic-gate 		} else {		/* search upper half */
4780Sstevel@tonic-gate 			low = mid;
4790Sstevel@tonic-gate 		}
4800Sstevel@tonic-gate 		mid = low + ((high - low) / 2);
4810Sstevel@tonic-gate 	}
4820Sstevel@tonic-gate 	if (errstat == status) {	/* found it */
4830Sstevel@tonic-gate 		return (nfsl_status_name[mid]);
4840Sstevel@tonic-gate 	}
4850Sstevel@tonic-gate 	return (NULL);
4860Sstevel@tonic-gate }
4870Sstevel@tonic-gate 
4880Sstevel@tonic-gate /* nfsl_get_time - return string with time formatted as hh:mm:ss */
4890Sstevel@tonic-gate static char *
nfsl_get_time(time_t tt)4900Sstevel@tonic-gate nfsl_get_time(time_t tt)
4910Sstevel@tonic-gate {
4920Sstevel@tonic-gate 	static char	timestr[20];
4930Sstevel@tonic-gate 	static time_t	lasttime;
4940Sstevel@tonic-gate 	struct tm	tmst;
4950Sstevel@tonic-gate 
4960Sstevel@tonic-gate 	if (tt == lasttime)
4970Sstevel@tonic-gate 		return (timestr);
4980Sstevel@tonic-gate 	if (localtime_r(&tt, &tmst) == NULL) {
4990Sstevel@tonic-gate 		return (empty_name);
5000Sstevel@tonic-gate 	}
5010Sstevel@tonic-gate 	(void) sprintf(timestr, "%02d:%02d:%02d",
5020Sstevel@tonic-gate 		tmst.tm_hour, tmst.tm_min, tmst.tm_sec);
5030Sstevel@tonic-gate 	lasttime = tt;
5040Sstevel@tonic-gate 	return (timestr);
5050Sstevel@tonic-gate }
5060Sstevel@tonic-gate 
5070Sstevel@tonic-gate /* nfsl_get_date - return date string formatted as "yyyy-mm-dd hh:mm:ss" */
5080Sstevel@tonic-gate static char *
nfsl_get_date(time_t tt)5090Sstevel@tonic-gate nfsl_get_date(time_t tt)
5100Sstevel@tonic-gate {
5110Sstevel@tonic-gate 	static char	timestr[30];
5120Sstevel@tonic-gate 	static time_t	lasttime;
5130Sstevel@tonic-gate 	struct tm	tmst;
5140Sstevel@tonic-gate 
5150Sstevel@tonic-gate 	if (tt == lasttime)
5160Sstevel@tonic-gate 		return (timestr);
5170Sstevel@tonic-gate 	if (localtime_r(&tt, &tmst) == NULL) {
5180Sstevel@tonic-gate 		return (empty_name);
5190Sstevel@tonic-gate 	}
5200Sstevel@tonic-gate 	(void) sprintf(timestr, "\"%04d-%02d-%02d %02d:%02d:%02d\"",
5210Sstevel@tonic-gate 		tmst.tm_year + 1900, tmst.tm_mon + 1, tmst.tm_mday,
5220Sstevel@tonic-gate 		tmst.tm_hour, tmst.tm_min, tmst.tm_sec);
5230Sstevel@tonic-gate 	lasttime = tt;
5240Sstevel@tonic-gate 	return (timestr);
5250Sstevel@tonic-gate }
5260Sstevel@tonic-gate 
5270Sstevel@tonic-gate /*
5280Sstevel@tonic-gate  * nfsl_get_date_nq - return date string formatted as yyyy-mm-dd hh:mm:ss
5290Sstevel@tonic-gate  * (no quotes)
5300Sstevel@tonic-gate  */
5310Sstevel@tonic-gate static char *
nfsl_get_date_nq(time_t tt)5320Sstevel@tonic-gate nfsl_get_date_nq(time_t tt)
5330Sstevel@tonic-gate {
5340Sstevel@tonic-gate 	static char	timestr[30];
5350Sstevel@tonic-gate 	static time_t	lasttime;
5360Sstevel@tonic-gate 	struct tm	tmst;
5370Sstevel@tonic-gate 
5380Sstevel@tonic-gate 	if (tt == lasttime)
5390Sstevel@tonic-gate 		return (timestr);
5400Sstevel@tonic-gate 	if (localtime_r(&tt, &tmst) == NULL) {
5410Sstevel@tonic-gate 		return (empty_name);
5420Sstevel@tonic-gate 	}
5430Sstevel@tonic-gate 	(void) sprintf(timestr, "%04d-%02d-%02d %02d:%02d:%02d",
5440Sstevel@tonic-gate 		tmst.tm_year + 1900, tmst.tm_mon + 1, tmst.tm_mday,
5450Sstevel@tonic-gate 		tmst.tm_hour, tmst.tm_min, tmst.tm_sec);
5460Sstevel@tonic-gate 	return (timestr);
5470Sstevel@tonic-gate }
5480Sstevel@tonic-gate 
5490Sstevel@tonic-gate /* write log buffer out to file */
5500Sstevel@tonic-gate static int
nfsl_write_elfbuf(struct nfsl_log_file * elfrec)5510Sstevel@tonic-gate nfsl_write_elfbuf(struct nfsl_log_file *elfrec)
5520Sstevel@tonic-gate {
5530Sstevel@tonic-gate 	int	rc;
5540Sstevel@tonic-gate 	char	*elfbuf = elfrec->buf;
5550Sstevel@tonic-gate 	int	elfbufoffset = elfrec->bufoffset;
5560Sstevel@tonic-gate 
5570Sstevel@tonic-gate 	if (debug > 1)
5580Sstevel@tonic-gate 		(void) printf("nfsl_write_elfbuf: bufoffset %d\n",
5590Sstevel@tonic-gate 			elfbufoffset);
5600Sstevel@tonic-gate 	if (elfbufoffset <= 0)
5610Sstevel@tonic-gate 		return (0);
5620Sstevel@tonic-gate 	elfbuf[elfbufoffset] = '\0';
5630Sstevel@tonic-gate 	if ((rc = fputs(elfbuf, elfrec->fp)) < 0) {
5640Sstevel@tonic-gate 		syslog(LOG_ERR, gettext("Write to %s failed: %s\n"),
5650Sstevel@tonic-gate 			elfrec->path, strerror(errno));
5660Sstevel@tonic-gate 		return (-1);
5670Sstevel@tonic-gate 	}
5680Sstevel@tonic-gate 	if (rc != elfbufoffset) {
5690Sstevel@tonic-gate 		syslog(LOG_ERR, gettext("Write %d bytes to %s returned %d\n"),
5700Sstevel@tonic-gate 			elfbufoffset, elfrec->path, rc);
5710Sstevel@tonic-gate 		return (-1);
5720Sstevel@tonic-gate 	}
5730Sstevel@tonic-gate 	elfrec->bufoffset = 0;
5740Sstevel@tonic-gate 	return (0);
5750Sstevel@tonic-gate }
5760Sstevel@tonic-gate 
5770Sstevel@tonic-gate /*ARGSUSED*/
5780Sstevel@tonic-gate static void
nfslog_null_args(struct nfsl_log_file * elfrec,caddr_t * nfsl_args)5790Sstevel@tonic-gate nfslog_null_args(struct nfsl_log_file *elfrec, caddr_t *nfsl_args)
5800Sstevel@tonic-gate {
5810Sstevel@tonic-gate }
5820Sstevel@tonic-gate 
5830Sstevel@tonic-gate /*ARGSUSED*/
5840Sstevel@tonic-gate static void
nfslog_null_res(struct nfsl_log_file * elfrec,caddr_t * nfsl_res)5850Sstevel@tonic-gate nfslog_null_res(struct nfsl_log_file *elfrec, caddr_t *nfsl_res)
5860Sstevel@tonic-gate {
5870Sstevel@tonic-gate }
5880Sstevel@tonic-gate 
5890Sstevel@tonic-gate static void
nfslog_fh3_print(struct nfsl_log_file * elfrec,nfs_fh3 * fh3)5900Sstevel@tonic-gate nfslog_fh3_print(struct nfsl_log_file *elfrec, nfs_fh3 *fh3)
5910Sstevel@tonic-gate {
5920Sstevel@tonic-gate 	if (!nfsl_print_fh)
5930Sstevel@tonic-gate 		return;
594*1610Sthurlow 	if (fh3->fh3_length == sizeof (fhandle_t)) {
595*1610Sthurlow 		nfslog_fhandle_print(elfrec, (fhandle_t *)&fh3->fh3_u.data);
5960Sstevel@tonic-gate 	} else {
5970Sstevel@tonic-gate 		nfslog_opaque_print_buf(fh3->fh3_u.data, fh3->fh3_length,
5980Sstevel@tonic-gate 			elfrec->buf, &elfrec->bufoffset,
5990Sstevel@tonic-gate 			DFLT_BUFFERSIZE + DFLT_OVFSIZE);
6000Sstevel@tonic-gate 	}
6010Sstevel@tonic-gate }
6020Sstevel@tonic-gate 
6030Sstevel@tonic-gate /*
6040Sstevel@tonic-gate  * NFS VERSION 2
6050Sstevel@tonic-gate  */
6060Sstevel@tonic-gate 
6070Sstevel@tonic-gate 
6080Sstevel@tonic-gate /* Functions that elf print the arguments */
6090Sstevel@tonic-gate 
6100Sstevel@tonic-gate static void
nfslog_fhandle_print(struct nfsl_log_file * elfrec,fhandle_t * args)6110Sstevel@tonic-gate nfslog_fhandle_print(struct nfsl_log_file *elfrec, fhandle_t *args)
6120Sstevel@tonic-gate {
6130Sstevel@tonic-gate 	if (!nfsl_print_fh)
6140Sstevel@tonic-gate 		return;
6150Sstevel@tonic-gate 	nfslog_opaque_print_buf(args, sizeof (*args),
6160Sstevel@tonic-gate 			elfrec->buf, &elfrec->bufoffset,
6170Sstevel@tonic-gate 			DFLT_BUFFERSIZE + DFLT_OVFSIZE);
6180Sstevel@tonic-gate }
6190Sstevel@tonic-gate 
6200Sstevel@tonic-gate static void
nfslog_diropargs_print(struct nfsl_log_file * elfrec,nfslog_diropargs * args)6210Sstevel@tonic-gate nfslog_diropargs_print(struct nfsl_log_file *elfrec, nfslog_diropargs *args)
6220Sstevel@tonic-gate {
6230Sstevel@tonic-gate 	char	*elfbuf = elfrec->buf;
6240Sstevel@tonic-gate 	int	elfbufoffset = elfrec->bufoffset;
6250Sstevel@tonic-gate 
6260Sstevel@tonic-gate 	if (nfsl_print_fh) {
6270Sstevel@tonic-gate 		nfslog_fhandle_print(elfrec, &args->da_fhandle);
6280Sstevel@tonic-gate 		elfbufoffset = elfrec->bufoffset;
6290Sstevel@tonic-gate 		if (args->da_name != NULL) {
6300Sstevel@tonic-gate 			elfbufoffset += sprintf(&elfbuf[elfbufoffset],
6310Sstevel@tonic-gate 				" \"%s\"", args->da_name);
6320Sstevel@tonic-gate 		} else {
6330Sstevel@tonic-gate 			elfbufoffset += sprintf(&elfbuf[elfbufoffset], " %s",
6340Sstevel@tonic-gate 				empty_name);
6350Sstevel@tonic-gate 		}
6360Sstevel@tonic-gate 	}
6370Sstevel@tonic-gate 	elfrec->bufoffset = elfbufoffset;
6380Sstevel@tonic-gate }
6390Sstevel@tonic-gate 
6400Sstevel@tonic-gate static void
nfslog_sattr_print(struct nfsl_log_file * elfrec,nfslog_sattr * args)6410Sstevel@tonic-gate nfslog_sattr_print(struct nfsl_log_file *elfrec, nfslog_sattr *args)
6420Sstevel@tonic-gate {
6430Sstevel@tonic-gate 	char	*elfbuf = elfrec->buf;
6440Sstevel@tonic-gate 	int	elfbufoffset = elfrec->bufoffset;
6450Sstevel@tonic-gate 
6460Sstevel@tonic-gate /* BEGIN CSTYLED */
6470Sstevel@tonic-gate 	if (args->sa_mode != (uint32_t)-1) {
6480Sstevel@tonic-gate 		elfbufoffset += sprintf(&elfbuf[elfbufoffset],
6490Sstevel@tonic-gate 			" \"mode=0%o\"", args->sa_mode);
6500Sstevel@tonic-gate 	}
6510Sstevel@tonic-gate 	if (args->sa_uid != (uint32_t)-1) {
6520Sstevel@tonic-gate 		elfbufoffset += sprintf(&elfbuf[elfbufoffset],
6530Sstevel@tonic-gate 			" \"uid=0x%x\"", args->sa_uid);
6540Sstevel@tonic-gate 	}
6550Sstevel@tonic-gate 	if (args->sa_gid != (uint32_t)-1) {
6560Sstevel@tonic-gate 		elfbufoffset += sprintf(&elfbuf[elfbufoffset],
6570Sstevel@tonic-gate 			" \"gid=0x%x\"", args->sa_gid);
6580Sstevel@tonic-gate 	}
6590Sstevel@tonic-gate 	if (args->sa_size != (uint32_t)-1) {
6600Sstevel@tonic-gate 		elfbufoffset += sprintf(&elfbuf[elfbufoffset],
6610Sstevel@tonic-gate 			" \"size=0x%x\"", args->sa_size);
6620Sstevel@tonic-gate 	}
6630Sstevel@tonic-gate 	if (args->sa_atime.tv_sec != (uint32_t)-1) {
6640Sstevel@tonic-gate 		elfbufoffset += sprintf(&elfbuf[elfbufoffset],
6650Sstevel@tonic-gate 			" \"atime=%s\"",
6660Sstevel@tonic-gate 		    nfsl_get_date_nq((time_t)args->sa_atime.tv_sec));
6670Sstevel@tonic-gate 	}
6680Sstevel@tonic-gate 	if (args->sa_mtime.tv_sec != (uint32_t)-1) {
6690Sstevel@tonic-gate 		elfbufoffset += sprintf(&elfbuf[elfbufoffset],
6700Sstevel@tonic-gate 			" \"mtime=%s\"",
6710Sstevel@tonic-gate 		    nfsl_get_date_nq((time_t)args->sa_mtime.tv_sec));
6720Sstevel@tonic-gate 	}
6730Sstevel@tonic-gate /* END CSTYLED */
6740Sstevel@tonic-gate 	elfrec->bufoffset = elfbufoffset;
6750Sstevel@tonic-gate }
6760Sstevel@tonic-gate 
6770Sstevel@tonic-gate static void
nfslog_setattrargs_print(struct nfsl_log_file * elfrec,nfslog_setattrargs * args)6780Sstevel@tonic-gate nfslog_setattrargs_print(struct nfsl_log_file *elfrec, nfslog_setattrargs *args)
6790Sstevel@tonic-gate {
6800Sstevel@tonic-gate 	nfslog_fhandle_print(elfrec, &args->saa_fh);
6810Sstevel@tonic-gate 	nfslog_sattr_print(elfrec, &args->saa_sa);
6820Sstevel@tonic-gate }
6830Sstevel@tonic-gate 
6840Sstevel@tonic-gate static void
nfslog_nfsreadargs_print(struct nfsl_log_file * elfrec,nfslog_nfsreadargs * args)6850Sstevel@tonic-gate nfslog_nfsreadargs_print(struct nfsl_log_file *elfrec,
6860Sstevel@tonic-gate 	nfslog_nfsreadargs *args)
6870Sstevel@tonic-gate {
6880Sstevel@tonic-gate 	char	*elfbuf = elfrec->buf;
6890Sstevel@tonic-gate 	int	elfbufoffset;
6900Sstevel@tonic-gate 
6910Sstevel@tonic-gate 	nfslog_fhandle_print(elfrec, &args->ra_fhandle);
6920Sstevel@tonic-gate 	elfbufoffset = elfrec->bufoffset;
6930Sstevel@tonic-gate 	elfbufoffset += sprintf(&elfbuf[elfbufoffset], " 0x%x",
6940Sstevel@tonic-gate 		args->ra_offset);
6950Sstevel@tonic-gate 	elfbufoffset += sprintf(&elfbuf[elfbufoffset], " 0x%x",
6960Sstevel@tonic-gate 		args->ra_count);
6970Sstevel@tonic-gate 	elfbufoffset += sprintf(&elfbuf[elfbufoffset], " 0x%x",
6980Sstevel@tonic-gate 		args->ra_totcount);
6990Sstevel@tonic-gate 	elfrec->bufoffset = elfbufoffset;
7000Sstevel@tonic-gate }
7010Sstevel@tonic-gate 
7020Sstevel@tonic-gate static void
nfslog_writeargs_print(struct nfsl_log_file * elfrec,nfslog_writeargs * args)7030Sstevel@tonic-gate nfslog_writeargs_print(struct nfsl_log_file *elfrec, nfslog_writeargs *args)
7040Sstevel@tonic-gate {
7050Sstevel@tonic-gate 	char	*elfbuf = elfrec->buf;
7060Sstevel@tonic-gate 	int	elfbufoffset = elfrec->bufoffset;
7070Sstevel@tonic-gate 
7080Sstevel@tonic-gate 	nfslog_fhandle_print(elfrec, &args->waargs_fhandle);
7090Sstevel@tonic-gate 	elfbufoffset = elfrec->bufoffset;
7100Sstevel@tonic-gate 	elfbufoffset += sprintf(&elfbuf[elfbufoffset], " 0x%x",
7110Sstevel@tonic-gate 		args->waargs_begoff);
7120Sstevel@tonic-gate 	elfbufoffset += sprintf(&elfbuf[elfbufoffset], " 0x%x",
7130Sstevel@tonic-gate 		args->waargs_offset);
7140Sstevel@tonic-gate 	elfbufoffset += sprintf(&elfbuf[elfbufoffset], " 0x%x",
7150Sstevel@tonic-gate 		args->waargs_totcount);
7160Sstevel@tonic-gate 	elfrec->bufoffset += sprintf(&elfrec->buf[elfrec->bufoffset], " 0x%x",
7170Sstevel@tonic-gate 		args->waargs_count);
7180Sstevel@tonic-gate }
7190Sstevel@tonic-gate 
7200Sstevel@tonic-gate static void
nfslog_writeresult_print(struct nfsl_log_file * elfrec,nfslog_writeresult * res,bool_t print_status)7210Sstevel@tonic-gate nfslog_writeresult_print(struct nfsl_log_file *elfrec, nfslog_writeresult *res,
7220Sstevel@tonic-gate 	bool_t print_status)
7230Sstevel@tonic-gate {
7240Sstevel@tonic-gate 	char	*elfbuf = elfrec->buf;
7250Sstevel@tonic-gate 	int	elfbufoffset = elfrec->bufoffset;
7260Sstevel@tonic-gate 
7270Sstevel@tonic-gate 	if (print_status) {
7280Sstevel@tonic-gate 		nfslog_nfsstat_print(elfrec, &res->wr_status, print_status);
7290Sstevel@tonic-gate 	} else if (res->wr_status == NFS_OK) {
7300Sstevel@tonic-gate 		elfbufoffset += sprintf(&elfbuf[elfbufoffset], " 0x%x",
7310Sstevel@tonic-gate 			res->nfslog_writeresult_u.wr_size);
7320Sstevel@tonic-gate 		elfrec->bufoffset = elfbufoffset;
7330Sstevel@tonic-gate 	}
7340Sstevel@tonic-gate }
7350Sstevel@tonic-gate 
7360Sstevel@tonic-gate static void
nfslog_creatargs_print(struct nfsl_log_file * elfrec,nfslog_createargs * args)7370Sstevel@tonic-gate nfslog_creatargs_print(struct nfsl_log_file *elfrec, nfslog_createargs *args)
7380Sstevel@tonic-gate {
7390Sstevel@tonic-gate 	nfslog_diropargs_print(elfrec, &args->ca_da);
7400Sstevel@tonic-gate 	nfslog_sattr_print(elfrec, &args->ca_sa);
7410Sstevel@tonic-gate }
7420Sstevel@tonic-gate 
7430Sstevel@tonic-gate 
7440Sstevel@tonic-gate static void
nfslog_rddirargs_print(struct nfsl_log_file * elfrec,nfslog_rddirargs * args)7450Sstevel@tonic-gate nfslog_rddirargs_print(struct nfsl_log_file *elfrec, nfslog_rddirargs *args)
7460Sstevel@tonic-gate {
7470Sstevel@tonic-gate 	char	*elfbuf = elfrec->buf;
7480Sstevel@tonic-gate 	int	elfbufoffset;
7490Sstevel@tonic-gate 
7500Sstevel@tonic-gate 	nfslog_fhandle_print(elfrec, &args->rda_fh);
7510Sstevel@tonic-gate 	elfbufoffset = elfrec->bufoffset;
7520Sstevel@tonic-gate 	elfbufoffset += sprintf(&elfbuf[elfbufoffset], " 0x%x",
7530Sstevel@tonic-gate 		args->rda_offset);
7540Sstevel@tonic-gate 	elfbufoffset += sprintf(&elfbuf[elfbufoffset], " 0x%x",
7550Sstevel@tonic-gate 		args->rda_count);
7560Sstevel@tonic-gate 	elfrec->bufoffset = elfbufoffset;
7570Sstevel@tonic-gate }
7580Sstevel@tonic-gate 
7590Sstevel@tonic-gate static void
nfslog_rnmargs_print(struct nfsl_log_file * elfrec,nfslog_rnmargs * args)7600Sstevel@tonic-gate nfslog_rnmargs_print(struct nfsl_log_file *elfrec, nfslog_rnmargs *args)
7610Sstevel@tonic-gate {
7620Sstevel@tonic-gate 	nfslog_diropargs_print(elfrec, &args->rna_from);
7630Sstevel@tonic-gate 	nfslog_diropargs_print(elfrec, &args->rna_to);
7640Sstevel@tonic-gate }
7650Sstevel@tonic-gate 
7660Sstevel@tonic-gate static void
nfslog_linkargs_print(struct nfsl_log_file * elfrec,nfslog_linkargs * args)7670Sstevel@tonic-gate nfslog_linkargs_print(struct nfsl_log_file *elfrec, nfslog_linkargs *args)
7680Sstevel@tonic-gate {
7690Sstevel@tonic-gate 	nfslog_fhandle_print(elfrec, &args->la_from);
7700Sstevel@tonic-gate 	nfslog_diropargs_print(elfrec, &args->la_to);
7710Sstevel@tonic-gate }
7720Sstevel@tonic-gate 
7730Sstevel@tonic-gate static void
nfslog_symlinkargs_print(struct nfsl_log_file * elfrec,nfslog_symlinkargs * args)7740Sstevel@tonic-gate nfslog_symlinkargs_print(struct nfsl_log_file *elfrec, nfslog_symlinkargs *args)
7750Sstevel@tonic-gate {
7760Sstevel@tonic-gate 	char	*elfbuf = elfrec->buf;
7770Sstevel@tonic-gate 	int	elfbufoffset;
7780Sstevel@tonic-gate 
7790Sstevel@tonic-gate 	nfslog_diropargs_print(elfrec, &args->sla_from);
7800Sstevel@tonic-gate 	elfbufoffset = elfrec->bufoffset;
7810Sstevel@tonic-gate 	elfbufoffset += sprintf(&elfbuf[elfbufoffset], " \"%s\"",
7820Sstevel@tonic-gate 		args->sla_tnm);
7830Sstevel@tonic-gate 	elfrec->bufoffset = elfbufoffset;
7840Sstevel@tonic-gate 	nfslog_sattr_print(elfrec, &args->sla_sa);
7850Sstevel@tonic-gate }
7860Sstevel@tonic-gate 
7870Sstevel@tonic-gate /*
7880Sstevel@tonic-gate  * SHARE/UNSHARE fs log args copy
7890Sstevel@tonic-gate  */
7900Sstevel@tonic-gate static void
nfslog_sharefsargs_print(struct nfsl_log_file * elfrec,nfslog_sharefsargs * args)7910Sstevel@tonic-gate nfslog_sharefsargs_print(struct nfsl_log_file *elfrec,
7920Sstevel@tonic-gate 	nfslog_sharefsargs *args)
7930Sstevel@tonic-gate {
7940Sstevel@tonic-gate 	unsigned int	elfbufoffset;
7950Sstevel@tonic-gate 	char		*elfbuf = elfrec->buf;
7960Sstevel@tonic-gate 
7970Sstevel@tonic-gate 	nfslog_fhandle_print(elfrec, &args->sh_fh_buf);
7980Sstevel@tonic-gate 
7990Sstevel@tonic-gate 	elfbufoffset = elfrec->bufoffset;
8000Sstevel@tonic-gate 	elfbufoffset += sprintf(&elfbuf[elfbufoffset], " 0x%x",
8010Sstevel@tonic-gate 		args->sh_flags);
8020Sstevel@tonic-gate 	elfbufoffset += sprintf(&elfbuf[elfbufoffset], " 0x%x",
8030Sstevel@tonic-gate 		args->sh_anon);
8040Sstevel@tonic-gate 	if (nfsl_print_fh) {
8050Sstevel@tonic-gate 		if (args->sh_path != NULL) {
8060Sstevel@tonic-gate 			elfbufoffset += sprintf(&elfbuf[elfbufoffset],
8070Sstevel@tonic-gate 				" \"%s\"", args->sh_path);
8080Sstevel@tonic-gate 		} else {
8090Sstevel@tonic-gate 			elfbufoffset += sprintf(&elfbuf[elfbufoffset], " %s",
8100Sstevel@tonic-gate 				empty_name);
8110Sstevel@tonic-gate 		}
8120Sstevel@tonic-gate 	}
8130Sstevel@tonic-gate 	elfrec->bufoffset = elfbufoffset;
8140Sstevel@tonic-gate }
8150Sstevel@tonic-gate 
8160Sstevel@tonic-gate static void
nfslog_getfhargs_print(struct nfsl_log_file * elfrec,nfslog_getfhargs * args)8170Sstevel@tonic-gate nfslog_getfhargs_print(struct nfsl_log_file *elfrec,
8180Sstevel@tonic-gate 	nfslog_getfhargs *args)
8190Sstevel@tonic-gate {
8200Sstevel@tonic-gate 	unsigned int	elfbufoffset;
8210Sstevel@tonic-gate 	char		*elfbuf = elfrec->buf;
8220Sstevel@tonic-gate 
8230Sstevel@tonic-gate 	nfslog_fhandle_print(elfrec, &args->gfh_fh_buf);
8240Sstevel@tonic-gate 
8250Sstevel@tonic-gate 	elfbufoffset = elfrec->bufoffset;
8260Sstevel@tonic-gate 	if (nfsl_print_fh) {
8270Sstevel@tonic-gate 		if (args->gfh_path != NULL) {
8280Sstevel@tonic-gate 			elfbufoffset += sprintf(&elfbuf[elfbufoffset],
8290Sstevel@tonic-gate 				" \"%s\"", args->gfh_path);
8300Sstevel@tonic-gate 		} else {
8310Sstevel@tonic-gate 			elfbufoffset += sprintf(&elfbuf[elfbufoffset], " %s",
8320Sstevel@tonic-gate 				empty_name);
8330Sstevel@tonic-gate 		}
8340Sstevel@tonic-gate 	}
8350Sstevel@tonic-gate 	elfrec->bufoffset = elfbufoffset;
8360Sstevel@tonic-gate }
8370Sstevel@tonic-gate 
8380Sstevel@tonic-gate static void
nfslog_nfsstat_print(struct nfsl_log_file * elfrec,enum nfsstat * res,bool_t print_status)8390Sstevel@tonic-gate nfslog_nfsstat_print(struct nfsl_log_file *elfrec, enum nfsstat *res,
8400Sstevel@tonic-gate 	bool_t print_status)
8410Sstevel@tonic-gate {
8420Sstevel@tonic-gate 	if (print_status) {
8430Sstevel@tonic-gate 		char	*statp = nfslog_get_status((short)(*res));
8440Sstevel@tonic-gate 
8450Sstevel@tonic-gate 		if (statp != NULL)
8460Sstevel@tonic-gate 			elfrec->bufoffset +=
8470Sstevel@tonic-gate 				sprintf(&elfrec->buf[elfrec->bufoffset], " %s",
8480Sstevel@tonic-gate 						statp);
8490Sstevel@tonic-gate 		else
8500Sstevel@tonic-gate 			elfrec->bufoffset +=
8510Sstevel@tonic-gate 				sprintf(&elfrec->buf[elfrec->bufoffset], " %5d",
8520Sstevel@tonic-gate 						*res);
8530Sstevel@tonic-gate 	}
8540Sstevel@tonic-gate }
8550Sstevel@tonic-gate 
8560Sstevel@tonic-gate static void
nfslog_diropres_print(struct nfsl_log_file * elfrec,nfslog_diropres * res,bool_t print_status)8570Sstevel@tonic-gate nfslog_diropres_print(struct nfsl_log_file *elfrec, nfslog_diropres *res,
8580Sstevel@tonic-gate 	bool_t print_status)
8590Sstevel@tonic-gate {
8600Sstevel@tonic-gate 	if (print_status) {
8610Sstevel@tonic-gate 		nfslog_nfsstat_print(elfrec, &res->dr_status, print_status);
8620Sstevel@tonic-gate 	} else if (res->dr_status == NFS_OK) {
8630Sstevel@tonic-gate 		nfslog_fhandle_print(elfrec,
8640Sstevel@tonic-gate 			&res->nfslog_diropres_u.dr_ok.drok_fhandle);
8650Sstevel@tonic-gate 	}
8660Sstevel@tonic-gate }
8670Sstevel@tonic-gate 
8680Sstevel@tonic-gate static void
nfslog_rdlnres_print(struct nfsl_log_file * elfrec,nfslog_rdlnres * res,bool_t print_status)8690Sstevel@tonic-gate nfslog_rdlnres_print(struct nfsl_log_file *elfrec, nfslog_rdlnres *res,
8700Sstevel@tonic-gate 	bool_t print_status)
8710Sstevel@tonic-gate {
8720Sstevel@tonic-gate 	if (print_status) {
8730Sstevel@tonic-gate 		nfslog_nfsstat_print(elfrec, &res->rl_status, print_status);
8740Sstevel@tonic-gate 	} else if (res->rl_status == NFS_OK) {
8750Sstevel@tonic-gate 		elfrec->bufoffset += sprintf(&elfrec->buf[elfrec->bufoffset],
8760Sstevel@tonic-gate 			" \"%s\"", res->nfslog_rdlnres_u.rl_ok);
8770Sstevel@tonic-gate 	}
8780Sstevel@tonic-gate }
8790Sstevel@tonic-gate 
8800Sstevel@tonic-gate static void
nfslog_rdresult_print(struct nfsl_log_file * elfrec,nfslog_rdresult * res,bool_t print_status)8810Sstevel@tonic-gate nfslog_rdresult_print(struct nfsl_log_file *elfrec, nfslog_rdresult *res,
8820Sstevel@tonic-gate 	bool_t print_status)
8830Sstevel@tonic-gate {
8840Sstevel@tonic-gate 	if (print_status) {
8850Sstevel@tonic-gate 		nfslog_nfsstat_print(elfrec, &res->r_status, print_status);
8860Sstevel@tonic-gate 	} else if (res->r_status == NFS_OK) {
8870Sstevel@tonic-gate 		elfrec->bufoffset += sprintf(&elfrec->buf[elfrec->bufoffset],
8880Sstevel@tonic-gate 			" 0x%x", res->nfslog_rdresult_u.r_ok.filesize);
8890Sstevel@tonic-gate 		elfrec->bufoffset += sprintf(&elfrec->buf[elfrec->bufoffset],
8900Sstevel@tonic-gate 			" 0x%x", res->nfslog_rdresult_u.r_ok.rrok_count);
8910Sstevel@tonic-gate 	}
8920Sstevel@tonic-gate }
8930Sstevel@tonic-gate 
8940Sstevel@tonic-gate static void
nfslog_rddirres_print(struct nfsl_log_file * elfrec,nfslog_rddirres * res,bool_t print_status)8950Sstevel@tonic-gate nfslog_rddirres_print(struct nfsl_log_file *elfrec, nfslog_rddirres *res,
8960Sstevel@tonic-gate 	bool_t print_status)
8970Sstevel@tonic-gate {
8980Sstevel@tonic-gate 	if (print_status) {
8990Sstevel@tonic-gate 		nfslog_nfsstat_print(elfrec, &res->rd_status, print_status);
9000Sstevel@tonic-gate 	} else if (res->rd_status == NFS_OK) {
9010Sstevel@tonic-gate 		char	*elfbuf = elfrec->buf;
9020Sstevel@tonic-gate 		int	elfbufoffset = elfrec->bufoffset;
9030Sstevel@tonic-gate 
9040Sstevel@tonic-gate 		elfbufoffset += sprintf(&elfbuf[elfbufoffset], " 0x%x",
9050Sstevel@tonic-gate 			res->nfslog_rddirres_u.rd_ok.rdok_offset);
9060Sstevel@tonic-gate 		elfbufoffset += sprintf(&elfbuf[elfbufoffset], " 0x%x",
9070Sstevel@tonic-gate 			res->nfslog_rddirres_u.rd_ok.rdok_size);
9080Sstevel@tonic-gate 		elfbufoffset += sprintf(&elfbuf[elfbufoffset], " 0x%x",
9090Sstevel@tonic-gate 			res->nfslog_rddirres_u.rd_ok.rdok_eof);
9100Sstevel@tonic-gate 		elfrec->bufoffset = elfbufoffset;
9110Sstevel@tonic-gate 	}
9120Sstevel@tonic-gate }
9130Sstevel@tonic-gate 
9140Sstevel@tonic-gate /*
9150Sstevel@tonic-gate  * NFS VERSION 3
9160Sstevel@tonic-gate  */
9170Sstevel@tonic-gate 
9180Sstevel@tonic-gate static void
nfslog_diropargs3_print(struct nfsl_log_file * elfrec,nfslog_diropargs3 * args)9190Sstevel@tonic-gate nfslog_diropargs3_print(struct nfsl_log_file *elfrec,
9200Sstevel@tonic-gate 	nfslog_diropargs3 *args)
9210Sstevel@tonic-gate {
9220Sstevel@tonic-gate 	if (nfsl_print_fh) {
9230Sstevel@tonic-gate 		nfslog_fh3_print(elfrec, &args->dir);
9240Sstevel@tonic-gate 		elfrec->bufoffset += sprintf(&elfrec->buf[elfrec->bufoffset],
9250Sstevel@tonic-gate 			" \"%s\"", args->name);
9260Sstevel@tonic-gate 	}
9270Sstevel@tonic-gate }
9280Sstevel@tonic-gate 
9290Sstevel@tonic-gate static void
nfslog_size3_print(struct nfsl_log_file * elfrec,set_size3 * args)9300Sstevel@tonic-gate nfslog_size3_print(struct nfsl_log_file *elfrec, set_size3 *args)
9310Sstevel@tonic-gate {
9320Sstevel@tonic-gate 	char	*elfbuf = elfrec->buf;
9330Sstevel@tonic-gate 	int	elfbufoffset = elfrec->bufoffset;
9340Sstevel@tonic-gate 
9350Sstevel@tonic-gate 	if (args->set_it) {
9360Sstevel@tonic-gate 		elfbufoffset += sprintf(&elfbuf[elfbufoffset],
9370Sstevel@tonic-gate 		/* CSTYLED */
9380Sstevel@tonic-gate 			" \"size=0x%llx\"", args->size);
9390Sstevel@tonic-gate 	}
9400Sstevel@tonic-gate 	elfrec->bufoffset = elfbufoffset;
9410Sstevel@tonic-gate }
9420Sstevel@tonic-gate 
9430Sstevel@tonic-gate static void
nfslog_SETATTR3args_print(struct nfsl_log_file * elfrec,nfslog_SETATTR3args * args)9440Sstevel@tonic-gate nfslog_SETATTR3args_print(struct nfsl_log_file *elfrec,
9450Sstevel@tonic-gate 	nfslog_SETATTR3args *args)
9460Sstevel@tonic-gate {
9470Sstevel@tonic-gate 	nfslog_fh3_print(elfrec, &args->object);
9480Sstevel@tonic-gate 	nfslog_size3_print(elfrec, &args->size);
9490Sstevel@tonic-gate }
9500Sstevel@tonic-gate 
9510Sstevel@tonic-gate static void
nfslog_READ3args_print(struct nfsl_log_file * elfrec,nfslog_READ3args * args)9520Sstevel@tonic-gate nfslog_READ3args_print(struct nfsl_log_file *elfrec, nfslog_READ3args *args)
9530Sstevel@tonic-gate {
9540Sstevel@tonic-gate 	nfslog_fh3_print(elfrec, &args->file);
9550Sstevel@tonic-gate 	elfrec->bufoffset += sprintf(&elfrec->buf[elfrec->bufoffset], " 0x%llx",
9560Sstevel@tonic-gate 		args->offset);
9570Sstevel@tonic-gate 	elfrec->bufoffset += sprintf(&elfrec->buf[elfrec->bufoffset], " 0x%x",
9580Sstevel@tonic-gate 		args->count);
9590Sstevel@tonic-gate }
9600Sstevel@tonic-gate 
9610Sstevel@tonic-gate static void
nfslog_WRITE3args_print(struct nfsl_log_file * elfrec,nfslog_WRITE3args * args)9620Sstevel@tonic-gate nfslog_WRITE3args_print(struct nfsl_log_file *elfrec,
9630Sstevel@tonic-gate 	nfslog_WRITE3args *args)
9640Sstevel@tonic-gate {
9650Sstevel@tonic-gate 	char	*elfbuf = elfrec->buf;
9660Sstevel@tonic-gate 	int	elfbufoffset;
9670Sstevel@tonic-gate 
9680Sstevel@tonic-gate 	nfslog_fh3_print(elfrec, &args->file);
9690Sstevel@tonic-gate 	elfbufoffset = elfrec->bufoffset;
9700Sstevel@tonic-gate 	elfbufoffset += sprintf(&elfbuf[elfbufoffset], " 0x%llx",
9710Sstevel@tonic-gate 		args->offset);
9720Sstevel@tonic-gate 	elfbufoffset += sprintf(&elfbuf[elfbufoffset], " 0x%x",
9730Sstevel@tonic-gate 		args->count);
9740Sstevel@tonic-gate 	elfbufoffset += sprintf(&elfbuf[elfbufoffset], " 0x%x",
9750Sstevel@tonic-gate 		args->stable);
9760Sstevel@tonic-gate 	elfrec->bufoffset = elfbufoffset;
9770Sstevel@tonic-gate }
9780Sstevel@tonic-gate 
9790Sstevel@tonic-gate static void
nfslog_CREATE3args_print(struct nfsl_log_file * elfrec,nfslog_CREATE3args * args)9800Sstevel@tonic-gate nfslog_CREATE3args_print(struct nfsl_log_file *elfrec,
9810Sstevel@tonic-gate 	nfslog_CREATE3args *args)
9820Sstevel@tonic-gate {
9830Sstevel@tonic-gate 	nfslog_diropargs3_print(elfrec, &args->where);
9840Sstevel@tonic-gate 	elfrec->bufoffset += sprintf(&elfrec->buf[elfrec->bufoffset], " %s",
9850Sstevel@tonic-gate 		NFSL_CREATEMODE3(args->how.mode));
9860Sstevel@tonic-gate 	if (args->how.mode != EXCLUSIVE) {
9870Sstevel@tonic-gate 		nfslog_size3_print(elfrec,
9880Sstevel@tonic-gate 			&args->how.nfslog_createhow3_u.size);
9890Sstevel@tonic-gate 	}
9900Sstevel@tonic-gate }
9910Sstevel@tonic-gate 
9920Sstevel@tonic-gate static void
nfslog_MKDIR3args_print(struct nfsl_log_file * elfrec,nfslog_MKDIR3args * args)9930Sstevel@tonic-gate nfslog_MKDIR3args_print(struct nfsl_log_file *elfrec,
9940Sstevel@tonic-gate 	nfslog_MKDIR3args *args)
9950Sstevel@tonic-gate {
9960Sstevel@tonic-gate 	nfslog_diropargs3_print(elfrec, &args->where);
9970Sstevel@tonic-gate }
9980Sstevel@tonic-gate 
9990Sstevel@tonic-gate static void
nfslog_SYMLINK3args_print(struct nfsl_log_file * elfrec,nfslog_SYMLINK3args * args)10000Sstevel@tonic-gate nfslog_SYMLINK3args_print(struct nfsl_log_file *elfrec,
10010Sstevel@tonic-gate 	nfslog_SYMLINK3args *args)
10020Sstevel@tonic-gate {
10030Sstevel@tonic-gate 	nfslog_diropargs3_print(elfrec, &args->where);
10040Sstevel@tonic-gate 	elfrec->bufoffset += sprintf(&elfrec->buf[elfrec->bufoffset],
10050Sstevel@tonic-gate 		" \"%s\"", args->symlink_data);
10060Sstevel@tonic-gate }
10070Sstevel@tonic-gate 
10080Sstevel@tonic-gate static void
nfslog_MKNOD3args_print(struct nfsl_log_file * elfrec,nfslog_MKNOD3args * args)10090Sstevel@tonic-gate nfslog_MKNOD3args_print(struct nfsl_log_file *elfrec,
10100Sstevel@tonic-gate 	nfslog_MKNOD3args *args)
10110Sstevel@tonic-gate {
10120Sstevel@tonic-gate 	nfslog_diropargs3_print(elfrec, &args->where);
10130Sstevel@tonic-gate 	elfrec->bufoffset += sprintf(&elfrec->buf[elfrec->bufoffset], " %s",
10140Sstevel@tonic-gate 		NFSL_FTYPE3(args->type));
10150Sstevel@tonic-gate }
10160Sstevel@tonic-gate 
10170Sstevel@tonic-gate static void
nfslog_REMOVE3args_print(struct nfsl_log_file * elfrec,nfslog_REMOVE3args * args)10180Sstevel@tonic-gate nfslog_REMOVE3args_print(struct nfsl_log_file *elfrec,
10190Sstevel@tonic-gate 	nfslog_REMOVE3args *args)
10200Sstevel@tonic-gate {
10210Sstevel@tonic-gate 	nfslog_diropargs3_print(elfrec, &args->object);
10220Sstevel@tonic-gate }
10230Sstevel@tonic-gate 
10240Sstevel@tonic-gate static void
nfslog_RMDIR3args_print(struct nfsl_log_file * elfrec,nfslog_RMDIR3args * args)10250Sstevel@tonic-gate nfslog_RMDIR3args_print(struct nfsl_log_file *elfrec,
10260Sstevel@tonic-gate 	nfslog_RMDIR3args *args)
10270Sstevel@tonic-gate {
10280Sstevel@tonic-gate 	nfslog_diropargs3_print(elfrec, &args->object);
10290Sstevel@tonic-gate }
10300Sstevel@tonic-gate 
10310Sstevel@tonic-gate static void
nfslog_RENAME3args_print(struct nfsl_log_file * elfrec,nfslog_RENAME3args * args)10320Sstevel@tonic-gate nfslog_RENAME3args_print(struct nfsl_log_file *elfrec,
10330Sstevel@tonic-gate 	nfslog_RENAME3args *args)
10340Sstevel@tonic-gate {
10350Sstevel@tonic-gate 	nfslog_diropargs3_print(elfrec, &args->from);
10360Sstevel@tonic-gate 	nfslog_diropargs3_print(elfrec, &args->to);
10370Sstevel@tonic-gate }
10380Sstevel@tonic-gate 
10390Sstevel@tonic-gate static void
nfslog_LINK3args_print(struct nfsl_log_file * elfrec,nfslog_LINK3args * args)10400Sstevel@tonic-gate nfslog_LINK3args_print(struct nfsl_log_file *elfrec, nfslog_LINK3args *args)
10410Sstevel@tonic-gate {
10420Sstevel@tonic-gate 	nfslog_fh3_print(elfrec, &args->file);
10430Sstevel@tonic-gate 	nfslog_diropargs3_print(elfrec, &args->link);
10440Sstevel@tonic-gate }
10450Sstevel@tonic-gate 
10460Sstevel@tonic-gate static void
nfslog_READDIRPLUS3args_print(struct nfsl_log_file * elfrec,nfslog_READDIRPLUS3args * args)10470Sstevel@tonic-gate nfslog_READDIRPLUS3args_print(struct nfsl_log_file *elfrec,
10480Sstevel@tonic-gate 	nfslog_READDIRPLUS3args *args)
10490Sstevel@tonic-gate {
10500Sstevel@tonic-gate 	nfslog_fh3_print(elfrec, &args->dir);
10510Sstevel@tonic-gate 	elfrec->bufoffset += sprintf(&elfrec->buf[elfrec->bufoffset], " 0x%x",
10520Sstevel@tonic-gate 		args->dircount);
10530Sstevel@tonic-gate 	elfrec->bufoffset += sprintf(&elfrec->buf[elfrec->bufoffset], " 0x%x",
10540Sstevel@tonic-gate 		args->maxcount);
10550Sstevel@tonic-gate }
10560Sstevel@tonic-gate 
10570Sstevel@tonic-gate static void
nfslog_COMMIT3args_print(struct nfsl_log_file * elfrec,nfslog_COMMIT3args * args)10580Sstevel@tonic-gate nfslog_COMMIT3args_print(struct nfsl_log_file *elfrec,
10590Sstevel@tonic-gate 	nfslog_COMMIT3args *args)
10600Sstevel@tonic-gate {
10610Sstevel@tonic-gate 	nfslog_fh3_print(elfrec, &args->file);
10620Sstevel@tonic-gate 	elfrec->bufoffset += sprintf(&elfrec->buf[elfrec->bufoffset], " 0x%llx",
10630Sstevel@tonic-gate 		args->offset);
10640Sstevel@tonic-gate 	elfrec->bufoffset += sprintf(&elfrec->buf[elfrec->bufoffset], " 0x%x",
10650Sstevel@tonic-gate 		args->count);
10660Sstevel@tonic-gate }
10670Sstevel@tonic-gate 
10680Sstevel@tonic-gate static void
nfslog_nfsstat3_print(struct nfsl_log_file * elfrec,enum nfsstat3 * res,bool_t print_status)10690Sstevel@tonic-gate nfslog_nfsstat3_print(struct nfsl_log_file *elfrec, enum nfsstat3 *res,
10700Sstevel@tonic-gate 	bool_t print_status)
10710Sstevel@tonic-gate {
10720Sstevel@tonic-gate 	if (print_status) {
10730Sstevel@tonic-gate 		char	*statp = nfslog_get_status((short)(*res));
10740Sstevel@tonic-gate 
10750Sstevel@tonic-gate 		if (statp != NULL)
10760Sstevel@tonic-gate 			elfrec->bufoffset +=
10770Sstevel@tonic-gate 				sprintf(&elfrec->buf[elfrec->bufoffset], " %s",
10780Sstevel@tonic-gate 					statp);
10790Sstevel@tonic-gate 		else
10800Sstevel@tonic-gate 			elfrec->bufoffset +=
10810Sstevel@tonic-gate 				sprintf(&elfrec->buf[elfrec->bufoffset], " %5d",
10820Sstevel@tonic-gate 					*res);
10830Sstevel@tonic-gate 	}
10840Sstevel@tonic-gate }
10850Sstevel@tonic-gate 
10860Sstevel@tonic-gate static void
nfslog_LOOKUP3res_print(struct nfsl_log_file * elfrec,nfslog_LOOKUP3res * res,bool_t print_status)10870Sstevel@tonic-gate nfslog_LOOKUP3res_print(struct nfsl_log_file *elfrec,
10880Sstevel@tonic-gate 	nfslog_LOOKUP3res *res, bool_t print_status)
10890Sstevel@tonic-gate {
10900Sstevel@tonic-gate 	if (print_status) {
10910Sstevel@tonic-gate 		nfslog_nfsstat3_print(elfrec, &res->status, print_status);
10920Sstevel@tonic-gate 	} else if (res->status == NFS3_OK) {
10930Sstevel@tonic-gate 		nfslog_fh3_print(elfrec, &res->nfslog_LOOKUP3res_u.object);
10940Sstevel@tonic-gate 	}
10950Sstevel@tonic-gate }
10960Sstevel@tonic-gate 
10970Sstevel@tonic-gate static void
nfslog_READLINK3res_print(struct nfsl_log_file * elfrec,nfslog_READLINK3res * res,bool_t print_status)10980Sstevel@tonic-gate nfslog_READLINK3res_print(struct nfsl_log_file *elfrec,
10990Sstevel@tonic-gate 	nfslog_READLINK3res *res, bool_t print_status)
11000Sstevel@tonic-gate {
11010Sstevel@tonic-gate 	if (print_status) {
11020Sstevel@tonic-gate 		nfslog_nfsstat3_print(elfrec, &res->status, print_status);
11030Sstevel@tonic-gate 	} else if (res->status == NFS3_OK) {
11040Sstevel@tonic-gate 		elfrec->bufoffset += sprintf(&elfrec->buf[elfrec->bufoffset],
11050Sstevel@tonic-gate 			" %s", res->nfslog_READLINK3res_u.data);
11060Sstevel@tonic-gate 	}
11070Sstevel@tonic-gate }
11080Sstevel@tonic-gate 
11090Sstevel@tonic-gate static void
nfslog_READ3res_print(struct nfsl_log_file * elfrec,nfslog_READ3res * res,bool_t print_status)11100Sstevel@tonic-gate nfslog_READ3res_print(struct nfsl_log_file *elfrec, nfslog_READ3res *res,
11110Sstevel@tonic-gate 	bool_t print_status)
11120Sstevel@tonic-gate {
11130Sstevel@tonic-gate 	if (print_status) {
11140Sstevel@tonic-gate 		nfslog_nfsstat3_print(elfrec, &res->status, print_status);
11150Sstevel@tonic-gate 	} else if (res->status == NFS3_OK) {
11160Sstevel@tonic-gate 		char	*elfbuf = elfrec->buf;
11170Sstevel@tonic-gate 		int	elfbufoffset = elfrec->bufoffset;
11180Sstevel@tonic-gate 
11190Sstevel@tonic-gate 		elfbufoffset += sprintf(&elfbuf[elfbufoffset], " 0x%llx",
11200Sstevel@tonic-gate 			res->nfslog_READ3res_u.ok.filesize);
11210Sstevel@tonic-gate 		elfbufoffset += sprintf(&elfbuf[elfbufoffset], " 0x%x",
11220Sstevel@tonic-gate 			res->nfslog_READ3res_u.ok.count);
11230Sstevel@tonic-gate 		elfbufoffset += sprintf(&elfbuf[elfbufoffset], " 0x%x",
11240Sstevel@tonic-gate 			res->nfslog_READ3res_u.ok.eof);
11250Sstevel@tonic-gate 		elfbufoffset += sprintf(&elfbuf[elfbufoffset], " 0x%x",
11260Sstevel@tonic-gate 			res->nfslog_READ3res_u.ok.size);
11270Sstevel@tonic-gate 		elfrec->bufoffset = elfbufoffset;
11280Sstevel@tonic-gate 	}
11290Sstevel@tonic-gate }
11300Sstevel@tonic-gate 
11310Sstevel@tonic-gate static void
nfslog_WRITE3res_print(struct nfsl_log_file * elfrec,nfslog_WRITE3res * res,bool_t print_status)11320Sstevel@tonic-gate nfslog_WRITE3res_print(struct nfsl_log_file *elfrec, nfslog_WRITE3res *res,
11330Sstevel@tonic-gate 	bool_t print_status)
11340Sstevel@tonic-gate {
11350Sstevel@tonic-gate 	if (print_status) {
11360Sstevel@tonic-gate 		nfslog_nfsstat3_print(elfrec, &res->status, print_status);
11370Sstevel@tonic-gate 	} else if (res->status == NFS3_OK) {
11380Sstevel@tonic-gate 		char	*elfbuf = elfrec->buf;
11390Sstevel@tonic-gate 		int	elfbufoffset = elfrec->bufoffset;
11400Sstevel@tonic-gate 
11410Sstevel@tonic-gate 		elfbufoffset += sprintf(&elfbuf[elfbufoffset], " 0x%llx",
11420Sstevel@tonic-gate 			res->nfslog_WRITE3res_u.ok.filesize);
11430Sstevel@tonic-gate 		elfbufoffset += sprintf(&elfbuf[elfbufoffset],
11440Sstevel@tonic-gate 			" 0x%x", res->nfslog_WRITE3res_u.ok.count);
11450Sstevel@tonic-gate 		elfbufoffset += sprintf(&elfrec->buf[elfbufoffset],
11460Sstevel@tonic-gate 			" 0x%x", res->nfslog_WRITE3res_u.ok.committed);
11470Sstevel@tonic-gate 		elfrec->bufoffset = elfbufoffset;
11480Sstevel@tonic-gate 	}
11490Sstevel@tonic-gate }
11500Sstevel@tonic-gate 
11510Sstevel@tonic-gate static void
nfslog_CREATE3res_print(struct nfsl_log_file * elfrec,nfslog_CREATE3res * res,bool_t print_status)11520Sstevel@tonic-gate nfslog_CREATE3res_print(struct nfsl_log_file *elfrec, nfslog_CREATE3res *res,
11530Sstevel@tonic-gate 	bool_t print_status)
11540Sstevel@tonic-gate {
11550Sstevel@tonic-gate 	if (print_status) {
11560Sstevel@tonic-gate 		nfslog_nfsstat3_print(elfrec, &res->status, print_status);
11570Sstevel@tonic-gate 	} else if (res->status == NFS3_OK) {
11580Sstevel@tonic-gate 		if (res->nfslog_CREATE3res_u.ok.obj.handle_follows) {
11590Sstevel@tonic-gate 			nfslog_fh3_print(elfrec,
11600Sstevel@tonic-gate 				&res->nfslog_CREATE3res_u.ok.obj.handle);
11610Sstevel@tonic-gate 		}
11620Sstevel@tonic-gate 	}
11630Sstevel@tonic-gate }
11640Sstevel@tonic-gate 
11650Sstevel@tonic-gate static void
nfslog_MKDIR3res_print(struct nfsl_log_file * elfrec,nfslog_MKDIR3res * res,bool_t print_status)11660Sstevel@tonic-gate nfslog_MKDIR3res_print(struct nfsl_log_file *elfrec, nfslog_MKDIR3res *res,
11670Sstevel@tonic-gate 	bool_t print_status)
11680Sstevel@tonic-gate {
11690Sstevel@tonic-gate 	if (print_status) {
11700Sstevel@tonic-gate 		nfslog_nfsstat3_print(elfrec, &res->status, print_status);
11710Sstevel@tonic-gate 	} else if (res->status == NFS3_OK) {
11720Sstevel@tonic-gate 		if (res->nfslog_MKDIR3res_u.obj.handle_follows) {
11730Sstevel@tonic-gate 			nfslog_fh3_print(elfrec,
11740Sstevel@tonic-gate 				&res->nfslog_MKDIR3res_u.obj.handle);
11750Sstevel@tonic-gate 		}
11760Sstevel@tonic-gate 	}
11770Sstevel@tonic-gate }
11780Sstevel@tonic-gate 
11790Sstevel@tonic-gate static void
nfslog_SYMLINK3res_print(struct nfsl_log_file * elfrec,nfslog_SYMLINK3res * res,bool_t print_status)11800Sstevel@tonic-gate nfslog_SYMLINK3res_print(struct nfsl_log_file *elfrec, nfslog_SYMLINK3res *res,
11810Sstevel@tonic-gate 	bool_t print_status)
11820Sstevel@tonic-gate {
11830Sstevel@tonic-gate 	if (print_status) {
11840Sstevel@tonic-gate 		nfslog_nfsstat3_print(elfrec, &res->status, print_status);
11850Sstevel@tonic-gate 	} else if (res->status == NFS3_OK) {
11860Sstevel@tonic-gate 		if (res->nfslog_SYMLINK3res_u.obj.handle_follows) {
11870Sstevel@tonic-gate 			nfslog_fh3_print(elfrec,
11880Sstevel@tonic-gate 				&res->nfslog_SYMLINK3res_u.obj.handle);
11890Sstevel@tonic-gate 		}
11900Sstevel@tonic-gate 	}
11910Sstevel@tonic-gate }
11920Sstevel@tonic-gate 
11930Sstevel@tonic-gate static void
nfslog_MKNOD3res_print(struct nfsl_log_file * elfrec,nfslog_MKNOD3res * res,bool_t print_status)11940Sstevel@tonic-gate nfslog_MKNOD3res_print(struct nfsl_log_file *elfrec, nfslog_MKNOD3res *res,
11950Sstevel@tonic-gate 	bool_t print_status)
11960Sstevel@tonic-gate {
11970Sstevel@tonic-gate 	if (print_status) {
11980Sstevel@tonic-gate 		nfslog_nfsstat3_print(elfrec, &res->status, print_status);
11990Sstevel@tonic-gate 	} else if (res->status == NFS3_OK) {
12000Sstevel@tonic-gate 		if (res->nfslog_MKNOD3res_u.obj.handle_follows) {
12010Sstevel@tonic-gate 			nfslog_fh3_print(elfrec,
12020Sstevel@tonic-gate 				&res->nfslog_MKNOD3res_u.obj.handle);
12030Sstevel@tonic-gate 		}
12040Sstevel@tonic-gate 	}
12050Sstevel@tonic-gate }
12060Sstevel@tonic-gate 
12070Sstevel@tonic-gate static void
nfslog_READDIRPLUS3res_print(struct nfsl_log_file * elfrec,nfslog_READDIRPLUS3res * res,bool_t print_status)12080Sstevel@tonic-gate nfslog_READDIRPLUS3res_print(struct nfsl_log_file *elfrec,
12090Sstevel@tonic-gate 	nfslog_READDIRPLUS3res *res, bool_t print_status)
12100Sstevel@tonic-gate {
12110Sstevel@tonic-gate 	if (print_status) {
12120Sstevel@tonic-gate 		nfslog_nfsstat3_print(elfrec, &res->status, print_status);
12130Sstevel@tonic-gate 	}
12140Sstevel@tonic-gate }
12150Sstevel@tonic-gate 
12160Sstevel@tonic-gate /*
12170Sstevel@tonic-gate  * **** End of table functions for logging specific procs ****
12180Sstevel@tonic-gate  *
12190Sstevel@tonic-gate  * Hereafter are the general logging management and dispatcher.
12200Sstevel@tonic-gate  */
12210Sstevel@tonic-gate 
12220Sstevel@tonic-gate 
12230Sstevel@tonic-gate /*
12240Sstevel@tonic-gate  * nfsl_ipaddr_print - extracts sender ip address from transport struct
12250Sstevel@tonic-gate  * and prints it in legible form.
12260Sstevel@tonic-gate  */
12270Sstevel@tonic-gate static void
nfsl_ipaddr_print(struct nfsl_log_file * elfrec,struct netbuf * ptr)12280Sstevel@tonic-gate nfsl_ipaddr_print(struct nfsl_log_file *elfrec, struct netbuf *ptr)
12290Sstevel@tonic-gate {
12300Sstevel@tonic-gate 	struct hostent	*hp;
12310Sstevel@tonic-gate 	extern char	*inet_ntop();
12320Sstevel@tonic-gate 	int		size, sin_family, error;
12330Sstevel@tonic-gate 	char		*elfbuf = elfrec->buf;
12340Sstevel@tonic-gate 	char		*addrp;
12350Sstevel@tonic-gate 	int		elfbufoffset = elfrec->bufoffset;
12360Sstevel@tonic-gate 
12370Sstevel@tonic-gate 	if (ptr->len == 0) {
12380Sstevel@tonic-gate 		elfbufoffset += sprintf(&elfbuf[elfbufoffset], " %s",
12390Sstevel@tonic-gate 			empty_name);
12400Sstevel@tonic-gate 		elfbufoffset += sprintf(&elfbuf[elfbufoffset], " %s",
12410Sstevel@tonic-gate 			empty_name);
12420Sstevel@tonic-gate 		elfrec->bufoffset = elfbufoffset;
12430Sstevel@tonic-gate 		return;
12440Sstevel@tonic-gate 	}
12450Sstevel@tonic-gate 	elfbufoffset += sprintf(&elfbuf[elfbufoffset], " ");
12460Sstevel@tonic-gate 	/* LINTED */
12470Sstevel@tonic-gate 	sin_family = ((struct sockaddr_in *)ptr->buf)->sin_family;
12480Sstevel@tonic-gate 	switch (sin_family) {
12490Sstevel@tonic-gate 	case (AF_INET):
12500Sstevel@tonic-gate 		/* LINTED */
12510Sstevel@tonic-gate 		addrp = (char *)&((struct sockaddr_in *)ptr->buf)->sin_addr;
12520Sstevel@tonic-gate 		size = sizeof (struct in_addr);
12530Sstevel@tonic-gate 		break;
12540Sstevel@tonic-gate 	case (AF_INET6):
12550Sstevel@tonic-gate 		/* LINTED */
12560Sstevel@tonic-gate 		addrp = (char *)&((struct sockaddr_in6 *)ptr->buf)->sin6_addr;
12570Sstevel@tonic-gate 		size = sizeof (struct in6_addr);
12580Sstevel@tonic-gate 		break;
12590Sstevel@tonic-gate 	default:
12600Sstevel@tonic-gate 		/* unknown protocol: print address in hex form */
12610Sstevel@tonic-gate 		for (size = ptr->len, addrp = ptr->buf; size > 0; size--) {
12620Sstevel@tonic-gate 			elfbufoffset += sprintf(&elfbuf[elfbufoffset], "%02x",
12630Sstevel@tonic-gate 				*addrp);
12640Sstevel@tonic-gate 		}
12650Sstevel@tonic-gate 		elfbufoffset += sprintf(&elfbuf[elfbufoffset], " %s",
12660Sstevel@tonic-gate 			empty_name);
12670Sstevel@tonic-gate 		elfrec->bufoffset = elfbufoffset;
12680Sstevel@tonic-gate 		return;
12690Sstevel@tonic-gate 	}
12700Sstevel@tonic-gate 	if (inet_ntop(sin_family, addrp, &elfbuf[elfbufoffset],
12710Sstevel@tonic-gate 		(size_t)(DFLT_BUFFERSIZE + DFLT_OVFSIZE - elfbufoffset))
12720Sstevel@tonic-gate 		    == NULL) {
12730Sstevel@tonic-gate 		/* Not enough space to print - should never happen */
12740Sstevel@tonic-gate 		elfbuf[elfrec->bufoffset] = '\0';	/* just in case */
12750Sstevel@tonic-gate 		return;
12760Sstevel@tonic-gate 	}
12770Sstevel@tonic-gate 	/* inet_ntop copied address into elfbuf, so update offset */
12780Sstevel@tonic-gate 	elfbufoffset += strlen(&elfbuf[elfbufoffset]);
12790Sstevel@tonic-gate 	/* get host name and log it as well */
12800Sstevel@tonic-gate 	hp = getipnodebyaddr(addrp, size, sin_family, &error);
12810Sstevel@tonic-gate 	if (hp != NULL) {
12820Sstevel@tonic-gate 		elfbufoffset += sprintf(&elfbuf[elfbufoffset], " \"%s\"",
12830Sstevel@tonic-gate 			hp->h_name);
12840Sstevel@tonic-gate 	} else {
12850Sstevel@tonic-gate 		elfbufoffset += sprintf(&elfbuf[elfbufoffset], " %s",
12860Sstevel@tonic-gate 			empty_name);
12870Sstevel@tonic-gate 	}
12880Sstevel@tonic-gate 	elfrec->bufoffset = elfbufoffset;
12890Sstevel@tonic-gate }
12900Sstevel@tonic-gate 
12910Sstevel@tonic-gate static void
nfsl_elf_record_header_print(struct nfsl_log_file * elfrec,nfslog_record_header * lhp,char * principal_name,char * tag,struct nfsl_proc_disp * disp,char * progname)12920Sstevel@tonic-gate nfsl_elf_record_header_print(struct nfsl_log_file *elfrec,
12930Sstevel@tonic-gate 	nfslog_record_header *lhp, char *principal_name, char *tag,
12940Sstevel@tonic-gate 	struct nfsl_proc_disp *disp, char *progname)
12950Sstevel@tonic-gate {
12960Sstevel@tonic-gate 	struct passwd	*pwp = NULL;
12970Sstevel@tonic-gate 	char	*elfbuf = elfrec->buf;
12980Sstevel@tonic-gate 	int	elfbufoffset = elfrec->bufoffset;
12990Sstevel@tonic-gate 
13000Sstevel@tonic-gate 	/*
13010Sstevel@tonic-gate 	 * Fields: time bytes tag rpc-program rpc-version rpc-procedure
13020Sstevel@tonic-gate 	 *	   auth-flavor s-user-name s-uid uid u-name gid net-id
13030Sstevel@tonic-gate 	 *   c-ip c-dns s-dns status rpcarg-path <arguments> <response>
13040Sstevel@tonic-gate 	 */
13050Sstevel@tonic-gate 	elfbufoffset += sprintf(&elfbuf[elfbufoffset], "%s",
13060Sstevel@tonic-gate 		nfsl_get_time((time_t)lhp->rh_timestamp.tv_sec));
13070Sstevel@tonic-gate 	elfbufoffset += sprintf(&elfbuf[elfbufoffset], " 0x%x",
13080Sstevel@tonic-gate 		lhp->rh_reclen);
13090Sstevel@tonic-gate 	if ((tag != NULL) && (tag[0] != '\0')) {
13100Sstevel@tonic-gate 		elfbufoffset += sprintf(&elfbuf[elfbufoffset], " \"%s\"", tag);
13110Sstevel@tonic-gate 	} else {
13120Sstevel@tonic-gate 		elfbufoffset += sprintf(&elfbuf[elfbufoffset], " %s",
13130Sstevel@tonic-gate 					empty_name);
13140Sstevel@tonic-gate 	}
13150Sstevel@tonic-gate 	elfbufoffset += sprintf(&elfbuf[elfbufoffset], " %s 0x%x %s",
13160Sstevel@tonic-gate 				progname, lhp->rh_version, disp->procname);
13170Sstevel@tonic-gate 	elfbufoffset += sprintf(&elfbuf[elfbufoffset], " %s",
13180Sstevel@tonic-gate 		NFSL_AUTH_FLAVOR_PRINT(lhp->rh_auth_flavor));
13190Sstevel@tonic-gate 	if ((principal_name != NULL) && (principal_name[0] != '\0')) {
13200Sstevel@tonic-gate 		elfbufoffset += sprintf(&elfbuf[elfbufoffset], " \"%s\"",
13210Sstevel@tonic-gate 			principal_name);
13220Sstevel@tonic-gate 		if ((pwp = getpwnam(principal_name)) != NULL) {
13230Sstevel@tonic-gate 			elfbufoffset += sprintf(&elfbuf[elfbufoffset],
13240Sstevel@tonic-gate 				" 0x%lx", pwp->pw_uid);
13250Sstevel@tonic-gate 		} else {
13260Sstevel@tonic-gate 			elfbufoffset += sprintf(&elfbuf[elfbufoffset],
13270Sstevel@tonic-gate 				" %s", empty_name);
13280Sstevel@tonic-gate 		}
13290Sstevel@tonic-gate 	} else {
13300Sstevel@tonic-gate 		elfbufoffset += sprintf(&elfbuf[elfbufoffset], " %s",
13310Sstevel@tonic-gate 			empty_name);
13320Sstevel@tonic-gate 		elfbufoffset += sprintf(&elfbuf[elfbufoffset], " %s",
13330Sstevel@tonic-gate 			empty_name);
13340Sstevel@tonic-gate 	}
13350Sstevel@tonic-gate 	elfbufoffset += sprintf(&elfbuf[elfbufoffset], " 0x%lx", lhp->rh_uid);
13360Sstevel@tonic-gate 	if (((pwp = getpwuid(lhp->rh_uid)) != NULL) && (pwp->pw_name != NULL)) {
13370Sstevel@tonic-gate 		elfbufoffset += sprintf(&elfbuf[elfbufoffset], " \"%s\"",
13380Sstevel@tonic-gate 			pwp->pw_name);
13390Sstevel@tonic-gate 	} else {
13400Sstevel@tonic-gate 		elfbufoffset += sprintf(&elfbuf[elfbufoffset], " %s",
13410Sstevel@tonic-gate 			empty_name);
13420Sstevel@tonic-gate 	}
13430Sstevel@tonic-gate 	elfbufoffset += sprintf(&elfbuf[elfbufoffset], " 0x%lx", lhp->rh_gid);
13440Sstevel@tonic-gate 	elfrec->bufoffset = elfbufoffset;
13450Sstevel@tonic-gate }
13460Sstevel@tonic-gate 
13470Sstevel@tonic-gate static void
nfsl_elf_buffer_header_print(struct nfsl_log_file * elfrec,nfslog_buffer_header * bufhdr)13480Sstevel@tonic-gate nfsl_elf_buffer_header_print(struct nfsl_log_file *elfrec,
13490Sstevel@tonic-gate 	nfslog_buffer_header *bufhdr)
13500Sstevel@tonic-gate {
13510Sstevel@tonic-gate 	int	rc;
13520Sstevel@tonic-gate 	struct utsname	name;
13530Sstevel@tonic-gate 	char	*elfbuf = elfrec->buf;
13540Sstevel@tonic-gate 	int	elfbufoffset = elfrec->bufoffset;
13550Sstevel@tonic-gate 
13560Sstevel@tonic-gate 	rc = uname(&name);
13570Sstevel@tonic-gate 	elfbufoffset += sprintf(&elfbuf[elfbufoffset],
13580Sstevel@tonic-gate 		"#Version %d.0\n#Software \"%s\"\n",
13590Sstevel@tonic-gate 		bufhdr->bh_version, ((rc >= 0) ? name.sysname : empty_name));
13600Sstevel@tonic-gate 	elfbufoffset += sprintf(&elfbuf[elfbufoffset], "#Date %s\n",
13610Sstevel@tonic-gate 		nfsl_get_date((time_t)bufhdr->bh_timestamp.tv_sec));
13620Sstevel@tonic-gate 	elfbufoffset += sprintf(&elfbuf[elfbufoffset], "#Remark %s\n",
13630Sstevel@tonic-gate 		empty_name);
13640Sstevel@tonic-gate 	elfbufoffset += sprintf(&elfbuf[elfbufoffset],
13650Sstevel@tonic-gate 		"#Fields: time bytes tag");
13660Sstevel@tonic-gate 	elfbufoffset += sprintf(&elfbuf[elfbufoffset],
13670Sstevel@tonic-gate 		" rpc-program rpc-version rpc-procedure");
13680Sstevel@tonic-gate 	elfbufoffset += sprintf(&elfbuf[elfbufoffset],
13690Sstevel@tonic-gate 		" auth-flavor s-user-name s-uid uid u-name gid net-id c-ip");
13700Sstevel@tonic-gate 	elfbufoffset += sprintf(&elfbuf[elfbufoffset],
13710Sstevel@tonic-gate 		" c-dns s-dns status rpcarg-path");
13720Sstevel@tonic-gate 	elfbufoffset += sprintf(&elfbuf[elfbufoffset],
13730Sstevel@tonic-gate 		" rpc-arguments... rpc-response...\n");
13740Sstevel@tonic-gate 	elfrec->bufoffset = elfbufoffset;
13750Sstevel@tonic-gate }
13760Sstevel@tonic-gate 
13770Sstevel@tonic-gate /*
13780Sstevel@tonic-gate  * nfsl_find_elf_dispatch - get the dispatch struct for this request
13790Sstevel@tonic-gate  */
13800Sstevel@tonic-gate static struct nfsl_proc_disp *
nfsl_find_elf_dispatch(nfslog_request_record * logrec,char ** prognamep)13810Sstevel@tonic-gate nfsl_find_elf_dispatch(nfslog_request_record *logrec, char **prognamep)
13820Sstevel@tonic-gate {
13830Sstevel@tonic-gate 	nfslog_record_header	*logrechdr = &logrec->re_header;
13840Sstevel@tonic-gate 	struct nfsl_prog_disp	*progtable;	/* prog struct */
13850Sstevel@tonic-gate 	struct nfsl_vers_disp	*verstable;	/* version struct */
13860Sstevel@tonic-gate 	int			i, vers;
13870Sstevel@tonic-gate 
13880Sstevel@tonic-gate 	/* Find prog element - search because can't use prog as array index */
13890Sstevel@tonic-gate 	for (i = 0; (i < nfsl_elf_dispatch_table_arglen) &&
13900Sstevel@tonic-gate 	    (logrechdr->rh_prognum != nfsl_elf_dispatch_table[i].nfsl_dis_prog);
13910Sstevel@tonic-gate 		i++);
13920Sstevel@tonic-gate 	if (i >= nfsl_elf_dispatch_table_arglen) {	/* program not logged */
13930Sstevel@tonic-gate 		/* not an error */
13940Sstevel@tonic-gate 		return (NULL);
13950Sstevel@tonic-gate 	}
13960Sstevel@tonic-gate 	progtable = &nfsl_elf_dispatch_table[i];
13970Sstevel@tonic-gate 	/* Find vers element - no validity check - if here it's valid vers */
13980Sstevel@tonic-gate 	vers = logrechdr->rh_version - progtable->nfsl_dis_versmin;
13990Sstevel@tonic-gate 	verstable = &progtable->nfsl_dis_vers_table[vers];
14000Sstevel@tonic-gate 	/* Find proc element - no validity check - if here it's valid proc */
14010Sstevel@tonic-gate 	*prognamep = progtable->progname;
14020Sstevel@tonic-gate 	return (&verstable->nfsl_dis_proc_table[logrechdr->rh_procnum]);
14030Sstevel@tonic-gate }
14040Sstevel@tonic-gate 
14050Sstevel@tonic-gate /*
14060Sstevel@tonic-gate  * nfsl_elf_rpc_print - Print the record buffer.
14070Sstevel@tonic-gate  */
14080Sstevel@tonic-gate static void
nfsl_elf_rpc_print(struct nfsl_log_file * elfrec,nfslog_request_record * logrec,struct nfsl_proc_disp * disp,char * progname,char * path1,char * path2)14090Sstevel@tonic-gate nfsl_elf_rpc_print(struct nfsl_log_file *elfrec,
14100Sstevel@tonic-gate 	nfslog_request_record *logrec, struct nfsl_proc_disp *disp,
14110Sstevel@tonic-gate 	char *progname, char *path1, char *path2)
14120Sstevel@tonic-gate {
14130Sstevel@tonic-gate 	if (debug > 1) {
14140Sstevel@tonic-gate 		(void) printf("%s %d %s", progname,
14150Sstevel@tonic-gate 			logrec->re_header.rh_version, disp->procname);
14160Sstevel@tonic-gate 		(void) printf(": '%s', '%s'\n",
14170Sstevel@tonic-gate 			((path1 != NULL) ? path1 : empty_name),
14180Sstevel@tonic-gate 			((path2 != NULL) ? path2 : empty_name));
14190Sstevel@tonic-gate 	}
14200Sstevel@tonic-gate 	/*
14210Sstevel@tonic-gate 	 * XXXX programs using this file to get a usable record should
14220Sstevel@tonic-gate 	 * take "record" struct.
14230Sstevel@tonic-gate 	 */
14240Sstevel@tonic-gate 	/*
14250Sstevel@tonic-gate 	 * Print the variable fields:
14260Sstevel@tonic-gate 	 *	principal name
14270Sstevel@tonic-gate 	 *	netid
14280Sstevel@tonic-gate 	 *	ip address
14290Sstevel@tonic-gate 	 *	rpc args
14300Sstevel@tonic-gate 	 *	rpc res
14310Sstevel@tonic-gate 	 * Use the displacements calculated earlier...
14320Sstevel@tonic-gate 	 */
14330Sstevel@tonic-gate 
14340Sstevel@tonic-gate 	/*
14350Sstevel@tonic-gate 	 * Fields: time bytes tag rpc-program rpc-version rpc-procedure
14360Sstevel@tonic-gate 	 *	   auth-flavor s-user-name s-uid uid u-name gid net-id c-ip
14370Sstevel@tonic-gate 	 *	 c-dns s-dns status rpcarg-path <arguments> <response>
14380Sstevel@tonic-gate 	 */
14390Sstevel@tonic-gate 	nfsl_elf_record_header_print(elfrec, &logrec->re_header,
14400Sstevel@tonic-gate 			logrec->re_principal_name, logrec->re_tag,
14410Sstevel@tonic-gate 			disp, progname);
14420Sstevel@tonic-gate 	if ((logrec->re_netid != NULL) && (logrec->re_netid[0] != '\0')) {
14430Sstevel@tonic-gate 		elfrec->bufoffset += sprintf(&elfrec->buf[elfrec->bufoffset],
14440Sstevel@tonic-gate 			" \"%s\"", logrec->re_netid);
14450Sstevel@tonic-gate 	} else {
14460Sstevel@tonic-gate 		elfrec->bufoffset += sprintf(&elfrec->buf[elfrec->bufoffset],
14470Sstevel@tonic-gate 			" %s", empty_name);
14480Sstevel@tonic-gate 	}
14490Sstevel@tonic-gate 	nfsl_ipaddr_print(elfrec, &logrec->re_ipaddr);
14500Sstevel@tonic-gate 	elfrec->bufoffset += sprintf(&elfrec->buf[elfrec->bufoffset],
14510Sstevel@tonic-gate 		" \"%s\"", hostname);
14520Sstevel@tonic-gate 	/* Next is return status */
14530Sstevel@tonic-gate 	(*disp->nfsl_dis_res)(elfrec, logrec->re_rpc_res, TRUE);
14540Sstevel@tonic-gate 	/* Next is argpath */
14550Sstevel@tonic-gate 	if (path1 != NULL) {
14560Sstevel@tonic-gate 		elfrec->bufoffset += sprintf(&elfrec->buf[elfrec->bufoffset],
14570Sstevel@tonic-gate 			" \"%s\"", path1);
14580Sstevel@tonic-gate 	} else {
14590Sstevel@tonic-gate 		elfrec->bufoffset += sprintf(&elfrec->buf[elfrec->bufoffset],
14600Sstevel@tonic-gate 			" %s", empty_name);
14610Sstevel@tonic-gate 	}
14620Sstevel@tonic-gate 	/*
14630Sstevel@tonic-gate 	 * path2 is non-empty for rename/link type operations. If it is non-
14640Sstevel@tonic-gate 	 * empty print it here as it's a part of the args
14650Sstevel@tonic-gate 	 */
14660Sstevel@tonic-gate 	if (path2 != NULL) {
14670Sstevel@tonic-gate 		elfrec->bufoffset += sprintf(&elfrec->buf[elfrec->bufoffset],
14680Sstevel@tonic-gate 			" \"%s\"", path2);
14690Sstevel@tonic-gate 	}
14700Sstevel@tonic-gate 	/* Next print formatted rpc args */
14710Sstevel@tonic-gate 	(*disp->nfsl_dis_args)(elfrec, logrec->re_rpc_arg);
14720Sstevel@tonic-gate 	/* Next print formatted rpc res (minus status) */
14730Sstevel@tonic-gate 	(*disp->nfsl_dis_res)(elfrec, logrec->re_rpc_res, FALSE);
14740Sstevel@tonic-gate 	elfrec->bufoffset += sprintf(&elfrec->buf[elfrec->bufoffset], "\n");
14750Sstevel@tonic-gate }
14760Sstevel@tonic-gate 
14770Sstevel@tonic-gate /*
14780Sstevel@tonic-gate  * nfsl_log_file_add - add a new record to the list
14790Sstevel@tonic-gate  */
14800Sstevel@tonic-gate static void
nfsl_log_file_add(struct nfsl_log_file * elfrec,struct nfsl_log_file ** elf_listp)14810Sstevel@tonic-gate nfsl_log_file_add(struct nfsl_log_file *elfrec,
14820Sstevel@tonic-gate 	struct nfsl_log_file **elf_listp)
14830Sstevel@tonic-gate {
14840Sstevel@tonic-gate 	elfrec->next = *elf_listp;
14850Sstevel@tonic-gate 	elfrec->prev = NULL;
14860Sstevel@tonic-gate 	if (*elf_listp != NULL) {
14870Sstevel@tonic-gate 		(*elf_listp)->prev = elfrec;
14880Sstevel@tonic-gate 	}
14890Sstevel@tonic-gate 	*elf_listp = elfrec;
14900Sstevel@tonic-gate }
14910Sstevel@tonic-gate 
14920Sstevel@tonic-gate /*
14930Sstevel@tonic-gate  * nfsl_log_file_find - finds a record in the list, given a cookie (== elfrec)
14940Sstevel@tonic-gate  * Returns the record.
14950Sstevel@tonic-gate  */
14960Sstevel@tonic-gate static struct nfsl_log_file *
nfsl_log_file_find(struct nfsl_log_file * elfrec,struct nfsl_log_file * elf_list)14970Sstevel@tonic-gate nfsl_log_file_find(struct nfsl_log_file *elfrec,
14980Sstevel@tonic-gate 	struct nfsl_log_file *elf_list)
14990Sstevel@tonic-gate {
15000Sstevel@tonic-gate 	struct nfsl_log_file	*rec;
15010Sstevel@tonic-gate 
15020Sstevel@tonic-gate 	for (rec = elf_list; (rec != NULL) && (rec != elfrec);
15030Sstevel@tonic-gate 		rec = rec->next);
15040Sstevel@tonic-gate 	return (rec);
15050Sstevel@tonic-gate }
15060Sstevel@tonic-gate 
15070Sstevel@tonic-gate /*
15080Sstevel@tonic-gate  * nfsl_log_file_del - delete a record from the list, does not free rec.
15090Sstevel@tonic-gate  * Returns the deleted record.
15100Sstevel@tonic-gate  */
15110Sstevel@tonic-gate static struct nfsl_log_file *
nfsl_log_file_del(struct nfsl_log_file * elfrec,struct nfsl_log_file ** elf_listp)15120Sstevel@tonic-gate nfsl_log_file_del(struct nfsl_log_file *elfrec,
15130Sstevel@tonic-gate 	struct nfsl_log_file **elf_listp)
15140Sstevel@tonic-gate {
15150Sstevel@tonic-gate 	struct nfsl_log_file	*rec;
15160Sstevel@tonic-gate 
15170Sstevel@tonic-gate 	if ((rec = nfsl_log_file_find(elfrec, *elf_listp)) == NULL) {
15180Sstevel@tonic-gate 		return (NULL);
15190Sstevel@tonic-gate 	}
15200Sstevel@tonic-gate 	if (rec->prev != NULL) {
15210Sstevel@tonic-gate 		rec->prev->next = rec->next;
15220Sstevel@tonic-gate 	} else {
15230Sstevel@tonic-gate 		*elf_listp = rec->next;
15240Sstevel@tonic-gate 	}
15250Sstevel@tonic-gate 	if (rec->next != NULL) {
15260Sstevel@tonic-gate 		rec->next->prev = rec->prev;
15270Sstevel@tonic-gate 	}
15280Sstevel@tonic-gate 	return (rec);
15290Sstevel@tonic-gate }
15300Sstevel@tonic-gate 
15310Sstevel@tonic-gate /*
15320Sstevel@tonic-gate  * nfsl_log_file_free - frees a record
15330Sstevel@tonic-gate  */
15340Sstevel@tonic-gate static void
nfsl_log_file_free(struct nfsl_log_file * elfrec)15350Sstevel@tonic-gate nfsl_log_file_free(struct nfsl_log_file *elfrec)
15360Sstevel@tonic-gate {
15370Sstevel@tonic-gate 	if (elfrec == NULL)
15380Sstevel@tonic-gate 		return;
15390Sstevel@tonic-gate 	if (elfrec->path != NULL)
15400Sstevel@tonic-gate 		free(elfrec->path);
15410Sstevel@tonic-gate 	if (elfrec->buf != NULL)
15420Sstevel@tonic-gate 		free(elfrec->buf);
15430Sstevel@tonic-gate 	free(elfrec);
15440Sstevel@tonic-gate }
15450Sstevel@tonic-gate 
15460Sstevel@tonic-gate /*
15470Sstevel@tonic-gate  * Exported Functions
15480Sstevel@tonic-gate  */
15490Sstevel@tonic-gate 
15500Sstevel@tonic-gate /*
15510Sstevel@tonic-gate  * nfslog_open_elf_file - open the output elf file and mallocs needed buffers
15520Sstevel@tonic-gate  * Returns a pointer to the nfsl_log_file on success, NULL on error.
15530Sstevel@tonic-gate  *
15540Sstevel@tonic-gate  * *error contains the last error encountered on this object, It can
15550Sstevel@tonic-gate  * be used to avoid reporting the same error endlessly, by comparing
15560Sstevel@tonic-gate  * the current error to the last error. It is reset to the current error
15570Sstevel@tonic-gate  * code on return.
15580Sstevel@tonic-gate  */
15590Sstevel@tonic-gate void *
nfslog_open_elf_file(char * elfpath,nfslog_buffer_header * bufhdr,int * error)15600Sstevel@tonic-gate nfslog_open_elf_file(char *elfpath, nfslog_buffer_header *bufhdr, int *error)
15610Sstevel@tonic-gate {
15620Sstevel@tonic-gate 	struct nfsl_log_file *elfrec;
15630Sstevel@tonic-gate 	struct stat stat_buf;
15640Sstevel@tonic-gate 	int preverror = *error;
15650Sstevel@tonic-gate 
15660Sstevel@tonic-gate 	if ((elfrec = malloc(sizeof (*elfrec))) == NULL) {
15670Sstevel@tonic-gate 		*error = errno;
15680Sstevel@tonic-gate 		if (*error != preverror) {
15690Sstevel@tonic-gate 			syslog(LOG_ERR, gettext("nfslog_open_elf_file: %s"),
15700Sstevel@tonic-gate 				strerror(*error));
15710Sstevel@tonic-gate 		}
15720Sstevel@tonic-gate 		return (NULL);
15730Sstevel@tonic-gate 	}
15740Sstevel@tonic-gate 	bzero(elfrec, sizeof (*elfrec));
15750Sstevel@tonic-gate 
15760Sstevel@tonic-gate 	elfrec->buf = (char *)malloc(DFLT_BUFFERSIZE + DFLT_OVFSIZE);
15770Sstevel@tonic-gate 	if (elfrec->buf == NULL) {
15780Sstevel@tonic-gate 		*error = errno;
15790Sstevel@tonic-gate 		if (*error != preverror) {
15800Sstevel@tonic-gate 			syslog(LOG_ERR, gettext("nfslog_open_elf_file: %s"),
15810Sstevel@tonic-gate 				strerror(*error));
15820Sstevel@tonic-gate 		}
15830Sstevel@tonic-gate 		nfsl_log_file_free(elfrec);
15840Sstevel@tonic-gate 		return (NULL);
15850Sstevel@tonic-gate 	}
15860Sstevel@tonic-gate 
15870Sstevel@tonic-gate 	if ((elfrec->path = strdup(elfpath)) == NULL) {
15880Sstevel@tonic-gate 		*error = errno;
15890Sstevel@tonic-gate 		if (*error != preverror) {
15900Sstevel@tonic-gate 			syslog(LOG_ERR, gettext("nfslog_open_elf_file: %s"),
15910Sstevel@tonic-gate 				strerror(*error));
15920Sstevel@tonic-gate 		}
15930Sstevel@tonic-gate 		nfsl_log_file_free(elfrec);
15940Sstevel@tonic-gate 		return (NULL);
15950Sstevel@tonic-gate 	}
15960Sstevel@tonic-gate 
15970Sstevel@tonic-gate 	if ((elfrec->fp = fopen(elfpath, "a")) == NULL) {
15980Sstevel@tonic-gate 		*error = errno;
15990Sstevel@tonic-gate 		if (*error != preverror) {
16000Sstevel@tonic-gate 			syslog(LOG_ERR, gettext("Cannot open '%s': %s"),
16010Sstevel@tonic-gate 				elfpath, strerror(*error));
16020Sstevel@tonic-gate 		}
16030Sstevel@tonic-gate 		nfsl_log_file_free(elfrec);
16040Sstevel@tonic-gate 		return (NULL);
16050Sstevel@tonic-gate 	}
16060Sstevel@tonic-gate 
16070Sstevel@tonic-gate 	if (stat(elfpath, &stat_buf) == -1) {
16080Sstevel@tonic-gate 		*error = errno;
16090Sstevel@tonic-gate 		if (*error != preverror) {
16100Sstevel@tonic-gate 			syslog(LOG_ERR, gettext("Cannot stat '%s': %s"),
16110Sstevel@tonic-gate 				elfpath, strerror(*error));
16120Sstevel@tonic-gate 		}
16130Sstevel@tonic-gate 		(void) fclose(elfrec->fp);
16140Sstevel@tonic-gate 		nfsl_log_file_free(elfrec);
16150Sstevel@tonic-gate 		return (NULL);
16160Sstevel@tonic-gate 	}
16170Sstevel@tonic-gate 
16180Sstevel@tonic-gate 	nfsl_log_file_add(elfrec, &elf_file_list);
16190Sstevel@tonic-gate 
16200Sstevel@tonic-gate 	if (stat_buf.st_size == 0) {
16210Sstevel@tonic-gate 		/*
16220Sstevel@tonic-gate 		 * Print header unto logfile
16230Sstevel@tonic-gate 		 */
16240Sstevel@tonic-gate 		nfsl_elf_buffer_header_print(elfrec, bufhdr);
16250Sstevel@tonic-gate 	}
16260Sstevel@tonic-gate 
16270Sstevel@tonic-gate 	if (hostname[0] == '\0') {
16280Sstevel@tonic-gate 		(void) gethostname(hostname, MAXHOSTNAMELEN);
16290Sstevel@tonic-gate 	}
16300Sstevel@tonic-gate 
16310Sstevel@tonic-gate 	return (elfrec);
16320Sstevel@tonic-gate }
16330Sstevel@tonic-gate 
16340Sstevel@tonic-gate /*
16350Sstevel@tonic-gate  * nfslog_close_elf_file - close elffile and write out last buffer
16360Sstevel@tonic-gate  */
16370Sstevel@tonic-gate void
nfslog_close_elf_file(void ** elfcookie)16380Sstevel@tonic-gate nfslog_close_elf_file(void **elfcookie)
16390Sstevel@tonic-gate {
16400Sstevel@tonic-gate 	struct nfsl_log_file	*elfrec;
16410Sstevel@tonic-gate 
16420Sstevel@tonic-gate 	if ((*elfcookie == NULL) || ((elfrec = nfsl_log_file_del(
16430Sstevel@tonic-gate 	    *elfcookie, &elf_file_list)) == NULL)) {
16440Sstevel@tonic-gate 		*elfcookie = NULL;
16450Sstevel@tonic-gate 		return;
16460Sstevel@tonic-gate 	}
16470Sstevel@tonic-gate 	if (elfrec->fp != NULL) {
16480Sstevel@tonic-gate 		/* Write the last output buffer to disk */
16490Sstevel@tonic-gate 		(void) nfsl_write_elfbuf(elfrec);
16500Sstevel@tonic-gate 		(void) fclose(elfrec->fp);
16510Sstevel@tonic-gate 	}
16520Sstevel@tonic-gate 	nfsl_log_file_free(elfrec);
16530Sstevel@tonic-gate 	*elfcookie = NULL;
16540Sstevel@tonic-gate }
16550Sstevel@tonic-gate 
16560Sstevel@tonic-gate /*
16570Sstevel@tonic-gate  * nfslog_process_elf_rec - processes the record in the buffer and outputs
16580Sstevel@tonic-gate  *	to the elf log.
16590Sstevel@tonic-gate  * Return 0 for success, errno else.
16600Sstevel@tonic-gate  */
16610Sstevel@tonic-gate int
nfslog_process_elf_rec(void * elfcookie,nfslog_request_record * logrec,char * path1,char * path2)16620Sstevel@tonic-gate nfslog_process_elf_rec(void *elfcookie, nfslog_request_record *logrec,
16630Sstevel@tonic-gate 	char *path1, char *path2)
16640Sstevel@tonic-gate {
16650Sstevel@tonic-gate 	struct nfsl_log_file	*elfrec;
16660Sstevel@tonic-gate 	struct nfsl_proc_disp	*disp;
16670Sstevel@tonic-gate 	char			*progname;
16680Sstevel@tonic-gate 
16690Sstevel@tonic-gate 	if ((elfrec = nfsl_log_file_find(elfcookie, elf_file_list)) == NULL) {
16700Sstevel@tonic-gate 		return (EINVAL);
16710Sstevel@tonic-gate 	}
16720Sstevel@tonic-gate 	/* Make sure there is room */
16730Sstevel@tonic-gate 	if (elfrec->bufoffset > DFLT_BUFFERSIZE) {
16740Sstevel@tonic-gate 		if (nfsl_write_elfbuf(elfrec) < 0) {
16750Sstevel@tonic-gate 			return (errno);
16760Sstevel@tonic-gate 		}
16770Sstevel@tonic-gate 	}
16780Sstevel@tonic-gate 	if ((disp = nfsl_find_elf_dispatch(logrec, &progname)) != NULL) {
16790Sstevel@tonic-gate 		nfsl_elf_rpc_print(elfrec, logrec, disp, progname,
16800Sstevel@tonic-gate 			path1, path2);
16810Sstevel@tonic-gate 	}
16820Sstevel@tonic-gate 	return (0);
16830Sstevel@tonic-gate }
1684