librpc/spoolss fixes for Samba 4

Jelmer Vernooij jelmer at samba.org
Tue Dec 27 17:41:35 MST 2011


Am 27/12/11 18:43, schrieb Fábio Ramon:
> 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)
>
>      try:
>          result = sp.EnumPrinterDrivers(server, arch, 1, 0, 0)
>      except Exception, e:
>          errno, errstr, result = e
>          if errno != constants.SAMBA_WERR_INSUFFICIENT_BUFFER:
>              raise
>
>      needed = result[2]
>      result = sp.EnumPrinterDrivers(server, arch, 1, needed, needed)[1]
I think the API should actually abstract this bit away for you, and just 
let you do a EnumPrinterDrivers call without having to pass in a length. 
/it/ should take care of passing in a buffer of the right size and not 
returning anything to you until it actually has the printer data.

The spoolss interface already adds in a lot of code that is not strictly 
DCE/RPC code, so I think this is a reasonable thing to do.

Cheers,

Jelmer


More information about the samba-technical mailing list