FileDocCategorySizeDatePackage
PasswdUserDatabase.javaAPI DocApache Tomcat 6.0.145241Fri Jul 20 04:20:30 BST 2007org.apache.catalina.startup

PasswdUserDatabase

public final class PasswdUserDatabase extends Object implements UserDatabase
Concrete implementation of the UserDatabase interface that processes the /etc/passwd file on a Unix system.
author
Craig R. McClanahan
version
$Revision: 467222 $ $Date: 2006-10-24 05:17:11 +0200 (mar., 24 oct. 2006) $

Fields Summary
private static final String
PASSWORD_FILE
The pathname of the Unix password file.
private Hashtable
homes
The set of home directories for all defined users, keyed by username.
private UserConfig
userConfig
The UserConfig listener with which we are associated.
Constructors Summary
public PasswdUserDatabase()
Initialize a new instance of this user database component.


        super();

    
Methods Summary
public java.lang.StringgetHome(java.lang.String user)
Return an absolute pathname to the home directory for the specified user.

param
user User for which a home directory should be retrieved


        return ((String) homes.get(user));

    
public UserConfiggetUserConfig()
Return the UserConfig listener with which we are associated.



    // ----------------------------------------------------------- Properties


                  
       

        return (this.userConfig);

    
public java.util.EnumerationgetUsers()
Return an enumeration of the usernames defined on this server.


        return (homes.keys());

    
private voidinit()
Initialize our set of users and home directories.


        BufferedReader reader = null;
        try {

            reader = new BufferedReader(new FileReader(PASSWORD_FILE));

            while (true) {

                // Accumulate the next line
                StringBuffer buffer = new StringBuffer();
                while (true) {
                    int ch = reader.read();
                    if ((ch < 0) || (ch == '\n"))
                        break;
                    buffer.append((char) ch);
                }
                String line = buffer.toString();
                if (line.length() < 1)
                    break;

                // Parse the line into constituent elements
                int n = 0;
                String tokens[] = new String[7];
                for (int i = 0; i < tokens.length; i++)
                    tokens[i] = null;
                while (n < tokens.length) {
                    String token = null;
                    int colon = line.indexOf(':");
                    if (colon >= 0) {
                        token = line.substring(0, colon);
                        line = line.substring(colon + 1);
                    } else {
                        token = line;
                        line = "";
                    }
                    tokens[n++] = token;
                }

                // Add this user and corresponding directory
                if ((tokens[0] != null) && (tokens[5] != null))
                    homes.put(tokens[0], tokens[5]);

            }

            reader.close();
            reader = null;

        } catch (Exception e) {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException f) {
                    ;
                }
                reader = null;
            }
        }

    
public voidsetUserConfig(UserConfig userConfig)
Set the UserConfig listener with which we are associated.

param
userConfig The new UserConfig listener


        this.userConfig = userConfig;
        init();