2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Set of functions used to run single signon authentication.
6 * @package phpMyAdmin-Auth-Signon
12 * Displays authentication form
14 * @global string the font face to use in case of failure
15 * @global string the default font size to use in case of failure
16 * @global string the big font size to use in case of failure
18 * @return boolean always true (no return indeed)
23 if (empty($GLOBALS['cfg']['Server']['SignonURL'])) {
24 PMA_fatalError('You must set SignonURL!');
25 } elseif (!empty($_REQUEST['old_usr']) && !empty($GLOBALS['cfg']['Server']['LogoutURL'])) {
26 /* Perform logout to custom URL */
27 PMA_sendHeaderLocation($GLOBALS['cfg']['Server']['LogoutURL']);
29 PMA_sendHeaderLocation($GLOBALS['cfg']['Server']['SignonURL']);
32 } // end of the 'PMA_auth()' function
36 * Gets advanced authentication settings
38 * @global string the username if register_globals is on
39 * @global string the password if register_globals is on
40 * @global array the array of server variables if register_globals is
42 * @global array the array of environment variables if register_globals
44 * @global string the username for the ? server
45 * @global string the password for the ? server
46 * @global string the username for the WebSite Professional server
47 * @global string the password for the WebSite Professional server
48 * @global string the username of the user who logs out
50 * @return boolean whether we get authentication settings or not
54 function PMA_auth_check()
56 global $PHP_AUTH_USER, $PHP_AUTH_PW;
59 $session_name = $GLOBALS['cfg']['Server']['SignonSession'];
62 $single_signon_host = $GLOBALS['cfg']['Server']['host'];
65 $single_signon_port = $GLOBALS['cfg']['Server']['port'];
67 /* Are we requested to do logout? */
68 $do_logout = !empty($_REQUEST['old_usr']);
70 /* Does session exist? */
71 if (isset($_COOKIE[$session_name])) {
72 /* End current session */
73 $old_session = session_name();
74 $old_id = session_id();
75 session_write_close();
77 /* Load single signon session */
78 session_name($session_name);
79 session_id($_COOKIE[$session_name]);
82 /* Grab credentials if they exist */
83 if (isset($_SESSION['PMA_single_signon_user'])) {
87 $PHP_AUTH_USER = $_SESSION['PMA_single_signon_user'];
90 if (isset($_SESSION['PMA_single_signon_password'])) {
94 $PHP_AUTH_PW = $_SESSION['PMA_single_signon_password'];
97 if (isset($_SESSION['PMA_single_signon_host'])) {
98 $single_signon_host = $_SESSION['PMA_single_signon_host'];
101 if (isset($_SESSION['PMA_single_signon_port'])) {
102 $single_signon_port = $_SESSION['PMA_single_signon_port'];
106 /* Also get token as it is needed to access subpages */
107 if (isset($_SESSION['PMA_single_signon_token'])) {
108 /* No need to care about token on logout */
109 $pma_token = $_SESSION['PMA_single_signon_token'];
112 /* End single signon session */
113 session_write_close();
115 /* Restart phpMyAdmin session */
116 session_name($old_session);
117 if (!empty($old_id)) {
122 /* Set the single signon host */
123 $GLOBALS['cfg']['Server']['host']=$single_signon_host;
125 /* Set the single signon port */
126 $GLOBALS['cfg']['Server']['port'] = $single_signon_port;
127 /* Restore our token */
128 if (!empty($pma_token)) {
129 $_SESSION[' PMA_token '] = $pma_token;
133 // Returns whether we get authentication settings or not
134 if (empty($PHP_AUTH_USER)) {
139 } // end of the 'PMA_auth_check()' function
143 * Set the user and password after last checkings if required
145 * @global array the valid servers settings
146 * @global integer the id of the current server
147 * @global array the current server settings
148 * @global string the current username
149 * @global string the current password
151 * @return boolean always true
155 function PMA_auth_set_user()
158 global $PHP_AUTH_USER, $PHP_AUTH_PW;
160 $cfg['Server']['user'] = $PHP_AUTH_USER;
161 $cfg['Server']['password'] = $PHP_AUTH_PW;
164 } // end of the 'PMA_auth_set_user()' function
168 * User is not allowed to login to MySQL -> authentication failed
170 * @return boolean always true (no return indeed)
174 function PMA_auth_fails()
176 $error = PMA_DBI_getError();
177 if ($error && $GLOBALS['errno'] != 1045) {
178 PMA_fatalError($error);
184 } // end of the 'PMA_auth_fails()' function