XRootD
Loading...
Searching...
No Matches
XrdSectestServer.cc File Reference
#include <unistd.h>
#include <cctype>
#include <cstdlib>
#include <strings.h>
#include <cstdio>
#include <sys/param.h>
#include "XrdNet/XrdNetAddr.hh"
#include "XrdOuc/XrdOucErrInfo.hh"
#include "XrdSys/XrdSysE2T.hh"
#include "XrdSys/XrdSysHeaders.hh"
#include "XrdSys/XrdSysLogger.hh"
#include "XrdSec/XrdSecInterface.hh"
+ Include dependency graph for XrdSectestServer.cc:

Go to the source code of this file.

Classes

struct  myOpts
 

Macros

#define H(x)   fprintf(stderr,x); fprintf(stderr, "\n");
 
#define I(x)   fprintf(stderr, "\n"); H(x)
 
#define insx(a, b)   sprintf(errbuff,a,b)
 
#define insy(a, b, c)   sprintf(errbuff,a,b,c)
 

Typedefs

typedef unsigned char uchar
 

Functions

int cvtx (uchar idig, uchar *odig)
 
int emsg (int rc, char *msg)
 
const char * Ereason ()
 
void getargs (int argc, char **argv)
 
int getbintix (uchar *buff, int blen)
 
void getline (uchar *buff, int blen)
 
void help (int rc)
 
int main (int argc, char **argv)
 
int unhex (uchar *ibuff, uchar *obuff, int blen)
 
void xerr (int x)
 
XrdSecServiceXrdSecgetService (XrdSysLogger *lp, const char *cfn)
 

Variables

char errbuff [256]
 
char hexbuff [256]
 
struct myOpts opts
 

Class Documentation

◆ myOpts

struct myOpts

Definition at line 62 of file XrdSectestServer.cc.

+ Collaboration diagram for myOpts:
Class Members
int bin
char * cfn
int debug
char * host
FILE * infid
char * inpt
int online
int xtra

Macro Definition Documentation

◆ H

#define H (   x)    fprintf(stderr,x); fprintf(stderr, "\n");

Definition at line 49 of file XrdSectestServer.cc.

◆ I

#define I (   x)    fprintf(stderr, "\n"); H(x)

Definition at line 50 of file XrdSectestServer.cc.

◆ insx

#define insx (   a,
 
)    sprintf(errbuff,a,b)

Definition at line 51 of file XrdSectestServer.cc.

◆ insy

#define insy (   a,
  b,
 
)    sprintf(errbuff,a,b,c)

Definition at line 52 of file XrdSectestServer.cc.

Typedef Documentation

◆ uchar

typedef unsigned char uchar

Definition at line 54 of file XrdSectestServer.cc.

Function Documentation

◆ cvtx()

int cvtx ( uchar  idig,
uchar odig 
)

Definition at line 281 of file XrdSectestServer.cc.

281 {
282if (idig >= '0' && idig <= '9') {*odig = idig & (uchar)0x0f; return 1;}
283idig = idig | (uchar)0x20; /* Change to lower case. */
284if (idig < 'a' || idig > 'f') return 0;
285*odig = (idig & (uchar)0x0f) + (uchar)0x09;
286return 1;
287}
unsigned char uchar

Referenced by unhex().

+ Here is the caller graph for this function:

◆ emsg()

int emsg ( int  rc,
char *  msg 
)

Definition at line 309 of file XrdSectestServer.cc.

309 {
310 std::cerr << "testServer: " <<msg <<std::endl;
311 if (!rc) return 0;
312 exit(rc);
313 }

Referenced by XrdOfsEvr::theEvent::theEvent(), XrdTlsContext::XrdTlsContext(), XrdOuca2x::a2fm(), XrdOuca2x::a2fm(), XrdOuca2x::a2i(), XrdOuca2x::a2ll(), XrdOuca2x::a2sn(), XrdOuca2x::a2sp(), XrdOuca2x::a2sz(), XrdOuca2x::a2tm(), XrdOuca2x::a2vp(), XrdSecProtocolkrb5::Authenticate(), getargs(), main(), XrdPosixXrootd::QueryError(), XrdPosixXrootd::QueryError(), XrdOucErrInfo::setErrInfo(), XrdAccSciTokens::Validate(), Macaroons::Authz::Validate(), and xerr().

