I am currently having a problem accessing Windows print shares (at work, so I don’t reall have access to their settings) in Ubuntu, so I eventually got down to poking around the source of Gnome’s ‘system-config-printer‘ which is written in Python, and uses the Python smbc bindings for Samba.
I have basically managed to get down my problem to this piece of code, which comes from /usr/share/system-config-printer/pysmb.py, and which I run in the python command line shell:
import smbc, os
def do_auth (svr, shr, wg, un, pw):
return ("myworkdomain.com", "MYWORKUSERNAME", "MYWORKPASSWORD")
ctx = smbc.Context (debug=10, auth_fn=do_auth)
f = ctx.open ("smb://%s/%s" % ("printserver.myworkdomain.com", "PRINTSHARENAME"), os.O_RDWR, 0777)
The first (sort of) a problem is that upon the execution of the ctx = smbc.Context... line, Python always complains:
params.c:OpenConfFile() - Unable to open configuration file "/home/MYUSERNAME/.smb/smb.conf":
No such file or directory
… but maybe that is not really a problem? (maybe smbc is supposed to recreate this file anew?).
The big problem is, of course, that I cannot connect to the share: after executing the f = ctx.open... line, there is a big dump of Samba communication, Windows server seems to be talking etc – and the connection effort finishes with failure:
SPNEGO login failed: Logon failure
cli_init_creds: user domain myworkdomain.com
session setup ok
map_errno_from_nt_status: 32 bit codes: code=c0000022
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
smbc.PermissionError: (13, 'Permission denied')
Basically, I know too little about Samba to be able to read the rest of the error log, but I find the line:
cli_init_creds: user domain myworkdomain.com
… very suspicious – it looks as if the ‘user‘ there is an empty string – even though I’d expect it to be ‘MYWORKUSERNAME‘, as specified by the ‘do_auth‘ function above!!
Note that this failure is somewhat similar to the NT_STATUS_LOGON_FAILURE that I used to get with the cmdline smbclient (see Obtaining Windows printer share SMB settings (for tsclient/rdesktop on Linux) – Super User), which was solved by explicity specifying a Windows workgroup on the command line – however, I cannot tell if that is also the problem here in the Python case; or if instead, the username is not passed here (or something completely third). EDIT: this working command line (which lists shares) is (in respect to this example):
smbclient -L \\printserver.myworkdomain.com -U MYWORKUSERNAME -W myworkdomain.com
Thanks in advance for any suggestions,
Cheers!
Ok, well, I think I finally got it, thanks to comments in Bug #848065 “system-config-printer cannot authenticate Windows Samba printer, while smbclient can (cli_init_creds)” – and reviewing newprinter.py (from
system-config-printer)…But first of all, a little overview:
MYUSERNAMEmyworkdomain.comMYWORKUSERNAMEMYWORKGROUP, which also has a subdomainmyworkgroup.myworkdomain.comprintserver.myworkdomain.comPRINTSHARENAMEWell, it turns out that a single line in the
test.pyscript above is wrong – instead of:return ("myworkdomain.com", "MYWORKUSERNAME", "MYWORKPASSWORD")… one should have had:
return ("MYWORKGROUP", "MYWORKUSERNAME", "MYWORKPASSWORD")… (with
MYWORKGROUPin allcaps, as typical for Windows)Interestingly, using the workgroup subdomain does not work:
return ("myworkgroup.myworkdomain.com", "MYWORKUSERNAME", "MYWORKPASSWORD")… as it will also fail with ‘
smbc.PermissionError: (13, 'Permission denied')‘ (just like the original post example).One way to troubleshoot the “permission denied” error is to check the log – it shows something like this:
… apparently, the DomainName should be:
For reference, here is a snippet of the log from the “working” setup (with
return ("MYWORKGROUP" ...):