Autopsy  4.10.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
MultiUserCaseNodeDataCollector.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2019-2019 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.casemodule.multiusercases;
20 
21 import java.io.File;
22 import java.io.IOException;
23 import java.nio.file.LinkOption;
24 import java.nio.file.Path;
25 import java.nio.file.Paths;
26 import java.text.ParseException;
27 import java.util.ArrayList;
28 import java.util.List;
29 import java.util.logging.Level;
33 
38 final public class MultiUserCaseNodeDataCollector {
39 
40  private static final Logger logger = Logger.getLogger(MultiUserCaseNodeDataCollector.class.getName());
41  private static final String CASE_AUTO_INGEST_LOG_NAME = "AUTO_INGEST_LOG.TXT"; //NON-NLS
42  private static final String RESOURCES_LOCK_SUFFIX = "_RESOURCES"; //NON-NLS
43 
53  public static List<CaseNodeData> getNodeData() throws CoordinationService.CoordinationServiceException {
54  final List<CaseNodeData> cases = new ArrayList<>();
55  final CoordinationService coordinationService = CoordinationService.getInstance();
56  final List<String> nodeList = coordinationService.getNodeList(CoordinationService.CategoryNode.CASES);
57  for (String nodeName : nodeList) {
58  /*
59  * Ignore auto ingest case name lock nodes.
60  */
61  final Path nodeNameAsPath = Paths.get(nodeName);
62  if (!(nodeNameAsPath.toString().contains("\\") || nodeNameAsPath.toString().contains("//"))) {
63  continue;
64  }
65 
66  /*
67  * Ignore case auto ingest log lock nodes and resource lock nodes.
68  */
69  final String lastNodeNameComponent = nodeNameAsPath.getFileName().toString();
70  if (lastNodeNameComponent.equals(CASE_AUTO_INGEST_LOG_NAME)) {
71  continue;
72  }
73 
74  /*
75  * Ignore case resources lock nodes.
76  */
77  if (lastNodeNameComponent.endsWith(RESOURCES_LOCK_SUFFIX)) {
78  continue;
79  }
80 
81  /*
82  * Get the data from the case directory lock node. This data may not
83  * exist for "legacy" nodes. If it is missing, create it.
84  */
85  try {
86  CaseNodeData nodeData;
87  byte[] nodeBytes = coordinationService.getNodeData(CoordinationService.CategoryNode.CASES, nodeName);
88  if (nodeBytes != null && nodeBytes.length > 0) {
89  nodeData = new CaseNodeData(nodeBytes);
90  if (nodeData.getVersion() == 0) {
91  /*
92  * Version 0 case node data was only written if errors
93  * occurred during an auto ingest job and consisted of
94  * only the set errors flag.
95  */
96  nodeData = createNodeDataFromCaseMetadata(nodeName, true);
97  }
98  } else {
99  nodeData = createNodeDataFromCaseMetadata(nodeName, false);
100  }
101  cases.add(nodeData);
102 
103  } catch (CoordinationService.CoordinationServiceException | InterruptedException | IOException | ParseException | CaseMetadata.CaseMetadataException ex) {
104  logger.log(Level.SEVERE, String.format("Error getting coordination service node data for %s", nodeName), ex);
105  }
106 
107  }
108  return cases;
109  }
110 
133  private static CaseNodeData createNodeDataFromCaseMetadata(String nodeName, boolean errorsOccurred) throws IOException, CaseMetadata.CaseMetadataException, ParseException, CoordinationService.CoordinationServiceException, InterruptedException {
134  CaseNodeData nodeData = null;
135  Path caseDirectoryPath = Paths.get(nodeName).toRealPath(LinkOption.NOFOLLOW_LINKS);
136  File caseDirectory = caseDirectoryPath.toFile();
137  if (caseDirectory.exists()) {
138  File[] files = caseDirectory.listFiles();
139  for (File file : files) {
140  String name = file.getName().toLowerCase();
141  if (name.endsWith(CaseMetadata.getFileExtension())) {
142  CaseMetadata metadata = new CaseMetadata(Paths.get(file.getAbsolutePath()));
143  nodeData = new CaseNodeData(metadata);
144  nodeData.setErrorsOccurred(errorsOccurred);
145  break;
146  }
147  }
148  }
149  if (nodeData != null) {
150  CoordinationService coordinationService = CoordinationService.getInstance();
151  coordinationService.setNodeData(CoordinationService.CategoryNode.CASES, nodeName, nodeData.toArray());
152  return nodeData;
153  } else {
154  throw new IOException(String.format("Could not find case metadata file for %s", nodeName));
155  }
156  }
157 
162  }
163 
164 }
static CaseNodeData createNodeDataFromCaseMetadata(String nodeName, boolean errorsOccurred)
void setNodeData(CategoryNode category, String nodePath, byte[] data)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

Copyright © 2012-2018 Basis Technology. Generated on: Fri Mar 22 2019
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.