#!/usr/bin/perl
# this script parses each file in the pam.d directory,
# adds the 'likeauth' option to the pam_pwdb.so entry,
# and adds the pam_wss.so module after that line.
$pamdir = "/etc/pam.d"; 
$auth_mod = "pam_unix.so";
@filelist = `ls -1 $pamdir`;
foreach $file (@filelist) {
	chop $file;
	open(input, "$pamdir/$file");
	open(output, ">$pamdir/$file.wss");
	# here's where all the dirty business occurs...
	while ($line = <input>) {
		if ($line =~ "auth       required" && $line =~ "$auth_mod") {
			if ($line =~ " likeauth") {
				$line =~ s/ likeauth//;
			}
			print output $line;
			$line = <input>; # skip next line
		} else {
			print output $line;
		}
	}
	# we are done!
	close(input);
	close(output);
	rename "$pamdir/$file.wss", "$pamdir/$file";
}
return 0;
