00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00037 #ifndef THREADSAFE_SETUID_H
00038 #define THREADSAFE_SETUID_H
00039
00040 #include <sys/types.h>
00041 #include <pthread.h>
00042 #include <string>
00043
00044 #include "protlib_types.h"
00045 #include "cleanuphandler.h"
00046
00047 namespace protlib {
00048
00053
00054
00057 class setuid {
00058 public:
00060 static void init();
00062 static void end();
00064 static void on();
00066 static void off();
00067 private:
00069 static bool is_init;
00071 static pthread_mutex_t mutex;
00073 static uint32 count;
00075 static uid_t file_userid;
00077 static string file_username;
00079 static uid_t real_userid;
00081 static string real_username;
00083 static bool is_setuid;
00084 };
00085
00087 #define BEGIN_SETUID_MODE protlib::setuid::on(); install_cleanup(call_void_fun,protlib::setuid::off)
00088 #define END_SETUID_MODE uninstall_cleanup(1)
00089
00091
00092 }
00093
00094 #endif