/** Idempotent. */ private void init() throws CollectException { if (!applicable) { String errmsg = JOVALMsg.getMessage(JOVALMsg.STATUS_XINETD_NOCONFIG, CONFIG); throw new CollectException(errmsg, FlagEnumeration.NOT_APPLICABLE); } else if (services != null) { return; } services = new HashMap<String, Service>(); try { IFilesystem fs = session.getFilesystem(); IFile config = fs.getFile(CONFIG, IFile.Flags.NOCACHE); if (config.exists()) { try { parseConfigFile(config); } catch (IOException e) { session.getLogger().warn(JOVALMsg.ERROR_XINETD_FILE, config.getPath(), e.getMessage()); } catch (IllegalArgumentException e) { session.getLogger().warn(JOVALMsg.ERROR_XINETD_FILE, config.getPath(), e.getMessage()); } } else { applicable = false; String errmsg = JOVALMsg.getMessage(JOVALMsg.STATUS_XINETD_NOCONFIG, CONFIG); throw new CollectException(errmsg, FlagEnumeration.NOT_APPLICABLE); } } catch (IOException e) { session.getLogger().warn(JOVALMsg.getMessage(Message.ERROR_IO, CONFIG, e.getMessage())); } }
public Collection<FilesetItem> getItems(ObjectType obj, IRequestContext rc) throws CollectException { FilesetObject fObj = (FilesetObject) obj; Collection<FilesetItem> items = new Vector<FilesetItem>(); switch (fObj.getFlstinst().getOperation()) { case EQUALS: try { String fileset = SafeCLI.checkArgument((String) fObj.getFlstinst().getValue(), session); session.getLogger().trace(JOVALMsg.STATUS_AIX_FILESET, fileset); for (String line : SafeCLI.multiLine("lslpp -lac '" + fileset + "'", session, IUnixSession.Timeout.M)) { if (!line.startsWith("#")) { List<String> info = StringTools.toList(StringTools.tokenize(line, ":")); if (info.get(0).equals("/etc/objrepos")) { FilesetItem item = Factories.sc.aix.createFilesetItem(); EntityItemStringType flstinst = Factories.sc.core.createEntityItemStringType(); flstinst.setValue(info.get(1)); item.setFlstinst(flstinst); EntityItemVersionType level = Factories.sc.core.createEntityItemVersionType(); level.setValue(info.get(2)); level.setDatatype(SimpleDatatypeEnumeration.VERSION.value()); item.setLevel(level); EntityItemFilesetStateType state = Factories.sc.aix.createEntityItemFilesetStateType(); state.setValue(info.get(4)); item.setState(state); EntityItemStringType description = Factories.sc.core.createEntityItemStringType(); description.setValue(info.get(6)); item.setDescription(description); items.add(item); } } } } catch (Exception e) { MessageType msg = Factories.common.createMessageType(); msg.setLevel(MessageLevelEnumeration.ERROR); msg.setValue(e.getMessage()); rc.addMessage(msg); session.getLogger().warn(JOVALMsg.getMessage(JOVALMsg.ERROR_EXCEPTION), e); } break; default: { String msg = JOVALMsg.getMessage( JOVALMsg.ERROR_UNSUPPORTED_OPERATION, fObj.getFlstinst().getOperation()); throw new CollectException(msg, FlagEnumeration.NOT_COLLECTED); } } return items; }
public Collection<PatchItem> getItems(ObjectType obj, IRequestContext rc) throws CollectException { if (!initialized) { scanRevisions(); } PatchObject pObj = (PatchObject) obj; Collection<PatchItem> items = new ArrayList<PatchItem>(); if (error != null) { MessageType msg = Factories.common.createMessageType(); msg.setLevel(MessageLevelEnumeration.ERROR); msg.setValue(error); rc.addMessage(msg); } try { int iBase = Integer.parseInt((String) pObj.getBase().getValue()); switch (pObj.getBase().getOperation()) { case EQUALS: items.addAll(getItems((String) pObj.getBase().getValue())); break; case NOT_EQUAL: for (String base : revisions.keySet()) { if (!base.equals((String) pObj.getBase().getValue())) { items.addAll(getItems(base)); } } break; case LESS_THAN: for (String base : revisions.keySet()) { if (Integer.parseInt(base) < iBase) { items.addAll(getItems(base)); } } break; case LESS_THAN_OR_EQUAL: for (String base : revisions.keySet()) { if (Integer.parseInt(base) <= iBase) { items.addAll(getItems(base)); } } break; case GREATER_THAN: for (String base : revisions.keySet()) { if (Integer.parseInt(base) > iBase) { items.addAll(getItems(base)); } } break; case GREATER_THAN_OR_EQUAL: for (String base : revisions.keySet()) { if (Integer.parseInt(base) >= iBase) { items.addAll(getItems(base)); } } break; case PATTERN_MATCH: Pattern p = StringTools.pattern((String) pObj.getBase().getValue()); for (String base : revisions.keySet()) { if (p.matcher(base).find()) { items.addAll(getItems(base)); } } break; default: String msg = JOVALMsg.getMessage( JOVALMsg.ERROR_UNSUPPORTED_OPERATION, pObj.getBase().getOperation()); throw new CollectException(msg, FlagEnumeration.NOT_COLLECTED); } } catch (NumberFormatException e) { MessageType msg = Factories.common.createMessageType(); msg.setLevel(MessageLevelEnumeration.ERROR); msg.setValue(e.getMessage()); rc.addMessage(msg); session.getLogger().warn(JOVALMsg.getMessage(JOVALMsg.ERROR_EXCEPTION), e); } catch (PatternSyntaxException e) { MessageType msg = Factories.common.createMessageType(); msg.setLevel(MessageLevelEnumeration.ERROR); msg.setValue(JOVALMsg.getMessage(JOVALMsg.ERROR_PATTERN, e.getMessage())); rc.addMessage(msg); session.getLogger().warn(JOVALMsg.getMessage(JOVALMsg.ERROR_EXCEPTION), e); } return items; }
/** REMIND: Stops if it encounters any exceptions at all; make this more robust? */ protected void scanRevisions() { try { for (String line : SafeCLI.multiLine("/usr/bin/showrev -p", session, IUnixSession.Timeout.M)) { if (!line.startsWith(PATCH)) { continue; } StringTokenizer tok = null; String buff = null; int begin, end; begin = line.indexOf(PATCH) + PATCH.length(); end = line.indexOf(OBSOLETES); buff = line.substring(begin, end).trim(); PatchEntry patch = new PatchEntry(buff); begin = line.indexOf(OBSOLETES) + OBSOLETES.length(); end = line.indexOf(REQUIRES); buff = line.substring(begin, end).trim(); ArrayList<PatchEntry> obsoletes = new ArrayList<PatchEntry>(); tok = new StringTokenizer(buff, ","); while (tok.hasMoreTokens()) { PatchEntry superceded = new PatchEntry(tok.nextToken().trim()); obsoletes.add(superceded); String obsoleteBase = superceded.getBaseString(); Collection<SupercedenceEntry> list = supercedence.get(obsoleteBase); if (list == null) { list = new ArrayList<SupercedenceEntry>(); supercedence.put(obsoleteBase, list); } SupercedenceEntry entry = new SupercedenceEntry(superceded, patch); if (!list.contains(entry)) { list.add(entry); } } begin = line.indexOf(REQUIRES) + REQUIRES.length(); end = line.indexOf(INCOMPATIBLES); buff = line.substring(begin, end).trim(); ArrayList<PatchEntry> requires = new ArrayList<PatchEntry>(); tok = new StringTokenizer(buff, ","); while (tok.hasMoreTokens()) { requires.add(new PatchEntry(tok.nextToken().trim())); } begin = line.indexOf(INCOMPATIBLES) + INCOMPATIBLES.length(); end = line.indexOf(PACKAGES); buff = line.substring(begin, end).trim(); ArrayList<PatchEntry> incompatibles = new ArrayList<PatchEntry>(); tok = new StringTokenizer(buff, ","); while (tok.hasMoreTokens()) { incompatibles.add(new PatchEntry(tok.nextToken().trim())); } begin = line.indexOf(PACKAGES) + PACKAGES.length(); buff = line.substring(begin).trim(); ArrayList<String> packages = new ArrayList<String>(); tok = new StringTokenizer(buff, ","); while (tok.hasMoreTokens()) { packages.add(tok.nextToken().trim()); } RevisionEntry entry = new RevisionEntry(patch, obsoletes, requires, incompatibles, packages); if (revisions.containsKey(patch.getBaseString())) { revisions.get(patch.getBaseString()).add(entry); } else { Collection<RevisionEntry> list = new ArrayList<RevisionEntry>(); list.add(entry); revisions.put(patch.getBaseString(), list); } } } catch (Exception e) { error = e.getMessage(); session.getLogger().error(JOVALMsg.getMessage(JOVALMsg.ERROR_EXCEPTION), e); } initialized = true; }
public Collection<XinetdItem> getItems(ObjectType obj, IRequestContext rc) throws CollectException { init(); Collection<XinetdItem> items = new ArrayList<XinetdItem>(); List<Service> list = new ArrayList<Service>(); XinetdObject xObj = (XinetdObject) obj; try { String protocol = (String) xObj.getProtocol().getValue(); OperationEnumeration op = xObj.getProtocol().getOperation(); Pattern p = null; if (op == OperationEnumeration.PATTERN_MATCH) { p = StringTools.pattern(protocol); } for (Service service : services.values()) { String serviceProtocol = ""; try { serviceProtocol = service.getString(Property.PROTOCOL); } catch (NoSuchElementException e) { } switch (op) { case EQUALS: if (protocol.equals(serviceProtocol)) { list.add(service); } break; case CASE_INSENSITIVE_EQUALS: if (protocol.equalsIgnoreCase(serviceProtocol)) { list.add(service); } break; case NOT_EQUAL: if (!protocol.equals(serviceProtocol)) { list.add(service); } break; case PATTERN_MATCH: if (p.matcher(serviceProtocol).find()) { list.add(service); } break; default: String msg = JOVALMsg.getMessage(JOVALMsg.ERROR_UNSUPPORTED_OPERATION, op); throw new CollectException(msg, FlagEnumeration.NOT_COLLECTED); } } String name = (String) xObj.getServiceName().getValue(); op = xObj.getServiceName().getOperation(); if (op == OperationEnumeration.PATTERN_MATCH) { p = StringTools.pattern(name); } for (Service service : list) { String serviceName = service.getName(); switch (op) { case EQUALS: if (name.equals(serviceName)) { items.add(makeItem(service)); } break; case CASE_INSENSITIVE_EQUALS: if (name.equalsIgnoreCase(serviceName)) { items.add(makeItem(service)); } break; case NOT_EQUAL: if (!name.equals(serviceName)) { items.add(makeItem(service)); } break; case PATTERN_MATCH: if (p.matcher(serviceName).find()) { items.add(makeItem(service)); } break; default: String msg = JOVALMsg.getMessage(JOVALMsg.ERROR_UNSUPPORTED_OPERATION, op); throw new CollectException(msg, FlagEnumeration.NOT_COLLECTED); } } } catch (PatternSyntaxException e) { MessageType msg = Factories.common.createMessageType(); msg.setLevel(MessageLevelEnumeration.ERROR); msg.setValue(JOVALMsg.getMessage(JOVALMsg.ERROR_PATTERN, e.getMessage())); rc.addMessage(msg); session.getLogger().warn(JOVALMsg.getMessage(JOVALMsg.ERROR_EXCEPTION), e); } return items; }
/** Parses (recursively, via include directives) the specified Xinetd configuration file. */ private void parseConfigFile(IFile config) throws IOException, IllegalArgumentException { session.getLogger().info(JOVALMsg.STATUS_XINETD_FILE, config.getPath()); BufferedReader reader = null; try { String line = null; reader = new BufferedReader(new InputStreamReader(config.getInputStream(), StringTools.ASCII)); while ((line = reader.readLine()) != null) { line = line.trim(); if (line.length() == 0 || line.startsWith("#")) { continue; } else { int ptr = line.indexOf("#"); if (ptr > 0) { line = line.substring(0, ptr); // strip any trailing comment } if (line.startsWith("defaults")) { defaults = parseConfigBlock(reader); } else if (line.startsWith("service")) { String name = line.substring(7).trim(); services.put(name, new Service(name, parseConfigBlock(reader))); } else if (line.startsWith("includefile")) { String path = line.substring(11).trim(); IFile file = session.getFilesystem().getFile(path, IFile.Flags.NOCACHE); if (file.exists() && file.isFile()) { try { parseConfigFile(file); } catch (IOException e) { session .getLogger() .warn(JOVALMsg.ERROR_XINETD_FILE, file.getPath(), e.getMessage()); } catch (IllegalArgumentException e) { session .getLogger() .warn(JOVALMsg.ERROR_XINETD_FILE, file.getPath(), e.getMessage()); } } } else if (line.startsWith("includedir")) { String path = line.substring(10).trim(); IFile dir = session.getFilesystem().getFile(path, IFile.Flags.NOCACHE); if (dir.exists() && dir.isDirectory()) { for (IFile file : dir.listFiles()) { try { parseConfigFile(file); } catch (IOException e) { session .getLogger() .warn(JOVALMsg.ERROR_XINETD_FILE, file.getPath(), e.getMessage()); } catch (IllegalArgumentException e) { session .getLogger() .warn(JOVALMsg.ERROR_XINETD_FILE, file.getPath(), e.getMessage()); } } } } } } } finally { if (reader != null) { try { reader.close(); } catch (IOException e) { } } } }