Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 #if !defined (_ink_cap_h_)
00025 #define _ink_cap_h_
00026 #include "ink_mutex.h"
00027 
00028 
00029 extern void DebugCapabilities(
00030   char const* tag 
00031 );
00032 
00033 
00034 extern int PreserveCapabilities();
00035 
00036 
00037 extern int RestrictCapabilities();
00038 
00039 
00040 
00041 
00042 
00043 extern int EnableCoreFile(
00044   bool flag 
00045 );
00046 
00047 
00048 
00049 #if TS_USE_POSIX_CAP
00050 bool elevateFileAccess(bool);
00051 #else
00052 bool restoreRootPriv(uid_t *old_euid = NULL);
00053 bool removeRootPriv(uid_t euid);
00054 #endif
00055 
00056 
00057 class ElevateAccess {
00058 public:
00059   ElevateAccess(const bool state): elevated(false), saved_uid(0) {
00060     if (state == true) {
00061       elevate();
00062     }
00063   }
00064 
00065   void elevate() {
00066 #if TS_USE_POSIX_CAP
00067     elevateFileAccess(true);
00068 #else
00069     
00070     
00071     restoreRootPriv(&saved_uid);
00072     ink_mutex_acquire(&lock);
00073 #endif
00074     elevated = true;
00075   }
00076 
00077   void demote() {
00078 #if TS_USE_POSIX_CAP
00079     elevateFileAccess(false);
00080 #else
00081     removeRootPriv(saved_uid);
00082     ink_mutex_release(&lock);
00083 #endif
00084     elevated = false;
00085   }
00086 
00087   ~ElevateAccess() {
00088     if (elevated == true) {
00089       demote();
00090     }
00091   }
00092 
00093 private:
00094   bool elevated;
00095   uid_t saved_uid;
00096 #if !TS_USE_POSIX_CAP
00097   static ink_mutex lock; 
00098 #endif
00099 };
00100 
00101 #endif