SMB HOWTO

�@��: David Wood, [1][email protected]
Ķ��: J.S. Lin, [2][email protected]

  v1.0, 10 August 1996
    _________________________________________________________________

  �o�O SMB HOWTO {�p��ϥ� SMB}. �o���y�z�b Linux �W�p��ϥ� Session
  Message Block (SMB) protocol{��w}, �]�s�� NetBIOS �� LanManager
  protocol.
    _________________________________________________________________

1. ����

2. �i�@�B��T

3. �w��

4. ����o��� daemon

5. �@��պA�]�w (/etc/smb.conf)

6. ���� Linux �Ϻе� Windows ����

7. ���� Windows �Ϻе� Linux ����

8. ���� Linux �L���� Windows ����

9. ���� Windows �L���� Linux ����

10. ���v

11. �P�E
    _________________________________________________________________

1. ����

  �o�O SMB HOWTO {�p��ϥ� SMB} . �o���y�z�b Linux �W�p��ϥ� Session
  Message Block (SMB) protocol, �]�s�� NetBIOS �� LanManager protocol.

  ����󪺺��@�̬O David Wood ( [3][email protected]). �A��,�ק�έץ�
  �i�H�H�쨺,�H�K�U�@���]�[�i�h.

  SMB protocol �Q�ϥΦb Microsoft Windows 3.11, NT �M 95 �ΨӤ��ɺϺФΦL
  ��. �ϥ� Andrew Tridgell �Ұ��� Samba �u��M��, UNIX (�]�t Linux) ����
  ���ɺϺлP�L���� Windows �D��.

  �^�H�ϥ� Samba ���|�˪F��i�H��:

   1. ���� linux �Ϻе� Windows ����.
   2. ���� Windows �Ϻе� linux ����.
   3. ���� linux �L���� Windows ����.
   4. ���� Windows �L���� linux ����.

  �o�ǪF�賣�w�]�t�b�����.

  Disclaimer: procedures �M script �n����@�̬O�i�H���`�B�@��,�έn���Ѩ�
  ��(procedures�Mscript)�����Ѫ̳��i�i�H���`�B�@. �H�b�o�ت���T�����P��
  �]�w�i��|���ॿ�`�B�@.�p�G�A�D�J������x��,�A�i�H e-mail ���@��,���X��
  ij�ӧ�i�����, ���@�̨ä��@���O��.�A�w������O? �@�̲����u�O���U
  ��.....

2. �i�@�B��T

  �o�� HOWTO �]�k�h����p��]�w�򥻪� SMB�ɥH�ΦC�L�A�Ȧb linux �����W.
  Samba �O�ӫD�`����B���㪺�]��. �b�o�Ӧa��S���n�]�k�h�ƻs�Ҧ��� Samba
  ���.

  �i�@�B��T,�ЬݥH�U���:
    * Samba ���, �i���o�� Samba �o��M��{distribution}������. ���o��M��
      �i���o�b: [4]ftp://nimbus.anu.edu.au/pub/tridge/samba/
    * The linux Printing HOWTO.
    * The Print2Win Mini-HOWTO.

3. �w��

  �̷s Samba ����l�{���i�H���o��:

  [5]ftp://nimbus.anu.edu.au/pub/tridge/samba/

  �M��,�p�G�w�w�� linux �� Redhat ����,�A�i�H�ϥγn��M��{package} �Ӧw��
  ��.���Ǩ�L�����]�]�t Samba ��binaries{�G���ɵ{��}.

  �H�U��� daemon{�޲z���F} �� Samba �n��M�� �O���n��. ���̤@��O�Q�w��
  �b /usr/sbin ,�ӥi�b�}����,�q�t�ΰ_�ʪ� scripts��inetd�Ӱ���. script��
  �Ҥl�Q�i�ܦb [6]���� Daemons.
    _________________________________________________________________

       smbd (The SMB daemon)
       nmbd (���� NetBIOS nameserver ���䴩�� clients)
    _________________________________________________________________

  �@��Ө�,�H�U�� Samba �� binaries �Q�w�˦b /usr/bin, ���M��������m�O�i
  ��ܩ�.
    _________________________________________________________________

       smbclient       (�@�بѵ� UNIX �����Ϊ� SMB  client{�{��})
       smbprint        (�@�� script �Φb�C�L�� SMB �D��{host}�W���C��)
       smbprint.sysv   (�P�W, ���O���ѵ� SVR4 UNIX �����Ϊ�)
       smbstatus       (�C�X���a�D�����ثe SMB �s�����p)
       smbrun          (�@�� 'glue' script �Ψ�²���a�����ε{���� SMB �D��)
    _________________________________________________________________

  �A��,�@�إs 'print' �� script �Q�]��b�� HOWTO ����, ��Ψӷ�@�@�ئ���
  �� front end{�e�ݤ���} �� smbprint script��.

  Samba �n��M��O²���w�˪�.²��a�q�W�z����}���o��l�X, �B�\Ū�b�o��M
  �󤤪� README �ɮ�. �b�o��M�󤤤]���@�� docs/INSTALL.txt �ɴ��Ѥ@��²
  �檺�v�B�w�˫���.

  ���ۦw�˫�, �� daemons ��� /usr/sbin �� binaries ��� /usr/bin. ��
  man pages{��U��} �\�b /usr/local/man.

  ��A�b�� Samba �n��M��, �A�b Makefile ���|���O���պA��,smb.conf,����
  �m. �o�@��O�b /etc�U, ���i�H�⥦�\��A���w�\����N��m. ���o�ǨϥΤ�
  �k{directions}, �ڭ̱N���]�A�O���ո��ɦ�m�� /etc/smb.conf, log �ɦ�m
  �� log file = /var/log/samba-log.%m ,�� lock �ؿ��� lock directory =
  /var/lock/samba.

  �w�˲պA{configuration}��, smb.conf. �h Samba �Ҧb�����ؿ�. �ݤ@�U�b��
  �l�ؿ� example/simple �ӥBŪ�@�U README ��. �ƻs�b���ӥؿ��U��
  smb.conf �ɨ� /etc �U. �`�N! �p�G�A���@ linux �o��M��w�w�˦n Samba,
  �A�]�\�w�� Samba �պA�ɦb /etc �U. �γ\�A���ӱq����ɶ}�l.

  �p�G�A���Q��պA�ɩ�b /etc �ؿ��U,�i�H�⥦�\�b�A�Q�n�\���a��,�M��b
  /etc �U���@�U symlink{�Ÿ��s��}:
    _________________________________________________________________

       ln -s /path/to/smb.conf /etc/smb.conf
    _________________________________________________________________

4. ����o��� daemon

  �o��� daemon �O /usr/sbin/smbd �M /usr/sbin/nmbd.

  �A�i�H���� Samba daemon �q inetd �η���W���{��. �p�G�A���]�w�@�ӥä[
  �ɮצ��A��,�A���ӱq inetd �Ӱ���,�ҥH�p�G�L�̦���,���N���s�}�l.�p�G�A�u
  �O�����Q�n�ϥ� SMB ���A��,�Ϊ̥Ψt�κ޲z�ӻ��U,��A�ݭn��,�A�i�H�ǥѨ�
  �� /etc/rc.d/init.d script,�άƦܪ�����ʪ�.

  �n�q inetd �Ӱ��� daemon , �Щ�H�U�X��b inetd �պA��,
  /etc/inetd.conf:
      ______________________________________________________________

   # SAMBA NetBIOS services (for PC file and print sharing)
   netbios-ssn stream tcp nowait root /usr/sbin/smbd smbd
   netbios-ns dgram udp wait root /usr/sbin/nmbd nmbd
      ______________________________________________________________

  �M��U���O�H�K���s�Ұ� inetd daemon :
    _________________________________________________________________

   kill -HUP 1
    _________________________________________________________________

  �n�q�t�αҰʪ� script �Ӱ��� daemon, �Ч�H�U�� script �m��@�ӥs��
  /etc/rc.d/init.d/smb ��, �ӥB symbolically link ���{comments}�һ���
  ���ɮ�:
      ______________________________________________________________

   #!/bin/sh

   #
   # /etc/rc.d/init.d/smb - starts and stops SMB services.
   #
   # The following files should be synbolic links to this file:
   # symlinks: /etc/rc.d/rc1.d/K35smb  (Kills SMB services on shutdown)
   #           /etc/rc.d/rc3.d/S91smb  (Starts SMB services in multiuser mode)
   #           /etc/rc.d/rc6.d/K35smb  (Kills SMB services on reboot)
   #

   # Source function library.
   . /etc/rc.d/init.d/functions

   # Source networking configuration.
   . /etc/sysconfig/network

   # Check that networking is up.
   [ ${NETWORKING} = "no" ] && exit 0

   # See how we were called.
   case "$1" in
     start)
       echo -n "Starting SMB services: "
       daemon smbd -D
       daemon nmbd -D
       echo
       touch /var/lock/subsys/smb
       ;;
     stop)
       echo -n "Shutting down SMB services: "
       killproc smbd
       killproc nmbd
       rm -f /var/lock/subsys/smb
       echo ""
       ;;
     *)
       echo "Usage: smb {start|stop}"
       exit 1
   esac
      ______________________________________________________________

5. �@��պA�]�w (/etc/smb.conf)

  �b linux (�Ψ�L UNIX����)�W�� Samba �պA�]�w�O�Q��@�ɮ�,
  /etc/smb.conf ,�ұ���. �o��ɨM�w�A�Q�n���Өt�θ귽���ɵ��~���@�ɥH�ΧA
  �Q��L�̰����򭭨�.

  �]���H�U���`�N�|�B�z���� linux �ϺлP�L���� Windows ����, ���p�`�Үi
  �ܪ� smb.conf �ɾ��q�O�A�ү��o��²�檺, ���u�O�H���Щʬ��ت�.

  �ثe�٤��n��߲Ӹ`����. �᭱�����`�N�|���ХD�n������.

  �b�ɮפ����C���q��{section}�|���Ӭq����Y�}�l, ���Y���O [global],
  [homes], [printers] ����.

  [global] �q���w�q�@���ܼ�, �� Samba �N�Ψөw�q��Ҧ��귽������.

  [homes] �q�����\���ݨϥΪ̨Ӧs���b��a(linux)�����W���L�̪�(�B�u���L��
  ��) home directories{�a�ؿ�}. �]�N�O, �p�G�@�� Windows �ϥΪ̱q�L�̪�
  Windows �����n�]�k�s����o�Ӥ���, �L�̱N�O�s����L�̦ۤv�ӤH�� home
  directiory. �n���o�˨Ʊ�,�ҭn�`�N���O,�L�̥����blinux box�W���ӱb��.

  �H�U�� smb.conf �ɮ׼˥����\���ݨϥΪ̨ӥη�a�����W�L�̪� home
  directories �ӥB�g��@�ӼȦs���ؿ�. ��@�� Windows �ϥΪ�,�n�Q�ݨ�o��
  ����, linux box �����O�b�ϰ���{local network}��. �M��,�ϥΪ�²��a�q
  Windows File Manager �� Windows Explorer �s������Ϻ�.

  �b�H�U�q���n�`�N���O, ��o��ɤ��B�~���رN�|�ΨӤ��\��h�귽�Q����.
      ______________________________________________________________

; /etc/smb.conf
;
; Make sure and restart the server after making changes to this file, ex:
; /etc/rc.d/init.d/smb stop
; /etc/rc.d/init.d/smb start

[global]
; Uncomment this if you want a guest account
; guest account = nobody
  log file = /var/log/samba-log.%m
  lock directory = /var/lock/samba
  share modes = yes

[homes]
  comment = Home Directories
  browseable = no
  read only = no
  create mode = 0750

[tmp]
  comment = Temporary file space
  path = /tmp
  read only = no
  public = yes
      ______________________________________________________________

6. ���� Linux �Ϻе� Windows ����

  �H�W�Үi�ܪ� smb.conf �˥���, ���� linux �Ϻе� Windows �ϥΪ̬O�ܮe��
  ��. �M��, �� Samba ��L���F��, �A�i�H�����ܤj���{��. �H�U���ǨҤl :

  ���F���ɥؿ����j�a�ϥ�, �N�إ߭�����W�z [tmp] �q��, ��Y�[�J���o�Ӫ��F
  ��� smb.conf:
      ______________________________________________________________

[public]
  comment = Public Stuff
  path = /home/public
  public = yes
  writable = yes
  printable = yes
      ______________________________________________________________

  ���F�ϥH�W�ؿ��Ѥj���iŪ��,���u���s�զ���{group staff}�i�g�J,�Эק�䶵
  �ع��o��:
      ______________________________________________________________

[public]
  comment = Public Stuff
  path = /home/public
  public = yes
  writable = yes
  printable = no
  write list = @staff
      ______________________________________________________________

  ��L���ϺФ��ɪ��ޥ�,�Ь� Samba ���� man pages.

7. ���� Windows �Ϻе� Linux ����

  �@�ص� UNIX �����Ϊ� SMB client �{���Q�]�t�b Samba �o��M�󤧤�.������
  �@�ئb�R�O�C�U����ftp������.

  �Q�n�ݦb���w���D���W�����Ǥ��ɥi���o, ����:
    _________________________________________________________________

   /usr/sbin/smbclient -L host
    _________________________________________________________________

  �o�ت� 'host' �O�A�Q�n�s��������W�l. �o�N�|�^���@�� 'service' ���W��
  - �]�N�O, ���Ҥ��ɵ��A���ϺЩΦL�����W��. ���D SMB ���A���S���w���W��
  �]�w, �_�h���N�n�D�A��J�K�X. ���� 'guest' �b�����K�X�άO�A�ӤH�b���x��
  ���W�b�����K�X.

  �|�ӨҤl:
    _________________________________________________________________

   smbclient -L zimmerman
    _________________________________________________________________

  �o�ӫ��O����X���Ӭݰ_�ӹ��O�o��:
      ______________________________________________________________

Server time is Sat Aug 10 15:58:27 1996
Timezone is UTC+10.0
Password:
Domain=[WORKGROUP] OS=[Windows NT 3.51] Server=[NT LAN Manager 3.51]

Server=[ZIMMERMAN] User=[] Workgroup=[WORKGROUP] Domain=[]

       Sharename      Type      Comment
       ---------      ----      -------
       ADMIN$         Disk      Remote Admin
       public         Disk      Public
       C$             Disk      Default share
       IPC$           IPC       Remote IPC
       OReilly        Printer   OReilly
       print$         Disk      Printer Drivers


This machine has a browse list:

       Server               Comment
       ---------            -------
       HOPPER               Samba 1.9.15p8
       KERNIGAN             Samba 1.9.15p8
       LOVELACE             Samba 1.9.15p8
       RITCHIE              Samba 1.9.15p8
       ZIMMERMAN
      ______________________________________________________________

  �o�� browse list �C�X��L���귽���ɵ���� SMB ���A��.

  �n�ϥΦ� client, �а���:
    _________________________________________________________________

   /usr/sbin/smbclient service <password>
    _________________________________________________________________

  �o�ت� 'service' �O�@�x�����M���ɦW��. �|�ҦӨ�,�p�G�A�]�k�s��@�x�s��
  zimmerman �������W���H 'public' �����ɦW�٪��ؿ� ,�� service �n�s��
  \\zimmerman\public. �M��,�]�� shell ����, �A�|�ݭn��� backslashes, ��
  �H�A�n���o�˪�����:
    _________________________________________________________________

   /usr/sbin/smbclient \\\\zimmerman\\public mypasswd
    _________________________________________________________________

  �o�˪� 'mypasswd' �O�A���K�X����r��{literal string}.

  �A�N�|�� smbclient �����ܲŸ�{prompt}�X�{:
      ______________________________________________________________

Server time is Sat Aug 10 15:58:44 1996
Timezone is UTC+10.0
Domain=[WORKGROUP] OS=[Windows NT 3.51] Server=[NT LAN Manager 3.51]
smb: \>
      ______________________________________________________________

  ��J 'h' ���o���ϥ� smbclient �� help:
      ______________________________________________________________

smb: \> h
ls             dir            lcd            cd             pwd
get            mget           put            mput           rename
more           mask           del            rm             mkdir
md             rmdir          rd             prompt         recurse
translate      lowercase      print          printmode      queue
cancel         stat           quit           q              exit
newer          archive        tar            blocksize      tarmode
setmode        help           ?              !
smb: \>
      ______________________________________________________________

  �p�G�A��ϥ�ftp,�A���Ӥ��ݭn�d�� smbclient �� man pages.

8. ���� Linux �L���� Windows ����

  ���F���� Linux �L���� Windows ����, �A�����T�w�A���L���w�g�˳]�n.
  �p�G�A��q linux �W�C�L,�]�w SMB ���L�����ɱN�|�ܪ���.

  �Ш� Printing HOWTO �ӳ]�w��a���C�L.

  �]���@�̨ϥγQ�s���� Windows NT �������L��, �o�p�`�����ӳQ�����ܧ���
  ��,�ӥu�O��ij.��󦳸ԲӸ�ƥi���ɥX�Ӫ��H, �бN�o�Ǹ�ƱH��
  [7][email protected] �ϱo�o�p�`������.

  �[�J�C�L�]�w��A�� smb.conf:
      ______________________________________________________________

[global]
  printing = bsd
  printcap name = /etc/printcap
  load printers = yes
  log file = /var/log/samba-log.%m
  lock directory = /var/lock/samba

[printers]
  comment = All Printers
  security = server
  path = /var/spool/lpd/lp
  browseable = no
  printable = yes
  public = yes
  writable = no
  create mode = 0700

[ljet]
  security = server
  path = /var/spool/lpd/lp
  printer name = lp
  writable = yes
  public = yes
  printable = yes
  print command = lpr -r -h -P %p %s
      ______________________________________________________________

  �T�{�L������|(���Ҥl���O�b[ljet]�U)�n�P /etc/printcap���� spool �ؿ�
  �۲ŦX!

  �`�N: �ϥ� Samba �Ӥ��� UNIX boxes �W���L���� Windows NT �������@�ǰ�
  �D. �䤤�@�Ӱ��D�O�ϥ� NT �A��a�ݨ��ɪ��L��. �Q�n�ץ��o�Ӱ��D, ��
  �� Samba �o��M��W������, �Y docs/WinNT.txt �ɮ�.��L�O�B�z�K�X����
  �D. ���o�Z�H���D���F�ѻP���ন�\���ץ�,�ЬݬۦP���W������.

