python:tests: Store keys as bytes rather than as lists of ints
[samba.git] / source4 / scripting / bin / enablerecyclebin
1 #!/usr/bin/env python3
2 #
3 # enabled the Recycle Bin optional feature
4 #
5 import optparse
6 import sys
7
8 # Find right directory when running from source tree
9 sys.path.insert(0, "bin/python")
10
11 import samba
12 from samba import getopt as options, Ldb
13 from ldb import SCOPE_BASE
14 import sys
15 import ldb
16 from samba.auth import system_session
17
18 parser = optparse.OptionParser("enablerecyclebin <URL>")
19 sambaopts = options.SambaOptions(parser)
20 parser.add_option_group(sambaopts)
21 credopts = options.CredentialsOptions(parser)
22 parser.add_option_group(credopts)
23 parser.add_option_group(options.VersionOptions(parser))
24
25 opts, args = parser.parse_args()
26 opts.dump_all = True
27
28 if len(args) != 1:
29     parser.print_usage()
30     sys.exit(1)
31
32 url = args[0]
33
34 lp_ctx = sambaopts.get_loadparm()
35
36 creds = credopts.get_credentials(lp_ctx)
37 sam_ldb = Ldb(url, session_info=system_session(), credentials=creds, lp=lp_ctx)
38
39 # get the rootDSE
40 res = sam_ldb.search(base="", expression="", scope=SCOPE_BASE, attrs=["configurationNamingContext"])
41 rootDse = res[0]
42
43 configbase=rootDse["configurationNamingContext"]
44
45 # enable the feature
46 msg = ldb.Message()
47 msg.dn = ldb.Dn(sam_ldb, "")
48 msg["enableOptionalFeature"] = ldb.MessageElement(
49      "CN=Partitions," +  str(configbase) + ":766ddcd8-acd0-445e-f3b9-a7f9b6744f2a",
50      ldb.FLAG_MOD_ADD, "enableOptionalFeature")
51 res = sam_ldb.modify(msg)
52
53 print("Recycle Bin feature enabled")