Update for 6.x
cybertron1 - January 4, 2008 - 07:46
| Project: | Webserver authentication |
| Version: | HEAD |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Description
Well, I am trying to make an update for 6.x, sofar not much has been changed actually, it works quite ok (mostly the info file that has been changed) although I am having trouble getting the admin interface working. I have the link working as it should (i belive) but the form itself doesn't show up.
I will try and fix this and if anyone knows what wrong, please help.
/CyberTron
| Attachment | Size |
|---|---|
| webserver_auth.zip | 13.63 KB |

#1
Well, I have finally implemented the last parts of getting it to work. It is probably not the best work securitywise or like that, but it works and that is all I need. Configuration works also.
I have not tested this on a complete new system (only with my own backup site) so I take no responsibility what so ever!
have fun
#2
pleae attach individual files. lets find a patch that is better than "not best security wise".
#3
HEAD now has a version suitable for D5 so this needs to rolled from HEAD again. Note that we have a hook_menu in this module now.
#4
@Moshe: do you mean "D6" in #3?
The patch inside the .zip #1 contains a hook_menu, which as Moshe says is now in HEAD, so that can probably be removed. What is the effect of the other changes supposed to be?
#5
OK, posting a patch here because this issue seems to have been posted earliest. Also relevant are:
The attached patch:
core = 6.xto the .info filewebserver_auth.installwhich modifies the {system} table to ensure the webserver_auth hooks are always run after user.module hooks. This was found to be necessary for the bits below...webserver_auth_menu()to (I hope) match 6.x conventions.webserver_auth_init()extensively:$_SERVER[].drupal_load(), because the {system} modification guarantees user.module will be loaded when this function is called.user_external_login_register(), which I guess was introduced to help with OpenID.webserver_auth_webserver_auth(), and moves most of its functionality towebserver_auth_user(), which:webserver_auth_settings():webserver_auth_domaintowebserver_auth_email_domain.webserver_auth_strip_prefix.webserver_auth_strip_domain.webserver_auth_insert.Notes
webserver_auth_insert:<?php// connect to LDAP
$ds = ldap_connect('ldap.example.com');
ldap_bind($ds, 'cn=myname,ou=users,dc=ldap,dc=example,dc=com', 'password');
// look up user by USERid
$search = ldap_search($ds, 'dc=ldap,dc=example,dc=com', 'userid='. $account->name);
$entry = ldap_first_entry($ds, $search);
$attr = ldap_get_attributes($ds, $entry);
ldap_unbind($ds);
// process canonical (full) name
if (array_key_exists('cn', $attr) && array_key_exists(0, $attr['cn']) && !empty($attr['cn'][0])) {
// update account object for further processing
$account->name = str_replace(' ', ' ', $attr['cn'][0]);
// save user name
db_query("UPDATE {users} SET name = '%s' WHERE uid = %d", $account->name, $account->uid);
}
?>
The effect of this is that the user's canonical (full) name is retrieved from the LDAP directory and set as their Drupal username, which looks much better than their Kerberos identifier (even with the domain stripped).
The only major difference the behaviour of this module is that it uses a completely un-mangled authname in the {authmap} table, and only changes the username in the {users} table. Prior to writing this patch I didn't know that {authmap} existed, hence my naive comments on some other issues. Also, the 'webserver_auth' hooks have disappeared in terms of a custom-PHP-from-the-user-interface-for-processing model, which is used elsewhere in Drupal and contributed modules (Blocks, Views, etc.)
Since this is more or less a total rewrite, I could submit separate patches but they would need to be applied simultaneously. I hope my explanations above serve just as well in making the code understandable.
Anyway, I would appreciate some eyes on the code, and maybe some testing (especially by NTLM users, since I don't have such a setup available for testing) and perhaps if it's alright even a 6.x development branch of the module which would be so so so wonderful (please?!).
#6
I have committed this patch to HEAD. I made some small changes. The only significant one is that I changed the username/email munging to happen during hook_user('submit') instead of 'insert'. That way, we don't have to UPDATE directly into users table. Also, all modules which listen on hook_user() get passed the correct username. Please test this. I actually coded this blind since I am not currently setup to test this module.
I made a DRUPAL-5 branch and finally a full D5 release. I also made a DRUPAL-6--1 branch and removed all the files from HEAD branch since thats going unused for a while.
Thanks for this nice patch.
#7
Automatically closed -- issue fixed for two weeks with no activity.
#8
@moshe: I just tried the 6.x-dev code, but the change to
hook_user('submit')doesn't appear to be working. I had used 'insert' instead of 'submit' becauseuser_module_invoke('insert', ...)is called duringuser_save(), right in the middle of the creation of the new account. The direct access to the database is messy, but I figured it was sanctioned when I read the following in the API docs forhook_user():I can't find a
user_module_invoke('submit', ...)call anywhere in core except in functions likeuser_edit_submit(), which appear only to be triggered on a form submission...not really what we want.For now I continue to run the code in my patch above; if you need me to reroll a patch against 6.x-dev, please let me know.
#9
paul - you are correct. please do reroll as you had it (no submit hook) and i will commit.
#10
Reroll.
#11
Committed. I'm issueing a release as well (finally). Thanks a ton.
#12
I'm trying to implement these patches but what are all the + and - and @ symbols? These cause errors in execution. Is there any way to get clean copies (cut & paste) versions? Thanks much.
#13
From http://drupal.org/patch: "patches describe the changes between a before and after state." If you only need the "after" state, you can download the 6.x-1.0 release.
#14
Thanks for this, can't believe I missed it. All is well now.
#15
Question on this new version: How hard would it be to backport to Drupal 5 and create a 5.x-1.0 release? I am interested in the new fixes and features here (especially the LDAP lookup scheme described in #5), but since some modules I'm using still aren't available for Drupal 6, upgrading is not yet a possibility.
#16
Automatically closed -- issue fixed for two weeks with no activity.