XRootD
Loading...
Searching...
No Matches
XrdSectestClient.cc File Reference
#include <unistd.h>
#include <cctype>
#include <cerrno>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <sys/param.h>
#include "XrdNet/XrdNetAddr.hh"
#include "XrdSys/XrdSysHeaders.hh"
#include "XrdSec/XrdSecInterface.hh"
+ Include dependency graph for XrdSectestClient.cc:

Go to the source code of this file.

Macros

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

Functions

void help (int rc)
 
int main (int argc, char **argv)
 
char * tohex (char *inbuff, int inlen, char *outbuff)
 
XrdSecProtocolXrdSecGetProtocol (const char *hostname, XrdNetAddrInfo &endPoint, XrdSecParameters &parms, XrdOucErrInfo *einfo=0)
 

Macro Definition Documentation

◆ H

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

Definition at line 64 of file XrdSectestClient.cc.

◆ I

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

Definition at line 65 of file XrdSectestClient.cc.

Function Documentation

◆ help()

void help ( int  rc)

Definition at line 187 of file XrdSectestClient.cc.

187 {
188/* Use H macro to avoid Sun string catenation bug. */
189I("Syntax: testClient [ options ] [sectoken]")
190I("Options: -b -d -l -h host")
191I("Function: Request for credentials relative to an operation.")
192
193if (rc > 1) exit(rc);
194I("options: (defaults: -o 01")
195I("-b output the ticket in binary format (i.e., not hexchar).")
196I("-d turns on debugging.")
197I("-l prefixes the ticket with its 4-byte length.")
198I("-h host the requesting hostname (default is localhost).")
199I("Notes: 1. Variable XrdSecSECTOKEN must contain the security token,")
200H(" sectoken, if it is not specified on the command line.")
201exit(rc);
202}
#define I(x)
#define H(x)
if(ec< 0) ec

References H, and I.

Referenced by main().

+ Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 71 of file XrdSectestClient.cc.

72{
73char *tohex(char *inbuff, int inlen, char *outbuff);
74
75char *protocols=0, *hostspec=0;
76
77XrdNetAddr theAddr;
78
79int putbin = 0, putlen = 0;
80char kbuff[8192];
81char c;
82
84XrdSecParameters SecToken;
86int DebugON = 0;
87void help(int);
88
89
90 /*Get all of the options.
91 */
92 while ((c=getopt(argc,argv,"bdlh:")) != (char)EOF)
93 { switch(c)
94 {
95 case 'b': putbin = 1; break;
96 case 'd': DebugON = 1; break;
97 case 'h': hostspec = optarg; break;
98 case 'l': putlen = 1; break;
99 default: help(1);
100 }
101 }
102
103// Check if the security token is the last argument
104//
105 if (optind < argc) protocols = argv[optind++];
106
107/*Make sure no more parameters exist.
108*/
109 if (optind < argc)
110 {std::cerr <<"testClient: Extraneous parameter, '" <<argv[optind] <<"'." <<std::endl;
111 help(2);
112 }
113
114// Determine protocol string
115//
116 if (!protocols && !(protocols = getenv("XrdSecSECTOKEN")))
117 {std::cerr <<"testClient: Security protocol string not specified." <<std::endl;
118 help(2);
119 }
120 SecToken.size = strlen(protocols);
121 SecToken.buffer = protocols;
122
123// if hostname given, get the hostname address
124//
125 if (hostspec && (eText = theAddr(hostspec,0)))
126 {std::cerr <<"testServer: Unable to resolve '" <<hostspec <<"'; " <<eText <<std::endl;
127 exit(1);
128 } else theAddr.Set("localhost",0);
129
130// Do debug processing
131//
132 if (DebugON)
133 {putenv((char *)"XrdSecDEBUG=1");
134 std::cerr <<"testClient: security token='" <<protocols <<"'" <<std::endl;
135 }
136
137// Get the protocol
138//
139 pp = XrdSecGetProtocol(hostspec, theAddr, SecToken, 0);
140 if (!pp) {std::cerr << "Unable to get protocol." <<std::endl; exit(1);}
141
142// Get credentials using this context
143//
144 pp->addrInfo = &theAddr;
145 cred = pp->getCredentials();
146 if (!cred)
147 {std::cerr << "Unable to get credentials," <<std::endl;
148 exit(1);
149 }
150 if (DebugON)
151 std::cerr << "testClient: credentials size=" <<cred->size <<std::endl;
152
153// Write out the credentials
154//
155 if (putbin)
156 {if (putlen)
157 {if (fwrite(&cred->size, sizeof(cred->size), 1, stdout) != sizeof(cred->size))
158 {std::cerr << "Unable to write credentials length" <<std::endl;
159 exit(1);}}
160 if (fwrite((char *) cred->buffer, cred->size, 1, stdout) != (size_t) cred->size)
161 {std::cerr << "Unable to write credentials" <<std::endl;
162 exit(1);}
163 } else {
164 if (putlen) printf("%s",
165 tohex((char *)&cred->size, sizeof(cred->size), kbuff));
166 printf("%s\n", tohex((char *) cred->buffer, cred->size, kbuff));
167 }
168
169// All done.
170//
171 pp->Delete();
172}
int DebugON
int optind
#define fwrite(b, s, n, f)
Definition XrdPosix.hh:72
XrdSecProtocol * XrdSecGetProtocol(const char *hostname, XrdNetAddrInfo &endPoint, XrdSecParameters &parms, XrdOucErrInfo *einfo=0)
void help(int rc)
char * tohex(char *inbuff, int inlen, char *outbuff)
const char * Set(const char *hSpec, int pNum=PortInSpec)
virtual XrdSecCredentials * getCredentials(XrdSecParameters *parm=0, XrdOucErrInfo *einfo=0)=0
virtual void Delete()=0
Delete the protocol object. DO NOT use C++ delete() on this object.
Generic structure to pass security information back and forth.
char * buffer
Pointer to the buffer.
int size
Size of the buffer or length of data in the buffer.

References XrdSecBuffer::buffer, DebugON, XrdSecProtocol::Delete(), fwrite, XrdSecProtocol::getCredentials(), help(), optind, XrdNetAddr::Set(), XrdSecBuffer::size, tohex(), and XrdSecGetProtocol().

+ Here is the call graph for this function:

◆ tohex()

char * tohex ( char *  inbuff,
int  inlen,
char *  outbuff 
)

Definition at line 174 of file XrdSectestClient.cc.

174 {
175 static const char hv[] = "0123456789abcdef";
176 int i, j = 0;
177 for (i = 0; i < inlen; i++) {
178 outbuff[j++] = hv[(inbuff[i] >> 4) & 0x0f];
179 outbuff[j++] = hv[ inbuff[i] & 0x0f];
180 }
181 outbuff[j] = '\0';
182 return outbuff;
183 }

Referenced by main().

+ Here is the caller graph for this function:

◆ XrdSecGetProtocol()

XrdSecProtocol * XrdSecGetProtocol ( const char *  hostname,
XrdNetAddrInfo endPoint,
XrdSecParameters parms,
XrdOucErrInfo einfo = 0 
)
extern

Definition at line 86 of file XrdSecClient.cc.

90{
91 static int DebugON = ((getenv("XrdSecDEBUG") &&
92 strcmp(getenv("XrdSecDEBUG"), "0")) ? 1 : 0);
93 static XrdSecProtNone ProtNone;
94 static XrdSecPManager PManager(DebugON, getenv("XrdSecPROXY") != 0,
95 getenv("XrdSecPROXYCREDS") != 0);
96 const char *noperr = "XrdSec: No authentication protocols are available.";
97
98 XrdSecProtocol *protp;
99
100// Perform any required debugging
101//
102 DEBUG("protocol request for host " <<hostname <<" token='"
103 <<(parms.size > 0 ? std::setw(parms.size) : std::setw(1))
104 <<(parms.size > 0 ? parms.buffer : "") <<"'");
105
106// Check if the server wants no security.
107//
108 if (!parms.size || !parms.buffer[0]) return (XrdSecProtocol *)&ProtNone;
109
110// Find a supported protocol.
111//
112 if (!(protp = PManager.Get(hostname, endPoint, parms, einfo)))
113 {if (einfo) einfo->setErrInfo(ENOPROTOOPT, noperr);
114 else std::cerr <<noperr <<std::endl;
115 }
116
117// All done
118//
119 return protp;
120}
#define DEBUG(x)
int setErrInfo(int code, const char *emsg)

References XrdSecBuffer::buffer, DEBUG, DebugON, XrdSecPManager::Get(), XrdOucErrInfo::setErrInfo(), and XrdSecBuffer::size.

Referenced by main().

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