CA client security plugin

This commit is contained in:
Matej Sekoranja
2014-09-10 09:21:03 +02:00
parent e32e7e4ed5
commit e12cf946a5
2 changed files with 70 additions and 1 deletions

View File

@@ -4,10 +4,50 @@
* in file LICENSE that is included with this distribution.
*/
#include <osiProcess.h>
#define epicsExportSharedSymbols
#include <pv/security.h>
using namespace epics::pvData;
using namespace epics::pvAccess;
NoSecurityPlugin::shared_pointer NoSecurityPlugin::INSTANCE(new NoSecurityPlugin());
CAClientSecurityPlugin::shared_pointer CAClientSecurityPlugin::INSTANCE(new CAClientSecurityPlugin());
CAClientSecurityPlugin::CAClientSecurityPlugin()
{
StructureConstPtr userAndHostStructure =
getFieldCreate()->createFieldBuilder()->
add("user", pvString)->
add("host", pvString)->
createStructure();
m_userAndHost = getPVDataCreate()->createPVStructure(userAndHostStructure);
//
// user name
//
char buffer[256];
std::string userName;
if (osiGetUserName(buffer, sizeof(buffer)) == osiGetUserNameSuccess)
userName = buffer;
// TODO more error handling
m_userAndHost->getSubField<PVString>("user")->put(userName);
//
// host name
//
std::string hostName;
if (gethostname(buffer, sizeof(buffer)) == 0)
hostName = buffer;
// TODO more error handling
m_userAndHost->getSubField<PVString>("host")->put(buffer);
}