Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Use config_get_global to access ldap options
Issue #26822
  • Loading branch information
atrol authored and dregad committed Apr 1, 2020
1 parent caf4f9b commit 0d46b29
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 30 deletions.
4 changes: 2 additions & 2 deletions account_page.php
Expand Up @@ -209,7 +209,7 @@
</td>
<td>
<?php
if( $t_ldap && ON == config_get( 'use_ldap_email' ) ) {
if( $t_ldap && ON == config_get_global( 'use_ldap_email' ) ) {
# With LDAP
echo string_display_line( $u_email );
} else {
Expand All @@ -220,7 +220,7 @@
</td>
</tr>
<tr><?php
if( $t_ldap && ON == config_get( 'use_ldap_realname' ) ) {
if( $t_ldap && ON == config_get_global( 'use_ldap_realname' ) ) {
# With LDAP
echo '<td class="category">' . lang_get( 'realname' ) . '</td>';
echo '<td>';
Expand Down
4 changes: 2 additions & 2 deletions account_update.php
Expand Up @@ -100,15 +100,15 @@

# Update email (but only if LDAP isn't being used)
# Do not update email for a user verification
if( !( $t_ldap && config_get( 'use_ldap_email' ) )
if( !( $t_ldap && config_get_global( 'use_ldap_email' ) )
&& !$t_account_verification ) {
if( !is_blank( $f_email ) && $f_email != user_get_email( $t_user_id ) ) {
$t_update_email = true;
}
}

# Update real name (but only if LDAP isn't being used)
if( !( $t_ldap && config_get( 'use_ldap_realname' ) ) ) {
if( !( $t_ldap && config_get_global( 'use_ldap_realname' ) ) ) {
# strip extra spaces from real name
$t_realname = string_normalize( $f_realname );
if( $t_realname != user_get_field( $t_user_id, 'realname' ) ) {
Expand Down
2 changes: 1 addition & 1 deletion core/email_api.php
Expand Up @@ -122,7 +122,7 @@ function email_is_valid( $p_email ) {
# If blank email is allowed or current user is admin, then accept blank emails which are useful for
# accounts that should never receive email notifications (e.g. anonymous account)
if( OFF == $t_validate_email ||
ON == config_get( 'use_ldap_email' ) ||
ON == config_get_global( 'use_ldap_email' ) ||
( is_blank( $p_email ) && ( ON == config_get( 'allow_blank_email' ) || current_user_is_administrator() ) )
) {
return true;
Expand Down
32 changes: 16 additions & 16 deletions core/ldap_api.php
Expand Up @@ -62,7 +62,7 @@ function ldap_connect_bind( $p_binddn = '', $p_password = '' ) {
trigger_error( ERROR_LDAP_EXTENSION_NOT_LOADED, ERROR );
}

$t_ldap_server = config_get( 'ldap_server' );
$t_ldap_server = config_get_global( 'ldap_server' );

log_event( LOG_LDAP, 'Attempting connection to LDAP server/URI \'' . $t_ldap_server . '\'.' );
$t_ds = @ldap_connect( $t_ldap_server );
Expand All @@ -75,7 +75,7 @@ function ldap_connect_bind( $p_binddn = '', $p_password = '' ) {

log_event( LOG_LDAP, 'Connection accepted by LDAP server' );

$t_network_timeout = config_get( 'ldap_network_timeout' );
$t_network_timeout = config_get_global( 'ldap_network_timeout' );
if( $t_network_timeout > 0 ) {
log_event( LOG_LDAP, "Setting LDAP network timeout to " . $t_network_timeout );
$t_result = @ldap_set_option( $t_ds, LDAP_OPT_NETWORK_TIMEOUT, $t_network_timeout );
Expand All @@ -84,7 +84,7 @@ function ldap_connect_bind( $p_binddn = '', $p_password = '' ) {
}
}

$t_protocol_version = config_get( 'ldap_protocol_version' );
$t_protocol_version = config_get_global( 'ldap_protocol_version' );
if( $t_protocol_version > 0 ) {
log_event( LOG_LDAP, 'Setting LDAP protocol version to ' . $t_protocol_version );
$t_result = @ldap_set_option( $t_ds, LDAP_OPT_PROTOCOL_VERSION, $t_protocol_version );
Expand All @@ -94,7 +94,7 @@ function ldap_connect_bind( $p_binddn = '', $p_password = '' ) {
}

# Set referrals flag.
$t_follow_referrals = ON == config_get( 'ldap_follow_referrals' );
$t_follow_referrals = ON == config_get_global( 'ldap_follow_referrals' );
$t_result = @ldap_set_option( $t_ds, LDAP_OPT_REFERRALS, $t_follow_referrals );
if( !$t_result ) {
ldap_log_error( $t_ds );
Expand All @@ -103,8 +103,8 @@ function ldap_connect_bind( $p_binddn = '', $p_password = '' ) {
# If no Bind DN and Password is set, attempt to login as the configured
# Bind DN.
if( is_blank( $p_binddn ) && is_blank( $p_password ) ) {
$p_binddn = config_get( 'ldap_bind_dn', '' );
$p_password = config_get( 'ldap_bind_passwd', '' );
$p_binddn = config_get_global( 'ldap_bind_dn', '' );
$p_password = config_get_global( 'ldap_bind_passwd', '' );
}

if( !is_blank( $p_binddn ) && !is_blank( $p_password ) ) {
Expand Down Expand Up @@ -169,7 +169,7 @@ function ldap_realname_from_username( $p_username ) {
if( ldap_simulation_is_enabled() ) {
$t_realname = ldap_simulatiom_realname_from_username( $p_username );
} else {
$t_ldap_realname_field = config_get( 'ldap_realname_field' );
$t_ldap_realname_field = config_get_global( 'ldap_realname_field' );
$t_realname = (string)ldap_get_field_from_username( $p_username, $t_ldap_realname_field );
}
return $t_realname;
Expand Down Expand Up @@ -221,15 +221,15 @@ function ldap_cache_user_data( $p_username ) {
}

# Search
$t_ldap_organization = config_get( 'ldap_organization' );
$t_ldap_root_dn = config_get( 'ldap_root_dn' );
$t_ldap_uid_field = config_get( 'ldap_uid_field' );
$t_ldap_organization = config_get_global( 'ldap_organization' );
$t_ldap_root_dn = config_get_global( 'ldap_root_dn' );
$t_ldap_uid_field = config_get_global( 'ldap_uid_field' );

$t_search_filter = '(&' . $t_ldap_organization
. '(' . $t_ldap_uid_field . '=' . ldap_escape_string( $p_username ) . '))';
$t_search_attrs = array(
'mail',
config_get( 'ldap_realname_field' )
config_get_global( 'ldap_realname_field' )
);

log_event( LOG_LDAP, 'Searching for ' . $t_search_filter );
Expand Down Expand Up @@ -327,10 +327,10 @@ function ldap_authenticate_by_username( $p_username, $p_password ) {
} else {
$c_username = ldap_escape_string( $p_username );

$t_ldap_organization = config_get( 'ldap_organization' );
$t_ldap_root_dn = config_get( 'ldap_root_dn' );
$t_ldap_organization = config_get_global( 'ldap_organization' );
$t_ldap_root_dn = config_get_global( 'ldap_root_dn' );

$t_ldap_uid_field = config_get( 'ldap_uid_field', 'uid' );
$t_ldap_uid_field = config_get_global( 'ldap_uid_field', 'uid' );
$t_search_filter = '(&' . $t_ldap_organization . '(' . $t_ldap_uid_field . '=' . $c_username . '))';
$t_search_attrs = array(
$t_ldap_uid_field,
Expand Down Expand Up @@ -391,11 +391,11 @@ function ldap_authenticate_by_username( $p_username, $p_password ) {

$t_fields_to_update = array('password' => md5( $p_password ));

if( ON == config_get( 'use_ldap_realname' ) ) {
if( ON == config_get_global( 'use_ldap_realname' ) ) {
$t_fields_to_update['realname'] = ldap_realname_from_username( $p_username );
}

if( ON == config_get( 'use_ldap_email' ) ) {
if( ON == config_get_global( 'use_ldap_email' ) ) {
$t_fields_to_update['email'] = ldap_email_from_username( $p_username );
}

Expand Down
6 changes: 3 additions & 3 deletions core/user_api.php
Expand Up @@ -596,7 +596,7 @@ function user_signup( $p_username, $p_email = null ) {
# I'll re-enable this once a plan has been properly formulated for LDAP
# account management and creation.
# $t_email = '';
# if( ON == config_get( 'use_ldap_email' ) ) {
# if( ON == config_get_global( 'use_ldap_email' ) ) {
# $t_email = ldap_email_from_username( $p_username );
# }
# if( !is_blank( $t_email ) ) {
Expand Down Expand Up @@ -921,7 +921,7 @@ function user_get_field( $p_user_id, $p_field_name ) {
*/
function user_get_email( $p_user_id ) {
$t_email = '';
if( LDAP == config_get_global( 'login_method' ) && ON == config_get( 'use_ldap_email' ) ) {
if( LDAP == config_get_global( 'login_method' ) && ON == config_get_global( 'use_ldap_email' ) ) {
$t_email = ldap_email( $p_user_id );
}
if( is_blank( $t_email ) ) {
Expand Down Expand Up @@ -954,7 +954,7 @@ function user_get_username( $p_user_id ) {
function user_get_realname( $p_user_id ) {
$t_realname = '';

if( LDAP == config_get_global( 'login_method' ) && ON == config_get( 'use_ldap_realname' ) ) {
if( LDAP == config_get_global( 'login_method' ) && ON == config_get_global( 'use_ldap_realname' ) ) {
$t_realname = ldap_realname( $p_user_id );
}

Expand Down
4 changes: 2 additions & 2 deletions manage_user_create_page.php
Expand Up @@ -83,7 +83,7 @@
<input type="text" id="user-username" name="username" class="input-sm" size="32" maxlength="<?php echo DB_FIELD_SIZE_USERNAME;?>" />
</td>
</tr><?php
if( !$t_ldap || config_get( 'use_ldap_realname' ) == OFF ) { ?>
if( !$t_ldap || config_get_global( 'use_ldap_realname' ) == OFF ) { ?>
<tr>
<td class="category">
<?php echo lang_get( 'realname' ) ?>
Expand All @@ -93,7 +93,7 @@
</td>
</tr><?php
}
if( !$t_ldap || config_get( 'use_ldap_email' ) == OFF ) { ?>
if( !$t_ldap || config_get_global( 'use_ldap_email' ) == OFF ) { ?>
<tr>
<td class="category">
<?php echo lang_get( 'email' ) ?>
Expand Down
4 changes: 2 additions & 2 deletions manage_user_edit_page.php
Expand Up @@ -129,7 +129,7 @@

<!-- Realname -->
<tr><?php
if( $t_ldap && ON == config_get( 'use_ldap_realname' ) ) {
if( $t_ldap && ON == config_get_global( 'use_ldap_realname' ) ) {
# With LDAP
echo '<td class="category">' . lang_get( 'realname_label' ) . '</td>';
echo '<td>';
Expand All @@ -144,7 +144,7 @@
</tr>
<!-- Email -->
<tr><?php
if( $t_ldap && ON == config_get( 'use_ldap_email' ) ) {
if( $t_ldap && ON == config_get_global( 'use_ldap_email' ) ) {
# With LDAP
echo '<td class="category">' . lang_get( 'email_label' ) . '</td>';
echo '<td>' . string_display_line( user_get_email( $t_user_id ) ) . '</td>';
Expand Down
4 changes: 2 additions & 2 deletions manage_user_update.php
Expand Up @@ -106,14 +106,14 @@

$t_ldap = ( LDAP == config_get_global( 'login_method' ) );

if( $t_ldap && config_get( 'use_ldap_realname' ) ) {
if( $t_ldap && config_get_global( 'use_ldap_realname' ) ) {
$t_realname = ldap_realname_from_username( $f_username );
} else {
# strip extra space from real name
$t_realname = string_normalize( $f_realname );
}

if( $t_ldap && config_get( 'use_ldap_email' ) ) {
if( $t_ldap && config_get_global( 'use_ldap_email' ) ) {
$t_email = ldap_email( $f_user_id );
} else {
$t_email = trim( $f_email );
Expand Down

0 comments on commit 0d46b29

Please sign in to comment.