[SCM] Samba Shared Repository - branch v4-0-test updated - release-4-0-0alpha2-1385-g2e14b4e

Andrew Bartlett abartlet at samba.org
Fri Mar 28 03:53:47 GMT 2008


The branch, v4-0-test has been updated
       via  2e14b4ea64ba7e223f29b5b535b1b1be326f711c (commit)
      from  ac11c018715a2e59af3a716f8fabe8aeb667e660 (commit)

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=v4-0-test


- Log -----------------------------------------------------------------
commit 2e14b4ea64ba7e223f29b5b535b1b1be326f711c
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Fri Mar 28 03:46:23 2008 +1100

    Add tool for enabling accounts

-----------------------------------------------------------------------

Summary of changes:
 source/setup/enableaccount |   74 ++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 74 insertions(+), 0 deletions(-)
 create mode 100644 source/setup/enableaccount


Changeset truncated at 500 lines:

diff --git a/source/setup/enableaccount b/source/setup/enableaccount
new file mode 100644
index 0000000..0c9937f
--- /dev/null
+++ b/source/setup/enableaccount
@@ -0,0 +1,74 @@
+#!/usr/bin/python
+#
+#	add a new user to a Samba4 server
+#	Copyright Andrew Tridgell 2005
+#	Copyright Jelmer Vernooij 2008
+#	Released under the GNU GPL v2 or later
+#
+
+import samba.getopt as options
+import optparse
+import pwd
+import sys
+import ldb
+
+from auth import system_session
+from samba.samdb import SamDB
+
+parser = optparse.OptionParser("setpassword [username] [options]")
+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("-H", help="LDB URL for database or target server", type=str)
+parser.add_option("--base", help="Base DN to search for user under", type=str)
+
+opts, args = parser.parse_args()
+
+#
+#  print a message if quiet is not set
+#
+def message(text):
+	if not opts.quiet:
+		print text
+
+if len(args) == 0:
+	parser.print_usage()
+	sys.exit(1)
+
+username = args[0]
+
+if username is None:
+	print "username must be specified"
+
+creds = credopts.get_credentials()
+
+lp = sambaopts.get_loadparm()
+if opts.H is not None:
+	url = opts.H
+else:
+	url = lp.get("sam database")
+
+samdb = SamDB(url=url, session_info=system_session(), 
+              credentials=creds, lp=lp)
+
+domain_dn = opts.base
+if opts.base is None:
+	res = samdb.search("", scope=ldb.SCOPE_BASE, 
+			  expression="(defaultNamingContext=*)", 
+			  attrs=["defaultNamingContext"])
+	assert(len(res) == 1 and res[0]["defaultNamingContext"] is not None)
+	domain_dn = res[0]["defaultNamingContext"][0]
+else:
+	domain_dn = opts.base
+
+filter = "(&(objectClass=user)(samAccountName=%s))" % username
+
+res = samdb.search(domain_dn, scope=ldb.SCOPE_SUBTREE, 
+		  expression=filter,
+		  attrs=[])
+assert(len(res) == 1)
+user_dn = res[0].dn
+
+samdb.enable_account(user_dn)


-- 
Samba Shared Repository


More information about the samba-cvs mailing list