libfilezilla
impersonation.hpp
Go to the documentation of this file.
1 #ifndef LIBFILEZILLA_IMPERSONATION_HEADER
2 #define LIBFILEZILLA_IMPERSONATION_HEADER
3 
8 #include "string.hpp"
9 
10 #include <memory>
11 #include <functional>
12 
13 namespace fz {
14 
15 #if !FZ_WINDOWS
16 enum class impersonation_flag
17 {
18  pwless
19 };
20 #endif
21 
22 class impersonation_token_impl;
23 
32 class FZ_PUBLIC_SYMBOL impersonation_token final
33 {
34 public:
36 
38  impersonation_token& operator=(impersonation_token&&) noexcept;
39 
41 #if FZ_WINDOWS
42  explicit impersonation_token(fz::native_string const& username, fz::native_string const& password, bool drop_admin_privileges = true);
43 #else
44  explicit impersonation_token(fz::native_string const& username, fz::native_string const& password);
45 #endif
46 
47 #if !FZ_WINDOWS
48  explicit impersonation_token(fz::native_string const& username, impersonation_flag flag, fz::native_string const& group = {});
50 #endif
51 
52  ~impersonation_token() noexcept;
53 
54  explicit operator bool() const {
55  return impl_.operator bool();
56  }
57 
58  bool operator==(impersonation_token const&) const;
59  bool operator<(impersonation_token const&) const;
60 
62  fz::native_string username() const;
63 
65  fz::native_string home() const;
66 
68  std::size_t hash() const noexcept;
69 
70 private:
71  friend class impersonation_token_impl;
72  std::unique_ptr<impersonation_token_impl> impl_;
73 };
74 
75 #if !FZ_WINDOWS
76 bool FZ_PUBLIC_SYMBOL set_process_impersonation(impersonation_token const& token);
78 #endif
79 
81 native_string FZ_PUBLIC_SYMBOL current_username();
82 
83 }
84 
85 namespace std {
86 
88 template <>
89 struct hash<fz::impersonation_token>
90 {
91  std::size_t operator()(fz::impersonation_token const& op) const noexcept
92  {
93  return op.hash();
94  }
95 };
96 
97 }
98 
99 #endif
bool operator==(symmetric_key const &lhs, symmetric_key const &rhs)
Side-channel safe comparison.
Definition: impersonation.hpp:85
Impersonation tokens for a given user can be used to spawn processes running as that user...
Definition: impersonation.hpp:32
native_string current_username()
Returns the username the calling thread is running under.
std::wstring native_string
A string in the system's native character type and encoding. Note: This typedef changes depending on...
Definition: string.hpp:34
String types and assorted functions.
The namespace used by libfilezilla.
Definition: apply.hpp:17