summaryrefslogtreecommitdiff
path: root/python/samba/samdb.py
AgeCommit message (Collapse)AuthorFilesLines
2019-07-04samba-tool: implement contact management commandsBjörn Baumbach1-0/+108
Usage: samba-tool contact <subcommand> Contact management. Available subcommands: create - Create a new contact. delete - Delete a contact. edit - Modify a contact. list - List all contacts. move - Move a contact object to an organizational unit or container. show - Display a contact. Signed-off-by: Björn Baumbach <bb@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2019-04-02Spelling fix s/informations/information/Mathieu Parent1-2/+2
Signed-off-by: Mathieu Parent <math.parent@gmail.com> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Martin Schwenke <martin@meltin.net>
2018-12-10python/samba: PY3 fix failing py3 samba.tests.group_audit testNoel Power1-3/+3
Fix bytes being compared against ldb.bytes Signed-off-by: Noel Power <noel.power@suse.com> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2018-12-10python/samba: PY3 don't call str for bytes (or str)Noel Power1-4/+9
Note: Fix needed also for gpo.apply minPwdAge, maxPwdAge, minPwdLength & set_pwdProperties all have a line like value = str(value).encode('utf8') this is a generic type statement I guess to convert int, float etc to utf8 encoded bytes representing the string value for those. This worked fine in PY2 but in py3 some routine already are passing bytes into these methods, in these cases e.g. b'200' will get converted to "b'200'", this change only performs the conversion above for non bytes (or str) types by replacing the above with if not isinstance(value, binary_type): value = str(value).encode('utf8') Signed-off-by: Noel Power <noel.power@suse.com> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2018-10-29python: do not use "is" for string equalityDouglas Bagnall1-2/+2
This is not always going to work, and is not guaranteed to be consistent even between minor versions. Here is a simple counterexample: >>> a = 'hello' >>> a is 'hello' True >>> a is 'hello'.lower() False >>> a == a.lower() True Possibly it always works for the empty string, but we cannot rely on that. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andreas Schneider <asn@samba.org> Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org> Autobuild-Date(master): Mon Oct 29 23:13:36 CET 2018 on sn-devel-144
2018-10-29python/samdb: properly use property()Douglas Bagnall1-2/+2
Python's property() function works like this: property([getter[, setter[, delete[, doc]]]]) but we have been forgetting the delete function, or rather setting it to be a string. A string is not callable and is unlikely to succeed at deleting the property. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andreas Schneider <asn@samba.org>
2018-09-03python/samba/netcmd: changes for samab.tests.samba_tool.computerNoel Power1-1/+1
Signed-off-by: Noel Power <noel.power@suse.com> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2018-09-03python/samba: port changes to allow samba.tests.dsdb_lock to work with PY3/PY2Noel Power1-2/+2
Signed-off-by: Noel Power <noel.power@suse.com> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2018-08-24PEP8: better formatting of (CONST1|CONST2)Douglas Bagnall1-1/+2
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2018-08-24PEP8: fix E713: test for membership should be 'not in'Joe Guo1-4/+4
Signed-off-by: Joe Guo <joeg@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
2018-08-24PEP8: fix E303: too many blank lines (2)Joe Guo1-4/+0
Signed-off-by: Joe Guo <joeg@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
2018-08-24PEP8: fix E302: expected 2 blank lines, found 1Joe Guo1-0/+1
Signed-off-by: Joe Guo <joeg@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
2018-08-24PEP8: fix E227: missing whitespace around bitwise or shift operatorJoe Guo1-1/+1
Signed-off-by: Joe Guo <joeg@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
2018-08-24PEP8: fix E225: missing whitespace around operatorJoe Guo1-1/+1
Signed-off-by: Joe Guo <joeg@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
2018-08-24PEP8: fix E203: whitespace before ':'Joe Guo1-1/+1
Signed-off-by: Joe Guo <joeg@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
2018-08-24PEP8: fix E128: continuation line under-indented for visual indentJoe Guo1-33/+37
Signed-off-by: Joe Guo <joeg@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
2018-08-24PEP8: fix E127: continuation line over-indented for visual indentJoe Guo1-9/+9
Signed-off-by: Joe Guo <joeg@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
2018-08-24PEP8: fix E121: continuation line under-indented for hanging indentJoe Guo1-1/+1
Signed-off-by: Joe Guo <joeg@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
2018-07-13samdb: use int for get and set methods instead of digit strJoe Guo1-4/+8
This will make the API work in a nature way. Also, because of a defect in ldb API, code like `res[0]["maxPwdAge"][0]` will return bytes even in Python3, which will cause trouble. By casting the value to int, we avoid the str/bytes issue. Signed-off-by: Joe Guo <joeg@catalyst.net.nz> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2018-05-29python/samba/netcmd/schema.py: samdb schema update nowWilliam Brown1-0/+9
When we change schema values, we should trigger a schema update to refresh the changes applied. This is called after a change is made. A helper to samdb is added so that it's easier for other locations to call additionally. Signed-off-by: William Brown <william@blackhats.net.au> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Garming Sam <garming@catalyst.net.nz> Autobuild-User(master): Andrew Bartlett <abartlet@samba.org> Autobuild-Date(master): Tue May 29 08:30:52 CEST 2018 on sn-devel-144
2018-05-29python/samba/netcmd/schema.py: add schema query and management.William Brown1-0/+4
Schema management in active directory is complex and dangerous. Having a tool that safely wraps administrative tasks as well as allowing query of the schema will make this complex topic more accessible to administrators. Signed-off-by: William Brown <william@blackhats.net.au> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Garming Sam <garming@catalyst.net.nz>
2018-05-17python/samba: Fix incorrect encode of passwordNoel Power1-1/+5
In python2 you can encode a 'str' type which doesn't really make sense since it is already bytes (as such). In python3 this isn't possible you can't encode bytes or decode strings. Also because you can call encode on 'str' in python2 it tries to to what you wanted and it implicity calls decode('ascii') before performing the encode. This is why we get mention of ascii codec in the error. This patch should future proof for python3 also. Bug: https://bugzilla.samba.org/show_bug.cgi?id=13435 Signed-off-by: Noel Power <noel.power@suse.com> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2018-05-03samdb: fix wrong computer container dn for newcomputerJoe Guo1-1/+1
CN=Users --> CN=Computers Signed-off-by: Joe Guo <joeg@catalyst.net.nz> Reviewed-by: Alexander Bokovoy <ab@samba.org> Reviewed-by: Rowland Penny <rpenny@samba.org>
2018-04-06samba-tool: improve computer management commandsJoe Guo1-3/+11
This pathch is based on Björn Baumbach's work: 1. Add `--ip-address` option for create subcommand, to allow user set DNS A or AAAA records while creating the computer. 2. Delete above DNS records while deleting the computer. 3. Add `--service-principal-name` option for create command, to allow user set `servicePrincipalName` while creating the computer. 4. Tests. Signed-off-by: Joe Guo <joeg@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
2018-04-06samba-tool: implement computer management commandsBjörn Baumbach1-0/+52
Usage: samba-tool computer <subcommand> Computer management. Available subcommands: create - Create a new computer. delete - Delete a computer. list - List all computers. move - Move a computer to an organizational unit/container. show - Display a computer AD object Signed-off-by: Björn Baumbach <bb@sernet.de> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
2018-04-06provision: allow provisioning of a different database backendGary Lockyer1-0/+3
This sets the backendStore field in @PARTITION, depending on which argument you set in the provision. Signed-off-by: Gary Lockyer <gary@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2018-03-19samba-tool: allow sid strings for 'group {add,remove}members'Stefan Metzmacher1-4/+20
This makes it possible to add foreign SIDS as group members. BUG: https://bugzilla.samba.org/show_bug.cgi?id=13300 Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
2018-02-15python: Port samdb module to Python 3 compatible formLumir Balhar1-6/+7
Signed-off-by: Lumir Balhar <lbalhar@redhat.com> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2018-02-15python: Convert base64 encoded password to utf-8Andreas Schneider1-1/+1
Pair-Programmed-With: Alexander Bokovoy <ab@samba.org> Signed-off-by: Andreas Schneider <asn@samba.org> Signed-off-by: Alexander Bokovoy <ab@samba.org> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2018-02-09python samdb.newuser(): use user DN not samaccountname to set passwordDouglas Bagnall1-1/+3
This is noticably faster in cases (e.g. tests) where the same user is added and deleted many times. The rreason is samaccountname is retained for deleted objects, so the search finds multiple objects that need to be filtered out internally. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2018-02-08python/samdb: Improve function comment on normalize_dn_in_domain()Andrew Bartlett1-2/+5
Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
2018-02-08python/samdb: Allow samdb.normalize_dn_in_domain() to take an ldb.Dn()Andrew Bartlett1-0/+4
Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
2018-02-08python/samdb: add method normalize_dn_in_domain(): get full dn of an relative dnBjörn Baumbach1-0/+11
Signed-off-by: Björn Baumbach <bb@sernet.de> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
2018-02-07python SamDB: init default flags to FLG_DONT_CREATE_DBGary Lockyer1-1/+2
The current defaults for SamDB are to create the database file if it does not exist. Most of the uses of SamDB assume the database already exists, and so auto-creation is not the desired behaviour. TDB will overwrite an existing non TDB file with a newly created TDB file. This becomes an issue when using alternate database file formats i.e. lmdb. Signed-off-by: Gary Lockyer <gary@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2017-11-20gpo: Initial commit for GPO workLuke Morrison1-0/+18
Enclosed is my Summer of Code 2013 patch to have vital password GPO always applied to the Samba4 Domain Controller using a GPO update service. To try it out "make -j" your samba with the patch, apply a security password GPO and see the difference in ~20 seconds. It also takes GPO hierarchy into account. Split from "Initial commit for GPO work done by Luke Morrison" by David Mulder Signed-off-by: Garming Sam <garming@catalyst.net.nz> Signed-off-by: Luke Morrison <luke@hubtrek.com> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2017-06-10dns_server: clobber MNAME in the SOAAndrew Bartlett1-1/+1
Otherwise, we always report the first server we created/provisioned the AD domain on which does not match AD behaviour. AD is multi-master so all RW servers are a master. Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Garming Sam <garming@catalyst.net.nz>
2017-06-10pydsdb_dns: Allow the partition DN to be specified into py_dsdb_dns_lookupAndrew Bartlett1-2/+6
This allows lookups to be confined to one partition, which in turn avoids issues when running this against MS Windows, which does not match Samba behaviour for dns_common_zones() Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Garming Sam <garming@catalyst.net.nz>
2017-06-09samba-tool: You cannot add members to a group if the member exists as a ↵Rowland Penny1-3/+6
sAMAccountName and a CN. Signed-off-by: Rowland Penny <rpenny@samba.org> Reviewed-by: Alexander Bokovoy <ab@samba.org> Autobuild-User(master): Alexander Bokovoy <ab@samba.org> Autobuild-Date(master): Fri Jun 9 23:24:47 CEST 2017 on sn-devel-144
2017-02-21python/samba: use an explicit .encode('utf-8') where we expect utf8 passwordsStefan Metzmacher1-1/+1
BUG: https://bugzilla.samba.org/show_bug.cgi?id=12262 Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
2016-11-04dsdb: Add python hooks to allocate a RID set and allocate a RID poolAndrew Bartlett1-0/+8
This will help us to correct errors during dbcheck Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Garming Sam <garming@catalyst.net.nz> BUG: https://bugzilla.samba.org/show_bug.cgi?id=9954
2016-09-01python: Add binding for dsdb_garbage_collect_tombstones()Andrew Bartlett1-0/+14
Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Garming Sam <garming@catalyst.net.nz>
2016-06-30samdb.py: add smartcard_required option to newuser()Stefan Metzmacher1-1/+7
BUG: https://bugzilla.samba.org/show_bug.cgi?id=11441 Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2016-03-07Remove posixAccount from samdb.pyRowland Penny1-1/+0
Signed-off-by: Rowland Penny rpenny@samba.org Reviewed-by: Andrew Bartlett <abartlet@samba.org> Autobuild-User(master): Garming Sam <garming@samba.org> Autobuild-Date(master): Mon Mar 7 08:13:42 CET 2016 on sn-devel-144
2015-10-26pydns: Add replace_by_dn()Andrew Bartlett1-1/+12
This allows us to find a DNS record by searching LDB and unpacking the dnsRecord but replace the record using the common code that will create a tombstone Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Garming Sam <garming@catalyst.net.nz>
2015-10-26dns_server: Add python method to extract a DNS entry from a ldb.MessageElementAndrew Bartlett1-0/+4
Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Garming Sam <garming@catalyst.net.nz>
2015-10-26dns_server: Add a python module directly accessing DNS records in sam.ldbAndrew Bartlett1-1/+9
Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Garming Sam <garming@catalyst.net.nz>
2015-08-24ldb: create a cache of known wellknown objects instead of continously ↵Matthieu Patou1-1/+14
searching in the db Profiling on dbcheck have shown that we spend 10% of the time looking for wellknown objects. BUG: https://bugzilla.samba.org/show_bug.cgi?id=10973 Change-Id: I13ed58e8062d1b7b6179d17b0e7e56f943572c6c Signed-off-by: Matthieu Patou <mat@matws.net> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
2015-06-16Group creation: Add msSFU30Name only when --nis-domain was givenMarc Muehlfeld1-2/+1
This fixes a bug, that all new created groups automatically get an msSFU30Name attribute added. This should only be the case, when we also have a nis-domain (samba-tool --nis-domain=...). Bugreport: https://bugzilla.samba.org/show_bug.cgi?id=11315 Signed-off-by: Marc Muehlfeld <mmuehlfeld@samba.org> Reviewed-by: Christian Ambach <ambi@samba.org> Autobuild-User(master): Christian Ambach <ambi@samba.org> Autobuild-Date(master): Tue Jun 16 11:58:02 CEST 2015 on sn-devel-104
2015-02-03samba-tool: Create NIS enabled users and unixHomeDirectory attributeMarc Muehlfeld1-2/+16
Allow to create NIS enabled user accounts via 'samba-tool user add'. To create NIS enabled accounts, the parameters --uid-number=, --login-shell=, --unix-home=, --gid-number= are mandatory. Because we didn't had a parameter to set unixHomeDirectory yet, this patch also adds this feature. 'unixUserPassword: ABCD!efgh12345$67890' is added by default, when you enable NIS on an account in ADUC. The same we do in samba-tool. See: https://bugzilla.samba.org/show_bug.cgi?id=10909 Signed-off-by: Marc Muehlfeld <mmuehlfeld@samba.org> Reviewed-By: Jelmer Vernooij <jelmer@samba.org> Autobuild-User(master): Marc Muehlfeld <mmuehlfeld@samba.org> Autobuild-Date(master): Tue Feb 3 17:18:32 CET 2015 on sn-devel-104
2014-10-23samba-tool group add: Add option --nis-domain and --gidMarc Muehlfeld1-1/+12
This allows creating RFC2307 enabled groups via samba-tool Signed-off-by: Marc Muehlfeld <mmuehlfeld@samba.org> Reviewed-by: Michael Adam <obnox@samba.org> Autobuild-User(master): Michael Adam <obnox@samba.org> Autobuild-Date(master): Thu Oct 23 18:19:35 CEST 2014 on sn-devel-104