LDAP Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesLDAP Programming
The ASP Free website provides in-depth information on the latest developer tools available from Microsoft. Our cadre of writers, highly experienced industry experts, reveals the best ways to use established technologies as well as new and emerging technologies. Our coverage of Microsoft's development and administration technologies is among the most respected in the IT industry today.

ASP Free and Iron Speed Designer are giving away $5,500+ in FREE licenses. Iron Speed's RAD CASE toolset can save up to 80% of your coding time. One free license per week, one perpetual license per month!
Download and Activate to enter!

Intel® Graphics Performance Analyzers is a powerful tool suite for analyzing and optimizing your games, media, and graphics-intensive applications. Used by some of the best developers on the planet, Intel GPA lets you maximize your app’s performance.


Tutorials
| Forums

Download to Enter
| Contest Rules

DOWNLOAD INTEL® GPA FOR FREE

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rating: Thread Rating: 10 votes, 5.00 average. Display Modes
 
Unread Dev Shed Forums Sponsor:
  #91  
Old December 8th, 2004, 08:15 AM
Zipi Zipi is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Location: Imatra, Finland
Posts: 7 Zipi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally Posted by MatthewClark
I forgot - exec() and system() never work. They always belch out "Unable to fork" errors.


You must give execute permissions to cmd.exe as well to get those functions to work.

Reply With Quote
  #92  
Old February 16th, 2005, 01:53 PM
phredbroughton phredbroughton is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Location: Birmingham Alabama
Posts: 1 phredbroughton User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 38 m 3 sec
Reputation Power: 0
Wink Success! (Sorta)

After following this loooong thread and following all of the great advice I found here and at php.net, I was like many able to connect to our server with SSL and bind with a users id and password, but I kept recieving an insufficient access error when trying to modify the password. After reading the info from Microsoft at http://support.microsoft.com/?kbid=269190 that I found posted here it hit me.
From MS page:
"There are two possible ways to modify the unicodePwd attribute. The first is similar to a normal "user change password" operation. In this case, the modify request must contain both a delete and an add operation. The delete operation must contain the current password with quotes around it. The add operation must contain the desired new password with quotes around it.

The second way to modify this attribute is analogous to an administrator resetting a password for a user. In order to do this, the client must bind as a user with sufficient permissions to modify another user's password. This modify request should contain a single replace operation with the new desired password surrounded by quotes. If the client has sufficient permissions, this password become the new password, regardless of what the old password was."

I was trying to use the posted code to modify the users password while binding as that user. According to this, this can only be done if the command contains both a delete and an add command. Not knowing how to do that, I tried option 2. I used an administrator id and password to bind to AD and bingo. User password modified.
Unless someone can tell me how to perform the delete/add command as MS states for option 1, it seems that I will have to use a method of first verifying that the user is valid by binding to AD, then if this is OK, bind with a user/password that has sufficient rights to reset passwords and modify using the code presented here. I usually store all system settings in my SQL database and I'm not sure I like having this user/password stored there, but it my be necessary to get this done.

Here is my test script complete with lots of echo feedback. Using this I am able to change the users password and validate the change. If run a second time it will fail as the password has changed. Modify the password variables and it will run again.
Notes:
If you screw up your variables and pass a blank auth user even though the password is there, ldap_bind() will succeed but it is an anonymous bind.

If you re-run this enough times with the wrong password, you will lock the account out if this is enabled in your domain.

Script is running on a RHES3 box that has been converted to CENTOS.
PHP 4.3.2
OpenSSL 0.9.7a
openldap-2.0.27-17
Windows 2000 SBS
Certificate services on a separate Win2000 server
RootCA exported as 64bit key and imported into openssl certs on linux box as per notes at http://us3.php.net/manual/en/function.ldap-connect.php

Hope this helps someone else :-)
Phred

PHP Code:
<?PHP
/*** Variable Settings ***/
$uid 'Testing';
$userbindDN 'testing@domain.com';
//existing password
$userbindPass '1234567';
// new password
$passwd1 'changeme';
$passwd2 'changeme';
// administrative bind user
$authbindDN 'someadminuser@domain.com';
$authbindPass '1234567';
// ldap server info
$ldapserver 'ldapserver.domain.com';
$baseDN 'DC=domain,DC=com';
/**************************/

