代码之家  ›  专栏  ›  技术社区  ›  BlooB

服务器不愿意执行-无法在活动状态下创建用户对象

  •  1
  • BlooB  · 技术社区  · 8 年前

    我设法做到了 connect, query and add to AD . 添加时 user object 具有 示例a (向下看) attributes 设置我没有问题,但是当我添加:

    $this->newUserEntry["UserAccountControl"] = 512; //LDAP will disable the account by default, This will create it in an enabled state
    

    我收到以下警告 ldap_add() 用户对象 未创建:

    Server is unwilling to perform
    

    示例A:

            $this->newUserEntry["objectclass"][0] = "top";
            $this->newUserEntry["objectclass"][1] = "person";
            $this->newUserEntry["objectclass"][2] = "organizationalPerson";
            $this->newUserEntry["objectclass"][3] = "user";
    
            //---------General Tab-----------------------------------------
            $this->newUserEntry['givenname'] = $this->givenName; //first name
            $this->newUserEntry['sn'] = $this->sn; // last name
            $this->newUserEntry["displayname"] = $this->sn.', '.$this->givenName; // display name - Format: Meow, Test
            $this->newUserEntry["physicalDeliveryOfficeName"] = $this->location; //office
            $this->newUserEntry["mail"] = $this->userMail;
            $this->newUserEntry["mailNickname"] = $this->userMail; // user mail
    
            //Change this to mobile field
            $this->newUserEntry["telephoneNumber"] = '9897157910'; // user phone
    
            //----------Account Tab----------------------------------------
            $this->newUserEntry["userPrincipalName"] = $this->samaccountname.'@comp.com'; //User logon name
            $this->newUserEntry["sAMAccountname"] = $this->samaccountname; //pre windows 2007 logon name
    
    
            //----------profile Tab-----------------------------------------
            $this->newUserEntry["scriptPath"] = $this->scriptPath; //Log on script
    
            //----------Organization Tab------------------------------------
            $this->newUserEntry["title"] = $this->title;
            $this->newUserEntry["department"] = $this->department; // department
            $this->newUserEntry["company"] = "Open Doors Test"; // Company name
            $this->newUserEntry["manager"] = $this->managerDn; // name of the manager
    

    我尝试过:

    1-设置 password attribute :

    我告诉大家这是因为我没有密码 attribute 设置,所以我尝试添加 password 具有 hashing 而且没有 散列 :

    密码示例:As33557b

    $this->newUserEntry["userPassword"] = '{MD5}' . base64_encode(pack('H*',md5($this->password))); //md5HASH - hash the password
    

    这两次尝试都失败了,就像以前一样,如果我删除帐户控制,则创建的用户对象没有任何问题。

    2-确保连接已结束 SSL :

    我改变了通过 LDAP :

    之前:

    ldap_connect('ldap://'. $this->dnToConnect)
    

    之后:

    ldap_connect('ldap://'. $this->dnToConnect, 636)

    我也跑了 nmap -p 636 mydomain.com 确保 port is open 我可以建立联系。

    3-尝试设置 512 值作为 string 作为一个 integer .

    笔记: 我可以 accounts, disable and enable 手动执行,因此问题不应出现在 user and password 我已经习惯了 bind .

    更新1:

    我已将问题缩小到密码。我可以创建 Enabled account 具有 no password 和设置 userAccountControl to 544 ,因此我认为问题在于我设置密码字段的方式。 Bloob就要爆炸了,如果有人帮忙,我们将不胜感激。

    评论部分请求的信息: 密码:

    最初,我将密码设置为:

    //$this->newUserEntry["userPassword"] = '{MD5}' . base64_encode(pack('H*',md5($this->password))); //md5HASH - hash the password
    

    而不是有人建议尝试将其设置为:

    $newPassword = $this->password;
    $newPassword = "\"" . $newPassword . "\"";
    $newPass = mb_convert_encoding($newPassword, "UTF-16LE");
    $this->newUserEntry["unicodePwd"] = $newPass;
    
    1 回复  |  直到 8 年前
        1
  •  2
  •   BlooB    8 年前

    希望这会对某人有所帮助,这就是我无法在中创建帐户的原因 active state 由于无法设置属性 unicodePwd 这是因为无法通过 LDAPS .

    我无法连接 LDAPS公司 由于缺少所需的证书和一些配置。

    分辨率:

    1-

    a、 在中创建以下文件夹 C: 目录(与您看到的 phps top folder )

    openldap -> sysconf
    

    b、 在中 sysconf系统 文件夹:

    b1、创建ldap。conf文件并添加以下行:

       TLS_CACERT C:\openldap\sysconf\ssl\cacert.pem
       TLS_REQCERT     never 
    

    b2、在中创建文件夹 sysconf 已命名 ssl :

       you will put a `certificate` in there (look at part 2 for details)
    

    2-转到托管您的 Active directory ,要求您的管理员执行以下链接中的说明,以及 put the cert in ssl folder ,还请记住使用转换证书 openSSL :

    https://social.technet.microsoft.com/wiki/contents/articles/2980.ldap-over-ssl-ldaps-certificate.aspx 
    

    3-您可以使用以下脚本进行测试:

    <?php
    
      $ldaphost = "ldaps://hostNameOfDC.DCName.com";
      $ldapUsername  = "adminUser@DCName.com";
      $ldapPassword = "adminPASS";
    
      $ds = ldap_connect($ldaphost,636);
      if(!ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3)){
      print "Could not set LDAPv3\r\n";
      }
      else {
    // now we need to bind to the ldap server
         $bth = ldap_bind($ds, $ldapUsername, $ldapPassword) or die("\r\nCould not connect to LDAP server\r\n");
      }
    
      if($bth){ echo"WEEEE you did it"; }
    
    ?>
    

    4.如何设置 unicodePwd公司 (密码 credit to ):

            $newPassword = "\"" . $newPassword . "\"";
            $newPass = mb_convert_encoding($newPassword, "UTF-16LE");
            $this->newUserEntry["unicodePwd"] = $newPass;