112 int TestAuth(
int port = 1094,
char *user =
"",
char *krb5 =
"",
char *globus =
"")
123 Bool_t HaveMeth[6] = {1,0,0,0,0,1};
124 Int_t TestMeth[6] = {0,0,0,0,0,0};
125 Int_t TestReUse[6] = {3,3,3,3,3,3};
129 printf(
"+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
131 printf(
"+ TestAuth.C +\n");
133 printf(
"+ Test of authentication methods +\n");
135 printf(
"+ Syntax: +\n");
137 printf(
"+ .x TestAuth.C(<port>,\"<user>\",\"<krb5_princ>\",\"<globus_det>\") +\n");
139 printf(
"+ <port> = rootd port (default 1094) +\n");
140 printf(
"+ <user> = login user name for the test +\n");
141 printf(
"+ (default from getpwuid) +\n");
142 printf(
"+ <krb5_princ> = Principal to be used for Krb5 authentication +\n");
143 printf(
"+ in the form user@THE.REA.LM +\n");
144 printf(
"+ ( default: <running_user@Default_Realm with +\n");
145 printf(
"+ Default_realm taken from /etc/krb5.conf +\n");
146 printf(
"+ or the $KRB5_CONFIG file ) +\n");
147 printf(
"+ <globus_det> = details for the globus authentication +\n");
148 printf(
"+ ( default ad:certificates cd:$HOME/.globus +\n");
149 printf(
"+ cf:usercert.pem kf:userkey.pem ) +\n");
151 printf(
"+ >>> MAKE SURE that rootd is running <<< +\n");
153 printf(
"+ See $ROOTSYS/README/README.AUTH for additional details +\n");
155 printf(
"+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n\n");
165 printf(
"\n >>>> 'user' not defined: please enter a valid username:\n");
166 char utmp[256] = {0};
171 printf(
">>>> no 'user' defined: return!\n");
189 HostName +
TString(
":")+ port ;
209 if (strlen(krb5) > 0) {
219 Krb5Conf =
"/etc/krb5.conf";
221 printf(
"\n >>>> Kerberos Principal undefined\n");
222 printf(
"\n >>>> unable to localize Kerberos config file to build a default\n");
223 printf(
"\n >>>> Switching off Kerberos\n");
224 printf(
"\n >>>> Run again with giving the principal as 3rd argument\n");
225 printf(
"\n >>>> or define the variable KRB5_CONFIG with the full path \n");
226 printf(
"\n >>>> to the config file (usually /etc/krb5.conf)\n");
229 if (HaveMeth[2] == 1) {
230 FILE *
fc = fopen(Krb5Conf.
Data(),
"r");
232 char line[1024], fs1[1024], fs2[1024], fs3[1024];
233 while (fgets(line,
sizeof(line), fc) != 0) {
234 int nf = sscanf(line,
"%s %s %s",fs1,fs2,fs3);
235 if (nf == 3 && !strcmp(fs1,
"default_realm")) {
240 Krb5Details =
TString(
"pt:0 ru:1 us:") + User +
TString(
"@") + Realm;
266 printf(
"\n+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
268 printf(
"+ Basic test parameters: +\n");
270 printf(
"+ Local User is : %s \n",User.
Data());
271 printf(
"+ Authentication Details : %s \n",Details.
Data());
273 printf(
"+ TFTP string : %s \n",TFTPPath.
Data());
275 printf(
"+ Krb5 Details : %s \n",Krb5Details.
Data());
278 printf(
"+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
288 printf(
"+ Testing UsrPwd ... +\n");
319 printf(
" >>>>>>>>>>>>>>>> Test of UsrPwd authentication failed \n");
323 if (TestMeth[0] == 1) {
327 if (ai->GetMethod() == 0) {
344 printf(
"+ Testing SRP ... +\n");
356 printf(
" >>>>>>>>>>>>>>>> Test of SRP authentication failed \n");
360 if (TestMeth[1] == 1) {
364 if (ai->GetMethod() == 1) {
385 printf(
"+ Testing Krb5 ... +\n");
393 printf(
" >>>>>>>>>>>>>>>> Krb5: existing THostAuth found \n");
411 t1 =
new TFTP(TFTPPathKrb5.
Data(),2);
415 printf(
" >>>>>>>>>>>>>>>> Test of Kerberos authentication failed \n");
416 if (strlen(krb5) > 0) {
417 printf(
" >>>>>>>>>>>>>>>> details used: '%s' \n",krb5);
422 if (TestMeth[2] == 1) {
426 if (ai->GetMethod() == 2) {
444 printf(
"+ Testing Globus ... +\n");
456 printf(
" >>>>>>>>>>>>>>>> Test of Globus authentication failed \n");
457 if (strlen(globus) > 0) {
458 printf(
" >>>>>>>>>>>>>>>> details used: '%s' \n",globus);
460 printf(
" >>>>>>>>>>>>>>>> using default details: \n");
461 printf(
" >>>>>>>>>>>>>>>> ad:/etc/grid-security/certificates");
462 printf(
" cd:$HOME/.globus cf:usercert.pem kf:userkey.pem\n");
467 printf(
" >>>>>>>>>>>>>>>> You are not root,");
468 printf(
" you may not have the right privileges\n");
469 printf(
" >>>>>>>>>>>>>>>> Make sure that the used details are correct! \n");
475 if (TestMeth[3] == 1) {
479 if (ai->GetMethod() == 3) {
498 printf(
"+ Testing SSH ... +\n");
510 printf(
" >>>>>>>>>>>>>>>> Test of SSH authentication failed \n");
514 if (TestMeth[4] == 1) {
518 if (ai->GetMethod() == 4) {
536 printf(
"+ Testing UidGid ... +\n");
549 printf(
" >>>>>>>>>>>>>>>> Test of UidGid authentication failed \n");
559 printf(
"+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
580 printf(
"\n+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
582 printf(
"+ Result of the tests: +\n");
584 char status[4][20] = {
"failed!",
"successful!",
"not testable",
"not tested"};
586 for( i=0; i<6; i++ ) {
587 if (HaveMeth[i] && TestMeth[i] < 2) {
589 printf(
"+ Method: %d %8s: %11s (reuse: %11s) +\n",i,
591 status[TestMeth[i]],status[TestReUse[i]]);
593 printf(
"+ Method: %d %8s: %11s +\n",i,
595 status[TestMeth[i]]);
599 for( i=0; i<6; i++ ) {
600 if (HaveMeth[i] && TestMeth[i] > 1) {
603 printf(
"+ Could not be tested: +\n");
607 printf(
"+ Method: %d %8s: %11s +\n",i,
609 status[TestMeth[i]]);
613 printf(
"+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
virtual const char * WorkingDirectory()
Return working directory.
virtual char * Which(const char *search, const char *file, EAccessMode mode=kFileExists)
Find location of file in a search path.
static Int_t ReadRootAuthrc()
Read authentication directives from $ROOTAUTHRC, $HOME/.rootauthrc or <Root_etc_dir>/system.rootauthrc and create related THostAuth objects.
static struct mg_connection * fc(struct mg_context *ctx)
TList * Established() const
virtual const char * Getenv(const char *env)
Get environment variable.
virtual UserGroup_t * GetUserInfo(Int_t uid)
Returns all user info in the UserGroup_t structure.
void RemoveMethod(Int_t level)
Remove method 'meth' from the list, if there ...
R__EXTERN TSystem * gSystem
virtual TObject * Remove(TObject *obj)
Remove object from the list.
char * Form(const char *fmt,...)
void AddMethod(Int_t level, const char *details=0)
Add method to the list.
static void Show(Option_t *opt="S")
Print info about the authentication sector.
static TList * GetAuthInfo()
Static method returning the list with authentication details.
virtual const char * HostName()
Return the system's host name.
char * DynamicPathName(const char *lib, Bool_t quiet=kFALSE)
Find a dynamic library called lib using the system search paths.
virtual void Add(TObject *obj)
void Update(THostAuth *ha)
Update info with the one in ha Remaining methods, if any, get lower priority.
void AddFirst(Int_t level, const char *details=0)
Add new method in first position If already in the list, set as first method 'level' with authenticat...
virtual void Print(Option_t *option="") const
Print object content.
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
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...
const char * Data() const
static const char * GetAuthMethod(Int_t idx)
Static method returning the method corresponding to idx.
void Reset()
Remove all methods, leaving Active status and list of associted TSceContexts unchanged.