3 # common functions for samba-tool python commands
5 # Copyright Andrew Tridgell 2010
6 # Copyright Giampaolo Lauria 2011 <lauria2@yahoo.com>
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
23 from samba
.dcerpc
import nbt
24 from samba
.net
import Net
27 def _get_user_realm_domain(user
):
28 """ get the realm or the domain and the base user
37 m
= re
.match(r
"(\w+)\\(\w+$)", user
)
41 return (baseuser
.lower(), domain
.upper(), realm
)
42 m
= re
.match(r
"(\w+)@(\w+)", user
)
46 return (baseuser
.lower(), domain
, realm
.upper())
49 def netcmd_dnsname(lp
):
50 '''return the full DNS name of our own host. Used as a default
51 for hostname when running status queries'''
52 return lp
.get('netbios name').lower() + "." + lp
.get('realm').lower()
55 def netcmd_finddc(lp
, creds
):
56 '''return domain-name of a writable/ldap-capable DC for the domain.'''
57 net
= Net(creds
=creds
, lp
=lp
)
58 realm
= lp
.get('realm')
59 cldap_ret
= net
.finddc(realm
,
60 nbt
.NBT_SERVER_LDAP | nbt
.NBT_SERVER_DS | nbt
.NBT_SERVER_WRITABLE
)
61 return cldap_ret
.pdc_dns_name