librpc/spoolss fixes for Samba 4
framon at monzeu.eti.br
Tue Dec 27 10:43:33 MST 2011
On 27 December 2011 12:04, Jelmer Vernooij <jelmer at samba.org> wrote:
> I don't think it breaks the API, but it's the wrong thing to do. The
> result variable is still incomplete at the point the exception is raised.
> If the condition is not fatal and partially succeeded, we shouldn't be
> raising an exception in the first place. Can you explain why you need this?
As we know, the RPC procotol defines that if the buffer is to small, the
needed field returns the number of bytes required. When this happens, the
result code is NOT OK and the current error handler raise an exception with
only error code and error string, losting the needed information.
Therefore, we are in the case where condition is partially succeeded. I
agree with you that putting the result on the exception is not the best
solution all the time, but the python client need a way to receive that
field. Maybe, the exception should not be raised in this case. Feel free to
design a solution.
Here is a sample code where I use this:
def enumPrinterDrivers(server, arch):
cs = 'ncacn_np:%s' % server
creds = makeCredentials()
sp = spoolss.spoolss(cs, credentials=creds)
result = sp.EnumPrinterDrivers(server, arch, 1, 0, 0)
except Exception, e:
errno, errstr, result = e
if errno != constants.SAMBA_WERR_INSUFFICIENT_BUFFER:
needed = result
result = sp.EnumPrinterDrivers(server, arch, 1, needed, needed)
drivers = [info.driver_name for info in result]
More information about the samba-technical