9. ���� Windows �L���� Linux ����

  ���F���� Windows �����W���L��, �A�������H�U�B�J:

  a) �A�����b /etc/printcap �����A���O��,�ӥB�L�̥����P��a�ؿ����c (��
  spool �ؿ���) �۲ŦX.

  b) �A������ script �� /usr/bin/smbprint. �o�|�H���b Samba source, ����
  �O�H����Ҧ� Samba binary �o��M��. �@�ӵy�L�ק睊���b�H�U�Q��.

  c) �p�G�A�Q�n�ഫ ASCII �ɨ� Postscript,�A������netscript,�λP�䵥��
  ��. netscipt �O�@�� Postscript �ഫ���ӥB�@��O�w�˦b /usr/bin.

  d) �A�i�H�Ʊ��ǥѦ�����ϥΪ� frond end �Ө� Samba �C�L��e��. �@�إΩ�
  �B�z ASCII, Postscript �Ϋإ� Postscript ��²�� perl script �b�U����
  �w.

  �H�U /etc/printcap ���إΦb Windows NT �D���W HP 5MP �L��. �o�Ƕ��ئp
  �U:
    _________________________________________________________________

       cm - comment
            {����}
       lp - device name to open for output
            {���F��X,�ӭn�}�Ҫ��]�ƦW��}
       sd - the printer's spool directory (on the local machine)
            {�L���� spool �ؿ� (�b��a�������W)}
       af - the accounting file
            {�b���ɮ�}
       mx - the maximum file size (zero is unlimited)
            {�̤j�ɮפj�p (�s��ܨS����)}
       if - name of the input filter (script)
            {��J�L�o���W�� (script)}
    _________________________________________________________________

  �n���o��h��T,�Ь� Printing HOWTO �Ϊ���� printcap �� man page.
      ______________________________________________________________

