Disk ARchive  2.4.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
user_group_bases.hpp
Go to the documentation of this file.
1 /*********************************************************************/
2 // dar - disk archive - a backup/restoration program
3 // Copyright (C) 2002-2052 Denis Corbin
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 //
19 // to contact the author : http://dar.linux.free.fr/email.html
20 /*********************************************************************/
21 // $Id: user_group_bases.hpp,v 1.4 2011/01/09 17:25:58 edrusb Rel $
22 //
23 /*********************************************************************/
24 
28 
29 #ifndef USER_GROUP_BASES_HPP
30 #define USER_GROUP_BASES_HPP
31 
32 #include "../my_config.h"
33 
34 #ifdef __DYNAMIC__
35 
36 extern "C"
37 {
38 #if MUTEX_WORKS
39 #if HAVE_PTHREAD_H
40 #include <pthread.h>
41 #endif
42 #endif
43 }
44 
45 #include <map>
46 #include <string>
47 #include "infinint.hpp"
48 
49 namespace libdar
50 {
51 
54 
55  class user_group_bases
56  {
57  public:
58  user_group_bases() : filled(false) {};
59 
61 
63  const std::string & get_username(const infinint & uid) const;
64 
65 
67 
69  const std::string & get_groupname(const infinint & gid) const;
70 
72 
73  static void class_init();
74 
75  private:
76  bool filled;
77  std::map<infinint, std::string> user_database;
78  std::map<infinint, std::string> group_database;
79 
80  void fill() const;
81 
82  static const std::string empty_string;
83 #if MUTEX_WORKS
84  // the system call used to read the password and group database are not re-entrant, the mutex
85  // must block all other thread while a given thread is reading the databases
86  // the best solution would have to let the user provide such a database object already filled
87  // but that would rely on it not to destroy this object while threads are using it
88  // for this reason, here the mutex is 'static'
89  static pthread_mutex_t lock_fill;
90 #endif
91  static bool class_initialized;
92 
93  };
94 
95 
97 
98 } // end of namespace
99 
100 #endif
101 
102 #endif