Logo ROOT   6.14/05
Reference Guide
authclient.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_net
3 /// This macro should be run together with authserv.C to test
4 /// authentication between two remote ROOT sessions.
5 /// Run first the authserv.C within a ROOT session on the server
6 /// machine, eg. "srv.machi.ne":
7 ///
8 /// root[] .x authserv.C(3000)
9 ///
10 /// authserv accepts as argument the port where it starts listening
11 /// (default 3000).
12 /// You can then run authclient.c in a ROOT session on the client
13 /// machine:
14 /// root[] .x authclient.C("srv.machi.ne:3000")
15 ///
16 /// and you should get prompted for the credentials, if the case.
17 /// To start a parallel socket of size, for example, 5, enter the
18 /// size as second argument, ie
19 ///
20 /// root[] .x authclient.C("srv.machi.ne:3000",5)
21 ///
22 /// \macro_code
23 ///
24 /// \author
25 
26 #include "TPSocket.h"
27 
28 int authclient(const char *host = "up://localhost:3000", int sz = 0)
29 {
30  Int_t par = (sz > 1) ? 1 : 0;
31 
32  // Parse protocol, if any
33  TString proto(TUrl(host).GetProtocol());
34  TString protosave = proto;
35 
36  // Get rid of authentication suffix
37  TString asfx = proto;
38  if (proto.EndsWith("up") || proto.EndsWith("ug")) {
39  asfx.Remove(0,proto.Length()-2);
40  proto.Resize(proto.Length()-2);
41  } else if (proto.EndsWith("s") || proto.EndsWith("k") ||
42  proto.EndsWith("g") || proto.EndsWith("h")) {
43  asfx.Remove(0,proto.Length()-1);
44  proto.Resize(proto.Length()-1);
45  }
46 
47  // Force parallel (even of size 1)
48  TString newurl = "p" + asfx;
49  newurl += "://";
50  if (strlen(TUrl(host).GetUser())) {
51  newurl += TUrl(host).GetUser();
52  newurl += "@";
53  }
54  newurl += TUrl(host).GetHost();
55  newurl += ":";
56  newurl += TUrl(host).GetPort();
57 
58  cout << "authclient: starting a (parallel) authenticated socket at "
59  << newurl.Data() << " (size: " << sz << ")" << endl;
60 
61  TSocket *s = TSocket::CreateAuthSocket(newurl.Data(),sz);
62 
63  // Print out;
64  if (s)
65  if (s->IsAuthenticated())
66  cout << "authclient: auth socket: OK" << endl;
67  else
68  cout << "authclient: auth socket: failed" << endl;
69 
70  // Cleanup
71  if (s) {
72  // Remove this authentication from the token list to avoid
73  // later warnings
74  s->GetSecContext()->DeActivate("R");
75  delete s;
76  }
77 }
This class represents a WWW compatible URL.
Definition: TUrl.h:35
Basic string class.
Definition: TString.h:131
int Int_t
Definition: RtypesCore.h:41
const char * GetHost() const
Definition: TUrl.h:70
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 &#39;url&#39; on re...
Definition: TSocket.cxx:1457
const char * GetUser() const
Definition: TUrl.h:68
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:668
static constexpr double s
virtual Bool_t IsAuthenticated() const
Definition: TSocket.h:150
Int_t GetPort() const
Definition: TUrl.h:81
TSecContext * GetSecContext() const
Definition: TSocket.h:146
const char * proto
Definition: civetweb.c:15049
const char * Data() const
Definition: TString.h:364