Disk ARchive  2.4.17
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules
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 
25 
26 #ifndef USER_GROUP_BASES_HPP
27 #define USER_GROUP_BASES_HPP
28 
29 #include "../my_config.h"
30 
31 #ifdef __DYNAMIC__
32 
33 extern "C"
34 {
35 #if MUTEX_WORKS
36 #if HAVE_PTHREAD_H
37 #include <pthread.h>
38 #endif
39 #endif
40 }
41 
42 #include <map>
43 #include <string>
44 #include "infinint.hpp"
45 
46 namespace libdar
47 {
48 
51 
52  class user_group_bases
53  {
54  public:
55  user_group_bases() : filled(false) {};
56 
58 
60  const std::string & get_username(const infinint & uid) const;
61 
62 
64 
66  const std::string & get_groupname(const infinint & gid) const;
67 
69 
70  static void class_init();
71 
72  private:
73  bool filled;
74  std::map<infinint, std::string> user_database;
75  std::map<infinint, std::string> group_database;
76 
77  void fill() const;
78 
79  static const std::string empty_string;
80 #if MUTEX_WORKS
81  // the system call used to read the password and group database are not re-entrant, the mutex
82  // must block all other thread while a given thread is reading the databases
83  // the best solution would have to let the user provide such a database object already filled
84  // but that would rely on it not to destroy this object while threads are using it
85  // for this reason, here the mutex is 'static'
86  static pthread_mutex_t lock_fill;
87 #endif
88  static bool class_initialized;
89 
90  };
91 
92 
94 
95 } // end of namespace
96 
97 #endif
98 
99 #endif
switch module to limitint (32 ou 64 bits integers) or infinint
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:43