Created
April 13, 2016 19:31
-
-
Save rayterrill/74d428480c0331aa59c5bc9abb5d334e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function checkADGroup($adLDAPHost, $ldap_dn, $queryUser, $queryPassword, $user, $group) { | |
// Connect to AD | |
$ldap = ldap_connect($adLDAPHost) or die("Could not connect to LDAP"); | |
ldap_bind($ldap,$queryUser,$queryPassword) or die("Could not bind to LDAP"); | |
// Search AD | |
$results = ldap_search($ldap,$ldap_dn,"(samaccountname=$user)",array("memberof","primarygroupid")); | |
$entries = ldap_get_entries($ldap, $results); | |
// No information found, bad user | |
if($entries['count'] == 0) return false; | |
// Get groups and primary group token | |
$output = $entries[0]['memberof']; | |
if (in_array($group, $output)) { | |
return 1; | |
} else { | |
return 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment