Printing on a Window Client from AIX

Alan Fahrner alan at chelz.com
Wed Jul 29 02:28:47 GMT 1998


Hi all...

First, thank you to Matt Chapman for pointing out why I could not connect to a
non-domain participating machine.  I needed to have a local account on that
machine (it wasn't checking back with the domain controllers as I thought it
would).  I guess I'm going to have to start venturing out of the UNIX world and
into the NT one.  Scary :-)

Either way, I now successfully am printing to a printer shared on a NT 4.0
workstation from AIX.

Below is the modified smbprint script with documentation.  In searching the
archives of this list and others, FAQs, web-sites, etc., I never saw an
explanation of how to deal with the weirdness of AIX printing while using
smbclient.  Well, I'm not claiming it's perfect, but here goes.

Alan
alan at chelz.com

---------------------------------------------------------
#!/bin/ksh

# smbprint (for AIX):  Print files from a UNIX system running samba to
#                      a printer shared on another smb serving machine.
#
# Since AIX doesn't use a standard printcap file, this script is modified
# from the one distributed with Samba.
#
# As if there is a standard way of printing in UNIX :-)
#
# The first printer I have done this way in AIX (4.3) has the following entry
# in the /etc/qconfig file:
#
#  p02:
#          discipline = fcfs
#          up = TRUE
#          device = dp02
#  dp02:
#          backend = /usr/local/bin/smbprint p02
#          file = FALSE
#          header = never
#          trailer = never
#
#  Technically, since most of the values are the defaults, it could be as
#  short as:
#
#  p02:
#          device = dp02
#  dp02:
#          backend = /usr/local/bin/smbprint p02
#
#  From what I could tell, when AIX calls the backend program, it appends
#  the file you are printing to the end of the command.  If you feed into
#  the lp command from standard in, this is a temporary file in the print
#  spool directory (as it is if you use the "-c" option to the lp command).
#
#  In the backend program definition, The "p02" is the name of the
#  configuration file for this "service", found in CONFIG_DIR(defined below).
#  In this case, the file /var/samba/print/p02 has:
#
#  SERVER=tkt15n3z
#  SERVICE=printer02
#  USER=print
#  PASSWORD=you_dont_think_i_would_actually_tell_you
#  TRANSLATE=TRUE
#
#  All but the last one are standard smb variables.  TRANSLATE is a way I
#  have made it so that you only do the CR/LF translation for printers
#  that require it.  It will do the conversion if TRANSLATE is set to "TRUE".
#  All other TRANSLATE values (or lack of a value) will be ignored.
#
#  Security.  Well, I could have easily passed all the script variables
#  on the backend line in /etc/qconfig, but it bothered me that
#  the world-readable qconfig file would contain a password.  So, I've
#  made this script run setgid (via a wrapper) as printq (please, those
#  more intelligent than I, let me know if there is a risk I don't realize
#  in doing this).  I then protected both write ability to the log and
#  read/write to the config files.
#
#  Dunce note:  Being unfamiliar with NT 4.0, I had a problem initially
#  connecting to a machine that wasn't participating in the domain.  I posted
#  to the samba at samba.anu.edu.au newsgroup (which you can get more info about
#  at http://samba.anu.edu.au/listproc) asking about the problem and got a
#  nice response from Matt Chapman asking if I had a local account on
#  the machine I was trying to connect to.  Since my Win95 pc connected fine
#  to the machine without me having a local account on it, I didn't think
#  it was required.  It was :-)
#
#  Thanks Matt.
#
#  Any suggestions for improvements/etc?  Please send them!
#
#  Alan (Fahrner)
#  alan at chelz.com
#  http://www.chelz.com/
#
#  Returns:
#      0 - Okee dokee
#      1 - Problem finding/reading config file or file to print
#      2 - Called incorrectly
#      ? - Some other problem

################################################################################
# DEFINES
################################################################################
# protect our path
export PATH="/bin"
# where is our smbclient program?
SMBCLIENT=/usr/local/bin/smbclient
# where do we keep the printer configurations (include final "/")?
CONFIG_DIR=/var/samba/print/
# Debugging log file, change to /dev/null if you like.
LOGFILE=/var/samba/log/log.smbprint


################################################################################
# MAIN
################################################################################
# logging/debugging.  Change to a ">" if you want to reset the log after
# each print job...
ID=$(id)
DATE=$(date)
echo "$ID -- $DATE" >> $LOGFILE

# are we called correctly?
if (( $# != 2 )); then
    echo "Called incorrectly \"$0 $*\""
	exit 2
fi

# these variables from arguments.  PRINTER is defined in the qconfig file,
# FILE is automatically passed to the backend program (this) for the
# print queue device.
PRINTER=$1   # is used for finding actual printer configuration
FILE=$2      # what file are we printing

# logging/debugging...
echo $PRINTER $FILE >> $LOGFILE

# get these from the printer config file.  If we can't read the file
# (for whatever reason), exit with a bad code
# SERVER, SERVICE, USER, PASSWORD, TRANSLATE
if [[ -r "$CONFIG_DIR$PRINTER" ]]; then
	eval  $(cat $CONFIG_DIR$PRINTER)
else
	echo "Either can't find or read config file $CONFIG_DIR$PRINTER" >> \
		$LOGFILE
	exit 1
fi

# Can we find the file we are going to print?
if [[ ! -r "$FILE" ]]; then
	echo "Either can't find or read input file $FILE" >> $LOGFILE
	exit 1
fi

# make sure we have all required variables.  PASSWORD and TRANSLATE can be
# blank or non-existant.
if [[ -z "$SERVER" || -z "$SERVICE" || -z "USER" ]]; then
    echo "Didn't get required values from $CONFIG_DIR$PRINTER" >> $LOGFILE
	exit 3
else
	# Logging/debugging...
	echo "server $SERVER, service $SERVICE, user $USER, tranlate $TRANSLATE" >>\
		$LOGFILE
fi

# group the following output for feeding into smbclient
{
    # translate to CR/LF (if we need to)...
    if [[ "$TRANSLATE" = "TRUE" ]]; then
		echo translate
    fi
	echo "print -"
	cat $FILE
} | $SMBCLIENT "\\\\$SERVER\\$SERVICE" $PASSWORD -U $USER -N -P >> $LOGFILE \
	2>&1



More information about the samba mailing list