# /etc/printcap
#
# //zimmerman/oreilly via smbprint
#
lp:\
       :cm=HP 5MP Postscript OReilly on zimmerman:\
       :lp=/dev/lp1:\
       :sd=/var/spool/lpd/lp:\
       :af=/var/spool/lpd/lp/acct:\
       :mx#0:\
       :if=/usr/bin/smbprint:
      ______________________________________________________________

  �нT�w spool �M accounting{�b��} ���ؿ��s�b�B�i�g�J. �нT�H�Y�榳�A��
  ��|���� smbprint script (�b�U���|��) �ӥB�T�w�A���]�ƳQ���� ( /dev
  �U�Y���).

  �U�ӬO smbprint script ����. ���q�`�Q�\�b /usr/bin �ӥB�O�]�� Andrew
  Tridgell ���t�G,�ӾڧکҪ��O�L�гy�F Samba. ���H���b Samba source �o��
  �M��, ���b�Y�� binary �o��M��èS��, �ҥH�b�o�ڦA�y�@��.

  �A�i�H�Ʊ�J�Ӧa�ݳo��. ���Y�Ǹ��p���ק�w�g�ҩ����̬O�ܦ��Ϊ�.
      ______________________________________________________________

#!/bin/sh -x

# This script is an input filter for printcap printing on a unix machine. It
# uses the smbclient program to print the file to the specified smb-based
# server and service.
# For example you could have a printcap entry like this
#
# smb:lp=/dev/null:sd=/usr/spool/smb:sh:if=/usr/local/samba/smbprint
#
# which would create a unix printer called "smb" that will print via this
# script. You will need to create the spool directory /usr/spool/smb with
# appropriate permissions and ownerships for your system.

# Set these to the server and service you wish to print to
# In this example I have a WfWg PC called "lapland" that has a printer
# exported called "printer" with no password.

#
# Script further altered by [email protected] (Michael Hamilton)
# so that the server, service, and password can be read from
# a /usr/var/spool/lpd/PRINTNAME/.config file.
#
# In order for this to work the /etc/printcap entry must include an
# accounting file (af=...):
#
#   cdcolour:\
#       :cm=CD IBM Colorjet on 6th:\
#       :sd=/var/spool/lpd/cdcolour:\
#       :af=/var/spool/lpd/cdcolour/acct:\
#       :if=/usr/local/etc/smbprint:\
#       :mx=0:\
#       :lp=/dev/null:
#
# The /usr/var/spool/lpd/PRINTNAME/.config file should contain:
#   server=PC_SERVER
#   service=PR_SHARENAME
#   password="password"
#
# E.g.
#   server=PAULS_PC
#   service=CJET_371
#   password=""

#
# Debugging log file, change to /dev/null if you like.
#
logfile=/tmp/smb-print.log
# logfile=/dev/null


#
# The last parameter to the filter is the accounting file name.
#
spool_dir=/var/spool/lpd/lp
config_file=$spool_dir/.config

# Should read the following variables set in the config file:
#   server
#   service
#   password
#   user
eval `cat $config_file`

#
# Some debugging help, change the >> to > if you want to same space.
#
echo "server $server, service $service" >> $logfile

(
# NOTE You may wish to add the line `echo translate' if you want automatic
# CR/LF translation when printing.
       echo translate
       echo "print -"
       cat
) | /usr/bin/smbclient "\\\\$server\\$service" $password -U $user -N -P >> $log
file
      ______________________________________________________________

  �j���� linux �o��M��H�� nenscript ��Ψ��ഫ ASCII ���
  Postscript. �H�U perl script �g�� smbprint �ϧ�e�����Ѥ@��²�椶����
  linux ���C�L.
    _________________________________________________________________