/************* Main Script Code ***************/
/**  Connect SSL to Ldap Server **/
echo "Connecting SSL to server<br>";
$ldap ldap_connect('ldaps://'.$ldapserver,686);
ldap_set_option($ldapLDAP_OPT_PROTOCOL_VERSION3);
ldap_set_option($ldapLDAP_OPT_REFERRALS0);
/**  Test connection by using anonymous bind **/
echo "Testing anonymous bind to server<br>";
ldap_bind($ldap);
if (
ldap_errno($ldap) !== 0)
{
    exit(
'Could not connect to LDAP server - '.ldap_error($ldap));
}
/**  Now try to bind with the username and password **/
echo "Now binding using user info<br>";
ldap_bind($ldap$userbindDN$userbindPass);
if (
ldap_errno($ldap) !== 0)
{
    exit(
'ERROR: User ID/Password Invalid - '.ldap_error($ldap));
}
/**  We got this far, let's bind with an admin user **/
echo "Now binding using admin info<br>";
ldap_bind($ldap$authbindDN$authbindPass);
if (
ldap_errno($ldap) !== 0)
{
     exit(
'ERROR: Unable to bind with admin user info - '.ldap_error($ldap));
}
$searchResults ldap_search($ldap$baseDN'CN='.$uid);
// no matching records
$info ldap_get_entries($ldap$searchResults);
if (
$searchResults === false)
{
  exit(
'User ($uid) not found in AD');
}
if (!
is_resource($searchResults))
{
  exit(
'Error in search results.');
}
$entry ldap_first_entry($ldap$searchResults);
if (!
is_resource($entry))
{
    exit(
'Couldn\'t get entry');
}
$userDn ldap_get_dn($ldap$entry);
// Check Pwds not really used in this script but...
if ($passwd1 == $passwd2){
    
// prepare data
    
$newPassword $passwd1;
    
$newPassword "\"" $newPassword "\"";
    
$len strlen($newPassword);
    for(
$i 0$i $len$i++)
  {
        
$newPassw .= "{$newPassword{$i}}\000";
  }
    
$newPassword $newPassw;
    
$userdata['unicodePwd'] = $newPassword;

  echo 
"<------------ Changing Password --------------><br><br>";
  echo 
"Username = ".$uid."<br>";
  echo 
"User login ID = ".$userbindDN."<br>";
  echo 
"User DN = $userDn<br>";
  
$result ldap_mod_replace($ldap$userDn $userdata);
    if(
$result)
  {
       echo 
"User modified!<br>" ;
    }else{
       echo 
"There was a problem!<br>";
       echo 
ldap_error($ldap)."<br>";
  }
    
/**  Now try to bind with the username and new password to insure change**/
    
echo "Now testing new password to insure change<br>";
    
ldap_bind($ldap$userbindDN$passwd1);
    if (
ldap_errno($ldap) !== 0)
    {
        exit(
'ERROR: User ID/Password Invalid - '.ldap_error($ldap));
    }else{
        echo 
"Password Verified OK. Password change complete<br>";
    }
}
?>
Comments on this post
Viper_SB agrees!

Reply With Quote
  #93  
Old May 26th, 2005, 05:07 PM
ebeyrent ebeyrent is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: New Hampshire
Posts: 9 ebeyrent User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 7 sec
Reputation Power: 0
The above script did not work for us initially. Then we realized that we were attempting to change the password on AD to a non-allowed syntax, which gave us a "Server unwilling to perform" error.

Once we modified the password to contain a capital letter and a number, everything worked as it should.

I hope that this information helps someone else out there!
Comments on this post
Viper_SB agrees: intresting thanks for the tip

Reply With Quote
  #94  
Old May 26th, 2005, 06:19 PM
MatthewClark's Avatar
MatthewClark MatthewClark is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: San Angelo, Texas (USA)
Posts: 286 MatthewClark User rank is Corporal (100 - 500 Reputation Level)MatthewClark User rank is Corporal (100 - 500 Reputation Level)MatthewClark User rank is Corporal (100 - 500 Reputation Level)MatthewClark User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 14 h 2 m 39 sec
Reputation Power: 11
Send a message via ICQ to MatthewClark Send a message via AIM to MatthewClark Send a message via Yahoo to MatthewClark
It's been a while since I have worked with PHP and Active Directory, and after bashing my head on this subject for a while, I haven't done much here either.

