Import Upstream version 1.8.5
[hcoop/debian/openafs.git] / src / tools / audit / readsysvmq
CommitLineData
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
20readsysvmq - example program to read the sysvmq audit log
21
22=head1 SYNOPSIS
23
24B<readsysvmq> I<path>
25
26=head1 DESCRIPTION
27
28This 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
30queue audit log when it is started with the C<-audit-interface sysvmq> option
31in conjuntion with the C<-auditlog> option.
32
33=head1 OPTIONS
34
35=over 8
36
37=item I<path>
38
39The path of the sysvmq audit log. This should match the path given in the
40fileserver C<-auditlog> command line option.
41
42=back
43
44=head1 SEE ALSO
45
46fileserver
47
48=head1 COPYRIGHT
49
50Copyright (c) 2012, Sine Nomine Associates
51
52=cut
53
54
55use strict;
56use warnings;
57use IPC::SysV qw(S_IRUSR ftok);
58
59if (scalar @ARGV != 1) {
60 print("usage: $0 <auditlog-path>\n");
61 exit(1);
62}
63
64my $path = $ARGV[0];
65
66my $mqkey = ftok($path, 1);
67unless (defined $mqkey) {
68 die "$path does not exist\n";
69}
70
71my $mqid = msgget($mqkey, S_IRUSR);
72unless (defined $mqid) {
73 die "message queue $mqkey ($path) cannot be opened\n";
74}
75
76my $msgsize = 2048;
77my ($msg, $msgtype, $msgtext);
78while (1) {
79 if (msgrcv($mqid, $msg, $msgsize, 0, 0)) {
80 ($msgtype, $msgtext) = unpack("l! a*", $msg);
81 print $msgtext, "\n";
82 }
83}
84