Now if it wasn't for the second bullet, it would be a simple matter of stripping off the leading \s*PATH=, splitting on colons, and checking to see if any of the items in the resulting list were just a single period.
Here is what I have that I believe is working, but any help/insight would be appreciated:
#!/usr/bin/perl use strict; use warnings; my @logins = qw( .profile .cshrc .login .tcshrc .bash_profile .bash_login ); for my $login (@logins) { next if ! -f $login; open ( LOGIN , '<' , $login ) or die "Unable to open $login for re +ading : $!"; my ($path, $flag); while ( <LOGIN> ) { chomp; if ( /^\s*PATH=(.*)/ || $flag) { $path .= ':' if $path && substr($path, -1, 1) ne ':'; my $new = $flag ? $_ : $1; $path .= $new; if ( substr($path, -1 , 1) eq '\\' ) { $flag = 1; chop $path; next; } else { $flag = 0; } } } next if ! $path; my @paths = split /:/ , $path; if ( grep /^\.$/ , @paths ) { print "$login contains a period in the PATH assignment\n"; } }
Update: I realize that without recompiling the shell, there is no real way to prevent a user from putting '.' in their path. I also realize that checking the path assignment in the login scripts is very rudimentary and can easily be bypassed. This doesn't change the local security policy. This also doesn't change my requirement to make a best effort at policing that policy. I truly appreciate the responses and will make the policy makers aware of the limitations.
In reply to Parsing Login Scripts For Variable Assignment by Limbic~Region
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |