mirror of
https://github.com/samba-team/samba.git
synced 2025-08-04 08:22:08 +03:00
s4-net: nicer error message (and no exception)
in net newuser and net setpasswd we shouldn't be throwing python exceptions on normal user errors like unknown user Pair-Programmed-With: Andrew Bartlett <abartlet@samba.org>
This commit is contained in:
@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
import samba.getopt as options
|
import samba.getopt as options
|
||||||
from samba.netcmd import Command, Option
|
from samba.netcmd import Command, Option
|
||||||
|
import sys, ldb
|
||||||
|
|
||||||
from getpass import getpass
|
from getpass import getpass
|
||||||
from samba.auth import system_session
|
from samba.auth import system_session
|
||||||
@ -61,5 +62,10 @@ class cmd_newuser(Command):
|
|||||||
|
|
||||||
samdb = SamDB(url=H, session_info=system_session(), credentials=creds,
|
samdb = SamDB(url=H, session_info=system_session(), credentials=creds,
|
||||||
lp=lp)
|
lp=lp)
|
||||||
|
try:
|
||||||
samdb.newuser(username, unixname, password,
|
samdb.newuser(username, unixname, password,
|
||||||
force_password_change_at_next_login_req=must_change_at_next_login)
|
force_password_change_at_next_login_req=must_change_at_next_login)
|
||||||
|
except ldb.LdbError, (num, msg):
|
||||||
|
print('Failed to create user "%s" : %s' % (username, msg))
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
import samba.getopt as options
|
import samba.getopt as options
|
||||||
from samba.netcmd import Command, CommandError, Option
|
from samba.netcmd import Command, CommandError, Option
|
||||||
|
import sys
|
||||||
from getpass import getpass
|
from getpass import getpass
|
||||||
from samba.auth import system_session
|
from samba.auth import system_session
|
||||||
from samba.samdb import SamDB
|
from samba.samdb import SamDB
|
||||||
@ -68,5 +68,11 @@ class cmd_setpassword(Command):
|
|||||||
samdb = SamDB(url=H, session_info=system_session(),
|
samdb = SamDB(url=H, session_info=system_session(),
|
||||||
credentials=creds, lp=lp)
|
credentials=creds, lp=lp)
|
||||||
|
|
||||||
|
try:
|
||||||
samdb.setpassword(filter, password,
|
samdb.setpassword(filter, password,
|
||||||
force_change_at_next_login=must_change_at_next_login)
|
force_change_at_next_login=must_change_at_next_login,
|
||||||
|
username=username)
|
||||||
|
except:
|
||||||
|
print('Failed to set password for user "%s"' % username)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user