posix
Class Passwd

java.lang.Object
  extended by posix.Passwd

public class Passwd
extends Object

POSIX style access to the unix passwd file. There is no caching. This gets you the most up to date data, but if you are looking up lots of user ids, you probably want to load them into a Hashtable.

This class is implemented in Java for the standard text passwd files used by unix systems. Some unix systems replace the text format with an indexed database of some description. This improves performance when there are thousands of users, but we won't be able to take advantage of that. Such systems should still keep a text version in the usual place.


Field Summary
 String pw_dir
           
 String pw_gecos
           
 int pw_gid
           
 String pw_name
           
 String pw_passwd
           
 String pw_shell
           
 int pw_uid
           
 
Constructor Summary
Passwd()
          Access the standard passwd file.
Passwd(String path)
          Access an arbitrary passwd format file.
 
Method Summary
 void endpwent()
          Close the passwd file.
 String getPath()
           
 boolean getpwent()
          Read the next record in the passwd file.
 boolean getpwnam(String nam)
          Read the first passwd record that matches a user name.
 boolean getpwuid(int uid)
          Read the passwd record that matches a user id.
 boolean putpwent()
          Update the passwd file with the current values.
 void setpwent()
          Open and position the passwd file just before the first record.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

pw_name

public String pw_name

pw_passwd

public String pw_passwd

pw_uid

public int pw_uid

pw_gid

public int pw_gid

pw_gecos

public String pw_gecos

pw_dir

public String pw_dir

pw_shell

public String pw_shell
Constructor Detail

Passwd

public Passwd(String path)
Access an arbitrary passwd format file.


Passwd

public Passwd()
Access the standard passwd file. For unix, this is /etc/passwd.

Method Detail

getpwent

public boolean getpwent()
                 throws IOException
Read the next record in the passwd file.

Returns:
true if we found another record
Throws:
IOException

getPath

public String getPath()

setpwent

public void setpwent()
              throws IOException
Open and position the passwd file just before the first record.

Throws:
IOException

getpwuid

public boolean getpwuid(int uid)
                 throws IOException
Read the passwd record that matches a user id.

Parameters:
uid - The user id
Returns:
true if the record is found
Throws:
IOException

getpwnam

public boolean getpwnam(String nam)
                 throws IOException
Read the first passwd record that matches a user name.

Parameters:
nam - The user name
Returns:
true if the record is found
Throws:
IOException

putpwent

public boolean putpwent()
                 throws IOException
Update the passwd file with the current values. This is not yet implemented. A proper implementation requires the traditional unix text file locking mechanism (which uses a temporary output file with a well known name as the lock). Traditional locking will soon be another feature of the posix package.

Throws:
IOException

endpwent

public void endpwent()
Close the passwd file.