/[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.19 - (show annotations) (download) (as text)
Mon Mar 10 21:43:42 2008 UTC (20 months, 2 weeks ago) by weitzman
Branch: MAIN
CVS Tags: DRUPAL-5--0-0-RC1
Changes since 1.18: +18 -4 lines
File MIME type: text/x-php
#109576 by scor and moshe weitzman. update webserver_auth module to D5
1 <?php
2 // $Id: webserver_auth.module,v 1.18 2007/04/24 01:17:45 weitzman Exp $
3
4 function webserver_auth_menu($may_cache) {
5 if ($may_cache) {
6 $items[] = array(
7 'title' => t('Webserver authentication'),
8 'path' => "admin/settings/webserver_auth",
9 'callback' => "drupal_get_form",
10 'callback arguments' => array('webserver_auth_settings'),
11 'description' => t('Configure a domain for generating email addresses. Optional.'),
12 );
13 }
14 return $items;
15
16 }
17
18 function webserver_auth_init() {
19 global $user, $account;
20
21 // two ways to get $name
22 if ($name != $_SERVER["REMOTE_USER"]) {
23 $name = $_SERVER["REDIRECT_REMOTE_USER"];
24 }
25
26 if (isset($user) && $user->id && $user->name === $name) {
27 //do nothing because user is already logged into Drupal, and hasn't presented different credentials vis web server
28 }
29 else {
30 if ($name) {
31 // user is logged into webserver.
32 $account->name = $name;
33 //modules get to change the user bits before saving. use a global $account to do so.
34 // only loaded modules will see this hook
35 module_invoke_all("webserver_auth");
36 // if we are in bootstrap, load user.module ourselves
37 if (!module_exists('user')) {
38 drupal_load('module', 'user');
39 }
40
41 // try to log into Drupal. if unsuccessful, register the user
42 $test_user = user_external_load($account->name);
43 if (!$test_user->uid) {
44 if (variable_get("user_register", 1) == 1) {
45 $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));
46 // 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
47 $user = user_save("", array_merge($user_default, (array)$account));
48 watchdog("user", "new user: $user->name (webserver_auth)", l(t("edit user"), "admin/user/edit/$user->uid"));
49 }
50 }
51 else{
52 $user = $test_user;
53 }
54 }
55 else {
56 // do nothing. user isn't logged into web server
57 }
58 }
59 }
60
61 // using a global to change your bits. module_invoke_all miffs me.
62 function webserver_auth_webserver_auth() {
63 global $account;
64
65 $account->name = trim($account->name);
66 // pretties up the username for NTLM authentication (i.e. Windows)
67 if ($_SERVER["AUTH_TYPE"] == "NTLM" || $_SERVER["AUTH_TYPE"] == 'Negotiate') {
68 if (!(strpos($account->name, "\\") === false)) {
69 $account->name = substr($account->name, strrpos($account->name, "\\")+1);
70 }
71 if (!(strpos($account->name, "@") === false)) {
72 $account->name = substr($account->name, 0, strrpos($account->name, "@"));
73 }
74 }
75
76 if ($domain = variable_get("webserver_auth_domain", "")) {
77 if ($account->name) {
78 $account->mail = $account->name. "@$domain";
79 }
80 }
81 }
82
83 function webserver_auth_settings() {
84 $form["webserver_auth_domain"] = array(
85 '#type' => 'textfield',
86 '#title' => t("Email Domain"),
87 '#default_value' => variable_get("webserver_auth_domain", ""),
88 '#size' => 30,
89 '#maxlength' => 55,
90 '#description' => t("Append this domain name to each new user in order generate his email address. Currently only used for NTLM authentication."),
91 );
92 return system_settings_form($form);
93 }
94
95 function webserver_auth_help($section) {
96 $output ="";
97
98 switch ($section) {
99 case 'admin/help#webserver_auth':
100 break;
101 case 'admin/modules#description':
102 $output .= t("Use web server authentication instead of Drupal");
103 break;
104 }
105
106 return $output;
107 }

  ViewVC Help
Powered by ViewVC 1.1.2