Disk ARchive
2.4.2
|
00001 /*********************************************************************/ 00002 // dar - disk archive - a backup/restoration program 00003 // Copyright (C) 2002-2052 Denis Corbin 00004 // 00005 // This program is free software; you can redistribute it and/or 00006 // modify it under the terms of the GNU General Public License 00007 // as published by the Free Software Foundation; either version 2 00008 // of the License, or (at your option) any later version. 00009 // 00010 // This program is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with this program; if not, write to the Free Software 00017 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00018 // 00019 // to contact the author : http://dar.linux.free.fr/email.html 00020 /*********************************************************************/ 00021 // $Id: user_group_bases.hpp,v 1.4 2011/01/09 17:25:58 edrusb Rel $ 00022 // 00023 /*********************************************************************/ 00024 00028 00029 #ifndef USER_GROUP_BASES_HPP 00030 #define USER_GROUP_BASES_HPP 00031 00032 #include "../my_config.h" 00033 00034 #ifdef __DYNAMIC__ 00035 00036 extern "C" 00037 { 00038 #if MUTEX_WORKS 00039 #if HAVE_PTHREAD_H 00040 #include <pthread.h> 00041 #endif 00042 #endif 00043 } 00044 00045 #include <map> 00046 #include <string> 00047 #include "infinint.hpp" 00048 00049 namespace libdar 00050 { 00051 00054 00055 class user_group_bases 00056 { 00057 public: 00058 user_group_bases() : filled(false) {}; 00059 00061 00063 const std::string & get_username(const infinint & uid) const; 00064 00065 00067 00069 const std::string & get_groupname(const infinint & gid) const; 00070 00072 00073 static void class_init(); 00074 00075 private: 00076 bool filled; 00077 std::map<infinint, std::string> user_database; 00078 std::map<infinint, std::string> group_database; 00079 00080 void fill() const; 00081 00082 static const std::string empty_string; 00083 #if MUTEX_WORKS 00084 // the system call used to read the password and group database are not re-entrant, the mutex 00085 // must block all other thread while a given thread is reading the databases 00086 // the best solution would have to let the user provide such a database object already filled 00087 // but that would rely on it not to destroy this object while threads are using it 00088 // for this reason, here the mutex is 'static' 00089 static pthread_mutex_t lock_fill; 00090 #endif 00091 static bool class_initialized; 00092 00093 }; 00094 00095 00097 00098 } // end of namespace 00099 00100 #endif 00101 00102 #endif