using /etc/passwd, /etc/mailname for users

From: Mark W. Eichin <eichin@thok.org>
Date: Mon Oct 29 2001 - 09:39:30 GMT

package: cvs2cl
Version: 2.38-1
priority: wishlist

Simple but debian-specific enhancement - upstream might try and be
more portable by making the /etc/mailname lookup something that an
argument can set, but it is actually right for debian in the simple
case (and in the complex case, well, you've already got -U.) Adds
this as --passwd option. Could also be extended to do NIS (via
ypmatch) or LDAP (ldapsearch), though using nss instead would be
better; could at least use some CPAN package for passwd access, even
the getpwnam/getpwent builtin would do. Mostly this is a 3 minute
hack that was useful for me, but that's more expressive than just
asking :-)
                        _Mark_ <eichin@thok.org>
                        The Herd of Kittens
                        Debian Package Maintainer

--- /usr/bin/cvs2cl Fri Feb 16 23:42:59 2001
+++ ../cvs2cl Mon Oct 29 04:33:01 2001
@@ -104,6 +104,7 @@ my $Cumulative = 0;
 
 # Expand usernames to email addresses based on a map file?
 my $User_Map_File = "";
+my $User_Passwd_File = undef;
 
 # Output to a file or to stdout?
 my $Output_To_Stdout = 0;
@@ -1488,6 +1489,28 @@ sub maybe_read_user_map_file ()
     close (MAPFILE);
   }
 
+ if (defined $User_Passwd_File)
+ {
+ open (MAILNAME, "</etc/mailname")
+ or die ("Unable to fetch local domain (mailname) to go with passwd file usernames ($!)");
+ my ($mailname) = <MAILNAME>;
+ chomp $mailname;
+ close (MAILNAME);
+
+ open (MAPFILE, "<$User_Passwd_File")
+ or die ("Unable to open $User_Passwd_File ($!)");
+ while (<MAPFILE>)
+ {
+ # all lines are valid
+ my ($username, $pw, $uid, $gid, $gecos, $homedir, $shell) = split ':';
+ my ($expansion) = split ',', $gecos;
+
+ $expansions{$username} = "$expansion <$username\@$mailname>";
+ }
+ close (MAPFILE);
+ }
+
+
   return %expansions;
 }
 
@@ -1535,6 +1558,9 @@ sub parse_options ()
       my $narg = shift (@ARGV) || die "$arg needs argument.\n";
       $User_Map_File = $narg;
     }
+ elsif ($arg =~ /^--passwd$/) {
+ $User_Passwd_File = "/etc/passwd";
+ }
     elsif ($arg =~ /^-W$|^--window$/) {
       my $narg = shift (@ARGV) || die "$arg needs argument.\n";
       $Max_Checkin_Duration = $narg;
@@ -1737,6 +1763,7 @@ Options/Arguments:
   --fsf Use this if log data is in FSF ChangeLog style
   -W SECS, --window SECS Window of time within which log entries unify
   -U UFILE, --usermap UFILE Expand usernames to email addresses from UFILE
+ --passwd Use system passwd file for user name expansion
   -R REGEXP, --regexp REGEXP Include only entries that match REGEXP
   -I REGEXP, --ignore REGEXP Ignore files whose names match REGEXP
   -C, --case-insensitive Any regexp matching is done case-insensitively
Received on Mon Oct 29 03:39:31 2001

This archive was generated by hypermail 2.1.8 : Wed Jan 21 2004 - 16:25:34 GMT