9.4 Passwords

   

Passwords are a thorny issue with Samba. So much so, in fact, that they are often the first major problem that users encounter when they install Samba. At this point, we need to delve deeper into Samba to discover what is happening on the network.

Passwords sent from individual clients can be either encrypted or nonencrypted. Encrypted passwords are, of course, more secure. A nonencrypted, plain-text password can be easily read with a packet-sniffing program, such as the modified tcpdump program for Samba that we used in Chapter 1. Whether passwords are encrypted by default depends on the operating system that the client is using to connect to the Samba server. Table 9-5 lists which Windows operating systems encrypt their passwords and which send plain-text passwords by default.

Table 9-5. Windows operating systems with encrypted passwords

Operating system

Encrypted or plain text

Windows for Workgroups

Plain text

Windows 95

Plain text

Windows 95 with SMB Update

Encrypted

Windows 98

Encrypted

Windows Me

Encrypted

Windows NT 3.x

Plain text

Windows NT 4.0 before SP 3

Plain text

Windows NT 4.0 after SP 3

Encrypted

Windows 2000

Encrypted

Windows XP

Encrypted

Three different encryption methods are used. Windows 95/98/Me clients use a method inherited from Microsoft's LAN Manager network software. Windows NT/2000/XP systems use a newer system, called NT LAN Manager, or NTLM. A newer version of this (called NT LAN Manager Version 2, or NTLMv2) uses a different method for password hashing.

If encrypted passwords are supported, Samba stores the encrypted passwords in a file called smbpasswd . By default, this file is located in the private directory of the Samba distribution (typically /usr/local/samba/private ). At the same time, the client stores an encrypted version of a user 's password on its own system. The plain-text password is never stored on either system. Each system encrypts the password automatically using a standard algorithm when the password is set or changed.

When a client requests a connection to an SMB server that supports encrypted passwords (such as Samba or Windows NT/2000/XP), the two computers undergo the following negotiations:

  1. The client attempts to negotiate a protocol with the server.

  2. The server responds with a protocol and indicates that it supports encrypted passwords. At this time, it sends back a randomly generated 8-byte challenge string.

  3. The client uses the challenge string as a key to encrypt its already encrypted password using an algorithm predefined by the negotiated protocol. It then sends the result to the server.

  4. The server does the same thing with the encrypted password stored in its database. If the results match, the passwords are equivalent, and the user is authenticated.

Note that even though the original passwords are not involved in the authentication process, you need to be very careful that the encrypted passwords located inside the smbpasswd file are guarded from unauthorized users. If they are compromised, an unauthorized user can break into the system by replaying the steps of the previous algorithm. The encrypted passwords are just as sensitive as the plain-text passwords ”this is known as plain-text-equivalent data in the cryptography world. Of course, your local security policy should require that the clients safeguard their plain-text-equivalent passwords as well.

You can configure Samba to accept encrypted passwords with the following global additions to smb.conf . Note that we explicitly name the location of the Samba password file:

 [global]     security = user     encrypt passwords = yes     smb passwd file = /usr/local/samba/private/smbpasswd 

Samba, however, will not accept any users until the smbpasswd file has been created and the users have been added to it with the smbpasswd command, as we showed you in Chapter 2.

9.4.1 Disabling Encrypted Passwords on the Client

While Unix authentication has been in use for decades ”including the use of telnet and rlogin access across the Internet ”it embodies well-known security risks. Plaintext passwords are sent over the Internet and can be retrieved from TCP packets by malicious snoopers. However, if you feel that your network is secure and you wish to use standard Unix /etc/passwd authentication for all clients, you can do so, but you must disable encrypted passwords on those Windows clients that default to using them.

To do this, you must modify the Windows registry on each client system. The Samba distribution includes the .reg files you need for this, located in the source distribution's /docs/Registry directory. Depending on the platform, you use one of the following files:

Win95_PlainPassword.reg
Win98_PlainPassword.reg
WinME_PlainPassword.reg
NT_PlainPassword.reg
Win2000_PlainPassword.reg

(For Windows XP, use the .reg file for Windows 2000.) You can perform the installation by copying the appropriate .reg file to a DOS floppy, inserting the floppy in the client's floppy drive, and running the .reg file from the Run menu item in the client's Start menu. (Or you can just double-click the file's icon.)

After you reboot the machine, the client will not encrypt its hashed passwords before sending them to the server. This means that the plain-text passwords can been seen in the TCP packets that are broadcast across the network. Again, we encourage you not to do this unless you are absolutely sure that your network is secure.

If passwords are not encrypted, use these two lines in your Samba configuration file:

 [global]     security = user     encrypt passwords = no 

9.4.2 The smbpasswd File

Samba stores its encrypted passwords in a file called smbpasswd , which by default resides in the /usr/local/samba/private directory. The smbpasswd file should be guarded as closely as the Unix system's password file (either /etc/passwd or /etc/shadow ). Only the root user should have read/write access to the private directory, and no other users should have access to it at all. In addition, the smbpasswd file should have all access denied to all users except for root. When things are set up for good security, long listings of the private directory and smbpasswd file look like the following:

 #  ls -ld /usr/local/samba/private  drwx- - - - - -   2 root   root   4096 Nov 26 01:11 /usr/local/samba/private #  ls -l /usr/local/samba/private/smbpasswd  -rw- - - - - - -   1 root   root    204 Nov 26 01:11 /usr/local/samba/private/smbpasswd 

Before you can use encrypted passwords, you need to create an entry for each Unix user in the smbpasswd file. The structure of the file is somewhat similar to a Unix passwd file, but has different fields. Figure 9-3 illustrates the layout of the smbpasswd file; the entry shown is actually one line in the file.

Figure 9-3. Structure of the smbpasswd file entry (actually one line)
figs/sam2_0903.gif

Normally, entries in the smbpasswd file are created automatically by the smbpasswd command. Still, you might like to know how to interpret data within the smbpasswd file, in case you'd like to see what accounts are stored in it or even modify it manually. Here is a breakdown of the individual fields:

Username

This is the username of the account. It is taken directly from the system password file.

UID

This is the user ID (UID) of the account. Like the username, it is taken directly from the system password file and must match the UID there.

LAN Manager Password Hash

This is a 32-bit hexadecimal sequence that represents the password Windows 95/98/Me clients will use. It is derived by splitting the password into two 7-character strings, with all lowercase letters forced into uppercase. If fewer than 14 characters are in the password, the strings are padded with nulls. Then each 7-character string is converted to a 56-bit DES key and used to encrypt the constant string KGS!@#$% . The two 64-bit results are concatenated and stored as the password hash.

If there is currently no password for the user, the first 11 characters of the hash will consist of the sequence NO PASSWORD followed by X characters for the remainder. If the password has been disabled, it will consist of 32 X characters.

NT LAN Manager (NTLM) Password Hash

This is a 32-bit hexadecimal sequence that represents the password Windows NT/2000/XP clients will use. It is derived by hashing the user's password (represented as a 16-bit little-endian Unicode sequence) with an MD4 hash. The password is not converted to uppercase letters first.

Account Flags

This field consists of 11 characters between two braces ( [ ] ). Any of the following characters can appear in any order; the remaining characters should be spaces:

U

This account is a standard user account.

D

This account is currently disabled, and Samba should not allow any logins.

N

This account has no password associated with it.

W

This is a workstation trust account that can be used to configure Samba as a PDC when allowing Windows NT machines to join its domain.

Last Change Time

This code consists of the characters LCT- followed by a hexadecimal representation of the number of seconds since the epoch (midnight on January 1, 1970) that the entry was last changed.

9.4.3 Password Synchronization

Having a regular password (either in /etc/passwd or /etc/shadow ) and an encrypted version of the same password (in the smbpasswd file) can be troublesome when you need to change both of them. Luckily, Samba affords you a limited ability to keep your passwords synchronized. Samba has a pair of configuration options to update a user's regular Unix password automatically when the encrypted password is changed on the system. The feature can be activated by specifying the unix password sync global configuration option:

 [global]     unix password sync = yes 

With this option enabled, Samba attempts to change the user's regular password (as root ) when the encrypted version is changed with smbpasswd . However, two other options have to be set correctly for this to work.

The easier of the two is passwd program . This option simply specifies the Unix command used to change a user's standard system password. It is set to /bin/passwd %u by default. With some Unix systems, this is sufficient, and you do not need to change anything. Others, such as Red Hat Linux, use /usr/bin/passwd instead. In addition, you might want to change this to another program or script at some point in the future. For example, let's assume that you want to use a script called changepass to change a user's password. Recall that you can use the variable %u to represent the current Unix username. So the example becomes:

 [global]     unix password sync = yes     passwd program = changepass %u 

Note that this program is called as the root user when the unix password sync option is set to yes . This is because Samba does not necessarily have the old plain-text password of the user.

The harder option to configure is passwd chat . The passwd chat option works like a Unix chat script. It specifies a series of strings to send, as well as responses to expect from the program specified by the passwd program option. For example, this is what the default passwd chat looks like. The delimiters are the spaces between each grouping of characters:

 passwd chat = *old*password* %o\n *new*password* %n\n *new*password* %n\n *changed* 

The first grouping represents a response expected from the password-changing program. Note that it can contain wildcards ( * ), which help to generalize the chat programs to handle a variety of similar outputs. Here, *old*password* indicates that Samba is expecting any line from the password program containing the letters old followed by the letters password , without regard for what comes before, after, or between them. If Samba does not receive the expected response, the password change will fail.

The second grouping indicates what Samba should send back once the data in the first grouping has been matched. In this case, you see %o\n . This response is actually two items: the variable %o represents the old password, while the \n is a newline character. So, in effect, this will "type" the old password into the standard input of the password-changing program, and then "press" Enter.

Following that is another response grouping, followed by data that will be sent back to the password-changing program. (In fact, this response/send pattern continues indefinitely in any standard Unix chat script.) The script continues until the final pattern is matched.

You can help match the response strings sent from the password program with the characters listed in Table 9-6. In addition, you can use the characters listed in Table 9-7 to help formulate your response.

Table 9-6. Password chat response characters

Character

Definition

*

Zero or more occurrences of any character.

" "

Allows you to include matching strings that contain spaces. Asterisks are still considered wildcards even inside of quotes, and you can represent a null response with empty quotes.

Table 9-7. Password chat send characters

Character

Definition

%o

The user's old password

%n

The user's new password

\n

The linefeed character

\r

The carriage -return character

\t

The tab character

\s

A space

For example, you might want to change your password chat to the following entry. This handles scenarios in which you do not have to enter the old password. In addition, this also handles the new all tokens updated successfully string that Red Hat Linux sends:

 passwd chat = *New password* %n\n *new password* %n\n *success* 

Again, the default chat should be sufficient for many Unix systems. If it isn't, you can use the passwd chat debug global option to set up a new chat script for the password change program. The passwd chat debug option logs everything during a password chat. This option is a simple Boolean, as shown here:

 [global]     unix password sync = yes     passwd chat debug = yes     log level = 100 

After you activate the password chat debug feature, all I/O received by Samba through the password chat can be sent to the log.smbd Samba log file with a debug level of 100, which is why we entered a new log level option as well. As this can often generate multitudes of error logs, it can be more efficient to use your own script ”by setting the passwd program option ”in place of /bin/passwd to record what happens during the exchange. Be careful because the log file contains the passwords in plain text. Keeping files containing plain-text passwords can (or should ) be against local security policy in your organization, and it also might raise serious legal issues. Make sure to protect your log files with strict file permissions and to delete them as soon as you've grabbed the information you need. If possible, use the passwd chat debug option only while your own password is being changed.

The operating system on which Samba is running might have strict requirements for valid passwords to make them more impervious to dictionary attacks and the like. Users should be made aware of these restrictions when changing their passwords.

Earlier we said that password synchronization is limited. This is because there is no reverse synchronization of the encrypted smbpasswd file when a standard Unix password is updated by a user. There are various strategies to get around this, including NIS and freely available implementations of the Pluggable Authentication Modules (PAM) standard, but none of them really solves all the problems.

More information regarding passwords can be found in the in the Samba source distribution file docs/htmldocs/ENCRYPTION.html .

9.4.4 Password Configuration Options

The options in Table 9-8 will help you work with passwords in Samba.

Table 9-8. Password configuration options

Option

Parameters

Function

Default

Scope

encrypt passwords

Boolean

If yes , enables encrypted passwords.

no

Global

unix password sync

Boolean

If yes , updates the standard Unix password database when a user changes his encrypted password.

no

Global

passwd chat

string (chat commands)

Sequence of commands sent to the password program.

See earlier section on this option

Global

passwd chat debug

Boolean

If yes , sends debug logs of the password-change process to the log files with a level of 100.

no

Global

passwd program

string (Unix command)

Program to be used to change passwords.

/bin/passwd %u

Global

password level

numeric

Number of capital-letter permutations to attempt when matching a client's password.

None

Global

update encrypted

Boolean

If yes , updates the encrypted password file when a client connects to a share with a plain-text password.

no

Global

null passwords

Boolean

If yes , allows access for users with null passwords.

no

Global

smb passwd file

string (filename)

Name of the encrypted password file.

/usr/local/samba/private/smbpasswd

Global

hosts equiv

string (filename)

Name of a file that contains hosts and users that can connect without using a password.

None

Global

use rhosts

string (filename)

Name of a . rhosts file that allows users to connect without using a password.

None

Global

9.4.4.1 encrypt passwords

The encrypt passwords global option switches Samba from using plain-text passwords to encrypted passwords for authentication. Encrypted passwords will be expected from clients if the option is set to yes :

 encrypt passwords = yes 

In Samba 2.2.x versions and with previous versions, encrypted passwords are disabled by default. This was changed in Samba 3.0 to make encrypted passwords enabled by default.

If you use encrypted passwords, you must have a valid smbpasswd file in place and populated with usernames that authenticate with encrypted passwords. (See Section 9.4.2 earlier in this chapter.) In addition, Samba must know the location of the smbpasswd file; if it is not in the default location (typically /usr/local/samba/private/smbpasswd ), you can explicitly name it using the smb passwd file option.

If you wish, you can use update encrypted to force Samba to update the smbpasswd file with encrypted passwords each time a client connects using a nonencrypted password.

If you have a mixture of clients on your network, with some of them using encrypted passwords and others using plain-text passwords, you can use the include option to make Samba treat each client appropriately. To do this, create individual configuration files based on the client name ( %m ). These host-specific configuration files can contain an encrypted passwords = yes option that activates only when those clients are connecting to the server.

9.4.4.2 unix password sync

The unix password sync global option allows Samba to update the standard Unix password file when a user changes her encrypted password. The encrypted password is stored on a Samba server in the smbpasswd file, which is located by default in /usr/local/samba/private . You can activate this feature as follows :

 [global]     unix password sync = yes 

If this option is enabled, Samba changes the encrypted password and, in addition, attempts to change the standard Unix password by passing the username and new password to the program specified by the passwd program option (described earlier). Note that Samba does not necessarily have access to the plain-text password for this user, so the password changing program must be invoked as root . [2] If the Unix password change does not succeed, for whatever reason, the SMB password is not changed either.

[2] This is because the Unix passwd program, which is the usual target for this operation, allows root to change a user's password without the security restriction that requests the old password of that user.

9.4.4.3 passwd chat

This option specifies a series of send/response strings similar to a Unix chat script, which interface with the password-changing program on the Samba server. Section 9.4.3 earlier in this chapter covers this option in detail.

9.4.4.4 passwd chat debug

If set to yes , the passwd chat debug global option logs everything sent or received by Samba during a password chat. All the I/O received by Samba through the password chat is sent to the Samba logs with a debug level of 100; you must specify log level = 100 for the information to be recorded. Section 9.4.3 earlier in this chapter describes this option in more detail. Be aware that if you do set this option, the plain-text passwords will be visible in the debugging logs, which could be a security hazard if they are not properly secured. It is against the security policy of some organizations for system administrators to have access to users' passwords.

9.4.4.5 passwd program

The passwd program option specifies a program on the Unix Samba server that Samba can use to update the standard system password file when the encrypted password file is updated. This option defaults to the standard passwd program, usually located in the /bin directory. The %u variable is typically used as the requesting user when the command is executed. The actual handling of input and output to this program during execution is handled through the passwd chat option. Section 9.4.3 earlier in this chapter covers this option in detail.

9.4.4.6 password level

With SMB, nonencrypted (or plain-text) passwords are sent with capital letters, just like the usernames mentioned previously. Many Unix users, however, choose passwords with both upper- and lowercase letters. Samba, by default, only attempts to match the password entirely in lowercase letters and not capitalizing the first letter.

Like username level , a password level option can be used to attempt various permutations of the password with capital letters. This option takes an integer value that specifies how many letters in the password should be capitalized when attempting to connect to a share. You can specify this option as follows:

 [global]     password level = 3 

In this case, Samba then attempts all permutations of the password it can compute having three capital letters. The larger the number, the more computations Samba has to perform to match the password, and the longer a connection to a specific share might take.

9.4.4.7 update encrypted

For sites switching over to the encrypted password format, Samba provides an option that should help with the transition. The update encrypted option allows a site to ease into using encrypted passwords from plain-text passwords. You can activate this option as follows:

 [global]     update encrypted = yes 

This instructs Samba to create an encrypted version of each user's Unix password in the smbpasswd file each time she connects to a share. When this option is enabled, you must have the encrypt passwords option set to no so that the client passes plain-text passwords to Samba to update the files. Once each user has connected at least once, you can set encrypted passwords = yes , allowing you to use only the encrypted passwords. The user must already have a valid entry in the smbpasswd file for this option to work.

9.4.4.8 null passwords

This global option tells Samba whether to allow access from users that have null passwords (encrypted or nonencrypted) set in their accounts. The default value is no . You can override it as follows:

 null passwords = yes 

We highly recommend against doing so because of the security risks this option can present to your system, including inadvertent access to system users (such as bin ) in the system password file who have null passwords set.

9.4.4.9 smb passwd file

This global option identifies the location of the encrypted password database. By default, it is set to /usr/local/samba/private/smbpasswd . You can override it as follows:

 [global]     smb passwd file = /etc/samba/smbpasswd 

This location, for example, is common on many Red Hat distributions on which Samba has been installed using an RPM package.

9.4.4.10 hosts equiv

This global option specifies the name of a standard Unix hosts.equiv file that allows hosts or users to access shares without specifying a password. You can specify the location of such a file as follows:

 [global]     hosts equiv = /etc/hosts.equiv 

The default value for this option does not specify any hosts.equiv file. Because using a hosts.equiv file is a huge security risk, we strongly recommend against using this option.

9.4.4.11 use rhosts

This global option specifies the name of a standard Unix user's .rhosts file that allows foreign hosts to access shares without specifying a password. You can specify the location of such a file as follows:

 [global]     use rhosts = /home/dave/.rhosts 

The default value for this option does not specify any .rhosts file. Like the hosts equiv option discussed earlier, using such a file is a security risk. We highly recommend that you do not use this option unless you are confident in the security of your network.

   


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

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