home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-05-23 | 2.1 KB | 93 lines |
- // JFSuser.java
- // A representation of one JFS user. Users are stored in the /etc/users file,
- // in the following format
- //
- // USERS = { USER '\n' }*
- //
- // USER = Name ':' Real ':' Password ':' Homedir ':' groups { ':' Group }*
- //
- import java.io.*;
- import java.util.Vector;
- import LineInputStream;
- import JFSdirectory;
- import StringSplitter;
-
- public class JFSuser
- {
- String name;
- String realname;
- String password;
- String home;
- Vector groups = new Vector();
-
- // JFSuser
- // Create a new user, read from a String
- JFSuser(String s) throws IOException
- {
- StringSplitter tok = new StringSplitter(s,':');
- if (tok.countTokens() < 5)
- throw new IOException("user format error");
- name = tok.nextToken();
- realname = tok.nextToken();
- password = tok.nextToken();
- home = tok.nextToken();
- int g = Integer.parseInt(tok.nextToken());
- for(int i=0; i<g; i++)
- groups.addElement(tok.nextToken());
- }
-
- // JFSuser
- // Create an empty JFSuser
- JFSuser()
- {
- }
-
- // output
- // Convert this user to a string
- String output()
- {
- StringJoiner j = new StringJoiner(':');
- j.add(name);
- j.add(realname);
- j.add(password);
- j.add(home);
- j.add(String.valueOf(groups.size()));
- for(int i=0; i<groups.size(); i++) {
- j.add((String)groups.elementAt(i));
- }
- return j.toString();
- }
-
- // perms
- // Returns the first set of permissions for this user (or one of this
- // user's groups) for a given file.
- String perms(JFSfile f)
- {
- if (name.equals("root"))
- return "rwp"; // root can do anything
- for(int i=0; i<f.users.size(); i++) {
- JFSfileuser u = (JFSfileuser)f.users.elementAt(i);
- if (u.name.equals(name))
- return u.rwp; // found this user
- if (u.name.equals("all"))
- return u.rwp; // every user is implicitly in all
- for(int j=0; j<groups.size(); j++)
- if (((String)groups.elementAt(j)).equals(u.name))
- return u.rwp; // found one of my groups
- }
- return "";
- }
-
- // ingroup
- // Is this user in the given group?
- boolean ingroup(String g)
- {
- if (g.equals("all")) return true;
- for(int i=0; i<groups.size(); i++)
- if (((String)groups.elementAt(i)).equals(g))
- return true;
- return false;
- }
- }
-
-