Debian Codegraph @

UTILS/smbprint

raw symbols SCIP
1 #!/bin/sh
2 # $Id: smbprint,v 1.67 2004/09/24 20:19:56 papowell Exp $
3 #
4 # Blatently lifted from some folks who blatently lifted it from
5 # other folks, who seem to have taken it from one of the very
6 # first Samba distributions.
7 # Patrick ("Worse than a chain letter") Powell
8 #
9 # This script supports sending a print job to an SMB (Samba/Microsoft)
10 # printer using the 'smbclient' from the Samba distribution.
11 #
12 # Variation 1: LPRng + smbclient -A auth
13 # smb:lp=|/.../smbprint
14 # :sd=/var/spool/lpd/%P
15 # :xfer_options=share=//host/share authfile=auth
16 # - user name and password in /var/spool/lpd/smb/auth file
17 # - requires version of smbclient that uses -A authfile
18 # Variation 2: LPRng + smbclient -U username password
19 # smb:lp=|/.../smbprint
20 # :sd=/var/spool/lpd/%P
21 # :xfer_options=share=//host/share authfile=auth
22 # - user name and password in /var/spool/lpd/smb/auth file
23 # - requires version of smbclient that uses -A authfile
24 # Variation 3: LPRng + used as filter
25 # smb:lp=/dev/null
26 # :if=/.../smbprint
27 # :sd=/var/spool/lpd/%P
28 # :xfer_options=share=//host/share authfile=auth
29 # - user name and password in /var/spool/lpd/smb/auth file
30 # Variation 4: pass options in $spooldir/general.cfg file
31 # smb:lp=/dev/null OR lp=|/.../smbprint OR :if=/.../smbprint
32 # - options in /var/spool/lpd/smb/general.cfg file
33 #
34 # The general.cfg file is used to set shell variables
35 #
36 # share=//host/share - share (required)
37 # hostip= - host ip address (optional)
38 # workgroup= - workgroup (required)
39 # authfile=auth - authorization file (optional)
40 # translate= - do translation (optional and DANGEROUS)
41 #
42 # The authentication file (authfile) holds the username and
43 # password value. You can put these in the general.cfg file
44 # as well. WARNING: smbclient requires the authentication file
45 # to have the format:
46 # username=name
47 # password=xxxx
48 # There are NO quotes allowed around the name and/or password
49 # files so the password value xxxx must not contain shell
50 # quote or metacharacters.
51 #
52
53 PATH=/bin:/usr/bin:/usr/local/bin
54 export PATH
55
56 # get options from general.cfg file
57 if [ -f ./general.cfg ] ; then
58 source ./general.cfg
59 fi
60
61 # get options from $PRINTCAP_ENTRY environment variable
62 options=`echo "${PRINTCAP_ENTRY}" | sed -n 's/:xfer_options=//p' `
63 echo OPTIONS $options >&2
64 if [ -n "$options" ] ; then
65 eval export $options
66 fi
67
68 # a brutal way to determine if smbclient takes the -A authfile option
69 smbclientold=`smbclient -A /dev/null 2>&1 </dev/null | grep 'invalid option'`
70
71 # check for smbclientold=yes and fix up authfile/password stuff
72 if [ "$smbclientold" != "" -a "$authfile" != "" -a -f "$authfile" ] ; then
73 . $authfile
74 authfile=
75 fi
76
77 if [ "$translate" = "yes" ]; then
78 command="translate ; print -"
79 else
80 command="print -"
81 fi
82
83 #echo $share $password $translate $x_command > /tmp/smbprint.log
84
85 # use the -A or
86 if [ "$smbclientold" = "" ] ; then
87 # echo smbclient "$share" ${password:+password} -E \
88 # ${username:+-U} ${username:+username} ${hostip:+-I} $hostip -N ${workgroup:+-W} $workgroup \
89 # ${authfile:+-A} $authfile -c "$command" >&2
90 smbclient "$share" ${password} -E \
91 ${username:+-U} ${username} ${hostip:+-I} $hostip -N ${workgroup:+-W} $workgroup \
92 ${authfile:+-A} $authfile -c "$command" >&2
93 else
94 # echo echo \"$command\" "|" smbclient "$share" ${password:+password} -E \
95 # ${username:+-U} ${username:+username} ${hostip:+-I} $hostip -N ${workgroup:+-W} $workgroup \
96 # >&2
97 echo $command | smbclient "$share" ${password} -E \
98 ${username:+-U} ${username} ${hostip:+-I} $hostip -N ${workgroup:+-W} $workgroup \
99 >&2
100 fi