cannot ldapadd in freebsd prompt, but ldap_add() in php is ok ?

This is a discussion on cannot ldapadd in freebsd prompt, but ldap_add() in php is ok ? within the PHP Language forums, part of the PHP Programming Forums category; under freebsd prompt, I typed ldapadd -f tester.ldif -x -D "uid=tester, ou=People, dc=aitc, dc=com, ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-31-2005
jiing
 
Posts: n/a
Default cannot ldapadd in freebsd prompt, but ldap_add() in php is ok ?

under freebsd prompt, I typed
ldapadd -f tester.ldif -x -D "uid=tester, ou=People, dc=aitc, dc=com,
dc=tw" -w orson
then
ldap_bind: Invalid credentials (49)
using whoami, I am root, so I think I have the right to do that
I use ldapsearch to search other entries is ok.

my tester.ldif is
dn: dc=aitc, dc=com, dc=tw
objectClass: top
objectClass: account
objectClass: posixAccount
dc: aitc

dn: uid=tester, ou=People, dc=aitc, dc=com, dc=tw
cn= Tester


but when I looked at the /usr/local/etc/openldap/slapd.conf
, the rootpw is orson (cleartext, I am testing)

but when I use php to write some code to add user, it works (I use
ldapbrowser to see the added entry)

<?php
$ldapServer="ldap://192.168.1.211";
$ldapPort="389";
$ldapconn=ldap_connect($ldapServer,$ldapPort);
$ldaprdn="uid=root, ou=People, dc=aitc, dc=com, dc=tw";
$ldappass="orson";

if($ldapconn){
echo "connect to ".$ldapServer." successfully \n<br>";
}else{
echo "can't connect to LDAP server!\n<br>";
}
ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);

if ($ldapconn) {
// binding to ldap server to give update access
$ldapbind = ldap_bind($ldapconn, $ldaprdn, $ldappass);
// verify binding
if ($ldapbind) {
echo "LDAP binding successful...\n";
} else {
echo "LDAP binding failed...\n";
}
}

//data preparation
//I am not very sure what attribute should be filled
$data["uid"]="tester";
$data["cn"]="Tester 1";
$data["objectclass"][0]="account";
$data["objectclass"][1]="posixAccount";
$data["objectclass"][2]="top";
$data["userpassword"]="";
$data["loginshell"]="/usr/local/bin/bash";
$data["uidnumber"]=3100;
$data["gidnumber"]=3100;
$data["homedirectory"]="/home/tester";
$data["gecos"]="Tester 1";

