/* * TSS::mbsinc * * ntmbs_t mbsinc( const_ntmbs_t psz ); * * REQUIRES: * const_ntmbs_t psz = current mbchar_t pointer (legal MBCS boundary) * * EFFECTS: * Move the supplied string pointer forward by one character. * NTMBS characters are handled correctly. * * POSTCONDITIONS: * Returns non-const pointer after moving it. */ ntmbs_t tss::mbsinc( const_ntmbs_t psz ) { cDebug dbg( "tss::mbsinc -" ); if ( psz == 0 ) throw eCharacter( TSS_GetString( cCore, core::STR_ERR_ISNULL ) ); int nBytes = ::mblen( (char*)psz, MB_CUR_MAX ); if ( nBytes == -1 ) { dbg.TraceDebug( "Character Fault: %c\n", *psz ); if ( (unsigned char)*psz > 0x7F ) { dbg.TraceDebug( "Normalizing.\n" ); return (((ntmbs_t)psz) + 1 ); } dbg.TraceDebug( "Incorrectly Formed, Cannot Normalize!\n" ); TSS_Raise( eCharacterEncoding, cCore, core::STR_ERR_BADCHAR ); } return ( ((ntmbs_t)psz) + nBytes ); }
/////////////////////////////////////////////////////////////////////////////// // WriteDatabase /////////////////////////////////////////////////////////////////////////////// void cTWUtil::WriteDatabase(const TCHAR* filename, cFCODatabaseFile& db, bool bEncrypt, const cElGamalSigPrivateKey* pPrivateKey) { cFileHeader fileHeader; fileHeader.SetID(db.GetFileHeaderID()); // I am almost positive that this does nothing, WriteObject() sets the version in the cFileHeader - Jun 8, 1999 - dmb //fileHeader.SetVersion(1); #ifdef TW_PROFILE cTaskTimer timer(_T("Write Database")); timer.Start(); #endif WriteObject(filename, 0, db, fileHeader, bEncrypt, pPrivateKey); #ifdef TW_PROFILE timer.Stop(); #endif iUserNotify::GetInstance()->Notify(iUserNotify::V_NORMAL, _T("%s%s\n"), TSS_GetString(cTW, tw::STR_WRITE_DB_FILE).c_str(), cDisplayEncoder::EncodeInline(filename).c_str()); }
void cParseNamedAttrList::MergeNoOverwrite( const cParseNamedAttrList* const pal ) { if( pal ) { // foreach attribute in pal for( constListIter newIter = pal->mList.begin(); newIter != pal->mList.end(); newIter++ ) { // look for this attribute in this list constListIter thisIter = Find( *newIter ); // if not already in list, just put it in if( thisIter == mList.end() ) { mList.push_back( (*newIter)->Clone() ); } else // do not overwrite value (except for emailto) { // special case for emailto: this can have multiple values, so add the new value to the old value if( 0 == (*thisIter)->GetName().compare( TSS_GetString( cTWParser, twparser::STR_PARSER_EMAILTO ) ) ) { TSTRING tstr = (*thisIter)->GetValue(); cParserUtil::MergeMailLists( tstr, (*newIter)->GetValue() ); (*thisIter)->SetValue( tstr ); } } } } }
void cTWUtil::WriteConfigText(const TCHAR* filename, const TSTRING configText, bool bEncrypt, const cElGamalSigPrivateKey* pPrivateKey) { cSerializableNString nstring; nstring.mString = CONFIG_FILE_MAGIC_8BYTE; std::string ns; cStringUtil::Convert(ns, configText); nstring.mString += ns; cFileHeader fileHeader; fileHeader.SetID(cConfigFile::GetFileHeaderID()); fileHeader.SetVersion(CURRENT_FIXED_VERSION); if (bEncrypt) { ASSERT(pPrivateKey != 0); cElGamalSigPublicKey publicKey(*pPrivateKey); fileHeader.GetBaggage().MapArchive(0, publicKey.GetWriteLen()); publicKey.Write(fileHeader.GetBaggage().GetMap()); } WriteObject(filename, NULL, nstring, fileHeader, bEncrypt, pPrivateKey); iUserNotify::GetInstance()->Notify(iUserNotify::V_NORMAL, _T("%s%s\n"), TSS_GetString(cTW, tw::STR_WRITE_CONFIG_FILE).c_str(), cDisplayEncoder::EncodeInline(filename).c_str()); }
int cFSPropSet::GetPropIndex(const TCHAR* name) const { for(int i=0; i<PROP_NUMITEMS; i++) { if( _tcscmp( name, TSS_GetString( cFS, cFSPropSet_PropNames[i]).c_str() ) == 0 ) return i; } return iFCOPropSet::PROP_NOT_FOUND; }
void cPipedMailMessage::SendString(const TSTRING& s) { if (_ftprintf(mpFile, "%s", s.c_str()) < 0) { TOSTRINGSTREAM estr; estr << TSS_GetString(cTripwire, tripwire::STR_ERR2_MAIL_MESSAGE_COMMAND) << mstrSendMailExePath; throw eMailPipedOpen(estr.str()); } }
void util_SignalHandler( int sig ) { //If we're on unix, let's print out a nice error message telling //the user which signal we've recieved. #if IS_UNIX tw_psignal( sig, (TSS_GetString( cCore, core::STR_SIGNAL).c_str() ) ); #endif exit( 8 ); }
size_t tss::mbsbytes( const_ntmbs_t psz ) { if ( psz == 0 ) throw eCharacter( TSS_GetString( cCore, core::STR_ERR_ISNULL ) ); const_ntmbs_t at; for ( at = psz; *at; ++at ); return (size_t)((char*)at - (char*)psz); }
/////////////////////////////////////////////////////////////////////////////// // OpenKeyFile /////////////////////////////////////////////////////////////////////////////// void cTWUtil::OpenKeyFile(cKeyFile& keyFile, TSTRING fileName) { // first, make sure the file exists... cFileUtil::TestFileExists(fileName); iUserNotify::GetInstance()->Notify(iUserNotify::V_VERBOSE, _T("%s%s\n"), TSS_GetString(cTW, tw::STR_OPEN_KEYFILE).c_str(), cDisplayEncoder::EncodeInline(fileName).c_str()); keyFile.ReadFile(fileName.c_str()); }
//############################################################################# // cFCOPropFileType //############################################################################# TSTRING cFCOPropFileType::AsString() const { static int fileTypes [] = { fs::STR_FT_INVALID, fs::STR_FT_FILE, fs::STR_FT_DIR, fs::STR_FT_BLOCKDEV, fs::STR_FT_CHARDEV, fs::STR_FT_SYMLINK, fs::STR_FT_FIFO, fs::STR_FT_SOCK, fs::STR_FT_DOOR, fs::STR_FT_PORT }; int32 fileType = GetValue(); if((fileType > cFSPropSet::FT_INVALID) && (fileType < cFSPropSet::FT_NUMITEMS)) return TSS_GetString( cFS, fileTypes[fileType] ); else return TSS_GetString( cFS, fileTypes[cFSPropSet::FT_INVALID] ); }
void tw_yy_scan::output( int c ) { TOSTRINGSTREAM sstr; TCHAR sz[2]; sstr << TSS_GetString( cTWParser, twparser::STR_PARSER_INVALID_CHAR ); sz[0] = (unsigned char)c; // don't want to sign extend this sz[1] = 0; sstr << sz; throw eParseFailed( sstr.str() ); }
/////////////////////////////////////////////////////////////////////////////// // ReadReport /////////////////////////////////////////////////////////////////////////////// void cTWUtil::ReadReport(const TCHAR* reportFileName, cFCOReportHeader& reportHeader, cFCOReport& r, const cElGamalSigPublicKey* pPublicKey, bool silent, bool& bEncrypted) { iUserNotify::GetInstance()->Notify(iUserNotify::V_VERBOSE, _T("%s%s\n"), TSS_GetString(cTW, tw::STR_OPEN_REPORT_FILE).c_str(), cDisplayEncoder::EncodeInline(reportFileName).c_str()); ReadObject(reportFileName, &reportHeader, r, cFCOReport::GetFileHeaderID(), pPublicKey, bEncrypted); }
/////////////////////////////////////////////////////////////////////////////// // MakeFileError /////////////////////////////////////////////////////////////////////////////// TSTRING cErrorUtil::MakeFileError( const TSTRING& msg, const TSTRING& fileName ) { TSTRING ret; ret = TSS_GetString( cCore, core::STR_ERR2_FILENAME ); ret.append( fileName ); ret.append( 1, _T('\n') ); if ( msg.length() > 0 ) { ret.append(msg); } return ret; }
/////////////////////////////////////////////////////////////////////////////// // WriteReport /////////////////////////////////////////////////////////////////////////////// void cTWUtil::WriteReport(const TCHAR* filename, const cFCOReportHeader& reportHeader, const cFCOReport& r, bool bEncrypt, const cElGamalSigPrivateKey* pPrivateKey) { cFileHeader fileHeader; fileHeader.SetID(cFCOReport::GetFileHeaderID()); WriteObject(filename, &reportHeader, r, fileHeader, bEncrypt, pPrivateKey); iUserNotify::GetInstance()->Notify(iUserNotify::V_NORMAL, _T("%s%s\n"), TSS_GetString(cTW, tw::STR_WRITE_REPORT_FILE).c_str(), cDisplayEncoder::EncodeInline(filename).c_str()); }
/////////////////////////////////////////////////////////////////////////////// // SendFinit /////////////////////////////////////////////////////////////////////////////// void cPipedMailMessage::SendFinit() //throw ( eMailMessageError ) { if (mpFile) { #if !USES_MPOPEN int result = fclose(mpFile); #else int result = mpclose(mpFile); #endif if (result != 0) { TOSTRINGSTREAM estr; estr << TSS_GetString(cTripwire, tripwire::STR_ERR2_MAIL_MESSAGE_COMMAND) << mstrSendMailExePath; // uh oh! something bad has happened! throw eMailPipedCmdFailed(estr.str()); } } mpFile = 0; }
/////////////////////////////////////////////////////////////////////////////// // ReadDatabase /////////////////////////////////////////////////////////////////////////////// void cTWUtil::ReadDatabase(const TCHAR* filename, cFCODatabaseFile& db, const cElGamalSigPublicKey* pPublicKey, bool& bEncrypted) { iUserNotify::GetInstance()->Notify(iUserNotify::V_VERBOSE, _T("%s%s\n"), TSS_GetString(cTW, tw::STR_OPEN_DB_FILE).c_str(), cDisplayEncoder::EncodeInline(filename).c_str()); #ifdef TW_PROFILE cTaskTimer timer("cTWUtil::ReadDatabase"); timer.Start(); #endif ReadObject(filename, 0, db, cFCODatabaseFile::GetFileHeaderID(), pPublicKey, bEncrypted); #ifdef TW_PROFILE timer.Stop(); #endif }
void cTWUtil::WritePolicyText(const TCHAR* filename, const std::string& polText, bool bEncrypt, const cElGamalSigPrivateKey* pPrivateKey) { cSerializableNString nstring; // add a 8 byte header we can use to verify decryption nstring.mString = POLICY_FILE_MAGIC_8BYTE; nstring.mString += polText; cFileHeader fileHeader; fileHeader.SetID(cPolicyFile::GetFileHeaderID()); WriteObject(filename, NULL, nstring, fileHeader, bEncrypt, pPrivateKey); iUserNotify::GetInstance()->Notify(iUserNotify::V_NORMAL, _T("%s%s\n"), TSS_GetString(cTW, tw::STR_WRITE_POLICY_FILE).c_str(), cDisplayEncoder::EncodeInline(filename).c_str()); }
TSTRING cTWUtil::GetCfgFilePath(const cCmdLineParser& cmdLine, int cfgFileID) { TSTRING cfgFilePath; bool fConfigOnCmdLine = false; // let's see if this was specified on the command line... cCmdLineIter iter(cmdLine); for (iter.SeekBegin(); !iter.Done(); iter.Next()) { if (iter.ArgId() == cfgFileID) { ASSERT(iter.NumParams() > 0); cfgFilePath = iter.ParamAt(0); fConfigOnCmdLine = true; } } // OK, now we need to figure out where to find the config file. // If the location was specified on the command line, get the full path to it. // otherwise, the location is the dir that this exe is in. if (fConfigOnCmdLine) { TSTRING pathOut; iFSServices::GetInstance()->FullPath(pathOut, cfgFilePath); cfgFilePath = pathOut; } else { iFSServices::GetInstance()->FullPath( cfgFilePath, TSS_GetString(cTW, tw::STR_DEF_CFG_FILENAME), cSystemInfo::GetExeDir()); } cFileUtil::TestFileExists(cfgFilePath); return (cfgFilePath); }
/////////////////////////////////////////////////////////////////////////////// // SendInit /////////////////////////////////////////////////////////////////////////////// void cPipedMailMessage::SendInit() // throw( eMailMessageError ) { ASSERT(mpFile == 0); TSTRING strHeader; strHeader += cStringUtil::StrToTstr(cMailMessage::Create822Header()); #if !USES_MPOPEN mpFile = popen(mstrSendMailExePath.c_str(), _T("w")); #else // call mpopen, our safe version popen mpFile = mpopen((char*)mstrSendMailExePath.c_str(), _T("w")); #endif if (!mpFile) { TOSTRINGSTREAM estr; estr << TSS_GetString(cTripwire, tripwire::STR_ERR2_MAIL_MESSAGE_COMMAND) << mstrSendMailExePath; throw eMailPipedOpen(estr.str()); } SendString(strHeader); }
int __cdecl _tmain(int argc, const TCHAR** argv) { int ret = 0; if (CheckEpoch()) return 1; try { // set unexpected and terminate handlers // Note: we do this before Init() in case it attempts to call these handlers // TODO: move this into the Init() routine EXCEPTION_NAMESPACE set_terminate(tw_terminate_handler); EXCEPTION_NAMESPACE set_unexpected(tw_unexpected_handler); //cTWInit twInit( argv[0] ); SiggenInit(); cDebug::SetDebugLevel(cDebug::D_DETAIL); cSiggenCmdLine siggen; // first, process the command line if (argc < 2) { TCOUT << TSS_GetString(cSiggen, siggen::STR_SIGGEN_VERSION) << std::endl; TCOUT << TSS_GetString(cTW, tw::STR_VERSION) << std::endl; TCOUT << TSS_GetString(cTW, tw::STR_GET_HELP) << std::endl; ret = 1; goto exit; } // // Display the version info... // this is quick and dirty ... just the way I like it :-) -- mdb // if (_tcscmp(argv[1], _T("--version")) == 0) { TCOUT << TSS_GetString(cTW, tw::STR_VERSION_LONG) << std::endl; ret = 0; goto exit; } cCmdLineParser cmdLine; siggen.InitCmdLineParser(cmdLine); try { cmdLine.Parse(argc, argv); } catch (eError& e) { cTWUtil::PrintErrorMsg(e); TCERR << TSS_GetString(cTW, tw::STR_GET_HELP) << std::endl; ret = 1; goto exit; } cCmdLineIter iter(cmdLine); if (iter.SeekToArg(cSiggenCmdLine::HELP)) { TCOUT << TSS_GetString(cSiggen, siggen::STR_SIGGEN_VERSION) << std::endl; TCOUT << TSS_GetString(cTW, tw::STR_VERSION) << std::endl; TCOUT << TSS_GetString(cSiggen, siggen::STR_SIGGEN_USAGE) << std::endl; ret = 1; goto exit; } if (!siggen.Init(cmdLine)) { TCOUT << TSS_GetString(cSiggen, siggen::STR_SIGGEN_VERSION) << std::endl; TCOUT << TSS_GetString(cTW, tw::STR_VERSION) << std::endl; TCOUT << TSS_GetString(cSiggen, siggen::STR_SIGGEN_USAGE) << std::endl; ret = 1; goto exit; } ret = siggen.Execute(); } //end try block catch (eError& error) { cErrorReporter::PrintErrorMsg(error); ASSERT(false); } exit: return ret; } //end MAIN
/////////////////////////////////////////////////////////////////////////////// // InitializeTypeInfo /////////////////////////////////////////////////////////////////////////////// bool cFSDataSourceIter::InitializeTypeInfo(iFCO* pFCO) { cFSObject* pObj = (cFSObject*)pFCO; iFCONameTranslator* pTrans = iTWFactory::GetInstance()->GetNameTranslator(); if( pObj->GetFSPropSet().GetValidVector().ContainsItem( cFSPropSet::PROP_FILETYPE) ) return true; // // assume invalid by default... // cFSPropSet& propSet = pObj->GetFSPropSet(); propSet.SetFileType(cFSPropSet::FT_INVALID); cFSStatArgs statArgs; try { iFSServices::GetInstance()->Stat( pTrans->ToStringAPI( pObj->GetName() ), statArgs); } catch(eFSServices& e) { cDebug d("CreateObject"); d.TraceError( "*** Stat of %s failed!!!\n", pObj->GetName().AsString().c_str() ); if( mpErrorBucket ) { e.SetFatality( false ); mpErrorBucket->AddError( e ); } return false; } // // don't create the object if it is on a different file system... // if( gCrossFileSystems == false && (mDev != 0) && (statArgs.dev != mDev) ) { TW_NOTIFY_NORMAL( TSS_GetString( cFS, fs::STR_DIFFERENT_FILESYSTEM ).c_str(), pTrans->ToStringDisplay( pObj->GetName() ).c_str() ); return false; } // // fill out all of the appropriate properties.... // propSet.SetDev (statArgs.dev); propSet.SetRDev (statArgs.rdev); propSet.SetInode (statArgs.ino); propSet.SetMode (statArgs.mode); propSet.SetNLink (statArgs.nlink); propSet.SetUID (statArgs.uid); propSet.SetGID (statArgs.gid); propSet.SetSize (statArgs.size); propSet.SetAccessTime (statArgs.atime); propSet.SetModifyTime (statArgs.mtime); propSet.SetCreateTime (statArgs.ctime); propSet.SetBlockSize (statArgs.blksize); propSet.SetBlocks (statArgs.blocks); propSet.SetGrowingFile (statArgs.size); // set the file type switch(statArgs.mFileType) { case cFSStatArgs::TY_FILE: propSet.SetFileType(cFSPropSet::FT_FILE); break; case cFSStatArgs::TY_DIR: propSet.SetFileType(cFSPropSet::FT_DIR); break; case cFSStatArgs::TY_BLOCKDEV: propSet.SetFileType(cFSPropSet::FT_BLOCKDEV); break; case cFSStatArgs::TY_CHARDEV: propSet.SetFileType(cFSPropSet::FT_CHARDEV); break; case cFSStatArgs::TY_SYMLINK: propSet.SetFileType(cFSPropSet::FT_SYMLINK); break; case cFSStatArgs::TY_FIFO: propSet.SetFileType(cFSPropSet::FT_FIFO); break; case cFSStatArgs::TY_SOCK: propSet.SetFileType(cFSPropSet::FT_SOCK); break; case cFSStatArgs::TY_DOOR: propSet.SetFileType(cFSPropSet::FT_DOOR); break; case cFSStatArgs::TY_PORT: propSet.SetFileType(cFSPropSet::FT_PORT); break; default: // set it to invalid propSet.SetFileType(cFSPropSet::FT_INVALID); } return true; }
/////////////////////////////////////////////////////////////////////////////// // WriteObjectToArchive -- called from WriteObject, does most of the work /////////////////////////////////////////////////////////////////////////////// static void ReadObjectFromArchive(cArchive& arch, const TCHAR* objFileName, iTypedSerializable* pObjHeader, iTypedSerializable& obj, const cFileHeaderID& fhid, const cElGamalSigPublicKey* pPublicKey, bool& bEncrypted) { cFileHeader fileHeader; { cSerializerImpl fhSer(arch, cSerializerImpl::S_READ, objFileName); fileHeader.Read(&fhSer); } // check for a mismatched header if (fileHeader.GetID() != fhid) ThrowAndAssert(eSerializerInputStreamFmt(_T(""), objFileName, eSerializer::TY_FILE)); // Check file version. // If we in the future we wish to support reading objects of different versions, // we will have to move this check to outside ReadObject(). if (fileHeader.GetVersion() != CURRENT_FIXED_VERSION) ThrowAndAssert(eSerializerVersionMismatch(_T(""), objFileName, eSerializer::TY_FILE)); try { // switch on the type of encoding... if (fileHeader.GetEncoding() == cFileHeader::ASYM_ENCRYPTION) { // tell the user the db is encrypted iUserNotify::GetInstance()->Notify(iUserNotify::V_VERBOSE, TSS_GetString(cTW, tw::STR_FILE_ENCRYPTED).c_str()); bEncrypted = true; if (pPublicKey == 0) ThrowAndAssert(eSerializerEncryption(_T(""))); cElGamalSigArchive cryptoArchive; cryptoArchive.SetRead(&arch, pPublicKey); cSerializerImpl ser(cryptoArchive, cSerializerImpl::S_READ, objFileName); ser.Init(); if (pObjHeader) ser.ReadObject(pObjHeader); ser.ReadObject(&obj); ser.Finit(); } else if (fileHeader.GetEncoding() == cFileHeader::COMPRESSED) { //not encrypted db... bEncrypted = false; cNullCryptoArchive cryptoArchive; cryptoArchive.Start(&arch); cSerializerImpl ser(cryptoArchive, cSerializerImpl::S_READ, objFileName); ser.Init(); if (pObjHeader) ser.ReadObject(pObjHeader); ser.ReadObject(&obj); ser.Finit(); } else // unknown encoding... ThrowAndAssert(eSerializerInputStreamFmt(_T(""))); } catch (eError& e) { // include filename in error msg throw ePoly(e.GetID(), cErrorUtil::MakeFileError(e.GetMsg(), objFileName), e.GetFlags()); } }
/////////////////////////////////////////////////////////////////////////////// // Parse /////////////////////////////////////////////////////////////////////////////// void cCmdLineParser::Parse(int argc, const TCHAR *const * argv) { // clear out any existing data mArgData.clear(); const TCHAR* pCurArg = 0; bool bProcessedFinalParams = false; // gets set to true when the parameters to the command line are processed // I assume argv[0] is the executable name... for(int i=1; i < argc; i++) { if(argv[i][0] == _T('-')) { pCurArg = argv[i]; // this is a switch; find it in the table... cArgInfo argInfo; if ( !mArgTable.Lookup( TSTRING(&argv[i][1] ), argInfo ) ) { // unknown switch! throw eCmdLineInvalidArg( TSS_GetString( cCore, core::STR_ERR2_BAD_ARG_PARAMS ) + pCurArg ); } // // make sure this hasn't been specified yet... // if( ArgInList( argInfo.mId ) ) { // Make sure it isn't okay for this one to appear more than once... std::set<int>::iterator it = mMultipleAllowed.find( argInfo.mId ); if( it == mMultipleAllowed.end() ) { // It wasn't in our list of allowed params, so error. throw eCmdLineMultiArg( TSS_GetString( cCore, core::STR_ERR2_BAD_ARG_PARAMS ) + argv[i] ); } } // // add it to the list.. // mArgData.push_back(cArgData(argInfo.mId, TSTRING(argv[i]))); cArgData& curArg = mArgData.back(); switch( argInfo.mNumParams ) { case PARAM_NONE: // make sure there are no parameters to this, but be careful because // it is legal to start the parameters to the executable here. if((i+1 < argc) && (argv[i+1][0] != _T('-'))) { // search for any more parameters // TODO: In the future we may want to support a '--' switch that specifies the start // of parameters to the executable. for (int j = i + 2; j < argc; ++j ) { if (argv[j][0] == _T('-')) { // >0 parameter passed ! throw eCmdLineBadParam( TSS_GetString( cCore, core::STR_ERR2_BAD_ARG_PARAMS ) + pCurArg ); } } } break; case PARAM_ONE: // get the next parameter... i++; if ( (i >= argc) || (argv[i][0] == _T('-')) ) { // zero parameters passed to something that needed one param throw eCmdLineBadParam( TSS_GetString( cCore, core::STR_ERR2_BAD_ARG_PARAMS ) + pCurArg ); } curArg.mParams.push_back( TSTRING(argv[i]) ); break; case PARAM_MANY: i++; while((i < argc) && (argv[i][0] != _T('-'))) { curArg.mParams.push_back(TSTRING(argv[i])); i++; } i--; // since we have gone too far at this point break; default: ASSERTMSG( false, "Unknown number of arguments to parser" ); } } else { bProcessedFinalParams = true; // this must be the final "unnamed" arg // first, make sure it is consistent with the current info... bool bResult = true; switch(mLastArgInfo.mNumParams) { case PARAM_NONE: // this is an error; they didn't want any command line parameters... bResult = false; break; case PARAM_ONE: if(i+1 != argc) // there is >1 final parameter; it is an error bResult = false; break; case PARAM_MANY: // we'll catch errors below break; default: ASSERT(false); } if(! bResult) { throw eCmdLineBadParam( ); } // ok, we can push the final parameter info onto the list... mArgData.push_back(cArgData(mLastArgInfo.mId)); cArgData& curArg = mArgData.back(); while ( i < argc ) { if ( argv[i][0] == _T('-') ) { if ( ! pCurArg ) { throw eCmdLineBadSwitchPos( TSS_GetString( cCore, core::STR_ERR2_BAD_ARG_PARAMS ) + argv[i] ); } else { // there was an extra parameter passed somewhere! throw eCmdLineBadArgParam( TSS_GetString( cCore, core::STR_ERR2_BAD_ARG_PARAMS ) + pCurArg ); } } // add this param to the list curArg.mParams.push_back(TSTRING(argv[i])); i++; } } } // it is possible not to process the final command line parameters in the "else" case above // (this only occurs if there are no command line parameters specified) so let's make sure that // is consistent with what we are configured with... // NOTE -- it is ok to have no cmd line parameters if they specified PARAM_NONE or PARAM_MANY if(! bProcessedFinalParams) { if(mLastArgInfo.mNumParams == PARAM_ONE) { throw eCmdLineBadParam( ); } } // Check for "relationship errors": TestMutEx(); TestDependency(); }
// case sensitive-matching bool cParseNamedAttr::NamesMatch( int nString, const TSTRING& strName ) const { return ( 0 == strName.compare( TSS_GetString( cTWParser, nString ) ) ); }
void cTWUtil::CreatePrivateKey( cPrivateKeyProxy& proxy, cKeyFile& keyFile, const WCHAR16* usePassphrase, KeyType keyType, int nSecs) { ASSERT(keyType == KEY_SITE || keyType == KEY_LOCAL || keyType == KEY_PROVIDED); wc16_string passphrase; if (usePassphrase != 0) { // sleep to hinder brute force (dictionary, etc.) attacks iFSServices::GetInstance()->Sleep(nSecs); passphrase = usePassphrase; #ifndef WORDS_BIGENDIAN passphrase.swapbytes(); #endif if (proxy.AquireKey(keyFile, (int8*)passphrase.data(), passphrase.length() * sizeof(WCHAR16))) return; // if we got here, then a passphrase was provided on the command line that // was not correct; this is an error condition. // if (keyType == KEY_LOCAL) throw eTWUtilBadPassLocal(); else throw eTWUtilBadPassSite(); } int count = 0; while (count < 3) { cTWUtil::NoEcho noEcho; switch (keyType) { case KEY_LOCAL: TCOUT << TSS_GetString(cTW, tw::STR_ENTER_LOCAL_PASSPHRASE); break; case KEY_SITE: TCOUT << TSS_GetString(cTW, tw::STR_ENTER_SITE_PASSPHRASE); break; case KEY_PROVIDED: default: TCOUT << TSS_GetString(cTW, tw::STR_ENTER_PROVIDED_PASSPHRASE); break; } cTWUtil::GetString(passphrase); TCOUT << std::endl; // sleep to hinder brute force (dictionary, etc.) attacks iFSServices::GetInstance()->Sleep(nSecs); #ifndef WORDS_BIGENDIAN passphrase.swapbytes(); #endif if (proxy.AquireKey(keyFile, (int8*)passphrase.data(), passphrase.length() * sizeof(WCHAR16))) return; // tell the user that they entered the wrong passphrase int strId = (keyType == KEY_LOCAL) ? tw::STR_ERR_WRONG_PASSPHRASE_LOCAL : (keyType == KEY_SITE) ? tw::STR_ERR_WRONG_PASSPHRASE_SITE : tw::STR_ERR_WRONG_PASSPHRASE_LOCAL; // TODO: make this provided TCOUT << TSS_GetString(cTW, strId) << std::endl; passphrase.resize(0); count++; } throw ePoly(); }
void cTWUtil::ReadConfigText(const TCHAR* filename, TSTRING& configText, cArchive* pBaggage) { // TODO -- neat up this function; try to use LoadObject() above... cSerializableNString nstring; // This was coppied from ReadObject(). We need to use the baggage of the // file header to obtain the public key, thus the special casing. cDebug d("ReadConfigText"); d.TraceDebug(_T("Reading %s from file %s\n"), nstring.GetType().AsString(), filename); iUserNotify::GetInstance()->Notify(iUserNotify::V_VERBOSE, _T("%s%s\n"), TSS_GetString(cTW, tw::STR_OPEN_CONFIG_FILE).c_str(), cDisplayEncoder::EncodeInline(filename).c_str()); cFileArchive arch; arch.OpenRead(filename); cFileHeader fileHeader; try { cSerializerImpl fhSer(arch, cSerializerImpl::S_READ); fileHeader.Read(&fhSer); } catch (eError&) { throw eSerializerInputStreamFmt(_T(""), filename, eSerializer::TY_FILE); } #if 0 // XXX: This is broken, what the h*ll are they trying to write here? -PH d.TraceDebug("Found a file header of type %d.\n", fileHeader.GetEncoding()); #endif // check for a mismatched header if (fileHeader.GetID() != cConfigFile::GetFileHeaderID()) throw eSerializerInputStreamFmt(_T(""), filename, eSerializer::TY_FILE); // check the version if (fileHeader.GetVersion() != CURRENT_FIXED_VERSION) throw eSerializerVersionMismatch(_T(""), filename, eSerializer::TY_FILE); // switch on the type of encoding... if (fileHeader.GetEncoding() == cFileHeader::ASYM_ENCRYPTION) { d.TraceDebug("Config file is compressed, public key len %d.\n", fileHeader.GetBaggage().Length()); // tell the user the db is encrypted iUserNotify::GetInstance()->Notify(iUserNotify::V_VERBOSE, TSS_GetString(cTW, tw::STR_FILE_ENCRYPTED).c_str()); iUserNotify::GetInstance()->Notify(iUserNotify::V_VERBOSE, TSS_GetString(cTW, tw::STR_NEWLINE).c_str()); ASSERT(fileHeader.GetBaggage().Length() > 0); if (fileHeader.GetBaggage().Length() <= 0) ThrowAndAssert(eSerializerInputStreamFmt(_T(""), filename, eSerializer::TY_FILE)); fileHeader.GetBaggage().MapArchive(0, fileHeader.GetBaggage().Length()); cElGamalSigPublicKey publicKey(fileHeader.GetBaggage().GetMap()); cElGamalSigArchive cryptoArchive; cryptoArchive.SetRead(&arch, &publicKey); cSerializerImpl ser(cryptoArchive, cSerializerImpl::S_READ); ser.Init(); ser.ReadObject(&nstring); ser.Finit(); // copy the baggage into the archive, if it was passed in // Note: We rely in VerifySiteKey that we only fill out pBaggage if // the config file is encrypted. // if (pBaggage) { fileHeader.GetBaggage().Seek(0, cBidirArchive::BEGINNING); pBaggage->Copy(&fileHeader.GetBaggage(), fileHeader.GetBaggage().Length()); } } else if (fileHeader.GetEncoding() == cFileHeader::COMPRESSED) { d.TraceDebug("Config file is not compressed.\n"); //not encrypted db... cNullCryptoArchive cryptoArchive; cryptoArchive.Start(&arch); cSerializerImpl ser(cryptoArchive, cSerializerImpl::S_READ); ser.Init(); ser.ReadObject(&nstring); ser.Finit(); } else // unknown encoding... throw eSerializerInputStreamFmt(_T(""), filename, eSerializer::TY_FILE); // check 8 byte header if (nstring.mString.compare(0, 8 * sizeof(byte), CONFIG_FILE_MAGIC_8BYTE) != 0) ThrowAndAssert(eSerializerInputStreamFmt(_T(""), filename, eSerializer::TY_FILE)); // remove 8 byte header nstring.mString.assign(nstring.mString.substr(8)); cStringUtil::Convert(configText, nstring.mString); }
// Change the encryption on a file. // If pNewKey is NULL, then encryption on the file will be removed. // If pOldKey is NULL and the file is currently encrypted, then the // function will throw eFileManip; // If pOldKey is not NULL and the file is encrypted, then the fuction // will throw eFileManip; // If pOldKey is NULL and pNewKey is NULL and the file is not // currently encrypted, the function will not do anything and will just // return. // Returns on successful encryption change. void cFileManipulator::ChangeEncryption(const cElGamalSigPublicKey* pOldKey, const cElGamalSigPrivateKey* pNewKey, bool backup) { ASSERT(mbInit); if (!mbInit) { Init(); } // check the pOldKey matches the current encryption state if (mFileHeader.GetEncoding() != cFileHeader::ASYM_ENCRYPTION) { if (pOldKey != NULL) throw eFileManipNotEncrypted(mFileName); if (pNewKey == NULL) return; // NOOP } else if (pOldKey == NULL) throw eFileManipMissingKey(); if (!cFileUtil::FileWritable(mFileName)) throw eFileManipNotWritable(mFileName); if (mFileHeader.GetID() == cFCODatabaseFile::GetFileHeaderID()) { cFCODatabaseFile db; bool encrypted; cTWUtil::ReadDatabase(mFileName.c_str(), db, pOldKey, encrypted); if (backup) { TSTRING backname = mFileName + iFSServices::GetInstance()->GetStandardBackupExtension(); iFSServices::GetInstance()->Rename(mFileName.c_str(), backname.c_str()); } cTWUtil::WriteDatabase(mFileName.c_str(), db, pNewKey != NULL, pNewKey); return; } else if (mFileHeader.GetID() == cFCOReport::GetFileHeaderID()) { cFCOReport rep; cFCOReportHeader reph; bool encrypted; cTWUtil::ReadReport(mFileName.c_str(), reph, rep, pOldKey, false, encrypted); if (backup) { TSTRING backname = mFileName + iFSServices::GetInstance()->GetStandardBackupExtension(); iFSServices::GetInstance()->Rename(mFileName.c_str(), backname.c_str()); } cTWUtil::WriteReport(mFileName.c_str(), reph, rep, pNewKey != NULL, pNewKey); return; } else if (mFileHeader.GetID() == cConfigFile::GetFileHeaderID()) { TSTRING configText; iUserNotify::GetInstance()->Notify(iUserNotify::V_VERBOSE, _T("%s%s\n"), TSS_GetString(cTW, tw::STR_OPEN_CONFIG_FILE).c_str(), cDisplayEncoder::EncodeInline(mFileName).c_str()); cTWUtil::ReadConfigText(mFileName.c_str(), configText); if (backup) { TSTRING backname = mFileName + iFSServices::GetInstance()->GetStandardBackupExtension(); iFSServices::GetInstance()->Rename(mFileName.c_str(), backname.c_str()); } cTWUtil::WriteConfigText(mFileName.c_str(), configText, pNewKey != NULL, pNewKey); return; } else if (mFileHeader.GetID() == cPolicyFile::GetFileHeaderID()) { std::string policyText; iUserNotify::GetInstance()->Notify(iUserNotify::V_VERBOSE, _T("%s%s\n"), TSS_GetString(cTW, tw::STR_OPEN_POLICY_FILE).c_str(), cDisplayEncoder::EncodeInline(mFileName).c_str()); cTWUtil::ReadPolicyText(mFileName.c_str(), policyText, pOldKey); if (backup) { TSTRING backname = mFileName + iFSServices::GetInstance()->GetStandardBackupExtension(); iFSServices::GetInstance()->Rename(mFileName.c_str(), backname.c_str()); } cTWUtil::WritePolicyText(mFileName.c_str(), policyText, pNewKey != NULL, pNewKey); return; } }
bool cFSParserUtil::EnumPredefinedVariables( int index, TSTRING& sName, TSTRING& sValue ) const { switch( index ) { case 0: sName = TSS_GetString( cFS, fs::STR_PARSER_READONLY ); sValue = TSS_GetString( cFS, fs::STR_FS_PARSER_READONLY_VAL ); return true; case 1: sName = TSS_GetString( cFS, fs::STR_PARSER_DYNAMIC ); sValue = TSS_GetString( cFS, fs::STR_FS_PARSER_DYNAMIC_VAL ); return true; case 2: sName = TSS_GetString( cFS, fs::STR_PARSER_GROWING ); sValue = TSS_GetString( cFS, fs::STR_FS_PARSER_GROWING_VAL ); return true; case 3: sName = TSS_GetString( cFS, fs::STR_PARSER_IGNOREALL ); sValue = TSS_GetString( cFS, fs::STR_FS_PARSER_IGNOREALL_VAL ); return true; case 4: sName = TSS_GetString( cFS, fs::STR_PARSER_IGNORENONE ); sValue = TSS_GetString( cFS, fs::STR_FS_PARSER_IGNORENONE_VAL ); return true; case 5: sName = TSS_GetString( cFS, fs::STR_PARSER_DEVICE ); sValue = TSS_GetString( cFS, fs::STR_FS_PARSER_DEVICE_VAL ); return true; default: return false; } ASSERT( false ); // unreachable code }
/////////////////////////////////////////////////////////////////////////////// // Execute /////////////////////////////////////////////////////////////////////////////// bool cUpdateDb::Execute( uint32 flags ) { cDebug d("cUpdateDb::Execute"); bool bResult = true; // I will assume that the current genre is correct... // cFCOReportSpecIter specIter( mReport, cGenreSwitcher::GetInstance()->CurrentGenre() ); cDbDataSourceIter dbIter ( &mDb ); dbIter.SetErrorBucket(mpBucket); iFCONameTranslator* pTrans = iTWFactory::GetInstance()->GetNameTranslator(); // // set flags // if( flags & FLAG_ERASE_FOOTPRINTS_UD ) { dbIter.SetIterFlags( iFCODataSourceIter::DO_NOT_MODIFY_OBJECTS ); } // // iterate through all the specs... // for(specIter.SeekBegin(); ! specIter.Done(); specIter.Next()) { // skip this spec if there is nothing to update... // if( (specIter.GetAddedSet()->IsEmpty()) && (specIter.GetRemovedSet()->IsEmpty()) && (specIter.GetNumChanged() == 0) ) { continue; } // // Add all of the "Added" files... // cIterProxy<iFCOIter> fcoIter (specIter.GetAddedSet()->GetIter()); for(fcoIter->SeekBegin(); ! fcoIter->Done(); fcoIter->Next()) { TW_NOTIFY_VERBOSE( _T("%s%s\n"), TSS_GetString( cTripwire, tripwire::STR_NOTIFY_DB_ADDING ).c_str(), pTrans->ToStringDisplay( fcoIter->FCO()->GetName() ).c_str() ); // // seek to the new FCO, creating the path if necessary.. // dbIter.CreatePath( fcoIter->FCO()->GetName() ); // // report an error if this already exists in the db // if( dbIter.HasFCOData() ) { d.TraceError(_T("Report says to add fco %s that already exists in the db!\n"), fcoIter->FCO()->GetName().AsString().c_str()); if( mpBucket ) mpBucket->AddError( eUpdateDbAddedFCO( pTrans->ToStringDisplay( fcoIter->FCO()->GetName() ), eError::SUPRESS_THIRD_MSG) ); bResult = false; } else { // add the fco to the database... // d.TraceDebug(_T(">>> Adding FCO %s\n"), fcoIter->FCO()->GetName().AsString().c_str()); dbIter.SetFCOData( fcoIter->FCO() ); } } // // remove all of the "Removed" files // cIterProxy<iFCOIter> rmIter(specIter.GetRemovedSet()->GetIter()); for(rmIter->SeekBegin(); ! rmIter->Done(); rmIter->Next()) { TW_NOTIFY_VERBOSE( _T("%s%s\n"), TSS_GetString( cTripwire, tripwire::STR_NOTIFY_DB_REMOVING ).c_str(), pTrans->ToStringDisplay( rmIter->FCO()->GetName() ).c_str() ); if(! cTripwireUtil::RemoveFCOFromDb( rmIter->FCO()->GetName(), dbIter ) ) { d.TraceError(_T("Report says to remove fco %s that doesn't exist in the db!\n"), rmIter->FCO()->GetName().AsString().c_str()); if( mpBucket ) mpBucket->AddError( eUpdateDbRemovedFCO( pTrans->ToStringDisplay( rmIter->FCO()->GetName() ), eError::SUPRESS_THIRD_MSG) ); bResult = false; } } // // change all the "Changed" fcos.... // cFCOCompare compareObj; cFCOReportChangeIter changeIter(specIter); for(changeIter.SeekBegin(); ! changeIter.Done(); changeIter.Next()) { TW_NOTIFY_VERBOSE( _T("%s%s\n"), TSS_GetString( cTripwire, tripwire::STR_NOTIFY_DB_CHANGING ).c_str(), pTrans->ToStringDisplay( changeIter.GetOld()->GetName() ).c_str() ); d.TraceDebug(">>> Changing FCO %s\n", changeIter.GetOld()->GetName().AsString().c_str()); // // error if the fco isn't in the database // dbIter.SeekToFCO( changeIter.GetOld()->GetName() ); if( dbIter.Done() || ( ! dbIter.HasFCOData() ) ) { d.TraceError("Report says to change fco %s but it doesn't exist in the db!\n", changeIter.GetOld()->GetName().AsString().c_str()); if( mpBucket ) mpBucket->AddError( eUpdateDbRemovedFCO( pTrans->ToStringDisplay( changeIter.GetOld()->GetName() ), eError::SUPRESS_THIRD_MSG) ); bResult = false; continue; } // make sure that the fco properties match the "old" value in the report // iFCO* pDbFCO = dbIter.CreateFCO(); compareObj.SetPropsToCmp(changeIter.GetOld()->GetPropSet()->GetValidVector()); if( (compareObj.Compare(changeIter.GetOld(), pDbFCO) & cFCOCompare::EQUAL) == 0 ) { d.TraceError("FCO %s in report doesn't match current db values for properties!\n", changeIter.GetOld()->GetName().AsString().c_str()); changeIter.GetOld()->TraceContents (cDebug::D_ERROR); pDbFCO->TraceContents (cDebug::D_ERROR); if( mpBucket ) mpBucket->AddError( eUpdateDbChangedFCO( pTrans->ToStringDisplay( pDbFCO->GetName() ), eError::SUPRESS_THIRD_MSG) ); pDbFCO->Release(); bResult = false; continue; } // // ok, we can finally update the database... // TODO -- I only think that we should be copying all of the properties if FLAG_REPLACE_PROPS // is set. For example, what if they ignore a property? This bears some investigation... //dbFcoIter->FCO()->GetPropSet()->CopyProps(changeIter.GetNew()->GetPropSet(), changeIter.GetNew()->GetPropSet()->GetValidVector()); // dbIter.RemoveFCOData(); if( flags & FLAG_REPLACE_PROPS ) { // replace the old fco's data with the new data // dbIter.SetFCOData( changeIter.GetNew() ); } else { iFCO* pNewFCO = changeIter.GetNew()->Clone(); // // we need to fold in all properties that are in the old FCO but not valid in the new one // (in case an integrity check ignored certain properties, we need to keep the old values in the // database) -- 5 feb 99 mdb // cFCOPropVector propsToCopy = pDbFCO->GetPropSet()->GetValidVector() ^ pNewFCO->GetPropSet()->GetValidVector(); propsToCopy &= pDbFCO->GetPropSet()->GetValidVector(); pNewFCO->GetPropSet()->CopyProps( pDbFCO->GetPropSet(), propsToCopy ); dbIter.SetFCOData( pNewFCO ); pNewFCO->Release(); } pDbFCO->Release(); } } return bResult; }
bool cFSParserUtil::MapStringToProperty( const TSTRING& str, int& propIndex ) const { bool fMappedChar = true; // assume we'll recognize this char // and set false if we don't // for short names if( str.length() == 1 ) { switch( str[0] ) { case 'p': propIndex = cFSPropSet::PROP_MODE; break; case 'i': propIndex = cFSPropSet::PROP_INODE; break; case 'n': propIndex = cFSPropSet::PROP_NLINK; break; case 'u': propIndex = cFSPropSet::PROP_UID; break; case 'g': propIndex = cFSPropSet::PROP_GID; break; case 's': propIndex = cFSPropSet::PROP_SIZE; break; case 't': propIndex = cFSPropSet::PROP_FILETYPE;break; case 'd': propIndex = cFSPropSet::PROP_DEV; break; case 'r': propIndex = cFSPropSet::PROP_RDEV; break; case 'b': propIndex = cFSPropSet::PROP_BLOCKS; break; case 'a': propIndex = cFSPropSet::PROP_ATIME; break; case 'm': propIndex = cFSPropSet::PROP_MTIME; break; case 'c': propIndex = cFSPropSet::PROP_CTIME; break; case 'C': propIndex = cFSPropSet::PROP_CRC32; break; case 'M': propIndex = cFSPropSet::PROP_MD5; break; case 'S': propIndex = cFSPropSet::PROP_SHA; break; case 'H': propIndex = cFSPropSet::PROP_HAVAL; break; case 'l': propIndex = cFSPropSet::PROP_GROWING_FILE; break; default: fMappedChar = false; break; } } else { if( 0 == str.compare( TSS_GetString( cFS, fs::STR_PARSER_PROP_MODE ) ) ) propIndex = cFSPropSet::PROP_MODE; else if( 0 == str.compare( TSS_GetString( cFS, fs::STR_PARSER_PROP_INODE ) ) ) propIndex = cFSPropSet::PROP_INODE; else if( 0 == str.compare( TSS_GetString( cFS, fs::STR_PARSER_PROP_UID ) ) ) propIndex = cFSPropSet::PROP_UID; else if( 0 == str.compare( TSS_GetString( cFS, fs::STR_PARSER_PROP_GID ) ) ) propIndex = cFSPropSet::PROP_GID; else if( 0 == str.compare( TSS_GetString( cFS, fs::STR_PARSER_PROP_SIZE ) ) ) propIndex = cFSPropSet::PROP_SIZE; else if( 0 == str.compare( TSS_GetString( cFS, fs::STR_PARSER_PROP_FILETYPE ) ) ) propIndex = cFSPropSet::PROP_FILETYPE; else if( 0 == str.compare( TSS_GetString( cFS, fs::STR_PARSER_PROP_DEV ) ) ) propIndex = cFSPropSet::PROP_DEV; else if( 0 == str.compare( TSS_GetString( cFS, fs::STR_PARSER_PROP_RDEV ) ) ) propIndex = cFSPropSet::PROP_RDEV; else if( 0 == str.compare( TSS_GetString( cFS, fs::STR_PARSER_PROP_BLOCKS ) ) ) propIndex = cFSPropSet::PROP_BLOCKS; else if( 0 == str.compare( TSS_GetString( cFS, fs::STR_PARSER_PROP_ATIME ) ) ) propIndex = cFSPropSet::PROP_ATIME; else if( 0 == str.compare( TSS_GetString( cFS, fs::STR_PARSER_PROP_MTIME ) ) ) propIndex = cFSPropSet::PROP_MTIME; else if( 0 == str.compare( TSS_GetString( cFS, fs::STR_PARSER_PROP_CTIME ) ) ) propIndex = cFSPropSet::PROP_CTIME; else if( 0 == str.compare( TSS_GetString( cFS, fs::STR_PARSER_PROP_CRC32 ) ) ) propIndex = cFSPropSet::PROP_CRC32; else if( 0 == str.compare( TSS_GetString( cFS, fs::STR_PARSER_PROP_MD5 ) ) ) propIndex = cFSPropSet::PROP_MD5; else if( 0 == str.compare( TSS_GetString( cFS, fs::STR_PARSER_PROP_SHA ) ) ) propIndex = cFSPropSet::PROP_SHA; else if( 0 == str.compare( TSS_GetString( cFS, fs::STR_PARSER_PROP_HAVAL ) ) ) propIndex = cFSPropSet::PROP_HAVAL; else if( 0 == str.compare( TSS_GetString( cFS, fs::STR_PARSER_PROP_GROWING_FILE ) ) ) propIndex = cFSPropSet::PROP_GROWING_FILE; else fMappedChar = false; } return( fMappedChar ); }