Disk ARchive  2.5.2
Full featured and portable backup and archiving tool
user_group_bases.hpp
Go to the documentation of this file.
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 
00025 
00026 #ifndef USER_GROUP_BASES_HPP
00027 #define USER_GROUP_BASES_HPP
00028 
00029 #include "../my_config.h"
00030 
00031 #ifdef __DYNAMIC__
00032 
00033 extern "C"
00034 {
00035 #if MUTEX_WORKS
00036 #if HAVE_PTHREAD_H
00037 #include <pthread.h>
00038 #endif
00039 #endif
00040 }
00041 
00042 #include <map>
00043 #include <string>
00044 #include "infinint.hpp"
00045 
00046 namespace libdar
00047 {
00048 
00051 
00052     class user_group_bases
00053     {
00054     public:
00055     user_group_bases() : filled(false) {};
00056 
00058 
00060     const std::string & get_username(const infinint & uid) const;
00061 
00062 
00064 
00066     const std::string & get_groupname(const infinint & gid) const;
00067 
00068 
00069     private:
00070     bool filled;
00071     std::map<infinint, std::string> user_database;
00072     std::map<infinint, std::string> group_database;
00073 
00074     void fill() const;
00075 
00076     static const std::string empty_string;
00077 #if MUTEX_WORKS
00078         // the system call used to read the password and group database are not re-entrant, the mutex
00079         // must block all other thread while a given thread is reading the databases
00080         // the best solution would have to let the user provide such a database object already filled
00081         // but that would rely on it not to destroy this object while threads are using it
00082         // for this reason, here the mutex is 'static'
00083     static pthread_mutex_t lock_fill;
00084 #endif
00085     };
00086 
00087 
00089 
00090 }  // end of namespace
00091 
00092 #endif
00093 
00094 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines