SUID check
n00dles
created: 2006-08-04 10:30:29
Hello all, Once again im alittle stuck and my ideas seem to surpass my ability. I'm trying to compare two files that store info on my SUID files for changes and print the details to a web page, im happy with it for the most part, I understand why the output is not produced but have no idea what so ever how to remede the situation.
    #!/usr/bin/perl -w
    
    use strict;
    
    my $setuidtoday = "/var/log/setuid.today";
    my $setuidyest = "/var/log/setuid.yesterday";
    my $DIFF = "/usr/bin/diff";
    
    print "Content-type: text/html\n\n";
    print "SET SUID FILE CHECK\n";
    print "SET SUID FILE CHECK\n";
    
    if(-e $setuidtoday && $setuidyest) {
            print "
    Setuid lists exist!
    \n"; print `$DIFF $setuidtoday $setuidyest`; } print "";
I believe its this line
print `$DIFF $setuidtoday $setuidyest`;
It works fine at the CLI but the output from diff is not displayed in the webpage, I can see why that is but dont know how to fix the issue... Also if anyone has any improvements please say. The reason I have not used any modules for HTML prasing etc... is because I haven't got that far in my study and i'd like to see what I can code with base perl before I branch out.

Re: SUID check
created: 2006-08-04 10:37:12

You say you know why, but don't elaborate. So, I suppose my first question is - why do you think it doesn't display in the webpage?

Without that information, my first guess is that diff isn't outputting HTML, so some of it may get lost by the webclient - but the data is still there. So I'd suggest something like:

  print "
", `$DIFF ...`, "
";
The diff output is pre-formatted anyway. If you want to spice this up, you'll have to parse the output and deal with that yourself - but that's stage 4 or 5 of this process, I bet ;-)

Minor nit: I think you mean if(-e $setuidtoday && -e $setuidyest). The -e operator doesn't go across the && the way you seem to think it does. Since $setuidyest is always true, the way you have it, that's a no-op. You probably want to test its existance.

Re: SUID check
created: 2006-08-04 12:23:50
It works fine at the CLI but the output from diff is not displayed in the webpage, I can see why that is but dont know how to fix the issue... Also if anyone has any improvements please say. The reason I have not used any modules for HTML prasing etc... is because I haven't got that far in my study and i'd like to see what I can code with base perl before I branch out.

If you don't use the modules for anything else -- use them for escaping the output from your diff command. Diff lines start with '<' and '>', which are special in HTML (as is '&') You need to encode them as : &lt; &gt; and &amp;

Your other option is to serve the page as text/plain as opposed to text/html

Re^2: SUID check
created: 2006-08-04 18:33:01
Another option might be to do a diff -u and wrap that in pre tags (though there may still be characters that need to be escaped). It might be a quick fix.
Re: SUID check
created: 2006-08-04 18:00:34
I tryed using PRE tags etc.. and the CODE tags are there to solve the < > issues. But still no output. Is there a way I can store the output in a variable? or redirect STDOUT?

Re^2: SUID check
created: 2006-08-04 18:39:33
my $out = `$DIFF $setuidtoday $setuidyest`;
print $out;
You might want to try:
use Data::Dumper;
my $out = `$DIFF $setuidtoday $setuidyest`;
print '
', Data::Dumper->Dump([$out],['out']), '
';
Re: SUID check
created: 2006-08-04 18:49:49
Could you be over thinking this? If the two files are identical then you would get no output, right? Could that be the case?
Re: SUID check
created: 2006-08-04 19:14:23
Code:
    #!/usr/bin/perl -w         
    use strict;
    
    my $setuidtoday = "/var/log/setuid.today";
    my $setuidyest = "/var/log/setuid.yesterday";
    my $DIFF = "/usr/bin/diff -u";
    my $out = `$DIFF $setuidtoday $setuidyest`;
    
    print "Content-type: text/html\n\n";
    print "SET SUID FILE CHECK\n";
    print "\n";
    print "

    SET SUID FILE CHECK

    \n"; if(-e $setuidtoday && -e $setuidyest) { print "
    Setuid lists exist!
    \n"; print "
    \n"; print "$out\n"; } #print `$DIFF $setuidtoday $setuidyest`; print "";
CLI output:
    Content-type: text/html
    
    SET SUID FILE CHECK
    
    

    SET SUID FILE CHECK

    Setuid lists exist!

    --- /var/log/setuid.today Wed Jul 12 03:03:52 2006 +++ /var/log/setuid.yesterday Fri Jun 30 03:03:13 2006 @@ -3,11 +3,11 @@ 31837 -r-sr-xr-x 1 root wheel 21792 Nov 3 08:10:37 2005 /sbin/ping 31838 -r-sr-xr-x 1 root wheel 28660 Nov 3 08:10:37 2005 /sbin/ping6 31850 -r-sr-x--- 1 root operator 10148 Nov 3 08:10:38 2005 /sbin/shutdown -1040389 -rws--x--x 1 root wheel 3348 Oct 12 20:39:40 2005 /usr/X11R6/bin/Eterm +1040389 -rws--x--x 1 root wheel 3348 Oct 12 20:39:40 2005 /usr/X11R6/bin/Eterm 1040154 -rws--x--x 1 root wheel 1664917 Oct 12 17:23:09 2005 /usr/X11R6/bin/Xorg -1040397 -rws--x--x 1 root wheel 94008 Oct 12 15:44:09 2005 /usr/X11R6/bin/aterm
WWW output:
    SET SUID FILE CHECK
    
    

    SET SUID FILE CHECK

    Setuid lists exist!

I really dont get this. file permissions are correct too.

perlmonks.org content © perlmonks.org and Argel, jhourcle, n00dles, Tanktalus

prlmnks.org © 2006 edmund von der burg (eccles & toad)

v 0.03