I think now I'll dust off my old PHP and AD scripts and see if I can make them work...

Reply With Quote
  #95  
Old June 7th, 2005, 06:24 AM
giorg giorg is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Posts: 7 giorg User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 40 m 45 sec
Reputation Power: 0
Quote:
Originally Posted by phredbroughton
Certificate services on a separate Win2000 server
RootCA exported as 64bit key and imported into openssl certs on linux box as per notes at http://us3.php.net/manual/en/function.ldap-connect.php

Hope this helps someone else :-)
Phred

[/PHP]


Hi,
maybe I am the only one, but I definitely not able to extract any certificate from AD and also the other thing I dont understand is why to use openldap while I've to connect as a client....
Thanks for any help

Reply With Quote
  #96  
Old June 7th, 2005, 06:52 AM
pabloj's Avatar
pabloj pabloj is offline
Modding: Oracle MsSQL Firebird
Dev Shed God 8th Plane (8500 - 8999 posts)
 
Join Date: Jun 2001
Location: Outside US
Posts: 8,526 pabloj User rank is Colonel (50000 - 60000 Reputation Level)pabloj User rank is Colonel (50000 - 60000 Reputation Level)pabloj User rank is Colonel (50000 - 60000 Reputation Level)pabloj User rank is Colonel (50000 - 60000 Reputation Level)pabloj User rank is Colonel (50000 - 60000 Reputation Level)pabloj User rank is Colonel (50000 - 60000 Reputation Level)pabloj User rank is Colonel (50000 - 60000 Reputation Level)pabloj User rank is Colonel (50000 - 60000 Reputation Level)pabloj User rank is Colonel (50000 - 60000 Reputation Level)pabloj User rank is Colonel (50000 - 60000 Reputation Level)pabloj User rank is Colonel (50000 - 60000 Reputation Level)pabloj User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 1 Day 3 h 1 m 2 sec
Reputation Power: 534
Quote:
Originally Posted by giorg
why to use openldap while I've to connect as a client....

because AD exposes an LDAP interface, so a php client connects through it.

Reply With Quote
  #97  
Old June 7th, 2005, 11:58 AM
giorg giorg is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Posts: 7 giorg User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 40 m 45 sec
Reputation Power: 0
Quote:
Originally Posted by pabloj
because AD exposes an LDAP interface, so a php client connects through it.

Exactly! A php client... and LDAP is a standard protocol... so why to use a server like OpenLDAP? Maybe my question is not clear...

Reply With Quote
  #98  
Old June 7th, 2005, 12:07 PM
Viper_SB's Avatar
Viper_SB Viper_SB is offline
Psycho Canadian
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Jan 2001
Location: Canada
Posts: 4,836 Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 15 h 32 m 54 sec
Reputation Power: 633
Quote:
Originally Posted by giorg
Exactly! A php client... and LDAP is a standard protocol... so why to use a server like OpenLDAP? Maybe my question is not clear...

nope I don't understand it
__________________
Miscellaneous Software
Viper_SB
Developershed E-Support


Anyone else play chess?
Challenge me

Reply With Quote
  #99  
Old June 7th, 2005, 01:08 PM
giorg giorg is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Posts: 7 giorg User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 40 m 45 sec
Reputation Power: 0
Quote:
Originally Posted by Viper_SB
nope I don't understand it

ok I'll try to explain it better: the AD is suppose to be the server in thhis case, right? Exposing ldaps is what is doing, right? A server which is giving a service... and when I connect to it I am a client ok? So, if (from my linux box) I want to connect to this server which is exposing ldaps, why should I configure another ldap server (OpenLDAP) on my box? Maybe this time I've been a little more clear...

Reply With Quote
  #100  
Old June 7th, 2005, 03:17 PM
Viper_SB's Avatar
Viper_SB Viper_SB is offline
Psycho Canadian
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Jan 2001
Location: Canada
Posts: 4,836 Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 15 h 32 m 54 sec
Reputation Power: 633
If I understand you correctly, I don't think you need openldap running to access AD. Openldap is more for non windows systems, or those that perfer to use a free ldap server.

Reply With Quote
  #101  
Old June 7th, 2005, 04:40 PM
pabloj's Avatar
pabloj pabloj is offline
Modding: Oracle MsSQL Firebird
Dev Shed God 8th Plane (8500 - 8999 posts)
 
Join Date: Jun 2001
Location: Outside US
Posts: 8,526 pabloj User rank is Colonel (50000 - 60000 Reputation Level)pabloj User rank is Colonel (50000 - 60000 Reputation Level)pabloj User rank is Colonel (50000 - 60000 Reputation Level)pabloj User rank is Colonel (50000 - 60000 Reputation Level)pabloj User rank is Colonel (50000 - 60000 Reputation Level)pabloj User rank is Colonel (50000 - 60000 Reputation Level)pabloj User rank is Colonel (50000 - 60000 Reputation Level)pabloj User rank is Colonel (50000 - 60000 Reputation Level)pabloj User rank is Colonel (50000 - 60000 Reputation Level)pabloj User rank is Colonel (50000 - 60000 Reputation Level)pabloj User rank is Colonel (50000 - 60000 Reputation Level)pabloj User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 1 Day 3 h 1 m 2 sec
Reputation Power: 534
Php uses the OpenLDAP CLIENT library to connect to the LDAP interface exposed by ActiveDirectory.

Reply With Quote
  #102  
Old June 7th, 2005, 10:45 PM
RobinHoo RobinHoo is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Posts: 2 RobinHoo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 45 m 29 sec
Reputation Power: 0
It's impressed php code, but I don't think that's good solution. As the result of Microsoft not willing to open source code to public, your code works today not means work tomorrow. My suggestion is that install a php on windows platform. Call DOS command "net user" to make it done. very easy! just use

system("net user $username $newpassword /domain");

You see!

Sometime, we just need our work done, not use certain technology. Is that true?

Reply With Quote
  #103  
Old June 8th, 2005, 02:54 AM
giorg giorg is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Posts: 7 giorg User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 40 m 45 sec
Reputation Power: 0
Quote:
Originally Posted by RobinHoo
Sometime, we just need our work done, not use certain technology. Is that true?

This is absolutely true, the problem is I am developing a centralized system on a linux server, and now is too late to move under windows. But I still don't get why I have to configure a new openldap server while I'm a client for AD. Isn't enough just to use the php ldap library? At the end, is there anyone who can gimme any reference/how to on the CA side? Generating certificate, exporting, and so on?
Thank you

Reply With Quote
  #104  
Old June 8th, 2005, 03:41 AM
pabloj's Avatar
pabloj pabloj is offline
Modding: Oracle MsSQL Firebird
Dev Shed God 8th Plane (8500 - 8999 posts)
 
Join Date: Jun 2001
Location: Outside US
Posts: 8,526 pabloj User rank is Colonel (50000 - 60000 Reputation Level)pabloj User rank is Colonel (50000 - 60000 Reputation Level)pabloj User rank is Colonel (50000 - 60000 Reputation Level)pabloj User rank is Colonel (50000 - 60000 Reputation Level)pabloj User rank is Colonel (50000 - 60000 Reputation Level)pabloj User rank is Colonel (50000 - 60000 Reputation Level)pabloj User rank is Colonel (50000 - 60000 Reputation Level)pabloj User rank is Colonel (50000 - 60000 Reputation Level)pabloj User rank is Colonel (50000 - 60000 Reputation Level)pabloj User rank is Colonel (50000 - 60000 Reputation Level)pabloj User rank is Colonel (50000 - 60000 Reputation Level)pabloj User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 1 Day 3 h 1 m 2 sec
Reputation Power: 534
The php ldap library needs Openldap client library to compile and run, it might be simpler to install the whole openldap server but I doubt you'll need to confugure and run it.

Reply With Quote
  #105  
Old June 8th, 2005, 05:48 AM
giorg giorg is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Posts: 7 giorg User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 40 m 45 sec
Reputation Power: 0
Quote:
Originally Posted by pabloj
The php ldap library needs Openldap client library to compile and run, it might be simpler to install the whole openldap server but I doubt you'll need to confugure and run it.


Now I got it, thank you pabloj. Following the "tutorial" on http://us2.php.net/manual/en/function.ldap-connect.php, my situation now is that when I try to verify the exported certificate I get:

error 20 at 0 depth lookup:unable to get local issuer certificate

This is of course 'cause openldap cannot recognize my AD server as a trusted root enterprise CA, but I don't how to say "trust it"!

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesLDAP Programming > Modifying Active Directory passwords through PHP and IIS


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.

© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 2 - Follow our Sitemap