Add showauth executable

This commit is contained in:
Michael Davidsaver
2019-04-10 11:57:23 -07:00
parent 4ea6831800
commit 2424c89bd7
2 changed files with 45 additions and 0 deletions

View File

@ -33,3 +33,6 @@ TESTPROD_HOST += testWildcard
testWildcard = testWildcard.cpp
testHarness_SRCS += testWildcard.cpp
TESTS += testWildcard
TESTPROD_HOST += showauth
showauth_SRCS += showauth.cpp

View File

@ -0,0 +1,42 @@
/**
* Copyright - See the COPYRIGHT that is included with this distribution.
* pvAccessCPP is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
*/
#include <vector>
#include <stdexcept>
#include <iostream>
#include <osiProcess.h>
#include <pv/security.h>
namespace pva = epics::pvAccess;
int main(int argc, char *argv[])
{
int ret = 0;
try {
std::vector<char> name(256u);
if(osiGetUserName(&name[0], name.size())!=osiGetUserNameSuccess)
throw std::runtime_error("Unable to determine username");
name[name.size()-1] = '\0';
std::cout<<"User: "<<(&name[0])<<"\n";
pva::PeerInfo::roles_t roles;
pva::osdGetRoles(&name[0], roles);
std::cout<<"Groups: \n";
for(pva::PeerInfo::roles_t::const_iterator it(roles.begin()), end(roles.end());
it!=end; ++it)
{
std::cout<<" "<<*it<<"\n";
}
} catch(std::exception& e) {
std::cerr<<"Error: "<<e.what()<<"\n";
ret = 2;
}
return ret;
}