~ubuntu-branches/ubuntu/maverick/openldap/maverick-proposed

« back to all changes in this revision

Viewing changes to debian/ldiftopasswd

  • Committer: Bazaar Package Importer
  • Author(s): Steve Langasek, Russ Allbery, Steve Langasek
  • Date: 2008-10-11 01:53:55 UTC
  • mto: (0.3.1 squeeze)
  • mto: This revision was merged to the branch mainline in revision 11.
  • Revision ID: james.westby@ubuntu.com-20081011015355-5iazff47eui9nypc
Tags: 2.4.11-1
* New upstream version (closes: #499560).
  - Fixes a crash with syncrepl and delcsn (closes: #491066).
  - Fix CRL handling with GnuTLS (closes: #498410).
  - Drop patches no_backend_inter-linking,
    CVE-2008-2952_BER-decoding-assertion, and gnutls-ssf, applied
    upstream.

[ Russ Allbery ]
* New patch, back-perl-init, which updates the calling conventions
  around initialization and shutdown of the Perl interpreter to match
  the current perlembed recommendations.  Fixes probable hangs on HPPA
  in back-perl.  Thanks, Niko Tyni.  (Closes: #495069)

[ Steve Langasek ]
* Drop the conflict with libldap2, which is not the standard means of
  handling symbol conflicts in Debian and which causes serious upgrade
  problems from etch.  Closes: #487211.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl -w
 
2
#
 
3
#
 
4
# Comments on usage from the email we received:
 
5
# I showed a friend the following script. He said I should submit it for
 
6
# inclusion in openldap, because it might useful for others. 
 
7
#
 
8
# The attached perl script, when used like
 
9
#
 
10
# ldapsearch | ldiftopasswd
 
11
#
 
12
# will automatically:
 
13
#
 
14
# 1. create /etc/passwd, /etc/shadow, /etc/group, and /etc/gshadow
 
15
#
 
16
# 2. append /etc/passwd.top, /etc/shadow.top, /etc/group.top, and /etc/gshadow.top to respective files.
 
17
#
 
18
# 3. use data from ldap to create the files (note: gshadow isn't really
 
19
# supported, because I don't use it, nor could I find any
 
20
# documentation. Adding support for other files should be easy).
 
21
#
 
22
# (of course you need access to all fields including the password field
 
23
# for this, so use correct parameters to ldapsearch).
 
24
#
 
25
# This could be useful for instance on laptop computers where you don't
 
26
# want to run a slave slapd server for some reason (perhaps memory
 
27
# constraints).
 
28
# ----------------------------------------
 
29
use strict;
 
30
use Getopt::Long;
 
31
use MIME::Base64;
 
32
use IO::File;
 
33
 
 
34
my $passwdfile="/etc/passwd";
 
35
my $shadowfile="/etc/shadow";
 
36
my $groupfile="/etc/group";
 
37
my $gshadowfile="/etc/gshadow";
 
38
my $help;
 
39
GetOptions (
 
40
                '--passwd=s',\$passwdfile,
 
41
                '--shadow=s',\$shadowfile,
 
42
                '--group=s',\$groupfile,
 
43
                '--gshadow=s',\$gshadowfile,
 
44
                '--help',\$help,
 
45
            ) or die "Bad options\n";
 
46
 
 
47
if ($help or $#ARGV != -1) {
 
48
  print STDERR "usage: $0 [etcfile=filename] [--help]\n";
 
49
  exit 255;
 
50
}
 
51
 
 
52
sub start_file($) {
 
53
  my ($file) = @_;
 
54
  my $outhandle = new IO::File;
 
55
  $outhandle->open(">$file") or die "Cannot open $file for writing";
 
56
 
 
57
  open(TMP,"<$file.top") or die "cannot open $file.top for reading";
 
58
  while (<TMP>) { $outhandle->print($_); }
 
59
  close(TMP) or die "cannot close $file for reading";
 
60
 
 
61
  return($outhandle);
 
62
}
 
63
 
 
64
my $PASSWD  = start_file($passwdfile);
 
65
my $SHADOW  = start_file($shadowfile);
 
66
my $GROUP   = start_file($groupfile);
 
67
my $GSHADOW = start_file($gshadowfile);
 
68
 
 
69
sub dopasswd($) {
 
70
      my ($record) = @_;
 
71
      my $userPassword="*";
 
72
 
 
73
      $PASSWD->print(
 
74
        $record->{"uid"},":",
 
75
        "x",":",
 
76
        $record->{"uidNumber"},":",
 
77
        $record->{"gidNumber"},":",
 
78
        $record->{"gecos"},":",
 
79
        $record->{"homeDirectory"},":",
 
80
        $record->{"loginShell"},"\n");
 
81
 
 
82
      if (defined($record->{"userPassword"}) &&
 
83
          $record->{"userPassword"} =~ /^{(crypt)}(.*)$/)
 
84
        { $userPassword = $2; }
 
85
 
 
86
      $SHADOW->print(
 
87
        $record->{"uid"},":",
 
88
        $userPassword,":",
 
89
        $record->{"shadowLastChange"} || "10706",":",
 
90
        $record->{"shadowMin"} || "0",":",
 
91
        $record->{"shadowMax"} || "99999",":",
 
92
        $record->{"shadowWarning"} || "7",":",
 
93
        $record->{"shadowInactive"} || "",":",
 
94
        $record->{"shadowExpire"} || "",":",
 
95
        "","\n");
 
96
}
 
97
 
 
98
sub dogroup($) {
 
99
      my ($record) = @_;
 
100
      my $userPassword="*";
 
101
 
 
102
      my $members="";
 
103
      if (defined($record->{"memberUid"})) {
 
104
        $members = join(",",@{$record->{"memberUid"}});
 
105
      }
 
106
 
 
107
      $GROUP->print(
 
108
        $record->{"cn"},":",
 
109
        "x",":",
 
110
        $record->{"gidNumber"},":",
 
111
        $members,"\n");
 
112
 
 
113
      if (defined($record->{"userPassword"}) &&
 
114
          $record->{"userPassword"} =~ /^{(crypt)}(.*)$/)
 
115
        { $userPassword = $2; }
 
116
 
 
117
# !FIXME!
 
118
#      $GSHADOW->print
 
119
#       $record->{"cn"},":",
 
120
#       "*",":",
 
121
#       "",":",
 
122
#       "","\n";
 
123
}
 
124
 
 
125
 
 
126
my %record;
 
127
my $user=0;
 
128
my $group=0;
 
129
 
 
130
while (<>) {
 
131
  if (/^$/) {
 
132
    if ($user) {
 
133
      dopasswd(\%record);
 
134
    }
 
135
    if ($group) {
 
136
      dogroup(\%record);
 
137
    }
 
138
 
 
139
    $user = $group = 0;
 
140
    %record=();
 
141
  }
 
142
  elsif (/^objectClass: posixAccount$/) {
 
143
    $user = 1;
 
144
  }
 
145
  elsif (/^objectClass: posixGroup$/) {
 
146
    $group = 1;
 
147
  }
 
148
  elsif (/^(uid|uidNumber|gidNumber|gecos|homeDirectory|loginShell): (.*)$/) {
 
149
    if (!defined($record{$1})) { $record{$1} = $2; }
 
150
  }
 
151
  elsif (/^(userPassword|shadowLastChange|shadowMin|shadowMax|shadowWarning|shadowInactive|shadowExpire): (.*)$/) {
 
152
    if (!defined($record{$1})) { $record{$1} = $2; }
 
153
  }
 
154
  elsif (/^(cn): (.*)$/) {
 
155
    if (!defined($record{$1})) { $record{$1} = $2; }
 
156
  }
 
157
  elsif (/^(uniqueMember): (.*)$/) {
 
158
    push @{$record{$1}},$2;
 
159
    if ($2 =~ /uid=([a-zA-Z]*),/) {
 
160
            push @{$record{"memberUid"}},$1;
 
161
    }
 
162
  }
 
163
  elsif (/^(memberUid): (.*)$/) {
 
164
    push @{$record{$1}},$2;
 
165
  }
 
166
  elsif (/^(userPassword):: (.*)$/) {
 
167
    $record{$1} = decode_base64($2);
 
168
  }
 
169
}
 
170
 
 
171
$PASSWD->close  or die "Cannot close $passwdfile for writing";
 
172
$SHADOW->close  or die "Cannot close $shadowfile for writing";
 
173
$GROUP->close   or die "Cannot close $groupfile for writing";
 
174
$GSHADOW->close or die "Cannot close $gshadowfile for writing";