[TriLUG] HOWTO: Create PDFs using Samba but not CUPS

Steve Hoffman srhoffman at gmail.com
Mon Feb 27 16:20:56 EST 2006


[pdfGen]
   path = /tmp
   printable = yes
   guest ok = yes
   print command = /usr/bin/printpdf %s %U
   lpq command =
   lprm command =

That's the relevant section from my smb.conf....i'm using v3.0.12a-1 on a
RH9 system, so it's a little old, but it should work on your system just as
well...  The only thing I can think of is since you're NOT using
authentication and you force a guest account to be "nobody" in the "GLOBAL"
section of smb.conf, perhaps one's stepping on the toes of the other.  I
don't have a   guest account = nobody line in my config.

Try removing that...

Steve

On 2/27/06, Rick DeNatale <rick.denatale at gmail.com> wrote:
>
> On 2/27/06, David McDowell <turnpike420 at gmail.com> wrote:
> > I presume with %s %U that you *are* authenticating to the share using
> > LDAP credetials?  Also, I'm trying to understand the origin of:
> > User = "$2"
> > Is this a value in some array gathered ($2) where the %U value comes
> > through from SMB to the bash script?
>
> $2 is just the second parameter to the bash script, just like $1
> (where you were always getting the temp file from) is the first.
>
> > Here are the changes I made:
> >
> > in smb.conf:
> > print command = /usr/bin/printpdf %s
> > is now
> > print command = /usr/bin/printpdf %s %U (there's a space between those
> items)
> >
> > in printpdf script:
> > DATE=`date +%b%d-%H%M%S`
> > User="$2"
> > filename="$User_$DATE"
> > OUTDIR=/pdfdropbox
> > ps2pdf $1 $OUTDIR/$DATE.temp
> > mv $OUTDIR/$DATE.temp $OUTDIR/$filename.pdf
> > rm $1
> >
> > I noticed there were single back ticks vs " and wasn't sure what
> > effect that has either.
>
> The backticks around `date +%b%d-%H%M%S` cause bash to set the DATE
> variable to the output of the date command.
>
> > Of course.  Do I have to have successful auth
> > to SMB with an AD user to have a value in %U or will it still pickup
> > the username of the user logged into the workstation (as was sort of
> > eluded to)?
>
> Yes, unless samba knows the remote user's identity it can't very well
> it to you.  Others will have to tell you how to accomplish that.
>
> > Currently I still get: Feb27-134739.pdf  as my filename format. No user
> info.
> >
> > thanks!
> > David
> >
> >
> >
> >
> > On 2/27/06, Steve Hoffman <srhoffman at gmail.com> wrote:
> > > Here's the relevant line from samba:  print command =
> /usr/bin/printpdf %s
> > > %U
> > >
> > > Then in my printpdf I have a section like this:
> > >
> > > DATE=`date +%b%d-%H%M%S`
> > > msgBody="Your PDF, blah blah"
> > > User="$2"
> > > mailDomain="domain.com"
> > > filename=$User-$DATE.pdf"
> > >
> > > echo $msgBody | mutt -s "PDF Generated!" -a $OUTDIR/$filename
> > > $User\@$mailDomain
> > >
> > >
> > > So the %U in the smb.conf file takes the logon credentials the user
> logged
> > > on to their workstation with and passes to shares when it attempts to
> > > connect.  I take that an append our domain to it to create an email
> address.
> > > I didn't copy the entire script as it's grown substantially with ldap
> calls
> > > etc to verify that the user exists (we have guests come onsite that
> print to
> > > it as user "owner" or "dell user" etc and that was hosing
> things).  There's
> > > also logic in there to take files over 10MB and dump them to the users
> > > personal folder share preventing others from getting access then does
> > > garbage cleanup.
> > >
> > >
> > >
> > > On 2/27/06, David McDowell <turnpike420 at gmail.com> wrote:
> > > >
> > > > I got this working, but I think I may need to take it a step
> further.
> > > > First, here's all my settings (the line items of importance anyway).
> > > > smb.conf:
> > > >    workgroup = DOMAIN
> > > >    server string = HOST1
> > > >    hosts allow = 192.168.0. 127.
> > > >    printing = lprng
> > > >    guest account = nobody
> > > >    security = share
> > > >
> > > > [pdfdropbox]
> > > >    path = /pdfdropbox
> > > >    browseable = yes
> > > >    writeable = yes
> > > >    guest ok = yes
> > > >    force user = nobody
> > > >
> > > > ; Set up our PDF-creation print service
> > > > [pdf]
> > > >    path = /tmp
> > > >    postscript = yes
> > > >    printable = yes
> > > >    guest ok = yes
> > > >    print command = /usr/bin/printpdf %s
> > > >    writable = yes
> > > >    public = yes
> > > >
> > > >    ; There is no need to support listing or removing print jobs,
> > > >    ; since the server begins to process them as soon as they arrive.
> > > >    ; So, we set the lpq (list queued jobs) and lprm (remove jobs in
> queue)
> > > >
> > > >    ; commands to be empty.
> > > >    lpq command =
> > > >    lprm command =
> > > >
> > > > My /use/bin/printpdf:
> > > > #!/bin/sh
> > > >
> > > > # Simple script to convert a specified postscript file into a PDF
> document
> > > > # and place it in a location that is shared by the Samba server.
> > > > #
> > > > # Arguments:
> > > > #   1st - The name of the spool file
> > > > #
> > > > # John Bright, 2001, jbright at winfordeng.com
> > > >
> > > > # We will create the pdf into a temporary file based upon the
> current
> > > > date and time.
> > > > # After we are finished, we'll rename it to a file with the same
> date,
> > > > but ending
> > > > # in .pdf.  We do this because if a user tries to open a PDF that is
> > > > still being written,
> > > > # they will get a message that it is corrupt, when it is actually
> just
> > > > not done yet.
> > > >
> > > > DATE=`date +%b%d-%H%M%S`
> > > >
> > > > # Directory in which to place the output
> > > > # Be sure this directory exists and is writable by the user that
> Samba
> > > > # is running as (for example, the nobody user)
> > > > OUTDIR=/pdfdropbox
> > > >
> > > > ps2pdf $1 $OUTDIR/$DATE.temp
> > > > mv $OUTDIR/$DATE.temp $OUTDIR/$DATE.pdf
> > > > rm $1
> > > > ------------------
> > > > OK.  So, here's my dilema.  We have about 20-30 employees who may
> > > > possibly use this feature on a semi/very regular basis.  If SMB has
> > > > the printer as public and is using the nobody user for the output
> > > > ownership, are there any suggestions to how I can get my W2K3 AD
> > > > usernames collected by SMB and have them become part of the name in
> > > > the output PDF file as well?  Currently I get a file called
> > > > "Feb27-084822.pdf" for example.  It would be nice if it was called
> > > > "<username>_Feb27-084822.pdf" instead.
> > > >
> > > > I know it "could/should" be possible for me to link this SMB up with
> > > > auth to my AD. I have version: samba-3.0.10-1.4E.2 on CentOS 4.2
> .  But
> > > > even then, IF I could get that working, where to go from there to
> get
> > > > that AD username to the bash script for output into the filename??
> > > >
> > > > Inevitably users will leave prints behind just like they do on paper
> > > > printers.  I have that covered by forcing username
> coversheets.  Here,
> > > > I need the username to act as a coversheet of sorts.  Also, I just
> > > > don't give my users credit enough to not complain that they can't
> tell
> > > > which is there print vs. somebody else's. *cry*
> > > >
> > > > Thanks!!
> > > > David McD
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > On 9/26/05, Brian Henning <brian at strutmasters.com> wrote:
> > > > > Hi Folks!
> > > > >   Here's the conclusion to "samba printing.. ugh".
> > > > >
> > > > > Building off the previously referenced website..  You'll need the
> > > > > following shell script in a handy location with 755 permissions
> (or make
> > > >
> > > > > sure the samba user [typically 'nobody'] has the right access
> rights to
> > > > it):
> > > > >
> > > > > -- begin script quote --
> > > > > #!/bin/sh
> > > > >
> > > > > # Simple script to convert a specified postscript file into a PDF
> > > > document
> > > > > # and place it in a location that is shared by the Samba server.
> > > > > #
> > > > > # Arguments:
> > > > > #   1st - The name of the spool file
> > > > > #
> > > > > # John Bright, 2001, jbright at winfordeng.com
> > > > >
> > > > > # 26-Sep-2005 - Brian Henning
> > > > > # TODO: We really need to  find a way to link PDFs with their
> respective
> > > > > # Sales Orders.  This is way not idiot-proof enough.
> > > > >
> > > > > # We will create the pdf into a temporary file based upon the
> current
> > > > > # date and time.  After we are finished, we'll rename it to a file
> with
> > > > > # the same date, but ending in .pdf.  We do this because if a user
> tries
> > > >
> > > > > # to open a PDF that is still being written, they will get a
> message
> > > > > # that it is corrupt, when it is actually just not done yet.
> > > > >
> > > > > DATE=`date +%b%d-%H%M%S`
> > > > >
> > > > > # Directory in which to place the output
> > > > > # Be sure this directory exists and is writable by the user that
> Samba
> > > > > # is running as (for example, the nobody user)
> > > > > OUTDIR=/home/public
> > > > >
> > > > > ps2pdf $1 $OUTDIR/$DATE.temp
> > > > > mv $OUTDIR/$DATE.temp $OUTDIR/$DATE.pdf
> > > > > rm $1
> > > > >
> > > > > -- end script quote --
> > > > >
> > > > > For the rest of this HOWTO, we assume this script is named
> > > > > /usr/share/pdfconvert
> > > > >
> > > > > Then, you'll need to adjust your smb.conf (typically found in
> > > > > /etc/samba/smb.conf).
> > > > >
> > > > > Under [global], you'll need to tell Samba not to use CUPS for
> printing,
> > > > > and use LPRNG instead.  This is done with a line:
> > > > >        printing = lprng
> > > > >
> > > > > Then you'll need a share for the actual printer.  À la:
> > > > >
> > > > > [pdffer]
> > > > >        postscript = yes
> > > > >        printable = yes
> > > > >        print command = /usr/share/pdfconvert %s
> > > > >        writeable = yes
> > > > >        path = /tmp
> > > > >        create mask = 0744
> > > > >        comment = Prints to a PDF file
> > > > >        public = yes
> > > > >
> > > > > Some of those lines may not be absolutes; i.e. "writeable" may not
> be
> > > > > necessary, and "create mask" may only need to be "700".  This is
> what
> > > > > worked for me, and includes some results of shots-in-dark before I
> found
> > > > > the real answer.
> > > > >
> > > > > Restart samba (or wait 60 seconds for it to reload its config).
> > > > >
> > > > > Map the printer in Windows.  Windows will complain about not
> knowing
> > > > > what kind of printer it's connecting to.  Choose any PS printer; I
> chose
> > > > > an HP LaserJet 4000 PS.  Be sure to choose a PS driver and not a
> PCL
> > > > > driver.  Beyond that, it doesn't particularly matter; Windows uses
> the
> > > > > same core PS engine for all its built-in PS drivers.
> > > > >
> > > > > That should do it.  Windows may advise you "Access denied, unable
> to
> > > > > connect" when you open Printers and Faxes, or when you
> double-click for
> > > > > the queue manager.  Ignore the warning.  It will work.
> > > > >
> > > > > The pdfconvert script, as you can see, will create a pdf file in
> its
> > > > > OUTDIR location, named with the date and time of creation.  Tailor
> to
> > > > > suit your needs.
> > > > >
> > > > > HTH, YMMV, IANAL, MIPS, SCUBA, etc. etc. etc.
> > > > >
> > > > > heh.
> > > > > Cheers,
> > > > > ~Brian
> > > > >
> > > > >
> > > > > --
> > > > > ----------------
> > > > > Brian A. Henning
> > > > > strutmasters.com
> > > > > 336.597.2397x238
> > > > > ----------------
> > > > > --
> > > > > TriLUG mailing list        :
> http://www.trilug.org/mailman/listinfo/trilug
> > > >
> > > > > TriLUG Organizational FAQ  : http://trilug.org/faq/
> > > > > TriLUG Member Services FAQ :
> http://members.trilug.org/services_faq/
> > > > >
> > > > --
> > > > TriLUG mailing list        :
> http://www.trilug.org/mailman/listinfo/trilug
> > > > TriLUG Organizational FAQ  : http://trilug.org/faq/
> > > > TriLUG Member Services FAQ : http://members.trilug.org/services_faq/
> > > >
> > > --
> > > TriLUG mailing list        :
> http://www.trilug.org/mailman/listinfo/trilug
> > > TriLUG Organizational FAQ  : http://trilug.org/faq/
> > > TriLUG Member Services FAQ : http://members.trilug.org/services_faq/
> > >
> > --
> > TriLUG mailing list        :
> http://www.trilug.org/mailman/listinfo/trilug
> > TriLUG Organizational FAQ  : http://trilug.org/faq/
> > TriLUG Member Services FAQ : http://members.trilug.org/services_faq/
> >
>
>
> --
> Rick DeNatale
>
> Visit the Project Mercury Wiki Site
> http://www.mercuryspacecraft.com/
> --
> TriLUG mailing list        : http://www.trilug.org/mailman/listinfo/trilug
> TriLUG Organizational FAQ  : http://trilug.org/faq/
> TriLUG Member Services FAQ : http://members.trilug.org/services_faq/
>



More information about the TriLUG mailing list