Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
28int 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}
int Int_t
Definition RtypesCore.h:45
const char * proto
Definition civetweb.c:17536
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",...
TSecContext * GetSecContext() const
Definition TSocket.h:127
static TSocket * CreateAuthSocket(const char *user, const char *host, Int_t port, Int_t size=0, Int_t tcpwindowsize=-1, TSocket *s=nullptr, Int_t *err=nullptr)
Creates a socket or a parallel socket and authenticates to the remote server specified in 'url' on re...
Definition TSocket.cxx:1432
virtual Bool_t IsAuthenticated() const
Definition TSocket.h:131
Basic string class.
Definition TString.h:139
const char * Data() const
Definition TString.h:380
void Resize(Ssiz_t n)
Resize the string. Truncate or add blanks as necessary.
Definition TString.cxx:1140
TString & Remove(Ssiz_t pos)
Definition TString.h:685
This class represents a WWW compatible URL.
Definition TUrl.h:33
const char * GetUser() const
Definition TUrl.h:65
const char * GetHost() const
Definition TUrl.h:67
Int_t GetPort() const
Definition TUrl.h:78