Пример #1
0
bool compareFile(const char *f1, const char *f2) throw(NtseException) {
	File file1(f1);
	File file2(f2);
	bool res = false;
	try {
		u64 errNo = file1.open(false);
		if (errNo != File::E_NO_ERROR)
			NTSE_THROW(errNo, "open file %s failed", f1);
		if ((errNo = file2.open(false)) != File::E_NO_ERROR)
			NTSE_THROW(errNo, "open file %s failed", f2);
		res = compareFile(&file1, &file2);
	} catch(NtseException &e) {
		throw e;
		file1.close();
		file2.close();
	}
	file1.close();
	file2.close();
	return res;
}
Пример #2
0
int SecPwd::switchCertificate() throw (SecurityException)
{
    // If same name, then no point trying to switch.
    if (strcmp(certFile, activeCertFile) == 0) return 1;

    struct stat inFileStats;
    struct stat outFileStats;
    int retVal = 0;

    if ( stat(certFile, &inFileStats) == 0 )
    {
        if ( stat(activeCertFile, &outFileStats) == 0 )
        {
            // if both files exist and they differ, then copy
            if ( inFileStats.st_size != outFileStats.st_size ||
                    compareFile(activeCertFile, certFile)   )
            {
                copyFile(certFile, activeCertFile);
            }
            else
            {
                // file with same content, don't switch.
                retVal = 1;
            }
        }
        else
        {
            // activeCertFile doesn't exist, copy from certFile
            copyFile(certFile, activeCertFile);
        }
    }
    else retVal = 1;

    if ( retVal == 0 )
    {
        delete m_sec;
        m_sec = new Security(activeCertFile);
    }
    return retVal;
}