source: branches/samba-3.5.x/source4/setup/setpassword

Last change on this file was 414, checked in by Herwig Bauernfeind, 16 years ago

Samba 3.5.0: Initial import

File size: 2.3 KB
Line 
1#!/usr/bin/python
2#
3# Sets a user password on a Samba4 server
4# Copyright Jelmer Vernooij 2008
5#
6# Based on the original in EJS:
7# Copyright Andrew Tridgell 2005
8#
9# This program is free software; you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation; either version 3 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program. If not, see <http://www.gnu.org/licenses/>.
21#
22
23import sys
24
25# Find right directory when running from source tree
26sys.path.insert(0, "bin/python")
27
28import samba.getopt as options
29import optparse
30
31from getpass import getpass
32from samba.auth import system_session
33from samba.samdb import SamDB
34
35parser = optparse.OptionParser("setpassword [username] [options]")
36sambaopts = options.SambaOptions(parser)
37parser.add_option_group(sambaopts)
38parser.add_option_group(options.VersionOptions(parser))
39credopts = options.CredentialsOptions(parser)
40parser.add_option_group(credopts)
41parser.add_option("-H", help="LDB URL for database or target server", type=str)
42parser.add_option("--filter", help="LDAP Filter to set password on", type=str)
43parser.add_option("--newpassword", help="Set password", type=str)
44parser.add_option("--must-change-at-next-login", help="Force password to be changed on next login", action="store_true")
45
46opts, args = parser.parse_args()
47
48filter = opts.filter
49
50if (len(args) == 0) and (filter is None):
51 print "Either the username or '--filter' must be specified!"
52 parser.print_usage()
53 sys.exit(1)
54
55password = opts.newpassword;
56if password is None:
57 password = getpass("New Password: ")
58
59if filter is None:
60 username = args[0]
61 filter = "(&(objectClass=user)(sAMAccountName=%s))" % (username)
62
63lp = sambaopts.get_loadparm()
64creds = credopts.get_credentials(lp)
65
66if opts.H is not None:
67 url = opts.H
68else:
69 url = lp.get("sam database")
70
71samdb = SamDB(url=url, session_info=system_session(), credentials=creds, lp=lp)
72
73samdb.setpassword(filter, password, force_password_change_at_next_login_req=opts.must_change_at_next_login)
74
Note: See TracBrowser for help on using the repository browser.