swh:1:snp:af87cd67498ef4fe47c76ed3e7caffe5b61facaf
Raw File
Tip revision: 59fe6578eda8d4c55e125a80e956ef4431ab5322 authored by Pere Mato on 04 March 2016, 14:47:28 UTC
Update ROOT version files to v6.07/04.
Tip revision: 59fe657
authclient.C
//--------------------------------------------------
#include "TPSocket.h"

//
// This macro should be run together with authserv.C to test
// authentication between two remote ROOT sessions.
// Run first the authserv.C within a ROOT session on the server
// machine, eg. "srv.machi.ne":
//
//          root[] .x authserv.C(3000)
//
// authserv accepts as argument the port wher it starts listening
// (default 3000).
// You can then run authclient.c in a ROOT session on the client
// machine:
//          root[] .x authclient.C("srv.machi.ne:3000")
//
// and you should get prompted for the credentials, if the case.
// To start a parallel socket of size, for example, 5, enter the
// size as second argument, ie
//
//          root[] .x authclient.C("srv.machi.ne:3000",5)
//

int authclient(const char *host = "up://localhost:3000", int sz = 0)
{
   Int_t par = (sz > 1) ? 1 : 0;

   // Parse protocol, if any
   TString proto(TUrl(host).GetProtocol());
   TString protosave = proto;

   // Get rid of authentication suffix
   TString asfx = proto;
   if (proto.EndsWith("up") || proto.EndsWith("ug")) {
      asfx.Remove(0,proto.Length()-2);
      proto.Resize(proto.Length()-2);
   } else if (proto.EndsWith("s") || proto.EndsWith("k") ||
              proto.EndsWith("g") || proto.EndsWith("h")) {
      asfx.Remove(0,proto.Length()-1);
      proto.Resize(proto.Length()-1);
   }

   // Force parallel (even of size 1)
   TString newurl = "p" + asfx;
   newurl += "://";
   if (strlen(TUrl(host).GetUser())) {
      newurl += TUrl(host).GetUser();
      newurl += "@";
   }
   newurl += TUrl(host).GetHost();
   newurl += ":";
   newurl += TUrl(host).GetPort();

   cout << "authclient: starting a (parallel) authenticated socket at "
        << newurl.Data() << " (size: " << sz << ")" << endl;

   TSocket *s = TSocket::CreateAuthSocket(newurl.Data(),sz);

   // Print out;
   if (s)
      if (s->IsAuthenticated())
         cout << "authclient: auth socket: OK" << endl;
      else
         cout << "authclient: auth socket: failed" << endl;

   // Cleanup
   if (s) {
      // Remove this authentication from the token list to avoid
      // later warnings
      s->GetSecContext()->DeActivate("R");
      delete s;
   }
}
//--------------------------------------------------

back to top