X-Git-Url: http://git.pjr.cc/?p=ga4php.git;a=blobdiff_plain;f=gaas%2Flib%2FglobalLib.php;fp=gaas%2Flib%2FglobalLib.php;h=51854875d88990d149828a766bb3c3e2e72d3f69;hp=4592618a0d01af215f5e915c8c43029fa55157b4;hb=e90887f0fd673f152c95fb9965707d9f0aa07497;hpb=40dc7f97626a703a943e27cdcd1a3d6a332a8f27 diff --git a/gaas/lib/globalLib.php b/gaas/lib/globalLib.php index 4592618..5185487 100644 --- a/gaas/lib/globalLib.php +++ b/gaas/lib/globalLib.php @@ -15,12 +15,17 @@ global $TCP_PORT_NUMBER; define("MSG_STATUS", 18); define("MSG_INIT_SERVER", 19); define("MSG_SET_AD_LOGIN", 20); +define("MSG_SET_CLIENT_GROUP", 21); +define("MSG_SET_ADMIN_GROUP", 22); + // the gaasd call's $MESSAGE[]_server() for the server side // and $MESSAGE[]_client() for the client side $MESSAGES[MSG_STATUS] = "gaasStatus"; $MESSAGES[MSG_INIT_SERVER] = "gaasInitServer"; $MESSAGES[MSG_SET_AD_LOGIN] = "gaasSetADLogin"; +$MESSAGES[MSG_SET_CLIENT_GROUP] = "gaasSetClientGroup"; +$MESSAGES[MSG_SET_ADMIN_GROUP] = "gaasSetAdminGroup"; global $MESSAGES; @@ -53,7 +58,44 @@ function adTestLogin($domain, $user, $password) function getADGroups($domain, $user, $password) { + $servers = dns_get_record("_gc._tcp.$domain"); + if(count($servers)<1) { + echo "AD servers cant be found for $domain, fail!\n"; + } + + echo count($servers)." AD servers returned, using ".$servers[0]["target"]."\n"; + + // we should check all servers, but lets just go with 0 for now + $cnt = ldap_connect($servers[0]["target"], $servers[0]["port"]); + echo "Connected\n"; + $bind = ldap_bind($cnt, "$user@$domain", "$password"); + if(!$bind) { + echo "login has failed\n"; + return false; + } + + $ars = explode(".", $addom); + + $tcn = ""; + foreach($ars as $val) { + $tcn .= "DC=$val,"; + } + + $basecn = preg_replace("/,$/", "", $tcn); + + $sr = ldap_search($cnt, "$basecn", "(objectclass=group)"); + $info = ldap_get_entries($cnt, $sr); + + if($info["count"] < 1) { + echo "Couldn't find a matching group\n"; + return 0; + } else { + echo "Found a group, ".$info[0]["cn"][0]."\n"; + echo "With a description of, ".$info[0]["description"][0]."\n"; + echo "and a dn of, ".$info[0]["dn"]."\n"; + } + return $info; } function generateRandomString($len)