smb.confの設定とログ、CUP-PDFの導入まで

■Wheezyのsamba3のログで最初に気になるのはCUPSのとの接続エラーだと思います。
 「cups-pdfを入れると良いですよ。」に至るまでのちょっと長い話。
 pdbeditの話は置いといて。。。

$ sudo smbpasswd -a labunix && sudo smbpasswd -e labunix
New SMB password:
Retype new SMB password:
Enabled user labunix.

■nmbdは137/udp、138/udp、139/tcp、445/tcpはsmbd、901/tcpはSWAT。

$ sudo netstat -an --program | grep "\:13[789]\|\:445\|\:901"
tcp        0      0 0.0.0.0:445             0.0.0.0:*               LISTEN      2154/inetd 
tcp        0      0 0.0.0.0:901             0.0.0.0:*               LISTEN      2154/inetd 
tcp        0      0 0.0.0.0:139             0.0.0.0:*               LISTEN      2154/inetd 
tcp6       0      0 :::445                  :::*                    LISTEN      2384/smbd  
tcp6       0      0 :::139                  :::*                    LISTEN      2384/smbd  
udp        0      0 192.168.1.255:137       0.0.0.0:*                           2364/nmbd  
udp        0      0 192.168.1.10:137        0.0.0.0:*                           2364/nmbd  
udp        0      0 0.0.0.0:137             0.0.0.0:*                           2364/nmbd  
udp        0      0 192.168.1.255:138       0.0.0.0:*                           2364/nmbd  
udp        0      0 192.168.1.10:138        0.0.0.0:*                           2364/nmbd  
udp        0      0 0.0.0.0:138             0.0.0.0:*                           2364/nmbd  

■inetd経由のポートは以下で再確認出来る。

$ awk '($1>"^#"){print $1}' /etc/inetd.conf | \
  for list in `xargs`;do \
    grep "$list" /etc/services | \
  grep tcp;done
netbios-ssn     139/tcp                         # NETBIOS session service
microsoft-ds    445/tcp                         # Microsoft Naked CIFS
swat            901/tcp                         # swat

■「smb ports」はデフォルトを利用していて、
 デフォルトは、445,139の両方を使用する。

$ sudo testparm -s 2>&1 | grep "smb ports"
$ sudo testparm -s -v 2>&1 | grep "smb ports"
        smb ports = 445 139

■私の場合、NBTは即座に無効にしますが、
 マスタブラウザの確認等をする予定なので、今回はスルーします。

$ sudo cp -p /etc/samba/smb.conf /etc/samba/smb.conf.test
$ diff /etc/samba/smb.conf /etc/samba/smb.conf.test
63a64
> interfaces = 192.168.1.0/24 eth0
70a72,73
> bind interfaces only = yes
> smb ports = 445

$ sudo testparm -s /etc/samba/smb.conf.test 2>&1 | grep "interfaces\|smb ports"
        interfaces = 192.168.1.0/24, eth0
        bind interfaces only = Yes
        smb ports = 445

■ログの設定
 syslogには出さずに、「/var/log/samba/log.マシン名」に1000KBまで出力。
 時刻は通常「debug timestamp」で充分、
 「debug uid」「ldap debug level」は変えても良い。

$ sudo testparm -s 2>&1 | grep "log \|debug"
        syslog = 0
        log file = /var/log/samba/log.%m
        max log size = 1000

$ sudo testparm -s -v 2>&1 | grep "log \|debug"
        passwd chat debug = No
        log level = 2
        syslog = 0
        syslog only = No
        log file = /var/log/samba/log.%m
        max log size = 1000
        debug timestamp = Yes
        debug prefix timestamp = No
        debug hires timestamp = Yes
        debug pid = No
        debug uid = No
        debug class = No
        log writeable files on exit = No
        ldap debug level = 0
        ldap debug threshold = 10
        eventlog list =
        log nt token command =

■「max log size」を超えると、「.old」になる。
 満たなければ普通に週単位でローテーションされる。

$ man smb.conf | grep -A 5 "max log size (G)"
       max log size (G)

           This option (an integer in kilobytes) specifies the max size the log file
           should grow to. Samba periodically checks the size and if it is exceeded it
           will rename the file, adding a .old extension.

$ ls -lk /var/log/samba/log.smbd.*
-rw-r--r-- 1 root root 1 2013-04-21 07:35 /var/log/samba/log.smbd.1.gz
-rw-r--r-- 1 root root 1 2013-04-14 07:35 /var/log/samba/log.smbd.2.gz
-rw-r--r-- 1 root root 1 2013-04-09 21:08 /var/log/samba/log.smbd.3.gz
-rw-r--r-- 1 root root 1 2013-03-31 07:35 /var/log/samba/log.smbd.4.gz
-rw-r--r-- 1 root root 1 2013-03-24 07:35 /var/log/samba/log.smbd.5.gz
-rw-r--r-- 1 root root 1 2013-03-20 00:33 /var/log/samba/log.smbd.6.gz
-rw-r--r-- 1 root root 1 2013-03-13 21:53 /var/log/samba/log.smbd.7.gz

