Error in Samba Python Bindings - NetShareAdd and NetShareSetInfo

Dhananjay Sathe dhananjaysathe at gmail.com
Fri Aug 12 05:37:04 MDT 2011


Hello all,

One of the major bugs plaguing my project has been the random error in the
python samba bindings where in the basic NetShareSetInfo and NetShareAdd
that returns RuntimeError: (1, 'WERR_BADFUNC') on attempt to add/modify  a
share.

I had initially written about this error in a mail dated 31 May 2011, and
have informed Jelmer, Kai and Andreas about the same .
A few days ago , my mentor , jelmer has asked  me to create a trivial sript
to help reproduce this error and post it to this list , hence helping
identify the issues and help resolve it

Here this script tries to add a share object to the rpc server using the
method via the srvsvc pipe object.
The same error is thrown up on attempt to modify or delete the share object.

The script needs youy to enter your creds in the top section for it to work.

Here is the script : (I have also attached a rw text .py file )


########### test script ######################
 # PLEASE DEFINE THE BELOW PARAMETERS FIRST
username = "" #required
password = "" #required
server_address = "" #required

transport_type = 0 # you could try 0,1,2

#import sys
#sys.path.append('/usr/local/samba/lib/python2.7/site-packages/')
# uncomment / modify as required depending on how samba has been installe
don your system

from samba import credentials
from samba.dcerpc import (
    srvsvc,
    security,
    )
# check if required params are set
if username is "" or password is "" or server_address is "":
    print "PLEASE first set the parameters at the top of this script"
    exit()

# first i set up the credentials
creds = credentials.Credentials()

creds.set_domain('')
creds.set_workstation('')
creds.set_username(username)
creds.set_password(password)

server_unc = ''.join(['\\',server_address])

# selecting binding type
binding=['ncacn_np:%s', 'ncacn_ip_tcp:%s', 'ncalrpc:%s'][transport_type]

pipe = srvsvc.srvsvc(binding % server_address,credentials=creds)

# Now i define a trivial share object of share type 502

share = srvsvc.NetShareInfo502()

share.name = unicode('test')
share.comment = unicode('test share')
share.type = 0 # setting it up as a disktree for the purpose of this test ,
no special flags
share.current_users = 0x00000000
share.max_users= 0xFFFFFFFF
share.password = unicode('')
share.path = unicode('C:\\usr\\local') # some random path
share.permissions = 0 # reserved , has to defined to 0 as in MS-Srvs
share.sd_buf =  security.sec_desc_buf()

# Now i define parm error as given in srvs
parm_error = 0x00000000

# This is where i attempt to add the shgare to the server and the part that
is failing
# parm_error should be 0x00000000 to indicate success
# currently it returns RuntimeError: (1, 'WERR_BADFUNC')

parm_error = pipe.NetShareAdd(server_unc, 502, share,parm_error)

############## end of test script ###############

Hope this this helps resolve the error.
Thanks For your support and time.

Cheers !!!


Dhananjay Deepak Sathe | +919764871950
dhananjaysathe at gmail.com,dhananjaysathe at acm.org,f2009260 at bits-goa.ac.in,<f2009260 at bits-goa.ac.in>
Blog : http://dsathe.blogspot.com
3rd Year Undergraduate,
BE(Hons) Electronics and Instrumentation,
BITS Pilani Goa Campus.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: testscript.py
Type: text/x-python
Size: 1825 bytes
Desc: not available
URL: <http://lists.samba.org/pipermail/samba-technical/attachments/20110812/b3468628/attachment.py>


More information about the samba-technical mailing list