1#ifndef LIBFILEZILLA_IMPERSONATION_HEADER
2#define LIBFILEZILLA_IMPERSONATION_HEADER
11#include <initializer_list>
21#include "glue/windows.hpp"
28class FZ_PUBLIC_SYMBOL user
31 struct FZ_PUBLIC_SYMBOL invalid
33 explicit operator bool()
const;
38 struct FZ_PUBLIC_SYMBOL name
45 explicit operator bool()
const;
49 struct FZ_PUBLIC_SYMBOL
id
53 explicit operator bool()
const;
58 template <
typename T, std::enable_if_t<std::is_constructible_v<name, T>>* =
nullptr>
60 : value_(
name{std::forward<T>(user_name)})
66 explicit operator bool()
const;
70 std::string
const *get_id()
const;
73 std::variant<invalid, name, id> value_;
77namespace impersonation_desktop
100 using mode = std::variant<automatic, isolated, named>;
140class impersonation_token_impl;
197 friend class impersonation_token;
199 std::array<impersonation_capability_state, 3> states_{};
212class FZ_PUBLIC_SYMBOL impersonation_token final
215 impersonation_token();
217 impersonation_token(impersonation_token&&)
noexcept;
218 impersonation_token& operator=(impersonation_token&&)
noexcept;
228 ~impersonation_token() noexcept;
230 explicit operator
bool()
const {
231 return impl_.operator bool();
244 std::size_t
hash() const noexcept;
252 friend class impersonation_token_impl;
253 std::unique_ptr<impersonation_token_impl> impl_;
258bool FZ_PUBLIC_SYMBOL set_process_impersonation(impersonation_token
const& token);
260HANDLE FZ_PUBLIC_SYMBOL get_handle(impersonation_token
const& token);
279struct hash<
fz::impersonation_token>
Definition impersonation.hpp:192
Impersonation tokens for a given user can be used to spawn processes running as that user.
Definition impersonation.hpp:213
std::string uid() const
A opaque unique identifier.
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.
impersonation_token(fz::user const &user, 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.
static impersonation_capabilities get_capabilities(std::initializer_list< impersonation_capability > requested)
Abstract interface for logging strings.
Definition logger.hpp:51
Definition impersonation.hpp:29
std::variant< automatic, isolated, named > mode
Window station and desktop selection mode for impersonated processes.
Definition impersonation.hpp:100
The namespace used by libfilezilla.
Definition apply.hpp:17
native_string current_username()
Returns the username the calling thread is running under.
std::string get_user_id(native_string const &name)
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
native_string get_user_name(std::string const &id)
impersonation_capability_state
Definition impersonation.hpp:174
@ indeterminate
The capability's prerequisites could not be determined.
Definition impersonation.hpp:182
@ not_applicable
The capability does not apply to the platform.
Definition impersonation.hpp:179
@ unavailable
The process does not satisfy the capability's known prerequisites.
Definition impersonation.hpp:185
@ not_requested
The capability was not requested.
Definition impersonation.hpp:176
@ available
The process satisfies the capability's known prerequisites.
Definition impersonation.hpp:188
impersonation_profile_mode
Definition impersonation.hpp:104
@ skip
Do not load the user's profile.
Definition impersonation.hpp:106
@ require_if_roaming
Definition impersonation.hpp:110
@ require
Load the user's profile and fail token construction if loading fails.
Definition impersonation.hpp:113
bool operator==(symmetric_key const &lhs, symmetric_key const &rhs)
Side-channel safe comparison.
bool operator<(strtokenizer< LhsString, LhsDelims > const &lhs, strtokenizer< RhsString, RhsDelims > const &rhs)
strtokenizer class less-than comparator.
Definition string.hpp:566
impersonation_capability
Definition impersonation.hpp:144
@ user_profile
Definition impersonation.hpp:170
@ password
Definition impersonation.hpp:152
@ passwordless
Definition impersonation.hpp:162
String types and assorted functions.
Definition impersonation.hpp:85
Create an isolated window station and desktop for spawned processes.
Definition impersonation.hpp:88
std::wstring desktop_name_prefix
Definition impersonation.hpp:91
Use a caller-provided desktop name, such as L"WinSta0\\Default".
Definition impersonation.hpp:95
Impersonate as any user without checking credentials.
Definition impersonation.hpp:120
Definition impersonation.hpp:118
bool drop_admin_privileges
If true, remove administrative privileges from the impersonation token.
Definition impersonation.hpp:133
impersonation_desktop::mode desktop
Definition impersonation.hpp:127
impersonation_profile_mode profile
Controls whether the user's profile is loaded.
Definition impersonation.hpp:130
Numeric UID on Unix-like systems, string SID on Windows.
Definition impersonation.hpp:50
A user name.
Definition impersonation.hpp:39