pion  5.0.6
admin_rights.hpp
1 // ---------------------------------------------------------------------
2 // pion: a Boost C++ framework for building lightweight HTTP interfaces
3 // ---------------------------------------------------------------------
4 // Copyright (C) 2007-2014 Splunk Inc. (https://github.com/splunk/pion)
5 //
6 // Distributed under the Boost Software License, Version 1.0.
7 // See http://www.boost.org/LICENSE_1_0.txt
8 //
9 
10 #ifndef __PION_ADMIN_RIGHTS_HEADER__
11 #define __PION_ADMIN_RIGHTS_HEADER__
12 
13 #include <pion/config.hpp>
14 #include <pion/logger.hpp>
15 #include <boost/cstdint.hpp>
16 #include <boost/thread/mutex.hpp>
17 
18 
19 namespace pion { // begin namespace pion
20 
21 
25 class PION_API admin_rights {
26 public:
27 
34  admin_rights(bool use_log = true);
35 
37  virtual ~admin_rights() { release(); }
38 
40  void release(void);
41 
43  static long run_as_user(const std::string& user_name);
44 
46  static long run_as_group(const std::string& group_name);
47 
48 
49 private:
50 
59  static long find_system_id(const std::string& name, const std::string& file);
60 
61 
63  static const boost::int16_t ADMIN_USER_ID;
64 
66  static boost::mutex m_mutex;
67 
69  logger m_logger;
70 
72  boost::unique_lock<boost::mutex> m_lock;
73 
75  boost::int16_t m_user_id;
76 
78  bool m_has_rights;
79 
81  bool m_use_log;
82 };
83 
84 
85 } // end namespace pion
86 
87 #endif
88 
virtual ~admin_rights()
destructor releases administrative rights