Logo ROOT   6.18/05
Reference Guide
TestAuth.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_net
3/// Macro test authentication methods stand alone
4///
5/// See `$ROOTSYS/README/README.AUTH` for additional details
6///
7/// Syntax:
8///
9/// ~~~ {.cpp}
10/// .x TestAuth.C(<port>,"<user>")
11///
12/// <port> = rootd port (default 1094)
13/// <user> = login user name for the test
14/// (default from getpwuid)
15/// ~~~
16///
17/// MAKE SURE that rootd is running
18///
19/// Example of successful output:
20///
21/// ~~~ {.cpp}
22/// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
23/// + +
24/// + TestAuth.C +
25/// + +
26/// + Test of authentication methods +
27/// + +
28/// + Syntax: +
29/// + +
30/// + .x TestAuth.C(<port>,"<user>") +
31/// + +
32/// + <port> = rootd port (default 1094) +
33/// + <user> = login user name for the test +
34/// + (default from getpwuid) +
35/// + +
36/// + >>> MAKE SURE that rootd is running <<< +
37/// + +
38/// + See $ROOTSYS/README/README.AUTH for additional details +
39/// + +
40/// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
41///
42/// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
43/// + +
44/// + Basic test parameters: +
45/// + +
46/// + Local User is : ganis
47/// + Authentication Details : pt:0 ru:1 us:ganis
48/// + Current directory is : /home/ganis/local/root/root/tutorials
49/// + TFTP string : root://localhost:1094
50/// + +
51/// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
52/// + +
53/// + Testing UsrPwd ... +
54/// ganis@localhost password:
55/// + +
56/// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
57///
58/// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
59/// + +
60/// + Result of the tests: +
61/// + +
62/// + Method: 0 (UsrPwd): successful! (reuse: successful!) +
63/// + +
64/// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
65/// ~~~
66///
67/// \macro_code
68///
69/// \author
70
71int TestAuth(int port = 1094, char *user = "")
72{
73 //
74 // This macro tests the authentication methods
75 //
76 gROOT->Reset();
77
78// Getting debug flag
79 Int_t lDebug = gEnv->GetValue("Root.Debug",0);
80
81// Useful flags
82 Bool_t HaveMeth[6] = {1,0,0,0,0,1};
83 Int_t TestMeth[6] = {0,0,0,0,0,0};
84 Int_t TestReUse[6] = {3,3,3,3,3,3};
85
86
87// Some Printout
88 printf("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
89 printf("+ +\n");
90 printf("+ TestAuth.C +\n");
91 printf("+ +\n");
92 printf("+ Test of authentication methods +\n");
93 printf("+ +\n");
94 printf("+ Syntax: +\n");
95 printf("+ +\n");
96 printf("+ .x TestAuth.C(<port>,\"<user>\") +\n");
97 printf("+ +\n");
98 printf("+ <port> = rootd port (default 1094) +\n");
99 printf("+ <user> = login user name for the test +\n");
100 printf("+ (default from getpwuid) +\n");
101 printf("+ +\n");
102 printf("+ >>> MAKE SURE that rootd is running <<< +\n");
103 printf("+ +\n");
104 printf("+ See $ROOTSYS/README/README.AUTH for additional details +\n");
105 printf("+ +\n");
106 printf("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n\n");
107
108// Useful variables
109
110// User
111 TString User = user;
112 if (User == "") {
113
115 if (!u) {
116 printf("\n >>>> 'user' not defined: please enter a valid username:\n");
117 char utmp[256] = {0};
118 scanf("%s",utmp);
119 if (strlen(utmp)) {
120 User = utmp;
121 } else {
122 printf(">>>> no 'user' defined: return!\n");
123 return 1;
124 }
125 } else {
126 User = u->fUser;
127 }
128
129 }
130
131// Host
132 TString Host = "localhost";
133 TString HostName = gSystem->HostName();
134
135// File path string for TFTP
136 //TString TFTPPath = TString("root://localhost:")+ port ;
137 TString TFTPPath = TString("root://")+User+TString("@localhost:")+ port ;
138
139// Details
140 TString Details = TString("pt:0 ru:1 us:") + User;
141
142// Testing availabilities
143 char *p;
144
145// Test parameter Printout
146 printf("\n+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
147 printf("+ +\n");
148 printf("+ Basic test parameters: +\n");
149 printf("+ +\n");
150 printf("+ Local User is : %s \n",User.Data());
151 printf("+ Authentication Details : %s \n",Details.Data());
152 printf("+ Current directory is : %s \n",gSystem->WorkingDirectory());
153 printf("+ TFTP string : %s \n",TFTPPath.Data());
154 printf("+ +\n");
155 printf("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
156
157// Read local <RootAuthrc> now to avoid to be later superseded
159 if (lDebug > 0)
161
162 TFTP *t1 = 0;
163// UsrPwd method
164 printf("+ +\n");
165 printf("+ Testing UsrPwd ... +\n");
166
167 // Check if by any chance locally there is already an THostAuth matching
168 // the one we want to use for testing
169 THostAuth *hasv1 = 0;
170 THostAuth *ha = TAuthenticate::HasHostAuth(Host.Data(),User.Data());
171 if (ha) {
172 // We need to save it to restore at the end
173 hasv1 = new THostAuth(*ha);
174 // We reset the existing one
175 ha->Reset();
176 // And update it with the info we want
177 ha->AddMethod(0,Details.Data());
178 } else {
179 // We create directly a new THostAuth
180 ha = new THostAuth(Host.Data(),User.Data(),0,Details.Data());
181 // And add object to list so that TAuthenticate has
182 // a chance to find it
184 }
185
186 // Print available host auth info
187 if (lDebug > 0)
188 ha->Print();
189
190 {
191 // First authentication attempt
192 t1 = new TFTP(TFTPPath.Data(),2);
193 if (t1->IsOpen()) {
194 TestMeth[0] = 1;
195 } else {
196 printf(" >>>>>>>>>>>>>>>> Test of UsrPwd authentication failed \n");
197 }}
198
199 // Try ReUse
200 if (TestMeth[0] == 1) {
201 TIter next(ha->Established());
202 TSecContext *ai;
203 while ((ai = (TSecContext *) next())) {
204 if (ai->GetMethod() == 0) {
205 Int_t OffSet = ai->GetOffSet();
206 TestReUse[0] = 0;
207 if (OffSet > -1) {
208 TestReUse[0] = 1;
209 }
210 }
211 }
212 }
213 // Delete t1
214 if (t1) delete t1;
215 // remove method from available list
216 ha->RemoveMethod(0);
217
218 printf("+ +\n");
219 printf("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
220
221 // Print available host auth info
222 if (lDebug > 0)
224
225// Now restore initial configuration
226 if (hasv1) {
227 ha->Reset();
228 ha->Update(hasv1);
229 } else {
231 }
232 if (hasv2) {
233 hak->Reset();
234 hak->Update(hasv2);
235 } else {
237 }
238
239// Final Printout
240 printf("\n+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
241 printf("+ +\n");
242 printf("+ Result of the tests: +\n");
243 printf("+ +\n");
244 char status[4][20] = {"failed!","successful!","not testable","not tested"};
245 int i = 0;
246 for( i=0; i<6; i++ ) {
247 if (HaveMeth[i] && TestMeth[i] < 2) {
248 if (i < 5) {
249 printf("+ Method: %d %8s: %11s (reuse: %11s) +\n",i,
251 status[TestMeth[i]],status[TestReUse[i]]);
252 } else
253 printf("+ Method: %d %8s: %11s +\n",i,
255 status[TestMeth[i]]);
256 }
257 }
258 Bool_t NotPrinted = kTRUE;
259 for( i=0; i<6; i++ ) {
260 if (HaveMeth[i] && TestMeth[i] > 1) {
261 if (NotPrinted) {
262 printf("+ +\n");
263 printf("+ Could not be tested: +\n");
264 printf("+ +\n");
265 NotPrinted = kFALSE;
266 }
267 printf("+ Method: %d %8s: %11s +\n",i,
269 status[TestMeth[i]]);
270 }
271 }
272 printf("+ +\n");
273 printf("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
274
275}
int Int_t
Definition: RtypesCore.h:41
const Bool_t kFALSE
Definition: RtypesCore.h:88
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kTRUE
Definition: RtypesCore.h:87
R__EXTERN TEnv * gEnv
Definition: TEnv.h:171
#define gROOT
Definition: TROOT.h:414
char * Form(const char *fmt,...)
R__EXTERN TSystem * gSystem
Definition: TSystem.h:560
static void Show(Option_t *opt="S")
Print info about the authentication sector.
static Int_t ReadRootAuthrc()
Read authentication directives from $ROOTAUTHRC, $HOME/.rootauthrc or <Root_etc_dir>/system....
static TList * GetAuthInfo()
Static method returning the list with authentication details.
static const char * GetAuthMethod(Int_t idx)
Static method returning the method corresponding to idx.
static THostAuth * HasHostAuth(const char *host, const char *user, Option_t *opt="R")
Checks if a THostAuth with exact match for {host,user} exists in the fgAuthInfo list If opt = "P" use...
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
Definition: TEnv.cxx:491
Definition: TFTP.h:34
void Reset()
Remove all methods, leaving Active status and list of associted TSceContexts unchanged.
Definition: THostAuth.cxx:344
virtual void Print(Option_t *option="") const
Print object content.
Definition: THostAuth.cxx:424
void RemoveMethod(Int_t level)
Remove method 'meth' from the list, if there ...
Definition: THostAuth.cxx:310
void AddMethod(Int_t level, const char *details=0)
Add method to the list.
Definition: THostAuth.cxx:277
TList * Established() const
Definition: THostAuth.h:100
void Update(THostAuth *ha)
Update info with the one in ha Remaining methods, if any, get lower priority.
Definition: THostAuth.cxx:533
virtual void Add(TObject *obj)
Definition: TList.h:87
virtual TObject * Remove(TObject *obj)
Remove object from the list.
Definition: TList.cxx:819
Int_t GetMethod() const
Definition: TSecContext.h:77
Int_t GetOffSet() const
Definition: TSecContext.h:79
Basic string class.
Definition: TString.h:131
const char * Data() const
Definition: TString.h:364
virtual const char * HostName()
Return the system's host name.
Definition: TSystem.cxx:312
virtual const char * WorkingDirectory()
Return working directory.
Definition: TSystem.cxx:878
virtual UserGroup_t * GetUserInfo(Int_t uid)
Returns all user info in the UserGroup_t structure.
Definition: TSystem.cxx:1588
TString fUser
Definition: TSystem.h:142
auto * t1
Definition: textangle.C:20