Skip to content

Commit

Permalink
Safer check on ad domain string (#293)
Browse files Browse the repository at this point in the history
* Remove check for ad format

* Only check the dc string exist if schema is ad

* Make sure AD domain string doesnt contains cn= and ou=
  • Loading branch information
Stell0 authored Sep 13, 2024
1 parent 26a2ee5 commit 4abb2ed
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 7 deletions.
7 changes: 1 addition & 6 deletions freepbx/configure_users.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@
$results = $stmt->fetchAll(\PDO::FETCH_ASSOC);

if ($_ENV['NETHVOICE_LDAP_SCHEMA'] === 'ad') {
# check if DOMAIN is in the right format
if (!preg_match('/DC=/i', $_ENV['NETHVOICE_LDAP_BASE'])) {
echo "Invalid DOMAIN format\n";
exit(1);
}
# extract username from LDAP user
if (preg_match('/^([^@]*)@([^@]*)$/', $_ENV['NETHVOICE_LDAP_USER'],$tmp)) {
# user: username@domain
Expand All @@ -50,7 +45,7 @@
"dn" => $_ENV['NETHVOICE_LDAP_BASE'],
"username" => $username,
"password" => $_ENV['NETHVOICE_LDAP_PASS'],
"domain" => preg_replace(['/DC=/i', '/,/i'], ['', '.'],$_ENV['NETHVOICE_LDAP_BASE']),
"domain" => preg_replace(['/OU=[^,]*,/i', '/CN=[^,]*,/i', '/DC=/i', '/,/i'], ['', '', '', '.'],$_ENV['NETHVOICE_LDAP_BASE']),
"connection" => '',
"localgroups" => '0',
"createextensions" => '',
Expand Down
2 changes: 1 addition & 1 deletion imageroot/actions/configure-module/10validate_user_domain
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ if not domain or not domparams:

if not 'host' in domparams or domparams['host'] == '' or \
not 'port' in domparams or domparams['port'] == '' or \
not 'base_dn' in domparams or not re.search(r'dc=', domparams['base_dn'], re.IGNORECASE) or \
not 'base_dn' in domparams or (not re.search(r'dc=', domparams['base_dn'], re.IGNORECASE) and domparams['schema'].lower() == 'ad') or \
not 'bind_password' in domparams or domparams['bind_password'] == '' or \
not 'schema' in domparams or domparams['schema'] == '' or \
not 'base_dn' in domparams or domparams['base_dn'] == '':
Expand Down

0 comments on commit 4abb2ed

Please sign in to comment.