# 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 : dar.linux@free.fr
    00020 /*********************************************************************/
    00021 // $Id: user_group_bases.hpp,v 1.1.2.1 2007/07/24 16:29:32 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
    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
    00069
    00070         static void class_init();
    00071
    00072     private:
    00073         bool filled;
    00074         std::map<infinint, std::string> user_database;
    00075         std::map<infinint, std::string> group_database;
    00076
    00077         void fill() const;
    00078
    00079         static const std::string empty_string;
    00080 #if MUTEX_WORKS
    00081             // the system call used to read the password and group database are not re-entrant, the mutex
    00082             // must block all other thread while a given thread is reading the databases
    00083             // the best solution would have to let the user provide such a database object already filled
    00084             // but that would rely on it not to destroy this object while threads are using it
    00085             // for this reason, here the mutex is 'static'
    00086         static pthread_mutex_t lock_fill;
    00087 #endif
    00088         static bool class_initialized;
    00089
    00090     };
    00091
    00092 }  // end of namespace
    00093
    00094 #endif
    00095
    00096 #endif