WHATSNEW: Update changes.
[Samba.git] / source4 / scripting / bin / enablerecyclebin
blob61ad32cd49530b58178c44f119ec2733baad8a63
1 #!/usr/bin/env python
3 # enabled the Recycle Bin optional feature
5 import base64
6 import optparse
7 import os
8 import sys
10 # Find right directory when running from source tree
11 sys.path.insert(0, "bin/python")
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 from samba.auth import system_session
20 parser = optparse.OptionParser("enablerecyclebin <URL>")
21 sambaopts = options.SambaOptions(parser)
22 parser.add_option_group(sambaopts)
23 credopts = options.CredentialsOptions(parser)
24 parser.add_option_group(credopts)
25 parser.add_option_group(options.VersionOptions(parser))
27 opts, args = parser.parse_args()
28 opts.dump_all = True
30 if len(args) != 1:
31 parser.print_usage()
32 sys.exit(1)
34 url = args[0]
36 lp_ctx = sambaopts.get_loadparm()
38 creds = credopts.get_credentials(lp_ctx)
39 sam_ldb = Ldb(url, session_info=system_session(), credentials=creds, lp=lp_ctx)
41 # get the rootDSE
42 res = sam_ldb.search(base="", expression="", scope=SCOPE_BASE, attrs=["configurationNamingContext"])
43 rootDse = res[0]
45 configbase=rootDse["configurationNamingContext"]
47 # enable the feature
48 msg = ldb.Message()
49 msg.dn = ldb.Dn(sam_ldb, "")
50 msg["enableOptionalFeature"] = ldb.MessageElement(
51 "CN=Partitions," + str(configbase) + ":766ddcd8-acd0-445e-f3b9-a7f9b6744f2a",
52 ldb.FLAG_MOD_ADD, "enableOptionalFeature")
53 res = sam_ldb.modify(msg)
55 print "Recycle Bin feature enabled"