Translation project - clean up a duplicate constant
[openemr.git] / library / authentication / privDB.php
blobbde753366ba035c89f4ce198c249242fc280b181
1 <?php
2 /**
3 * To support an optional higher level of security, queries that access password
4 * related information use these functions instead of the standard functions
5 * provided by sql.inc.
6 *
7 * By default, the privQuery and privStatement calls pass-through to
8 * the existing ADODB instance initialized by sql.inc.
9 *
10 * If an additional configuration file is created (secure_sqlconf.php) and saved
11 * in the sites/<sitename> directory (e.g. sites/default). The MySQL login
12 * information defined in that file as $secure_* will be used to create an ADODB
13 * instance specifically for querying privileged information.
15 * By configuring a server in this way, the default MySQL user can be denied access
16 * to sensitive tables (currently only "users_secure" would qualify). Thus
17 * the likelyhood of unintended modification can be reduced (e.g. through SQL Injection).
19 * Details on how to set this up are included in Documentation/privileged_db/priv_db_HOWTO
21 * The trade off for this additional security is extra complexity in configuration and
22 * maintenance of the database, hence it is not enabled at install time and must be
23 * done manually.
25 * Copyright (C) 2013 Kevin Yeh <kevin.y@integralemr.com> and OEMR <www.oemr.org>
27 * LICENSE: This program is free software; you can redistribute it and/or
28 * modify it under the terms of the GNU General Public License
29 * as published by the Free Software Foundation; either version 3
30 * of the License, or (at your option) any later version.
31 * This program is distributed in the hope that it will be useful,
32 * but WITHOUT ANY WARRANTY; without even the implied warranty of
33 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34 * GNU General Public License for more details.
35 * You should have received a copy of the GNU General Public License
36 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
38 * @package OpenEMR
39 * @author Kevin Yeh <kevin.y@integralemr.com>
40 * @link http://www.open-emr.org
44 define("PRIV_DB","PRIV_DB");
45 function getPrivDB()
47 if(!isset($GLOBALS[PRIV_DB]))
49 $secure_config=$GLOBALS['OE_SITE_DIR'] . "/secure_sqlconf.php";
50 if(file_exists($secure_config))
52 require_once($secure_config);
53 $GLOBALS[PRIV_DB]=NewADOConnection("mysql_log");
54 $GLOBALS[PRIV_DB]->PConnect($secure_host, $secure_login, $secure_pass, $secure_dbase);
56 else
58 $GLOBALS[PRIV_DB]=$GLOBALS['adodb']['db'];
61 return $GLOBALS[PRIV_DB];
64 /**
65 * mechanism to use "super user" for SQL queries related to password operations
67 * @param type $sql
68 * @param type $params
69 * @return type
71 function privStatement($sql,$params=null)
73 if(is_array($params))
75 $recordset = getPrivDB()->Execute( $sql, $params );
77 else
79 $recordset = getPrivDB()->Execute( $sql );
81 if ($recordset === FALSE) {
83 // These error messages are explictly NOT run through xl() because we still
84 // need them if there is a database problem.
85 echo "Failure during database access! Check server error log.";
87 error_log("Executing as user:" .getPrivDB()->user." Statement failed:".$sql.":");
88 exit;
90 return $recordset;
91 return sqlStatement($sql,$params);
94 /**
96 * Wrapper for privStatement that just returns the first row of a query or FALSE
97 * if there were no results.
99 * @param type $sql
100 * @param type $params
101 * @return boolean
103 function privQuery($sql,$params=null)
105 $recordset=privStatement($sql,$params);
106 if ($recordset->EOF)
107 return FALSE;
108 $rez = $recordset->FetchRow();
109 if ($rez == FALSE)
110 return FALSE;
111 return $rez;