dsdb:schema: use NUMERIC_CMP in place of uint32_cmp
[Samba.git] / source4 / scripting / bin / findprovisionusnranges
blobb05b5cee3e8d388f0ec6ef4a4488cd33ce40cb48
1 #!/usr/bin/env python3
3 # Helper for determining USN ranges created of modified by provision and
4 # upgradeprovision.
5 # Copyright (C) Matthieu Patou <mat@matws.net> 2009-2011
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.
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.
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/>.
21 import sys
22 import optparse
23 sys.path.insert(0, "bin/python")
25 from samba.credentials import DONT_USE_KERBEROS
26 from samba.auth import system_session
27 from samba import Ldb
28 import ldb
29                 
30 import samba.getopt as options
31 from samba import param
32 from samba.upgradehelpers import get_paths, print_provision_ranges, findprovisionrange
33 from samba.ndr import ndr_unpack
34 from samba.dcerpc import misc
36 parser = optparse.OptionParser("findprovisionusnranges [options]")
37 sambaopts = options.SambaOptions(parser)
38 parser.add_option_group(sambaopts)
39 parser.add_option_group(options.VersionOptions(parser))
40 parser.add_option("--storedir", type="string", help="Directory where to store result files")
41 credopts = options.CredentialsOptions(parser)
42 parser.add_option_group(credopts)
43 opts = parser.parse_args()[0]
44 lp = sambaopts.get_loadparm()
45 smbconf = lp.configfile
47 creds = credopts.get_credentials(lp)
48 creds.set_kerberos_state(DONT_USE_KERBEROS)
49 session = system_session()
50 paths = get_paths(param, smbconf=smbconf)
51 basedn="DC=" + lp.get("realm").replace(".",",DC=")
52 samdb = Ldb(paths.samdb, session_info=session, credentials=creds,lp=lp)
54 res = samdb.search(base="", scope=ldb.SCOPE_BASE, attrs=["dsServiceName"])
56 invocation = None
57 if res and len(res) == 1 and res[0]["dsServiceName"] != None:
58     dn = ldb.Dn(samdb, str(res[0]["dsServiceName"]))
59     res = samdb.search(base=str(dn), scope=ldb.SCOPE_BASE, attrs=["invocationId"],
60                         controls=["search_options:1:2"])
62     if res and len(res) == 1 and res[0]["invocationId"]:
63         invocation = str(ndr_unpack(misc.GUID, res[0]["invocationId"][0]))   
64     else:
65         print("Unable to find invocation ID")
66         sys.exit(1)
67 else:
68     print("Unable to find attribute dsServiceName in rootDSE")
69     sys.exit(1)
71 minobj = 5
72 (hash_id, nb_obj) = findprovisionrange(samdb, basedn)
73 print("Here is a list of changes that modified more than %d objects in 1 minute." % minobj)
74 print("Usually changes made by provision and upgradeprovision are those who affect a couple"
75       " of hundred of objects or more")
76 print("Total number of objects: %d\n" % nb_obj)
78 print_provision_ranges(hash_id, minobj, opts.storedir, str(paths.samdb), invocation)