/[perl]/osf2pam.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /osf2pam.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (show annotations)
Thu May 8 15:57:02 2003 UTC (20 years, 10 months ago) by dpavlin
Branch: MAIN
CVS Tags: HEAD
File MIME type: text/plain
script for migration of OSF (Digital Unix) passwords (without C2) to pam

1 #!/usr/bin/perl -w
2
3 use strict;
4
5 my %passwd_here;
6 my %passwd_new;
7
8 my $local_users = 0;
9 my $new_users = 0;
10 my $new_aliases = 0;
11
12 open(PI,"/etc/passwd") || die "can't open current passwd: $!";
13 while(<PI>) {
14 chomp;
15 my ($login,$passwd,$uid,$gid,$gecos,$rest) = split(/:/,$_,6);
16 if (defined $passwd_here{$login}) {
17 print "user $login ($gecos) is listed twice in local passwd";
18 } else {
19 $passwd_here{$login}=$gecos;
20 $local_users++;
21 }
22 }
23 close(PI);
24
25 open(PO,"> passwd.new") || die "can't open passwd.new: $!";
26 open(SO,"> shadow.new") || die "can't open shadow.new: $!";
27
28 open(PI,"passwd") || die "can't open input passwd: $!";
29 while(<PI>) {
30 chomp;
31 my ($login,$passwd,$uid,$gid,$gecos,$rest) = split(/:/,$_,6);
32
33 $uid += 10000; # all new uid's will be > 10000
34
35 if ($passwd_here{$login}) {
36 print "user $login ($gecos) allready exists in local passwd, skipping...\n";
37 } else {
38 # create home, imapd need it!
39 my $home = "/var/webmail/home/$login";
40 mkdir $home || die "can't create home dir $home: $!";
41 chmod 0777,$home || die "can't chmod home $home to 777: $!";
42
43 # /bin/true must be in /etc/shells or most services won't work!
44 print PO "$login:x:$uid:100:$gecos:$home:/bin/true\n";
45 print SO "$login:$passwd:12110:0:99999:7:::\n";
46 $passwd_new{$login}=$gecos;
47 $new_users++;
48 }
49 }
50 close(PI);
51 close(PO);
52
53 open(AI,"aliases") || die "can't open aliases: $!";
54 open(AO,"> aliases.new") || die "can't open aliases.new: $!";
55 while(<AI>) {
56 chomp;
57 next if (/^\s*$/ || /^\s*#/);
58 my ($alias,$account) = split(/\s*:\s*/,$_,2);
59 if ($passwd_new{$account}) {
60 print AO "$alias:\t$account\n";
61 $new_aliases++;
62 } else {
63 # this will try to expand users on the right
64 # it might be overkill, but hey! it might help also...
65 if ($account =~ /,/) {
66 my $all_local = 1;
67 foreach my $login (split(/\s*,\s*/,$account)) {
68 $all_local = 0 if (! $passwd_new{$login});
69 }
70 if ($all_local) {
71 print AO "$alias\t$account\n";
72 $new_aliases++;
73 } else {
74 # debug, verbose, remove...
75 #print "skip: $alias -> $account\n";
76 }
77 }
78 }
79 }
80 close(AI);
81 close(AO);
82
83 print "local users: $local_users\n";
84 print "new users: $new_users\n";
85 print "new aliases: $new_aliases\n";

  ViewVC Help
Powered by ViewVC 1.1.26