Blame view

pma/libraries/auth/signon.auth.lib.php 7.8 KB
a1684257   Administrator   first commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
  <?php
  /* vim: set expandtab sw=4 ts=4 sts=4: */
  /**
   * Set of functions used to run single signon authentication.
   *
   * @package PhpMyAdmin-Auth-Signon
   */
  
  
  /**
   * Displays authentication form
   *
   * @global  string    the font face to use in case of failure
   * @global  string    the default font size to use in case of failure
   * @global  string    the big font size to use in case of failure
   *
   * @return  boolean   always true (no return indeed)
   *
   * @access  public
   */
  function PMA_auth()
  {
      unset($_SESSION['LAST_SIGNON_URL']);
      if (empty($GLOBALS['cfg']['Server']['SignonURL'])) {
          PMA_fatalError('You must set SignonURL!');
      } elseif (!empty($_REQUEST['old_usr']) && !empty($GLOBALS['cfg']['Server']['LogoutURL'])) {
          /* Perform logout to custom URL */
          PMA_sendHeaderLocation($GLOBALS['cfg']['Server']['LogoutURL']);
      } else {
          PMA_sendHeaderLocation($GLOBALS['cfg']['Server']['SignonURL']);
      }
      exit();
  } // end of the 'PMA_auth()' function
  
  
  /**
   * Gets advanced authentication settings
   *
   * @global  string    the username if register_globals is on
   * @global  string    the password if register_globals is on
   * @global  array     the array of server variables if register_globals is
   *                    off
   * @global  array     the array of environment variables if register_globals
   *                    is off
   * @global  string    the username for the ? server
   * @global  string    the password for the ? server
   * @global  string    the username for the WebSite Professional server
   * @global  string    the password for the WebSite Professional server
   * @global  string    the username of the user who logs out
   *
   * @return  boolean   whether we get authentication settings or not
   *
   * @access  public
   */
  function PMA_auth_check()
  {
      global $PHP_AUTH_USER, $PHP_AUTH_PW;
  
      /* Check if we're using same sigon server */
      if (isset($_SESSION['LAST_SIGNON_URL']) && $_SESSION['LAST_SIGNON_URL'] != $GLOBALS['cfg']['Server']['SignonURL']) {
          return false;
      }
  
      /* Script name */
      $script_name = $GLOBALS['cfg']['Server']['SignonScript'];
  
      /* Session name */
      $session_name = $GLOBALS['cfg']['Server']['SignonSession'];
  
      /* Login URL */
      $signon_url = $GLOBALS['cfg']['Server']['SignonURL'];
  
      /* Current host */
      $single_signon_host = $GLOBALS['cfg']['Server']['host'];
  
      /* Current port */
      $single_signon_port = $GLOBALS['cfg']['Server']['port'];
  
      /* No configuration updates */
      $single_signon_cfgupdate = array();
  
      /* Are we requested to do logout? */
      $do_logout = !empty($_REQUEST['old_usr']);
  
      /* Handle script based auth */
      if (!empty($script_name)) {
          if (! file_exists($script_name)) {
              PMA_fatalError(__('Can not find signon authentication script:') . ' ' . $script_name);
          }
          include $script_name;
  
          list ($PHP_AUTH_USER, $PHP_AUTH_PW) = get_login_credentials($cfg['Server']['user']);
  
      /* Does session exist? */
      } elseif (isset($_COOKIE[$session_name])) {
          /* End current session */
          $old_session = session_name();
          $old_id = session_id();
          session_write_close();
  
          /* Load single signon session */
          session_name($session_name);
          session_id($_COOKIE[$session_name]);
          session_start();
  
          /* Clear error message */
          unset($_SESSION['PMA_single_signon_error_message']);
  
          /* Grab credentials if they exist */
          if (isset($_SESSION['PMA_single_signon_user'])) {
              if ($do_logout) {
                  $PHP_AUTH_USER = '';
              } else {
                  $PHP_AUTH_USER = $_SESSION['PMA_single_signon_user'];
              }
          }
          if (isset($_SESSION['PMA_single_signon_password'])) {
              if ($do_logout) {
                  $PHP_AUTH_PW = '';
              } else {
                  $PHP_AUTH_PW = $_SESSION['PMA_single_signon_password'];
              }
          }
          if (isset($_SESSION['PMA_single_signon_host'])) {
              $single_signon_host = $_SESSION['PMA_single_signon_host'];
          }
  
          if (isset($_SESSION['PMA_single_signon_port'])) {
              $single_signon_port = $_SESSION['PMA_single_signon_port'];
          }
  
          if (isset($_SESSION['PMA_single_signon_cfgupdate'])) {
              $single_signon_cfgupdate = $_SESSION['PMA_single_signon_cfgupdate'];
          }
  
  
          /* Also get token as it is needed to access subpages */
          if (isset($_SESSION['PMA_single_signon_token'])) {
              /* No need to care about token on logout */
              $pma_token = $_SESSION['PMA_single_signon_token'];
          }
  
          /* End single signon session */
          session_write_close();
  
          /* Restart phpMyAdmin session */
          session_name($old_session);
          if (!empty($old_id)) {
              session_id($old_id);
          }
          session_start();
  
          /* Set the single signon host */
          $GLOBALS['cfg']['Server']['host'] = $single_signon_host;
  
          /* Set the single signon port */
          $GLOBALS['cfg']['Server']['port'] = $single_signon_port;
  
          /* Configuration update */
          $GLOBALS['cfg']['Server'] = array_merge($GLOBALS['cfg']['Server'], $single_signon_cfgupdate);
  
          /* Restore our token */
          if (!empty($pma_token)) {
              $_SESSION[' PMA_token '] = $pma_token;
          }
  
          /**
           * Clear user cache.
           */
          PMA_clearUserCache();
      }
  
      // Returns whether we get authentication settings or not
      if (empty($PHP_AUTH_USER)) {
          unset($_SESSION['LAST_SIGNON_URL']);
          return false;
      } else {
          $_SESSION['LAST_SIGNON_URL'] = $GLOBALS['cfg']['Server']['SignonURL'];
          return true;
      }
  } // end of the 'PMA_auth_check()' function
  
  
  /**
   * Set the user and password after last checkings if required
   *
   * @global  array     the valid servers settings
   * @global  integer   the id of the current server
   * @global  array     the current server settings
   * @global  string    the current username
   * @global  string    the current password
   *
   * @return  boolean   always true
   *
   * @access  public
   */
  function PMA_auth_set_user()
  {
      global $cfg;
      global $PHP_AUTH_USER, $PHP_AUTH_PW;
  
      $cfg['Server']['user']     = $PHP_AUTH_USER;
      $cfg['Server']['password'] = $PHP_AUTH_PW;
  
      return true;
  } // end of the 'PMA_auth_set_user()' function
  
  
  /**
   * User is not allowed to login to MySQL -> authentication failed
   *
   * @return  boolean   always true (no return indeed)
   *
   * @access  public
   */
  function PMA_auth_fails()
  {
      /* Session name */
      $session_name = $GLOBALS['cfg']['Server']['SignonSession'];
  
      /* Does session exist? */
      if (isset($_COOKIE[$session_name])) {
          /* End current session */
          $old_session = session_name();
          $old_id = session_id();
          session_write_close();
  
          /* Load single signon session */
          session_name($session_name);
          session_id($_COOKIE[$session_name]);
          session_start();
  
          /* Set error message */
          if (! empty($GLOBALS['login_without_password_is_forbidden'])) {
              $_SESSION['PMA_single_signon_error_message'] = __('Login without a password is forbidden by configuration (see AllowNoPassword)');
          } elseif (! empty($GLOBALS['allowDeny_forbidden'])) {
              $_SESSION['PMA_single_signon_error_message'] = __('Access denied');
          } elseif (! empty($GLOBALS['no_activity'])) {
              $_SESSION['PMA_single_signon_error_message'] = sprintf(__('No activity within %s seconds; please log in again'), $GLOBALS['cfg']['LoginCookieValidity']);
          } elseif (PMA_DBI_getError()) {
              $_SESSION['PMA_single_signon_error_message'] = PMA_sanitize(PMA_DBI_getError());
          } else {
              $_SESSION['PMA_single_signon_error_message'] = __('Cannot log in to the MySQL server');
          }
      }
      PMA_auth();
  } // end of the 'PMA_auth_fails()' function
  
  ?>