From: <gi...@ma...> - 2009-07-06 07:38:27
|
The branch, master has been updated via 7165bda4982c1494e5765fc3afe3780bb8b53f56 (commit) via 198de10ac8de83bb63fab397177de8f7d237132b (commit) from a0f99f7a63dcbf719d6ce3b1bea80b99162af793 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 7165bda4982c1494e5765fc3afe3780bb8b53f56 Author: Victor Boctor <vb...@gm...> Date: Mon Jul 6 00:38:18 2009 -0700 Fixes #10689: Support pulling realname from LDAP. commit 198de10ac8de83bb63fab397177de8f7d237132b Author: Victor Boctor <vb...@gm...> Date: Mon Jul 6 00:37:49 2009 -0700 Fixes #10690: Reporter username link in View Issue page is incorrect in case of LDAP. ----------------------------------------------------------------------- Summary of changes: account_page.php | 18 +++++- config_defaults_inc.php | 13 ++++ core/ldap_api.php | 104 ++++++++++++++++++++++++++---- core/print_api.php | 11 ++-- core/user_api.php | 10 +++- docbook/adminguide/en/configuration.sgml | 16 ++++- manage_user_create.php | 2 +- manage_user_create_page.php | 9 ++- manage_user_edit_page.php | 14 ++++- view_user_page.php | 3 +- 10 files changed, 175 insertions(+), 25 deletions(-) ----------------------------------------------------------------------- commit 7165bda4982c1494e5765fc3afe3780bb8b53f56 Author: Victor Boctor <vb...@gm...> Date: Mon Jul 6 00:38:18 2009 -0700 Fixes #10689: Support pulling realname from LDAP. diff --git a/account_page.php b/account_page.php index 55cc81a..32a3476 100644 --- a/account_page.php +++ b/account_page.php @@ -72,6 +72,9 @@ # this is a mandatory password change request $t_force_pw_reset = is_page_name( 'verify.php' ); + # Only show the update button if there is something to update. + $t_show_update_button = false; + html_page_top( lang_get( 'account_link' ) ); ?> @@ -130,6 +133,7 @@ </tr> <?php } else { ?> <!-- Without LDAP --> + $t_show_update_button = true; <!-- Username --> <tr <?php echo helper_alternate_class() ?>> @@ -194,7 +198,10 @@ if ( $t_ldap && ON == config_get( 'use_ldap_email' ) ) { ?> <!-- With LDAP Email <?php echo lang_get( 'email' ) ?> </td> <td> - <?php print_email_input( 'email', $u_email ) ?> + <?php + $t_show_update_button = true; + print_email_input( 'email', $u_email ); + ?> </td> </tr> @@ -206,7 +213,14 @@ if ( $t_ldap && ON == config_get( 'use_ldap_email' ) ) { ?> <!-- With LDAP Email <?php echo lang_get( 'realname' ) ?> </td> <td> +<?php +if ( $t_ldap && ON == config_get( 'use_ldap_realname' ) ) { + echo string_display( ldap_realname_from_username( $u_username ) ); +} else { + $t_show_update_button = true; +?> <input type="text" size="32" maxlength="<?php echo REALLEN;?>" name="realname" value="<?php echo string_attribute( $u_realname ) ?>" /> +<?php } ?> </td> </tr> @@ -240,6 +254,7 @@ if ( $t_ldap && ON == config_get( 'use_ldap_email' ) ) { ?> <!-- With LDAP Email </td> </tr> + <?php if ( $t_show_update_button ) { ?> <!-- BUTTONS --> <tr> <td class="left"> @@ -252,6 +267,7 @@ if ( $t_ldap && ON == config_get( 'use_ldap_email' ) ) { ?> <!-- With LDAP Email <input type="submit" class="button" value="<?php echo lang_get( 'update_user_button' ) ?>" /> </td> </tr> + <?php } ?> </table> </form> </div> diff --git a/config_defaults_inc.php b/config_defaults_inc.php index 9415c52..ae08d8d 100644 --- a/config_defaults_inc.php +++ b/config_defaults_inc.php @@ -1782,6 +1782,12 @@ $g_ldap_uid_field = 'uid'; /** + * The LDAP field for real name (i.e. common name). + * @global string $g_ldap_uid_field + */ + $g_ldap_realname_field = 'cn'; + + /** * * @global string $g_ldap_bind_dn */ @@ -1800,6 +1806,13 @@ $g_use_ldap_email = OFF; /** + * Whether or not to pull the real name from LDAP. + * ON from LDAP, OFF from database. + * @global int $g_use_ldap_realname + */ + $g_use_ldap_realname = OFF; + + /** * The LDAP Protocol Version, if 0, then the protocol version is not set. * @global int $g_ldap_protocol_version */ diff --git a/core/ldap_api.php b/core/ldap_api.php index 1bd5dee..696bdb7 100644 --- a/core/ldap_api.php +++ b/core/ldap_api.php @@ -107,26 +107,89 @@ function ldap_email_from_username( $p_username ) { return ldap_simulation_email_from_username( $p_username ); } - $t_ldap_organization = config_get( 'ldap_organization' ); - $t_ldap_root_dn = config_get( 'ldap_root_dn' ); + $t_email = ldap_get_field_from_username( $p_username, 'mail' ); + if ( $t_email === null ) { + return ''; + } - $t_ldap_uid_field = config_get( 'ldap_uid_field', 'uid' ); - $t_search_filter = "(&$t_ldap_organization($t_ldap_uid_field=$p_username))"; - $t_search_attrs = array( - $t_ldap_uid_field, - 'mail', - 'dn', - ); - $t_ds = ldap_connect_bind(); + return $t_email; +} + +/** + * Gets a user's real name (common name) given the id. + * + * @param int $p_user_id The user id. + * @return string real name. + */ +function ldap_realname( $p_user_id ) { + $t_username = user_get_field( $p_user_id, 'username' ); + return ldap_realname_from_username( $t_username ); +} + +/** + * Gets a user real name given their user name. + * + * @param string $p_username The user's name. + * @return string The user's real name. + */ +function ldap_realname_from_username( $p_username ) { + if ( ldap_simulation_is_enabled() ) { + return ldap_simulatiom_realname_from_username( $p_username ); + } + $t_ldap_realname_field = config_get( 'ldap_realname_field' ); + $t_realname = ldap_get_field_from_username( $p_username, $t_ldap_realname_field ); + if ( $t_realname === null ) { + return ''; + } + + return $t_realname; +} + +/** + * Gets the value of a specific field from LDAP given the user name + * and LDAP field name. + * + * @todo Implement caching by retrieving all needed information in one query. + * @todo Implement logging to LDAP queries same way like DB queries. + * + * @param string $p_username The user name. + * @param string $p_field The LDAP field name. + * @return string The field value or null if not found. + */ +function ldap_get_field_from_username( $p_username, $p_field ) { + $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' ); + + # Bind + log_event( LOG_LDAP, "Binding to LDAP server" ); + $t_ds = ldap_connect_bind(); + + # Search + $t_search_filter = "(&$t_ldap_organization($t_ldap_uid_field=$p_username))"; + $t_search_attrs = array( $t_ldap_uid_field, $p_field, 'dn' ); log_event( LOG_LDAP, "Searching for $t_search_filter" ); $t_sr = ldap_search( $t_ds, $t_ldap_root_dn, $t_search_filter, $t_search_attrs ); + # Get results $t_info = ldap_get_entries( $t_ds, $t_sr ); + + # Free results / unbind + log_event( LOG_LDAP, "Unbinding from LDAP server" ); ldap_free_result( $t_sr ); ldap_unbind( $t_ds ); - return $t_info[0]['mail'][0]; + # If no matches, return null. + if ( count( $t_info ) == 0 ) { + log_event( LOG_LDAP, "No matches found." ); + return null; + } + + $t_value = $t_info[0][$p_field][0]; + log_event( LOG_LDAP, "Found value '{$t_value}' for field '{$p_field}'." ); + + return $t_value; } /** @@ -226,7 +289,7 @@ function ldap_simulation_get_user( $p_username ) { return $t_user; } - log_event( LOG_LDAP, "ldap_simulation_get_user: user '$t_username' not found." ); + log_event( LOG_LDAP, "ldap_simulation_get_user: user '$p_username' not found." ); return null; } @@ -248,6 +311,23 @@ function ldap_simulation_email_from_username( $p_username ) { } /** + * Given a username, this methods gets the realname or empty string if not found. + * + * @param string $p_username The username. + * @return string The real name or an empty string if not found. + */ +function ldap_simulatiom_realname_from_username( $p_username ) { + $t_user = ldap_simulation_get_user( $p_username ); + if ( $t_user === null ) { + log_event( LOG_LDAP, "ldap_simulatiom_realname_from_username: user '$p_username' not found." ); + return ''; + } + + log_event( LOG_LDAP, "ldap_simulatiom_realname_from_username: user '$p_username' has email '{$t_user['realname']}'." ); + return $t_user['realname']; +} + +/** * Authenticates the specified user id / password based on the simulation data. * * @param string $p_user_id The user id. diff --git a/core/user_api.php b/core/user_api.php index 48294a3..9ef7a9b 100644 --- a/core/user_api.php +++ b/core/user_api.php @@ -753,7 +753,15 @@ function user_get_email( $p_user_id ) { # -------------------- # lookup the user's realname function user_get_realname( $p_user_id ) { - $t_realname = user_get_field( $p_user_id, 'realname' ); + $t_realname = ''; + + if ( ON == config_get( 'use_ldap_realname' ) ) { + $t_realname = ldap_realname( $p_user_id ); + } + + if ( is_blank( $t_realname ) ) { + $t_realname = user_get_field( $p_user_id, 'realname' ); + } return $t_realname; } diff --git a/docbook/adminguide/en/configuration.sgml b/docbook/adminguide/en/configuration.sgml index 287ec81..210ab58 100644 --- a/docbook/adminguide/en/configuration.sgml +++ b/docbook/adminguide/en/configuration.sgml @@ -1745,12 +1745,18 @@ </listitem> </varlistentry> <varlistentry> - <term>$g_ldap_organisation</term> + <term>$g_ldap_organization</term> <listitem> <para>"organizationname=*Example)"</para> </listitem> </varlistentry> <varlistentry> + <term>$g_ldap_realname_field</term> + <listitem> + <para>The LDAP field for real name (i.e. common name). Default value is 'cn'.</para> + </listitem> + </varlistentry> + <varlistentry> <term>$g_use_ldap_email</term> <listitem> <para>Use email address in LDAP rather than the email stored in @@ -1759,6 +1765,14 @@ </listitem> </varlistentry> <varlistentry> + <term>$g_use_ldap_realname</term> + <listitem> + <para>Use realname in LDAP rather than the email stored in the database. + ON for LDAP, OFF for database. The default value is OFF. + </para> + </listitem> + </varlistentry> + <varlistentry> <term>$g_ldap_bind_dn</term> <listitem> <para> "cn=Manager, dc=example, dc=com" </para> diff --git a/manage_user_create.php b/manage_user_create.php index 84c631f..2665972 100644 --- a/manage_user_create.php +++ b/manage_user_create.php @@ -33,7 +33,7 @@ access_ensure_global_level( config_get( 'manage_user_threshold' ) ); $f_username = gpc_get_string( 'username' ); - $f_realname = gpc_get_string( 'realname' ); + $f_realname = gpc_get_string( 'realname', '' ); $f_password = gpc_get_string( 'password', '' ); $f_password_verify = gpc_get_string( 'password_verify', '' ); $f_email = gpc_get_string( 'email', '' ); diff --git a/manage_user_create_page.php b/manage_user_create_page.php index 881d691..9ccfca6 100644 --- a/manage_user_create_page.php +++ b/manage_user_create_page.php @@ -29,6 +29,8 @@ access_ensure_global_level( config_get( 'manage_user_threshold' ) ); + $t_ldap = ( LDAP == config_get( 'login_method' ) ); + html_page_top(); print_manage_menu( 'manage_user_create_page.php' ); @@ -51,6 +53,9 @@ <input type="text" name="username" size="32" maxlength="<?php echo USERLEN;?>" /> </td> </tr> +<?php + if ( !$t_ldap || config_get( 'use_ldap_realname' ) == OFF ) { +?> <tr <?php echo helper_alternate_class() ?>> <td class="category"> <?php echo lang_get( 'realname' ) ?> @@ -60,7 +65,9 @@ </td> </tr> <?php - if ( config_get( 'use_ldap_email' ) == OFF ) { + } + + if ( !$t_ldap || config_get( 'use_ldap_email' ) == OFF ) { ?> <tr <?php echo helper_alternate_class() ?>> <td class="category"> diff --git a/manage_user_edit_page.php b/manage_user_edit_page.php index 03e7a37..769dbe0 100644 --- a/manage_user_edit_page.php +++ b/manage_user_edit_page.php @@ -44,6 +44,8 @@ $t_user = user_get_row( $t_user_id ); + $t_ldap = ( LDAP == config_get( 'login_method' ) ); + html_page_top(); print_manage_menu(); @@ -81,7 +83,15 @@ <?php echo lang_get( 'realname' ) ?>: </td> <td width="70%"> - <input type="text" size="16" maxlength="<?php echo REALLEN;?>" name="realname" value="<?php echo string_attribute( $t_user['realname'] ) ?>" /> + <?php + if ( !$t_ldap || config_get( 'use_ldap_realname' ) == OFF ) { + ?> + <input type="text" size="16" maxlength="<?php echo REALLEN;?>" name="realname" value="<?php echo string_attribute( $t_user['realname'] ) ?>" /> + <?php + } else { + echo string_display( user_get_realname( $f_user_id ) ); + } + ?> </td> </tr> @@ -92,7 +102,7 @@ </td> <td> <?php - if ( config_get( 'use_ldap_email' ) == OFF ) { + if ( !$t_ldap || config_get( 'use_ldap_email' ) == OFF ) { print_email_input( 'email', $t_user['email'] ); } else { echo string_display( user_get_email( $f_user_id ) ); diff --git a/view_user_page.php b/view_user_page.php index 503ead4..394ab18 100644 --- a/view_user_page.php +++ b/view_user_page.php @@ -41,7 +41,8 @@ # In case we're using LDAP to get the email address... this will pull out # that version instead of the one in the DB - $u_email = user_get_email( $u_id, $u_username ); + $u_email = user_get_email( $u_id ); + $u_realname = user_get_realname( $u_id ); html_page_top(); ?> commit 198de10ac8de83bb63fab397177de8f7d237132b Author: Victor Boctor <vb...@gm...> Date: Mon Jul 6 00:37:49 2009 -0700 Fixes #10690: Reporter username link in View Issue page is incorrect in case of LDAP. diff --git a/core/print_api.php b/core/print_api.php index b5339e8..fcc6028 100644 --- a/core/print_api.php +++ b/core/print_api.php @@ -172,7 +172,7 @@ function print_user_with_subject( $p_user_id, $p_bug_id ) { $t_username = user_get_name( $p_user_id ); if( user_exists( $p_user_id ) && user_get_field( $p_user_id, 'enabled' ) ) { - $t_email = user_get_field( $p_user_id, 'email' ); + $t_email = user_get_email( $p_user_id ); print_email_link_with_subject( $t_email, $t_username, $p_bug_id ); } else { echo '<font STYLE="text-decoration: line-through">'; @@ -1473,11 +1473,12 @@ function get_email_link_with_subject( $p_email, $p_text, $p_summary ) { # gets turned into a %40 and you can't right click in browsers to # do Copy Email Address. If we don't apply string_url() to the # summary text then an ampersand (for example) will truncate the text - $p_summary = string_url( $p_summary ); - $t_mailto = string_attribute( "mailto:$p_email?subject=$p_summary" ); - $p_text = string_display( $p_text ); + $t_summary = string_url( $p_summary ); + $t_email = string_url( $p_email ); + $t_mailto = string_attribute( "mailto:$t_email?subject=$t_summary" ); + $t_text = string_display( $p_text ); - return "<a href=\"$t_mailto\">$p_text</a>"; + return "<a href=\"$t_mailto\">$t_text</a>"; } # Print a hidden input for each name=>value pair in the array ----------------------------------------------------------------------- -- Mantis Bug Tracker |