Usage: print [-a|c|p] <filename>
      -a prints <filename> as ASCII
      -c prints <filename> formatted as source code
      -p prints <filename> as Postscript
       If no switch is given, print attempts to
       guess the file type and print appropriately.
    _________________________________________________________________

  �ϥ� smbprint �ӦC�L ASCII �ɮ׫K��I�_�L������. �p�G�i�઺��,�o��
  script �I�_�����ť��B(���N�b�r������).

  �榡�ƹL����l�X�O�Q nenscript �B�z�L. ���B�z ASCII �ɦӥB�έӯS�諸��
  �Y(�� date,filename��)�榡�Ʀ�����. ���]�i�p����. �ϥγo��@�Ҥl, ��
  �L�榡���A�i�H�F����.

  Postscript ���w�g�A��a�榡�ƤF,�ҥH���̪����q�L.
      ______________________________________________________________

#!/usr/bin/perl

# Script:   print
# Authors:  Brad Marshall, David Wood
#           Plugged In Communications
# Date:     960808
#
# Script to print to oreilly which is currently on zimmerman
# Purpose:  Takes files of various types as arguments and
# processes them appropriately for piping to a Samba print script.
#
# Currently supported file types:
#
# ASCII      - ensures that lines longer than $line_length characters wrap on
#              whitespace.
# Postscript - Takes no action.
# Code       - Formats in Postscript (using nenscript) to display
#              properly (landscape, font, etc).
#