■ログサイズを考えるなら、以下のような細かいログレベルの設定も可能。

$ man smb.conf | grep -A 52 "log level (G)" | grep -v "^\$"
       log level (G)
           The value of the parameter (a astring) allows the debug level (logging level)
           to be specified in the smb.conf file.
           This parameter has been extended since the 2.2.x series, now it allows to
           specify the debug level for multiple debug classes. This is to give greater
           flexibility in the configuration of the system. The following debug classes
           are currently implemented:
           ·   all
           ·   tdb
           ·   printdrivers
           ·   lanman
           ·   smb
           ·   rpc_parse
           ·   rpc_srv
           ·   rpc_cli
           ·   passdb
           ·   sam
           ·   auth
           ·   winbind
           ·   vfs
           ·   idmap
           ·   quota
           ·   acls
           ·   locking
           ·   msdfs
           ·   dmapi
           ·   registry
       Default: log level = 0
       Example: log level = 3 passdb:5 auth:10 winbind:2

■デフォルトのままだとCUPSサービスに接続できないというエラーが出る。

$ smbclient -L //lpic3
Enter labunix’s password:
Domain=[WORKGROUP] OS=[Unix] Server=[Samba 3.6.6]

        Sharename       Type      Comment
        ---------       ----      -------
        print$          Disk      Printer Drivers
        IPC$            IPC       IPC Service (lpic3 server)
Domain=[WORKGROUP] OS=[Unix] Server=[Samba 3.6.6]

        Server               Comment
        ---------            -------
        LPIC3                lpic3 server

        Workgroup            Master
        ---------            -------
        WORKGROUP            LPIC3

$ sudo tail -f /var/log/samba/log.smbd
[2013/05/03 00:06:03,  0] smbd/server.c:1053(main)
  smbd version 3.6.6 started.
  Copyright Andrew Tridgell and the Samba Team 1992-2011
[2013/05/03 00:06:03.673045,  0] printing/print_cups.c:110(cups_connect)
  Unable to connect to CUPS server localhost:631 - Connection refused

■一時的なdebugレベルの変更
 デバッグレベルを変えてもCUPSのエラーは変わりません。

$ sudo smbcontrol smbd debug 10
[2013/05/03 00:07:47.585767,  5] ../lib/util/debug.c:330(debug_dump_status)
  INFO: Current debug levels:
    all: 10
    tdb: 10
    printdrivers: 10
    lanman: 10
    smb: 10
    rpc_parse: 10
    rpc_srv: 10
    rpc_cli: 10
    passdb: 10
    sam: 10
    auth: 10
    winbind: 10
    vfs: 10
    idmap: 10
    quota: 10
    acls: 10
    locking: 10
    msdfs: 10
    dmapi: 10
    registry: 10
[2013/05/03 00:07:47.586354, 10] lib/messages_local.c:255(messaging_tdb_store)
  messaging_tdb_store:
...

■デフォルトの設定の確認

$ sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.org
$ testparm -s 2>&1 | grep "load printers\|spool"
        path = /var/spool/samba

$ ls -l /var/spool/samba/
合計 0

$ testparm -s -v 2>&1 | grep "load printers\|spool"
        load printers = Yes
        disable spoolss = No
        path = /var/spool/samba

■仮想プリンタを導入する。

$ apt-cache search cups-pdf
cups-pdf - CUPS 用 PDF 出力バックエンド

$ sudo apt-get install -y cups-pdf
$ netstat -an | grep "\:631"
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN
tcp6       0      0 ::1:631                 :::*                    LISTEN
udp        0      0 0.0.0.0:631             0.0.0.0:*

■仮想プリンタの導入確認。
 上部のプリンタを選択する。

$ w3m -dump http://localhost:631 | head -1
[left]   ホーム     管理     クラス     ヘルプ     ジョブ    プリンター  [                    ] ●

■以下のような表示を確認。

                          1 台のプリンターのうち 1 台を表示中。

▼キュー名▼ 説明 場所     メーカーとモデル     状態
PDF        PDF       Generic CUPS-PDF Printer 待機

■「PDF」リンクを選択すると、「Generic CUPS-PDF Printer」ドライバであることが分かる。

PDF (待機中, ジョブを受け付け中, 非共有, デフォルトプリンター)

