[Samba] python: listing samba shares
Igor Katson
descentspb at gmail.com
Sun Aug 16 13:16:42 MDT 2009
When just launching your code (with provided credentials), I have a
segfault. With the credentials code snippet removed, everything works
fine, and I can see the shares listing! But when changing "localhost" to
another ip address (a windows machine), it fails:
descent at descent:/usr/local/samba/lib/python2.6/site-packages$ smbclient
-N -L 192.168.37.37
Domain=[SARDINKA] OS=[Windows 5.1] Server=[Windows 2000 LAN Manager]
Sharename Type Comment
--------- ---- -------
IPC$ IPC Remote IPC
ExampleShare Disk
Domain=[test] OS=[Windows 5.1] Server=[Windows 2000 LAN Manager]
Server Comment
--------- -------
Workgroup Master
--------- -------
descent at descent:/usr/local/samba/lib/python2.6/site-packages$ python
/tmp/shares2.py
boooooo
(-1073741811, 'Unexpected information received')
Ricardo Jorge wrote:
> Hi,
>
> There was a line missing from source4/librpc/config.mk and it wasn't
> building the Python module.
>
> Here is a patch if you can apply it:
>
>
>
> ==================
> After recompiling I could get the share names listed using this Python
> code. Replace the credentials where necessary and server address.
>
> #!/usr/bin/env python
>
> import sys
>
> sys.path.append('/usr/local/samba/lib/python2.6/site-packages')
> sys.path.append('/usr/local/samba/lib/python2.6/site-packages/samba')
> sys.path.append('/usr/local/samba/lib/python2.6/site-packages/samba/dcerpc')
>
> from samba.dcerpc import samr, security, srvsvc
> from samba import credentials
>
> creds = credentials.Credentials()
> creds.set_username("Administrator")
> creds.set_password("x")
>
> # you must leave this line or it will cause a segmentation fault
> creds.set_workstation("")
>
> try:
> conn = srvsvc.srvsvc('ncacn_np:localhost', credentials=creds)
> except Exception, msg:
> print 'boooooo'
> print str(msg)
> else:
> ctr = srvsvc.NetShareInfoCtr()
> shares = conn.NetShareEnumAll(u'localhost', ctr, 0, 0)
>
> print "\n\n============"
> print "There are " + str(shares[0].ctr.count) + " shares"
> print "============\n"
>
> for i in range(0, shares[0].ctr.count):
> print str(i) + ": " + shares[0].ctr.array[i].name
>
> print "\n\n"
>
> I don't know how it will work for you because of your server
> configuration. My Samba4 server is just for coding so it's pretty much
> all default and local.
>
>
>
>
> On Sun, Aug 16, 2009 at 5:08 PM, Ricardo Jorge<rvelhote at gmail.com> wrote:
>
>> Hi,
>>
>> I was investigating this and I believe there is actually a way with
>> Python but the problem is that the Python module with the binding is
>> not being compiled (sorry but I have no idea why).
>>
>> There should be a module called samba.dcerpc.srvsvc.
>>
>> If you look at librpc/gen_ndr/py_srvsvc.c you will find
>> NetShareEnumAll which binds to the same function that's called when -L
>> is used in smbclient.
>>
>> Maybe it's something with the make file?
>>
>>
>>
>> On Sun, Aug 16, 2009 at 4:36 PM, Igor Katson<descentspb at gmail.com> wrote:
>>
>>> Helmut Hullen wrote:
>>>
>>>> Hallo, Igor,
>>>>
>>>> Du meintest am 16.08.09:
>>>>
>>>>
>>>>
>>>>> Is it possible to list samba shares and their contents of a
>>>>> particular host? --
>>>>>
>>>>>
>>>> Shell:
>>>>
>>>> smbclient -N -L $particular_host
>>>>
>>>> shows first all shares of that particular host and then some other stuff.
>>>> Perhaps you filter some output depending on the key word "Disk" (or
>>>> "Printer").
>>>>
>>>> Contents: "that depends".
>>>> You must have some rights.
>>>>
>>>> Viele Gruesse!
>>>> Helmut
>>>>
>>>>
>>> Thanks.
>>> Yes, I know of that shell command, but I would like to do that directly from
>>> python for more flexibility, control and convenience.
>>> --
>>> To unsubscribe from this list go to the following URL and read the
>>> instructions: https://lists.samba.org/mailman/options/samba
>>>
>>>
More information about the samba
mailing list