XRootD
XrdSecClient.cc
Go to the documentation of this file.
1 /******************************************************************************/
2 /* */
3 /* X r d S e c C l i e n t . c c */
4 /* */
5 /* (c) 2003 by the Board of Trustees of the Leland Stanford, Jr., University */
6 /* All Rights Reserved */
7 /* Produced by Andrew Hanushevsky for Stanford University under contract */
8 /* DE-AC02-76-SFO0515 with the Department of Energy */
9 /* */
10 /* This file is part of the XRootD software suite. */
11 /* */
12 /* XRootD is free software: you can redistribute it and/or modify it under */
13 /* the terms of the GNU Lesser General Public License as published by the */
14 /* Free Software Foundation, either version 3 of the License, or (at your */
15 /* option) any later version. */
16 /* */
17 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */
18 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
19 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
20 /* License for more details. */
21 /* */
22 /* You should have received a copy of the GNU Lesser General Public License */
23 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
24 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
25 /* */
26 /* The copyright holder's institutional names and contributor's names may not */
27 /* be used to endorse or promote products derived from this software without */
28 /* specific prior written permission of the institution or contributor. */
29 /******************************************************************************/
30 
31 #include <unistd.h>
32 #include <cctype>
33 #include <cerrno>
34 #include <netdb.h>
35 #include <cstdlib>
36 #include <cstring>
37 #include <cstdio>
38 #include <iomanip>
39 #include <sys/param.h>
40 #include <sys/types.h>
41 
42 #include "XrdNet/XrdNetAddrInfo.hh"
43 #include "XrdOuc/XrdOucErrInfo.hh"
44 #include "XrdSys/XrdSysHeaders.hh"
45 #include "XrdSys/XrdSysPthread.hh"
46 #include "XrdSec/XrdSecPManager.hh"
48 
49 /******************************************************************************/
50 /* M i s c e l l a n e o u s D e f i n e s */
51 /******************************************************************************/
52 
53 #define DEBUG(x) {if (DebugON) std::cerr <<"sec_Client: " <<x <<std::endl;}
54 
55 /******************************************************************************/
56 /* L o c a l C l a s s e s */
57 /******************************************************************************/
58 
60 {
61 public:
63  XrdSecParameters **parms,
64  XrdOucErrInfo *einfo=0)
65  {return 0;}
66 
68  XrdOucErrInfo *einfo=0)
69  {return new XrdSecCredentials();}
70 
71 void Delete() {} // Never deleted because it's static!
72 
75 };
76 
77 /******************************************************************************/
78 /* X r d S e c G e t P r o t o c o l */
79 /******************************************************************************/
80 
81 // This function is only invoked by the client. It exists in the top level
82 // shared library that interposes between all other protocol shared libraries.
83 //
84 extern "C"
85 {
86 XrdSecProtocol *XrdSecGetProtocol(const char *hostname,
87  XrdNetAddrInfo &endPoint,
88  XrdSecParameters &parms,
89  XrdOucErrInfo *einfo)
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 }
121 }
int DebugON
#define DEBUG(x)
Definition: XrdSecClient.cc:53
XrdSecProtocol * XrdSecGetProtocol(const char *hostname, XrdNetAddrInfo &endPoint, XrdSecParameters &parms, XrdOucErrInfo *einfo)
Definition: XrdSecClient.cc:86
XrdSecBuffer XrdSecCredentials
int setErrInfo(int code, const char *emsg)
XrdSecProtocol * Get(const char *hname, XrdNetAddrInfo &endPoint, const char *pname, XrdOucErrInfo *erp)
int Authenticate(XrdSecCredentials *cred, XrdSecParameters **parms, XrdOucErrInfo *einfo=0)
Definition: XrdSecClient.cc:62
void Delete()
Delete the protocol object. DO NOT use C++ delete() on this object.
Definition: XrdSecClient.cc:71
XrdSecCredentials * getCredentials(XrdSecParameters *parm=0, XrdOucErrInfo *einfo=0)
Definition: XrdSecClient.cc:67
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.