libfilezilla
Loading...
Searching...
No Matches
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
13namespace fz {
14
15#if !FZ_WINDOWS
16enum class impersonation_flag
17{
18 pwless
19};
20#endif
21
22class impersonation_token_impl;
23
32class FZ_PUBLIC_SYMBOL impersonation_token final
33{
34public:
36
38 impersonation_token& operator=(impersonation_token&&) noexcept;
39
41 explicit impersonation_token(fz::native_string const& username, fz::native_string const& password);
42
43#if !FZ_WINDOWS
45 explicit impersonation_token(fz::native_string const& username, impersonation_flag flag, fz::native_string const& group = {});
46#endif
47
48 ~impersonation_token() noexcept;
49
50 explicit operator bool() const {
51 return impl_.operator bool();
52 }
53
54 bool operator==(impersonation_token const&) const;
55 bool operator<(impersonation_token const&) const;
56
59
62
64 std::size_t hash() const noexcept;
65
66private:
67 friend class impersonation_token_impl;
68 std::unique_ptr<impersonation_token_impl> impl_;
69};
70
71#if !FZ_WINDOWS
73bool FZ_PUBLIC_SYMBOL set_process_impersonation(impersonation_token const& token);
74#endif
75
78
79}
80
81namespace std {
82
84template <>
85struct hash<fz::impersonation_token>
86{
87 std::size_t operator()(fz::impersonation_token const& op) const noexcept
88 {
89 return op.hash();
90 }
91};
92
93}
94
95#endif
Impersonation tokens for a given user can be used to spawn processes running as that user.
Definition: impersonation.hpp:33
impersonation_token(fz::native_string const &username, fz::native_string const &password)
Creates an impersonation token, verifying credentials in the proceess.
fz::native_string home() const
Returns home directory, may be empty.
fz::native_string username() const
Returns the name of the impersonated user.
std::size_t hash() const noexcept
For std::hash.
The namespace used by libfilezilla.
Definition: apply.hpp:17
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.