// @(#)root/net:$Id$
// Author: G. Ganis   31/03/2003

/*************************************************************************
 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#ifndef ROOT_TSecContext
#define ROOT_TSecContext


//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TSecContext                                                         //
//                                                                      //
// Contains details about successful authentications                    //
// Used by THostAuth                                                    //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#ifndef ROOT_TObject
#include "TObject.h"
#endif
#ifndef ROOT_TString
#include "TString.h"
#endif
#ifndef ROOT_TDatime
#include "TDatime.h"
#endif

// Jan 1, 1995, 00:00:00 in sec from EPOCH (Jan 1, 1970)
const TDatime kROOTTZERO = 788914800;

// Small class with information for final cleanup
class TSecContextCleanup;
class TPwdCtx;

class TSecContext : public TObject {

friend class TRootSecContext;

private:
   void        *fContext;             // Krb5, Globus: ptr to specific sec context
   TList       *fCleanup;             // Points to list with info for remote cleanup
   TDatime      fExpDate;             // Expiring date (one sec precision)
   TString      fHost;                // Remote host name
   TString      fID;                  // String identifying uniquely this context
   Int_t        fMethod;              // Authentication method used
   TString      fMethodName;          // Authentication method name
   Int_t        fOffSet;              // offset in remote host auth tab file (in bytes)
   TString      fToken;               // Token identifying this authentication
   TString      fUser;                // Remote login username

   virtual Bool_t  CleanupSecContext(Bool_t all);
   void         Cleanup();

protected:
   TSecContext(const TSecContext&);
   TSecContext& operator=(const TSecContext&);

public:

   TSecContext(const char *url, Int_t meth, Int_t offset,
               const char *id, const char *token,
               TDatime expdate = kROOTTZERO, void *ctx = 0);
   TSecContext(const char *user, const char *host, Int_t meth, Int_t offset,
               const char *id, const char *token,
               TDatime expdate = kROOTTZERO, void *ctx = 0);
   virtual    ~TSecContext();

   void        AddForCleanup(Int_t port, Int_t proto, Int_t type);
   virtual const char *AsString(TString &out);

   virtual void DeActivate(Option_t *opt = "CR");
   void       *GetContext() const { return fContext; }
   TDatime     GetExpDate() const { return fExpDate; }
   const char *GetHost()    const { return fHost; }
   const char *GetID() const { return fID; }
   Int_t       GetMethod()  const { return fMethod; }
   const char *GetMethodName() const { return fMethodName; }
   Int_t       GetOffSet()  const { return fOffSet; }
   TList      *GetSecContextCleanup() const { return fCleanup; }
   const char *GetToken()   const { return fToken; }
   const char *GetUser()    const { return fUser; }

   Bool_t      IsA(const char *methodname);
   Bool_t      IsActive()   const;

   virtual void Print(Option_t *option = "F") const;

   void        SetExpDate(TDatime expdate)  { fExpDate= expdate; }
   void        SetID(const char *id)        { fID= id; }
   void        SetOffSet(Int_t offset)      { fOffSet = offset; }
   void        SetUser(const char *user)    { fUser   = user; }

   ClassDef(TSecContext,0)  // Class providing host specific authentication information
};

//
// TSecContextCleanup
//
// When the context is destroyed the remote authentication table
// should be updated; also, for globus, remote shared memory segments
// should be destroyed; for this we need to open a socket to a remote
// service; we keep track here of port and type of socket needed by
// the remote service used in connection with this security context.
// The last used is the first in the list.
// This info is used in TAuthenticate::CleanupSecContext to trasmit
// the actual cleanup request
//
class TSecContextCleanup : public TObject {

private:
   Int_t   fPort;
   Int_t   fServerProtocol;
   Int_t   fServerType;     // 0 = sockd, 1 = rootd, 2 = proofd

public:
   TSecContextCleanup(Int_t port, Int_t proto, Int_t type) :
               fPort(port), fServerProtocol(proto), fServerType(type) { };
   virtual ~TSecContextCleanup() { };

   Int_t   GetPort() const { return fPort; }
   Int_t   GetProtocol() const { return fServerProtocol; }
   Int_t   GetType() const { return fServerType; }

   ClassDef(TSecContextCleanup,0) //Update the remote authentication table
};

//
// TPwdCtx
//
// To store associated passwd for UsrPwd and SRP methods
//
class TPwdCtx {

private:
   TString fPasswd;
   Bool_t  fPwHash;

public:
   TPwdCtx(const char *pwd, Bool_t pwh): fPasswd(pwd), fPwHash(pwh) {};
   virtual ~TPwdCtx() {};

   const char *GetPasswd() const { return fPasswd; }
   Bool_t      IsPwHash() const { return fPwHash; }

};



#endif
 TSecContext.h:1
 TSecContext.h:2
 TSecContext.h:3
 TSecContext.h:4
 TSecContext.h:5
 TSecContext.h:6
 TSecContext.h:7
 TSecContext.h:8
 TSecContext.h:9
 TSecContext.h:10
 TSecContext.h:11
 TSecContext.h:12
 TSecContext.h:13
 TSecContext.h:14
 TSecContext.h:15
 TSecContext.h:16
 TSecContext.h:17
 TSecContext.h:18
 TSecContext.h:19
 TSecContext.h:20
 TSecContext.h:21
 TSecContext.h:22
 TSecContext.h:23
 TSecContext.h:24
 TSecContext.h:25
 TSecContext.h:26
 TSecContext.h:27
 TSecContext.h:28
 TSecContext.h:29
 TSecContext.h:30
 TSecContext.h:31
 TSecContext.h:32
 TSecContext.h:33
 TSecContext.h:34
 TSecContext.h:35
 TSecContext.h:36
 TSecContext.h:37
 TSecContext.h:38
 TSecContext.h:39
 TSecContext.h:40
 TSecContext.h:41
 TSecContext.h:42
 TSecContext.h:43
 TSecContext.h:44
 TSecContext.h:45
 TSecContext.h:46
 TSecContext.h:47
 TSecContext.h:48
 TSecContext.h:49
 TSecContext.h:50
 TSecContext.h:51
 TSecContext.h:52
 TSecContext.h:53
 TSecContext.h:54
 TSecContext.h:55
 TSecContext.h:56
 TSecContext.h:57
 TSecContext.h:58
 TSecContext.h:59
 TSecContext.h:60
 TSecContext.h:61
 TSecContext.h:62
 TSecContext.h:63
 TSecContext.h:64
 TSecContext.h:65
 TSecContext.h:66
 TSecContext.h:67
 TSecContext.h:68
 TSecContext.h:69
 TSecContext.h:70
 TSecContext.h:71
 TSecContext.h:72
 TSecContext.h:73
 TSecContext.h:74
 TSecContext.h:75
 TSecContext.h:76
 TSecContext.h:77
 TSecContext.h:78
 TSecContext.h:79
 TSecContext.h:80
 TSecContext.h:81
 TSecContext.h:82
 TSecContext.h:83
 TSecContext.h:84
 TSecContext.h:85
 TSecContext.h:86
 TSecContext.h:87
 TSecContext.h:88
 TSecContext.h:89
 TSecContext.h:90
 TSecContext.h:91
 TSecContext.h:92
 TSecContext.h:93
 TSecContext.h:94
 TSecContext.h:95
 TSecContext.h:96
 TSecContext.h:97
 TSecContext.h:98
 TSecContext.h:99
 TSecContext.h:100
 TSecContext.h:101
 TSecContext.h:102
 TSecContext.h:103
 TSecContext.h:104
 TSecContext.h:105
 TSecContext.h:106
 TSecContext.h:107
 TSecContext.h:108
 TSecContext.h:109
 TSecContext.h:110
 TSecContext.h:111
 TSecContext.h:112
 TSecContext.h:113
 TSecContext.h:114
 TSecContext.h:115
 TSecContext.h:116
 TSecContext.h:117
 TSecContext.h:118
 TSecContext.h:119
 TSecContext.h:120
 TSecContext.h:121
 TSecContext.h:122
 TSecContext.h:123
 TSecContext.h:124
 TSecContext.h:125
 TSecContext.h:126
 TSecContext.h:127
 TSecContext.h:128
 TSecContext.h:129
 TSecContext.h:130
 TSecContext.h:131
 TSecContext.h:132
 TSecContext.h:133
 TSecContext.h:134
 TSecContext.h:135
 TSecContext.h:136
 TSecContext.h:137
 TSecContext.h:138
 TSecContext.h:139
 TSecContext.h:140
 TSecContext.h:141
 TSecContext.h:142
 TSecContext.h:143
 TSecContext.h:144
 TSecContext.h:145
 TSecContext.h:146
 TSecContext.h:147
 TSecContext.h:148
 TSecContext.h:149
 TSecContext.h:150
 TSecContext.h:151
 TSecContext.h:152
 TSecContext.h:153
 TSecContext.h:154
 TSecContext.h:155
 TSecContext.h:156