Section 11.2. FreeBSD s smbfs


11.2. FreeBSD's smbfs

FreeBSD, Darwin, and Mac OS X all provide the smbutil and mount_smbfs programs for connecting to SMB/CIFS shares. Neither of the programs is part of Samba; however, we include them to give you a little additional support in case you have BSD-related Unix systems on your network.[*]

[*] The examples in this section are based on FreeBSD 6.1.

11.2.1. smbutil

The smbutil program provides functionality similar to some of the Samba suite's command-line utilities. It can be used to list the shares available on an SMB server or perform NetBIOS name lookups.

The first argument given to smbutil is one of a number of subcommands and is usually followed by arguments specific to the subcommand. For example, to list the resources offered by a server, use the view subcommand and enter your server password when prompted:

 $ smbutil view //elm Password: <enter password> Share        Type        Comment ------------------------------------------------------------- public        disk SS2500        printer    Stylus Scan 2500 IPC$          pipe       IPC Service (Samba 3.0.22) lizard        disk       User Home Directories 4 shares listed from 4 available 

If the smbfs.ko kernel module is not loaded, you will see this error message:

 smbutil: smb_lib_init: can't find kernel module 

You can load the module manually by running the following command as root:

 $ kldload smbfs.ko netsmb_dev: loaded 


If you wish to connect to the server with a username that differs from the one you are currently logged in as, you can specify it on the command line by preceding the name of the server with the username and using an at-sign (@) as a separator:

 $ smbutil view //lizard@elm 

You can also include the password after the username, using a colon (:) as a separator, to avoid being prompted for it:

 $ smbutil view //lizard:secret@elm 

Typing your password in the open like this is strongly discouraged. An alternative is to use smbutil to generate a password hash using the crypt subcommand:

 $ smbutil crypt secret $$1625a5723293f0710e5faffcfc6 

This hash can then be used in place of a clear-text password. However, the encryption is not particularly strong and will foil only the most casual inspection. The only reasonably secure method of providing a password is to be prompted for it.

While starting up, smbutil reads the file .nsmbrc in the user's home directory. A list of common configuration parameters is summarized at the end of this section in Table 11-3.

Table 11-3. Common smbutil and mount_smbfs options

Command-line option

Configuration file parameter

Description

-I hostname

addr

Avoid NetBIOS name resolution and connect to the server using the specified DNS hostname or IP address.

-N

None

Do not prompt for a password.

-R count

retry_count

Number of times to retry connection before giving up.

-T seconds

timeout

Timeout, in seconds, per connection request.

-U username

username

Username to use for authentication. Defaults to Unix username.

-W workgroup

workgroup

Name of workgroup of remote server.

-d mode

None

Permissions to apply to directories in the mounted share. Defaults to the same as the file permissions, plus an execute (search) bit whenever the read bit is set.

-f mode

None

Permissions to apply to files in the mounted share. Defaults to the same as the permissions set on the directory used as the mount point.

-g group

None

Name or numeric gid to apply to all files and directories in the mounted share. Defaults to the group of the directory used as the mount point.

-u username

None

Username or numeric UID to apply as the owner of all files and directories in the mounted share. Defaults to the owner of the directory used as the mount point.


For example, to keep your password in your ~/.nsmbrc file, you can create an entry in the file such as the following:

 [ELM:LIZARD]     password=$$1625a5723293f0710e5faffcfc6 

The section heading in brackets specifies the SMB server's NetBIOS name and the username to which the subsequent parameter settings apply. (The hostname and username must be supplied in uppercase characters.) Section headings can also consist of just a hostname or can contain a share name as a third element for specifying parameters applicable to a single share. Finally, if a [default] section is present, the settings in it apply to all connections.

The following example .nsmbrc shows some of the other parameters you might use:

 [default]     # NetBIOS name server     nbns=192.168.1.74 [ELM]     # server IP address     addr=192.168.1.46     workgroup=TEST [ELM:LIZARD]     password=$$1625a5723293f0710e5faffcfc6 

Directives in per-user configurations can be overridden on a systemwide basis by storing directives in the file /etc/nsmb.conf. This method provides you with a means to apply mandatory settings to all users. Directives can be placed in this file using the section and parameter format similar to that of the Samba configuration file.

smbutil is somewhat of a hybrid of Samba's smbclient and nmblookup tools. The lookup subcommand returns the IP address associated with a given NetBIOS hostname. A NetBIOS name server can be optionally specified with the -w argument:

 $ smbutil lookup -w 192.168.1.74 ELM Got response from 192.168.1.74 IP address of ELM: 192.168.1.46 

11.2.2. mount_smbfs

The mount_smbfs program performs essentially the same function as mount.cifs on Linux. It mounts an SMB/CIFS share on a directory in the local filesystem. The share can then be accessed just like any other directory. The command synopsis for mount_smbfs is:

 mount_smbfs [options] Share-UNC mount-point 

where Share-UNC is of the form:

 //[workgroup;][username[:password]@]server[/share] 

For example:

 $ mount_smbfs //TEST;lizard:$$1625a5723293f0710e5faffcfc6@elm/lizard\  /smb/lizard 

A list of common configuration parameters and command-line options is provided in Table 11-3.

The ownership and permissions of the mount point determine the default ownership and permissions for files and directories in the mounted share. These can be modified with command-line arguments, like this:

 $ mount_smbfs -u lizard -g admin -f 0750 -d 0755 \   //lizard@elm/lizard /smb/lizard 

In this example, the files and directories in the mounted share are owned by the user lizard and the group admin, with files and directories having permissions 750 and 755, respectively. As usual, the permissions are specified in the octal format used by the Unix chmod command.

The mount_smbfs command also makes use of settings in /etc/nsmb.conf and ~/.nsmbrc, as described earlier.




Using Samba
Using Samba: A File and Print Server for Linux, Unix & Mac OS X, 3rd Edition
ISBN: 0596007698
EAN: 2147483647
Year: 2004
Pages: 135

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net