<?php
/*
 * postLdapAdmin
 *
 * Copyright (C) 2006,2007 DesigNET, INC.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

/***********************************************************
 * 桼Ƚѥ饤֥
 *
 * $RCSfile: libuser,v $
 * $Revision: 1.6 $
 * $Date: 2008/12/05 06:02:08 $
 **********************************************************/
/* CSVѷɽ̤Υå */
define("CSV_OK_MSG", "%08d %s OK %s<br>\n");
define("CSV_NG_MSG", "%08d %s NG %s<br>\n");

define("ADD_MODE",  0);
define("MOD_MODE",  1);

/***********************************************************
 * check_userdata
 *
 * 桼ǡͥå
 *
 * []
 *        &$data     ϥǡ
 *
 * [֤]
 *        TRUE       
 *        FALSE      顼
 *
 **********************************************************/
function check_userdata($data) {

    global $err_msg;

    /* 桼̾Υå(ɬ) */
    if ($data["uid"] == "") {
        $err_msg = "桼̾ϤƤޤ";
        return FALSE;
    }
    if (check_name($data["uid"], MAXUID) === FALSE) {
        return FALSE;
    }

    /* ѥɤΥå(ɬ) */
    if (check_passwd($data["pass"], MINPASSWD, MAXPASSWD) === FALSE) {
        return FALSE;
    }

    /* ᡼ܥå̤Υå */
    if (check_diskquota($data["quota"]) === FALSE) {
        return FALSE;
    }

    /* ᡼륨ꥢΥå */
    if ($data["alias"] != "") {
        if ($data["alias"] == $data["uid"]) {
            $err_msg = "᡼륨ꥢ桼̾ȽʣƤޤ";
            return FALSE;
        }
        if (check_name($data["alias"], MAXNAME) === FALSE) {
            $err_msg = "᡼륨ꥢηǤ";
            return FALSE;
        }
    }

    /* ᡼žɥ쥹Υå */
    if ($data["transes"][0] != "") {
        if (check_mail($data["transes"][0]) === FALSE) {
            $err_msg = "᡼žɥ쥹ηǤ";
            return FALSE;
        }
        /* ᡼¸å */
        if (!isset($data["save"])) {
            $err_msg = "᡼Ĥ/Ĥʤ꤬Ƥޤ";
            return FALSE;
        } elseif (check_flg($data["save"]) === FALSE) {
            $err_msg = "᡼Ĥ/ĤʤͤǤ";
            return FALSE;
        }
    }
    return TRUE;

}

/***********************************************************
 * check_csv_trans
 *
 * 桼žɥ쥹Υå
 *
 * []
 *        &$data     ϥǡ
 *
 * [֤]
 *        TRUE       
 *        FALSE      顼
 *
 **********************************************************/
function check_csv_trans(&$data)
{
    global $err_msg;
    global $domain;

    /* ᡼žɥ쥹Υå */
    if ($data['transes'][0] != "") {
        if ($data['transes'][0] == $data["mail"]) {
            $err_msg = "᡼žɥ쥹᡼륢ɥ쥹ȽʣƤޤ";
            return FALSE;
        }
        if (isset($data["mailalias"]) &&
            $data['transes'][0] == $data["mailalias"]) {
            $err_msg = "᡼žɥ쥹᡼륨ꥢȽʣƤޤ";
            return FALSE;
        }
        if ($data["save"] == ON) {
            /* ᡼Ĥξžɥ쥹˼᡼륢ɥ쥹ɲ */
            array_push($data["transes"], $data["mail"]);
        }
    }

    return TRUE;
}

/***********************************************************
 * check_add_data
 *
 * 桼ɲûͥå
 *
 * []
 *        &$data     ϥǡ
 *        $csvcheck  CSVեѤΥåե饰(ʣå뤫ɤ)
 * [֤]
 *        TRUE       
 *        FALSE      顼
 *
 **********************************************************/
function check_add_data(&$data, $csvcheck = FALSE)
{
    global $err_msg;
    global $domain;
    $transes = array();
    /* 桼̾Υå(ɬ) */
    if ($data["uid"] == "") {
        $err_msg = "桼̾ϤƤޤ";
        return FALSE;
    }
    if (check_name($data["uid"], MAXUID) === FALSE) {
        return FALSE;
    }

    /* ѥɤΥå(ɬ) */
    if (check_passwd($data["pass"], MINPASSWD, MAXPASSWD) === FALSE) {
        return FALSE;
    }

    /* ᡼ܥå̤Υå */
    if (check_diskquota($data["quota"]) === FALSE) {
        return FALSE;
    }

    /* ᡼륨ꥢΥå */
    if ($data["alias"] != "") {
        if ($data["alias"] == $data["uid"]) {
            $err_msg = "᡼륨ꥢ桼̾ȽʣƤޤ";
            return FALSE;
        }
        if (check_name($data["alias"], MAXNAME) === FALSE) {
            $err_msg = "᡼륨ꥢηǤ";
            return FALSE;
        }
    }

    /* ѥɡѥ(ǧ)Υå */
    if ($data["pass"] != $data["re_pass"]) {
        $err_msg = "ѥɤפޤ";
        return FALSE;
    }

    /* 桼̾νʣå */
    $mail = $data["uid"] . "@" . $domain;
    if ($csvcheck === FALSE) {
        $ret = check_duplicate($mail);
        if ($ret == LDAP_FOUNDUSER || $ret == LDAP_FOUNDALIAS ||
            $ret == LDAP_FOUNDOTHER) {
            $err_msg = "桼̾ϴ˻ȤƤޤ";
            return FALSE;
        } elseif ($ret == LDAP_ERRUSER) {
            return FALSE;
        }
    }
    $data["mail"] = $mail;

    /* ᡼žɥ쥹Υå */
    if ($data["trans"] != "") {
        if (check_mail ($data["trans"]) === FALSE) {
            $err_msg = "᡼žɥ쥹ηǤ";
            return FALSE;
        }
        /* ᡼¸å */
        if (!isset($data["save"])) {
            $err_msg = "᡼Ĥ/Ĥʤ꤬Ƥޤ";
            return FALSE;
        } elseif (check_flg($data["save"]) === FALSE) {
            $err_msg = "᡼Ĥ/ĤʤͤǤ";
            return FALSE;
        }
    }

    /* ᡼륨ꥢνʣå */
    if ($data["alias"] != "") {
        $data["mailalias"] = $data["alias"] . "@" . $domain;
        $ret = check_duplicate($data["mailalias"]);
        if ($ret == LDAP_FOUNDUSER || $ret == LDAP_FOUNDALIAS ||
            $ret == LDAP_FOUNDOTHER) {
            $err_msg = "᡼륨ꥢϴ˻ȤƤޤ";
            return FALSE;
        } elseif ($ret == LDAP_ERRUSER) {
            return FALSE;
        }
    }


    /* ᡼žɥ쥹Υå */
    if ($data['trans'] != "") {
        if ($data['trans'] == $mail) {
            $err_msg = "᡼žɥ쥹᡼륢ɥ쥹ȽʣƤޤ";
            return FALSE;
        }
        if (isset($data["mailalias"]) && $data['trans'] == $data["mailalias"]) {
            $err_msg = "᡼žɥ쥹᡼륨ꥢȽʣƤޤ";
            return FALSE;
        }
        if (isset ($data["save"]) && $data["save"] == ON) {
            /* ᡼Ĥξžɥ쥹˼᡼륢ɥ쥹ɲ */
            array_push($transes, $mail);
        }
        if ($data["trans"] != "") {
            array_push($transes, $data["trans"]);
        }

        $data["transes"] = $transes;
    }
    return TRUE;
}

/*********************************************************
 * check_mod_data
 *
 * ϥեηå
 *
 * []
 *          &$data     ϥǡ
 * [֤]
 *          TRUE       
 *          FALSE      顼
 *
 **********************************************************/
