ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
authclient.C
Go to the documentation of this file.
1 //--------------------------------------------------
2 #include "TPSocket.h"
3 
4 //
5 // This macro should be run together with authserv.C to test
6 // authentication between two remote ROOT sessions.
7 // Run first the authserv.C within a ROOT session on the server
8 // machine, eg. "srv.machi.ne":
9 //
10 // root[] .x authserv.C(3000)
11 //
12 // authserv accepts as argument the port wher it starts listening
13 // (default 3000).
14 // You can then run authclient.c in a ROOT session on the client
15 // machine:
16 // root[] .x authclient.C("srv.machi.ne:3000")
17 //
18 // and you should get prompted for the credentials, if the case.
19 // To start a parallel socket of size, for example, 5, enter the
20 // size as second argument, ie
21 //
22 // root[] .x authclient.C("srv.machi.ne:3000",5)
23 //
24 
25 int authclient(const char *host = "up://localhost:3000", int sz = 0)
26 {
27  Int_t par = (sz > 1) ? 1 : 0;
28 
29  // Parse protocol, if any
30  TString proto(TUrl(host).GetProtocol());
31  TString protosave = proto;
32 
33  // Get rid of authentication suffix
34  TString asfx = proto;
35  if (proto.EndsWith("up") || proto.EndsWith("ug")) {
36  asfx.Remove(0,proto.Length()-2);
37  proto.Resize(proto.Length()-2);
38  } else if (proto.EndsWith("s") || proto.EndsWith("k") ||
39  proto.EndsWith("g") || proto.EndsWith("h")) {
40  asfx.Remove(0,proto.Length()-1);
41  proto.Resize(proto.Length()-1);
42  }
43 
44  // Force parallel (even of size 1)
45  TString newurl = "p" + asfx;
46  newurl += "://";
47  if (strlen(TUrl(host).GetUser())) {
48  newurl += TUrl(host).GetUser();
49  newurl += "@";
50  }
51  newurl += TUrl(host).GetHost();
52  newurl += ":";
53  newurl += TUrl(host).GetPort();
54 
55  cout << "authclient: starting a (parallel) authenticated socket at "
56  << newurl.Data() << " (size: " << sz << ")" << endl;
57 
58  TSocket *s = TSocket::CreateAuthSocket(newurl.Data(),sz);
59 
60  // Print out;
61  if (s)
62  if (s->IsAuthenticated())
63  cout << "authclient: auth socket: OK" << endl;
64  else
65  cout << "authclient: auth socket: failed" << endl;
66 
67  // Cleanup
68  if (s) {
69  // Remove this authentication from the token list to avoid
70  // later warnings
71  s->GetSecContext()->DeActivate("R");
72  delete s;
73  }
74 }
75 //--------------------------------------------------
76 
const char * GetHost() const
Definition: TUrl.h:76
double par[1]
Definition: unuranDistr.cxx:38
Ssiz_t Length() const
Definition: TString.h:390
This class represents a WWW compatible URL.
Definition: TUrl.h:41
Basic string class.
Definition: TString.h:137
int Int_t
Definition: RtypesCore.h:41
const char * Data() const
Definition: TString.h:349
static TSocket * CreateAuthSocket(const char *user, const char *host, Int_t port, Int_t size=0, Int_t tcpwindowsize=-1, TSocket *s=0, Int_t *err=0)
Creates a socket or a parallel socket and authenticates to the remote server specified in 'url' on re...
Definition: TSocket.cxx:1457
virtual Bool_t IsAuthenticated() const
Definition: TSocket.h:161
Int_t GetPort() const
Definition: TUrl.h:87
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
Definition: TString.cxx:2207
virtual void DeActivate(Option_t *opt="CR")
Set OffSet to -1 and expiring Date to default Remove from the list If Opt contains "C" or "c"...
TString & Remove(Ssiz_t pos)
Definition: TString.h:616
int authclient(const char *host="up://localhost:3000", int sz=0)
Definition: authclient.C:25
TSecContext * GetSecContext() const
Definition: TSocket.h:157
const char * GetUser() const
Definition: TUrl.h:74
void Resize(Ssiz_t n)
Resize the string. Truncate or add blanks as necessary.
Definition: TString.cxx:1045