1 # Unix SMB/CIFS implementation.
2 # Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2008
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 """Local host configuration."""
19 from .samdb
import SamDB
22 class Hostconfig(object):
23 """Aggregate object that contains all information about the configuration
26 def __init__(self
, lp
):
30 return SharesContainer(self
.lp
)
32 def get_samdb(self
, session_info
, credentials
):
33 """Access the SamDB host.
35 :param session_info: Session info to use
36 :param credentials: Credentials to access the SamDB with
38 return SamDB(url
=self
.lp
.samdb_url(),
39 session_info
=session_info
, credentials
=credentials
,
43 # TODO: Rather than accessing Loadparm directly here, we should really
44 # have bindings to the param/shares.c and use those.
47 class SharesContainer(object):
48 """A shares container."""
50 def __init__(self
, lp
):
53 def __getitem__(self
, name
):
55 # [global] is not a share
57 return Share(self
._lp
[name
])
60 if "global" in self
._lp
.services():
61 return len(self
._lp
) - 1
65 return [name
for name
in self
._lp
.services() if name
!= "global"]
68 return iter(self
.keys())
74 def __init__(self
, service
):
75 self
._service
= service
77 def __getitem__(self
, name
):
78 return self
._service
[name
]
80 def __setitem__(self
, name
, value
):
81 self
._service
[name
] = value