2008-08-01 23:12:37 +04:00
# Unix SMB/CIFS implementation.
# Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2008
2010-11-28 15:39:12 +03:00
#
2008-08-01 23:12:37 +04:00
# 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 3 of the License, or
# (at your option) any later version.
2010-11-28 15:39:12 +03:00
#
2008-08-01 23:12:37 +04:00
# 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.
2010-11-28 15:39:12 +03:00
#
2008-08-01 23:12:37 +04:00
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
2010-11-28 15:39:12 +03:00
""" Local host configuration. """
2018-04-03 06:24:28 +03:00
from . samdb import SamDB
2008-08-01 23:12:37 +04:00
2018-07-30 09:20:39 +03:00
2008-08-01 23:12:37 +04:00
class Hostconfig ( object ) :
2010-11-28 15:39:12 +03:00
""" Aggregate object that contains all information about the configuration
2008-08-01 23:12:37 +04:00
of a Samba host . """
2010-11-28 15:39:12 +03:00
def __init__ ( self , lp ) :
2008-08-01 23:12:37 +04:00
self . lp = lp
2010-11-28 15:39:12 +03:00
def get_shares ( self ) :
return SharesContainer ( self . lp )
2008-08-01 23:12:37 +04:00
def get_samdb ( self , session_info , credentials ) :
2010-11-28 15:39:12 +03:00
""" Access the SamDB host.
: param session_info : Session info to use
: param credentials : Credentials to access the SamDB with
"""
2011-06-02 09:43:40 +04:00
return SamDB ( url = self . lp . samdb_url ( ) ,
2010-11-28 15:39:12 +03:00
session_info = session_info , credentials = credentials ,
2008-08-01 23:12:37 +04:00
lp = self . lp )
2010-11-28 15:39:12 +03:00
# TODO: Rather than accessing Loadparm directly here, we should really
# have bindings to the param/shares.c and use those.
class SharesContainer ( object ) :
""" A shares container. """
def __init__ ( self , lp ) :
self . _lp = lp
def __getitem__ ( self , name ) :
if name == " global " :
# [global] is not a share
raise KeyError
return Share ( self . _lp [ name ] )
def __len__ ( self ) :
if " global " in self . _lp . services ( ) :
2018-07-30 09:18:25 +03:00
return len ( self . _lp ) - 1
2010-11-28 15:39:12 +03:00
return len ( self . _lp )
def keys ( self ) :
return [ name for name in self . _lp . services ( ) if name != " global " ]
def __iter__ ( self ) :
return iter ( self . keys ( ) )
class Share ( object ) :
""" A file share. """
def __init__ ( self , service ) :
self . _service = service
def __getitem__ ( self , name ) :
return self . _service [ name ]
def __setitem__ ( self , name , value ) :
self . _service [ name ] = value