Code

Include personal title in cn/dn
[gosa.git] / plugins / personal / generic / class_user.inc
index cbc936215356373f2956dc4a33cbd9e06e9b2800..46ecbc77d434db966131cb7fe6910dbc588d2228 100644 (file)
@@ -580,6 +580,41 @@ class user extends plugin
       $og->save ();
     }
 
+    /* Kerberos server defined? */
+    if (isset($this->config->data['SERVERS']['KERBEROS'])){
+      $cfg= $this->config->data['SERVERS']['KERBEROS'];
+    }
+    if (isset($cfg['SERVER']) && function_exists('kadm5_init_with_password')){
+
+      /* Connect to the admin interface */
+      $handle = kadm5_init_with_password($cfg['SERVER'], $cfg['REALM'],
+          $cfg['ADMIN'], $cfg['PASSWORD']);
+
+      /* Errors? */            
+      if ($handle === FALSE){
+        print_red (_("Kerberos database communication failed"));
+        return (2);
+      }
+
+      /* Build user principal, get list of existsing principals */
+      $principal= $this->uid."@".$cfg['REALM'];
+      $principals = kadm5_get_principals($handle);
+
+      /* User exists in database? */
+      if (in_array($principal, $principals)){
+
+        /* Ok. User exists. Remove him/her */
+          $ret= kadm5_delete_principal ( $handle, $principal);
+          if ($ret === FALSE){
+            print_red (_("Can't remove user from kerberos database."));
+          }
+      }
+
+      /* Free kerberos admin handle */
+      kadm5_destroy($handle);
+    }
+
+
     /* Optionally execute a command after we're done */
     $this->handle_post_events("remove",array("uid" => $this->uid));
   }
@@ -647,9 +682,6 @@ class user extends plugin
     /* Only force save of changes .... 
        If this attributes aren't changed, avoid saving.
      */
-    if ($this->use_dob == "1"){
-      $this->dateOfBirth= date("Y-m-d", $this->dateOfBirth);
-    }
     if($this->gender=="0") $this->gender ="";
     if($this->preferredLanguage=="0") $this->preferredLanguage ="";
     
@@ -657,6 +689,12 @@ class user extends plugin
     /* First use parents methods to do some basic fillup in $this->attrs */
     plugin::save ();
 
+    if ($this->use_dob == "1"){
+      /* If it is an array, the generic page has never been loaded - so there's no difference. Using an array would cause an error btw. */
+      if(!is_array($this->attrs['dateOfBirth'])) {
+        $this->attrs['dateOfBirth']= date("Y-m-d", $this->attrs['dateOfBirth']);
+      }
+    }
     /* Remove additional objectClasses */
     $tmp= array();
     foreach ($this->attrs['objectClass'] as $key => $set){
@@ -909,7 +947,7 @@ class user extends plugin
 
         /* Ok. User exists. Remove him/her when pw_storage has
            changed to be NOT kerberos. */
-        if ($this->pw_storage != "kerberos"){
+        if ($this->pw_storage != $this->config->current['KRBSASL']){
           $ret= kadm5_delete_principal ( $handle, $principal);
 
           if ($ret === FALSE){
@@ -919,8 +957,8 @@ class user extends plugin
 
       } else {
 
-        /* User doesn't exists, create it when pw_storage is kerberos. */
-        if ($this->pw_storage == "kerberos"){
+        /* User doesn't exists, create it when pw_storage is kerberos or SASL. */
+        if ($this->pw_storage == "kerberos" || $this->pw_storage == "sasl" ){
           $ret= kadm5_create_principal ( $handle, $principal);
 
           if ($ret === FALSE){
@@ -955,7 +993,12 @@ class user extends plugin
     $message= plugin::check();
 
     /* Assemble cn */
-    $this->cn= $this->givenName." ".$this->sn;
+    if ($this->personalTitle == ""){
+      $pt= "";
+    } else {
+      $pt= $this->personalTitle." ";
+    }
+    $this->cn= $pt.$this->givenName." ".$this->sn;
 
     /* Permissions for that base? */
     if (isset($this->config->current['DNMODE']) && $this->config->current['DNMODE'] == "uid"){
@@ -1301,6 +1344,23 @@ class user extends plugin
       }
     } 
   }
+
+
+  function PrepareForCopyPaste($source)
+  {
+    plugin::PrepareForCopyPaste($source);
+
+    /* Reset certificate information addepted from source user
+        to avoid setting the same user certificate for the destination user. */
+    $this->userPKCS12= "";
+    $this->userSMIMECertificate= "";
+    $this->userCertificate= "";
+    $this->certificateSerialNumber= "";
+    $this->old_certificateSerialNumber= "";
+    $this->old_userPKCS12= "";
+    $this->old_userSMIMECertificate= "";
+    $this->old_userCertificate= "";
+  }
 }
 
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: