r26621: vampire: Add simple Python-based vampire script
[Samba/gebeck_regimport.git] / source4 / setup / vampire.py
blob392cd2d4fb22a17b11287431b394134a99ba6d75
1 #!/usr/bin/python
3 # Unix SMB/CIFS implementation.
4 # Vampire a remote domain
5 # Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 from net import libnet
22 import optparse
23 import samba.getopt as options
24 import param
25 from auth import system_session
26 import sys
28 parser = optparse.OptionParser("vampire [options] <domain>")
29 parser.add_option_group(options.SambaOptions(parser))
30 parser.add_option_group(options.VersionOptions(parser))
31 credopts = options.CredentialsOptions(parser)
32 parser.add_option_group(credopts)
34 opts, args = parser.parse_args()
36 if len(args) < 1:
37 parser.print_usage()
38 sys.exit(1)
40 def vampire(domain, session_info, credentials, lp):
41 ctx = libnet(lp_ctx=lp)
42 ctx.cred = credentials
43 machine_creds = Credentials();
44 machine_creds.set_domain(domain);
45 if not machine_creds.set_machine_account():
46 raise Exception("Failed to access domain join information!")
47 ctx.samsync_ldb(vampire_ctx, machine_creds=machine_creds,
48 session_info=session_info)
50 lp = param.LoadParm()
51 if opts.configfile:
52 lp.load(opts.configfile)
53 vampire(args[0], session_info=system_session(),
54 credentials=credopts.get_credentials(), lp=lp)