[メンテナンス              ] [Go] [管理                      ] [Go]

              説明: PDF
              場所:
 プリンタードライバ Generic CUPS-PDF Printer (カラー, 両面可)
                ー:
            接続先: cups-pdf:/
    デフォルト設定: バナー=none, none 用紙サイズ=iso_a4_210x297mm 両面指定=
                    one-sided

■cups-pdfによるPDF出力の保存場所はユーザのホームディレクトリ配下。

$ grep ^Out /etc/cups/cups-pdf.conf
Out ${HOME}/PDF

■対処1)プリンタ機能を無効にする。
 明示的にプリンタを無効にすることは出来るが、エラーログが載るのは変わらない。

 ※仮想プリンタを導入した上で行うと「smbd_open_once_socket」のエラーに変わる。
  仮想プリンタを導入しなければ「Unable to connect to CUPS server」のエラーは変わらない。

$ diff /etc/samba/smb.conf /etc/samba/smb.conf.org
183,184d182
< load printers = no
< disable spoolss = yes

$ testparm -s 2>&1 | grep "load printers\|spool"
        load printers = No
        disable spoolss = Yes
        path = /var/spool/samba

$ sudo /etc/init.d/samba restart

$ sudo tail -f /var/log/samba/log.smbd
[2013/05/03 00:31:22,  0] smbd/server.c:1053(main)
  smbd version 3.6.6 started.
  Copyright Andrew Tridgell and the Samba Team 1992-2011
[2013/05/03 00:31:22.034032,  0] smbd/server.c:578(smbd_open_one_socket)
  smbd_open_once_socket: open_socket_in: アドレスは既に使用中です

■対処2)プリンタ無効の設定を元に戻すと、PDFプリンタが認識されていることが確認できる。
 ログにはCUPS関連のエラーは出なくなる。

$ testparm -s -v 2>&1 | grep "load printers\|spool"
        load printers = Yes
        disable spoolss = No
        path = /var/spool/samba

$ testparm -s -v 2>&1 | grep printing
        printing = cups

$ sudo smbcontrol smbd reload-config

$ smbclient -L //lpic3
Enter labunix’s password:
Domain=[WORKGROUP] OS=[Unix] Server=[Samba 3.6.6]

        Sharename       Type      Comment
        ---------       ----      -------
        print$          Disk      Printer Drivers
        IPC$            IPC       IPC Service (lpic3 server)
        PDF             Printer   PDF
Domain=[WORKGROUP] OS=[Unix] Server=[Samba 3.6.6]

        Server               Comment
        ---------            -------
        LPIC3                lpic3 server

        Workgroup            Master
        ---------            -------
        WORKGROUP            LPIC3

$ sudo tail -f /var/log/samba/log.smbd
[2013/05/03 00:40:25,  0] smbd/server.c:1053(main)
  smbd version 3.6.6 started.
  Copyright Andrew Tridgell and the Samba Team 1992-2011

■Windows側ドライバ(HP Desk Jet 1200C/PS)を導入。

 LinuxパソコンをPDF作成用マシンに 2ページ
 http://sourceforge.jp/magazine/07/05/11/0038239/2

■Windowsの表示上、「アクセス拒否 - 接続できません」と出る対処について。

$ testparm -s -v 2>&1 | grep "use client driver"
        use client driver = No

$ man smb.conf | grep -A 10 "use client driver ("
       use client driver (S)

           This parameter applies only to Windows NT/2000 clients. It has no
           effect on Windows 95/98/ME clients. When serving a printer to
           Windows NT/2000 clients without first installing a valid printer
           driver on the Samba host, the client will be required to install a
           local printer driver. From this point on, the client will treat the
           print as a local printer and not a network printer connection. This
           is much the same behavior that will occur when disable spoolss =
           yes.

■「アクセス拒否 - 接続できません」は印刷には支障は無いが、
 「print$」の方ではなく、新たにプリンタ共有を定義して、
 そこに「use client driver = Yes」の設定が必要。

$ testparm -s 2>&1 | grep -A 3 "^\[print\\$\]"
[print$]
        comment = Printer Drivers
        path = /var/lib/samba/printers
        write list = labunix

$ testparm -s 2>&1 | grep -A 3 "^\[pdf\]"
[pdf]
        path = /var/spool/samba
        printable = Yes
        use client driver = Yes

■印刷テスト
 印刷したログはクライアントホストのログに出る。

$ sudo tail -f /var/log/samba/log.dummyhost
[2013/05/03 01:13:33.239789,  1] smbd/service.c:1070(make_connection_snum)
  dummyhost (192.168.1.2) connect to service PDF initially as user labunix (uid=1000, gid=1000) (pid 22779)