function check_mod_data(&$data)
{
    global $err_msg;
    global $domain;
    global $ldapdata;
    $transes = array();

    $mail = $data['mail'];

    if ((!isset($ldapdata[0]['userPassword'][0])) || $data["pass"] != ""
                                               || $data["re_pass"] != "") {
        /* ѥɤꤵƤʤȥǤХѥɤɬ */
        if ($data["pass"] == "") {
            $err_msg = "ѥɤꤵƤޤ";
            return FALSE;
        }
        /* ѥɤΥå(ɬ) */
        if (check_passwd($data["pass"], MINPASSWD, MAXPASSWD) === FALSE) {
            return FALSE;
        }
        /* ѥɡѥ(ǧ)ΰץå */
        if ($data["pass"] != $data["re_pass"]) {
            $err_msg = "ѥɤפޤ";
            return FALSE;
        }
    }

    /* ᡼ܥå̤Υå(ɬ) */
    if ($data["quota"] != "") {
        if (check_diskquota($data["quota"]) === FALSE) {
            return FALSE;
        }
    }

    /* ᡼륨ꥢΥå */
    if ($data["alias"] != "") {
        if ($data["alias"] == $data["uid"]) {
            $err_msg = "᡼륨ꥢ桼̾ȽʣƤޤ";
            return FALSE;
        }
        if (check_name($data["alias"], MAXNAME) === FALSE) {
            $err_msg = "᡼륨ꥢηǤ";
            return FALSE;
        }
    }

    /* ᡼žɥ쥹Υå */
    if ($data["trans"] != "") {
        if (check_mail ($data["trans"]) === FALSE) {
            $err_msg = "᡼žɥ쥹ηǤ";
            return FALSE;
        }
        /* ᡼¸å */
        if (!isset($data["save"])) {
            $err_msg = "᡼Ĥ/Ĥʤ꤬Ƥޤ";
            return FALSE;
        } elseif (check_flg($data["save"]) === FALSE) {
            $err_msg = "᡼Ĥ/ĤʤͤǤ";
            return FALSE;
        }
    }
    /* ᡼륨ꥢνʣå */
    if ($data["alias"] != "") {
        $data["mailAlias"] = $data["alias"] . "@" . $domain;
        /* ꥢ񤭴ե饰ǥեȤON */
        $chflg = ON;

        if (isset($ldapdata[0]["mailAlias"][0])) {
            /* ꥢѹʤн񤭴ե饰:OFF */
            if ($data["mailAlias"] == $ldapdata[0]["mailAlias"][0]) {
                $chflg = OFF;
            }
        }

        /* ꥢѹСʣå */
        if ($chflg == ON) {
            $ret = check_duplicate($data["mailAlias"]);
            if ($ret == LDAP_FOUNDUSER || $ret == LDAP_FOUNDALIAS ||
                $ret == LDAP_FOUNDOTHER) {
                $err_msg = "᡼륨ꥢϴ˻ȤƤޤ";
                return FALSE;
            } elseif ($ret == LDAP_ERRUSER) {
                return FALSE;
            }
        }
    }

    /* ᡼žɥ쥹Υå */
    if ($data['trans'] != "") {
        if ($data['trans'] == $mail) {
            $err_msg = "᡼žɥ쥹᡼륢ɥ쥹ȽʣƤޤ";
            return FALSE;
        }
        if (isset($data["mailAlias"]) && $data['trans'] == $data["mailAlias"]) {
            $err_msg = "᡼žɥ쥹᡼륨ꥢȽʣƤޤ";
            return FALSE;
        }
        if ($data["save"] == ON) {
            /* ᡼Ĥξžɥ쥹˼᡼륢ɥ쥹ɲ */
            array_push($transes, $mail);
        }
        if ($data["trans"] != "") {
            array_push($transes, $data["trans"]);
        }

        $data["transes"] = $transes;
    }
    return TRUE;
}

/***********************************************************
 * add_user
 *
 * 桼ǡɲä
 *
 * []
 *       $data    ɲå桼ΥǡǼ줿Ϣ
 *
 * [֤]
 *       TRUE     
 *       FALSE    顼
 *
 **********************************************************/
function add_user($data)
{
    global $web_conf;
    global $err_msg;
    global $domain;
    global $attr;

    /* Ͽѥǡ */
    $user = $data["uid"];
    $pass = CRYPT . my_crypt($data["pass"]);
    $mail = $data["mail"];
    $alias = $data["alias"];
    $maildir = $web_conf["basemaildir"] . "/" . $user . "/";
    $objectclass = mk_oc_list($web_conf['ldapobjectclass']);

    /* LDAPϿɬ°Υå */
    $attr = array("objectClass" => $objectclass,
                  "uid" => $data["uid"],
                  "userPassword" => $pass,
                  "mail" => $mail,
                  "mailDirectory" => $maildir);

    /* ɬܤǤϤʤ°Υå */
    if ($data["quota"] != "") {
        $quota = $data["quota"] * 1024 * 1024;
        $attr["quotaSize"] = $quota;
    }
    if (isset($data["mailalias"])) {
        $attr["mailAlias"] = $data["mailalias"];
    }
    if (isset ($data["transes"]) && count($data["transes"]) != 0) {
        $attr["mailForwardingAddr"] = $data["transes"];
    }

    /* LDAPϿ */
    $add_dn = sprintf(ADD_DN, $mail, $web_conf["ldapusersuffix"], $web_conf["ldapbasedn"]);
    $ret = LDAP_add_entry($add_dn, $attr);
    if ($ret != LDAP_OK) {
        return FALSE;
    }

    return TRUE;
}

/***********************************************************
 * add_user_connect
 *
 * 桼ǡɲä(LDAP³ʤ)
 *
 * []
 *       $data    ɲå桼ΥǡǼ줿Ϣ
 *       $ds      LDAPID
 *
 * [֤]
 *       TRUE     
 *       FALSE    顼
 *
 **********************************************************/
function add_user_connect($data, $ds)
{
    global $web_conf;
    global $err_msg;
    global $domain;
    global $attr;

    /* Ͽѥǡ */
    $user = $data["uid"];
    $pass = CRYPT . my_crypt($data["pass"]);
    $mail = $data["mail"];
    $alias = $data["alias"];
    $maildir = $web_conf["basemaildir"] . "/" . $user . "/";
    $objectclass = mk_oc_list($web_conf['ldapobjectclass']);

    /* LDAPϿɬ°Υå */
    $attr = array("objectClass" => $objectclass,
                  "uid" => $data["uid"],
                  "userPassword" => $pass,
                  "mail" => $mail,
                  "mailDirectory" => $maildir);

    /* ɬܤǤϤʤ°Υå */
    if ($data["quota"] != "") {
        $quota = $data["quota"] * 1024 * 1024;
        $attr["quotaSize"] = $quota;
    }
    if (isset($data["mailalias"])) {
        $attr["mailAlias"] = $data["mailalias"];
    }
    if ($data["transes"][0] != "") {
        $attr["mailForwardingAddr"] = $data["transes"];
    }

    /* LDAPϿ */
    $add_dn = sprintf(ADD_DN, $mail, $web_conf["ldapusersuffix"], $web_conf["ldapbasedn"]);
    $ret = LDAP_add_entry_connect($add_dn, $ds, $attr);
    if ($ret != LDAP_OK) {
        return FALSE;
    }

    return TRUE;
}

/*********************************************************
 * mod_user
 *
 * 桼ν
 *
 * []
 *          $data  桼γǼ줿Ϣ
 * [֤]
 *          TRUE   
 *          FALSE  顼
 *
 **********************************************************/
function mod_user($data)
{
    global $err_msg;
    global $domain;
    global $user;
    global $ldapdata;
    global $web_conf;
    global $userdn;

    if (isset($data["mailAlias"])) {
        $alias = $data["mailAlias"];
    } else {
        $alias = "";
    }
    if (isset($data["alias"])) {
        $alias_name = $data["alias"];
    } else {
        $alias_name = "";
    }
    if (isset($data["transes"])) {
        $transes = $data["transes"];
    } else {
        $transes = array();
    }

    if ($data["pass"] != "") {
        $attrs['userPassword'] = CRYPT . my_crypt($data["pass"]);
    }

    /* ǥ̤ѹʤк */
    if ($data["quota"] != "") {
        $attrs["quotaSize"] = $data["quota"] * 1024 * 1024;
    } else {
        $attrs["quotaSize"] = array();
    }

    /* Х᡼륨ꥢѹʤк */
    if ($alias != "") {
        $attrs["mailAlias"] = $alias;
    } else {
        $attrs["mailAlias"] = array();
    }

    /* ᡼žɥ쥹γǼ */
    if (count($transes) != 0) {
        $attrs["mailForwardingAddr"] = $transes;
    } else {
        $attrs["mailForwardingAddr"] = array();
    }

    /* ᡼ǥ쥯ȥ°ʤк */
    if (!isset($ldapdata[0]["mailDirectory"][0])) {
        $attrs["mailDirectory"] = $web_conf["basemaildir"] . "/" . $user . "/";
    }

    /* LDAPǡι */
    $ret = LDAP_mod_entry($userdn, $attrs);
    if ($ret !== LDAP_OK && $ret != LDAP_ERR_NOATTR) {
        return FALSE;
    }

    return TRUE;
}

