authclient.C

Go to the documentation of this file.
00001 //--------------------------------------------------
00002 #include "TPSocket.h"
00003 
00004 //
00005 // This macro should be run together with authserv.C to test
00006 // authentication between two remote ROOT sessions. 
00007 // Run first the authserv.C within a ROOT session on the server
00008 // machine, eg. "srv.machi.ne":
00009 //
00010 //          root[] .x authserv.C(3000)
00011 //
00012 // authserv accepts as argument the port wher it starts listening
00013 // (default 3000).
00014 // You can then run authclient.c in a ROOT session on the client
00015 // machine:
00016 //          root[] .x authclient.C("srv.machi.ne:3000")
00017 //
00018 // and you should get prompted for the credentials, if the case.
00019 // To start a parallel socket of size, for example, 5, enter the
00020 // size as second argument, ie
00021 //
00022 //          root[] .x authclient.C("srv.machi.ne:3000",5)
00023 //
00024 
00025 int authclient(const char *host = "up://localhost:3000", int sz = 0)
00026 {
00027    Int_t par = (sz > 1) ? 1 : 0;
00028 
00029    // Parse protocol, if any
00030    TString proto(TUrl(host).GetProtocol());
00031    TString protosave = proto;
00032 
00033    // Get rid of authentication suffix
00034    TString asfx = proto;
00035    if (proto.EndsWith("up") || proto.EndsWith("ug")) {
00036       asfx.Remove(0,proto.Length()-2);
00037       proto.Resize(proto.Length()-2);
00038    } else if (proto.EndsWith("s") || proto.EndsWith("k") ||
00039               proto.EndsWith("g") || proto.EndsWith("h")) {
00040       asfx.Remove(0,proto.Length()-1);
00041       proto.Resize(proto.Length()-1);
00042    }
00043 
00044    // Force parallel (even of size 1)
00045    TString newurl = "p" + asfx;
00046    newurl += "://";
00047    if (strlen(TUrl(host).GetUser())) {
00048       newurl += TUrl(host).GetUser();
00049       newurl += "@";
00050    }
00051    newurl += TUrl(host).GetHost();
00052    newurl += ":";
00053    newurl += TUrl(host).GetPort();
00054 
00055    cout << "authclient: starting a (parallel) authenticated socket at "
00056         << newurl.Data() << " (size: " << sz << ")" << endl;
00057 
00058    TSocket *s = TSocket::CreateAuthSocket(newurl.Data(),sz);
00059 
00060    // Print out;
00061    if (s) 
00062       if (s->IsAuthenticated()) 
00063          cout << "authclient: auth socket: OK" << endl;
00064       else
00065          cout << "authclient: auth socket: failed" << endl;
00066 
00067    // Cleanup
00068    if (s) {
00069       // Remove this authentication from the token list to avoid
00070       // later warnings
00071       s->GetSecContext()->DeActivate("R");
00072       delete s;
00073    }
00074 }
00075 //--------------------------------------------------
00076 

Generated on Tue Jul 5 15:44:51 2011 for ROOT_528-00b_version by  doxygen 1.5.1