home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / c / cops_104.zip / cops_104 / docs / readme.filter < prev    next >
Text File  |  1992-03-10  |  5KB  |  127 lines

  1.  
  2. A quick primer on "cops_filter"
  3.  
  4.   "cops_filter" is a mechanism for eliminating warning messages in
  5. the final COPS report that you deem spurious.  It's a simple awk
  6. program that looks at a list of regular expressions and prunes
  7. out any that match.  As simple as it is, however, it is an extremely
  8. dangerous program -- a slip of the ol' regular expression and bam --
  9. you don't get notified that /etc/passwd is world writable, or something
  10. like that.  Hence this file, in hopes to enlighten the masses (yeah,
  11. right, like I can do that... anyway, on to business.)
  12.  
  13.   Awk uses regular expressions to search for things, which means you
  14. can use wildcards or even a part of a line to nuke a warning.  For
  15. instance -- let's say on a particular host you have NIS explicitly
  16. included in your password file (e.g. no "+" there), but you are a
  17. member of a NIS domain that does have NIS password maps.  Since COPS
  18. isn't smart enough right now to figure out that you might not care
  19. about the NIS password maps on your machine (and I'm not sure that
  20. it would be a good idea to ignore this anyway), it checks everything...
  21. you might get a warning like:
  22.  
  23. Warning!  YPassword file, line 9, no password:
  24.     ypg::2200:10:YP guest acct:/tmp:/bin/rsh
  25.  
  26.   There are several things you can do to eliminate this message.
  27. If you're familiar with awk, there are some example lines in
  28. "cops_filter"; you can just change those to do what you want.  If
  29. you're not an awk hacker, run out and by the book by aho, kernighan,
  30. and weinberger, and learn awk.  Well, no, you don't have to -- it's
  31. very easy to do simple things.
  32.  
  33.  
  34.  
  35. IMPORTANT!  All filter lines in "cops_filter" will *ONLY* match the
  36. first line of this multi-line warning message (at least, and do the
  37. right thing.)  Do not try to filter out the second line -- it won't
  38. work.
  39.  
  40.  
  41.  
  42. (No new information below to awk/shell people that you couldn't get
  43. by just glancing at the filter file -- you can go play with "cops_filter"
  44. now if you wish.)
  45.  
  46.   The simplest thing to do is to add a line (actually 4 lines, as you'll
  47. see below -- but the most important one is the first line) that exactly
  48. matches what you want to get rid of; e.g., for the above example,
  49. you could put something like:
  50.  
  51. if ($0 ~ /Warning!  YPassword file, line 9, no password:/) {
  52.     skip_next = 1
  53.     next
  54.     }
  55.  
  56.   An explanation.  In awk, every line of code in the awk program
  57. will act on every line in the input file.  In most programming languages
  58. you need to put a loop around the program, but in awk, it is implied.
  59. The $0 here refers to the current input line that the awk program
  60. is looking at.  This line says that if the current input line is
  61. equal to "Warning!  YPassword file, line 9, no password:", then
  62. you should do what it says between the two curly braces.  In this case,
  63. you just set a variable (don't worry about exactly what it does right
  64. now), and then skip to the next line of input from the COPS report file.
  65. That's all there is to it.  Notice that at the bottom half of the awk
  66. program, there are places where information gets printed out -- all
  67. those mean is that unless awk sees a pattern that it matches and gets
  68. told to go to the next line, it will print out the current line.
  69.  
  70.   Well, this is probably as clear as mud, but the basic idea is
  71. that you'll be putting a regular expression inbetween two forward
  72. slanting lines ("/"), and if awk matches that, then it will not
  73. print that out in the final COPS report file.
  74.  
  75.   If you don't want to use an exactly matching line, either because
  76. you're a poor typist or lazy or perhaps you have a group of warnings,
  77. all alike, and you'd like to get rid of them, then you can use
  78. wildcards, or even a part of the line(s) in question -- be careful with
  79. this, and make sure you test your awk program out before inflicting it
  80. for real on your cops reports.
  81.  
  82.   For instance, to match the above example, you could say:
  83.  
  84.     if ($0 ~ /Warning!  YPassword file, line 9, no password:/)
  85.  
  86. or:
  87.  
  88.     if ($0 ~ /YPassword file, line 9, no password/)
  89.  
  90. or, if you really don't want to see any YP/NIS messages, you could use:
  91.  
  92.     if ($0 ~ /YPassword file/)
  93.  
  94. alternately, an example with wildcards:
  95.  
  96.     if ($0 ~ /YP.* no password/)
  97.  
  98.   All of these would match the example line.  However, the bottom two
  99. would match other lines as well -- something like:
  100.  
  101. Warning!  YPassword file, line 12, invalid login directory:
  102.  
  103.   Would also be eliminated from the result file.  Be careful especially
  104. when you're dealing with anything that is in the report file that looks
  105. like a regular expression -- characters like "*", "+", and "?", as
  106. well as the forward slash "/" (to keep it separate from the awk
  107. regular expression separator character) should be preceded with a
  108. backslash -- e.g. something like:
  109.  
  110.     if ($0 ~ /\/usr\/spool\/mail is _World_ writable!/)
  111.  
  112.   Check your awk program as described before, and compare the output
  113. with the old report file with diff -- does it do what you thought?
  114. Be careful.
  115.  
  116.  
  117.  
  118.   Almost the last Important note -- you can test your filter by saying
  119. something like:
  120.  
  121. awk -f cops_filter cops_result_file
  122.  
  123.   Where cops_result_file is usually named something like "1992_Dec_31".
  124. Well, that's about it -- good luck!
  125.  
  126.  -- dan
  127.