# Set the maximum allowable length for each line of ASCII text.
$line_length = 76;

# Set the path and name of the Samba print script
$print_prog = "/usr/bin/smbprint";

# Set the path and name to nenscript (the ASCII-->Postscript converter)
$nenscript = "/usr/bin/nenscript";

unless ( -f $print_prog ) {
       die "Can't find $print_prog!";
}
unless ( -f $nenscript ) {
       die "Can't find $nenscript!";
}

&ParseCmdLine(@ARGV);

# DBG
print "filetype is $filetype\n";

if ($filetype eq "ASCII") {
       &wrap($line_length);
} elsif ($filetype eq "code") {
       &codeformat;
} elsif ($filetype eq "ps") {
       &createarray;
} else {
       print "Sorry..no known file type.\n";
       exit 0;
}
# Pipe the array to smbprint
open(PRINTER, "|$print_prog") || die "Can't open $print_prog: $!\n";
foreach $line (@newlines) {
       print PRINTER $line;
}
# Send an extra linefeed in case a file has an incomplete last line.
print PRINTER "\n";
close(PRINTER);
print "Completed\n";
exit 0;

# --------------------------------------------------- #
#        Everything below here is a subroutine        #
# --------------------------------------------------- #

sub ParseCmdLine {
       # Parses the command line, finding out what file type the file is

       # Gets $arg and $file to be the arguments (if the exists)
       # and the filename
       if ($#_ < 0) {
               &usage;
       }
       # DBG
#       foreach $element (@_) {
#               print "*$element* \n";
#       }

       $arg = shift(@_);
       if ($arg =~ /\-./) {
               $cmd = $arg;
       # DBG
#       print "\$cmd found.\n";

               $file = shift(@_);
       } else {
               $file = $arg;
       }

       # Defining the file type
       unless ($cmd) {
               # We have no arguments

               if ($file =~ /\.ps$/) {
                       $filetype = "ps";
               } elsif ($file =~ /\.java$|\.c$|\.h$|\.pl$|\.sh$|\.csh$|\.m4$|\
inc$|\.html$|\.htm$/) {
                       $filetype = "code";
               } else {
                       $filetype = "ASCII";
               }

               # Process $file for what type is it and return $filetype
       } else {
               # We have what type it is in $arg
               if ($cmd =~ /^-p$/) {
                       $filetype = "ps";
               } elsif ($cmd =~ /^-c$/) {
                       $filetype = "code";
               } elsif ($cmd =~ /^-a$/) {
                       $filetype = "ASCII"
               }
       }
}

