26 #include <sys/socket.h> 27 #include <netinet/in.h> 28 #include <netinet/tcp.h> 29 #include <arpa/inet.h> 34 # include <features.h> 35 # if __GNU_LIBRARY__ == 6 41 #if defined(__MACH__) && !defined(__APPLE__) 47 # if __SUNPRO_CC > 0x420 78 const char *confdir,
const char *tmpdir,
81 return SrvAuthImpl(socket, confdir, tmpdir, user, meth, type, ctkn, secctxlist);
100 if (execdir.length()) {
101 int len = 15 + execdir.length();
102 char *tmp =
new char[len+1];
104 snprintf(tmp,len+1,
"ROOTBINDIR=%.*s", len, execdir.c_str());
112 if (etcdir.length()) {
113 int len = 15 + etcdir.length();
114 char *tmp =
new char[len+1];
116 snprintf(tmp, len+1,
"ROOTETCDIR=%.*s", len, etcdir.c_str());
123 string daemonrc = string(
gEnv->
GetValue(
"SrvAuth.DaemonRc",
""));
124 if (daemonrc.length()) {
125 int len = 15 + daemonrc.length();
126 char *tmp =
new char[len+1];
128 snprintf(tmp, len+1,
"ROOTDAEMONRC=%.*s", len, daemonrc.c_str());
135 string gridmap = string(
gEnv->
GetValue(
"SrvAuth.GridMap",
""));
136 if (gridmap.length()) {
137 int len = 15 + gridmap.length();
138 char *tmp =
new char[len+1];
140 snprintf(tmp, len+1,
"GRIDMAP=%.*s", len, gridmap.c_str());
147 string hcconf = string(
gEnv->
GetValue(
"SrvAuth.HostCert",
""));
148 if (hcconf.length()) {
149 int len = 15 + hcconf.length();
150 char *tmp =
new char[len+1];
152 snprintf(tmp, len+1,
"ROOTHOSTCERT=%.*s", len, hcconf.c_str());
164 void Err(
int level,
const char *msg,
int size)
166 Perror((
char *)msg, size);
172 void ErrFatal(
int level,
const char *msg,
int size)
174 Perror((
char *)msg, size);
180 void ErrSys(
int level,
const char *msg,
int size)
182 Perror((
char *)msg, size);
194 if (!strncmp(nsc->
GetID(),
"server",6)) {
195 int rc = RpdCleanupAuthTab(nsc->
GetToken());
197 ErrorInfo(
"SrvClupImpl: operation unsuccessful (rc: %d, ctkn: %s)",
220 string altSRPpass = string(
gEnv->
GetValue(
"SrvAuth.SRPpassfile",
""));
231 int parentid = getpid();
234 unsigned int options = kDMN_RQAUTH | kDMN_HOSTEQ;
236 options &= ~kDMN_HOSTEQ;
244 tmpdir, altSRPpass.c_str());
247 if (RpdGenRSAKeys(0))
252 RpdSetMethInitFlag(0);
260 int clientprotocol = 0;
261 rc = RpdInitSession(
gService, user, clientprotocol, meth, type, ctoken);
272 if (!(strncmp(seccontext->
GetID(),
"server",6))) {
274 if (!strcmp(openhost.c_str(),seccontext->
GetHost())) {
275 if (!strcmp(user.c_str(),seccontext->
GetUser()))
286 seccontext =
new TSecContext(user.c_str(), openhost.c_str(), meth, -1,
287 "server", ctoken.c_str());
290 secctxlist->
Add(seccontext);
295 ErrorInfo(
"SrvAuthImpl: could not create sec context object" 296 ": potential problems in cleaning");
324 static int Recvn(
int sock,
void *buffer,
int length)
326 if (sock < 0)
return -1;
329 char *buf = (
char *)buffer;
331 for (n = 0; n < length; n += nrecv) {
332 while ((nrecv = recv(sock, buf+n, length-n, 0)) == -1
337 "Recvn: error (sock: %d): errno: %d",sock,
GetErrno());
339 }
else if (nrecv == 0)
378 return gSocket->
Recv(msg, max);
388 Int_t rc = gSocket->
Recv(msg, len, tmpkind);
404 len = ntohl(hdr[0]) -
sizeof(int);
407 buf =
new char* [len];
420 return gSocket->
RecvRaw(buf,len);
428 if (sock == -1)
return -1;
430 if (
Recvn(sock, buf, len) < 0) {
432 "NetRecvRaw: Recvn error (sock: %d, errno: %d)",sock,
GetErrno());
444 int hlen =
sizeof(int) +
sizeof(
int);
445 hdr[0] = htonl(hlen);
446 hdr[1] = htonl(kind);
447 hdr[2] = htonl(code);
449 return gSocket->
SendRaw(hdr,
sizeof(hdr));
457 return gSocket->
Send(msg, kind);
466 int hlen =
sizeof(int) + len;
467 hdr[0] = htonl(hlen);
468 hdr[1] = htonl(kind);
469 if (gSocket->
SendRaw(hdr,
sizeof(hdr)) < 0)
472 return gSocket->
SendRaw(buf, len);
496 return gSocket->
SendRaw(buf, len);
536 int len = strlen(buf);
537 #if (defined(__sun) && defined (__SVR4)) || defined (__linux) || \ 538 defined(_AIX) || defined(__MACH__) 555 va_start(ap,
va_(fmt));
556 vsprintf(buf, fmt, ap);
569 va_start(ap,
va_(fmt));
570 vsprintf(buf, fmt, ap);
577 if (func) (*func)(code,(
const char *)buf,
sizeof(buf));
virtual void Add(TObject *obj)
int NetSendError(ERootdErrors err)
Send error code.
int GetErrno()
return errno
const char * GetToken() const
Namespace for new ROOT classes and functions.
const char * GetHostName() const
static int Recvn(int sock, void *buffer, int length)
Receive exactly length bytes into buffer.
int NetSend(const void *buf, int len, EMessageTypes kind)
Send buffer of len bytes. Message will be of type "kind".
virtual Int_t Send(const TMessage &mess)
Send a TMessage object.
int NetGetSockFd()
return open socket descriptor
virtual Int_t Recv(TMessage *&mess)
Receive a TMessage object.
void ErrorInfo(const char *va_(fmt),...)
Formats a string in a circular formatting buffer and prints the string.
void SetSecContext(TSecContext *ctx)
int NetSendRaw(const void *buf, int len)
Send buffer of len bytes.
const char * GetHost() const
virtual Int_t SendRaw(const void *buffer, Int_t length, ESendRecvOptions opt=kDefault)
Send a raw buffer of specified length.
Sequenceable collection abstract base class.
void SrvSetSocket(TSocket *Socket)
Fill socket parameters.
Int_t SrvClupImpl(TSeqCollection *secls)
Wrapper to cleanup code.
Int_t SrvAuthCleanup(TSeqCollection *sls)
void ErrFatal(int level, const char *msg, int size)
const char * GetUser() const
void(* ErrorHandler_t)(int level, const char *msg, int size)
void ResetErrno()
reset errno
Int_t SrvAuthImpl(TSocket *socket, const char *confdir, const char *tmpdir, string &user, Int_t &meth, Int_t &type, string &ctoken, TSeqCollection *secctxlist)
Server authentication code.
Int_t SrvAuthenticate(TSocket *socket, const char *confdir, const char *tmpdir, string &user, Int_t &meth, Int_t &type, string &ctkn, TSeqCollection *secctxlist)
int NetParOpen(int port, int size)
Empty call, for consistency.
static Int_t gSrvProtocol
const char * GetID() const
void NetGetRemoteHost(std::string &openhost)
Return name of connected host.
void ErrSys(int level, const char *msg, int size)
static Int_t SrvSetVars(string)
Set relevant environment variables.
static const TString & GetEtcDir()
Get the sysconfig directory in the installation. Static utility function.
int NetSendAck()
Send acknowledge code.
int NetRecvRaw(int sock, void *buf, int len)
Receive a buffer of maximum len bytes from generic socket sock.
void NetClose()
Empty call, for consistency.
void Err(int level, const char *msg, int size)
virtual Int_t GetDescriptor() const
void Perror(char *buf, int size)
Return in buf the message belonging to errno.
int NetRecv(void *&buf, int &len, EMessageTypes &kind)
Receive a buffer.
TInetAddress GetInetAddress() const
static const TString & GetBinDir()
Get the binary directory in the installation. Static utility function.
virtual Int_t RecvRaw(void *buffer, Int_t length, ESendRecvOptions opt=kDefault)
Receive a raw buffer of specified length bytes.
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
void Error(ErrorHandler_t func, int code, const char *va_(fmt),...)
Write error message and call a handler, if required.