Possible to set printer devmode using samba3-python?

Kurt Pfeifle kpfeifle at danka.de
Wed Nov 12 15:50:46 GMT 2003


daniel.jarboe at custserv.com wrote:
>>A valid *devmode* can only be set (if it needs to be set) by 
>>*executing*
>>the Windows binaries of the Windows printer driver. That execution is
>>only possible by opening the driver properties from a Windows client,
>>thusly causing a client-side driver execution.
>>
>>It suffices to change (f.e.) the page mode from "portrait" to 
>>"landscape",
>>then "Apply", then back again to have that Windows code executed once
>>(on the Windows client), and then loaded back a valid device mode onto
>>the (Samba) server.
>>
>>But maybe I don't understand your intention?
> 
> 
> My intention is to copy all printer-related settings from an NT
> print-server to a samba server.  The NT server is already configured
> appropriately with several printers, and if I can clone those settings,

Ouch! That's rather difficult.

Windows stores these settings in the registry (and not at *one* obvious
spot, IIRC).

Samba stores them in *.tdb files.

> it would be a big time-saver and less error prone.  Also, for new
> printers to be installed, I'd like our print admin to have the
> capability of installing/configuring/shareing the printer on a windows
> pc like they've always done,

But Samba's support for the "APW" functions in uploading drivers to
its [print$] share by an Admin sitting in front of his workstation
already provide for that, no? (There are only minor differences in
starting/handling the APW which they need to be taught...)

> then trigger a process on our samba server
> to use smbclient to retrieve the drivers from their PC, rpcclient
> adddriver the printer to samba,

That's not enough: You need to make sure your print subsystem (CUPS?)
provides (at least "raw") queues first, and that Samba recognizes these
queues. Otherwise each "rpcclient setdriver" call will fail (while
"rpcclient adddriver" may even succeed)..

> and then copy all the printer settings /
> devmode etc.  It's this copy all the printer settings / devmode etc
> portion that is tripping me up.
> 

Yes, the other stuff can actually be automated by a script. (I've
already put some work into that, but it is far from finished. I did
intend it as a sort of "migration utility", which helps to switch
from an NT print server to a CUPS/Samba one. But it is not feasable
to be used on a day-to-day admin basis once the CUPS/Samba-server
is established and needs driver updates and some such....)

> Our users require functionality available in vendor-provided print
> drivers that don't take kindly to being remotely uploaded to a samba
> server using print$,

Why? What's the problem? Have you filed any bug report at Samba's
bugzilla?

 > and I'm hoping that I can get them to work by
> installing them locally and then duplicating all the driver files /
> settings they use onto the samba server.
> 

My fear is that if there are still bugs and deficiencies with the
MS-RPC functions in Samba regarding SPOOLSS, and these are preventing
your driver from upload and store in the *.tdbs via APW, the same
bugs might prevent you from "duplicating" the Windows *.reg chunks
into the Samba *.tdb files...

Probably the time and effort is better put to use by helping the
Samba developers to trace down the last major bugs and deficiencies
in the RPC/SPOOLSS code?

> 
>>What is the "samba3-python" thing you are talking about?
> 
> 
> Experimental python helpers that can be built with samba 3.

I'll need to dig the sources to find them.... Sounds interesting
in any case, even if it doesn't (yet) do what you want. Thanks for
the hint

> It allows
> an interface to many of the spoolss commands from python scripts.  I
> thought I might be able to take advantage of this interface to achieve
> the printer share cloning.
> 

This is new to me and I don't understand anything about it (yet).

> 
>>Maybe you are intending to address the setting of 
>>user-selectable printjob
>>options to certain defaults (and not setting a "DeviceMode" 
>>which is s.th.
>>different...)?
> 
> 
> Yes, that too.  Everything.  I'm not sure what data is stored where when
> it comes to the various Window printing driver options, but by copying
> all of it I should be covered.
> 
> 
>>>I'm trying to automate printer driver installation on samba 
>>>servers for Our print admin.  I've no problem getting the driver
>>>files from a windows
>>>printer shared with rpcclient and smbclient, and access 
>>>printerdata to set things like installed printer accessories...
>>>
>>
>>But you're doing that from the Windows client? Or?
> 
> 
> In effect a process on the samba server becomes a client, connecting to
> a windows printer share and copying driver files, printer settings,
> devmode, whatever it needs.  Then the process connects to localhost (or
> wherever the samba server is) and uploads the printer drivers, and
> stores the printer settings (that were originally generated by a windows
> client) onto the samba server.
> 

I see...

But I have yet to see any "rpcclient [retriev driversettings]" at all.
So there is also little chance that the "python helpers" you explained
to me now will be able to do it. I imagine this rather difficult,
looking at the overall Windows print organization being rather.... hmm,
should I say "messy"?

Maybe one of the real developers could comment on this?

> 
>>>But in order to have the printing preferences and defaults 
>>
>>set I believe
>>
>>>I need getprinter and setprinter.
>>>
>>>Getprinter seems to work well, but when doing a python spoolss
>>>setprinter for info2, I get:
>>>spoolss.werror: [31, 'DOS code 0x0000001f'] ...
>>>
>>>And when doing a setprinter(info1) I get segmentation fault.
>>>backtrace of core yields:
>>>#0  0x40322688 in prs_uint32 ()
>>>   from /usr/lib/python2.2/lib-dynload/samba/spoolss.so
>>>#1  0x40372806 in spool_io_printer_info_level_1 ()
>>>   from /usr/lib/python2.2/lib-dynload/samba/spoolss.so
>>>#2  0x403732a0 in spool_io_printer_info_level ()
>>>   from /usr/lib/python2.2/lib-dynload/samba/spoolss.so
>>>#3  0x4037129e in spoolss_io_q_setprinter ()
>>>   from /usr/lib/python2.2/lib-dynload/samba/spoolss.so
>>>#4  0x4038c43e in cli_spoolss_setprinter ()
>>>   from /usr/lib/python2.2/lib-dynload/samba/spoolss.so
>>>#5  0x402bcbd4 in spoolss_hnd_setprinter ()
>>>   from /usr/lib/python2.2/lib-dynload/samba/spoolss.so
>>>#6  0x00490162 in PyCFunction_Call ()
>>>#7  0x0046fe68 in PyObject_Call ()
>>>#8  0x00439b7a in PyEval_GetFuncDesc ()
>>>
>>>For setprinter(info3) I get:
>>>spoolss.error: error converting to printer info 3 ... 
>>>That is with info3=hnd.getprinter(level=3) ... I made no 
>>>modifications to the format of the data.
>>>
>>>Is samba3 python not ready for what I'm trying to do?  Any 
>>>ideas how I can accomplish it by other means? 
>>
>>Please explain, in simple words, to a dumb little documentation writer
>>what exactly you want to achieve.
> 

I got it now from your elaboration above...   ;-)

> 
> Sorry to frustrate you, I know you know your stuff when it comes to
> samba and cups printing... you wrote the book on it :).  You know that
> there are certain pitfalls necessary to avoid when configuring a samba
> printer share to support point 'n print.  All in all, I think it can be
> a fairly delicate process, and I'd like to try to eliminate the source
> of some potential mistakes... i.e. let our print admin install/configure
> a printer share just like they are used to on a windows box, click a
> button on a webpage and *poof*, have an exact copy of that printer share
> they created on the windows box, available on the samba server.
> 

Once that is accomplished.... sigh...

> 
>>>This is with 3.0.1pre2 on SLES8 s/390,
>>>with a w2k pc on the other end.
>>>
>>>Thanks,
>>>~ Daniel
>>

Cheers,
Kurt




More information about the samba-technical mailing list