[Samba] python module

David Bear dwbear75 at gmail.com
Fri Apr 7 23:14:53 UTC 2023


Thanks Rowland. I really appreciate your rapid responses and many years of
work helping the python community.
To answer your question, I could wrap samba tool -- but I thought it would
be easier -- and more pythonic to keep the code pure python.

As for what chatgpt knows... for the curious I'll paste the relevant
responses below. Chat did suggest making calls to the samba-tool. I thought
things would go faster for the script if it didn't have to spawn a new
shell to execute samba-tool in.
---- now, on the chat answers..----

There are several Python libraries for interacting with Samba and Active
Directory, and the best library to use depends on your specific use case
and requirements. Here are some popular options:

   1.

   samba-python: This is the official Python bindings for Samba, which
   allows you to use Samba's internal libraries and functions from Python.
   This library is low-level and may require more expertise in Samba to use
   effectively.
   2.

   python-samba: This is a higher-level Python module that provides an
   object-oriented interface to Samba's internal libraries. It includes
   modules for interacting with Active Directory, LDAP, SMB, and more.
   3.

   pysmb: This is a Python module for interacting with SMB/CIFS file
   servers, including Samba servers. It provides a simple API for reading and
   writing files, browsing directories, and executing commands on a remote
   server.
   4.

   smbprotocol: This is another Python module for working with SMB/CIFS
   file servers, including Samba servers. It provides a lower-level API for
   sending and receiving SMB messages and packets.

==== NOTE the distinction between samba-python and python-samba =====
==== Here is the paragraph that caught my attention ===

If you are looking for a high-level, object-oriented interface to Samba and
> Active Directory, python-samba is probably the best choice. It provides a
> comprehensive set of classes and methods for interacting with Active
> Directory, including creating, modifying, and deleting user accounts,
> groups, and more. If you only need to interact with SMB/CIFS file shares,
> pysmb or smbprotocol may be more appropriate.


>  Note that python-samba and samba-python require the Samba libraries to be
> installed on your system, while pysmb and smbprotocol do not.


======

Note that Debian does have a python3-samba package

ii  python3-samba                                 2:4.13.13+dfsg-1~deb11u5

and I can import that into python

But it does not have the samba.netcmd.user.create name ...



On Fri, Apr 7, 2023 at 12:51 PM Rowland Penny via samba <
samba at lists.samba.org> wrote:

>
>
> On 07/04/2023 20:20, David Bear via samba wrote:
> > I am looking for the python-samba module. I would like to
> > add/disable/modify AD accounts using python running on a linux machine.
> > ChatGPT suggested the python-samba module.  Sample code as follows:
> >
> > from samba.credentials import Credentials
> > from samba.netcmd.user import create as create_user
> > from samba.netcmd.user import setpassword as set_user_password
> >
> > ...
> > I am running Debuan bullseye and I can import the samba module. But there
> > is no samba.netcmd.user name available. So chatgpt suggested I need a
> newer
> > version of python-samba.
> >
> > I attempted to pip install it -- and it is not available on pypi.
> >
> > After googling for about 15 minutes I gave up trying to find the
> > python-samba module and thought I would ask -- is this something I need
> to
> > get from git ?
> >
>
> As far as I am aware, there isn't one. There is however, a samba C
> module that python can use and the samba in 'samba.netcmd.user' is a
> directory.
>
> A long time ago, I had the same problem and couldn't understand why you
> would name a C module 'samba'.
>
> Can I ask why you are trying to use Python to do something that sounds
> like something that samba-tool can already do ?
>
> For most of this you could just write a wrapper around samba-tool, or
> use LAM or something similar.
>
>  From my understanding, ChatGPT can only work with what is out there on
> the internet and most of what is out there about Samba is full of errors
> and omissions.
>
> Rowland
>
> --
> To unsubscribe from this list go to the following URL and read the
> instructions:  https://lists.samba.org/mailman/options/samba
>


-- 
David Bear
mobile: (602) 903-6476


More information about the samba mailing list