/[drupal]/contributions/modules/webserver_auth/webserver_auth.module
ViewVC logotype

Contents of /contributions/modules/webserver_auth/webserver_auth.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.17 - (show annotations) (download) (as text)
Tue Apr 24 01:09:26 2007 UTC (2 years, 7 months ago) by weitzman
Branch: MAIN
Changes since 1.16: +8 -2 lines
File MIME type: text/x-php
#68196 Name cleanup fix for NTLM and Negotiate. patch by anuradha.
1 <?php
2 // $Id: webserver_auth.module,v 1.16 2006/03/25 06:01:54 weitzman Exp $
3
4 function webserver_auth_init() {
5 global $user, $account;
6
7 // two ways to get $name
8 if ($name != $_SERVER["REMOTE_USER"]) {
9 $name = $_SERVER["REDIRECT_REMOTE_USER"];
10 }
11
12 if (isset($user) && $user->id && $user->name === $name) {
13 //do nothing because user is already logged into Drupal, and hasn't presented different credentials vis web server
14 }
15 else {
16 if ($name) {
17 // user is logged into webserver.
18 $account->name = $name;
19 //modules get to change the user bits before saving. use a global $account to do so.
20 // only loaded modules will see this hook
21 module_invoke_all("webserver_auth");
22 // if we are in bootstrap, load user.module ourselves
23 if (!module_exist('user')) {
24 drupal_load('module', 'user');
25 }
26
27 // try to log into Drupal. if unsuccessful, register the user
28 $user = user_external_load($account->name);
29 if (!$user->uid) {
30 if (variable_get("user_register", 1) == 1) {
31 $user_default = array("name" => $account->name, "pass" => "cyan", "init" => db_escape_string($name), "authname_webserver_auth" => $account->name, "status" => 1, "roles" => array(DRUPAL_AUTHENTICATED_RID));
32 // TODO - the hook_user('register') will fire but only for loaded modules. could be a problem for sites using page cache and that hook+operation
33 $user = user_save("", array_merge($user_default, (array)$account));
34 watchdog("user", "new user: $user->name (webserver_auth)", l(t("edit user"), "admin/user/edit/$user->uid"));
35 }
36 }
37 }
38 else {
39 // do nothing. user isn't logged into web server
40 }
41 }
42 }
43
44 // using a global to change your bits. module_invoke_all miffs me.
45 function webserver_auth_webserver_auth() {
46 global $account;
47
48 $account->name = trim($account->name);
49 // pretties up the username for NTLM authentication (i.e. Windows)
50 if ($_SERVER["AUTH_TYPE"] == "NTLM" || $_SERVER["AUTH_TYPE"] == 'Negotiate') {
51 if (!(strpos($account->name, "\\") === false)) {
52 $account->name = substr($account->name, strrpos($account->name, "\\")+1);
53 }
54 if (!(strpos($account->name, "@") === false)) {
55 $account->name = substr($account->name, 0, strrpos($account->name, "@"));
56 }
57 }
58
59 if ($domain = variable_get("webserver_auth_domain", "")) {
60 if ($account->name) {
61 $account->mail = $account->name. "@$domain";
62 }
63 }
64 }
65
66 function webserver_auth_settings() {
67 $form["webserver_auth_domain"] = array(
68 '#type' => 'textfield',
69 '#title' => t("Email Domain"),
70 '#default_value' => variable_get("webserver_auth_domain", ""),
71 '#size' => 30,
72 '#maxlength' => 55,
73 '#description' => t("Append this domain name to each new user in order generate his email address."),
74 );
75 return $form;
76 }
77
78 function webserver_auth_help($section) {
79 $output ="";
80
81 switch ($section) {
82 case 'admin/help#webserver_auth':
83 break;
84 case 'admin/modules#description':
85 $output .= t("Use web server authentication instead of Drupal");
86 break;
87 }
88
89 return $output;
90 }

  ViewVC Help
Powered by ViewVC 1.1.2