index 48e1db979f941c05703ca3fde1cb812e3cc16af1..677ebb193c86fbe16d749bfa387c3804ab54980c 100644 (file)
<?php
/*
- * This code is part of GOsa (https://gosa.gonicus.de)
- * Copyright (C) 2003 Cajus Pollmeier
+ * This code is part of GOsa (http://www.gosa-project.org)
+ * Copyright (C) 2003-2008 GONICUS GmbH
+ *
+ * ID: $$Id$$
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
define ("HELP_BASEDIR", "/var/www/doc/");
/* Define get_list flags */
-define("GL_NONE", 0);
-define("GL_SUBSEARCH", 1);
-define("GL_SIZELIMIT", 2);
-define("GL_CONVERT" , 4);
+define("GL_NONE", 0);
+define("GL_SUBSEARCH", 1);
+define("GL_SIZELIMIT", 2);
+define("GL_CONVERT", 4);
+define("GL_NO_ACL_CHECK", 8);
/* Heimdal stuff */
define('UNIVERSAL',0x00);
define('DES3_CBC_SHA1',16);
/* Define globals for revision comparing */
-$svn_path = '$HeadURL$';
-$svn_revision = '$Revision$';
+$svn_path = '$HeadURL: https://oss.gonicus.de/repositories/gosa/trunk/gosa-core/include/functions.inc $';
+$svn_revision = '$Revision: 9246 $';
/* Include required files */
require_once("class_location.inc");
if (isset($class_mapping[$class_name])){
require_once($BASE_DIR."/".$class_mapping[$class_name]);
} else {
- echo sprintf(_("Fatal error: cannot instantiate class '%s' - execution aborted"), $class_name);
- print_a(debug_backtrace());
+ echo sprintf(_("Fatal error: cannot instantiate class '%s' - try running '%s' to fix this"), $class_name, "<b>update-gosa</b>");
exit;
}
}
+/*! \brief Checks if a class is available.
+ * @param name String The class name.
+ * @return boolean True if class is available, else false.
+ */
+function class_available($name)
+{
+ global $class_mapping;
+ return(isset($class_mapping[$name]));
+}
+
+
/* Check if plugin is avaliable */
function plugin_available($plugin)
{
/* Look for entry or realm */
$ldap= $config->get_ldap_link();
if (!preg_match("/Success/i", $ldap->error)){
- msg_dialog::display(_("LDAP error"), sprintf(_('User login failed.').'<br><br>'._('LDAP server returned: %s'), "<br><br><i>".$ldap->get_error()."</i>"), ERROR_DIALOG);
+ msg_dialog::display(_("LDAP error"), sprintf(_('User login failed.').'<br><br>'._('LDAP server returned: %s'), "<br><br><i>".$ldap->get_error()."</i>"), FATAL_ERROR_DIALOG);
$smarty= get_smarty();
$smarty->display(get_template_path('headers.tpl'));
echo "<body>".session::get('errors')."</body></html>";
$ldap->search("(&(objectClass=gosaAccount)(uid=$username))", array("uid"));
/* Found no uniq match? Strange, because we did above... */
if ($ldap->count() != 1) {
- msg_dialog::display(_("LDAP error"), _("Username / UID is not unique inside the LDAP tree. Please contact your Administrator."), ERROR_DIALOG);
+ msg_dialog::display(_("LDAP error"), _("Username / UID is not unique inside the LDAP tree. Please contact your Administrator."), FATAL_ERROR_DIALOG);
return (NULL);
}
$attrs= $ldap->fetch();
/* look through the entire ldap */
$ldap = $config->get_ldap_link();
if (!preg_match("/Success/i", $ldap->error)){
- msg_dialog::display(_("LDAP error"), sprintf(_("User login failed.")."<br><br>"._('LDAP server returned: %s'), "<br><br><i>".$ldap->get_error()."</i>"), ERROR_DIALOG);
+ msg_dialog::display(_("LDAP error"), sprintf(_("User login failed.")."<br><br>"._('LDAP server returned: %s'), "<br><br><i>".$ldap->get_error()."</i>"), FATAL_ERROR_DIALOG);
$smarty= get_smarty();
$smarty->display(get_template_path('headers.tpl'));
echo "<body>".session::get('errors')."</body></html>";
/* found more than one matching id */
default:
- msg_dialog::display(_("Internal error"), _("Username / UID is not unique inside the LDAP tree. Please contact your Administrator."), ERROR_DIALOG);
+ msg_dialog::display(_("Internal error"), _("Username / UID is not unique inside the LDAP tree. Please contact your Administrator."), FATAL_ERROR_DIALOG);
return (NULL);
}
/* \!brief This function searches the ldap database.
- It search in $sub_base,*,$base for all objects matching the $filter.
+ It search in $sub_bases,*,$base for all objects matching the $filter.
@param $filter String The ldap search filter
@param $category String The ACL category the result objects belongs
- @param $sub_base String The sub base we want to search for e.g. "ou=apps"
+ @param $sub_bases String The sub base we want to search for e.g. "ou=apps"
@param $base String The ldap base from which we start the search
@param $attributes Array The attributes we search for.
@param $flags Long A set of Flags
*/
-function get_sub_list($filter, $category,$sub_base, $base= "", $attributes= array(), $flags= GL_SUBSEARCH)
+function get_sub_list($filter, $category,$sub_deps, $base= "", $attributes= array(), $flags= GL_SUBSEARCH)
{
-
global $config, $ui;
+ $departments = array();
+
+# $start = microtime(TRUE);
/* Get LDAP link */
$ldap= $config->get_ldap_link($flags & GL_SIZELIMIT);
/* Set search base to configured base if $base is empty */
if ($base == ""){
- $ldap->cd ($config->current['BASE']);
- } else {
- $ldap->cd ($base);
+ $base = $config->current['BASE'];
+ }
+ $ldap->cd ($base);
+
+ /* Ensure we have an array as department list */
+ if(is_string($sub_deps)){
+ $sub_deps = array($sub_deps);
}
- /* Remove , ("ou=1,ou=2.." => "ou=1") */
- $sub_base = preg_replace("/,.*$/","",$sub_base);
+ /* Remove ,.*$ ("ou=1,ou=2.." => "ou=1") */
+ $sub_bases = array();
+ foreach($sub_deps as $key => $sub_base){
+ if(empty($sub_base)){
- /* Check if there is a sub department specified */
- if($sub_base == ""){
- return(get_list($filter, $category,$base,$attributes,$flags));
+ /* Subsearch is activated and we got an empty sub_base.
+ * (This may be the case if you have empty people/group ous).
+ * Fall back to old get_list().
+ * A log entry will be written.
+ */
+ if($flags & GL_SUBSEARCH){
+ $sub_bases = array();
+ break;
+ }else{
+
+ /* Do NOT search within subtrees is requeste and the sub base is empty.
+ * Append all known departments that matches the base.
+ */
+ $departments[$base] = $base;
+ }
+ }else{
+ $sub_bases[$key] = preg_replace("/,.*$/","",$sub_base);
+ }
+ }
+
+ /* If there is no sub_department specified, fall back to old method, get_list().
+ */
+ if(!count($sub_bases) && !count($departments)){
+
+ /* Log this fall back, it may be an unpredicted behaviour.
+ */
+ if(!count($sub_bases) && !count($departments)){
+ // log($action,$objecttype,$object,$changes_array = array(),$result = "")
+ new log("debug","all",__FILE__,$attributes,
+ sprintf("get_sub_list(): Falling back to get_list(), due to empty sub_bases parameter.".
+ " This may slow down GOsa. Search was: '%s'",$filter));
+ }
+ $tmp = get_list($filter, $category,$base,$attributes,$flags);
+ return($tmp);
}
- /* Get all deparments matching the given sub_base */
- $departments = array();
- $ldap->search($sub_base,array("dn"));
+ /* Get all deparments matching the given sub_bases */
+ $base_filter= "";
+ foreach($sub_bases as $sub_base){
+ $base_filter .= "(".$sub_base.")";
+ }
+ $base_filter = "(&(objectClass=organizationalUnit)(|".$base_filter."))";
+ $ldap->search($base_filter,array("dn"));
while($attrs = $ldap->fetch()){
- $departments[$attrs['dn']] = $attrs['dn'];
+ foreach($sub_deps as $sub_dep){
+
+ /* Only add those departments that match the reuested list of departments.
+ *
+ * e.g. sub_deps = array("ou=servers,ou=systems,");
+ *
+ * In this case we have search for "ou=servers" and we may have also fetched
+ * departments like this "ou=servers,ou=blafasel,..."
+ * Here we filter out those blafasel departments.
+ */
+ if(preg_match("/".normalizePreg($sub_dep)."/",$attrs['dn'])){
+ $departments[$attrs['dn']] = $attrs['dn'];
+ break;
+ }
+ }
}
$result= array();
@@ -791,7 +861,7 @@ function get_sub_list($filter, $category,$sub_base, $base= "", $attributes= arra
if ($flags & GL_SUBSEARCH) {
$ldap->search ($filter, $attributes);
} else {
- $ldap->ls ($filter,$base,$attributes);
+ $ldap->ls ($filter,$dep,$attributes);
}
/* Check for size limit exceeded messages for GUI feedback */
@@ -812,21 +882,30 @@ function get_sub_list($filter, $category,$sub_base, $base= "", $attributes= arra
$attrs["dn"]= $dn;
}
- /* Sort in every value that fits the permissions */
- if (is_array($category)){
- foreach ($category as $o){
- if ($ui->get_category_permissions($dn, $o) != ""){
+ /* Skip ACL checks if we are forced to skip those checks */
+ if($flags & GL_NO_ACL_CHECK){
+ $result[]= $attrs;
+ }else{
+
+ /* Sort in every value that fits the permissions */
+ if (is_array($category)){
+ foreach ($category as $o){
+ if ($ui->get_category_permissions($dn, $o) != ""){
+ $result[]= $attrs;
+ break;
+ }
+ }
+ } else {
+ if ( $ui->get_category_permissions($dn, $category) != ""){
$result[]= $attrs;
- break;
}
}
- } else {
- if ($ui->get_category_permissions($dn, $category) != ""){
- $result[]= $attrs;
- }
}
}
}
+# if(microtime(TRUE) - $start > 0.1){
+# echo sprintf("<pre>GET_SUB_LIST %s .| %f --- $base -----$filter ---- $flags</pre>",__LINE__,microtime(TRUE) - $start);
+# }
return($result);
}
@@ -835,6 +914,8 @@ function get_list($filter, $category, $base= "", $attributes= array(), $flags= G
{
global $config, $ui;
+# $start = microtime(TRUE);
+
/* Get LDAP link */
$ldap= $config->get_ldap_link($flags & GL_SIZELIMIT);
@@ -862,36 +943,42 @@ function get_list($filter, $category, $base= "", $attributes= array(), $flags= G
$result= array();
while($attrs = $ldap->fetch()) {
+
$dn= $ldap->getDN();
- /* Sort in every value that fits the permissions */
- if (is_array($category)){
- foreach ($category as $o){
- if ($ui->get_category_permissions($dn, $o) != ""){
- if ($flags & GL_CONVERT){
- $attrs["dn"]= convert_department_dn($dn);
- } else {
- $attrs["dn"]= $dn;
+ /* Convert dn into a printable format */
+ if ($flags & GL_CONVERT){
+ $attrs["dn"]= convert_department_dn($dn);
+ } else {
+ $attrs["dn"]= $dn;
+ }
+
+ if($flags & GL_NO_ACL_CHECK){
+ $result[]= $attrs;
+ }else{
+
+ /* Sort in every value that fits the permissions */
+ if (is_array($category)){
+ foreach ($category as $o){
+ if ($ui->get_category_permissions($dn, $o) != ""){
+
+ /* We found what we were looking for, break speeds things up */
+ $result[]= $attrs;
}
+ }
+ } else {
+ if ($ui->get_category_permissions($dn, $category) != ""){
/* We found what we were looking for, break speeds things up */
$result[]= $attrs;
}
}
- } else {
- if ($ui->get_category_permissions($dn, $category) != ""){
- if ($flags & GL_CONVERT){
- $attrs["dn"]= convert_department_dn($dn);
- } else {
- $attrs["dn"]= $dn;
- }
-
- /* We found what we were looking for, break speeds things up */
- $result[]= $attrs;
- }
}
}
-
+
+# if(microtime(TRUE) - $start > 0.1){
+# echo sprintf("<pre>GET_LIST %s .| %f --- $base -----$filter ---- $flags</pre>",__LINE__,microtime(TRUE) - $start);
+# }
return ($result);
}
/* Assemble the message array to a plain string */
foreach ($message as $error){
- if ($complete == ""){
- $complete= $error;
- } else {
- $complete= "$error<br>$complete";
- }
+ msg_dialog::display(_("Error"), $error, ERROR_DIALOG);
}
-
- /* Fill ERROR variable with nice error dialog */
- msg_dialog::display(_("Error"), $complete, ERROR_DIALOG);
}
}
if(!$rfc2307bis && !isset($tmp['posixGroup']['STRUCTURAL'])){
$checks['posixGroup']['STATUS'] = FALSE;
- $checks['posixGroup']['MSG'] = _("You have disabled the rfc2307bis option on the 'ldap setup' step, but your schema configuration do not support this option.");
+ $checks['posixGroup']['MSG'] = _("Your schema is configured to support the rfc2307bis group, but you have disabled this option on the 'ldap setup' step.");
$checks['posixGroup']['INFO'] = _("The objectClass 'posixGroup' must be STRUCTURAL");
}
}
function generate_smb_nt_hash($password)
{
global $config;
- $tmp= $config->data['MAIN']['SMBHASH']." ".escapeshellarg($password);
- @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__, $tmp, "Execute");
- exec($tmp, $ar);
- flush();
- reset($ar);
- $hash= current($ar);
+ # Try to use gosa-si?
+ if (isset($config->current['GOSA_SI'])){
+ $res= gosaSupportDaemon::send("gosa_gen_smb_hash", "GOSA", array("password" => $password), TRUE);
+ $hash= $res['XML']['HASH'];
+ } else {
+ $tmp= $config->data['MAIN']['SMBHASH']." ".escapeshellarg($password);
+ @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__, $tmp, "Execute");
+
+ exec($tmp, $ar);
+ flush();
+ reset($ar);
+ $hash= current($ar);
+ }
+
if ($hash == "") {
- msg_dialog::display(_("Configuration error"), _("Setting for SMBHASH in gosa.conf is incorrect! Cannot change Samba password."), ERROR_DIALOG);
+ msg_dialog::display(_("Configuration error"), _("Cannot generate samba hash!"), ERROR_DIALOG);
+ return ("");
+ }
+
+ list($lm,$nt)= split (":", trim($hash));
+
+ if ($config->current['SAMBAVERSION'] == 3) {
+ $attrs['sambaLMPassword']= $lm;
+ $attrs['sambaNTPassword']= $nt;
+ $attrs['sambaPwdLastSet']= date('U');
+ $attrs['sambaBadPasswordCount']= "0";
+ $attrs['sambaBadPasswordTime']= "0";
} else {
- list($lm,$nt)= split (":", trim($hash));
-
- if ($config->current['SAMBAVERSION'] == 3) {
- $attrs['sambaLMPassword']= $lm;
- $attrs['sambaNTPassword']= $nt;
- $attrs['sambaPwdLastSet']= date('U');
- $attrs['sambaBadPasswordCount']= "0";
- $attrs['sambaBadPasswordTime']= "0";
- } else {
- $attrs['lmPassword']= $lm;
- $attrs['ntPassword']= $nt;
- $attrs['pwdLastSet']= date('U');
- }
- return($attrs);
+ $attrs['lmPassword']= $lm;
+ $attrs['ntPassword']= $nt;
+ $attrs['pwdLastSet']= date('U');
}
+ return($attrs);
}
}
}
+/*! \brief Initialize a file download with given content, name and data type.
+ * @param data String The content to send.
+ * @param name String The name of the file.
+ * @param type String The content identifier, default value is "application/octet-stream";
+ */
+function send_binary_content($data,$name,$type = "application/octet-stream")
+{
+ header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
+ header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
+ header("Cache-Control: no-cache");
+ header("Pragma: no-cache");
+ header("Cache-Control: post-check=0, pre-check=0");
+ header("Content-type: ".$type."");
+
+ /* force download dialog */
+ if (preg_match('/MSIE 5.5/', $HTTP_USER_AGENT) || preg_match('/MSIE 6.0/', $HTTP_USER_AGENT)) {
+ header('Content-Disposition: filename="'.$name.'"');
+ } else {
+ header('Content-Disposition: attachment; filename="'.$name.'"');
+ }
-function display_error_page()
-{
- $smarty= get_smarty();
- $smarty->display(get_template_path('headers.tpl'));
- echo "<body>".msg_dialog::get_dialogs()."</body></html>";
+ echo $data;
exit();
}