Commit | Line | Data |
---|---|---|
805e021f CE |
1 | #!/usr/bin/perl |
2 | # | |
3 | # Copyright (c) 2012, Sine Nomine Associates | |
4 | # | |
5 | # Permission to use, copy, modify, and/or distribute this software for any | |
6 | # purpose with or without fee is hereby granted, provided that the above | |
7 | # copyright notice and this permission notice appear in all copies. | |
8 | # | |
9 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
10 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
11 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
12 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
13 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
14 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
15 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
16 | # | |
17 | ||
18 | =head1 NAME | |
19 | ||
20 | readsysvmq - example program to read the sysvmq audit log | |
21 | ||
22 | =head1 SYNOPSIS | |
23 | ||
24 | B<readsysvmq> I<path> | |
25 | ||
26 | =head1 DESCRIPTION | |
27 | ||
28 | This is an example script to read the OpenAFS fileserver System V message queue | |
29 | (sysvmq) based audit log. The OpenAFS fileserver writed to the sysv message | |
30 | queue audit log when it is started with the C<-audit-interface sysvmq> option | |
31 | in conjuntion with the C<-auditlog> option. | |
32 | ||
33 | =head1 OPTIONS | |
34 | ||
35 | =over 8 | |
36 | ||
37 | =item I<path> | |
38 | ||
39 | The path of the sysvmq audit log. This should match the path given in the | |
40 | fileserver C<-auditlog> command line option. | |
41 | ||
42 | =back | |
43 | ||
44 | =head1 SEE ALSO | |
45 | ||
46 | fileserver | |
47 | ||
48 | =head1 COPYRIGHT | |
49 | ||
50 | Copyright (c) 2012, Sine Nomine Associates | |
51 | ||
52 | =cut | |
53 | ||
54 | ||
55 | use strict; | |
56 | use warnings; | |
57 | use IPC::SysV qw(S_IRUSR ftok); | |
58 | ||
59 | if (scalar @ARGV != 1) { | |
60 | print("usage: $0 <auditlog-path>\n"); | |
61 | exit(1); | |
62 | } | |
63 | ||
64 | my $path = $ARGV[0]; | |
65 | ||
66 | my $mqkey = ftok($path, 1); | |
67 | unless (defined $mqkey) { | |
68 | die "$path does not exist\n"; | |
69 | } | |
70 | ||
71 | my $mqid = msgget($mqkey, S_IRUSR); | |
72 | unless (defined $mqid) { | |
73 | die "message queue $mqkey ($path) cannot be opened\n"; | |
74 | } | |
75 | ||
76 | my $msgsize = 2048; | |
77 | my ($msg, $msgtype, $msgtext); | |
78 | while (1) { | |
79 | if (msgrcv($mqid, $msg, $msgsize, 0, 0)) { | |
80 | ($msgtype, $msgtext) = unpack("l! a*", $msg); | |
81 | print $msgtext, "\n"; | |
82 | } | |
83 | } | |
84 |