steffen: server/kolabd/kolabd kolabpasswd,1.2,1.3

cvs at intevation.de cvs at intevation.de
Tue Dec 14 21:47:21 CET 2004


Author: steffen

Update of /kolabrepository/server/kolabd/kolabd
In directory doto:/tmp/cvs-serv13851

Modified Files:
	kolabpasswd 
Log Message:
add ability to change nobody and calendar passwords

Index: kolabpasswd
===================================================================
RCS file: /kolabrepository/server/kolabd/kolabd/kolabpasswd,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- kolabpasswd	13 Dec 2004 14:49:23 -0000	1.2
+++ kolabpasswd	14 Dec 2004 20:47:19 -0000	1.3
@@ -50,10 +50,20 @@
 my %config = readConfig($kolabconfname);
 my $kolabconf = IO::File->new($kolab_prefix.'/etc/kolab/kolab.conf','r')
                 || die "kolabpasswd: Fatal Error: could not open kolab config at $kolabconfname";
+
+my $account = 'manager';
+my $account_dn = $config{'bind_dn'};
+if( $#ARGV == 0 ) {
+    $account = $ARGV[0];
+    if( $account ne 'calendar' and $account ne 'nobody' and $account ne 'manager' ) {
+	die("$^X can only change the passwod for manager, nobody and calendar");
+    }
+    $account_dn =~ s/cn=manager/cn=$account/;
+}
       
-print "Changing password for manager";
+print "Changing password for $account";
 
-# open ldap connection and verify old manager password
+# open ldap connection and verify old password
 my $ldap = Net::LDAP->new( $config{'ldap_uri'})
          || die "\nkolabpasswd: Fatal Error: could not connect to LDAP Server";
 
@@ -62,12 +72,12 @@
   ReadMode 'noecho';
   my $old_password = ReadLine 0; chomp $old_password;
 
-  $mesg = $ldap->bind( $config{'bind_dn'}, password => $old_password ) || die "\nkolabpasswd: Failed to bind to LDAP server";
-
-} while ( $mesg->code ); 
+  $mesg = $ldap->bind( $account_dn, password => $old_password ) || die "\nkolabpasswd: Failed to bind to LDAP server";
+  if( $mesg->code ) { print "\nError: ".$mesg->error.". Please try again\n"; }
+} while ( $mesg->code );
    
-# read in new manager password
-print "\nNew Password: ";
+# read in new password
+print "\nNew Password for $account: ";
 ReadMode 'noecho';
 my $new_password = ReadLine 0; chomp $new_password;
 
@@ -84,16 +94,30 @@
 
 # copy and replace old config to temporary file
 foreach ($kolabconf->getlines()) {
-  if (/^(bind_pw\s:\s).*$/) {
-    print $tmp $1.$new_password."\n";
-  } else {
-    if (/^(bind_pw_hash\s:\s).*$/) {
-      my $bind_pw_hash = hashPassword($new_password);
-      print $tmp $1.$bind_pw_hash."\n"; 
-    } else {
-      print $tmp $_;  
+    if( $account eq 'manager' ) {
+	if (/^(bind_pw\s:\s).*$/) {
+	    print $tmp $1.$new_password."\n";
+	} else {
+	    if (/^(bind_pw_hash\s:\s).*$/) {
+		my $bind_pw_hash = hashPassword($new_password);
+		print $tmp $1.$bind_pw_hash."\n"; 
+	    } else {
+		print $tmp $_;
+	    }
+	}
+    } elsif( $account eq 'calendar' ) {
+	if (/^(calendar_pw\s:\s).*$/) {
+	    print $tmp $1.$new_password."\n";
+	} else {
+	    print $tmp $_;
+	}
+    } elsif( $account eq 'nobody' ) {
+	if (/^(php_pw\s:\s).*$/) {
+	    print $tmp $1.$new_password."\n";
+	} else {
+	    print $tmp $_;  
+	}
     }
-  }  
 }
 undef $tmp;
 undef $kolabconf;
@@ -103,7 +127,7 @@
    || die "Error: could not connect LDAP Server";
 $ldap->bind( $config{'bind_dn'}, password => $config{'bind_pw'} )
    || die "Error: Failed to bind as manager to LDAP Server";
-$ldap->modify($config{'bind_dn'}, replace => {'userPassword' => $new_password } )
+$ldap->modify($account_dn, replace => {'userPassword' => $new_password } )
    || die "Error: could not update LDAP with new manager password";
 $ldap->unbind;
 undef $ldap;





More information about the commits mailing list