📄 newuser
字号:
#!/usr/bin/python## add a new user to a Samba4 server# Copyright Andrew Tridgell 2005# Copyright Jelmer Vernooij 2008# Released under the GNU GPL version 3 or later#import sys# Find right directory when running from source treesys.path.insert(0, "bin/python")import samba.getopt as optionsimport optparseimport pwdfrom getpass import getpassfrom samba.auth import system_sessionfrom samba.samdb import SamDBparser = optparse.OptionParser("newuser [options] <username> [<password>]")sambaopts = options.SambaOptions(parser)parser.add_option_group(sambaopts)parser.add_option_group(options.VersionOptions(parser))credopts = options.CredentialsOptions(parser)parser.add_option_group(credopts)parser.add_option("--quiet", help="Be quiet", action="store_true")parser.add_option("--unixname", help="Unix Username", type=str)opts, args = parser.parse_args()## print a message if quiet is not set#def message(text): if not opts.quiet: print textif len(args) == 0: parser.print_usage() sys.exit(1)username = args[0]if len(args) > 1: password = args[1]else: password = getpass("New Password: ")if opts.unixname is None: opts.unixname = usernamelp = sambaopts.get_loadparm()creds = credopts.get_credentials(lp)samdb = SamDB(url=lp.get("sam database"), session_info=system_session(), credentials=creds, lp=lp)samdb.newuser(username, opts.unixname, password)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -