[Samba] Looking for Python docs/examples to modify DNS via keytab

David Mulder dmulder at samba.org
Sat Jun 29 08:11:55 UTC 2024


On 6/28/24 10:07 PM, christian baltini via samba wrote:
> Hello all,
>
> I am looking to rewrite the shell script here (https://wiki.samba.org/index.php/Configure_DHCP_to_update_DNS_records) in Python.
>
> Is anyone aware of any resources (docs, existing code, etc.) that may be useful in doing so?  I’m not finding any introductory docs or simple code examples that show things like instantiating a DNS server connection with a keytab.
It's a bit awkward, but you can import and call the samba-tool commands 
directly within Python (samba-tool of course is written in Python). See 
an example of this hack here:
https://github.com/yast/yast2-dns-manager/blob/master/src/modules/SambaToolDnsAPI.py 


This example uses username/password for auth, but the CredentialsOptions 
parser can be instructed to use the keytab, IIUC: 
https://gitlab.com/samba-team/samba/-/blob/master/python/samba/getopt.py?ref_type=heads#L384 


If you don't like this hacky approach, you could re-implement something 
using the same calls made by samba-tool: 
https://gitlab.com/samba-team/samba/-/blob/master/python/samba/netcmd/dns.py?ref_type=heads

This is probably a more appropriate approach, but a bit more work.

-- 
David Mulder
Labs Software Engineer, Samba
SUSE
1221 S Valley Grove Way, Suite 500
Pleasant Grove, UT 84062
(P)+1 385.208.2989
dmulder at suse.com
http://www.suse.com




More information about the samba mailing list