3 // the global lib sets alot of global variables, its fairly unexciting
4 $BASE_DIR = realpath(dirname(__FILE__)."/../../");
7 // the tcp port number we use for comms
8 $TCP_PORT_NUMBER = 21336;
9 global $TCP_PORT_NUMBER;
14 // the messages structure, used to extend gaas if needed
15 define("MSG_STATUS", 18);
16 define("MSG_INIT_SERVER", 19);
17 define("MSG_SET_AD_LOGIN", 20);
18 define("MSG_SET_CLIENT_GROUP", 21);
19 define("MSG_SET_ADMIN_GROUP", 22);
20 define("MSG_PROVISION_USER",23);
23 // the gaasd call's $MESSAGE[<MSG>]_server() for the server side
24 // and $MESSAGE[<msg>]_client() for the client side
25 $MESSAGES[MSG_STATUS] = "gaasStatus";
26 $MESSAGES[MSG_INIT_SERVER] = "gaasInitServer";
27 $MESSAGES[MSG_SET_AD_LOGIN] = "gaasSetADLogin";
28 $MESSAGES[MSG_SET_CLIENT_GROUP] = "gaasSetClientGroup";
29 $MESSAGES[MSG_SET_ADMIN_GROUP] = "gaasSetAdminGroup";
30 $MESSAGES[MSG_PROVISION_USER] = "gaasProvisionUser";
39 function adTestLogin($domain, $user, $password)
41 $servers = dns_get_record("_gc._tcp.$domain");
42 if(count($servers)<1) {
43 echo "AD servers cant be found for $domain, fail!\n";
46 echo count($servers)." AD servers returned, using ".$servers[0]["target"]."\n";
48 // we should check all servers, but lets just go with 0 for now
49 $cnt = ldap_connect($servers[0]["target"], $servers[0]["port"]);
51 $bind = ldap_bind($cnt, "$user@$domain", "$password");
53 echo "login has succeeded\n";
56 echo "login has failed\n";
61 function getADGroups($domain, $user, $password)
63 $servers = dns_get_record("_gc._tcp.$domain");
64 if(count($servers)<1) {
65 echo "AD servers cant be found for $domain, fail!\n";
68 echo count($servers)." AD servers returned, using ".$servers[0]["target"]."\n";
70 // we should check all servers, but lets just go with 0 for now
71 $cnt = ldap_connect($servers[0]["target"], $servers[0]["port"]);
73 $bind = ldap_bind($cnt, "$user@$domain", "$password");
75 echo "login has failed\n";
79 $ars = explode(".", $addom);
82 foreach($ars as $val) {
86 $basecn = preg_replace("/,$/", "", $tcn);
88 $sr = ldap_search($cnt, "$basecn", "(objectclass=group)");
89 $info = ldap_get_entries($cnt, $sr);
91 if($info["count"] < 1) {
92 echo "Couldn't find a matching group\n";
95 echo "Found a group, ".$info[0]["cn"][0]."\n";
96 echo "With a description of, ".$info[0]["description"][0]."\n";
97 echo "and a dn of, ".$info[0]["dn"]."\n";
103 function userInGroup($user, $domain, $adlogin, $adpass, $group)
106 $usertocheck = $user;
108 $servers = dns_get_record("_gc._tcp.$addom");
109 if(count($servers)<1) {
110 echo "AD servers cant be found, fail!\n";
114 // we should check all servers, but lets just go with 0 for now
115 $cnt = ldap_connect($servers[0]["target"], $servers[0]["port"]);
116 $bind = ldap_bind($cnt, "$adlogin@$addom", "$adpass");
119 echo "Bind Failed\n";
123 $ars = explode(".", $addom);
126 foreach($ars as $val) {
130 $basecn = preg_replace("/,$/", "", $tcn);
132 // first, find the dn for our user
133 $sr = ldap_search($cnt, "$basecn", "(&(objectclass=user)(samaccountname=$usertocheck))");
134 $info = ldap_get_entries($cnt, $sr);
136 $usercn=$info[0]["dn"];
141 $basecn = preg_replace("/,$/", "", $tcn);
142 $sr = ldap_search($cnt, "$basecn", "(&(objectCategory=group)(member:1.2.840.113556.1.4.1941:=$usercn))");
143 $fil = "(&(objectCategory=group)(member:1.2.840.113556.1.4.1941:=$usercn))";
144 $info = ldap_get_entries($cnt, $sr);
145 foreach($info as $kpot => $lpot) {
146 if(isset($lpot["samaccountname"])) {
147 if($lpot["cn"][0] == $group) return true;
153 function generateRandomString($len)
156 $strpos = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
158 for($i=0; $i<$len; $i++) {
159 $str .= $strpos[rand(0, strlen($strpos)-1)];
165 function generateHexString($len)
168 $strpos = "0123456789ABCDEF";
170 for($i=0; $i<$len; $i++) {
171 $str .= $strpos[rand(0, strlen($strpos)-1)];