uint32 indexOffset = mTableSection.at(indexSectionOffset + (i + 2) * AtomSize);
ReadSection indexSection(mTableSection.subsection(indexOffset));
- auto_ptr<DbConstIndex> index(new DbConstIndex(*this, indexSection));
+ unique_ptr<DbConstIndex> index(new DbConstIndex(*this, indexSection));
mIndexMap.insert(ConstIndexMap::value_type(index->indexId(), index.get()));
index.release();
}
{
modifyTable();
- auto_ptr<WriteSection> aWriteSection(new WriteSection());
+ unique_ptr<WriteSection> aWriteSection(new WriteSection());
getMetaRecord().packRecord(*aWriteSection, inAttributes, inData);
uint32 aRecordNumber = nextRecordNumber();
#endif
// Update the actual packed record.
- auto_ptr<WriteSection> aDbRecord(new WriteSection());
+ unique_ptr<WriteSection> aDbRecord(new WriteSection());
getMetaRecord().updateRecord(anOldDbRecord, *aDbRecord,
CssmDbRecordAttributeData::overlay(inAttributes), inData, inModifyMode);
Table::ConstIndexMap::const_iterator it;
for (it = mTable->mIndexMap.begin(); it != mTable->mIndexMap.end(); it++) {
- auto_ptr<DbMutableIndex> mutableIndex(new DbMutableIndex(*it->second));
+ unique_ptr<DbMutableIndex> mutableIndex(new DbMutableIndex(*it->second));
mIndexMap.insert(MutableIndexMap::value_type(it->first, mutableIndex.get()));
mutableIndex.release();
}
if (it == mIndexMap.end()) {
// create the new index
- auto_ptr<DbMutableIndex> index(new DbMutableIndex(metaRecord, indexId, isUniqueIndex));
+ unique_ptr<DbMutableIndex> index(new DbMutableIndex(metaRecord, indexId, isUniqueIndex));
it = mIndexMap.insert(MutableIndexMap::value_type(indexId, index.get())).first;
index.release();
}
// XXX Set the size boundary on aTableSection.
const ReadSection aTableSection =
aSchemaSection.subsection(aTableOffset);
- auto_ptr<Table> aTable(new Table(aTableSection));
+ unique_ptr<Table> aTable(new Table(aTableSection));
Table::Id aTableId = aTable->getMetaRecord().dataRecordType();
mTableMap.insert(TableMap::value_type(aTableId, aTable.get()));
aTable.release();
uint32 anAttributeId = aRecordData[1];
uint32 anAttributeNameFormat = aRecordData[2];
uint32 anAttributeFormat = aRecordData[5];
- auto_ptr<string> aName;
+ unique_ptr<string> aName;
const CssmData *aNameID = NULL;
if (aRecordData[3].size() == 1)
if (aRecordData[3].format() != CSSM_DB_ATTRIBUTE_FORMAT_STRING)
CssmError::throwMe(CSSMERR_DL_DATABASE_CORRUPT);
- auto_ptr<string> aName2(new string(static_cast<string>(aRecordData[3])));
- aName = aName2;
+ unique_ptr<string> aName2(new string(static_cast<string>(aRecordData[3])));
+ aName = std::move(aName2);
}
if (aRecordData[4].size() == 1)
IndexCursor::~IndexCursor()
{
- // the query key will be deleted automatically, since it's an auto_ptr
+ // the query key will be deleted automatically, since it's an unique_ptr
}
bool
mDbVersion->mTableMap.end();
for (; anIt != anEnd; ++anIt)
{
- auto_ptr<ModifiedTable> aTable(new ModifiedTable(anIt->second));
+ unique_ptr<ModifiedTable> aTable(new ModifiedTable(anIt->second));
mModifiedTableMap.insert(ModifiedTableMap::value_type(anIt->first,
aTable.get()));
aTable.release();
ModifiedTable *
DbModifier::createTable(MetaRecord *inMetaRecord)
{
- auto_ptr<MetaRecord> aMetaRecord(inMetaRecord);
- auto_ptr<ModifiedTable> aModifiedTable(new ModifiedTable(inMetaRecord));
+ unique_ptr<MetaRecord> aMetaRecord(inMetaRecord);
+ unique_ptr<ModifiedTable> aModifiedTable(new ModifiedTable(inMetaRecord));
// Now that aModifiedTable is fully constructed it owns inMetaRecord
aMetaRecord.release();
return;
try
{
- secdebugfunc("integrity", "committing to %s", mAtomicFile.path().c_str());
+ secinfo("integrity", "committing to %s", mAtomicFile.path().c_str());
WriteSection aHeaderSection(Allocator::standard(), size_t(HeaderSize));
// Set aHeaderSection to the correct size.
}
void
-DbModifier::rollback() throw()
+DbModifier::rollback() _NOEXCEPT
{
// This will destroy the AtomicTempFile if we have one causing it to rollback.
mAtomicTempFile = NULL;
{
try
{
- // syslog if it's the .Mac password
- CSSM_DB_RECORD_ATTRIBUTE_DATA attrData;
- // we have to do this in two phases -- the first to get the record type, and the second to actually read the attributes. Otherwise, we might get
- // an exception.
- memset(&attrData, 0, sizeof(attrData));
- dataGetFromUniqueRecordId(inDbContext, inUniqueRecord, &attrData, NULL);
-
- if (attrData.DataRecordType == CSSM_DL_DB_RECORD_GENERIC_PASSWORD)
- {
- CSSM_DB_ATTRIBUTE_DATA attributes;
-
- // setup some attributes and see if we are indeed the .Mac password
- attributes.Info.AttributeNameFormat = CSSM_DB_ATTRIBUTE_NAME_AS_INTEGER;
- attributes.Info.Label.AttributeID = 'svce';
- attributes.Info.AttributeFormat = 0;
- attributes.NumberOfValues = 1;
- attributes.Value = NULL;
-
- attrData.NumberOfAttributes = 1;
- attrData.AttributeData = &attributes;
-
- dataGetFromUniqueRecordId(inDbContext, inUniqueRecord, &attrData, NULL);
-
- // now check the results
- std::string dataString((const char*) attrData.AttributeData[0].Value[0].Data, attrData.AttributeData[0].Value[0].Length);
- if (dataString == "iTools")
- {
- syslog(LOG_WARNING, "Warning: Removed .Me password");
- }
-
- free(attrData.AttributeData[0].Value[0].Data);
- free(attrData.AttributeData[0].Value);
- }
-
StLock<Mutex> _(mWriteLock);
Table::Id aTableId;
const RecordId aRecordId(parseUniqueRecord(inUniqueRecord, aTableId));
{
// XXX: register Cursor with DbContext and have DbContext call
// dataAbortQuery for all outstanding Query objects on close.
- auto_ptr<Cursor> aCursor(mDbModifier.createCursor(inQuery));
+ unique_ptr<Cursor> aCursor(mDbModifier.createCursor(inQuery));
Table::Id aTableId;
RecordId aRecordId;
CssmData *inoutData,
CSSM_DB_UNIQUE_RECORD_PTR &outUniqueRecord)
{
- auto_ptr<Cursor> aCursor(&HandleObject::find<Cursor>(inResultsHandle, CSSMERR_DL_INVALID_RESULTS_HANDLE));
+ unique_ptr<Cursor> aCursor(&HandleObject::find<Cursor>(inResultsHandle, CSSMERR_DL_INVALID_RESULTS_HANDLE));
Table::Id aTableId;
RecordId aRecordId;
dbMakeBackup();
break;
+ case CSSM_APPLEFILEDL_MAKE_COPY:
+ dbMakeCopy((const char *) inputParams);
+ break;
+
+ case CSSM_APPLEFILEDL_DELETE_FILE:
+ dbDeleteFile();
+ break;
+
case CSSM_APPLECSPDL_DB_RELATION_EXISTS:
{
CSSM_BOOL returnValue;
default:
CssmError::throwMe(CSSM_ERRCODE_FUNCTION_NOT_IMPLEMENTED);
- break;
}
}
string filename_temp(filename_temp_cstr);
filename_temp += "_backup";
- const char * dstFilename = filename_temp.c_str();
free(filename_temp_cstr);
- if(copyfile(mAtomicFile.path().c_str(), dstFilename, NULL, COPYFILE_ALL) < 0) {
+ dbMakeCopy(filename_temp.c_str());
+}
+
+void
+AppleDatabase::dbMakeCopy(const char* path) {
+ if(copyfile(mAtomicFile.path().c_str(), path, NULL, COPYFILE_UNLINK | COPYFILE_ALL) < 0) {
UnixError::throwMe(errno);
}
}
+void AppleDatabase::dbDeleteFile() {
+ if(unlink(mAtomicFile.path().c_str()) < 0) {
+ UnixError::throwMe(errno);
+ }
+}