2003-12-27 11:21:00 +00:00
< ? php
/*
$Id $
This code is part of LDAP Account Manager ( http :// www . sourceforge . net / projects / lam )
Copyright ( C ) 2003 Tilo Lutz
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
the Free Software Foundation ; either version 2 of the License , or
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
along with this program ; if not , write to the Free Software
Foundation , Inc . , 59 Temple Place , Suite 330 , Boston , MA 02111 - 1307 USA
*/
/* Session variables which are used :
* $_SESSION [ 'cacheAttributes' ] : This variable contains a list of attributes and their scope which should be cached
*
* Coockie variables which are used :
* $_COOKIE [ " IV " ], $_COOKIE [ " Key " ] : Needed to en / decrypt passwords .
*
* Variables in basearray which are no objects :
* type : Type of account . Can be user , group , host
* attributes : List of all attributes , how to get them and are theiy required or optional
* dn : current DN without uid = or cn =
* dn_orig : old DN if account was loaded with uid = or cn =
* External functions which are used
* account . inc : findgroups , incache , get_cache , array_delete , getshells
* ldap . inc : pwd_is_enabled , pwd_hash
*/
/* This class contains all sambaGroupMapping LDAP attributes
* and funtioncs required to deal with sambaGroupMapping
* sambaGroupMapping can only be created when it should be added
* to an array .
* basearray is the same array sambaGroupMapping should be added
* to . If basearray is not given the constructor tries to
* create an array with sambaGroupMapping and all other required
* objects .
* Example : $user [] = new sambaGroupMapping ( $user );
*
* In container array the following things have to exist :
* account or inetOrgPerson object
* type : 'user' or 'host'
* 'attributes' : this is a list of arrays with all ldap attributes wich are allowed for this account
*/
class sambaGroupMapping {
// Constructor
function sambaGroupMapping ( $base ) {
/* Return an error if sambaGroupMapping should be created without
* base container
*/
if ( ! $base ) trigger_error ( _ ( 'Please create a base object with $var = new accountContainer();' ), E_USER_ERROR );
if ( ! is_string ( $base )) trigger_error ( _ ( 'Please create a new module object with $accountContainer->add_objectClass(\'sambaGroupMapping\');' ), E_USER_ERROR );
$this -> base = $base ;
// sambaGroupMapping is only a valid objectClass for user and host
if ( $_SESSION [ $this -> base ] -> get_type () != 'group' ) trigger_error ( _ ( 'sambaGroupMapping can only be used for groups.' ), E_USER_WARNING );
// Add Array with all attributes and type
$this -> attributes = $_SESSION [ $this -> base ] -> get_module_attributes ( 'sambaGroupMapping' );
$_SESSION [ $this -> base ] -> add_attributes ( 'sambaGroupMapping' );
$this -> alias = _ ( 'sambaGroupMapping' );
// Make references to attributes which already esists in ldap
$newattributes = array_keys ( $this -> attributes );
$module = array_keys ( $_SESSION [ $this -> base ] -> module );
// fixme *** do we have to unset module posixAccuont itself
for ( $i = 0 ; $i < count ( $module ); $i ++ ) {
foreach ( $newattributes as $attribute )
if ( isset ( $_SESSION [ $this -> base ] -> module [ $module [ $i ]] -> attributes [ $attribute ])) $this -> attributes [ $attribute ] =& $_SESSION [ $this -> base ] -> module [ $module [ $i ]] -> attributes [ $attribute ];
}
$this -> orig = $this -> attributes ;
$this -> rids = array ( _ ( 'Domain Admins' ) => 512 , _ ( 'Domain Users' ) => 513 , _ ( 'Domain Guests' ) => 514 , _ ( 'Domain Computers' ) => 515 , _ ( 'Domain Controllers' ) => 516 ,
_ ( 'Domain Certificate Admins' ) => 517 , _ ( 'Domain Schema Admins' ) => 518 , _ ( 'Domain Enterprise Admins' ) => 519 , _ ( 'Domain Policy Admins' ) => 520 );
}
// Variables
// name of accountContainer so we can read other classes in accuontArray
var $base ;
// This variable contains all inetOrgPerson attributes
var $attributes ;
/* If an account was loaded all attributes are kept in this array
* to compare it with new changed attributes
*/
var $orig ;
// Array of well known rids
var $rids ;
2003-12-30 15:36:30 +00:00
function get_alias () {
return _ ( 'sambaGroupMapping' );
}
2003-12-27 11:21:00 +00:00
/* This function returns a list with all required modules
*/
2003-12-30 15:36:30 +00:00
function get_dependencies ( $scope ) {
if ( $scope == 'group' ) return array ( 'require' => array ( 'posixGroup' ), 'conflict' => array () );
return - 1 ;
2003-12-27 11:21:00 +00:00
}
function module_ready () {
if ( $_SESSION [ $this -> base ] -> module [ 'posixGroup' ] -> attributes [ 'gidNumber' ][ 0 ] == '' ) return false ;
return true ;
}
2003-12-30 15:36:30 +00:00
/* This function returns a list of all html - pages in module
* This is usefull for mass upload and pdf - files
* because lam can walk trough all pages itself and do some
* error checkings
2003-12-27 11:21:00 +00:00
*/
2003-12-30 15:36:30 +00:00
function pages () {
return array ( 'attributes' );
2003-12-27 11:21:00 +00:00
}
2003-12-30 15:36:30 +00:00
/* This function returns all ldap attributes
* which are part of sambaGroupMapping and returns
* also their values .
*/
function get_attributes () {
return $this -> attributes ;
}
2003-12-27 11:21:00 +00:00
/* This function loads all attributes into the object
* $attr is an array as it ' s retured from ldap_get_attributes
*/
function load_attributes ( $attr ) {
// Load attributes which are displayed
// unset count entries
unset ( $attr [ 'count' ]);
$attributes = array_keys ( $attr );
foreach ( $attributes as $attribute ) unset ( $attr [ $attribute ][ 'count' ]);
// unset double entries
for ( $i = 0 ; $i < count ( $attr ); $i ++ )
if ( isset ( $attr [ $i ])) unset ( $attr [ $i ]);
foreach ( $attributes as $attribute ) {
if ( isset ( $this -> attributes [ $attribute ])) {
// decode as unicode
$this -> attributes [ $attribute ] = $attr [ $attribute ];
2003-12-30 17:09:15 +00:00
for ( $i = 0 ; $i < count ( $this -> attributes [ $attribute ]); $i ++ ) {
$this -> attributes [ $attribute ][ $i ] = utf8_decode ( $this -> attributes [ $attribute ][ $i ]);
$this -> orig [ $attribute ][ $i ] = utf8_decode ( $this -> attributes [ $attribute ][ $i ]);
}
2003-12-27 11:21:00 +00:00
}
}
// Values are kept as copy so we can compare old attributes with new attributes
$this -> attributes [ 'objectClass' ][ 0 ] = 'sambaGroupMapping' ;
return 0 ;
}
/* This function returns an array with 3 entries :
* array ( DN1 ( 'add' => array ( $attr ), 'remove' => array ( $attr ), 'modify' => array ( $attr )), DN2 .... )
* DN is the DN to change . It may be possible to change several DNs ,
* e . g . create a new user and add him to some groups via attribute memberUid
* add are attributes which have to be added to ldap entry
* remove are attributes which have to be removed from ldap entry
* modify are attributes which have to been modified in ldap entry
*/
function save_attributes () {
// Get Domain SID from name
$sambaDomains = $_SESSION [ $_SESSION [ $this -> base ] -> ldap ] -> search_domains ( $_SESSION [ $_SESSION [ $this -> base ] -> config ] -> get_domainSuffix ());
// Get Domain-SID from group SID
$domainSID = substr ( $this -> attributes [ 'sambaSID' ][ 0 ], 0 , strrpos ( $this -> attributes [ 'sambaSID' ][ 0 ], " - " ));
for ( $i = 0 ; $i < count ( $sambaDomains ); $i ++ )
if ( $domainSID == $sambaDomains [ $i ] -> SID )
$SID = $sambaDomains [ $i ] -> SID ;
$names = array_keys ( $this -> rids );
$wrid = false ;
for ( $i = 0 ; $i < count ( $names ); $i ++ )
if ( $this -> attributes [ 'sambaSID' ][ 0 ] == $SID . " - " . $this -> rids [ $names [ $i ]]) {
$wrid = true ;
}
if ( ! $wrid ) $this -> attributes [ 'sambaSID' ][ 0 ] == $SID . " - " . ( $_SESSION [ $this -> base ] -> module [ 'posixGroup' ] -> attributes [ 'gidNumber' ][ 0 ] * 2 + 1 + $RIDbase );
$return = $_SESSION [ $this -> base ] -> save_module_attributes ( $this -> attributes , $this -> orig );
return $return ;
}
2003-12-30 15:36:30 +00:00
function delete_attributes ( $post ) {
2004-01-10 11:47:48 +00:00
return 0 ;
2003-12-30 15:36:30 +00:00
}
2003-12-27 11:21:00 +00:00
2003-12-30 15:36:30 +00:00
/* Write variables into object and do some regexp checks
2003-12-27 11:21:00 +00:00
*/
2003-12-30 15:36:30 +00:00
function proccess_attributes ( $post ) {
// Get Domain SID from name
$sambaDomains = $_SESSION [ $_SESSION [ $this -> base ] -> ldap ] -> search_domains ( $_SESSION [ $_SESSION [ $this -> base ] -> config ] -> get_domainSuffix ());
for ( $i = 0 ; $i < count ( $sambaDomains ); $i ++ )
if ( $post [ 'sambaDomainName' ] == $sambaDomains [ $i ] -> name ) {
$SID = $sambaDomains [ $i ] -> SID ;
$RIDbase = $sambaDomain [ $i ] -> RIDbase ;
}
// Load attributes
$this -> attributes [ 'displayName' ][ 0 ] = $post [ 'displayName' ];
$this -> attributes [ 'sambaGroupType' ][ 0 ] = 2 ;
$rids = array_keys ( $this -> rids );
$wrid = false ;
for ( $i = 0 ; $i < count ( $rids ); $i ++ ) {
if ( $post [ 'sambaSID' ] == $rids [ $i ]) {
$wrid = true ;
// Get Domain SID
$this -> attributes [ 'sambaSID' ][ 0 ] = $SID . " - " . $this -> rids [ $rids [ $i ]];
// Do a check if special grou pis unique
if ( $_SESSION [ $_SESSION [ $this -> base ] -> cache ] -> in_cache ( $SID . " - " . $this -> rids [ $rids [ $i ]], 'sambaSID' , 'group' ))
$errors [] = array ( 'ERROR' , _ ( 'Special Group' ), sprintf ( _ ( 'There can be only one group %s.' ), $rids [ $i ]), 'sambaSID' );
}
}
if ( ! $wrid ) $this -> attributes [ 'sambaSID' ][ 0 ] = $SID . " - " . ( $_SESSION [ $this -> base ] -> module [ 'posixGroup' ] -> attributes [ 'gidNumber' ][ 0 ] * 2 ) + $RIDbase + 1 ;
// Return error-messages
if ( is_array ( $errors )) return $errors ;
return 0 ;
2003-12-27 11:21:00 +00:00
}
/* This function will create the html - page
* to show a page with all attributes .
* It will output a complete html - table
*/
function display_html_attributes ( $post ) {
// Get Domain SID from name
$sambaDomains = $_SESSION [ $_SESSION [ $this -> base ] -> ldap ] -> search_domains ( $_SESSION [ $_SESSION [ $this -> base ] -> config ] -> get_domainSuffix ());
// Get Domain-SID from group SID
$domainSID = substr ( $this -> attributes [ 'sambaSID' ][ 0 ], 0 , strrpos ( $this -> attributes [ 'sambaSID' ][ 0 ], " - " ));
for ( $i = 0 ; $i < count ( $sambaDomains ); $i ++ ) {
// List with all valid domains
$sambaDomainNames [] = $sambaDomains [ $i ] -> name ;
if ( $domainSID == $sambaDomains [ $i ] -> SID ) {
$SID = $sambaDomains [ $i ] -> SID ;
$sel_domain = $sambaDomains [ $i ] -> name ;
}
}
echo " <table border=0 width= \" 100% \" > \n " ;
echo " <tr> \n " ;
echo " <td> " . _ ( " Display name " ) . " </td> \n " ;
2003-12-30 15:36:30 +00:00
echo " <td><input name= \" displayName \" type= \" text \" size= \" 30 \" maxlength= \" 50 \" value= \" " . $this -> attributes [ 'displayName' ][ 0 ] . " \" ></td> \n " ;
2003-12-27 11:21:00 +00:00
echo " <td><a href= \" ../help.php?HelpNumber=420 \" target= \" lamhelp \" > " . _ ( 'Help' ) . " </a></td> \n " ;
echo " </tr> \n " ;
echo " <tr> \n " ;
echo " <td> " . _ ( 'Special group' ) . " </td> \n " ;
2003-12-30 15:36:30 +00:00
echo " <td><select name= \" sambaSID \" > " ;
2003-12-27 11:21:00 +00:00
// Display if group SID should be mapped to a well kown SID
$names = array_keys ( $this -> rids );
$wrid = false ;
for ( $i = 0 ; $i < count ( $names ); $i ++ ) {
if ( $this -> attributes [ 'sambaSID' ][ 0 ] == $SID . " - " . $this -> rids [ $names [ $i ]]) {
echo " <option selected> " . $names [ $i ] . " </option> " ;
$wrid = true ;
}
else echo " <option> " . $names [ $i ] . " </option> " ;
}
if ( $wrid ) echo " <option> " . $this -> attributes [ 'cn' ][ 0 ] . " </option> " ;
else echo " <option selected> " . $this -> attributes [ 'cn' ][ 0 ] . " </option> " ;
echo " </select></td> \n " ;
echo " <td><a href= \" ../help.php?HelpNumber=464 \" target= \" lamhelp \" > " . _ ( 'Help' ) . " </a></td> \n " ;
echo " </tr> \n " ;
echo " <tr> \n " ;
echo " <td> " . _ ( 'Domain' ) . " </td> \n " ;
2003-12-30 15:36:30 +00:00
echo " <td><select name= \" sambaDomainName \" > " ;
2003-12-27 11:21:00 +00:00
foreach ( $sambaDomainNames as $domain ) {
if ( $sel_domain == $domain ) echo " <option selected> $domain </option> " ;
else echo " <option> $domain </option> " ;
}
echo " </select></td> \n " ;
echo " <td><a href= \" ../help.php?HelpNumber=467 \" target= \" lamhelp \" > " . _ ( 'Help' ) . " </a></td> \n " ;
echo " </tr> \n " ;
echo " </table> \n " ;
return 0 ;
}
2003-12-30 15:36:30 +00:00
function display_html_delete ( $post ) {
return 0 ;
}
2003-12-27 11:21:00 +00:00
}
?>