printing spool modifications
Greg Dickie
greg at discreet.com
Wed Jan 13 12:29:15 GMT 1999
A "trick" I used at my last job pulled the filename from the PostScript code.
This works very well assuming you are using PostScript.
Greg
On 13-Jan-99 Tim Hockin wrote:
> I am having a couple issues with samba, and I am halfway to having them
> fixed...
>
> When joe user prints from win95 to my shared samba queue, he sees in his
> printer status dialog a garbled name. ALL the users see each others
> garbled names. I have written a small patch to make a new config option
>
> printer spoolfile template
>
> so you can say something like ... = %M_%T and it gets parsed out
> correctly, and expanded, then has mktemp() run on it, giving it a .XXXXXX
> of random chars at the end.
>
> This works so far.
> I'd like to change the default behavior from being only 6 chars of the
> remote machine + .XXXXXX to the fullname of the remote machine + .XXXXXX
> (%m ?). I'd also like to add %r and %t switches for that param (1 random
> char, and 6 random chars (mktemp) respectively)
>
> That is, if people like my ideas and patch, and if the samba guys want to
> use it. I put the changes in unix_convert(), and I THINK that is the right
> place for them, and that is one of my questions. :)) IS that the right
> place? The preliminary patch is below, but doesn't include the further
> extensions I am thinking about.
>
> My main remaining problem is this: is there ANY ANY ANY way for smbd to
> learn what the filename that was printed was. E.g - if Windows prints "My
> long named document.doc" I'd like to be able to grab that in smbd, and use
> it for another % expansion on this new parameter.
>
> btw,
> I'm new to the list and to samba - HI!. I have to hand it to the samba
> guys for making the smbd code pretty darn straight forward and
> understandable. a few more comments might help a new hacker, but i
> survived :)
>
> Thanks!!
> Tim
>
> diff -ruN samba-orig/docs/manpages/smb.conf.5
> samba-changed/docs/manpages/smb.conf.5
> --- samba-orig/docs/manpages/smb.conf.5 Wed Dec 2 16:37:29 1998
> +++ samba-changed/docs/manpages/smb.conf.5 Tue Jan 12 18:28:27 1999
> @@ -4476,8 +4476,8 @@
> with two exceptions: All occurrences of \f(CW"%s"\fP will be replaced by
> the appropriate spool file name, and all occurrences of \f(CW"%p"\fP will
> be replaced by the appropriate printer name\&. The spool file name is
> -generated automatically by the server, the printer name is discussed
> -below\&.
> +derived from the \fB"printer spoolfile template"\fP command, the printer
> +name is discussed below\&.
> .IP
> The full path name will be used for the filename if \f(CW"%s"\fP is not
> preceded by a \f(CW\'/\'\fP\&. If you don\'t like this (it can stuff up some
> @@ -4526,6 +4526,27 @@
> .IP
> \fBExample:\fP
> \f(CW print command = /usr/local/samba/bin/myprintscript %p %s\fP
> +.IP
> +.IP "\fBprinter spoolfile template (S)\fP"
> +.IP
> +This option is used to set the name of the temporary file used by smbd to
> spool
> +a print job\&. When a print request is received, samba stores it to a file
> on
> +the local filesystem (as defined by the \fB"path"\fP option) and spools it
> +from there to the native UNIX print subsystem\&.
> +.IP
> +This value must be set on a per-service basis, and has a default value of
> +the first six characters of the remote machine's NetBIOS name. All spooled
> +jobs are followed by a period (\&.) and 6 pseudo-random characters (as
> +generated by mktemp())\&. All spoolfile template values are made unique by
> +adding these 6 characters\&.
> +.IP
> +The most flexible feature of this command is that the value allows all the
> +standard \fB%\fP substitutions (though some are obviously not appropriate).
> +This is aimed at sites which do print queuing and need more information
> +about the spooled jobs\&.
> +.IP
> +\fBExample:\fP
> +\f(CW printer spoolfile template = %M__%T\fP
> .IP
> .IP "\fBprint ok (S)\fP"
> .IP
> diff -ruN samba-orig/source/include/proto.h
> samba-changed/source/include/proto.h
> --- samba-orig/source/include/proto.h Wed Dec 16 12:50:54 1998
> +++ samba-changed/source/include/proto.h Tue Jan 12 13:25:12 1999
> @@ -1281,6 +1281,7 @@
> char *lp_queuepausecommand(int );
> char *lp_queueresumecommand(int );
> char *lp_printername(int );
> +char *lp_printerspoolfiletemplate(int );
> char *lp_printerdriver(int );
> char *lp_hostsallow(int );
> char *lp_hostsdeny(int );
> diff -ruN samba-orig/source/include/smb.h samba-changed/source/include/smb.h
> --- samba-orig/source/include/smb.h Wed Dec 16 12:50:54 1998
> +++ samba-changed/source/include/smb.h Tue Jan 12 11:44:35 1999
> @@ -1107,6 +1107,7 @@
> #define PRINTCAP (lp_printcapname())
> #define PRINTCOMMAND(snum) (lp_printcommand(snum))
> #define PRINTERNAME(snum) (lp_printername(snum))
> +#define PRINTERSPOOLFILETEMPLATE(snum) (lp_printerspoolfiletemplate(snum))
> #define CAN_WRITE(conn) (!conn->read_only)
> #define VALID_SNUM(snum) (lp_snum_ok(snum))
> #define GUEST_OK(snum) (VALID_SNUM(snum) && lp_guest_ok(snum))
> diff -ruN samba-orig/source/param/loadparm.c
> samba-changed/source/param/loadparm.c
> --- samba-orig/source/param/loadparm.c Mon Dec 7 15:37:16 1998
> +++ samba-changed/source/param/loadparm.c Tue Jan 12 17:27:32 1999
> @@ -266,6 +266,7 @@
> char *szPrintername;
> char *szPrinterDriver;
> char *szPrinterDriverLocation;
> + char *szPrinterSpoolfileTemplate;
> char *szDontdescend;
> char *szHostsallow;
> char *szHostsdeny;
> @@ -359,6 +360,7 @@
> NULL, /* szPrintername */
> NULL, /* szPrinterDriver - this is set in init_globals() */
> NULL, /* szPrinterDriverLocation */
> + NULL, /* szPrinterSpoolfileTemplate */
> NULL, /* szDontdescend */
> NULL, /* szHostsallow */
> NULL, /* szHostsdeny */
> @@ -664,6 +666,7 @@
> {"printer", P_STRING, P_LOCAL, &sDefault.szPrintername,
> NULL, NULL, 0},
> {"printer driver", P_STRING, P_LOCAL, &sDefault.szPrinterDriver,
> NULL, NULL, 0},
> {"printer driver location", P_STRING, P_LOCAL,
> &sDefault.szPrinterDriverLocation, NULL, NULL, FLAG_GLOBAL},
> + {"printer spoolfile template", P_STRING, P_LOCAL,
> &sDefault.szPrinterSpoolfileTemplate, NULL, NULL, 0},
>
> {"Filename Handling", P_SEP, P_SEPARATOR},
> {"strip dot", P_BOOL, P_GLOBAL, &Globals.bStripDot,
> NULL, NULL, 0},
> @@ -1261,6 +1264,7 @@
> FN_LOCAL_STRING(lp_queueresumecommand,szQueueresumecommand)
> FN_LOCAL_STRING(lp_printername,szPrintername)
> FN_LOCAL_STRING(lp_printerdriver,szPrinterDriver)
> +FN_LOCAL_STRING(lp_printerspoolfiletemplate,szPrinterSpoolfileTemplate)
> FN_LOCAL_STRING(lp_hostsallow,szHostsallow)
> FN_LOCAL_STRING(lp_hostsdeny,szHostsdeny)
> FN_LOCAL_STRING(lp_magicscript,szMagicScript)
> diff -ruN samba-orig/source/smbd/filename.c
> samba-changed/source/smbd/filename.c
> --- samba-orig/source/smbd/filename.c Fri Nov 20 19:26:18 1998
> +++ samba-changed/source/smbd/filename.c Tue Jan 12 17:06:35 1999
> @@ -402,12 +402,28 @@
> if (conn->printer) {
> if ((! *name) || strchr(name,'/') || !is_8_3(name, True)) {
> char *s;
> - fstring name2;
> - slprintf(name2,sizeof(name2)-1,"%.6s.XXXXXX",remote_machine);
> + pstring name2;
> + pstring str;
> + char *spooltemplate;
> + int snum = SNUM(conn);
>
> /*
> * Sanitise the name.
> + *
> + * Do substitutions on the spoolfile name if needed
> + * --Tim Hockin <thockin at ais.net>
> */
> + spooltemplate = PRINTERSPOOLFILETEMPLATE(snum);
> + if (spooltemplate == NULL) {
> + /* default filename */
> + slprintf(str,sizeof(str)-1,"%.6s", remote_machine);
> + } else {
> + /* parse it */
> + pstrcpy(str, spooltemplate);
> + standard_sub(conn, str);
> + }
> +
> + slprintf(name2,sizeof(name2)-1, "%s.XXXXXX", str);
>
> for (s=name2 ; *s ; s++)
> if (!issafe(*s)) *s = '_';
---------------------------------------------------------------------
Greg Dickie
Just A Guy*
*from discreet logic
Montreal
(514) 954-7171
greg at discreet.com
More information about the samba-technical
mailing list