source: vendor/current/source4/scripting/bin/findprovisionusnranges

Last change on this file was 988, checked in by Silvan Scherrer, 9 years ago

Samba Server: update vendor to version 4.4.3

File size: 2.9 KB
Line 
1#!/usr/bin/env python
2#
3# Helper for determining USN ranges created of modified by provision and
4# upgradeprovision.
5# Copyright (C) Matthieu Patou <mat@matws.net> 2009-2011
6#
7#
8# This program is free software; you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation; either version 3 of the License, or
11# (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License
19# along with this program. If not, see <http://www.gnu.org/licenses/>.
20#
21
22import sys
23import optparse
24sys.path.insert(0, "bin/python")
25
26from samba.credentials import DONT_USE_KERBEROS
27from samba.auth import system_session
28from samba import Ldb
29import ldb
30
31import samba.getopt as options
32from samba import param
33from samba.upgradehelpers import get_paths, print_provision_ranges, findprovisionrange
34from samba.ndr import ndr_unpack
35from samba.dcerpc import misc
36
37parser = optparse.OptionParser("provision [options]")
38sambaopts = options.SambaOptions(parser)
39parser.add_option_group(sambaopts)
40parser.add_option_group(options.VersionOptions(parser))
41parser.add_option("--storedir", type="string", help="Directory where to store result files")
42credopts = options.CredentialsOptions(parser)
43parser.add_option_group(credopts)
44opts = parser.parse_args()[0]
45lp = sambaopts.get_loadparm()
46smbconf = lp.configfile
47
48creds = credopts.get_credentials(lp)
49creds.set_kerberos_state(DONT_USE_KERBEROS)
50session = system_session()
51paths = get_paths(param, smbconf=smbconf)
52basedn="DC=" + lp.get("realm").replace(".",",DC=")
53samdb = Ldb(paths.samdb, session_info=session, credentials=creds,lp=lp)
54
55res = samdb.search(base="", scope=ldb.SCOPE_BASE, attrs=["dsServiceName"])
56
57invocation = None
58if res and len(res) == 1 and res[0]["dsServiceName"] != None:
59 dn = ldb.Dn(samdb, str(res[0]["dsServiceName"]))
60 res = samdb.search(base=str(dn), scope=ldb.SCOPE_BASE, attrs=["invocationId"],
61 controls=["search_options:1:2"])
62
63 if res and len(res) == 1 and res[0]["invocationId"]:
64 invocation = str(ndr_unpack(misc.GUID, res[0]["invocationId"][0]))
65 else:
66 print "Unable to find invocation ID"
67 sys.exit(1)
68else:
69 print "Unable to find attribute dsServiceName in rootDSE"
70 sys.exit(1)
71
72minobj = 5
73(hash_id, nb_obj) = findprovisionrange(samdb, basedn)
74print "Here is a list of changes that modified more than %d objects in 1 minute." % minobj
75print "Usually changes made by provision and upgradeprovision are those who affect a couple"\
76 " of hundred of objects or more"
77print "Total number of objects: %d" % nb_obj
78print
79
80print_provision_ranges(hash_id, minobj, opts.storedir, str(paths.samdb), invocation)
Note: See TracBrowser for help on using the repository browser.