File: pw2userdb

package info (click to toggle)
maildrop 0.75-2.1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 2,760 kB
  • ctags: 1,588
  • sloc: cpp: 9,269; ansic: 6,018; perl: 786; sh: 467; makefile: 398
file content (40 lines) | stat: -rw-r--r-- 862 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#! /usr/bin/perl5
#
#  Convert /etc/passwd and /etc/shadow to userdb format.
#
#  $Id: pw2userdb.in,v 1.1 1999/08/16 16:33:51 mrsam Exp $

open(PASSWD, "/etc/passwd") || die "$!\n";

while (<PASSWD>)
{
	chop if /\n$/;
	($acct,$passwd,$uid,$gid,$name,$home,$shell)=split( /:/ );

	$PASSWORD{$acct}=$passwd if $passwd ne "x";
	$UID{$acct}=$uid;
	$GID{$acct}=$gid;
	$HOME{$acct}=$home;
	$SHELL{$acct}=$shell;
}
close (PASSWD);

if ( -f "/etc/shadow" )
{
	open (SHADOW, "/etc/shadow") || die "$!\n";
	while (<SHADOW>)
	{
		($acct,$passwd,$dummy)=split(/:/);
		$PASSWORD{$acct}=$passwd;
	}
	close (SHADOW);
}

while ( defined ($key=each %UID))
{
	print "$key\tuid=$UID{$key}|gid=$GID{$key}|home=$HOME{$key}" .
		( $SHELL{$key} =~ /./ ? "|shell=$SHELL{$key}":"") .
		( $PASSWORD{$key} =~ /./ ? "|systempw=$PASSWORD{$key}":"") .
		"\n";
	print "$UID{$key}=\t$key\n";
}