/*********************************************************
 * mod_user_connect
 *
 * 桼ν(LDAP³ʤ)
 *
 * []
 *          $data  桼γǼ줿Ϣ
 *          $ds    LDAPID
 * [֤]
 *          TRUE   
 *          FALSE  顼
 *
 **********************************************************/
function mod_user_connect($data, $ds)
{
    global $err_msg;
    global $domain;
    global $ldapdata;
    global $web_conf;
    global $userdn;

    $user = $data["uid"];

    if (isset($data["mailAlias"])) {
        $alias = $data["mailAlias"];
    } else {
        $alias = "";
    }
    if (isset($data["alias"])) {
        $alias_name = $data["alias"];
    } else {
        $alias_name = "";
    }
    if ($data["transes"][0] != "") {
        $transes = $data["transes"];
    } else {
        $transes = array();
    }

    if ($data["pass"] != "") {
        $attrs['userPassword'] = CRYPT . my_crypt($data["pass"]);
    }

    /* ǥ̤ѹʤк */
    if ($data["quota"] != "") {
        $attrs["quotaSize"] = $data["quota"] * 1024 * 1024;
    } else {
        $attrs["quotaSize"] = array();
    }

    /* Х᡼륨ꥢѹʤк */
    if ($alias != "") {
        $attrs["mailAlias"] = $alias;
    } else {
        $attrs["mailAlias"] = array();
    }

    /* ᡼žɥ쥹γǼ */
    if (count($transes) != 0) {
        $attrs["mailForwardingAddr"] = $transes;
    } else {
        $attrs["mailForwardingAddr"] = array();
    }

    /* ᡼ǥ쥯ȥ°ʤк */
    if (!isset($ldapdata[0]["mailDirectory"][0])) {
        $attrs["mailDirectory"] = $web_conf["basemaildir"] . "/" . $user . "/";
    }

    /* LDAPǡι */
    $ret = LDAP_mod_entry_connect($userdn, $ds, $attrs);
    if ($ret !== LDAP_OK && $ret != LDAP_ERR_NOATTR) {
        return FALSE;
    }

    return TRUE;
}
/*********************************************************
 * del_user
 *
 * 桼
 *
 * []
 *         $user    оݥ桼
 * [֤]
 *         TRUE     
 *         FALSE    顼
 *
 **********************************************************/
