mirror of
https://github.com/samba-team/samba.git
synced 2025-01-10 01:18:15 +03:00
gpo: Test Group Policy Message of the day
Signed-off-by: David Mulder <dmulder@suse.com> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
This commit is contained in:
parent
fee00231f6
commit
e8757e0d36
22
python/samba/gp_msgs_ext.py
Normal file
22
python/samba/gp_msgs_ext.py
Normal file
@ -0,0 +1,22 @@
|
||||
# gp_msgs_ext samba gpo policy
|
||||
# Copyright (C) David Mulder <dmulder@suse.com> 2020
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# 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, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from samba.gpclass import gp_pol_ext
|
||||
|
||||
class gp_msgs_ext(gp_pol_ext):
|
||||
def process_group_policy(self, deleted_gpo_list, changed_gpo_list,
|
||||
cdir='/etc'):
|
||||
pass
|
@ -31,6 +31,7 @@ from samba.gpclass import gp_inf_ext
|
||||
from samba.gp_smb_conf_ext import gp_smb_conf_ext
|
||||
import logging
|
||||
from samba.credentials import Credentials
|
||||
from samba.gp_msgs_ext import gp_msgs_ext
|
||||
from samba.compat import get_bytes
|
||||
from samba.dcerpc import preg
|
||||
from samba.ndr import ndr_pack
|
||||
@ -718,3 +719,54 @@ class GPOTests(tests.TestCase):
|
||||
|
||||
# Unstage the Registry.pol file
|
||||
unstage_file(reg_pol)
|
||||
|
||||
def test_gp_motd(self):
|
||||
local_path = self.lp.cache_path('gpo_cache')
|
||||
guid = '{31B2F340-016D-11D2-945F-00C04FB984F9}'
|
||||
reg_pol = os.path.join(local_path, policies, guid,
|
||||
'MACHINE/REGISTRY.POL')
|
||||
logger = logging.getLogger('gpo_tests')
|
||||
cache_dir = self.lp.get('cache directory')
|
||||
store = GPOStorage(os.path.join(cache_dir, 'gpo.tdb'))
|
||||
|
||||
machine_creds = Credentials()
|
||||
machine_creds.guess(self.lp)
|
||||
machine_creds.set_machine_account()
|
||||
|
||||
# Initialize the group policy extension
|
||||
ext = gp_msgs_ext(logger, self.lp, machine_creds, store)
|
||||
|
||||
ads = gpo.ADS_STRUCT(self.server, self.lp, machine_creds)
|
||||
if ads.connect():
|
||||
gpos = ads.get_gpo_list(machine_creds.get_username())
|
||||
|
||||
# Stage the Registry.pol file with test data
|
||||
stage = preg.file()
|
||||
e = preg.entry()
|
||||
e.keyname = b'Software\\Policies\\Samba\\Unix Settings\\Messages'
|
||||
e.valuename = b'motd'
|
||||
e.type = 1
|
||||
e.data = b'Have a lot of fun!'
|
||||
stage.num_entries = 1
|
||||
stage.entries = [e]
|
||||
ret = stage_file(reg_pol, ndr_pack(stage))
|
||||
self.assertTrue(ret, 'Could not create the target %s' % reg_pol)
|
||||
|
||||
# Process all gpos, with temp output directory
|
||||
with TemporaryDirectory() as dname:
|
||||
ext.process_group_policy([], gpos, dname)
|
||||
motd_file = os.path.join(dname, 'motd')
|
||||
self.assertTrue(os.path.exists(motd_file),
|
||||
'Message of the day file not created')
|
||||
data = open(motd_file, 'r').read()
|
||||
self.assertEquals(data, e.data, 'Message of the day not applied')
|
||||
|
||||
# Unapply policy, and ensure the test files are removed
|
||||
gp_db = store.get_gplog(machine_creds.get_username())
|
||||
del_gpos = get_deleted_gpos_list(gp_db, [])
|
||||
ext.process_group_policy(del_gpos, [], dname)
|
||||
data = open(motd_file, 'r').read()
|
||||
self.assertFalse(data, 'Message of the day file not removed')
|
||||
|
||||
# Unstage the Registry.pol file
|
||||
unstage_file(reg_pol)
|
||||
|
@ -396,3 +396,4 @@
|
||||
^samba.tests.ntlmdisabled.python\(ktest\).python2.ntlmdisabled.NtlmDisabledTests.test_samr_change_password\(ktest\)
|
||||
^samba.tests.ntlmdisabled.python\(ad_dc_no_ntlm\).python3.ntlmdisabled.NtlmDisabledTests.test_ntlm_connection\(ad_dc_no_ntlm\)
|
||||
^samba.tests.ntlmdisabled.python\(ad_dc_no_ntlm\).python2.ntlmdisabled.NtlmDisabledTests.test_ntlm_connection\(ad_dc_no_ntlm\)
|
||||
^samba.tests.gpo.samba.tests.gpo.GPOTests.test_gp_motd
|
||||
|
Loading…
Reference in New Issue
Block a user