From e90887f0fd673f152c95fb9965707d9f0aa07497 Mon Sep 17 00:00:00 2001 From: paulr Date: Fri, 11 Feb 2011 17:48:54 +1100 Subject: [PATCH] implementing client/server messages --- gaas/gaasd/gaasclient.php | 36 +++++++++++++++++++++++++++++++- gaas/lib/gaasClientMessages.php | 31 ++++++++++++++++++++++++++- gaas/lib/gaasdMessages.php | 19 +++++++++++++--- gaas/lib/globalLib.php | 42 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 120 insertions(+), 8 deletions(-) diff --git a/gaas/gaasd/gaasclient.php b/gaas/gaasd/gaasclient.php index 0fd1401..361acb1 100644 --- a/gaas/gaasd/gaasclient.php +++ b/gaas/gaasd/gaasclient.php @@ -10,8 +10,12 @@ function usage() { global $argv; echo "Usage: ".$argv[0]." command [options]\n"; - echo "\nCommands:\n\tinit AD user password domain clientgroup admingroup\n"; - echo "\tinit IN user password\n"; + echo "\nCommands:\n\tinit AD user password domain clientgroup admingroup - init for active directory installation\n"; + echo "\tinit IN user password - init for internal database\n"; + echo "\tstatus - return the status of the server\n"; + echo "\tsetadlogin username password domain\n"; + echo "\tsetclientgroup groupname - change the group membership requirements for client's with AD\n"; + echo "\tsetadmingroup groupname - change the group membership requirements for admin's with AD\n"; echo "\n"; exit(0); } @@ -21,6 +25,10 @@ if($argc < 1) { } switch($argv[1]) { + case "status": + $ret = $myga->MSG_STATUS(); + echo "Status: $ret\n"; + break; case "init": if($argv[2] == "AD") { if($argc < 7) usage(); @@ -32,6 +40,30 @@ switch($argv[1]) { echo "initialising server failed\n"; } break; + case "setadlogin": + $ret = $myga->MSG_SET_AD_LOGIN($argv[2], $argv[3], $argv[4]); + if($ret) { + echo "Resetting AD login details succeeded\n"; + } else { + echo "Resetting AD login details failed\n"; + } + break; + case "setclientgroup": + $ret = $myga->MSG_SET_CLIENT_GROUP($argv[2]); + if($ret) { + echo "Resetting AD client group details succeeded\n"; + } else { + echo "Resetting AD client group details failed\n"; + } + break; + case "setadmingroup": + $ret = $myga->MSG_SET_ADMIN_GROUP($argv[2]); + if($ret) { + echo "Resetting AD admin group details succeeded\n"; + } else { + echo "Resetting AD admin group details failed\n"; + } + break; default: echo "No such command, ".$argv[1]."\n"; usage(); diff --git a/gaas/lib/gaasClientMessages.php b/gaas/lib/gaasClientMessages.php index f9581f9..69589fc 100644 --- a/gaas/lib/gaasClientMessages.php +++ b/gaas/lib/gaasClientMessages.php @@ -3,7 +3,7 @@ // thie file defines the messages sent too and from the gaas client. function gaasStatus_clientsend($params) { - return $params[0]; + return $params; } function gaasStatus_clientrecv($params) @@ -44,11 +44,38 @@ function gaasInitServer_clientrecv($params) function gaasSetADLogin_clientsend($params) { + $msg["domain"] = $params[2]; + $msg["user"] = $params[0]; + $msg["pass"] = $params[1]; + return $msg; } function gaasSetADLogin_clientrecv($params) { - + return $params; } + +function gaasSetClientGroup_clientsend($params) +{ + $msg["clientgroup"] = $params[0]; + return $msg; +} + +function gaasSetClientGroup_clientrecv($params) +{ + return $params; +} + +function gaasSetAdminGroup_clientsend($params) +{ + $msg["admingroup"] = $params[0]; + return $msg; +} + +function gaasSetAdminGroup_clientrecv($params) +{ + return $params; +} + ?> \ No newline at end of file diff --git a/gaas/lib/gaasdMessages.php b/gaas/lib/gaasdMessages.php index 3b59931..a9c6460 100644 --- a/gaas/lib/gaasdMessages.php +++ b/gaas/lib/gaasdMessages.php @@ -123,8 +123,6 @@ function gaasSetADLogin_server($msg) $addom = $msg["domain"]; $adlogin = $msg["user"]; $adpass = $msg["pass"]; - $adclientdef = $msg["clientdef"]; - $adadmindef = $msg["admindef"]; $res = adTestLogin($addmo, $adlogin, $adpass); if($res != 0) { @@ -134,10 +132,23 @@ function gaasSetADLogin_server($msg) confSetVal("ad.domain", $addom); confSetVal("ad.user", $adlogin); confSetVal("ad.pass", $adpass); - confSetVal("ad.clientdef", $adclientdef); - confSetVal("ad.admindef", $adadmindef); return true; } + +function gaasSetAdminGroup_server($msg) +{ + confSetVal("ad.admindef", $msg["admingroup"]); + + return true; +} + +function gaasSetClientGroup_server($msg) +{ + confSetVal("ad.clientdef", $msg["clientgroup"]); + + return true; +} + ?> \ No newline at end of file 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) -- 1.7.0.4