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