Skip to content
This repository has been archived by the owner on Jul 24, 2023. It is now read-only.

Operations error on user->save() #818

Open
DarkestSoul1992 opened this issue Mar 12, 2023 · 0 comments
Open

Operations error on user->save() #818

DarkestSoul1992 opened this issue Mar 12, 2023 · 0 comments

Comments

@DarkestSoul1992
Copy link

  • Adldap2 Version: 10.5
  • LDAP Type: Active Directory
  • PHP Version: 8.2.3

Description:

Warning: ldap_add(): Add: Operations error in C:\inetpub\wwwroot\vendor\adldap2\adldap2\src\Connections\Ldap.php on line 354

Steps To Reproduce:

			require $_SERVER['DOCUMENT_ROOT'] . '/vendor/autoload.php';

			// Construct new Adldap instance.
			$ad = new Adldap\Adldap();

			$connectionName = 'wolfnet-computing';

			// Create a configuration array.
			$config = [  
				// An array of your LDAP hosts. You can use either
				// the host name or the IP address of your host.
				'hosts'    => ['xxxx.wolfnet.local'],

				// The base distinguished name of your domain to perform searches upon.
				'base_dn'  => 'dc=wolfnet,dc=local',

				// The account to use for querying / modifying LDAP records. This
				// does not need to be an admin account. This can also
				// be a full distinguished name of the user account.
				'username' => 'xxxx@wolfnet.local',
				'password' => 'xxxx',
				
				// Optional Configuration Options
				'account_suffix'   => '@wolfnet.local',
				'port'             => 636,
				'use_ssl'          => true,
			];
			
			$ad->addProvider($config, $connectionName);
			$ad->setDefaultProvider($connectionName);
			$provider = $ad->getDefaultProvider();
			$username = sanitizeUserData($_POST["user"]);
                        $password = sanitizeUserData($_POST["password"]);
                        $password2 = sanitizeUserData($_POST["password2"]);
                        $group = sanitizeUserData($_POST["group"]);
                        $name = sanitizeUserData($_POST["name"]);
                        $email = sanitizeUserData($_POST["email"]);
                        $jobTitle = sanitizeUserData($_POST["jobTitle"]);
			
			try {
				$user = $provider->make()->user();
				$user->dn = $user->getDnBuilder()->addOu('Users');
				$user->samAccountName = $username;
				$user->cn = $name;
				$user->password = $password;
				$user->mail = $email;
				// Save the user.
				if ($user->save()) {   // << ERROR HERE
					$user->setCompany($siteCompany);
					// Enable the new user (using user account control).
					$user->setUserAccountControl(512);
					if(!$user->save()) {
						echo 'Error saving password';
						exit();
					}
				} else {
					echo $provider->getConnection()->getLastError();
					echo '<br>User couldn\'t be created in AD!<br>';
					exit();
				}
				// All done! An enabled user will be created and is ready for use.
				if ($group == 'admins') {
					$groupObj = $provider->search()->find('Domain Admins');
				} else {
					$groupObj = $provider->search()->find('Domain Users');
				}
				print_r($groupObj);
				if (!$groupObj->addMember($user)) {
					echo 'User wasn\'t added to group!';
					exit();
				}
			} catch (\Adldap\Auth\BindException $e) {
				echo 'LDAP Bind error!';
			}
			echo 'AD User created!';`
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant