BzzWare AS, Norway
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.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/***************************************************************************
* parse_samba_conf - parses the smb.conf on the machin lwat is running from
* check_samba_conf - Check if samba is configured somewhat correctly
* check_or_create - Check if some objects exists, or try to create them
***************************************************************************/
/***************************************************************************
* parse_samba_conf - parses the smb.conf on the machin lwat is running from
***************************************************************************/
function parse_samba_conf () {
$sambaconffile= @file ('/etc/samba/smb.conf') ;
$section = "empty";
$sambaconf = array () ;
if (empty ($sambaconffile)) return $sambaconf ;
foreach ($sambaconffile as $lines) {
$newline = trim ($lines) ;
switch ($newline[0]) {
case "#":
case ";":
case "";
break ;
case "[";
$section = strtolower(substr($newline, 1, strlen($newline) - 2)) ;
$sambaconf[$section] = array () ;
break ;
default:
list ($key, $value) = explode (" = ", $newline, 2);
$sambaconf[$section][strtolower(trim ($key))] = trim ($value) ;
break ;
}
}
return $sambaconf ;
}
/***************************************************************************
* check_samba_conf - Check if samba is configured somewhat correctly
*****************
* Arguments
* ldap - ldap connection
* base - search base for ldap queries
* authenticated - True if there is already an authenticated connection
* foundbase - If base is found in the ldap db
* smbAdmPW - Samba Adminstrator password
*****************
* return imidiatly if this function has already run
* Set variable to remember that function already has run
* Parse local samba config (may it can help us ...)
* set up search for ldap information from ldapDB
***************************************************************************/
function check_samba ($ldap, $base, $authenticated,
$foundbase = true, $smbAdmPW) {
global $samba_checked, $ldaphost, $groupprefix, $hostprefix;
if ($samba_checked) return ;
$samba_checked = true ;
$sambaconf = parse_samba_conf () ;
$want = array ('sambaDomainName', 'sambaSID') ;
$filter = ('objectClass=sambaDomain') ;
$result = ldap_search ($ldap, $base, $filter, $want) ;
$entries = ldap_get_entries ($ldap, $result) ;
$workgroup = $sambaconf["global"]["workgroup"] ;
switch ($entries[count]) {
case 1:
$workgroup = $entries[0]['sambadomainname'][0] ;
$sambaSID = $entries[0]['sambasid'][0] ;
break ;
}
$ldapSambaAdmin = $sambaconf["global"]["ldap admin dn"] ;
$want = array ("cn", "description") ;
$filter = "(&(objectClass=simpleSecurityObject)(description=samba administrator))" ;
$result = ldap_search ($ldap, $base, $filter, $want) ;
if ($result) {
$entries = ldap_get_entries ($ldap, $result) ;
$ldapSambaAdmin = $entries[0]["dn"];
$found = true ;
}
if (!$ldapSambaAdmin) {
$ldapSambaAdmin = "cn=smbadmin,$base" ;
$found=false ;
}
if ($found) {
$want = array ("cn", "description") ;
list ( $filter, $rest) = explode (",", $ldapSambaAdmin, 2) ;
$result = ldap_search ($ldap, $rest, $filter, $want) ;
if ($result) {
$entries = ldap_get_entries ($ldap, $result) ;
$ldapSambaAdmin = $entries[0]["dn"];
} else {
unset ($entries) ;
}
if (!$ldapSambaAdmin) {
$found=false ;
} else $found=true ;
}
printf ("