Ignore:
Timestamp:
02/21/06 23:52:15 (7 years ago)
Author:
anarcat
Message:

[project @ alternc: changeset 2004-05-19 14:23:06 by benjamin]
Inclusion du patch de securite 01/05/2004.

Original author: benjamin
Date: 2004-05-19 14:23:06

File:
1 edited

Legend:

Unmodified
Added
Removed
  • bureau/class/m_mail.php

    r174 r222  
    11<?php 
    22/* 
    3  $Id: m_mail.php,v 1.9 2004/02/17 15:38:26 remi Exp $ 
     3 $Id: m_mail.php,v 1.10 2004/05/19 14:23:06 benjamin Exp $ 
    44 ---------------------------------------------------------------------- 
    55 LICENSE 
     
    3333class m_mail { 
    3434 
    35   /** Membre dont on gère les mails */ 
    36   var $uid=0; 
    37  
    38   var $alternc_quota_name="mail"; 
    39  
    4035  /** Connexion ldap 
    4136   * @access private 
     
    5853   * Constructeur 
    5954   */ 
    60   function m_mail($membre=0) { 
     55  function m_mail() { 
    6156    global $L_LDAP_HOST,$L_LDAP_ROOT,$L_LDAP_ROOTPWD,$L_LDAP_POSTFIX; 
    62     $this->uid=$membre; 
    6357    $this->ldap=array( 
    6458                      "server"  =>      $L_LDAP_HOST, 
     
    7064 
    7165  /* ----------------------------------------------------------------- */ 
     66  /** 
     67   * Liste des quotas 
     68   */ 
     69  function alternc_quota_names() { 
     70    return "mail"; 
     71  } 
     72 
     73  /* ----------------------------------------------------------------- */ 
    7274  /** Retourne la liste des domaines hébergés en mails sur le compte. 
    7375   * @return array Tableau indexé des domaines hébergés en mail. 
    7476   */ 
    7577  function enum_domains() { 
    76     global $db,$err; 
     78    global $db,$err,$cuid; 
    7779    $err->log("mail","enum_domains"); 
    7880    if (!is_array($this->domains)) { 
    79       $db->query("select * from domaines where compte=".$this->uid." AND gesmx=1;"); 
     81      $db->query("select * from domaines where compte='$cuid' AND gesmx=1;"); 
    8082      $this->domains=array(); 
    8183      if ($db->num_rows()>0) { 
     
    100102   */ 
    101103  function enum_doms_mails($dom,$sort=0) { 
    102     global $err; 
     104    global $err,$cuid; 
    103105    $err->log("mail","enum_doms_mails",$dom); 
    104106    if (!$this->_connectldap()) { 
     
    106108      return false; 
    107109    } 
    108     $sr=ldap_search($this->ds,"dc=domains,".$this->ldap["basedn"],"(&(uid=".$this->uid.")(type=mail)(mail=*@".$dom."))",array("mail","pop")); 
     110    $sr=ldap_search($this->ds,"dc=domains,".$this->ldap["basedn"],"(&(uid=$cuid)(type=mail)(mail=*@".$dom."))",array("mail","pop")); 
    109111    $info = ldap_get_entries($this->ds, $sr); 
    110112    if ($info["count"]==0) { 
     
    115117    for($i=0;$i<$info["count"];$i++) { 
    116118      if ($info[$i]["pop"][0]) { 
     119        /* 
    117120        $size=exec("/usr/lib/alternc/du.pl /var/alternc/mail/".substr($info[$i]["mail"][0],0,1)."/".str_replace("@","_",$info[$i]["mail"][0])); 
    118121        $size=$size*1024; 
     122        */ 
     123        $size=0; 
    119124      } else { 
    120125        $size=0; 
     
    218223   */ 
    219224  function add_wrapper($login,$domain,$command,$type) { 
    220     global $err; 
     225    global $err,$cuid; 
    221226    if (!$this->_connectldap()) { 
    222227      $err->raise("mail",1); 
     
    227232      return false; 
    228233    } 
    229     $res=array("mail" => $login."@".$domain, "uid" => $this->uid, "type" => $type, "objectclass" => "mail", "pop" => "0", "account"=>$login."_".$domain ); 
     234    $res=array("mail" => $login."@".$domain, "uid" => $cuid, "type" => $type, "objectclass" => "mail", "pop" => "0", "account"=>$login."_".$domain ); 
    230235    if (!ldap_add($this->ds,"mail=".$res["mail"].",dc=domains,".$this->ldap["basedn"],$res)) { 
    231236      $err->raise("mail",5,ldap_error($this->ds)); 
     
    304309   */ 
    305310  function put_mail_details($mail,$pop,$pass,$alias) { 
    306     global $err; 
     311    global $err,$cuid; 
    307312    $err->log("mail","put_mail_details",$mail); 
    308313    $account=array(); 
     
    355360    } 
    356361    if ($pop) $pop="1"; else $pop="0"; 
    357     $res=array("mail" => $mail."@".$dom, "uid" => $this->uid, "type" => "mail", "objectclass" => "mail", "pop"=> $pop); 
     362    $res=array("mail" => $mail."@".$dom, "uid" => $cuid, "type" => "mail", "objectclass" => "mail", "pop"=> $pop); 
    358363    $res["account"]=$account; 
    359364    //modification du mail dans ldap-domains 
     
    389394   */ 
    390395  function add_mail($dom,$mail,$pop,$pass,$alias) { 
    391     global $quota,$err; 
     396    global $quota,$err,$cuid; 
    392397    $err->log("mail","add_mail",$dom."/".$mail); 
    393398    $account=array(); 
     
    446451    } 
    447452    if ($pop!="1" && $pop!="0") $pop="0"; 
    448     $res=array("mail" => $mail."@".$dom, "uid" => $this->uid, "type" => "mail", "objectclass" => "mail", "pop" => $pop); 
     453    $res=array("mail" => $mail."@".$dom, "uid" => $cuid, "type" => "mail", "objectclass" => "mail", "pop" => $pop); 
    449454    $res["account"]=$account; 
    450455    /* QuotaCheck */ 
     
    512517   */ 
    513518  function _createpop($mail,$dom,$pass) { 
    514     global $err; 
     519    global $err,$cuid; 
    515520    $err->log("mail","_createpop",$mail."@".$dom); 
    516521    $m=substr($mail,0,1); 
     
    523528    $res=array( 
    524529               "uid" => $mail."_".$dom, 
    525                "gidnumber" => $this->uid, 
     530               "gidnumber" => $cuid, 
    526531               "uidnumber" => 33, 
    527532               "objectclass" => array("posixAccount","shadowAccount"), 
     
    529534               "gecos" => $gecos, 
    530535               "status" => "y", 
    531                "userpassword" => "{CRYPT}".$this->_md5cr($pass) 
     536               "userpassword" => "{CRYPT}"._md5cr($pass) 
    532537               ); 
    533538    @ldap_add($this->ds,"uid=".$mail."_".$dom.",dc=users,".$this->ldap["basedn"],$res); 
     
    535540    $res=array( 
    536541               "uid" => $mail."@".$dom, 
    537                "gidnumber" => $this->uid, 
     542               "gidnumber" => $cuid, 
    538543               "uidnumber" => 33, 
    539544               "objectclass" => array("posixAccount","shadowAccount"), 
     
    541546               "gecos" => $gecos, 
    542547               "status" => "y", 
    543                "userpassword" => "{CRYPT}".$this->_md5cr($pass) 
     548               "userpassword" => "{CRYPT}"._md5cr($pass) 
    544549               ); 
    545550    if (!ldap_add($this->ds,"uid=".$mail."@".$dom.",dc=users,".$this->ldap["basedn"],$res)) { 
     
    563568        return false; 
    564569      } else { 
    565         exec("/usr/lib/alternc/mail_add ".$mail."_".$dom." ".$this->uid); 
     570        exec("/usr/lib/alternc/mail_add ".$mail."_".$dom." ".$cuid); 
    566571        exec("/bin/echo ".escapeshellarg($pass)." | /usr/sbin/saslpasswd -u postfix -c -p ".$mail."@".$dom); 
    567572        exec("/bin/echo ".escapeshellarg($pass)." | /usr/sbin/saslpasswd -u postfix -c -p ".$mail."_".$dom); 
     
    580585   */ 
    581586  function _updatepop($mail,$dom,$pass) { 
    582     global $err; 
     587    global $err,$cuid; 
    583588    $err->log("mail","_updatepop",$mail."@".$dom); 
    584589    $m=substr($mail,0,1); 
     
    586591    $res=array( 
    587592               "uid" => $mail."_".$dom, 
    588                "gidnumber" => $this->uid, 
     593               "gidnumber" => $cuid, 
    589594               "uidnumber" => 33, 
    590595               "objectclass" => array("posixAccount","shadowAccount"), 
     
    592597               "gecos" => $mail, 
    593598               "status" => "y", 
    594                "userpassword" => "{CRYPT}".$this->_md5cr($pass) 
     599               "userpassword" => "{CRYPT}"._md5cr($pass) 
    595600               ); 
    596601    @ldap_modify($this->ds,"uid=".$mail."_".$dom.",dc=users,".$this->ldap["basedn"],$res); 
    597602    $res=array( 
    598603               "uid" => $mail."@".$dom, 
    599                "gidnumber" => $this->uid, 
     604               "gidnumber" => $cuid, 
    600605               "uidnumber" => 33, 
    601606               "objectclass" => array("posixAccount","shadowAccount"), 
     
    603608               "gecos" => $mail, 
    604609               "status" => "y", 
    605                "userpassword" => "{CRYPT}".$this->_md5cr($pass) 
     610               "userpassword" => "{CRYPT}"._md5cr($pass) 
    606611               ); 
    607612    if (!ldap_modify($this->ds,"uid=".$mail."@".$dom.",dc=users,".$this->ldap["basedn"],$res)) { 
     
    705710   * @return boolean TRUE si le domaine a bien été créé, FALSE si une erreur s'est produite. 
    706711   * @access private 
     712   * TODO : ne créer les entrées que si le MX est à true ! (déplacer a alternc_add_mx_domain 
    707713   */ 
    708714  function alternc_add_domain($dom) { 
    709     global $err; 
     715    global $err,$cuid; 
    710716    $err->log("mail","add_dom",$dom); 
    711717    if (!$this->_connectldap()) { 
     
    719725      return false; 
    720726    } 
    721     $res=array("mail" => $dom, "uid" => $this->uid, "type" => "domain", "objectclass" => "mail", "account"=> $dom); 
     727    $res=array("mail" => $dom, "uid" => $cuid, "type" => "domain", "objectclass" => "mail", "account"=> $dom); 
    722728    if (!ldap_add($this->ds,"mail=$dom,dc=domains,".$this->ldap["basedn"],$res)) { 
    723729      $err->raise("mail",5,ldap_error($this->ds)); 
     
    730736  function alternc_quota_check($id=-1) { 
    731737    global $quota,$err; 
    732     $err->log("mail","checkquota"); 
    733     if ($id==-1) $id=$this->uid; 
    734     if (!$this->_connectldap()) { 
    735       $err->raise("mail",1); 
    736       return false; 
    737     } 
    738     $sr=ldap_search($this->ds,"dc=domains,".$this->ldap["basedn"],"(&(uid=".$this->uid.")(type=mail))",array("")); 
    739     $info = ldap_get_entries($this->ds, $sr); 
    740     $quota->setquota("mail",$info[count],1,$id);   
    741  
     738    if ($id==-1) $id=$cuid; 
    742739    return true; 
    743740  } 
     
    771768  } 
    772769 
    773   /* ----------------------------------------------------------------- */ 
    774   /** Crypte un mot de passe en clair en MD5 avec un salt aléatoire 
    775    * @param string $pass Mot de passe à crypter (max 32 caractères) 
    776    * @return string Retourne le mot de passe crypté 
    777    * @access private 
    778    */ 
    779   function _md5cr($pass) { 
    780     $salt="";     //generate a salt using characters [A-Z][a-z][0-9]./ 
    781     $chars="./0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; 
    782     for ($i=0;$i<16;$i++) { 
    783       $salt.=substr($chars,(mt_rand(0,strlen($chars))),1); 
    784     } 
    785     return crypt($pass,"$1$".$salt); 
    786     /* " */ 
    787   } 
    788  
    789770} /* Class m_mail */ 
    790771 
Note: See TracChangeset for help on using the changeset viewer.