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);
98 string execdir, etcdir;
100 execdir = string(ROOTBINDIR);
103 etcdir = string(ROOTETCDIR);
107 if (!execdir.length())
108 execdir =
string(confdir).append(
"/bin");
110 if (execdir.length()) {
111 int len = 15 + execdir.length();
112 char *tmp =
new char[len+1];
114 snprintf(tmp,len+1,
"ROOTBINDIR=%.*s", len, execdir.c_str());
121 if (!etcdir.length())
122 etcdir =
string(confdir).append(
"/etc");
124 if (etcdir.length()) {
125 int len = 15 + etcdir.length();
126 char *tmp =
new char[len+1];
128 snprintf(tmp, len+1,
"ROOTETCDIR=%.*s", len, etcdir.c_str());
135 string daemonrc = string(
gEnv->
GetValue(
"SrvAuth.DaemonRc",
""));
136 if (daemonrc.length()) {
137 int len = 15 + daemonrc.length();
138 char *tmp =
new char[len+1];
140 snprintf(tmp, len+1,
"ROOTDAEMONRC=%.*s", len, daemonrc.c_str());
147 string gridmap = string(
gEnv->
GetValue(
"SrvAuth.GridMap",
""));
148 if (gridmap.length()) {
149 int len = 15 + gridmap.length();
150 char *tmp =
new char[len+1];
152 snprintf(tmp, len+1,
"GRIDMAP=%.*s", len, gridmap.c_str());
159 string hcconf = string(
gEnv->
GetValue(
"SrvAuth.HostCert",
""));
160 if (hcconf.length()) {
161 int len = 15 + hcconf.length();
162 char *tmp =
new char[len+1];
164 snprintf(tmp, len+1,
"ROOTHOSTCERT=%.*s", len, hcconf.c_str());
176 void Err(
int level,
const char *msg,
int size)
178 Perror((
char *)msg, size);
184 void ErrFatal(
int level,
const char *msg,
int size)
186 Perror((
char *)msg, size);
192 void ErrSys(
int level,
const char *msg,
int size)
194 Perror((
char *)msg, size);
206 if (!strncmp(nsc->
GetID(),
"server",6)) {
209 ErrorInfo(
"SrvClupImpl: operation unsuccessful (rc: %d, ctkn: %s)",
232 string altSRPpass = string(
gEnv->
GetValue(
"SrvAuth.SRPpassfile",
""));
243 int parentid = getpid();
246 unsigned int options = kDMN_RQAUTH | kDMN_HOSTEQ;
248 options &= ~kDMN_HOSTEQ;
256 tmpdir, altSRPpass.c_str());
272 int clientprotocol = 0;
284 if (!(strncmp(seccontext->
GetID(),
"server",6))) {
286 if (!strcmp(openhost.c_str(),seccontext->
GetHost())) {
287 if (!strcmp(user.c_str(),seccontext->
GetUser()))
298 seccontext =
new TSecContext(user.c_str(), openhost.c_str(), meth, -1,
299 "server", ctoken.c_str());
302 secctxlist->
Add(seccontext);
307 ErrorInfo(
"SrvAuthImpl: could not create sec context object" 308 ": potential problems in cleaning");
336 static int Recvn(
int sock,
void *buffer,
int length)
338 if (sock < 0)
return -1;
341 char *buf = (
char *)buffer;
343 for (n = 0; n < length; n += nrecv) {
344 while ((nrecv = recv(sock, buf+n, length-n, 0)) == -1
349 "Recvn: error (sock: %d): errno: %d",sock,
GetErrno());
351 }
else if (nrecv == 0)
390 return gSocket->
Recv(msg, max);
400 Int_t rc = gSocket->
Recv(msg, len, tmpkind);
416 len = ntohl(hdr[0]) -
sizeof(int);
419 buf =
new char* [len];
432 return gSocket->
RecvRaw(buf,len);
440 if (sock == -1)
return -1;
442 if (
Recvn(sock, buf, len) < 0) {
444 "NetRecvRaw: Recvn error (sock: %d, errno: %d)",sock,
GetErrno());
456 int hlen =
sizeof(int) +
sizeof(
int);
457 hdr[0] = htonl(hlen);
458 hdr[1] = htonl(kind);
459 hdr[2] = htonl(code);
461 return gSocket->
SendRaw(hdr,
sizeof(hdr));
469 return gSocket->
Send(msg, kind);
478 int hlen =
sizeof(int) + len;
479 hdr[0] = htonl(hlen);
480 hdr[1] = htonl(kind);
481 if (gSocket->
SendRaw(hdr,
sizeof(hdr)) < 0)
484 return gSocket->
SendRaw(buf, len);
508 return gSocket->
SendRaw(buf, len);
548 int len = strlen(buf);
549 #if (defined(__sun) && defined (__SVR4)) || defined (__linux) || \ 550 defined(_AIX) || defined(__MACH__) 567 va_start(ap,
va_(fmt));
568 vsprintf(buf, fmt, ap);
581 va_start(ap,
va_(fmt));
582 vsprintf(buf, fmt, ap);
589 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
void RpdSetMethInitFlag(int methinit)
This namespace contains pre-defined functions to be used in conjuction with TExecutor::Map and TExecu...
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)
void RpdInit(EService serv, int pid, int sproto, unsigned int opts, int rumsk, int sshp, const char *tmpd, const char *asrpp, int login=0)
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.
int RpdCleanupAuthTab(const char *crypttoken)
void SrvSetSocket(TSocket *Socket)
Fill socket parameters.
void RpdSetErrorHandler(ErrorHandler_t Err, ErrorHandler_t Sys, ErrorHandler_t Fatal)
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.
virtual Int_t GetValue(const char *name, Int_t dflt)
Returns the integer value for a resource.
static Int_t SrvSetVars(string confdir)
Set relevant environment variables.
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)
int NetSendAck()
Send acknowledge code.
double func(double *x, double *p)
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
virtual Int_t RecvRaw(void *buffer, Int_t length, ESendRecvOptions opt=kDefault)
Receive a raw buffer of specified length bytes.
int RpdInitSession(int, std::string &, int &, int &, int &, std::string &)
void Error(ErrorHandler_t func, int code, const char *va_(fmt),...)
Write error message and call a handler, if required.