Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentes Révision précédente | |||
|
activedirectoy:owncloud [2019/03/03 17:23] etienne Quelques notes préliminaires à propose de l'implémentation |
activedirectoy:owncloud [2019/03/03 18:31] (Version actuelle) etienne Travail préliminaire sur l'obtention des chemins GPO avec authentification à travers TLS |
||
|---|---|---|---|
| Ligne 64: | Ligne 64: | ||
| ==== LDAP ==== | ==== LDAP ==== | ||
| - | === Naming context | + | === Connexion |
| - | La première phase est de trouver le " | + | La première phase est de trouver le " |
| <code php> | <code php> | ||
| - | function | + | function |
| $root = null; | $root = null; | ||
| - | | ||
| $lc = ldap_connect($server); | $lc = ldap_connect($server); | ||
| - | | + | $result = ldap_read($lc, |
| - | | + | if ($result && ($entry = ldap_first_entry($lc, |
| - | if ($result && ($entry = ldap_first_entry($lc, | + | $nctx = ldap_get_values($lc, |
| - | $nctx = ldap_get_values($lc, | + | /* first one should be the naming context, but do some checking */ |
| - | /* first one should be the naming context, but do some checking */ | + | for ($i = 0; $i < $nctx[' |
| - | for ($i = 0; $i < $nctx[' | + | if (is_null($root)) { $root = $nctx[$i]; continue; } |
| - | if (is_null($root)) { $root = $nctx[$i]; continue; } | + | if (strpos(strtolower($nctx[$i]), |
| - | if (strpos(strtolower($nctx[$i]), | + | $root = $nctx[$i]; |
| - | $root = $nctx[$i]; | + | } |
| + | } | ||
| + | |||
| + | $opt_version = 0; | ||
| + | $version = ldap_get_values($lc, | ||
| + | for ($i = 0; $i < $version[' | ||
| + | if ($opt_version < intval($version[$i])) { | ||
| + | $opt_version = intval($version[$i]); | ||
| + | } | ||
| + | } | ||
| + | ldap_set_option($lc, | ||
| + | } | ||
| + | return array($lc, $root); | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | === Authentification === | ||
| + | |||
| + | Une fois la connexion établie, nous pouvons directement nous authentifier. ActiveDirectory nécessite une authentification avec TLS activé. Il est donc nécessaire de démarrer TLS. L' | ||
| + | |||
| + | <code php> | ||
| + | function auth_ldap ($lc, $user, $pass) { | ||
| + | if (ldap_start_tls($lc)) { | ||
| + | if (ldap_bind($lc, | ||
| + | return true; | ||
| + | } | ||
| + | } | ||
| + | |||
| + | return false; | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | === Obtention des chemins GPO === | ||
| + | |||
| + | Une fois authentifié, | ||
| + | |||
| + | <code php> | ||
| + | function get_gpo_path($lc, | ||
| + | $gpo_paths = array(); | ||
| + | $result = ldap_read($lc, | ||
| + | if ($result && ($entry = ldap_first_entry($lc, | ||
| + | $gplinks = ldap_get_values($lc, | ||
| + | for ($i = 0; $i < $gplinks[' | ||
| + | if(preg_match_all('/ | ||
| + | foreach ($matches[1] as $dn) { | ||
| + | $res = ldap_read($lc, | ||
| + | if ($res && | ||
| + | $paths = ldap_get_values($lc, | ||
| + | for ($j = 0; $j < $paths[' | ||
| + | $gpo_paths[] = $paths[$j]; | ||
| + | } | ||
| + | } | ||
| } | } | ||
| } | } | ||
| } | } | ||
| } | } | ||
| - | | + | return $gpo_paths; |
| - | | + | |
| } | } | ||
| </ | </ | ||
| + | |||
| + | === Test === | ||
| + | |||
| + | En mettant tout ça ensemble, avec un nom d' | ||
| + | |||
| + | <code php> | ||
| + | $user = " | ||
| + | $password = " | ||
| + | |||
| + | $server = get_ldap(explode($user, | ||
| + | list ($lc, $rootdn) = connect_ldap($server); | ||
| + | if (auth_ldap($lc, | ||
| + | print_r(get_gpo_path($lc, | ||
| + | } | ||
| + | |||
| + | /* result on my test domain | ||
| + | Array | ||
| + | ( | ||
| + | [0] => \\test.artnum.ch\SysVol\test.artnum.ch\Policies\{5EE8813F-3AFE-483C-AC76-CB06FCFFDF0D} | ||
| + | [1] => \\test.artnum.ch\SysVol\test.artnum.ch\Policies\{0071FA96-BA06-4033-AB98-5FE59F5C0565} | ||
| + | [2] => \\test.artnum.ch\sysvol\test.artnum.ch\Policies\{31B2F340-016D-11D2-945F-00C04FB984F9} | ||
| + | ) | ||
| + | */ | ||
| + | </ | ||
| + | |||