Samba Client On Solaris 10

1. To check for the installation of Samba.

#pkginfo -x | grep -i samba

SUNWsmbac                         samba - A Windows SMB/CIFS fileserver for UNIX (client)
SUNWsmbar                         samba - A Windows SMB/CIFS fileserver for UNIX (Root)
SUNWsmbau                         samba - A Windows SMB/CIFS fileserver for UNIX (Usr)

2. To find view information for each package

#pkginfo -l SUNWsmbac

   PKGINST:  SUNWsmbac
      NAME:  samba - A Windows SMB/CIFS fileserver for UNIX (client)
  CATEGORY:  system
      ARCH:  i386
   VERSION:  11.10.0,REV=2005.01.08.01.09
   BASEDIR:  /
    VENDOR:  Sun Microsystems, Inc.
      DESC:  samba - A Windows SMB/CIFS fileserver for UNIX (client)
    PSTAMP:  sfw10-patch-x20080124060051
  INSTDATE:  Dec 12 2008 05:03
   HOTLINE:  Please contact your local service provider
    STATUS:  completely installed
     FILES:        3 installed pathnames
                   3 shared pathnames
                   3 directories

#pkginfo -l SUNWsmbar

   PKGINST:  SUNWsmbar
      NAME:  samba - A Windows SMB/CIFS fileserver for UNIX (Root)
  CATEGORY:  system
      ARCH:  i386
   VERSION:  11.10.0,REV=2005.01.08.01.09
   BASEDIR:  /
    VENDOR:  Sun Microsystems, Inc.
      DESC:  samba - A Windows SMB/CIFS fileserver for UNIX (Root)
    PSTAMP:  sfw10-patch-x20080308095610
  INSTDATE:  Dec 12 2008 04:20
   HOTLINE:  Please contact your local service provider
    STATUS:  completely installed
     FILES:       26 installed pathnames
                  15 shared pathnames
                  19 directories
                  44 blocks used (approx)

3. To view the files for each respective package

pkgchk -v SUNWsmbar

/etc
/etc/inet
/etc/inet/services
/etc/init.d
/etc/pam.conf-winbind
/etc/rc0.d
/etc/rc1.d
/etc/rc2.d
/etc/rc3.d
/etc/rcS.d
/etc/sfw
/etc/sfw/private
/etc/sfw/smb.conf-example
/var
/var/samba
/var/samba/locks
/var/samba/log
/var/spool
/var/spool/samba
/var/svc
/var/svc/manifest
/var/svc/manifest/network
/var/svc/manifest/network/samba.xml
/var/svc/manifest/network/swat.xml
/var/svc/manifest/network/winbind.xml
/var/svc/manifest/network/wins.xml

4. To check if the samba service is running

svcs -a | grep -i samba

online         May_23   svc:/network/samba:default

5. Some samba client utilities are,

