· 8 years ago · Aug 03, 2018, 02:08 PM
1diff -urN scuttle-0.7.2/config.inc.php.example scuttle-0.7.2-patched/config.inc.php.example
2--- scuttle-0.7.2/config.inc.php.example 2008-04-11 16:25:36.000000000 -0400
3+++ scuttle-0.7.2-patched/config.inc.php.example 2008-04-22 21:19:43.000000000 -0400
4@@ -116,5 +116,8 @@
5 );
6 $reservedusers = array('all', 'watchlist');
7
8+$use_ldap = false;
9+$ldap_host = 'ldap.foo.com';
10+
11 include_once('debug.inc.php');
12 ?>
13diff -urN scuttle-0.7.2/register.php scuttle-0.7.2-patched/register.php
14--- scuttle-0.7.2/register.php 2008-04-11 16:25:36.000000000 -0400
15+++ scuttle-0.7.2-patched/register.php 2008-04-11 17:42:44.000000000 -0400
16@@ -29,8 +29,8 @@
17 $posteduser = trim(utf8_strtolower($_POST['username']));
18
19 // Check if form is incomplete
20- if (!($posteduser) || !($_POST['password']) || !($_POST['email'])) {
21- $tplVars['error'] = T_('You <em>must</em> enter a username, password and e-mail address.');
22+ if (!($posteduser) || !($_POST['password'])) {
23+ $tplVars['error'] = T_('You <em>must</em> enter a username and password.');
24
25 // Check if username is reserved
26 } elseif ($userservice->isReserved($posteduser)) {
27@@ -40,12 +40,8 @@
28 } elseif ($userservice->getUserByUsername($posteduser)) {
29 $tplVars['error'] = T_('This username already exists, please make another choice.');
30
31- // Check if e-mail address is valid
32- } elseif (!$userservice->isValidEmail($_POST['email'])) {
33- $tplVars['error'] = T_('E-mail address is not valid. Please try again.');
34-
35 // Register details
36- } elseif ($userservice->addUser($posteduser, $_POST['password'], $_POST['email'])) {
37+ } elseif ($userservice->addUser($posteduser, $_POST['password'], "$posteduser@foo.com")) {
38 // Log in with new username
39 $login = $userservice->login($posteduser, $_POST['password']);
40 if ($login) {
41diff -urN scuttle-0.7.2/services/userservice.php scuttle-0.7.2-patched/services/userservice.php
42--- scuttle-0.7.2/services/userservice.php 2008-04-11 16:25:36.000000000 -0400
43+++ scuttle-0.7.2-patched/services/userservice.php 2008-04-23 10:16:12.000000000 -0400
44@@ -146,12 +146,23 @@
45 }
46
47 function login($username, $password, $remember = FALSE) {
48- $password = $this->sanitisePassword($password);
49- $query = 'SELECT '. $this->getFieldName('primary') .' FROM '. $this->getTableName() .' WHERE '. $this->getFieldName('username') .' = "'. $this->db->sql_escape($username) .'" AND '. $this->getFieldName('password') .' = "'. $this->db->sql_escape($password) .'"';
50-
51+ if (! $GLOBALS['use_ldap']) {
52+ $password = $this->sanitisePassword($password);
53+ $query = 'SELECT ' . $this->getFieldName('primary') .
54+ ' FROM ' . $this->getTableName() .
55+ ' WHERE ' . $this->getFieldName('username') .' = "'. $this->db->sql_escape($username) .
56+ '" AND ' . $this->getFieldName('password') . ' = "' . $password . '"';
57+ } else {
58+ if (! ($this->_ldapLogin($username, $password)) ) {
59+ return false;
60+ }
61+
62+ $query = 'SELECT '. $this->getFieldName('primary') .' FROM '. $this->getTableName() .' WHERE '. $this->getFieldName('username') .' = "'. $this->db->sql_escape($username) .'"';
63+ }
64+
65 if (! ($dbresult =& $this->db->sql_query($query)) ) {
66- message_die(GENERAL_ERROR, 'Could not get user', '', __LINE__, __FILE__, $query, $this->db);
67- return false;
68+ message_die(GENERAL_ERROR, 'Error accessing Scuttle database', '', __LINE__, __FILE__, $query, $this->db);
69+ return false;
70 }
71
72 if ($row =& $this->db->sql_fetchrow($dbresult)) {
73@@ -165,6 +176,21 @@
74 return false;
75 }
76 }
77+
78+ function _ldapLogin($username, $password) {
79+ $bind_user = $username . "@foo.com";
80+
81+ if ($ldap_conn = @ldap_connect($GLOBALS['ldap_host'])) {
82+ if (@ldap_bind($ldap_conn, $bind_user, $password)) {
83+ ldap_unbind($ldap_conn);
84+ return true;
85+ }
86+ } else {
87+ message_die(GENERAL_ERROR, 'Unable to connect to LDAP server.', '', __LINE__, __FILE__, NULL, NULL);
88+ }
89+
90+ return false;
91+ }
92
93 function logout() {
94 @setcookie($this->cookiekey, NULL, time() - 1);
95diff -urN scuttle-0.7.2/templates/register.tpl.php scuttle-0.7.2-patched/templates/register.tpl.php
96--- scuttle-0.7.2/templates/register.tpl.php 2008-04-11 16:25:36.000000000 -0400
97+++ scuttle-0.7.2-patched/templates/register.tpl.php 2008-04-11 18:11:16.000000000 -0400
98@@ -10,6 +10,8 @@
99
100 <p><?php echo sprintf(T_('Sign up here to create a free %s account. All the information requested below is required'), $GLOBALS['sitename']); ?>.</p>
101
102+<p><strong>Note:</strong> Enter your LDAP credentials below. For username, enter the first part of your email address (e.g. johndoe if your email address is johndoe@foo.com).</p>
103+
104 <form action="<?php echo $formaction; ?>" method="post">
105 <table>
106 <tr>
107@@ -23,11 +25,6 @@
108 <td></td>
109 </tr>
110 <tr>
111- <th align="left"><label for="email"><?php echo T_('E-mail'); ?></label></th>
112- <td><input type="text" id="email" name="email" size="40" class="required" /></td>
113- <td></td>
114-</tr>
115-<tr>
116 <td></td>
117 <td><input type="submit" name="submitted" value="<?php echo T_('Register'); ?>" /></td>
118 <td></td>