/[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 - (hide 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 weitzman 1.1 <?php
2 weitzman 1.17 // $Id: webserver_auth.module,v 1.16 2006/03/25 06:01:54 weitzman Exp $
3 weitzman 1.1
4 weitzman 1.5 function webserver_auth_init() {
5     global $user, $account;
6 weitzman 1.10
7 weitzman 1.16 // 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 weitzman 1.1 }
15     else {
16 weitzman 1.16 if ($name) {
17 weitzman 1.10 // user is logged into webserver.
18 weitzman 1.5 $account->name = $name;
19     //modules get to change the user bits before saving. use a global $account to do so.
20 weitzman 1.12 // only loaded modules will see this hook
21 weitzman 1.5 module_invoke_all("webserver_auth");
22 weitzman 1.12 // if we are in bootstrap, load user.module ourselves
23     if (!module_exist('user')) {
24     drupal_load('module', 'user');
25     }
26 weitzman 1.10
27 weitzman 1.5 // try to log into Drupal. if unsuccessful, register the user
28 weitzman 1.7 $user = user_external_load($account->name);
29 weitzman 1.1 if (!$user->uid) {
30     if (variable_get("user_register", 1) == 1) {
31 weitzman 1.14 $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 weitzman 1.16 // 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 weitzman 1.13 $user = user_save("", array_merge($user_default, (array)$account));
34 weitzman 1.5 watchdog("user", "new user: $user->name (webserver_auth)", l(t("edit user"), "admin/user/edit/$user->uid"));
35 weitzman 1.1 }
36     }
37     }
38     else {
39     // do nothing. user isn't logged into web server
40     }
41     }
42     }
43    
44 weitzman 1.5 // using a global to change your bits. module_invoke_all miffs me.
45     function webserver_auth_webserver_auth() {
46     global $account;
47 weitzman 1.10
48 weitzman 1.17 $account->name = trim($account->name);
49 weitzman 1.3 // pretties up the username for NTLM authentication (i.e. Windows)
50 weitzman 1.6 if ($_SERVER["AUTH_TYPE"] == "NTLM" || $_SERVER["AUTH_TYPE"] == 'Negotiate') {
51 weitzman 1.17 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 weitzman 1.5 }
58 weitzman 1.10
59 weitzman 1.5 if ($domain = variable_get("webserver_auth_domain", "")) {
60     if ($account->name) {
61     $account->mail = $account->name. "@$domain";
62     }
63 weitzman 1.3 }
64     }
65    
66 weitzman 1.5 function webserver_auth_settings() {
67 weitzman 1.13 $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 weitzman 1.5 }
77    
78 weitzman 1.3 function webserver_auth_help($section) {
79     $output ="";
80    
81     switch ($section) {
82     case 'admin/help#webserver_auth':
83     break;
84 weitzman 1.8 case 'admin/modules#description':
85 weitzman 1.3 $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