+ Here is the caller graph for this function:

◆ Ereason()

const char * Ereason ( )

Definition at line 299 of file XrdSectestServer.cc.

299 {
300 return XrdSysE2T(errno);
301 }
const char * XrdSysE2T(int errcode)
Definition XrdSysE2T.cc:104

References XrdSysE2T().

Referenced by getargs(), and getbintix().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getargs()

void getargs ( int  argc,
char **  argv 
)

Definition at line 205 of file XrdSectestServer.cc.

206 {
207 extern int optind; extern char *optarg; char c;
208
209/* Establish defaults here.
210*/
211 opts.debug = 0;
212 opts.bin = 0;
213 opts.online = 0;
214 opts.cfn = 0;
215 opts.host = 0;
216 opts.xtra = 0;
217 opts.inpt = (char *)"";
218 opts.infid = stdin;
219 opts.cfn = 0;
220
221/* Process the options
222*/
223while ((c=getopt(argc,argv,"c:h:i:k:p:bdx")) != (char)EOF)
224 { switch(c)
225 {
226 case 'b': opts.bin = 1; break;
227 case 'c': opts.cfn = optarg; break;
228 case 'd': opts.debug = 1; break;
229 case 'h': opts.host = optarg; break;
230 case 'i': opts.inpt = optarg; break;
231 case 'x': opts.xtra = 1; break;
232 case '?': help(1);
233 }
234 }
235
236/*Get the credentials, if specified on the command line.
237*/
238if (optind < argc) {opts.inpt = argv[optind++]; opts.online = 1;}
239
240/*Make sure no more parameters exist.
241*/
242if (optind < argc) xerr(insx("Extraneous parameter, '%s'.", argv[optind]));
243
244/*If the input stream is other than stdin, verify that it exists.
245*/
246if (opts.inpt[0] != '\000' && !opts.online
247 && (!(opts.infid = fopen(opts.inpt, "r"))) )
248 xerr(insy("Cannot open '%s'; %s.", opts.inpt, Ereason() ));
249
250/* Make sure that -i * and -b are not specified together.
251*/
252if (opts.online && opts.bin)
253 emsg(8, (char *)"-b is incompatible with inline creds.");
254
255/*All done
256*/
257 return;
258 }
int optind
#define fopen(a, b)
Definition XrdPosix.hh:54
void xerr(int x)
#define insy(a, b, c)
void help(int rc)
struct myOpts opts
const char * Ereason()
int emsg(int rc, char *msg)
#define insx(a, b)

References myOpts::bin, myOpts::cfn, myOpts::debug, emsg(), Ereason(), fopen, help(), myOpts::host, myOpts::infid, myOpts::inpt, insx, insy, myOpts::online, optind, opts, xerr(), and myOpts::xtra.

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getbintix()

int getbintix ( uchar buff,
int  blen 
)

Definition at line 189 of file XrdSectestServer.cc.

189 {
190int i, j;
191 for (i = 0; i < blen; i++)
192 if ((j = getc(opts.infid)) >= 0) buff[i] = (uchar)j;
193 else if (j == EOF) return i;
194 else xerr(insx("Error reading cred; %s.", Ereason()));
195 xerr(insx("Cred longer than %d bytes.", blen));
196 return -1;
197}

References Ereason(), myOpts::infid, insx, opts, and xerr().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getline()

void getline ( uchar buff,
int  blen 
)

Definition at line 291 of file XrdSectestServer.cc.

291 {
292 int i;
293 if (!fgets((char *)buff, blen, opts.infid)) return;
294 for (i = 0; i < blen; i++)
295 if (buff[i] == '\n') {buff[i] = '\000'; break;}
296 return;
297 }

References myOpts::infid, and opts.

Referenced by encode_xrootd_opaque_to_uri(), and main().

+ Here is the caller graph for this function:

◆ help()

void help ( int  rc)

Definition at line 317 of file XrdSectestServer.cc.

317 {
318/* Use H macro to avoid Sun string catenation bug. */
319I("Syntax: testServer [ options ] cred ]")
320I("Options: -b -c config -d -h -i input -t")
321H(" -p principal[.instance][@realm] -s sep")
322I("Function: Display the credentials contents.")
323
324if (rc > 1) exit(rc);
325I("options: (defaults: -k /etc/srvtab\\n")
326I("-b indicates the cred is in binary format (i.e., not hexchar).")
327I("-c cfn the config file.")
328I("-d turns on debugging.")
329I("-h host the incoming hostname.")
330I("-i input specifies the input stream (e.g., fname) if other than stdin.")
331H(" This -i is ignored if cred is specified on the command line.")
332exit(rc);
333}
void Display()
Definition XrdCks.cc:56
#define I(x)
#define H(x)
if(ec< 0) ec

References H, and I.

Referenced by getargs().

+ Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 105 of file XrdSectestServer.cc.

106{
107 XrdNetAddr theAddr;
108 XrdOucErrInfo einfo;
110 XrdSecService *ServerSecurity;
111 XrdSecParameters *parmp;
112 XrdSecCredentials cred((char *)malloc(8192), 8192);
113 XrdSecProtocol *pp;
114 const char *eText;
115 unsigned char bbuff[4096];
116 int i, rc;
117
118// Parse the argument list.
119//
120 getargs(argc, argv);
121
122// if hostname given, get the hostname address
123//
124 if (opts.host)
125 {if ((eText = theAddr.Set(opts.host,0)))
126 {std::cerr <<"testServer: Unable to resolve '" <<opts.host <<"'; " <<eText <<std::endl;
127 exit(1);
128 }
129 }
130 else theAddr.Set("localhost",0);
131
132// Create a new security server
133//
134 ServerSecurity = XrdSecgetService(&Logger, opts.cfn);
135 if (!ServerSecurity)
136 {std::cerr <<"testServer: Unable to create server." <<std::endl; exit(1);}
137
138// Get the security token and display it
139//
140 const char *sect = ServerSecurity->getParms(i, opts.host);
141 if (!sect) std::cerr <<"testServer: No security token for " <<opts.host <<std::endl;
142 else std::cerr <<"testServer: " <<i <<" bytes of SecToken='" <<sect <<"'" <<std::endl;
143
144//Get the credentials from whatever source was specified
145//
146 if (opts.bin) cred.size = getbintix((uchar *)cred.buffer, cred.size);
147 else {if (opts.online) strcpy((char *)bbuff, opts.inpt);
148 else getline(bbuff, sizeof(bbuff));
149 cred.size = unhex(bbuff, (uchar *)cred.buffer, cred.size);
150 }
151
152// Verify the length
153//
154 if (cred.size < 0) emsg(100,(char *)"Invalid credentials format.");
155
156// Get the protocol
157//
158 if (!(pp = ServerSecurity->getProtocol(opts.host, theAddr,
159 (const XrdSecCredentials *)&cred,
160 &einfo)))
161 {rc = einfo.getErrInfo();
162 std::cerr << "testServer: getProtocol error " <<rc <<"; ";
163 std::cerr <<einfo.getErrText() <<std::endl;
164 exit(1);
165 }
166
167// Now convert the credentials
168//
169 if (pp->Authenticate(&cred, &parmp, &einfo) < 0)
170 {rc = einfo.getErrInfo();
171 std::cerr << "testServer: Authenticate error " <<rc <<"; ";
172 std::cerr <<einfo.getErrText() <<std::endl;
173 exit(1);
174 }
175
176// Tell everyone what the client identity is.
177//
178 std::cout <<(pp->Entity.name ? pp->Entity.name : "?")
179 <<"@" <<(pp->Entity.host ? pp->Entity.host : "?")
180 <<" prot=" <<pp->Entity.prot <<std::endl;
181
182// All done
183//
184 exit(0);
185}
static XrdSysLogger Logger
int getbintix(uchar *buff, int blen)
void getline(uchar *buff, int blen)
XrdSecService * XrdSecgetService(XrdSysLogger *lp, const char *cfn)
int unhex(uchar *ibuff, uchar *obuff, int blen)
void getargs(int argc, char **argv)
const char * Set(const char *hSpec, int pNum=PortInSpec)
const char * getErrText()
char * name
Entity's name.
char * host
Entity's host name dnr dependent.
XrdSecEntity Entity
virtual int Authenticate(XrdSecCredentials *cred, XrdSecParameters **parms, XrdOucErrInfo *einfo=0)=0
virtual XrdSecProtocol * getProtocol(const char *host, XrdNetAddrInfo &endPoint, const XrdSecCredentials *cred, XrdOucErrInfo &einfo)=0
virtual const char * getParms(int &size, XrdNetAddrInfo *endPoint=0)=0
Generic structure to pass security information back and forth.

References XrdSecProtocol::Authenticate(), myOpts::bin, XrdSecBuffer::buffer, myOpts::cfn, emsg(), XrdSecProtocol::Entity, getargs(), getbintix(), XrdOucErrInfo::getErrInfo(), XrdOucErrInfo::getErrText(), getline(), XrdSecService::getParms(), XrdSecService::getProtocol(), XrdSecEntity::host, myOpts::host, myOpts::inpt, Logger, XrdSecEntity::name, myOpts::online, opts, XrdSecEntity::prot, XrdNetAddr::Set(), XrdSecBuffer::size, unhex(), and XrdSecgetService().

+ Here is the call graph for this function:

◆ unhex()

int unhex ( uchar ibuff,
uchar obuff,
int  blen 
)

Definition at line 269 of file XrdSectestServer.cc.

269 {
270int i=0, j;
271uchar dig1, dig2;
272
273for (j = 0; j < blen; j++) {
274 if (!ibuff[i]) return j;
275 if (!cvtx(ibuff[i++], &dig1) || !cvtx(ibuff[i++], &dig2)) return -1;
276 obuff[j] = (dig1 << 4) | dig2;
277 }
278return -1; /* Buffer overflow */
279 }
int cvtx(uchar idig, uchar *odig)

References cvtx().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ xerr()

void xerr ( int  x)

Definition at line 305 of file XrdSectestServer.cc.

305{ emsg(8, errbuff); }
char errbuff[256]

References emsg(), and errbuff.

Referenced by getargs(), getbintix(), and XProtocol::toErrno().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ XrdSecgetService()

XrdSecService * XrdSecgetService ( XrdSysLogger lp,
const char *  cfn 
)
extern

Definition at line 1195 of file XrdSecServer.cc.

1196{
1197 XrdSecServer *SecServer = new XrdSecServer(lp);
1198
1199// Configure the server object
1200//
1201 if (SecServer->Configure(cfn)) return 0;
1202
1203// Return the server object
1204//
1205 return (XrdSecService *)SecServer;
1206}
int Configure(const char *cfn)

References XrdSecServer::Configure().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ errbuff

char errbuff[256]

Definition at line 75 of file XrdSectestServer.cc.

Referenced by xerr().

◆ hexbuff

char hexbuff[256]

Definition at line 77 of file XrdSectestServer.cc.

◆ opts

struct myOpts opts

Referenced by XrdOucNSWalk::XrdOucNSWalk(), XrdRmcData::XrdRmcData(), XrdSecProtocolgsi::XrdSecProtocolgsi(), XrdSecProtocolpwd::XrdSecProtocolpwd(), XrdSutBuffer::XrdSutBuffer(), XrdSutBuffer::XrdSutBuffer(), XrdTlsContext::XrdTlsContext(), XrdXrootdJob2Do::XrdXrootdJob2Do(), XrdInet::Accept(), XrdNet::Accept(), XrdNet::Accept(), XrdLinkCtl::Alloc(), XrdNet::Bind(), XrdNet::Bind(), XrdInet::BindSD(), XrdCpConfig::Config(), XrdInet::Connect(), XrdNet::Connect(), XrdNet::Connect(), XrdOssWrapper::Create(), XrdNetSocket::Create(), XrdXrootdMonFile::Defaults(), XrdOssCsiPages::FetchRange(), XrdOssCsiPages::FetchRangeAligned(), XrdOssCsiPages::FetchRangeUnaligned(), XrdOssCsiPages::FetchRangeUnaligned_postblock(), XrdOssCsiPages::FetchRangeUnaligned_preblock(), XrdNetUtils::GetAddrs(), XrdNetUtils::GetAddrs(), XrdNetRegistry::GetAddrs(), XrdNetUtils::GetAddrs(), getargs(), getbintix(), XrdCl::Utils::GetHostAddresses(), getline(), XrdOssSpace::Init(), XrdOssCsiFileAio::Init(), XrdNetUtils::IPFormat(), XrdNetUtils::IPFormat(), XrdCmsCluster::List(), main(), main(), XrdOssMio::Map(), XrdOucCacheIO::pgRead(), XrdPosixFile::pgRead(), XrdPosixExtra::pgRead(), XrdOssCsiFile::pgRead(), XrdOfsHanOssErr::pgRead(), XrdOssWrapDF::pgRead(), XrdOssDFHandler::pgRead(), XrdOssStats::File::pgRead(), XrdPfc::IOFile::pgRead(), XrdOucCacheIO::pgRead(), XrdPosixFile::pgRead(), XrdOssCsiFile::pgRead(), XrdOfsHanOssErr::pgRead(), XrdOssDF::pgRead(), XrdOssWrapDF::pgRead(), XrdOssDFHandler::pgRead(), XrdOssStats::File::pgRead(), XrdOfsFile::pgRead(), XrdSfsFile::pgRead(), XrdThrottle::File::pgRead(), XrdOfsFile::pgRead(), XrdThrottle::File::pgRead(), XrdOucCacheIO::pgWrite(), XrdOssCsiFile::pgWrite(), XrdOssDF::pgWrite(), XrdOssWrapDF::pgWrite(), XrdOssDFHandler::pgWrite(), XrdPssFile::pgWrite(), XrdOssStats::File::pgWrite(), XrdOucCacheIO::pgWrite(), XrdOssCsiFile::pgWrite(), XrdOssDF::pgWrite(), XrdOssWrapDF::pgWrite(), XrdOssDFHandler::pgWrite(), XrdPssFile::pgWrite(), XrdOssStats::File::pgWrite(), XrdOfsFile::pgWrite(), XrdSfsFile::pgWrite(), XrdThrottle::File::pgWrite(), XrdThrottle::File::pgWrite(), XrdOfsFile::pgWrite(), XrdSfsFile::pgWrite(), XrdOssCsiPages::pgWritePrelockCheck(), XrdOucCacheIO::Preread(), XrdNet::Relay(), XrdOssSys::Remdir(), XrdSysThread::Run(), XrdOucSxeq::Serialize(), XrdTlsContext::SessionCache(), XrdXrootdXPath::Set(), XrdSecProtocolkrb5::setClientOpts(), XrdTls::SetDebug(), XrdTls::SetDebug(), XrdAccGroups::SetOptions(), XrdNetSocket::setOpts(), XrdSecProtocolkrb5::setOpts(), XrdOssSys::Stat(), XrdOssStats::FileSystem::Stat(), XrdOssWrapper::Stat(), XrdOssCsi::Stat(), XrdOssHandler::Stat(), XrdOssAt::Stat(), XrdOssSys::StatPF(), XrdOssWrapper::StatPF(), XrdOssCsi::StatPF(), XrdOssHandler::StatPF(), XrdOssStats::FileSystem::StatPF(), XrdStats::Stats(), XrdXrootdStats::Stats(), XrdOssCsiPages::StoreRange(), XrdOssStatInfo(), XrdSecProtocolgsiInit(), XrdSecProtocolkrb5Init(), XrdSecProtocolpwdInit(), XrdSecProtocolztnInit(), and XrdSsiStatInfo().