#!/usr/bin/perl
# this script parses each file in the /etc/pam.d directory,
# adds the 'likeauth' option to the pam_unix.so entry,
# and adds the pam_wss.so module after that line.
$pamdir = "/etc/pam.d";
$auth_mod = "pam_unix.so";
$wss_path = "";
@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" ) {
			chop $line;
			print output $line;
			if (!($line =~ "likeauth")) {
				print output " likeauth";
			}
			print output "\nauth       required\t" . $wss_path . "pam_wss.so\n";
		} else {
			print output $line;
		}
	}
	# we are done!
	close(input);
	close(output);
	rename "$pamdir/$file.wss", "$pamdir/$file";
}
return 0;
