libfilezilla
Toggle main menu visibility
Loading...
Searching...
No Matches
lib
libfilezilla
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
18
namespace
fz
{
19
20
class
logger_interface
;
21
22
struct
impersonation_options
23
{
25
struct
pwless_type
{};
26
static
constexpr
pwless_type
pwless{};
27
28
#if FZ_WINDOWS
29
bool
drop_admin_privileges =
true
;
30
#else
32
fz::native_string
group;
33
#endif
34
};
35
36
class
impersonation_token_impl;
37
46
class
FZ_PUBLIC_SYMBOL impersonation_token final
47
{
48
public
:
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
68
fz::native_string
username
()
const
;
69
71
fz::native_string
home
()
const
;
72
74
std::size_t
hash
() const noexcept;
75
77
std::
string
uid
() const;
78
79
private:
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
88
bool
FZ_PUBLIC_SYMBOL set_process_impersonation(impersonation_token
const
& token);
89
#endif
90
92
native_string
FZ_PUBLIC_SYMBOL
current_username
();
93
96
std::string FZ_PUBLIC_SYMBOL
get_user_uid
(
native_string
const
& username);
97
98
}
99
100
namespace
std {
101
103
template
<>
104
struct
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
fz::impersonation_token
Impersonation tokens for a given user can be used to spawn processes running as that user.
Definition
impersonation.hpp:47
fz::impersonation_token::uid
std::string uid() const
A opaque unique identifier.
fz::impersonation_token::impersonation_token
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::impersonation_token::home
fz::native_string home() const
Returns home directory, may be empty.
fz::impersonation_token::username
fz::native_string username() const
Returns the name of the impersonated user.
fz::impersonation_token::hash
std::size_t hash() const noexcept
For std::hash.
fz::logger_interface
Abstract interface for logging strings.
Definition
logger.hpp:51
logger.hpp
Interface for logging.
fz
The namespace used by libfilezilla.
Definition
apply.hpp:17
fz::get_user_uid
std::string get_user_uid(native_string const &username)
fz::current_username
native_string current_username()
Returns the username the calling thread is running under.
fz::native_string
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
fz::operator==
bool operator==(symmetric_key const &lhs, symmetric_key const &rhs)
Side-channel safe comparison.
string.hpp
String types and assorted functions.
fz::impersonation_options::pwless_type
Impersonate as any user without checking credentials.
Definition
impersonation.hpp:25
fz::impersonation_options
Definition
impersonation.hpp:23
Generated by
1.17.0