Skip to content
Snippets Groups Projects
Unverified Commit 5313b36c authored by Richard Cordovano's avatar Richard Cordovano Committed by GitHub
Browse files

Merge pull request #2265 from jayaramcs/develop

OsAccount Add attribute event bug fix
parents d5d60558 fbec6ff6
Branches
Tags
No related merge requests found
...@@ -64,6 +64,7 @@ public final class OsAccount extends AbstractContent { ...@@ -64,6 +64,7 @@ public final class OsAccount extends AbstractContent {
private boolean isDirty = false; // indicates that some member value has changed since construction and it should be updated in the database. private boolean isDirty = false; // indicates that some member value has changed since construction and it should be updated in the database.
/** /**
* Encapsulates status of an account - whether is it active or disabled or * Encapsulates status of an account - whether is it active or disabled or
* deleted. * deleted.
...@@ -371,18 +372,13 @@ void resetDirty() { ...@@ -371,18 +372,13 @@ void resetDirty() {
} }
/** /**
* Adds account attributes to the account. Attributes can be at a host-level * This function is used by OsAccountManger to update the list of
* or domain-level (for domain-scoped accounts). * OsAccount attributes.
* *
* @param osAccountAttributes List of attributes to add. * @param osAccountAttribute The osAccount Attribute that is to be added.
*
* @throws TskCoreException
*
* @throws org.sleuthkit.datamodel.TskCoreException
*/ */
public void addAttributes(List<OsAccountAttribute> osAccountAttributes) throws TskCoreException { void setAttributesInternal(List<OsAccountAttribute> osAccountAttributes) {
sleuthkitCase.getOsAccountManager().addOsAccountAttributes(this, osAccountAttributes); this.osAccountAttributes = osAccountAttributes;
osAccountAttributes.addAll(osAccountAttributes);
} }
/** /**
...@@ -485,7 +481,7 @@ public OsAccountDbStatus getOsAccountDbStatus() { ...@@ -485,7 +481,7 @@ public OsAccountDbStatus getOsAccountDbStatus() {
* *
* @throws TskCoreException * @throws TskCoreException
*/ */
public List<OsAccountAttribute> getOsAccountAttributes() throws TskCoreException { public synchronized List<OsAccountAttribute> getOsAccountAttributes() throws TskCoreException {
if (osAccountAttributes == null) { if (osAccountAttributes == null) {
osAccountAttributes = sleuthkitCase.getOsAccountManager().getOsAccountAttributes(this); osAccountAttributes = sleuthkitCase.getOsAccountManager().getOsAccountAttributes(this);
} }
......
...@@ -964,74 +964,77 @@ public Optional<OsAccount> getWindowsOsAccount(String sid, String loginName, Str ...@@ -964,74 +964,77 @@ public Optional<OsAccount> getWindowsOsAccount(String sid, String loginName, Str
* *
* @throws TskCoreException, * @throws TskCoreException,
*/ */
void addOsAccountAttributes(OsAccount account, List<OsAccountAttribute> accountAttributes) throws TskCoreException { public void addOsAccountAttributes(OsAccount account, List<OsAccountAttribute> accountAttributes) throws TskCoreException {
synchronized (account) { // synchronized to prevent multiple threads trying to add osAccount attributes concurrently to the same osAccount.
db.acquireSingleUserCaseWriteLock();
db.acquireSingleUserCaseWriteLock(); try (CaseDbConnection connection = db.getConnection()) {
for (OsAccountAttribute accountAttribute : accountAttributes) {
try (CaseDbConnection connection = db.getConnection()) { String attributeInsertSQL = "INSERT INTO tsk_os_account_attributes(os_account_obj_id, host_id, source_obj_id, attribute_type_id, value_type, value_byte, value_text, value_int32, value_int64, value_double)"
for (OsAccountAttribute accountAttribute : accountAttributes) { + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; // NON-NLS
String attributeInsertSQL = "INSERT INTO tsk_os_account_attributes(os_account_obj_id, host_id, source_obj_id, attribute_type_id, value_type, value_byte, value_text, value_int32, value_int64, value_double)" PreparedStatement preparedStatement = connection.getPreparedStatement(attributeInsertSQL, Statement.RETURN_GENERATED_KEYS);
+ " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; // NON-NLS preparedStatement.clearParameters();
PreparedStatement preparedStatement = connection.getPreparedStatement(attributeInsertSQL, Statement.RETURN_GENERATED_KEYS); preparedStatement.setLong(1, account.getId());
preparedStatement.clearParameters(); if (accountAttribute.getHostId().isPresent()) {
preparedStatement.setLong(2, accountAttribute.getHostId().get());
} else {
preparedStatement.setNull(2, java.sql.Types.NULL);
}
if (accountAttribute.getSourceObjectId().isPresent()) {
preparedStatement.setLong(3, accountAttribute.getSourceObjectId().get());
} else {
preparedStatement.setNull(3, java.sql.Types.NULL);
}
preparedStatement.setLong(1, account.getId()); preparedStatement.setLong(4, accountAttribute.getAttributeType().getTypeID());
if (accountAttribute.getHostId().isPresent()) { preparedStatement.setLong(5, accountAttribute.getAttributeType().getValueType().getType());
preparedStatement.setLong(2, accountAttribute.getHostId().get());
} else {
preparedStatement.setNull(2, java.sql.Types.NULL);
}
if (accountAttribute.getSourceObjectId().isPresent()) {
preparedStatement.setLong(3, accountAttribute.getSourceObjectId().get());
} else {
preparedStatement.setNull(3, java.sql.Types.NULL);
}
preparedStatement.setLong(4, accountAttribute.getAttributeType().getTypeID()); if (accountAttribute.getAttributeType().getValueType() == TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.BYTE) {
preparedStatement.setLong(5, accountAttribute.getAttributeType().getValueType().getType()); preparedStatement.setBytes(6, accountAttribute.getValueBytes());
} else {
preparedStatement.setBytes(6, null);
}
if (accountAttribute.getAttributeType().getValueType() == TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.BYTE) { if (accountAttribute.getAttributeType().getValueType() == TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.STRING
preparedStatement.setBytes(6, accountAttribute.getValueBytes()); || accountAttribute.getAttributeType().getValueType() == TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.JSON) {
} else { preparedStatement.setString(7, accountAttribute.getValueString());
preparedStatement.setBytes(6, null); } else {
} preparedStatement.setString(7, null);
}
if (accountAttribute.getAttributeType().getValueType() == TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.INTEGER) {
preparedStatement.setInt(8, accountAttribute.getValueInt());
} else {
preparedStatement.setNull(8, java.sql.Types.NULL);
}
if (accountAttribute.getAttributeType().getValueType() == TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.STRING if (accountAttribute.getAttributeType().getValueType() == TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.DATETIME
|| accountAttribute.getAttributeType().getValueType() == TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.JSON) { || accountAttribute.getAttributeType().getValueType() == TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.LONG) {
preparedStatement.setString(7, accountAttribute.getValueString()); preparedStatement.setLong(9, accountAttribute.getValueLong());
} else { } else {
preparedStatement.setString(7, null); preparedStatement.setNull(9, java.sql.Types.NULL);
} }
if (accountAttribute.getAttributeType().getValueType() == TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.INTEGER) {
preparedStatement.setInt(8, accountAttribute.getValueInt());
} else {
preparedStatement.setNull(8, java.sql.Types.NULL);
}
if (accountAttribute.getAttributeType().getValueType() == TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.DATETIME if (accountAttribute.getAttributeType().getValueType() == TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.DOUBLE) {
|| accountAttribute.getAttributeType().getValueType() == TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.LONG) { preparedStatement.setDouble(10, accountAttribute.getValueDouble());
preparedStatement.setLong(9, accountAttribute.getValueLong()); } else {
} else { preparedStatement.setNull(10, java.sql.Types.NULL);
preparedStatement.setNull(9, java.sql.Types.NULL); }
}
if (accountAttribute.getAttributeType().getValueType() == TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.DOUBLE) { connection.executeUpdate(preparedStatement);
preparedStatement.setDouble(10, accountAttribute.getValueDouble());
} else {
preparedStatement.setNull(10, java.sql.Types.NULL);
} }
} catch (SQLException ex) {
connection.executeUpdate(preparedStatement); throw new TskCoreException(String.format("Error adding OS Account attribute for account id = %d", account.getId()), ex);
} finally {
db.releaseSingleUserCaseWriteLock();
} }
} catch (SQLException ex) { List<OsAccountAttribute> currentAttribsList = getOsAccountAttributes(account);
throw new TskCoreException(String.format("Error adding OS Account attribute for account id = %d", account.getId()), ex); currentAttribsList.addAll(accountAttributes);
} finally { account.setAttributesInternal(currentAttribsList);
db.releaseSingleUserCaseWriteLock();
} }
fireChangeEvent(account); fireChangeEvent(account);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment