Going to sound strange, but here i go.
We use Windows 2000 AD for everything. However, we are also running
XAMPP (basically Apache, MySQL, PHP for windows) on a Windows box for
our Intranet. I have a few applications that need to authenticate via
AD from PHP and every example I see uses the LDAP functions built into
PHP.
I cannot query our AD server via LDAP. If I type
ldap://domaincontrolle r it fails, so of course, when I try to use the
LDAP function in PHP they fail.
How do I get LDAP running on AD? I'm sure I'm missing something simple,
but I'm very frustrated.
BTW, I've started coding another app that queries AD using ASP and it
is soooo easy it hurts.
Jul 17 '05
15 12669
I cannot believe the answer to my problem was so simple...
The code I was using was correct and only missing one thing:
username had to have @domain.com added on. In my ldap_bind() i was
passing
ldap_bind($ldap connect, "username", "password")
and it has to be
ldap_bind($ldap connect, "us******@mydom ain.com", "password")
Uggh. Thank you to everyone that replied to this.
Thanks for the code. As I was testing it on our systems here I found
that if the username in the second attempt to connect was blank, it
would respond as if it succeeded. So it might be best to change the
second if !$bind to if ( (!bind) && ($ldap_user_dn= ="") )
Sacs wrote: This is on Linux, don't know anything about Windoze, so this might be
different for you!
e.g.
$ldap_server = "ad_controller. company.com"; $ldap_base_dn = "ou=Users,dc=co mpany,dc=com"; $ldap_def_user = "cn=ldapquery,o u=Users,dc=comp any,dc=com"; $ldap_def_pass = "password";
$Username = "dumbuser"; $Passwowd = "abc123";
$ld_connect = @ldap_connect($ ldap_server); $bind = @ldap_bind($ld_ connect, $ldap_def_user, $ldap_def_pass) ; if(!$bind) { print "Eeek! Cannot bind to ldap server."; exit; }
$ld_filter = '(sAMAccountNam e='. $Username .')'; $ld_data = array('dn'); $ld_sr = ldap_search($ld _connect, $ldap_base_dn, $ld_filter,
$ld_data); $ld_info = ldap_get_entrie s($ld_connect, $ld_sr); $ldap_user_dn = $ld_info[0]['dn'];
$bind = @ldap_bind($ld_ connect, $ldap_user_dn, $Password);
if(!$bind) { print "Invalid login, get lost"; exit; } else { print "Logged in Ok!"; }
jd142 wrote: Thanks for the code. As I was testing it on our systems here I found that if the username in the second attempt to connect was blank, it would respond as if it succeeded. So it might be best to change the second if !$bind to if ( (!bind) && ($ldap_user_dn= ="") )
Hmm, intersting. Was that against Active Directory or a real LDAP
server? AD isn't meant to allow unauthenticated searches, and it
shouldn't return a bind resource on an invalid bind attempt. *shrug*
Watch out when getting the GUID from AD, it's a pig to deal with, 16
byte octect string, with NULLs, so you can't treat it as a string. It is
the unique identifier for an AD object, thus usefull for treating AD
as an authoritative source for user info.
Glad to have helped!
Sacs
Sacs wrote:
This is on Linux, don't know anything about Windoze, so this might be
different for you!
e.g.
$ldap_serve r = "ad_controller. company.com"; $ldap_base_ dn = "ou=Users,dc=co mpany,dc=com"; $ldap_def_use r = "cn=ldapquery,o u=Users,dc=comp any,dc=com"; $ldap_def_pas s = "password";
$Username = "dumbuser"; $Passwowd = "abc123";
$ld_connect = @ldap_connect($ ldap_server); $bind = @ldap_bind($ld_ connect, $ldap_def_user, $ldap_def_pass) ; if(!$bind) { print "Eeek! Cannot bind to ldap server."; exit; }
$ld_filter = '(sAMAccountNam e='. $Username .')'; $ld_data = array('dn'); $ld_sr = ldap_search($ld _connect, $ldap_base_dn, $ld_filter,
$ld_data);
$ld_info = ldap_get_entrie s($ld_connect, $ld_sr); $ldap_user_ dn = $ld_info[0]['dn'];
$bind = @ldap_bind($ld_ connect, $ldap_user_dn, $Password);
if(!$bind) { print "Invalid login, get lost"; exit; } else { print "Logged in Ok!"; }
Bonegavel wrote: I cannot believe the answer to my problem was so simple...
The code I was using was correct and only missing one thing:
username had to have @domain.com added on. In my ldap_bind() i was passing
ldap_bind($ldap connect, "username", "password")
and it has to be
ldap_bind($ldap connect, "us******@mydom ain.com", "password")
Uggh. Thank you to everyone that replied to this.
Glad to hear you've nailed it! Personally I found this LDAP/AD stuff
the hardest thing I've ever had to grok. Once it works though, it is SO
usefull!
Sacs
Hey!
I am working on the same thing and I having a huge problem here with
the searching of my ad structure..
i am able to get my script to run far enough to bind but then the
search fails:
LDAP query test
Connecting ...connect result is Resource id #3
Binding ...Bind result is 1
Searching ...
Warning: ldap_search(): Search: Partial results and referral received
in /home/engage/public_html/authenticate.ph p on line 47
Search result is
here is my script:
<?php
echo "<h3>LDAP query test</h3>";
echo "Connecting ...";
$ds=ldap_connec t("ads.iu.edu") ; // must be a valid LDAP server!
echo "connect result is " . $ds . "<br />";
$ldaprdn = 'xxxxx';
$ldappass = 'xxxx';
//set ldap option
ldap_set_option ($ds, LDAP_OPT_REFERR ALS, 0);
if ($ds) {
echo "Binding ...";
$r=ldap_bind($d s, $ldaprdn, $ldappass);
echo "Bind result is " . $r . "<br />";
echo "Searching ...";
$username="msgr eenf";
$dn = "dc=ads, dc=iu, dc=edu";
$filter="(cn=$u sername)";
$justthese = array("srname", "givenname" , "mail", "memberOf") ;
//echo $ds. " ". $dn . " " . $filter . " " . $justthese;
$sr=ldap_search ($ds, $dn, $filter, $justthese);
echo "Search result is " . $sr . "<br />";
echo "Number of entires returned is " . ldap_count_entr ies($ds, $sr)
..
"<br />";
echo "Getting entries ...<p>";
$info = ldap_get_entrie s($ds, $sr);
echo "Data for " . $info["count"] . " items returned:<p>";
for ($i=0; $i<$info["count"]; $i++) {
echo "dn is: " . $info[$i]["dn"] . "<br />";
echo "first cn entry is: " . $info[$i]["cn"][0] . "<br />";
echo "first email entry is: " . $info[$i]["mail"][0] . "<br
/><hr />";
}
echo "Closing connection";
ldap_close($ds) ;
} else {
echo "<h4>Unable to connect to LDAP server</h4>";
}
//header to redirect at the end
// echo("Output: ".$result);
header("Locatio n: http://www.indiana.edu/~engage/index.php");
?>
Sacs wrote: Bonegavel wrote: I cannot believe the answer to my problem was so simple...
The code I was using was correct and only missing one thing:
username had to have @domain.com added on. In my ldap_bind() i was passing
ldap_bind($ldap connect, "username", "password")
and it has to be
ldap_bind($ldap connect, "us******@mydom ain.com", "password")
Uggh. Thank you to everyone that replied to this.
Glad to hear you've nailed it! Personally I found this LDAP/AD stuff
the hardest thing I've ever had to grok. Once it works though, it is
SO usefull!
Sacs
Mitch wrote: Hey!
I am working on the same thing and I having a huge problem here with the searching of my ad structure.. i am able to get my script to run far enough to bind but then the search fails: LDAP query test Connecting ...connect result is Resource id #3 Binding ...Bind result is 1 Searching ... Warning: ldap_search(): Search: Partial results and referral received in /home/engage/public_html/authenticate.ph p on line 47 Search result is
here is my script:
<?php echo "<h3>LDAP query test</h3>"; echo "Connecting ..."; $ds=ldap_connec t("ads.iu.edu") ; // must be a valid LDAP server! echo "connect result is " . $ds . "<br />"; $ldaprdn = 'xxxxx'; $ldappass = 'xxxx';
//set ldap option ldap_set_option ($ds, LDAP_OPT_REFERR ALS, 0);
if ($ds) { echo "Binding ..."; $r=ldap_bind($d s, $ldaprdn, $ldappass); echo "Bind result is " . $r . "<br />";
echo "Searching ..."; $username="msgr eenf"; $dn = "dc=ads, dc=iu, dc=edu"; $filter="(cn=$u sername)"; $justthese = array("srname", "givenname" , "mail", "memberOf") ; //echo $ds. " ". $dn . " " . $filter . " " . $justthese; $sr=ldap_search ($ds, $dn, $filter, $justthese); echo "Search result is " . $sr . "<br />";
echo "Number of entires returned is " . ldap_count_entr ies($ds, $sr) . "<br />";
echo "Getting entries ...<p>"; $info = ldap_get_entrie s($ds, $sr); echo "Data for " . $info["count"] . " items returned:<p>";
for ($i=0; $i<$info["count"]; $i++) { echo "dn is: " . $info[$i]["dn"] . "<br />"; echo "first cn entry is: " . $info[$i]["cn"][0] . "<br />"; echo "first email entry is: " . $info[$i]["mail"][0] . "<br /><hr />"; }
echo "Closing connection"; ldap_close($ds) ;
} else { echo "<h4>Unable to connect to LDAP server</h4>"; }
//header to redirect at the end // echo("Output: ".$result); header("Locatio n: http://www.indiana.edu/~engage/index.php");
?>
<snip>
Ok, I got the same results (once I had changed the obvious bits :-). I
changed the line:
$dn = "dc=ads, dc=iu, dc=edu";
to:
$dn = "ou=Domain Users,dc=mycoma ny,dc=co,dc=nz" ;
and it worked!
Try setting the $dn to be the top level organisational unit in you AD.
(Might be "Users" or something - it may be AD not allowing a full search
of the forest)
Sacs This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Renato Neves |
last post by:
The following code is working fine, i can create the user in the Active
Directory and "enable" it.
My problem is that, when i'm trying to authenticate him, i can't get to
work!! The user and pass is correct, but it can't authenticate. If i try
other user created in the AD, it work just fine!!!
<------------------------------------------------------------------------------------------------------------->
< ...
|
by: allenj |
last post by:
DB2 UDB 7.2 WSE
Fixpak 9
Linux Red Hat 7.3
A very strange thing just happened w/ my DB2 server. I am on Linux and
using NIS - the instance owner is in the servers /etc/passwd file.
Suddenly, DB2 would not authenticate any NIS-based logins, but it
*would* authenticate the local non-NIS instance owner. This was
happening not only w/ local connections on the server, but also
|
by: Ram |
last post by:
How to Authenticate NDS server using C#
|
by: B111Gates |
last post by:
OK I know this is a complex question so I will break it up.
I know that SSPI is the prefered method of authentication, however if I
use the sample provide by MS I cannot authenticate across domains.
Sample Here
http://support.microsoft.com/default.aspx?scid=kb;en-us;279815
Article ID : 279815
|
by: ALI-R |
last post by:
I know how to authenticate to a webservice using either of these
ways(Assuming that rService represents the webservice):
1) rService.Credentials = new
System.Net.NetworkCredential("username","password","domainName");
2)rService.Credentials = System.Net.CredentialCache.DefaultCredentials;
My question is that is there a way to authenticate to a user using
WindowsIdentity ???
| |
by: J-T |
last post by:
I need to create a webserivce which is able to talk to the following
components:
1) Another webservice which is written by java and talks to its own backend
database to authenticate the users
2) Directly talk to a sql server database containg a table to store username
and passwords
3) Directoly talks to an Oracle Databse containg a table to store username
and passwords
4) Can query our internal Active Directory to authenticate our
|
by: EricRybarczyk |
last post by:
I am starting a rewrite of an existing Classic ASP web site in ASP.NET 2.0.
The existing ASP application has several types of users, each with a separate
login process (separate login page, separate DB tables, etc). For one of
these user types, the current application has an additional input field
required for login… they have a username, password, and another “location
code” field. Please don’t make me explain or justify this…...
|
by: robert |
last post by:
In a DAV scheme with PROPFIND or GET (PROPFIND /test/ HTTP/1.1) and
Basic AUTH to a MS SharePoint over https server (AUTH required), he
responds 'WWW-Authenticate: NTLM' only:
reply: 'HTTP/1.1 401 Unauthorized\r\n'
header: Content-Length: 1656
header: Content-Type: text/html
header: Server: Microsoft-IIS/6.0
header: WWW-Authenticate: NTLM
header: X-Powered-By: ASP.NET
|
by: fomalhaut |
last post by:
Hi All,
I'm builing an application that requires domain admin access to run,
and I'm trying to allow for the application to be run as a normal user
and allow the user to provide it with a username/password that has the
access.
I have a method that will check if the username/password is correct,
however, it will only authenticate the user running the program...
|
by: Proogeren |
last post by:
I have a problem with a httpwebrequest that I am creating. The request in itself looks correct but using fiddler I see that a www-authentication header is sent along as well. The code is pasted below. I do not add any www-authentication header here so I was wondering if anyone knows how to remove it.
I have used almost 2 days trying to figure this out so help would be highly appreciated.
CORRECT
No proxy-authenticate header is present
no...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |