1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
|
/* ****************************************************************************
* eID Middleware Project.
* Copyright (C) 2008-2009 FedICT.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License version
* 3.0 as published by the Free Software Foundation.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, see
* http://www.gnu.org/licenses/.
**************************************************************************** */
#ifndef _ANALYSEPCSCDETECTINFO_H_
#define _ANALYSEPCSCDETECTINFO_H_
#include <exception>
#include "analysis.h"
#include "middleware.h"
#include "AnalysisError.h"
#include "pcsc.h"
//******************************************
// Check if PCSC is available
//
// Pass:
// PCSC available and context could be established
// Fail:
// PCSC not available
//******************************************
class AnalysePCSCDetectInfo : public Analysis
{
public:
AnalysePCSCDetectInfo()
{
m_testName = "pcsc_detect";
m_friendlyName = "PCSC detection";
}
virtual ~AnalysePCSCDetectInfo()
{
}
virtual int run()
{
m_bPassed = false;
setProgress(0);
setStartTime();
int retVal = DIAGLIB_OK;
Report_TYPE reportType = REPORT_TYPE_RESULT;
try
{
//------------------------------------------
// write to the report what we're doing
//------------------------------------------
wchar_t sepa = L'~';
reportPrintHeader2(reportType, L"Detecting PCSC available", sepa);
//------------------------------------------
// Step 1: detect the PCSC daemon/service is available
//------------------------------------------
bool bPCSCAvailable = false;
retVal = pcscIsAvailable(&bPCSCAvailable);
if(DIAGLIB_OK!=retVal)
{
std::wstring msg;
switch(retVal)
{
//------------------------------------------
// incorrect function call, should not happen
//------------------------------------------
case DIAGLIB_ERR_BAD_CALL:
msg = L"[Error] Internal error calling pcscIsAvailable()";
break;
//------------------------------------------
// the winscard dll could not be loaded
//------------------------------------------
case DIAGLIB_ERR_LIBRARY_NOT_FOUND:
msg = L"[Error] PCSC library not found";
break;
default:
msg = L"[Error] Unknown error calling pcscIsAvailable()";
break;
}
processParamsToStop();
resultToReport(reportType,msg.c_str());
resultToReport(reportType,m_bPassed);
return retVal;
}
if (false == bPCSCAvailable)
{
resultToReport(reportType,L"[Error] Could not establish context to PCSC");
//retVal = DIAGLIB_ERR_PCSC_CONTEXT_FAILED;
resultToReport(reportType,L"[Info ] Checking service");
}
else
{
resultToReport(reportType,L"[Info ] PCSC available");
}
#ifdef __APPLE__
Proc_LIST processList;
Proc_NAME process=L"pcscd";
retVal = processGetIDs(process,&processList);
if ( 0 == processList.size())
{
resultToReport(reportType,L"[Error] pcscd not running");
}
else
{
processReportList(reportType,processList);
m_bPassed = true;
}
#endif
#ifdef WIN32
Service_ID service=L"SCardSvr";
Service_INFO info;
retVal = serviceGetInfo(service, &info);
if (DIAGLIB_OK!=retVal)
{
switch(retVal)
{
case DIAGLIB_ERR_BAD_CALL:
resultToReport(reportType,L"[Error] Error calling serviceGetInfo()");
break;
case DIAGLIB_ERR_INTERNAL:
resultToReport(reportType,L"[Error] Internal error serviceGetInfo()");
break;
default:
resultToReport(reportType,L"[Error] Unknown error serviceGetInfo()");
break;
}
processParamsToStop();
return retVal;
}
resultToReport(reportType,L"[Info ] SCardSvr info:");
retVal = serviceReportInfo(reportType, info);
m_bPassed = bPCSCAvailable;
#endif
processParamsToStop();
}
//------------------------------------------
// exception from writing to the report
//------------------------------------------
catch (ExcReport& exc)
{
processParamsToStop();
retVal = exc.getErr();
}
resultToReport(reportType,m_bPassed);
return retVal;
}
};
#endif
|