function del_user($user)
{
    global $err_msg;
    global $web_conf;
    global $domain;
    global $userdn;
    global $ldapdata;

    $maildir = "";

    $delmail = $user . "@" . $domain;

    /* LDAPΥȥ */
    $ret = LDAP_del_entry($userdn);
    if ($ret == LDAP_ERR_NODATA) {
        /* ¸ߤʤ */
        $err_msg = "";
    } elseif ($ret != LDAP_OK) {
        return FALSE;
    }

    /* ᡼ǥ쥯ȥ¸ߥå */
    if (isset($ldapdata[0]['mailDirectory'][0])) {
        $maildir = $ldapdata[0]['mailDirectory'][0];
    }
    if ($maildir != "" && is_dir ($maildir)) {
        /* ᡼ǥ쥯ȥޥɤ¹ */
        $delcmd = $web_conf['maildelcommand'] . " " . $maildir . " > /dev/null 2>&1";
        system ($delcmd, $cmd_st);
        if ($cmd_st != 0) {
            $err_msg = "᡼ǥ쥯ȥޥɤμ¹Ԥ˼Ԥޤ";
            result_log (OPERATION . ":NG:ޥɡ" . $delcmd . "פμ¹Ԥ˼Ԥޤ
");
            return FALSE;
        }
    }

    /* ᡼󥰥ꥹȥɥ쥹 */
    $dn = sprintf(SEARCH_DN, $web_conf['ldaplistsuffix'], $web_conf['ldapbasedn']);
    $filter = "(mailForwardingAddr=" . $delmail . ")";
    $attrs = array();

    $ret = main_get_entry($dn, $filter, $attrs, $web_conf['ldapscope'], $mldata);
    if ($ret == LDAP_ERR_NODATA) {
        /* ¸ߤʤϤʤˤ⤷ʤ */
        $err_msg = "";
    } elseif ($ret != LDAP_OK) {
        return FALSE;
    } else {
        /* ᡼륢ɥ쥹° */
        for ($i = 0; isset($mldata[$i]["mail"][0]); $i++) {
            $del_mldn = sprintf(ADD_DN, $mldata[$i]["mail"][0],
                                $web_conf['ldaplistsuffix'], $web_conf['ldapbasedn']);
            $fwaddr = array();
            $modaddr = array();

            foreach ($mldata[$i]["mailForwardingAddr"] as $each) {
                if ($each != $delmail) {
                    array_push($fwaddr, $each);
                }
            }
            $modaddr["mailForwardingAddr"] = $fwaddr;
            $ret = LDAP_mod_entry($del_mldn, $modaddr);
            if ($ret !== LDAP_OK && $ret != LDAP_ERR_NOATTR) {
                return FALSE;
            }
            result_log(OPERATION . ":OK:" . "᡼󥰥ꥹȡ" .
                      $mldata[$i]["mail"][0] . "פ桼ޤ");
        }
    }
    return TRUE;
}

/*********************************************************
 * del_user_connect
 *
 * 桼
 *
 * []
 *         $user    оݥ桼
 *         $ds     LDAPID
 * [֤]
 *         TRUE     
 *         FALSE    顼
 *
 **********************************************************/
function del_user_connect($user, $ds)
{
    global $err_msg;
    global $web_conf;
    global $domain;
    global $userdn;
    global $ldapdata;

    $maildir = "";

    $delmail = $user . "@" . $domain;

    /* LDAPΥȥ */
    $ret = LDAP_del_entry($userdn);
    if ($ret == LDAP_ERR_NODATA) {
        /* ¸ߤʤ */
        $err_msg = "";
    } elseif ($ret != LDAP_OK) {
        return FALSE;
    }

    /* ᡼ǥ쥯ȥ¸ߥå */
    if (isset($ldapdata[0]['mailDirectory'][0])) {
        $maildir = $ldapdata[0]['mailDirectory'][0];
    }
    if ($maildir != "" && is_dir ($maildir)) {
        /* ᡼ǥ쥯ȥޥɤ¹ */
        $delcmd = $web_conf['maildelcommand'] . " " . $maildir . " > /dev/null 2>&1";
        system ($delcmd, $cmd_st);
        if ($cmd_st != 0) {
            $err_msg = "᡼ǥ쥯ȥޥɤμ¹Ԥ˼Ԥޤ";
            result_log (OPERATION . ":NG:ޥɡ" . $delcmd . "פμ¹Ԥ˼Ԥޤ
");
            return FALSE;
        }
    }

    /* ᡼󥰥ꥹȥɥ쥹 */
    $dn = sprintf(SEARCH_DN, $web_conf['ldaplistsuffix'], $web_conf['ldapbasedn']);
    $filter = "(mailForwardingAddr=" . $delmail . ")";
    $attrs = array();

    $ret = main_get_entry_connect($dn, $ds, $filter, $attrs,
                                  $web_conf['ldapscope'], $mldata);
    if ($ret == LDAP_ERR_NODATA) {
        /* ¸ߤʤϤʤˤ⤷ʤ */
        $err_msg = "";
    } elseif ($ret != LDAP_OK) {
        return FALSE;
    } else {
        /* ᡼륢ɥ쥹° */
        for ($i = 0; isset($mldata[$i]["mail"][0]); $i++) {
            $del_mldn = sprintf(ADD_DN, $mldata[$i]["mail"][0],
                                $web_conf['ldaplistsuffix'], $web_conf['ldapbasedn']);
            $fwaddr = array();
            $modaddr = array();

            foreach ($mldata[$i]["mailForwardingAddr"] as $each) {
                if ($each != $delmail) {
                    array_push($fwaddr, $each);
                }
            }
            $modaddr["mailForwardingAddr"] = $fwaddr;
            $ret = LDAP_mod_entry($del_mldn, $ds, $modaddr);
            if ($ret !== LDAP_OK && $ret != LDAP_ERR_NOATTR) {
                return FALSE;
            }
            result_log(OPERATION . ":OK:" . "᡼󥰥ꥹȡ" .
                      $mldata[$i]["mail"][0] . "פ桼ޤ");
        }
    }
    return TRUE;
}
?>
