4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
27 * nfs log - read buffer file and print structs in user-readable form
40 #include <sys/types.h>
42 #include <sys/param.h>
43 #include <sys/utsname.h>
52 #include <netconfig.h>
54 #include <nfs/nfs_sec.h>
55 #include <nfs/export.h>
61 #include <nfs/nfs_log.h>
65 static char empty_name
[4] = "-";
67 static char ftype3_names
[NF3FIFO
+ 1][20] = {
68 "\"none\"", "\"file\"", "\"dir\"", "\"blk device\"",
69 "\"chr device\"", "\"link\"", "\"socket\"", "\"fifo\""
72 #define NFSL_FTYPE3(ftype) \
73 ((((ftype) >= 0) && ((ftype) <= NF3FIFO)) ? \
74 ftype3_names[ftype] : empty_name)
76 static char createmode3_names
[EXCLUSIVE
+ 1][20] = {
77 "\"unchecked", "\"guarded\"", "\"exclusive\""
80 #define NFSL_CREATEMODE3(createmode) \
81 ((((createmode) >= 0) && ((createmode) <= EXCLUSIVE)) ? \
82 createmode3_names[createmode] : empty_name)
84 static char auth_flavor_name
[RPCSEC_GSS
+ 1][20] = {
85 "\"auth_null\"", "\"auth_unix\"", "\"auth_short\"", "\"auth_des\"",
86 "\"auth_kerb\"", "\"none\"", "\"rpcsec_gss\""
89 #define NFSL_AUTH_FLAVOR_PRINT(auth_flavor) \
90 (((auth_flavor) <= RPCSEC_GSS) ? \
91 auth_flavor_name[auth_flavor] : empty_name)
93 #define NFSL_ERR_CNT 31 /* Actual err numbers */
96 * Two arrays - one short ints containing err codes, the other the strings
97 * (merged codes for both v2 and v3
99 static char nfsl_status_name
[NFSL_ERR_CNT
][30] = {
100 "\"ok\"", "\"perm\"", "\"noent\"", "\"io\"",
101 "\"nxio\"", "\"access\"", "\"exist\"", "\"xdev\"",
102 "\"nodev\"", "\"notdir\"", "\"isdir\"", "\"inval\"",
103 "\"fbig\"", "\"nospc\"", "\"rofs\"", "\"mlink\"",
104 "\"notsupp\"", "\"nametoolong\"", "\"notempty\"", "\"dquot\"",
105 "\"stale\"", "\"remote\"", "\"wflush\"", "\"badhandle\"",
106 "\"not_sync\"", "\"bad_cookie\"", "\"notsupp\"", "\"toosmall\"",
107 "\"serverfault\"", "\"badtype\"", "\"jukebox\"",
110 static short nfsl_status
[NFSL_ERR_CNT
] = {
111 0, 1, 2, 5, 6, 13, 17, 18,
112 19, 20, 21, 22, 27, 28, 30, 31,
113 45, 63, 66, 69, 70, 71, 99, 10001,
114 10002, 10003, 10004, 10005, 10006, 10007, 10008
117 /* list of open elf files */
118 static struct nfsl_log_file
*elf_file_list
= NULL
;
120 /* Imported functions */
121 extern void bcopy(const void *s1
, void *s2
, size_t n
);
123 /* Static functions */
124 static void nfsl_log_file_free(struct nfsl_log_file
*elfrec
);
125 static void nfsl_log_file_add(struct nfsl_log_file
*elfrec
,
126 struct nfsl_log_file
**elf_listp
);
127 static struct nfsl_log_file
*nfsl_log_file_find(struct nfsl_log_file
*elfrec
,
128 struct nfsl_log_file
*elf_list
);
129 static struct nfsl_log_file
*nfsl_log_file_del(struct nfsl_log_file
*elfrec
,
130 struct nfsl_log_file
**elf_listp
);
132 static char *nfsl_get_time(time_t tt
);
133 static char *nfsl_get_date(time_t tt
);
134 static char *nfsl_get_date_nq(time_t tt
);
135 static int nfsl_write_elfbuf(struct nfsl_log_file
*elfrec
);
136 static void nfsl_ipaddr_print(struct nfsl_log_file
*, struct netbuf
*);
137 static void nfsl_elf_record_header_print(struct nfsl_log_file
*,
138 nfslog_record_header
*, char *, char *,
139 struct nfsl_proc_disp
*, char *);
140 static void nfsl_elf_buffer_header_print(struct nfsl_log_file
*,
141 nfslog_buffer_header
*);
142 static struct nfsl_proc_disp
*nfsl_find_elf_dispatch(
143 nfslog_request_record
*, char **);
144 static void nfsl_elf_rpc_print(struct nfsl_log_file
*,
145 nfslog_request_record
*, struct nfsl_proc_disp
*,
146 char *, char *, char *);
147 static void nfslog_size3_print(struct nfsl_log_file
*, set_size3
*);
149 static void nfslog_null_args(struct nfsl_log_file
*, caddr_t
*);
150 static void nfslog_null_res(struct nfsl_log_file
*, caddr_t
*);
157 /* Functions for elf print of the arguments */
158 static void nfslog_fhandle_print(struct nfsl_log_file
*, fhandle_t
*);
159 static void nfslog_diropargs_print(struct nfsl_log_file
*, nfslog_diropargs
*);
160 static void nfslog_setattrargs_print(struct nfsl_log_file
*,
161 nfslog_setattrargs
*);
162 static void nfslog_sattr_print(struct nfsl_log_file
*,
164 static void nfslog_nfsreadargs_print(struct nfsl_log_file
*,
165 nfslog_nfsreadargs
*);
166 static void nfslog_writeargs_print(struct nfsl_log_file
*,
168 static void nfslog_writeresult_print(struct nfsl_log_file
*,
169 nfslog_writeresult
*, bool_t
);
170 static void nfslog_creatargs_print(struct nfsl_log_file
*,
171 nfslog_createargs
*);
172 static void nfslog_rddirargs_print(struct nfsl_log_file
*, nfslog_rddirargs
*);
173 static void nfslog_linkargs_print(struct nfsl_log_file
*, nfslog_linkargs
*);
174 static void nfslog_rnmargs_print(struct nfsl_log_file
*, nfslog_rnmargs
*);
175 static void nfslog_symlinkargs_print(struct nfsl_log_file
*,
176 nfslog_symlinkargs
*);
178 static void nfslog_sharefsargs_print(struct nfsl_log_file
*,
179 nfslog_sharefsargs
*);
180 static void nfslog_getfhargs_print(struct nfsl_log_file
*,
183 /* Functions for elf print of the response */
184 static void nfslog_nfsstat_print(struct nfsl_log_file
*, enum nfsstat
*,
186 static void nfslog_diropres_print(struct nfsl_log_file
*, nfslog_diropres
*,
188 static void nfslog_rdlnres_print(struct nfsl_log_file
*, nfslog_rdlnres
*,
190 static void nfslog_rdresult_print(struct nfsl_log_file
*,
191 nfslog_rdresult
*, bool_t
);
192 static void nfslog_rddirres_print(struct nfsl_log_file
*, nfslog_rddirres
*,
199 /* Functions for elf print of the arguments */
200 static void nfslog_fh3_print(struct nfsl_log_file
*, nfs_fh3
*);
201 static void nfslog_diropargs3_print(struct nfsl_log_file
*,
202 nfslog_diropargs3
*);
203 static void nfslog_SETATTR3args_print(struct nfsl_log_file
*,
204 nfslog_SETATTR3args
*);
205 static void nfslog_READ3args_print(struct nfsl_log_file
*, nfslog_READ3args
*);
206 static void nfslog_WRITE3args_print(struct nfsl_log_file
*,
207 nfslog_WRITE3args
*);
208 static void nfslog_CREATE3args_print(struct nfsl_log_file
*,
209 nfslog_CREATE3args
*);
210 static void nfslog_MKDIR3args_print(struct nfsl_log_file
*,
211 nfslog_MKDIR3args
*);
212 static void nfslog_SYMLINK3args_print(struct nfsl_log_file
*,
213 nfslog_SYMLINK3args
*);
214 static void nfslog_MKNOD3args_print(struct nfsl_log_file
*,
215 nfslog_MKNOD3args
*);
216 static void nfslog_REMOVE3args_print(struct nfsl_log_file
*,
217 nfslog_REMOVE3args
*);
218 static void nfslog_RMDIR3args_print(struct nfsl_log_file
*,
219 nfslog_RMDIR3args
*);
220 static void nfslog_RENAME3args_print(struct nfsl_log_file
*,
221 nfslog_RENAME3args
*);
222 static void nfslog_LINK3args_print(struct nfsl_log_file
*,
224 static void nfslog_COMMIT3args_print(struct nfsl_log_file
*,
225 nfslog_COMMIT3args
*);
226 static void nfslog_READDIRPLUS3args_print(struct nfsl_log_file
*,
227 nfslog_READDIRPLUS3args
*);
229 /* Functions for elf print of the response */
230 static void nfslog_nfsstat3_print(struct nfsl_log_file
*,
232 static void nfslog_LOOKUP3res_print(struct nfsl_log_file
*,
233 nfslog_LOOKUP3res
*, bool_t
);
234 static void nfslog_READLINK3res_print(struct nfsl_log_file
*,
235 nfslog_READLINK3res
*, bool_t
);
236 static void nfslog_READ3res_print(struct nfsl_log_file
*,
237 nfslog_READ3res
*, bool_t
);
238 static void nfslog_WRITE3res_print(struct nfsl_log_file
*,
239 nfslog_WRITE3res
*, bool_t
);
240 static void nfslog_CREATE3res_print(struct nfsl_log_file
*,
241 nfslog_CREATE3res
*, bool_t
);
242 static void nfslog_MKDIR3res_print(struct nfsl_log_file
*,
243 nfslog_MKDIR3res
*, bool_t
);
244 static void nfslog_SYMLINK3res_print(struct nfsl_log_file
*,
245 nfslog_SYMLINK3res
*, bool_t
);
246 static void nfslog_MKNOD3res_print(struct nfsl_log_file
*,
247 nfslog_MKNOD3res
*, bool_t
);
248 static void nfslog_READDIRPLUS3res_print(struct nfsl_log_file
*,
249 nfslog_READDIRPLUS3res
*, bool_t
);
252 static bool_t nfsl_print_fh
= FALSE
; /* print file handles? */
254 #define DFLT_BUFFERSIZE 8192
255 #define DFLT_OVFSIZE 3072 /* Maximum logged or buffered size */
257 static char hostname
[MAXHOSTNAMELEN
]; /* name of host */
261 * Define the actions taken per prog/vers/proc:
263 * In some cases, the nl types are the same as the nfs types and a simple
264 * bcopy should suffice. Rather that define tens of identical procedures,
265 * simply define these to bcopy. Similarly this takes care of different
266 * procs that use same parameter struct.
269 static struct nfsl_proc_disp nfsl_elf_proc_v2
[] = {
275 {nfslog_null_args
, nfslog_null_res
, "\"null\""},
277 /* RFS_GETATTR = 1 */
278 {nfslog_fhandle_print
, nfslog_nfsstat_print
, "\"getattr\""},
280 /* RFS_SETATTR = 2 */
281 {nfslog_setattrargs_print
, nfslog_nfsstat_print
, "\"setattr\""},
283 /* RFS_ROOT = 3 *** NO LONGER SUPPORTED *** */
284 {nfslog_null_args
, nfslog_null_res
, "\"root\""},
287 {nfslog_diropargs_print
, nfslog_diropres_print
, "\"lookup\""},
289 /* RFS_READLINK = 5 */
290 {nfslog_fhandle_print
, nfslog_rdlnres_print
, "\"readlink\""},
293 {nfslog_nfsreadargs_print
, nfslog_rdresult_print
, "\"read\""},
295 /* RFS_WRITECACHE = 7 *** NO LONGER SUPPORTED *** */
296 {nfslog_null_args
, nfslog_null_res
, "\"writecache\""},
299 {nfslog_writeargs_print
, nfslog_writeresult_print
, "\"write\""},
302 {nfslog_creatargs_print
, nfslog_diropres_print
, "\"create\""},
304 /* RFS_REMOVE = 10 */
305 {nfslog_diropargs_print
, nfslog_nfsstat_print
, "\"remove\""},
307 /* RFS_RENAME = 11 */
308 {nfslog_rnmargs_print
, nfslog_nfsstat_print
, "\"rename\""},
311 {nfslog_linkargs_print
, nfslog_nfsstat_print
, "\"link\""},
313 /* RFS_SYMLINK = 13 */
314 {nfslog_symlinkargs_print
, nfslog_nfsstat_print
, "\"symlink\""},
317 {nfslog_creatargs_print
, nfslog_diropres_print
, "\"mkdir\""},
320 {nfslog_diropargs_print
, nfslog_nfsstat_print
, "\"rmdir\""},
322 /* RFS_READDIR = 16 */
323 {nfslog_rddirargs_print
, nfslog_rddirres_print
, "\"readdir\""},
325 /* RFS_STATFS = 17 */
326 {nfslog_fhandle_print
, nfslog_nfsstat_print
, "\"statfs\""},
334 static struct nfsl_proc_disp nfsl_elf_proc_v3
[] = {
336 /* NFSPROC3_NULL = 0 */
337 {nfslog_null_args
, nfslog_null_res
, "\"null\""},
339 /* NFSPROC3_GETATTR = 1 */
340 {nfslog_fh3_print
, nfslog_nfsstat3_print
, "\"getattr\""},
342 /* NFSPROC3_SETATTR = 2 */
343 {nfslog_SETATTR3args_print
, nfslog_nfsstat3_print
, "\"setattr\""},
345 /* NFSPROC3_LOOKUP = 3 */
346 {nfslog_diropargs3_print
, nfslog_LOOKUP3res_print
, "\"lookup\""},
348 /* NFSPROC3_ACCESS = 4 */
349 {nfslog_fh3_print
, nfslog_nfsstat3_print
, "\"access\""},
351 /* NFSPROC3_READLINK = 5 */
352 {nfslog_fh3_print
, nfslog_READLINK3res_print
, "\"readlink\""},
354 /* NFSPROC3_READ = 6 */
355 {nfslog_READ3args_print
, nfslog_READ3res_print
, "\"read\""},
357 /* NFSPROC3_WRITE = 7 */
358 {nfslog_WRITE3args_print
, nfslog_WRITE3res_print
, "\"write\""},
360 /* NFSPROC3_CREATE = 8 */
361 {nfslog_CREATE3args_print
, nfslog_CREATE3res_print
, "\"create\""},
363 /* NFSPROC3_MKDIR = 9 */
364 {nfslog_MKDIR3args_print
, nfslog_MKDIR3res_print
, "\"mkdir\""},
366 /* NFSPROC3_SYMLINK = 10 */
367 {nfslog_SYMLINK3args_print
, nfslog_SYMLINK3res_print
, "\"symlink\""},
369 /* NFSPROC3_MKNOD = 11 */
370 {nfslog_MKNOD3args_print
, nfslog_MKNOD3res_print
, "\"mknod\""},
372 /* NFSPROC3_REMOVE = 12 */
373 {nfslog_REMOVE3args_print
, nfslog_nfsstat3_print
, "\"remove\""},
375 /* NFSPROC3_RMDIR = 13 */
376 {nfslog_RMDIR3args_print
, nfslog_nfsstat3_print
, "\"rmdir\""},
378 /* NFSPROC3_RENAME = 14 */
379 {nfslog_RENAME3args_print
, nfslog_nfsstat3_print
, "\"rename\""},
381 /* NFSPROC3_LINK = 15 */
382 {nfslog_LINK3args_print
, nfslog_nfsstat3_print
, "\"link\""},
384 /* NFSPROC3_READDIR = 16 */
385 {nfslog_fh3_print
, nfslog_nfsstat3_print
, "\"readdir\""},
387 /* NFSPROC3_READDIRPLUS = 17 */
388 {nfslog_READDIRPLUS3args_print
, nfslog_READDIRPLUS3res_print
,
391 /* NFSPROC3_FSSTAT = 18 */
392 {nfslog_fh3_print
, nfslog_nfsstat3_print
, "\"fsstat\""},
394 /* NFSPROC3_FSINFO = 19 */
395 {nfslog_fh3_print
, nfslog_nfsstat3_print
, "\"fsinfo\""},
397 /* NFSPROC3_PATHCONF = 20 */
398 {nfslog_fh3_print
, nfslog_nfsstat3_print
, "\"pathconf\""},
400 /* NFSPROC3_COMMIT = 21 */
401 {nfslog_COMMIT3args_print
, nfslog_nfsstat3_print
, "\"commit\""},
408 static struct nfsl_proc_disp nfsl_log_elf_proc_v1
[] = {
410 /* NFSLOG_NULL = 0 */
411 {nfslog_null_args
, nfslog_null_res
, "\"null\""},
413 /* NFSLOG_SHARE = 1 */
414 {nfslog_sharefsargs_print
, nfslog_nfsstat_print
, "\"log_share\""},
416 /* NFSLOG_UNSHARE = 2 */
417 {nfslog_sharefsargs_print
, nfslog_nfsstat_print
, "\"log_unshare\""},
419 /* NFSLOG_LOOKUP = 3 */
420 {nfslog_diropargs3_print
, nfslog_LOOKUP3res_print
, "\"lookup\""},
422 /* NFSLOG_GETFH = 4 */
423 {nfslog_getfhargs_print
, nfslog_nfsstat_print
, "\"log_getfh\""},
426 static struct nfsl_vers_disp nfsl_elf_vers_disptable
[] = {
427 {sizeof (nfsl_elf_proc_v2
) / sizeof (nfsl_elf_proc_v2
[0]),
429 {sizeof (nfsl_elf_proc_v3
) / sizeof (nfsl_elf_proc_v3
[0]),
433 static struct nfsl_vers_disp nfsl_log_elf_vers_disptable
[] = {
434 {sizeof (nfsl_log_elf_proc_v1
) / sizeof (nfsl_log_elf_proc_v1
[0]),
435 nfsl_log_elf_proc_v1
},
438 static struct nfsl_prog_disp nfsl_elf_dispatch_table
[] = {
441 sizeof (nfsl_elf_vers_disptable
) /
442 sizeof (nfsl_elf_vers_disptable
[0]),
443 nfsl_elf_vers_disptable
, "nfs"},
446 sizeof (nfsl_log_elf_vers_disptable
) /
447 sizeof (nfsl_log_elf_vers_disptable
[0]),
448 nfsl_log_elf_vers_disptable
, "nfslog"},
451 static int nfsl_elf_dispatch_table_arglen
=
452 sizeof (nfsl_elf_dispatch_table
) /
453 sizeof (nfsl_elf_dispatch_table
[0]);
456 nfslog_get_status(short status
)
461 /* Usually status is 0... */
463 return (nfsl_status_name
[0]);
467 mid
= NFSL_ERR_CNT
/ 2;
468 /* binary search for status string */
469 while (((errstat
= nfsl_status
[mid
]) != status
) && (low
< mid
) &&
471 if (errstat
> status
) { /* search bottom half */
473 } else { /* search upper half */
476 mid
= low
+ ((high
- low
) / 2);
478 if (errstat
== status
) { /* found it */
479 return (nfsl_status_name
[mid
]);
484 /* nfsl_get_time - return string with time formatted as hh:mm:ss */
486 nfsl_get_time(time_t tt
)
488 static char timestr
[20];
489 static time_t lasttime
;
494 if (localtime_r(&tt
, &tmst
) == NULL
) {
497 (void) sprintf(timestr
, "%02d:%02d:%02d",
498 tmst
.tm_hour
, tmst
.tm_min
, tmst
.tm_sec
);
503 /* nfsl_get_date - return date string formatted as "yyyy-mm-dd hh:mm:ss" */
505 nfsl_get_date(time_t tt
)
507 static char timestr
[30];
508 static time_t lasttime
;
513 if (localtime_r(&tt
, &tmst
) == NULL
) {
516 (void) sprintf(timestr
, "\"%04d-%02d-%02d %02d:%02d:%02d\"",
517 tmst
.tm_year
+ 1900, tmst
.tm_mon
+ 1, tmst
.tm_mday
,
518 tmst
.tm_hour
, tmst
.tm_min
, tmst
.tm_sec
);
524 * nfsl_get_date_nq - return date string formatted as yyyy-mm-dd hh:mm:ss
528 nfsl_get_date_nq(time_t tt
)
530 static char timestr
[30];
531 static time_t lasttime
;
536 if (localtime_r(&tt
, &tmst
) == NULL
) {
539 (void) sprintf(timestr
, "%04d-%02d-%02d %02d:%02d:%02d",
540 tmst
.tm_year
+ 1900, tmst
.tm_mon
+ 1, tmst
.tm_mday
,
541 tmst
.tm_hour
, tmst
.tm_min
, tmst
.tm_sec
);
545 /* write log buffer out to file */
547 nfsl_write_elfbuf(struct nfsl_log_file
*elfrec
)
550 char *elfbuf
= elfrec
->buf
;
551 int elfbufoffset
= elfrec
->bufoffset
;
554 (void) printf("nfsl_write_elfbuf: bufoffset %d\n",
556 if (elfbufoffset
<= 0)
558 elfbuf
[elfbufoffset
] = '\0';
559 if ((rc
= fputs(elfbuf
, elfrec
->fp
)) < 0) {
560 syslog(LOG_ERR
, gettext("Write to %s failed: %s\n"),
561 elfrec
->path
, strerror(errno
));
564 if (rc
!= elfbufoffset
) {
565 syslog(LOG_ERR
, gettext("Write %d bytes to %s returned %d\n"),
566 elfbufoffset
, elfrec
->path
, rc
);
569 elfrec
->bufoffset
= 0;
575 nfslog_null_args(struct nfsl_log_file
*elfrec
, caddr_t
*nfsl_args
)
581 nfslog_null_res(struct nfsl_log_file
*elfrec
, caddr_t
*nfsl_res
)
586 nfslog_fh3_print(struct nfsl_log_file
*elfrec
, nfs_fh3
*fh3
)
590 if (fh3
->fh3_length
== sizeof (fhandle_t
)) {
591 nfslog_fhandle_print(elfrec
, (fhandle_t
*)&fh3
->fh3_u
.data
);
593 nfslog_opaque_print_buf(fh3
->fh3_u
.data
, fh3
->fh3_length
,
594 elfrec
->buf
, &elfrec
->bufoffset
,
595 DFLT_BUFFERSIZE
+ DFLT_OVFSIZE
);
604 /* Functions that elf print the arguments */
607 nfslog_fhandle_print(struct nfsl_log_file
*elfrec
, fhandle_t
*args
)
611 nfslog_opaque_print_buf(args
, sizeof (*args
),
612 elfrec
->buf
, &elfrec
->bufoffset
,
613 DFLT_BUFFERSIZE
+ DFLT_OVFSIZE
);
617 nfslog_diropargs_print(struct nfsl_log_file
*elfrec
, nfslog_diropargs
*args
)
619 char *elfbuf
= elfrec
->buf
;
620 int elfbufoffset
= elfrec
->bufoffset
;
623 nfslog_fhandle_print(elfrec
, &args
->da_fhandle
);
624 elfbufoffset
= elfrec
->bufoffset
;
625 if (args
->da_name
!= NULL
) {
626 elfbufoffset
+= sprintf(&elfbuf
[elfbufoffset
],
627 " \"%s\"", args
->da_name
);
629 elfbufoffset
+= sprintf(&elfbuf
[elfbufoffset
], " %s",
633 elfrec
->bufoffset
= elfbufoffset
;
637 nfslog_sattr_print(struct nfsl_log_file
*elfrec
, nfslog_sattr
*args
)
639 char *elfbuf
= elfrec
->buf
;
640 int elfbufoffset
= elfrec
->bufoffset
;
643 if (args
->sa_mode
!= (uint32_t)-1) {
644 elfbufoffset
+= sprintf(&elfbuf
[elfbufoffset
],
645 " \"mode=0%o\"", args
->sa_mode
);
647 if (args
->sa_uid
!= (uint32_t)-1) {
648 elfbufoffset
+= sprintf(&elfbuf
[elfbufoffset
],
649 " \"uid=0x%x\"", args
->sa_uid
);
651 if (args
->sa_gid
!= (uint32_t)-1) {
652 elfbufoffset
+= sprintf(&elfbuf
[elfbufoffset
],
653 " \"gid=0x%x\"", args
->sa_gid
);
655 if (args
->sa_size
!= (uint32_t)-1) {
656 elfbufoffset
+= sprintf(&elfbuf
[elfbufoffset
],
657 " \"size=0x%x\"", args
->sa_size
);
659 if (args
->sa_atime
.tv_sec
!= (uint32_t)-1) {
660 elfbufoffset
+= sprintf(&elfbuf
[elfbufoffset
],
662 nfsl_get_date_nq((time_t)args
->sa_atime
.tv_sec
));
664 if (args
->sa_mtime
.tv_sec
!= (uint32_t)-1) {
665 elfbufoffset
+= sprintf(&elfbuf
[elfbufoffset
],
667 nfsl_get_date_nq((time_t)args
->sa_mtime
.tv_sec
));
670 elfrec
->bufoffset
= elfbufoffset
;
674 nfslog_setattrargs_print(struct nfsl_log_file
*elfrec
, nfslog_setattrargs
*args
)
676 nfslog_fhandle_print(elfrec
, &args
->saa_fh
);
677 nfslog_sattr_print(elfrec
, &args
->saa_sa
);
681 nfslog_nfsreadargs_print(struct nfsl_log_file
*elfrec
,
682 nfslog_nfsreadargs
*args
)
684 char *elfbuf
= elfrec
->buf
;
687 nfslog_fhandle_print(elfrec
, &args
->ra_fhandle
);
688 elfbufoffset
= elfrec
->bufoffset
;
689 elfbufoffset
+= sprintf(&elfbuf
[elfbufoffset
], " 0x%x",
691 elfbufoffset
+= sprintf(&elfbuf
[elfbufoffset
], " 0x%x",
693 elfbufoffset
+= sprintf(&elfbuf
[elfbufoffset
], " 0x%x",
695 elfrec
->bufoffset
= elfbufoffset
;
699 nfslog_writeargs_print(struct nfsl_log_file
*elfrec
, nfslog_writeargs
*args
)
701 char *elfbuf
= elfrec
->buf
;
702 int elfbufoffset
= elfrec
->bufoffset
;
704 nfslog_fhandle_print(elfrec
, &args
->waargs_fhandle
);
705 elfbufoffset
= elfrec
->bufoffset
;
706 elfbufoffset
+= sprintf(&elfbuf
[elfbufoffset
], " 0x%x",
707 args
->waargs_begoff
);
708 elfbufoffset
+= sprintf(&elfbuf
[elfbufoffset
], " 0x%x",
709 args
->waargs_offset
);
710 elfbufoffset
+= sprintf(&elfbuf
[elfbufoffset
], " 0x%x",
711 args
->waargs_totcount
);
712 elfrec
->bufoffset
+= sprintf(&elfrec
->buf
[elfrec
->bufoffset
], " 0x%x",
717 nfslog_writeresult_print(struct nfsl_log_file
*elfrec
, nfslog_writeresult
*res
,
720 char *elfbuf
= elfrec
->buf
;
721 int elfbufoffset
= elfrec
->bufoffset
;
724 nfslog_nfsstat_print(elfrec
, &res
->wr_status
, print_status
);
725 } else if (res
->wr_status
== NFS_OK
) {
726 elfbufoffset
+= sprintf(&elfbuf
[elfbufoffset
], " 0x%x",
727 res
->nfslog_writeresult_u
.wr_size
);
728 elfrec
->bufoffset
= elfbufoffset
;
733 nfslog_creatargs_print(struct nfsl_log_file
*elfrec
, nfslog_createargs
*args
)
735 nfslog_diropargs_print(elfrec
, &args
->ca_da
);
736 nfslog_sattr_print(elfrec
, &args
->ca_sa
);
741 nfslog_rddirargs_print(struct nfsl_log_file
*elfrec
, nfslog_rddirargs
*args
)
743 char *elfbuf
= elfrec
->buf
;
746 nfslog_fhandle_print(elfrec
, &args
->rda_fh
);
747 elfbufoffset
= elfrec
->bufoffset
;
748 elfbufoffset
+= sprintf(&elfbuf
[elfbufoffset
], " 0x%x",
750 elfbufoffset
+= sprintf(&elfbuf
[elfbufoffset
], " 0x%x",
752 elfrec
->bufoffset
= elfbufoffset
;
756 nfslog_rnmargs_print(struct nfsl_log_file
*elfrec
, nfslog_rnmargs
*args
)
758 nfslog_diropargs_print(elfrec
, &args
->rna_from
);
759 nfslog_diropargs_print(elfrec
, &args
->rna_to
);
763 nfslog_linkargs_print(struct nfsl_log_file
*elfrec
, nfslog_linkargs
*args
)
765 nfslog_fhandle_print(elfrec
, &args
->la_from
);
766 nfslog_diropargs_print(elfrec
, &args
->la_to
);
770 nfslog_symlinkargs_print(struct nfsl_log_file
*elfrec
, nfslog_symlinkargs
*args
)
772 char *elfbuf
= elfrec
->buf
;
775 nfslog_diropargs_print(elfrec
, &args
->sla_from
);
776 elfbufoffset
= elfrec
->bufoffset
;
777 elfbufoffset
+= sprintf(&elfbuf
[elfbufoffset
], " \"%s\"",
779 elfrec
->bufoffset
= elfbufoffset
;
780 nfslog_sattr_print(elfrec
, &args
->sla_sa
);
784 * SHARE/UNSHARE fs log args copy
787 nfslog_sharefsargs_print(struct nfsl_log_file
*elfrec
,
788 nfslog_sharefsargs
*args
)
790 unsigned int elfbufoffset
;
791 char *elfbuf
= elfrec
->buf
;
793 nfslog_fhandle_print(elfrec
, &args
->sh_fh_buf
);
795 elfbufoffset
= elfrec
->bufoffset
;
796 elfbufoffset
+= sprintf(&elfbuf
[elfbufoffset
], " 0x%x",
798 elfbufoffset
+= sprintf(&elfbuf
[elfbufoffset
], " 0x%x",
801 if (args
->sh_path
!= NULL
) {
802 elfbufoffset
+= sprintf(&elfbuf
[elfbufoffset
],
803 " \"%s\"", args
->sh_path
);
805 elfbufoffset
+= sprintf(&elfbuf
[elfbufoffset
], " %s",
809 elfrec
->bufoffset
= elfbufoffset
;
813 nfslog_getfhargs_print(struct nfsl_log_file
*elfrec
,
814 nfslog_getfhargs
*args
)
816 unsigned int elfbufoffset
;
817 char *elfbuf
= elfrec
->buf
;
819 nfslog_fhandle_print(elfrec
, &args
->gfh_fh_buf
);
821 elfbufoffset
= elfrec
->bufoffset
;
823 if (args
->gfh_path
!= NULL
) {
824 elfbufoffset
+= sprintf(&elfbuf
[elfbufoffset
],
825 " \"%s\"", args
->gfh_path
);
827 elfbufoffset
+= sprintf(&elfbuf
[elfbufoffset
], " %s",
831 elfrec
->bufoffset
= elfbufoffset
;
835 nfslog_nfsstat_print(struct nfsl_log_file
*elfrec
, enum nfsstat
*res
,
839 char *statp
= nfslog_get_status((short)(*res
));
843 sprintf(&elfrec
->buf
[elfrec
->bufoffset
], " %s",
847 sprintf(&elfrec
->buf
[elfrec
->bufoffset
], " %5d",
853 nfslog_diropres_print(struct nfsl_log_file
*elfrec
, nfslog_diropres
*res
,
857 nfslog_nfsstat_print(elfrec
, &res
->dr_status
, print_status
);
858 } else if (res
->dr_status
== NFS_OK
) {
859 nfslog_fhandle_print(elfrec
,
860 &res
->nfslog_diropres_u
.dr_ok
.drok_fhandle
);
865 nfslog_rdlnres_print(struct nfsl_log_file
*elfrec
, nfslog_rdlnres
*res
,
869 nfslog_nfsstat_print(elfrec
, &res
->rl_status
, print_status
);
870 } else if (res
->rl_status
== NFS_OK
) {
871 elfrec
->bufoffset
+= sprintf(&elfrec
->buf
[elfrec
->bufoffset
],
872 " \"%s\"", res
->nfslog_rdlnres_u
.rl_ok
);
877 nfslog_rdresult_print(struct nfsl_log_file
*elfrec
, nfslog_rdresult
*res
,
881 nfslog_nfsstat_print(elfrec
, &res
->r_status
, print_status
);
882 } else if (res
->r_status
== NFS_OK
) {
883 elfrec
->bufoffset
+= sprintf(&elfrec
->buf
[elfrec
->bufoffset
],
884 " 0x%x", res
->nfslog_rdresult_u
.r_ok
.filesize
);
885 elfrec
->bufoffset
+= sprintf(&elfrec
->buf
[elfrec
->bufoffset
],
886 " 0x%x", res
->nfslog_rdresult_u
.r_ok
.rrok_count
);
891 nfslog_rddirres_print(struct nfsl_log_file
*elfrec
, nfslog_rddirres
*res
,
895 nfslog_nfsstat_print(elfrec
, &res
->rd_status
, print_status
);
896 } else if (res
->rd_status
== NFS_OK
) {
897 char *elfbuf
= elfrec
->buf
;
898 int elfbufoffset
= elfrec
->bufoffset
;
900 elfbufoffset
+= sprintf(&elfbuf
[elfbufoffset
], " 0x%x",
901 res
->nfslog_rddirres_u
.rd_ok
.rdok_offset
);
902 elfbufoffset
+= sprintf(&elfbuf
[elfbufoffset
], " 0x%x",
903 res
->nfslog_rddirres_u
.rd_ok
.rdok_size
);
904 elfbufoffset
+= sprintf(&elfbuf
[elfbufoffset
], " 0x%x",
905 res
->nfslog_rddirres_u
.rd_ok
.rdok_eof
);
906 elfrec
->bufoffset
= elfbufoffset
;
915 nfslog_diropargs3_print(struct nfsl_log_file
*elfrec
,
916 nfslog_diropargs3
*args
)
919 nfslog_fh3_print(elfrec
, &args
->dir
);
920 elfrec
->bufoffset
+= sprintf(&elfrec
->buf
[elfrec
->bufoffset
],
921 " \"%s\"", args
->name
);
926 nfslog_size3_print(struct nfsl_log_file
*elfrec
, set_size3
*args
)
928 char *elfbuf
= elfrec
->buf
;
929 int elfbufoffset
= elfrec
->bufoffset
;
932 elfbufoffset
+= sprintf(&elfbuf
[elfbufoffset
],
934 " \"size=0x%llx\"", args
->size
);
936 elfrec
->bufoffset
= elfbufoffset
;
940 nfslog_SETATTR3args_print(struct nfsl_log_file
*elfrec
,
941 nfslog_SETATTR3args
*args
)
943 nfslog_fh3_print(elfrec
, &args
->object
);
944 nfslog_size3_print(elfrec
, &args
->size
);
948 nfslog_READ3args_print(struct nfsl_log_file
*elfrec
, nfslog_READ3args
*args
)
950 nfslog_fh3_print(elfrec
, &args
->file
);
951 elfrec
->bufoffset
+= sprintf(&elfrec
->buf
[elfrec
->bufoffset
], " 0x%llx",
953 elfrec
->bufoffset
+= sprintf(&elfrec
->buf
[elfrec
->bufoffset
], " 0x%x",
958 nfslog_WRITE3args_print(struct nfsl_log_file
*elfrec
,
959 nfslog_WRITE3args
*args
)
961 char *elfbuf
= elfrec
->buf
;
964 nfslog_fh3_print(elfrec
, &args
->file
);
965 elfbufoffset
= elfrec
->bufoffset
;
966 elfbufoffset
+= sprintf(&elfbuf
[elfbufoffset
], " 0x%llx",
968 elfbufoffset
+= sprintf(&elfbuf
[elfbufoffset
], " 0x%x",
970 elfbufoffset
+= sprintf(&elfbuf
[elfbufoffset
], " 0x%x",
972 elfrec
->bufoffset
= elfbufoffset
;
976 nfslog_CREATE3args_print(struct nfsl_log_file
*elfrec
,
977 nfslog_CREATE3args
*args
)
979 nfslog_diropargs3_print(elfrec
, &args
->where
);
980 elfrec
->bufoffset
+= sprintf(&elfrec
->buf
[elfrec
->bufoffset
], " %s",
981 NFSL_CREATEMODE3(args
->how
.mode
));
982 if (args
->how
.mode
!= EXCLUSIVE
) {
983 nfslog_size3_print(elfrec
,
984 &args
->how
.nfslog_createhow3_u
.size
);
989 nfslog_MKDIR3args_print(struct nfsl_log_file
*elfrec
,
990 nfslog_MKDIR3args
*args
)
992 nfslog_diropargs3_print(elfrec
, &args
->where
);
996 nfslog_SYMLINK3args_print(struct nfsl_log_file
*elfrec
,
997 nfslog_SYMLINK3args
*args
)
999 nfslog_diropargs3_print(elfrec
, &args
->where
);
1000 elfrec
->bufoffset
+= sprintf(&elfrec
->buf
[elfrec
->bufoffset
],
1001 " \"%s\"", args
->symlink_data
);
1005 nfslog_MKNOD3args_print(struct nfsl_log_file
*elfrec
,
1006 nfslog_MKNOD3args
*args
)
1008 nfslog_diropargs3_print(elfrec
, &args
->where
);
1009 elfrec
->bufoffset
+= sprintf(&elfrec
->buf
[elfrec
->bufoffset
], " %s",
1010 NFSL_FTYPE3(args
->type
));
1014 nfslog_REMOVE3args_print(struct nfsl_log_file
*elfrec
,
1015 nfslog_REMOVE3args
*args
)
1017 nfslog_diropargs3_print(elfrec
, &args
->object
);
1021 nfslog_RMDIR3args_print(struct nfsl_log_file
*elfrec
,
1022 nfslog_RMDIR3args
*args
)
1024 nfslog_diropargs3_print(elfrec
, &args
->object
);
1028 nfslog_RENAME3args_print(struct nfsl_log_file
*elfrec
,
1029 nfslog_RENAME3args
*args
)
1031 nfslog_diropargs3_print(elfrec
, &args
->from
);
1032 nfslog_diropargs3_print(elfrec
, &args
->to
);
1036 nfslog_LINK3args_print(struct nfsl_log_file
*elfrec
, nfslog_LINK3args
*args
)
1038 nfslog_fh3_print(elfrec
, &args
->file
);
1039 nfslog_diropargs3_print(elfrec
, &args
->link
);
1043 nfslog_READDIRPLUS3args_print(struct nfsl_log_file
*elfrec
,
1044 nfslog_READDIRPLUS3args
*args
)
1046 nfslog_fh3_print(elfrec
, &args
->dir
);
1047 elfrec
->bufoffset
+= sprintf(&elfrec
->buf
[elfrec
->bufoffset
], " 0x%x",
1049 elfrec
->bufoffset
+= sprintf(&elfrec
->buf
[elfrec
->bufoffset
], " 0x%x",
1054 nfslog_COMMIT3args_print(struct nfsl_log_file
*elfrec
,
1055 nfslog_COMMIT3args
*args
)
1057 nfslog_fh3_print(elfrec
, &args
->file
);
1058 elfrec
->bufoffset
+= sprintf(&elfrec
->buf
[elfrec
->bufoffset
], " 0x%llx",
1060 elfrec
->bufoffset
+= sprintf(&elfrec
->buf
[elfrec
->bufoffset
], " 0x%x",
1065 nfslog_nfsstat3_print(struct nfsl_log_file
*elfrec
, enum nfsstat3
*res
,
1066 bool_t print_status
)
1069 char *statp
= nfslog_get_status((short)(*res
));
1072 elfrec
->bufoffset
+=
1073 sprintf(&elfrec
->buf
[elfrec
->bufoffset
], " %s",
1076 elfrec
->bufoffset
+=
1077 sprintf(&elfrec
->buf
[elfrec
->bufoffset
], " %5d",
1083 nfslog_LOOKUP3res_print(struct nfsl_log_file
*elfrec
,
1084 nfslog_LOOKUP3res
*res
, bool_t print_status
)
1087 nfslog_nfsstat3_print(elfrec
, &res
->status
, print_status
);
1088 } else if (res
->status
== NFS3_OK
) {
1089 nfslog_fh3_print(elfrec
, &res
->nfslog_LOOKUP3res_u
.object
);
1094 nfslog_READLINK3res_print(struct nfsl_log_file
*elfrec
,
1095 nfslog_READLINK3res
*res
, bool_t print_status
)
1098 nfslog_nfsstat3_print(elfrec
, &res
->status
, print_status
);
1099 } else if (res
->status
== NFS3_OK
) {
1100 elfrec
->bufoffset
+= sprintf(&elfrec
->buf
[elfrec
->bufoffset
],
1101 " %s", res
->nfslog_READLINK3res_u
.data
);
1106 nfslog_READ3res_print(struct nfsl_log_file
*elfrec
, nfslog_READ3res
*res
,
1107 bool_t print_status
)
1110 nfslog_nfsstat3_print(elfrec
, &res
->status
, print_status
);
1111 } else if (res
->status
== NFS3_OK
) {
1112 char *elfbuf
= elfrec
->buf
;
1113 int elfbufoffset
= elfrec
->bufoffset
;
1115 elfbufoffset
+= sprintf(&elfbuf
[elfbufoffset
], " 0x%llx",
1116 res
->nfslog_READ3res_u
.ok
.filesize
);
1117 elfbufoffset
+= sprintf(&elfbuf
[elfbufoffset
], " 0x%x",
1118 res
->nfslog_READ3res_u
.ok
.count
);
1119 elfbufoffset
+= sprintf(&elfbuf
[elfbufoffset
], " 0x%x",
1120 res
->nfslog_READ3res_u
.ok
.eof
);
1121 elfbufoffset
+= sprintf(&elfbuf
[elfbufoffset
], " 0x%x",
1122 res
->nfslog_READ3res_u
.ok
.size
);
1123 elfrec
->bufoffset
= elfbufoffset
;
1128 nfslog_WRITE3res_print(struct nfsl_log_file
*elfrec
, nfslog_WRITE3res
*res
,
1129 bool_t print_status
)
1132 nfslog_nfsstat3_print(elfrec
, &res
->status
, print_status
);
1133 } else if (res
->status
== NFS3_OK
) {
1134 char *elfbuf
= elfrec
->buf
;
1135 int elfbufoffset
= elfrec
->bufoffset
;
1137 elfbufoffset
+= sprintf(&elfbuf
[elfbufoffset
], " 0x%llx",
1138 res
->nfslog_WRITE3res_u
.ok
.filesize
);
1139 elfbufoffset
+= sprintf(&elfbuf
[elfbufoffset
],
1140 " 0x%x", res
->nfslog_WRITE3res_u
.ok
.count
);
1141 elfbufoffset
+= sprintf(&elfrec
->buf
[elfbufoffset
],
1142 " 0x%x", res
->nfslog_WRITE3res_u
.ok
.committed
);
1143 elfrec
->bufoffset
= elfbufoffset
;
1148 nfslog_CREATE3res_print(struct nfsl_log_file
*elfrec
, nfslog_CREATE3res
*res
,
1149 bool_t print_status
)
1152 nfslog_nfsstat3_print(elfrec
, &res
->status
, print_status
);
1153 } else if (res
->status
== NFS3_OK
) {
1154 if (res
->nfslog_CREATE3res_u
.ok
.obj
.handle_follows
) {
1155 nfslog_fh3_print(elfrec
,
1156 &res
->nfslog_CREATE3res_u
.ok
.obj
.handle
);
1162 nfslog_MKDIR3res_print(struct nfsl_log_file
*elfrec
, nfslog_MKDIR3res
*res
,
1163 bool_t print_status
)
1166 nfslog_nfsstat3_print(elfrec
, &res
->status
, print_status
);
1167 } else if (res
->status
== NFS3_OK
) {
1168 if (res
->nfslog_MKDIR3res_u
.obj
.handle_follows
) {
1169 nfslog_fh3_print(elfrec
,
1170 &res
->nfslog_MKDIR3res_u
.obj
.handle
);
1176 nfslog_SYMLINK3res_print(struct nfsl_log_file
*elfrec
, nfslog_SYMLINK3res
*res
,
1177 bool_t print_status
)
1180 nfslog_nfsstat3_print(elfrec
, &res
->status
, print_status
);
1181 } else if (res
->status
== NFS3_OK
) {
1182 if (res
->nfslog_SYMLINK3res_u
.obj
.handle_follows
) {
1183 nfslog_fh3_print(elfrec
,
1184 &res
->nfslog_SYMLINK3res_u
.obj
.handle
);
1190 nfslog_MKNOD3res_print(struct nfsl_log_file
*elfrec
, nfslog_MKNOD3res
*res
,
1191 bool_t print_status
)
1194 nfslog_nfsstat3_print(elfrec
, &res
->status
, print_status
);
1195 } else if (res
->status
== NFS3_OK
) {
1196 if (res
->nfslog_MKNOD3res_u
.obj
.handle_follows
) {
1197 nfslog_fh3_print(elfrec
,
1198 &res
->nfslog_MKNOD3res_u
.obj
.handle
);
1204 nfslog_READDIRPLUS3res_print(struct nfsl_log_file
*elfrec
,
1205 nfslog_READDIRPLUS3res
*res
, bool_t print_status
)
1208 nfslog_nfsstat3_print(elfrec
, &res
->status
, print_status
);
1213 * **** End of table functions for logging specific procs ****
1215 * Hereafter are the general logging management and dispatcher.
1220 * nfsl_ipaddr_print - extracts sender ip address from transport struct
1221 * and prints it in legible form.
1224 nfsl_ipaddr_print(struct nfsl_log_file
*elfrec
, struct netbuf
*ptr
)
1227 extern char *inet_ntop();
1228 int size
, sin_family
, error
;
1229 char *elfbuf
= elfrec
->buf
;
1231 int elfbufoffset
= elfrec
->bufoffset
;
1233 if (ptr
->len
== 0) {
1234 elfbufoffset
+= sprintf(&elfbuf
[elfbufoffset
], " %s",
1236 elfbufoffset
+= sprintf(&elfbuf
[elfbufoffset
], " %s",
1238 elfrec
->bufoffset
= elfbufoffset
;
1241 elfbufoffset
+= sprintf(&elfbuf
[elfbufoffset
], " ");
1243 sin_family
= ((struct sockaddr_in
*)ptr
->buf
)->sin_family
;
1244 switch (sin_family
) {
1247 addrp
= (char *)&((struct sockaddr_in
*)ptr
->buf
)->sin_addr
;
1248 size
= sizeof (struct in_addr
);
1252 addrp
= (char *)&((struct sockaddr_in6
*)ptr
->buf
)->sin6_addr
;
1253 size
= sizeof (struct in6_addr
);
1256 /* unknown protocol: print address in hex form */
1257 for (size
= ptr
->len
, addrp
= ptr
->buf
; size
> 0; size
--) {
1258 elfbufoffset
+= sprintf(&elfbuf
[elfbufoffset
], "%02x",
1261 elfbufoffset
+= sprintf(&elfbuf
[elfbufoffset
], " %s",
1263 elfrec
->bufoffset
= elfbufoffset
;
1266 if (inet_ntop(sin_family
, addrp
, &elfbuf
[elfbufoffset
],
1267 (size_t)(DFLT_BUFFERSIZE
+ DFLT_OVFSIZE
- elfbufoffset
))
1269 /* Not enough space to print - should never happen */
1270 elfbuf
[elfrec
->bufoffset
] = '\0'; /* just in case */
1273 /* inet_ntop copied address into elfbuf, so update offset */
1274 elfbufoffset
+= strlen(&elfbuf
[elfbufoffset
]);
1275 /* get host name and log it as well */
1276 hp
= getipnodebyaddr(addrp
, size
, sin_family
, &error
);
1278 elfbufoffset
+= sprintf(&elfbuf
[elfbufoffset
], " \"%s\"",
1281 elfbufoffset
+= sprintf(&elfbuf
[elfbufoffset
], " %s",
1284 elfrec
->bufoffset
= elfbufoffset
;
1288 nfsl_elf_record_header_print(struct nfsl_log_file
*elfrec
,
1289 nfslog_record_header
*lhp
, char *principal_name
, char *tag
,
1290 struct nfsl_proc_disp
*disp
, char *progname
)
1292 struct passwd
*pwp
= NULL
;
1293 char *elfbuf
= elfrec
->buf
;
1294 int elfbufoffset
= elfrec
->bufoffset
;
1297 * Fields: time bytes tag rpc-program rpc-version rpc-procedure
1298 * auth-flavor s-user-name s-uid uid u-name gid net-id
1299 * c-ip c-dns s-dns status rpcarg-path <arguments> <response>
1301 elfbufoffset
+= sprintf(&elfbuf
[elfbufoffset
], "%s",
1302 nfsl_get_time((time_t)lhp
->rh_timestamp
.tv_sec
));
1303 elfbufoffset
+= sprintf(&elfbuf
[elfbufoffset
], " 0x%x",
1305 if ((tag
!= NULL
) && (tag
[0] != '\0')) {
1306 elfbufoffset
+= sprintf(&elfbuf
[elfbufoffset
], " \"%s\"", tag
);
1308 elfbufoffset
+= sprintf(&elfbuf
[elfbufoffset
], " %s",
1311 elfbufoffset
+= sprintf(&elfbuf
[elfbufoffset
], " %s 0x%x %s",
1312 progname
, lhp
->rh_version
, disp
->procname
);
1313 elfbufoffset
+= sprintf(&elfbuf
[elfbufoffset
], " %s",
1314 NFSL_AUTH_FLAVOR_PRINT(lhp
->rh_auth_flavor
));
1315 if ((principal_name
!= NULL
) && (principal_name
[0] != '\0')) {
1316 elfbufoffset
+= sprintf(&elfbuf
[elfbufoffset
], " \"%s\"",
1318 if ((pwp
= getpwnam(principal_name
)) != NULL
) {
1319 elfbufoffset
+= sprintf(&elfbuf
[elfbufoffset
],
1320 " 0x%lx", pwp
->pw_uid
);
1322 elfbufoffset
+= sprintf(&elfbuf
[elfbufoffset
],
1326 elfbufoffset
+= sprintf(&elfbuf
[elfbufoffset
], " %s",
1328 elfbufoffset
+= sprintf(&elfbuf
[elfbufoffset
], " %s",
1331 elfbufoffset
+= sprintf(&elfbuf
[elfbufoffset
], " 0x%lx", lhp
->rh_uid
);
1332 if (((pwp
= getpwuid(lhp
->rh_uid
)) != NULL
) && (pwp
->pw_name
!= NULL
)) {
1333 elfbufoffset
+= sprintf(&elfbuf
[elfbufoffset
], " \"%s\"",
1336 elfbufoffset
+= sprintf(&elfbuf
[elfbufoffset
], " %s",
1339 elfbufoffset
+= sprintf(&elfbuf
[elfbufoffset
], " 0x%lx", lhp
->rh_gid
);
1340 elfrec
->bufoffset
= elfbufoffset
;
1344 nfsl_elf_buffer_header_print(struct nfsl_log_file
*elfrec
,
1345 nfslog_buffer_header
*bufhdr
)
1348 struct utsname name
;
1349 char *elfbuf
= elfrec
->buf
;
1350 int elfbufoffset
= elfrec
->bufoffset
;
1353 elfbufoffset
+= sprintf(&elfbuf
[elfbufoffset
],
1354 "#Version %d.0\n#Software \"%s\"\n",
1355 bufhdr
->bh_version
, ((rc
>= 0) ? name
.sysname
: empty_name
));
1356 elfbufoffset
+= sprintf(&elfbuf
[elfbufoffset
], "#Date %s\n",
1357 nfsl_get_date((time_t)bufhdr
->bh_timestamp
.tv_sec
));
1358 elfbufoffset
+= sprintf(&elfbuf
[elfbufoffset
], "#Remark %s\n",
1360 elfbufoffset
+= sprintf(&elfbuf
[elfbufoffset
],
1361 "#Fields: time bytes tag");
1362 elfbufoffset
+= sprintf(&elfbuf
[elfbufoffset
],
1363 " rpc-program rpc-version rpc-procedure");
1364 elfbufoffset
+= sprintf(&elfbuf
[elfbufoffset
],
1365 " auth-flavor s-user-name s-uid uid u-name gid net-id c-ip");
1366 elfbufoffset
+= sprintf(&elfbuf
[elfbufoffset
],
1367 " c-dns s-dns status rpcarg-path");
1368 elfbufoffset
+= sprintf(&elfbuf
[elfbufoffset
],
1369 " rpc-arguments... rpc-response...\n");
1370 elfrec
->bufoffset
= elfbufoffset
;
1374 * nfsl_find_elf_dispatch - get the dispatch struct for this request
1376 static struct nfsl_proc_disp
*
1377 nfsl_find_elf_dispatch(nfslog_request_record
*logrec
, char **prognamep
)
1379 nfslog_record_header
*logrechdr
= &logrec
->re_header
;
1380 struct nfsl_prog_disp
*progtable
; /* prog struct */
1381 struct nfsl_vers_disp
*verstable
; /* version struct */
1384 /* Find prog element - search because can't use prog as array index */
1385 for (i
= 0; (i
< nfsl_elf_dispatch_table_arglen
) &&
1386 (logrechdr
->rh_prognum
!= nfsl_elf_dispatch_table
[i
].nfsl_dis_prog
);
1388 if (i
>= nfsl_elf_dispatch_table_arglen
) { /* program not logged */
1392 progtable
= &nfsl_elf_dispatch_table
[i
];
1393 /* Find vers element - no validity check - if here it's valid vers */
1394 vers
= logrechdr
->rh_version
- progtable
->nfsl_dis_versmin
;
1395 verstable
= &progtable
->nfsl_dis_vers_table
[vers
];
1396 /* Find proc element - no validity check - if here it's valid proc */
1397 *prognamep
= progtable
->progname
;
1398 return (&verstable
->nfsl_dis_proc_table
[logrechdr
->rh_procnum
]);
1402 * nfsl_elf_rpc_print - Print the record buffer.
1405 nfsl_elf_rpc_print(struct nfsl_log_file
*elfrec
,
1406 nfslog_request_record
*logrec
, struct nfsl_proc_disp
*disp
,
1407 char *progname
, char *path1
, char *path2
)
1410 (void) printf("%s %d %s", progname
,
1411 logrec
->re_header
.rh_version
, disp
->procname
);
1412 (void) printf(": '%s', '%s'\n",
1413 ((path1
!= NULL
) ? path1
: empty_name
),
1414 ((path2
!= NULL
) ? path2
: empty_name
));
1417 * XXXX programs using this file to get a usable record should
1418 * take "record" struct.
1421 * Print the variable fields:
1427 * Use the displacements calculated earlier...
1431 * Fields: time bytes tag rpc-program rpc-version rpc-procedure
1432 * auth-flavor s-user-name s-uid uid u-name gid net-id c-ip
1433 * c-dns s-dns status rpcarg-path <arguments> <response>
1435 nfsl_elf_record_header_print(elfrec
, &logrec
->re_header
,
1436 logrec
->re_principal_name
, logrec
->re_tag
,
1438 if ((logrec
->re_netid
!= NULL
) && (logrec
->re_netid
[0] != '\0')) {
1439 elfrec
->bufoffset
+= sprintf(&elfrec
->buf
[elfrec
->bufoffset
],
1440 " \"%s\"", logrec
->re_netid
);
1442 elfrec
->bufoffset
+= sprintf(&elfrec
->buf
[elfrec
->bufoffset
],
1445 nfsl_ipaddr_print(elfrec
, &logrec
->re_ipaddr
);
1446 elfrec
->bufoffset
+= sprintf(&elfrec
->buf
[elfrec
->bufoffset
],
1447 " \"%s\"", hostname
);
1448 /* Next is return status */
1449 (*disp
->nfsl_dis_res
)(elfrec
, logrec
->re_rpc_res
, TRUE
);
1450 /* Next is argpath */
1451 if (path1
!= NULL
) {
1452 elfrec
->bufoffset
+= sprintf(&elfrec
->buf
[elfrec
->bufoffset
],
1455 elfrec
->bufoffset
+= sprintf(&elfrec
->buf
[elfrec
->bufoffset
],
1459 * path2 is non-empty for rename/link type operations. If it is non-
1460 * empty print it here as it's a part of the args
1462 if (path2
!= NULL
) {
1463 elfrec
->bufoffset
+= sprintf(&elfrec
->buf
[elfrec
->bufoffset
],
1466 /* Next print formatted rpc args */
1467 (*disp
->nfsl_dis_args
)(elfrec
, logrec
->re_rpc_arg
);
1468 /* Next print formatted rpc res (minus status) */
1469 (*disp
->nfsl_dis_res
)(elfrec
, logrec
->re_rpc_res
, FALSE
);
1470 elfrec
->bufoffset
+= sprintf(&elfrec
->buf
[elfrec
->bufoffset
], "\n");
1474 * nfsl_log_file_add - add a new record to the list
1477 nfsl_log_file_add(struct nfsl_log_file
*elfrec
,
1478 struct nfsl_log_file
**elf_listp
)
1480 elfrec
->next
= *elf_listp
;
1481 elfrec
->prev
= NULL
;
1482 if (*elf_listp
!= NULL
) {
1483 (*elf_listp
)->prev
= elfrec
;
1485 *elf_listp
= elfrec
;
1489 * nfsl_log_file_find - finds a record in the list, given a cookie (== elfrec)
1490 * Returns the record.
1492 static struct nfsl_log_file
*
1493 nfsl_log_file_find(struct nfsl_log_file
*elfrec
,
1494 struct nfsl_log_file
*elf_list
)
1496 struct nfsl_log_file
*rec
;
1498 for (rec
= elf_list
; (rec
!= NULL
) && (rec
!= elfrec
);
1504 * nfsl_log_file_del - delete a record from the list, does not free rec.
1505 * Returns the deleted record.
1507 static struct nfsl_log_file
*
1508 nfsl_log_file_del(struct nfsl_log_file
*elfrec
,
1509 struct nfsl_log_file
**elf_listp
)
1511 struct nfsl_log_file
*rec
;
1513 if ((rec
= nfsl_log_file_find(elfrec
, *elf_listp
)) == NULL
) {
1516 if (rec
->prev
!= NULL
) {
1517 rec
->prev
->next
= rec
->next
;
1519 *elf_listp
= rec
->next
;
1521 if (rec
->next
!= NULL
) {
1522 rec
->next
->prev
= rec
->prev
;
1528 * nfsl_log_file_free - frees a record
1531 nfsl_log_file_free(struct nfsl_log_file
*elfrec
)
1541 * Exported Functions
1545 * nfslog_open_elf_file - open the output elf file and mallocs needed buffers
1546 * Returns a pointer to the nfsl_log_file on success, NULL on error.
1548 * *error contains the last error encountered on this object, It can
1549 * be used to avoid reporting the same error endlessly, by comparing
1550 * the current error to the last error. It is reset to the current error
1554 nfslog_open_elf_file(char *elfpath
, nfslog_buffer_header
*bufhdr
, int *error
)
1556 struct nfsl_log_file
*elfrec
;
1557 struct stat stat_buf
;
1558 int preverror
= *error
;
1560 if ((elfrec
= malloc(sizeof (*elfrec
))) == NULL
) {
1562 if (*error
!= preverror
) {
1563 syslog(LOG_ERR
, gettext("nfslog_open_elf_file: %s"),
1568 bzero(elfrec
, sizeof (*elfrec
));
1570 elfrec
->buf
= (char *)malloc(DFLT_BUFFERSIZE
+ DFLT_OVFSIZE
);
1571 if (elfrec
->buf
== NULL
) {
1573 if (*error
!= preverror
) {
1574 syslog(LOG_ERR
, gettext("nfslog_open_elf_file: %s"),
1577 nfsl_log_file_free(elfrec
);
1581 if ((elfrec
->path
= strdup(elfpath
)) == NULL
) {
1583 if (*error
!= preverror
) {
1584 syslog(LOG_ERR
, gettext("nfslog_open_elf_file: %s"),
1587 nfsl_log_file_free(elfrec
);
1591 if ((elfrec
->fp
= fopen(elfpath
, "a")) == NULL
) {
1593 if (*error
!= preverror
) {
1594 syslog(LOG_ERR
, gettext("Cannot open '%s': %s"),
1595 elfpath
, strerror(*error
));
1597 nfsl_log_file_free(elfrec
);
1601 if (stat(elfpath
, &stat_buf
) == -1) {
1603 if (*error
!= preverror
) {
1604 syslog(LOG_ERR
, gettext("Cannot stat '%s': %s"),
1605 elfpath
, strerror(*error
));
1607 (void) fclose(elfrec
->fp
);
1608 nfsl_log_file_free(elfrec
);
1612 nfsl_log_file_add(elfrec
, &elf_file_list
);
1614 if (stat_buf
.st_size
== 0) {
1616 * Print header unto logfile
1618 nfsl_elf_buffer_header_print(elfrec
, bufhdr
);
1621 if (hostname
[0] == '\0') {
1622 (void) gethostname(hostname
, MAXHOSTNAMELEN
);
1629 * nfslog_close_elf_file - close elffile and write out last buffer
1632 nfslog_close_elf_file(void **elfcookie
)
1634 struct nfsl_log_file
*elfrec
;
1636 if ((*elfcookie
== NULL
) || ((elfrec
= nfsl_log_file_del(
1637 *elfcookie
, &elf_file_list
)) == NULL
)) {
1641 if (elfrec
->fp
!= NULL
) {
1642 /* Write the last output buffer to disk */
1643 (void) nfsl_write_elfbuf(elfrec
);
1644 (void) fclose(elfrec
->fp
);
1646 nfsl_log_file_free(elfrec
);
1651 * nfslog_process_elf_rec - processes the record in the buffer and outputs
1653 * Return 0 for success, errno else.
1656 nfslog_process_elf_rec(void *elfcookie
, nfslog_request_record
*logrec
,
1657 char *path1
, char *path2
)
1659 struct nfsl_log_file
*elfrec
;
1660 struct nfsl_proc_disp
*disp
;
1663 if ((elfrec
= nfsl_log_file_find(elfcookie
, elf_file_list
)) == NULL
) {
1666 /* Make sure there is room */
1667 if (elfrec
->bufoffset
> DFLT_BUFFERSIZE
) {
1668 if (nfsl_write_elfbuf(elfrec
) < 0) {
1672 if ((disp
= nfsl_find_elf_dispatch(logrec
, &progname
)) != NULL
) {
1673 nfsl_elf_rpc_print(elfrec
, logrec
, disp
, progname
,