sub usage {
       print "
Usage: print [-a|c|p] <filename>
      -a prints <filename> as ASCII
      -c prints <filename> formatted as source code
      -p prints <filename> as Postscript
       If no switch is given, print attempts to
       guess the file type and print appropriately.\n
";
       exit(0);
}

sub wrap {
       # Create an array of file lines, where each line is < the
       # number of characters specified, and wrapped only on whitespace

       # Get the number of characters to limit the line to.
       $limit = pop(@_);

       # DBG
       #print "Entering subroutine wrap\n";
       #print "The line length limit is $limit\n";

       # Read in the file, parse and put into an array.
       open(FILE, "<$file") || die "Can't open $file: $!\n";
       while(<FILE>) {
               $line = $_;

               # DBG
               #print "The line is:\n$line\n";

               # Wrap the line if it is over the limit.
               while ( length($line) > $limit ) {

                       # DBG
                       #print "Wrapping...";

                       # Get the first $limit +1 characters.
                       $part = substr($line,0,$limit +1);

                       # DBG
                       #print "The partial line is:\n$part\n";

                       # Check to see if the last character is a space.
                       $last_char = substr($part,-1, 1);
                       if ( " " eq $last_char ) {
                           # If it is, print the rest.

                           # DBG
                           #print "The last character was a space\n";

                           substr($line,0,$limit + 1) = "";
                           substr($part,-1,1) = "";
                           push(@newlines,"$part\n");
                       } else {
                            # If it is not, find the last space in the
                            # sub-line and print up to there.

                           # DBG
                           #print "The last character was not a space\n";

                            # Remove the character past $limit
                            substr($part,-1,1) = "";
                            # Reverse the line to make it easy to find
                            # the last space.
                            $revpart = reverse($part);
                            $index = index($revpart," ");
                            if ( $index > 0 ) {
                              substr($line,0,$limit-$index) = "";
                              push(@newlines,substr($part,0,$limit-$index)
                                  . "\n");
                            } else {
                              # There was no space in the line, so
                              # print it up to $limit.
                              substr($line,0,$limit) = "";
                              push(@newlines,substr($part,0,$limit)
                                  . "\n");
                            }
                       }
               }
               push(@newlines,$line);
       }
       close(FILE);
}

