Trouble Using RPC for Share Management
Ricardo Jorge
ricardo.swat.samba at gmail.com
Sun Nov 21 07:44:11 MST 2010
Hello.
I'm having some trouble using the RPC functions. Basically, they don't work.
I can list shares without a problem but I can't Add or Delete them.
I keep get RuntimeError: (1, 'WERR_BADFUNC') when adding or deleting (have
not got to setting info). I'm using some Microsoft documentation on MSDN for
reference on parameters (
http://msdn.microsoft.com/en-us/library/bb525393%28v=VS.85%29.aspx)
I ran Samba4 with debug level 3:
This message shows up so apparently everything is being loaded ok:
> (...)
> DCERPC endpoint server 'srvsvc' registered
> (...)
This happens when I try to add or delete a share:
> (...)
> Terminating connection - 'NT_STATUS_CONNECTION_DISCONNECTED'
> single_terminate: reason[NT_STATUS_CONNECTION_DISCONNECTED]
> Got NTLMSSP neg_flags=0x60088205
> Got user=[administrator] domain=[] workstation=[] len1=24 len2=24
> auth_check_password_send: Checking password for unmapped user
[]\[administrator]@[]
> auth_check_password_send: mapped user is: [SAMDOM]\[administrator]@[]
> NTLMSSP Sign/Seal - Initialising with flags:
> Got NTLMSSP neg_flags=0x60088205
> Terminating connection - 'NT_STATUS_CONNECTION_DISCONNECTED'
> single_terminate: reason[NT_STATUS_CONNECTION_DISCONNECTED]
(...)
Here is the source code I'm using to test the functions. I've tried to do
this a number if ways but I always get the RuntimeError above.
- Specify 'localhost' or the IP Adress instead of None in the NetShare*
functions
- Different levels in addShare
- Lots of other stuff :P
#!/usr/bin/env python
from samba.dcerpc import srvsvc
from samba import credentials
##
##
##
def listShares(conn):
ctr = srvsvc.NetShareInfoCtr()
shares = conn.NetShareEnumAll(None, ctr, 0, None)
print "Initial Share List"
print "There are " + str(shares[0].ctr.count) + " shares\n"
for i in range(0, shares[0].ctr.count):
share_info = conn.NetShareGetInfo(None, shares[0].ctr.array[i].name,
2)
print share_info.name + "\t" + share_info.path + "\t " +
share_info.comment
print "\n\n=====================================\n\n"
##
## Add Share
## http://msdn.microsoft.com/en-us/library/bb525384%28v=VS.85%29.aspx
##
def addShare(conn, shareName):
shareinfo = srvsvc.NetShareInfo2()
shareinfo.name = shareName
conn.NetShareAdd(None, 2, shareinfo, None)
##
## Delete Share
## http://msdn.microsoft.com/en-us/library/bb525386%28v=VS.85%29.aspx
##
def deleteShare(conn, shareName):
conn.NetShareDel(None, shareName, 0)
##
## Credentials
##
creds = credentials.Credentials()
creds.set_username("administrator")
creds.set_password("mypassword")
creds.set_workstation("")
# I get segmentation fault if I remove this. A post for later.
creds.set_domain("")
##
## Connect
##
conn = srvsvc.srvsvc('ncalrpc:', credentials=creds)
##
## Initial List Shares
##
listShares(conn)
##
## Add Share
##
addShare(conn, "Testing12")
addShare(conn, "Test1234")
##
## Delete Share
##
deleteShare(conn, "Testing12")
##
## Final List Shares
##
listShares(conn)
Thank you for any help.
Best Regards,
Ricardo
More information about the samba-technical
mailing list