audit.sh 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. #!@l_prefix@/lib/openpkg/bash
  2. ##
  3. ## audit -- OpenPKG Tool Chain "audit" command
  4. ## Copyright (c) 2004 The OpenPKG Project <http://www.openpkg.org/>
  5. ## Copyright (c) 2004 Ralf S. Engelschall <rse@engelschall.com>
  6. ## Copyright (c) 2004 Cable & Wireless <http://www.cw.com/>
  7. ##
  8. ## Permission to use, copy, modify, and distribute this software for
  9. ## any purpose with or without fee is hereby granted, provided that
  10. ## the above copyright notice and this permission notice appear in all
  11. ## copies.
  12. ##
  13. ## THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  14. ## WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  15. ## MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  16. ## IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
  17. ## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  18. ## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  19. ## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  20. ## USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  21. ## ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  22. ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  23. ## OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  24. ## SUCH DAMAGE.
  25. ##
  26. # configuration
  27. logfile="@l_prefix@/var/openpkg-audit/openpkg-audit.log"
  28. # command line parsing
  29. opt_m=""
  30. opt_r=no
  31. opt_h=no
  32. opt_l=no
  33. opt_n=0
  34. opt_f=no
  35. OPTIND=1
  36. while getopts m:rln:fh opt; do
  37. case ${opt} in
  38. m ) opt_m=$OPTARG ;;
  39. r ) opt_r=yes ;;
  40. l ) opt_l=yes ;;
  41. n ) opt_n=$OPTARG ;;
  42. f ) opt_f=yes ;;
  43. h ) opt_h=yes ;;
  44. * ) echo "openpkg:audit:ERROR: invalid option \"${opt}\"" 1>&2; exit 1 ;;
  45. esac
  46. done
  47. shift $(($OPTIND - 1))
  48. # dispatch into commands
  49. if [ ".${opt_h}" = .yes ]; then
  50. # show usage message
  51. echo "Usage: openpkg audit [-m <message>] [-r] [-l] [-n <lines>] [-f] [-h]" 1>&2
  52. elif [ ".${opt_l}" = .yes ]; then
  53. # show logfile
  54. if [ ".${opt_f}" = .yes ]; then
  55. tail -f ${logfile}
  56. elif [ ".${opt_n}" != .0 ]; then
  57. tail -n ${opt_n} ${logfile}
  58. else
  59. cat ${logfile}
  60. fi
  61. elif [ ".${opt_m}" != . ]; then
  62. # add manual administrator entry to logfile
  63. if [ ! -w $logfile ]; then
  64. echo "openpkg:audit:ERROR: unsufficient privileges to write to \"$logfile\"" 1>&2
  65. exit 1
  66. fi
  67. # determine date and user
  68. date=`date '+%Y-%m-%d %H:%M:%S'`
  69. user=`@l_prefix@/lib/openpkg/shtool echo -e '%u'`
  70. # create logfile entry
  71. if [ ".${opt_r}" = .yes ]; then
  72. echo "$date user=$user, $opt_m" >>$logfile
  73. else
  74. echo "$date user=$user, message=\"$opt_m\"" >>$logfile
  75. fi
  76. fi
  77. exit 0
  78. ##
  79. ## MANUAL PAGE
  80. ##
  81. =pod
  82. =head1 NAME
  83. B<openpkg audit> - OpenPKG Auditing Facility
  84. =head1 SYNOPSIS
  85. B<openpkg audit> [B<-m> I<message>] [B<-r>]
  86. B<openpkg audit> [B<-l>] [B<-n> I<lines>] [B<-f>]
  87. B<openpkg audit> [B<-h>]
  88. =head1 DESCRIPTION
  89. The B<openpkg audit> command is the frontend to the OpenPKG auditing
  90. logfile which is currently written by the B<openpkg rpm>
  91. command in case the RPM database was changed.
  92. =head1 OPTIONS
  93. The following command line options exist:
  94. =over 4
  95. =item B<-m> I<message>
  96. Adds I<message> to the auditing logfile as a C<message="..."> entry.
  97. =item B<-r>
  98. In conjunction with B<-m>, adds I<message> to the auditing logfile as a
  99. raw message.
  100. =item B<-l>
  101. Shows the auditing logfile.
  102. =item B<-n> I<lines>
  103. In conjunction with B<-l>, shows only the last I<lines> number of lines.
  104. =item B<-f>
  105. In conjunction with B<-l>, follows the logfile.
  106. =item B<-h>
  107. Shows a command usage.
  108. =back
  109. =head1 FILES
  110. The following paths are used by B<openpkg audit>:
  111. =over 4
  112. =item F<@l_prefix@/bin/openpkg>
  113. =item F<@l_prefix@/var/openpkg-audit/openpkg-audit.log>
  114. =back
  115. =head1 SEE ALSO
  116. C<openpkg man rpm>.
  117. =head1 AUTHOR
  118. Ralf S. Engelschall E<lt>rse@openpkg.orgE<gt>
  119. =cut