sub codeformat {
       # Call subroutine wrap then filter through nenscript
       &wrap($line_length);

       # Pipe the results through nenscript to create a Postscript
       # file that adheres to some decent format for printing
       # source code (landscape, Courier font, line numbers).
       # Print this to a temporary file first.
       $tmpfile = "/tmp/nenscript$$";
       open(FILE, "|$nenscript -2G -i$file -N -p$tmpfile -r") ||
               die "Can't open nenscript: $!\n";
       foreach $line (@newlines) {
               print FILE $line;
       }
       close(FILE);

       # Read the temporary file back into an array so it can be
       # passed to the Samba print script.
       @newlines = ("");
       open(FILE, "<$tmpfile") || die "Can't open $file: $!\n";
       while(<FILE>) {
               push(@newlines,$_);
       }
       close(FILE);
       system("rm $tmpfile");
}

sub createarray {
       # Create the array for postscript
       open(FILE, "<$file") || die "Can't open $file: $!\n";
       while(<FILE>) {
               push(@newlines,$_);
       }
       close(FILE);
}
      ______________________________________________________________

10. ���v

  1996 �~�� HOWTO ���v�O�ݩ� David Wood. ���i�H�Υ�󫬦����A���в��ͥH��
  �ۥѪ�����,�u�n�o��ɭ�ʤ���,�]�t�o�q�ԭz.

11. �P�E

  �u�n�A�g�H���ڴ��ѷN��, �ڱN�|�b�o(���)���U�@���P�E�A.

References

  1. mailto:[email protected]
  2. mailto:[email protected]
  3. mailto:[email protected]
  4. ftp://nimbus.anu.edu.au/pub/tridge/samba/
  5. ftp://nimbus.anu.edu.au/pub/tridge/samba/
  6. file://localhost/tmp/zh-sgmltools.16199/SMB-HOWTO.txt.html#sec-daemons
  7. mailto:[email protected]