// AccountFactoryImpl.java // last modified 30.10.97 // Factory for normal system accounts and NIS Accounts import java.util.*; import java.io.*; import mytools.*; public class AccountFactoryImpl extends sysagent._AccountFactoryImplBase { public final String passwdFile = "/etc/passwd"; public final String ypcatCmd ="/usr/bin/ypcat "; private org.omg.CORBA.ORB orb; private org.omg.CORBA.BOA boa; private Dictionary accDic = new Hashtable(); // Hashtable for IORs public AccountFactoryImpl(String name) { super(name); orb = org.omg.CORBA.ORB.init(); boa = orb.BOA_init(); FileInputStream source = null; BufferedReader in; String line; parseLineColon plc; Runtime shell = Runtime.getRuntime(); Process process; InputStream input; BufferedReader reader; String out = new String(""); SystemAccountImpl sysaccount_ref; sysagent.SystemAccount account; NISAccountImpl nisaccount_ref; sysagent.NISAccount nisaccount; // factory for normal system accounts // reads from /etc/passwd try { source = new FileInputStream(new File(passwdFile)); in = new BufferedReader(new InputStreamReader(source)); while(true) { line = in.readLine(); if (line == null) break; plc = new parseLineColon(line); if (plc.field(1).equals("+")) continue; // login:passwd:id:gid:gecos:home:shell System.out.println("Creating account: " + plc.field(1) + "-" + plc.field(2) + "-" + plc.field(3) + "-" + plc.field(4) + "-" + plc.field(5) + "-" + plc.field(6) + "-" + plc.field(7)); // create new Account server object // tie model sysaccount_ref = new SystemAccountImpl(plc.field(1), plc.field(2), (new Long(plc.field(3))).longValue(), (new Long(plc.field(4))).longValue(), plc.field(5), plc.field(6), plc.field(7)); account = new sysagent._tie_SystemAccount(sysaccount_ref); // Make the object available to the ORB. boa.obj_is_ready(account); // Save object in dictionary accDic.put(plc.field(1), account); } } catch (IOException e) { e.printStackTrace(); } finally { if(source != null) try { source.close(); } catch (IOException e) { e.printStackTrace(); } } // factory for NISAccounts // output from ypcat passwd [...] public sysagent.Account open(String name) { // Lookup object in dictionary sysagent.Account acc = (sysagent.Account) accDic.get(name); // return the IOR return acc; } public sysagent.Account[] list() { Enumeration enumAccounts = accDic.elements(); sysagent.Account[] acclist = new sysagent.Account[accDic.size()]; int count = 0; while (enumAccounts.hasMoreElements()) { acclist[count] = (sysagent.Account) enumAccounts.nextElement(); count++; } return acclist; } public void delete(String name) { // get IOR sysagent.Account acc = (sysagent.Account) accDic.get(name); // removes object with key <name> from dictionary accDic.remove(name); System.out.println("Account " + name + " deleted."); // and deactivate transient object boa.deactivate_obj(acc); System.out.println("Deleted object with IOR: " + acc); } // public void create() // not yet implemented }