smbtree - network neighborhood text utility
smbtree -b - relies upon broadcasts for resolving workgroups/hosts
smbtree -D - echoes discovered workgroups using broadcasts/master browser
smbclient - provides an FTP-like interface to SMB/CIFS servers
smbclient service_name(//HOSTNAME/Share)
smbclient //hostname/sharename
smbclient -L HOSTNAME - enumerates the shares on the server\
smbclient -A ./.smbpaswd //HOSTNAME/share
smbtar - facilitates backups of remote shares
smbtar -s hostname -x share -t share.tar - backup
smbtar -s hostname -x share -r -t share.tar - restore
smbget - used to get a remote samba shared file.

To obtain a more comprehensive list of the command line options for each utility the --help option may be used to list the available options.

#smbtree --help

Usage: [OPTION...]
  -b, --broadcast                    Use broadcast instead of using the master
                                     browser
  -D, --domains                      List only domains (workgroups) of tree
  -S, --servers                      List domains(workgroups) and servers of
                                     tree

Help options:
  -?, --help                         Show this help message
  --usage                            Display brief usage message

Common samba options:
  -d, --debuglevel=DEBUGLEVEL        Set debug level
  -s, --configfile=CONFIGFILE        Use alternate configuration file
  -l, --log-basename=LOGFILEBASE     Base name for log files
  -V, --version                      Print version

Authentication options:
  -U, --user=USERNAME                Set the network username
  -N, --no-pass                      Don't ask for a password
  -k, --kerberos                     Use kerberos (active directory)
                                     authentication
  -A, --authentication-file=FILE     Get the credentials from a file
  -S, --signing=on|off|required      Set the client signing state
  -P, --machine-pass                 Use stored machine account password

#smbget --help

Usage: smbget [OPTION...]
  -a, --guest                 Work as user guest
  -r, --resume                Automatically resume aborted files
  -R, --recursive             Recursively download files
  -u, --username=STRING       Username to use
  -p, --password=STRING       Password to use
  -w, --workgroup=STRING      Workgroup to use (optional)
  -n, --nonprompt             Don't ask anything (non-interactive)
  -d, --debuglevel=INT        Debuglevel to use
  -o, --outputfile=STRING     Write downloaded data to specified file
  -O, --stdout                Write data to stdout
  -D, --dots                  Show dots as progress indication
  -q, --quiet                 Be quiet
  -v, --verbose               Be verbose
  -P, --keep-permissions      Keep permissions
  -b, --blocksize=INT         Change number of bytes in a block
  -f, --rcfile=STRING         Use specified rc file

Help options:
  -?, --help                  Show this help message
  --usage                     Display brief usage message

#smbclient --help

#smbtar --help

/usr/sfw/bin/smbtar: illegal option -- help
Usage: smbtar [] []
Function: backup/restore a Windows PC directories to a local tape file
Options:         (Description)                 (Default)
  -r             Restore from tape file to PC  Save from PC to tapefile
  -i             Incremental mode              Full backup mode
  -a             Reset archive bit mode        Don't reset archive bit
  -v             Verbose mode: echo command    Don't echo anything
  -s    Specify PC Server
  -p  Specify PC Password
  -x     Specify PC Share              backup
  -X             Exclude mode                  Include
  -N     File for date comparison
  -bSpecify tape's blocksize
  -d

Specify a directory in share \ -lSpecify a Samba Log Level 2 -uSpecify User Name skeng -tSpecify Tape device tar.out Invalid switch specified - abort.


6. To view the available workgroups, hosts and shares on my local subnet as an anonymous user with a blank password,

#smbtree

Password:
UNIXSTORM
        \\SOLARIS                       SUN Samba Server
                \\SOLARIS\IPC$                  IPC Service (SUN Samba Server)
                \\SOLARIS\public                Linux/Scripting Tutors
        \\MAIL                          Samba Mail Server
                \\MAIL\public           Public Stuff
                \\MAIL\IPC$             IPC Service (Samba Mail Server)
        \\DEBIAN                        Dbian server
                \\DEBIAN\print$                 Printer Drivers
                \\DEBIAN\IPC$                   IPC Service (Debian server)


Where the hostnames for the share are SOLARIS,MAIL,DEBIAN. Along with each share for the respective hosts.

7. To list the share for an individual host as an anonymous user(with NO PASSWORD) the smbclient utility may be used. Also the local master browser for the subnet is displayed.

#smbclient -L SOLARIS

Password:

Anonymous login successful
Domain=[UNIXSTORM] OS=[Unix] Server=[Samba 3.0.28]

        Sharename       Type      Comment
        ---------       ----      -------
        public          Disk      Linux/Scripting Tutors
        IPC$            IPC       IPC Service (SUN Samba Server)
Anonymous login successful
Domain=[UNIXSTORM] OS=[Unix] Server=[Samba 3.0.28]

        Server               Comment
        ---------            -------
        MAIL                 Samba Mail Server
        SOLARIS              SUN Samba Server

        Workgroup            Master
        ---------            -------
        UNIXSTORM            MAIL


To list the share for an individual host an authenticated user(with NO PASSWORD) the smbclient utility may be used with the -U -L option.

#smbclient -U skeng -L SOLARIS

 

# smbclient -U skeng -L MAIL
Password:
Domain=[MAIL] OS=[Unix] Server=[Samba 3.0.23a-1.fc4.1]

        Sharename       Type      Comment
        ---------       ----      -------
        IPC$            IPC       IPC Service (Samba Mail Server)
        public          Disk      Public Stuff
        skeng          Disk      Home Directories
Domain=[MAIL] OS=[Unix] Server=[Samba 3.0.23a-1.fc4.1]

        Server               Comment
        ---------            -------

        Workgroup            Master
        ---------            -------
        UNIXSTORM            MAIL

Notice the authenticated user's Home Directories is listed. Whereas only the general shares are enurated for anonymous shares.

8. The smbclient utility provides a ftp client interface that allows ftp commands to be executed against a samba share. Most of these options are the same as the standard ftp commnads. If the samba share allows anonymous access then the smbclient followed by the host and share name may be used.
#smbclient //MAIL/public

Password:
Anonymous login successful
Domain=[UNIXSTORM] OS=[Unix] Server=[Samba 3.0.23a-1.fc4.1]
smb: \> ?
?              altname        archive        blocksize      cancel
case_sensitive cd             chmod          chown          close
del            dir            du             exit           get
getfacl        hardlink       help           history        lcd
link           lock           lowercase      ls             mask
md             mget           mkdir          more           mput
newer          open           posix          posix_open     posix_mkdir
posix_rmdir    posix_unlink   print          prompt         put
pwd            q              queue          quit           rd
recurse        reget          rename         reput          rm
rmdir          showacls       setmode        stat           symlink
tar            tarmode        translate      unlock         volume
vuid           wdel           logon          listconnect    showconnect
!
smb: \>


Notice in the samba client utility mode the prompt looks like (smb: \>). The available commands are shown by using the ? similarly to a regular ftp client.

To view the remote samba share the ls command may be used. HELP for any command may be obtained using the 'HELP command' option.

smb: \> ls
  .                                   D       0  Tue Jun  8 15:24:15 2010
  ..                                  D       0  Thu Jun 10 04:08:43 2010
  lost+found                          D       0  Sun Mar 21 12:28:08 2010
  musix.txt                                  35  Sun Mar 21 12:33:44 2010
  Speeches                            D       0  Mon Mar 22 21:00:12 2010
  SoulRnB                             D       0  Tue Mar 23 04:35:41 2010
  deb-packages                        D       0  Tue Jun  8 15:24:15 2010

                37550 blocks of size 2097152. 12521 blocks available
smb: \> help ls
HELP ls:
         list the contents of the current directory

9. Regular ftp command get, mget, put, mput etc may also be used to transfer files to and from the samba shares if the permissions settings are permissible, also when in smbclient interactive mode, prefix commands with '!' execute locally on client, otherwise the commands run on the server.
smb: \> !ls -l *.txt

-rw-r--r--   1 root     root       86100 Aug 19  2009 aide_changes.txt
-rw-------   1 root     root     5618524 Dec  9  2009 aide.db.12_09_09.txt
-rwx------   1 skeng   other      29284 Aug 23  2009 Before I messed up.txt
-rw-r--r--   1 skeng   other      36535 Aug 10  2009 cisco_router_snmp.txt
-rw-r--r--   1 skeng   other         72 Aug 23  2009 fedora4-rpo.txt
-rw-r--r--   1 root     root           0 May 22 18:08 files.txt
-rwx------   1 skeng   other       6463 Aug 20  2009 IPF-Sun10_firewall.txt
-rw-r--r--   1 skeng   other         25 Aug 15  2009 mailforskeng.txt
-rw-r--r--   1 root     root          35 Jun 10 11:03 musix.txt
-rwx------   1 skeng   other       8915 Jul 10  2009 sed_man.txt
-rw-r--r--   1 root     root           0 May 18 18:22 test_seq.txt
-rwxr--r--   1 skeng   other         27 Oct 16  2009 testing_samba_write.txt.txt


To copy the file musix.txt form the samba share to the local file system the mget command will be used.

smb: \> ls
  .                                   D       0  Tue Jun  8 15:24:15 2010
  ..                                  D       0  Thu Jun 10 04:08:43 2010
  lost+found                          D       0  Sun Mar 21 12:28:08 2010
  musix.txt                                  35  Sun Mar 21 12:33:44 2010
  Speeches                            D       0  Mon Mar 22 21:00:12 2010
  SoulRnB                             D       0  Tue Mar 23 04:35:41 2010
  deb-packages                        D       0  Tue Jun  8 15:24:15 2010

                37550 blocks of size 2097152. 12521 blocks available
smb: \> mget musix.txt
Get file musix.txt? y
getting file \musix.txt of size 35 as musix.txt (1.1 kb/s) (average 1.1 kb/s)


10. The smbget utility is used to get a file from a samba share.

#smbget -u skeng smb://MAIL/public/musix.txt

Password for public at mail:
Using workgroup UNIXSTORM, user skeng
smb://mail/public/musix.txt


11. Smbtar facilitates backups of remote shares. In the samba share public I will create a directory called deb-packages with six text files.

#touch test{1,2,3,4,5,6}.txt
# ls -l

total 0
-rw-r--r--  1 root root 0 Jun 10 11:40 test1.txt
-rw-r--r--  1 root root 0 Jun 10 11:40 test2.txt
-rw-r--r--  1 root root 0 Jun 10 11:40 test3.txt
-rw-r--r--  1 root root 0 Jun 10 11:40 test4.txt
-rw-r--r--  1 root root 0 Jun 10 11:40 test5.txt
-rw-r--r--  1 root root 0 Jun 10 11:40 test6.txt


I'll then populate each of the text files with a simple message.

#echo "testing file cpoying with smbtar" > test1.txt

The contents of the share directory deb-packages appear as.

#ls -l deb-packages

total 16
-rw-r--r--  1 root root 34 Jun 10 11:41 test1.txt
-rw-r--r--  1 root root 34 Jun 10 11:41 test2.txt
-rw-r--r--  1 root root 34 Jun 10 11:41 test3.txt
-rw-r--r--  1 root root 34 Jun 10 11:41 test4.txt
-rw-r--r--  1 root root  0 Jun 10 11:40 test5.txt
-rw-r--r--  1 root root  0 Jun 10 11:40 test6.txt


Using the smblient ftp utility the files appear as,

smb: \deb-packages\> ls
  .                                   D       0  Thu Jun 10 11:40:10 2010
  ..                                  D       0  Tue Jun  8 15:24:15 2010
  test1.txt                                  34  Thu Jun 10 11:41:33 2010
  test2.txt                                  34  Thu Jun 10 11:41:37 2010
  test3.txt                                  34  Thu Jun 10 11:41:40 2010
  test4.txt                                  34  Thu Jun 10 11:41:43 2010
  test5.txt                                   0  Thu Jun 10 11:40:10 2010
  test6.txt                                   0  Thu Jun 10 11:40:10 2010

                37550 blocks of size 2097152. 12521 blocks available
smb: \deb-packages\>


To create a tar file of the contents of the remote sambs share text file in the deb-packages directory we could use the command smbtar, the -v allows verbosity.

#smbtar -s MAIL -x public -d deb-packages -t music.tar -v

server    is MAIL
share     is public\deb-packages
tar args  is
tape      is music.tar
blocksize is
added interface eth0 ip=fe80::20d:61ff:fe53:e88b%eth0 bcast=fe80::ffff:ffff:ffff:ffff%eth0 netmask=ffff:ffff:ffff:ffff::
added interface eth0 ip=192.168.1.20 bcast=192.168.1.255 netmask=255.255.255.0
tdb(unnamed): tdb_open_ex: could not open file /var/run/samba/gencache.tdb: Permission denied
Anonymous login successful
Domain=[UNIXSTORM] OS=[Unix] Server=[Samba 3.0.23a-1.fc4.1]
tarmode is now full, system, hidden, noreset, verbose
          34 (   16.6 kb/s) \deb-packages\test1.txt
          34 (   33.2 kb/s) \deb-packages\test2.txt
          34 (   33.2 kb/s) \deb-packages\test3.txt
          34 (   33.2 kb/s) \deb-packages\test4.txt
           0 (    0.0 kb/s) \deb-packages\test5.txt
           0 (    0.0 kb/s) \deb-packages\test6.txt
tar: dumped 6 files and directories
Total bytes written: 3072


This produces a file music.tar on the local file system. The content of this can be enumerated using the tar command.

#ls -lh music.tar

-rw-r--r-- 1 skeng skeng 6.0K 2010-06-10 11:59 music.tar

#tar -tvf music.tar

-rw-r--r-- 0/0              34 2010-06-10 11:41 ./deb-packages/test1.txt
-rw-r--r-- 0/0              34 2010-06-10 11:41 ./deb-packages/test2.txt
-rw-r--r-- 0/0              34 2010-06-10 11:41 ./deb-packages/test3.txt
-rw-r--r-- 0/0              34 2010-06-10 11:41 ./deb-packages/test4.txt
-rw-r--r-- 0/0               0 2010-06-10 11:40 ./deb-packages/test5.txt
-rw-r--r-- 0/0               0 2010-06-10 11:40 ./deb-packages/test6.txt


To copy the entire public share then the command would be 

#smbtar -s MAIL -x public -d deb-packages -t music.tar