/[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.18 - (show annotations) (download) (as text)
Tue Apr 24 01:17:45 2007 UTC (2 years, 7 months ago) by weitzman
Branch: MAIN
Changes since 1.17: +6 -3 lines
File MIME type: text/x-php
#138649 Conflict with Profile module (and potentially others). patch by zibas
1 <?php
2 // $Id: webserver_auth.module,v 1.17 2007/04/24 01:09:26 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 $test_user = user_external_load($account->name);
29 if (!$test_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 else{
38 $user = $test_user;
39 }
40 }
41 else {
42 // do nothing. user isn't logged into web server
43 }
44 }
45 }
46
47 // using a global to change your bits. module_invoke_all miffs me.
48 function webserver_auth_webserver_auth() {
49 global $account;
50
51 $account->name = trim($account->name);
52 // pretties up the username for NTLM authentication (i.e. Windows)
53 if ($_SERVER["AUTH_TYPE"] == "NTLM" || $_SERVER["AUTH_TYPE"] == 'Negotiate') {
54 if (!(strpos($account->name, "\\") === false)) {
55 $account->name = substr($account->name, strrpos($account->name, "\\")+1);
56 }
57 if (!(strpos($account->name, "@") === false)) {
58 $account->name = substr($account->name, 0, strrpos($account->name, "@"));
59 }
60 }
61
62 if ($domain = variable_get("webserver_auth_domain", "")) {
63 if ($account->name) {
64 $account->mail = $account->name. "@$domain";
65 }
66 }
67 }
68
69 function webserver_auth_settings() {
70 $form["webserver_auth_domain"] = array(
71 '#type' => 'textfield',
72 '#title' => t("Email Domain"),
73 '#default_value' => variable_get("webserver_auth_domain", ""),
74 '#size' => 30,
75 '#maxlength' => 55,
76 '#description' => t("Append this domain name to each new user in order generate his email address."),
77 );
78 return $form;
79 }
80
81 function webserver_auth_help($section) {
82 $output ="";
83
84 switch ($section) {
85 case 'admin/help#webserver_auth':
86 break;
87 case 'admin/modules#description':
88 $output .= t("Use web server authentication instead of Drupal");
89 break;
90 }
91
92 return $output;
93 }

  ViewVC Help
Powered by ViewVC 1.1.2