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
7
8#include <memory>
9#include <functional>
10
11#include "string.hpp"
12#include "logger.hpp"
13
14#ifdef FZ_WINDOWS
15#include "glue/windows.hpp"
16#endif
17
18namespace fz {
19
21
23{
25 struct pwless_type{};
26 static constexpr pwless_type pwless{};
27
28#if FZ_WINDOWS
29 bool drop_admin_privileges = true;
30#else
33#endif
34};
35
36class impersonation_token_impl;
37
46class FZ_PUBLIC_SYMBOL impersonation_token final
47{
48public:
49 impersonation_token();
50
51 impersonation_token(impersonation_token&&) noexcept;
52 impersonation_token& operator=(impersonation_token&&) noexcept;
53
55 explicit impersonation_token(fz::native_string const& username, fz::native_string const &password, fz::logger_interface& logger = get_null_logger(), impersonation_options const& opts = {});
56 explicit impersonation_token(fz::native_string const& username, impersonation_options::pwless_type, fz::logger_interface& logger = get_null_logger(), impersonation_options const& opts = {});
57
58 ~impersonation_token() noexcept;
59
60 explicit operator bool() const {
61 return impl_.operator bool();
62 }
63
64 bool operator==(impersonation_token const&) const;
65 bool operator<(impersonation_token const&) const;
66
69
72
74 std::size_t hash() const noexcept;
75
77 std::string uid() const;
78
79private:
80 impersonation_token(fz::native_string const& username, fz::native_string const *password, fz::logger_interface& logger = get_null_logger(), impersonation_options const& opts = {});
81
82 friend class impersonation_token_impl;
83 std::unique_ptr<impersonation_token_impl> impl_;
84};
85
86#if !FZ_WINDOWS
88bool FZ_PUBLIC_SYMBOL set_process_impersonation(impersonation_token const& token);
89#endif
90
93
96std::string FZ_PUBLIC_SYMBOL get_user_uid(native_string const& username);
97
98}
99
100namespace std {
101
103template <>
104struct hash<fz::impersonation_token>
105{
106 std::size_t operator()(fz::impersonation_token const& op) const noexcept
107 {
108 return op.hash();
109 }
110};
111
112}
113
114#endif
Impersonation tokens for a given user can be used to spawn processes running as that user.
Definition impersonation.hpp:47
std::string uid() const
A opaque unique identifier.
impersonation_token(fz::native_string const &username, fz::native_string const &password, fz::logger_interface &logger=get_null_logger(), impersonation_options const &opts={})
Creates an impersonation token, verifying credentials in the process.
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.
Abstract interface for logging strings.
Definition logger.hpp:51
Interface for logging.
The namespace used by libfilezilla.
Definition apply.hpp:17
std::string get_user_uid(native_string const &username)
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:69
bool operator==(symmetric_key const &lhs, symmetric_key const &rhs)
Side-channel safe comparison.
String types and assorted functions.
Impersonate as any user without checking credentials.
Definition impersonation.hpp:25
Definition impersonation.hpp:23