Re: [PHP] Problem wit doing ldap_add and modify in same script

2003-02-27 Thread Bill MacAllister


--On Wednesday, February 26, 2003 06:05:20 PM -0500 Jim Greene 
[EMAIL PROTECTED] wrote:

 So you suggest turning the $info into an array...  How would I go
 about using the:

No, I don't suggest turning the $info into any array.  It already is 
an array.  Quoting from the www.php.net documentation:

  An array in PHP is actually an ordered map.

So, in PHPese $foo['key'] is an array reference.

What I suggest is that you need to initialize it before you reuse the 
$info name in a different context.

Bill

 $info[objectClass][0]=posixAccount;
 $info[objectClass][1]=top;
 In the array ? Thanks :)


  On Wed, 2003-02-26 at 17:36, Bill MacAllister wrote:
 Looks to me like a judiciously place $info = array(); would do
 wonders.

 Bill

 --On Wednesday, February 26, 2003 08:23:39 AM -0500 Jim Greene
 [EMAIL PROTECTED] wrote:

  Strange problem: Taking the 2 halfs of the scripts (the section to
  update uidNumber and the one to add the user) and combining them
  causes an error:
  Fatal error: ldap_add() [http://www.php.net/function.ldap-add]:
  Unknown attribute in the data in /home/jwgreene/ldap-add.php on
  line 68
 
  Yes doing them as 2 seperate scripts works fine. I did read
  something about not being able to do a modify, and add in the same
  statment, so I do a ldap_unbind after the completion of the first.
  Still does the same thing. Any help would be appreciated.. Thanks
 
 
  ?php
 
  // LDAP variables
  $ldaphost = ldap.server;  // your ldap servers
  $ldapport = 389; // your ldap server's port number
  $ldaprdn  = cn=Directory Manager; // ldap rdn or dn
  $ldappass = test123;  // associated password
  $dn2=uid=default, ou=Users, dc=megalink, dc=net;
 
  // Connecting to LDAP
  $ldapconn = ldap_connect( $ldaphost, $ldapport )
  or die(Could not connect to LDAP server.);
 
  // connect to ldap server
 
  if ($ldapconn) {
 
  // binding to ldap server
  $ldapbind = ldap_bind($ldapconn, $ldaprdn, $ldappass);
 
  // verify binding
  if ($ldapbind) {
  echo LDAP bind successful...\n;
  $result=ldap_search($ldapconn,ou=Users,dc=megalink,dc=net
  , u id=default);
  $info = ldap_get_entries($ldapconn, $result);
  $defaultUid = $info[0][uidnumber][0];
  //print $defaultUid;
  //print $info[0][uidnumber][0];
  $newUid=$defaultUid+1;
  print $newUid\n;
  $newinfo[uidNumber]=$newUid;
  ldap_modify($ldapconn,$dn2,$newinfo);
  echo LDAP Modify successful...\n;
  ldap_unbind($ldapconn);
 
  } else {
  echo LDAP bind failed...;
  }
 
  }
  //Second half of script *works by itself*
  $dn=cn=Directory Manager;
  $bindPassword = test123;
  $mySalt = substr(
  ereg_replace([^a-zA-Z0-9./],,
  crypt(rand(1000,), rand(10,99))),
  2, 2);
  $password = crypt(test123,$mySalt);
 
  $info[loginShell]=/bin/false;
  $info[uidNumber]=1002;
  $info[gidNumber]=100;
  $info[objectClass][0]=posixAccount;
  $info[objectClass][1]=top;
  $info[uid]=test2;
  $info[gecos]=test;
  $info[cn]=test2;
  $info[homeDirectory]=/home/test1;
  $info[userPassword]={crypt}test123;
  if (($ldap = ldap_connect(ldap.server,389))) {
  echo Bind Good...\n;
  }
  else {
  echo Connection Failed...\n;
  }
  if (($res = @ldap_bind($ldap, $dn, $bindPassword))) {
  ldap_add($ldap, uid=test2, ou=Users, dc=megalink, dc=net, $info);
  echo User Added...\n;
  }
  else {
  echo Addition Failed...\n;
  }
  ?
 
  Jim G
 
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 



 +
 | Bill MacAllister
 | 14219 Auburn Road
 | Grass Valley, CA 95949
 | Phone: 530-272-8555
 --
 [EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL 
 PROTECTED]@[EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL 
 PROTECTED]@[EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL PROTECTED]@
 Jim Greene
 Unix Systems Administrator / Security Engineer
 Oxford Networks
 www.oxfordnetworks.com
 Dial-Up - Colo - Web Hosting - Bandwidth
 [EMAIL PROTECTED]

 Working with UNIX is like wrestling a worthy
 opponent. Working with Windows is like attacking
 a small whining child who is carrying a .38.

 [EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL 
 PROTECTED]@[EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL 
 PROTECTED]@[EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL PROTECTED]@





+
| Bill MacAllister
| 14219 Auburn Road
| Grass Valley, CA 95949
| Phone: 530-272-8555

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Problem wit doing ldap_add and modify in same script

2003-02-26 Thread Jim Greene
Strange problem: Taking the 2 halfs of the scripts (the section to update uidNumber 
and the one to add the user) and combining them causes
an error:
Fatal error: ldap_add() [http://www.php.net/function.ldap-add]: Unknown attribute in 
the data in /home/jwgreene/ldap-add.php on line 68

Yes doing them as 2 seperate scripts works fine. I did read something about not being 
able to do a modify, and add in the same statment, so I do a ldap_unbind after the 
completion
of the first. Still does the same thing. Any help would be appreciated.. Thanks


?php

// LDAP variables
$ldaphost = ldap.server;  // your ldap servers
$ldapport = 389; // your ldap server's port number
$ldaprdn  = cn=Directory Manager; // ldap rdn or dn
$ldappass = test123;  // associated password
$dn2=uid=default, ou=Users, dc=megalink, dc=net;

// Connecting to LDAP
$ldapconn = ldap_connect( $ldaphost, $ldapport )
or die(Could not connect to LDAP server.);

// connect to ldap server

if ($ldapconn) {

// binding to ldap server
$ldapbind = ldap_bind($ldapconn, $ldaprdn, $ldappass);

// verify binding
if ($ldapbind) {
echo LDAP bind successful...\n;
$result=ldap_search($ldapconn,ou=Users,dc=megalink,dc=net, u
id=default);
$info = ldap_get_entries($ldapconn, $result);
$defaultUid = $info[0][uidnumber][0];
//print $defaultUid;
//print $info[0][uidnumber][0];
$newUid=$defaultUid+1;
print $newUid\n;
$newinfo[uidNumber]=$newUid;
ldap_modify($ldapconn,$dn2,$newinfo);
echo LDAP Modify successful...\n;
ldap_unbind($ldapconn);

} else {
echo LDAP bind failed...;
}

}
//Second half of script *works by itself*
$dn=cn=Directory Manager;
$bindPassword = test123;
$mySalt = substr(
ereg_replace([^a-zA-Z0-9./],,
crypt(rand(1000,), rand(10,99))),
2, 2);
$password = crypt(test123,$mySalt);

$info[loginShell]=/bin/false;
$info[uidNumber]=1002;
$info[gidNumber]=100;
$info[objectClass][0]=posixAccount;
$info[objectClass][1]=top;
$info[uid]=test2;
$info[gecos]=test;
$info[cn]=test2;
$info[homeDirectory]=/home/test1;
$info[userPassword]={crypt}test123;
if (($ldap = ldap_connect(ldap.server,389))) {
echo Bind Good...\n;
}
else {
echo Connection Failed...\n;
}
if (($res = @ldap_bind($ldap, $dn, $bindPassword))) {
ldap_add($ldap, uid=test2, ou=Users, dc=megalink, dc=net, $info);
echo User Added...\n;
}
else {
echo Addition Failed...\n;
}
?

Jim G


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Problem wit doing ldap_add and modify in same script

2003-02-26 Thread Bill MacAllister
Looks to me like a judiciously place $info = array(); would do wonders.

Bill

--On Wednesday, February 26, 2003 08:23:39 AM -0500 Jim Greene 
[EMAIL PROTECTED] wrote:

 Strange problem: Taking the 2 halfs of the scripts (the section to
 update uidNumber and the one to add the user) and combining them
 causes an error:
 Fatal error: ldap_add() [http://www.php.net/function.ldap-add]:
 Unknown attribute in the data in /home/jwgreene/ldap-add.php on line
 68

 Yes doing them as 2 seperate scripts works fine. I did read something
 about not being able to do a modify, and add in the same statment, so
 I do a ldap_unbind after the completion of the first. Still does the
 same thing. Any help would be appreciated.. Thanks


 ?php

 // LDAP variables
 $ldaphost = ldap.server;  // your ldap servers
 $ldapport = 389; // your ldap server's port number
 $ldaprdn  = cn=Directory Manager; // ldap rdn or dn
 $ldappass = test123;  // associated password
 $dn2=uid=default, ou=Users, dc=megalink, dc=net;

 // Connecting to LDAP
 $ldapconn = ldap_connect( $ldaphost, $ldapport )
 or die(Could not connect to LDAP server.);

 // connect to ldap server

 if ($ldapconn) {

 // binding to ldap server
 $ldapbind = ldap_bind($ldapconn, $ldaprdn, $ldappass);

 // verify binding
 if ($ldapbind) {
 echo LDAP bind successful...\n;
 $result=ldap_search($ldapconn,ou=Users,dc=megalink,dc=net,
 u id=default);
 $info = ldap_get_entries($ldapconn, $result);
 $defaultUid = $info[0][uidnumber][0];
 //print $defaultUid;
 //print $info[0][uidnumber][0];
 $newUid=$defaultUid+1;
 print $newUid\n;
 $newinfo[uidNumber]=$newUid;
 ldap_modify($ldapconn,$dn2,$newinfo);
 echo LDAP Modify successful...\n;
 ldap_unbind($ldapconn);

 } else {
 echo LDAP bind failed...;
 }

 }
 //Second half of script *works by itself*
 $dn=cn=Directory Manager;
 $bindPassword = test123;
 $mySalt = substr(
 ereg_replace([^a-zA-Z0-9./],,
 crypt(rand(1000,), rand(10,99))),
 2, 2);
 $password = crypt(test123,$mySalt);

 $info[loginShell]=/bin/false;
 $info[uidNumber]=1002;
 $info[gidNumber]=100;
 $info[objectClass][0]=posixAccount;
 $info[objectClass][1]=top;
 $info[uid]=test2;
 $info[gecos]=test;
 $info[cn]=test2;
 $info[homeDirectory]=/home/test1;
 $info[userPassword]={crypt}test123;
 if (($ldap = ldap_connect(ldap.server,389))) {
 echo Bind Good...\n;
 }
 else {
 echo Connection Failed...\n;
 }
 if (($res = @ldap_bind($ldap, $dn, $bindPassword))) {
 ldap_add($ldap, uid=test2, ou=Users, dc=megalink, dc=net, $info);
 echo User Added...\n;
 }
 else {
 echo Addition Failed...\n;
 }
 ?

 Jim G


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php




+
| Bill MacAllister
| 14219 Auburn Road
| Grass Valley, CA 95949
| Phone: 530-272-8555

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php