// Before ldap_add(), should check the user already exists or not
if(!ldap_add($ldapconn,"uid=tester, ou=People, dc=aitc, dc=com,
dc=tw", $data)){
echo "There is a problem to create the account\n";
echo "Please contact your administrator!\n";
exit;
}else{
echo "account creation successfully";
}
ldap_close($ldapconn);
?>

Does anyone know what's wrong with it?
I use openldap mount in freebsd

Thanks in advance.

-jiing-
Reply With Quote
  #2 (permalink)  
Old 01-31-2005
Steve
 
Posts: n/a
Default Re: cannot ldapadd in freebsd prompt, but ldap_add() in php is ok?

jiing wrote:
> under freebsd prompt, I typed
> ldapadd -f tester.ldif -x -D "uid=tester, ou=People, dc=aitc, dc=com,
> dc=tw" -w orson
> then
> ldap_bind: Invalid credentials (49)
> using whoami, I am root, so I think I have the right to do that
> I use ldapsearch to search other entries is ok.
>
> my tester.ldif is
> dn: dc=aitc, dc=com, dc=tw
> objectClass: top
> objectClass: account
> objectClass: posixAccount
> dc: aitc
>
> dn: uid=tester, ou=People, dc=aitc, dc=com, dc=tw
> cn= Tester

Continuation lines as above need to start with white space.

Steve
>
>
> but when I looked at the /usr/local/etc/openldap/slapd.conf
> , the rootpw is orson (cleartext, I am testing)
>
> but when I use php to write some code to add user, it works (I use
> ldapbrowser to see the added entry)
>
> <?php
> $ldapServer="ldap://192.168.1.211";
> $ldapPort="389";
> $ldapconn=ldap_connect($ldapServer,$ldapPort);
> $ldaprdn="uid=root, ou=People, dc=aitc, dc=com, dc=tw";
> $ldappass="orson";
>
> if($ldapconn){
> echo "connect to ".$ldapServer." successfully \n<br>";
> }else{
> echo "can't connect to LDAP server!\n<br>";
> }
> ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
>
> if ($ldapconn) {
> // binding to ldap server to give update access
> $ldapbind = ldap_bind($ldapconn, $ldaprdn, $ldappass);
> // verify binding
> if ($ldapbind) {
> echo "LDAP binding successful...\n";
> } else {
> echo "LDAP binding failed...\n";
> }
> }
>
> //data preparation
> //I am not very sure what attribute should be filled
> $data["uid"]="tester";
> $data["cn"]="Tester 1";
> $data["objectclass"][0]="account";
> $data["objectclass"][1]="posixAccount";
> $data["objectclass"][2]="top";
> $data["userpassword"]="";
> $data["loginshell"]="/usr/local/bin/bash";
> $data["uidnumber"]=3100;
> $data["gidnumber"]=3100;
> $data["homedirectory"]="/home/tester";
> $data["gecos"]="Tester 1";
>
> // Before ldap_add(), should check the user already exists or not
> if(!ldap_add($ldapconn,"uid=tester, ou=People, dc=aitc, dc=com,
> dc=tw", $data)){
> echo "There is a problem to create the account\n";
> echo "Please contact your administrator!\n";
> exit;
> }else{
> echo "account creation successfully";
> }
> ldap_close($ldapconn);
> ?>
>
> Does anyone know what's wrong with it?
> I use openldap mount in freebsd
>
> Thanks in advance.
>
> -jiing-

Reply With Quote
  #3 (permalink)  
Old 01-31-2005
Steve
 
Posts: n/a
Default Re: cannot ldapadd in freebsd prompt, but ldap_add() in php is ok?

Steve wrote:
> jiing wrote:
>
>> under freebsd prompt, I typed
>> ldapadd -f tester.ldif -x -D "uid=tester, ou=People, dc=aitc, dc=com,
>> dc=tw" -w orson

You're also trying to bind to the directory using the credentials of the
user that you want to add, as opposed to root, which you're using in the
php example.


>> then ldap_bind: Invalid credentials (49)
>> using whoami, I am root, so I think I have the right to do that
>> I use ldapsearch to search other entries is ok.
>>
>> my tester.ldif is dn: dc=aitc, dc=com, dc=tw
>> objectClass: top
>> objectClass: account
>> objectClass: posixAccount
>> dc: aitc
>>
>> dn: uid=tester, ou=People, dc=aitc, dc=com, dc=tw
>> cn= Tester

>
> Continuation lines as above need to start with white space.
>
> Steve
>
>>
>>
>> but when I looked at the /usr/local/etc/openldap/slapd.conf
>> , the rootpw is orson (cleartext, I am testing)
>>
>> but when I use php to write some code to add user, it works (I use
>> ldapbrowser to see the added entry)
>>
>> <?php
>> $ldapServer="ldap://192.168.1.211";
>> $ldapPort="389";
>> $ldapconn=ldap_connect($ldapServer,$ldapPort);
>> $ldaprdn="uid=root, ou=People, dc=aitc, dc=com, dc=tw";
>> $ldappass="orson";
>>
>> if($ldapconn){
>> echo "connect to ".$ldapServer." successfully \n<br>";
>> }else{
>> echo "can't connect to LDAP server!\n<br>";
>> }
>> ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
>> if ($ldapconn) {
>> // binding to ldap server to give update access
>> $ldapbind = ldap_bind($ldapconn, $ldaprdn, $ldappass);
>> // verify binding
>> if ($ldapbind) {
>> echo "LDAP binding successful...\n";
>> } else {
>> echo "LDAP binding failed...\n";
>> }
>> }
>> //data preparation
>> //I am not very sure what attribute should be filled
>> $data["uid"]="tester";
>> $data["cn"]="Tester 1";
>> $data["objectclass"][0]="account";
>> $data["objectclass"][1]="posixAccount";
>> $data["objectclass"][2]="top";
>> $data["userpassword"]="";
>> $data["loginshell"]="/usr/local/bin/bash";
>> $data["uidnumber"]=3100;
>> $data["gidnumber"]=3100;
>> $data["homedirectory"]="/home/tester"; $data["gecos"]="Tester 1";
>> // Before ldap_add(), should check the user already exists or not
>> if(!ldap_add($ldapconn,"uid=tester, ou=People, dc=aitc, dc=com,
>> dc=tw", $data)){
>> echo "There is a problem to create the account\n";
>> echo "Please contact your administrator!\n";
>> exit;
>> }else{
>> echo "account creation successfully";
>> }
>> ldap_close($ldapconn);
>> ?>
>>
>> Does anyone know what's wrong with it?
>> I use openldap mount in freebsd
>>
>> Thanks in advance.
>>
>> -jiing-

Reply With Quote
  #4 (permalink)  
Old 02-17-2005
jiing.deng@gmail.com
 
Posts: n/a
Default Re: cannot ldapadd in freebsd prompt, but ldap_add() in php is ok ?

thanks a lot
Steve wrote:
> Steve wrote:
> > jiing wrote:
> >
> >> under freebsd prompt, I typed
> >> ldapadd -f tester.ldif -x -D "uid=tester, ou=People, dc=aitc,

dc=com,
> >> dc=tw" -w orson

> You're also trying to bind to the directory using the credentials of

the
> user that you want to add, as opposed to root, which you're using in

the
> php example.
>
>
> >> then ldap_bind: Invalid credentials (49)
> >> using whoami, I am root, so I think I have the right to do that
> >> I use ldapsearch to search other entries is ok.
> >>
> >> my tester.ldif is dn: dc=aitc, dc=com, dc=tw
> >> objectClass: top
> >> objectClass: account
> >> objectClass: posixAccount
> >> dc: aitc
> >>
> >> dn: uid=tester, ou=People, dc=aitc, dc=com, dc=tw
> >> cn= Tester

> >
> > Continuation lines as above need to start with white space.
> >
> > Steve
> >
> >>
> >>
> >> but when I looked at the /usr/local/etc/openldap/slapd.conf
> >> , the rootpw is orson (cleartext, I am testing)
> >>
> >> but when I use php to write some code to add user, it works (I use
> >> ldapbrowser to see the added entry)
> >>
> >> <?php
> >> $ldapServer="ldap://192.168.1.211";
> >> $ldapPort="389";
> >> $ldapconn=ldap_connect($ldapServer,$ldapPort);
> >> $ldaprdn="uid=root, ou=People, dc=aitc, dc=com, dc=tw";
> >> $ldappass="orson";
> >>
> >> if($ldapconn){
> >> echo "connect to ".$ldapServer." successfully \n<br>";
> >> }else{
> >> echo "can't connect to LDAP server!\n<br>";
> >> }
> >> ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
> >> if ($ldapconn) {
> >> // binding to ldap server to give update access
> >> $ldapbind = ldap_bind($ldapconn, $ldaprdn, $ldappass);
> >> // verify binding
> >> if ($ldapbind) {
> >> echo "LDAP binding successful...\n";
> >> } else {
> >> echo "LDAP binding failed...\n";
> >> }
> >> }
> >> //data preparation
> >> //I am not very sure what attribute should be filled
> >> $data["uid"]="tester";
> >> $data["cn"]="Tester 1";
> >> $data["objectclass"][0]="account";
> >> $data["objectclass"][1]="posixAccount";
> >> $data["objectclass"][2]="top";
> >> $data["userpassword"]="";
> >> $data["loginshell"]="/usr/local/bin/bash";
> >> $data["uidnumber"]=3100;
> >> $data["gidnumber"]=3100;
> >> $data["homedirectory"]="/home/tester";

$data["gecos"]="Tester 1";
> >> // Before ldap_add(), should check the user already exists or

not
> >> if(!ldap_add($ldapconn,"uid=tester, ou=People, dc=aitc, dc=com,
> >> dc=tw", $data)){
> >> echo "There is a problem to create the account\n";
> >> echo "Please contact your administrator!\n";
> >> exit;
> >> }else{
> >> echo "account creation successfully";
> >> }
> >> ldap_close($ldapconn);
> >> ?>
> >>
> >> Does anyone know what's wrong with it?
> >> I use openldap mount in freebsd
> >>
> >> Thanks in advance.
> >>
> >> -jiing-


Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 10:15 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0