xentara-utils v2.0.4
The Xentara Utility Library
Loading...
Searching...
No Matches
xentara::utils::windows::Sid Class Referencefinal

A Windows security descriptor (SID) that is automatically freed on destruct. More...

#include <xentara/utils/windows/Sid.hpp>

+ Inheritance diagram for xentara::utils::windows::Sid:

Classes

class  Setter
 Helper class for calling functions that take an output parameter. More...
 

Public Types

using NativeType = PSID
 A native Windows SID pointer.
 

Public Member Functions

constexpr Sid () noexcept=default
 Default constructor.
 
constexpr Sid (PSID sid) noexcept
 Conversion from a native SID pointer.
 
constexpr Sid (Sid &&other) noexcept
 Move constructor.
 
 ~Sid ()
 Destructor. Frees the SID.
 
auto operator= (Sid &&rhs) noexcept -> Sid &
 Move assignment operator.
 
 operator PSID () const
 Conversion to a native SID pointer.
 
constexpr operator bool () const noexcept
 Checks whether the object contains an SID.
 
auto operator= (PSID sid) noexcept -> Sid &
 Assignment from a native SID pointer.
 
constexpr auto release () noexcept -> PSID
 Removes the SID and passes ownership to the caller.
 
auto reset () noexcept -> void
 Frees the SID, if any.
 
auto setter () noexcept -> Setter
 Gets a setter for use as an output parameter for C functions.
 

Detailed Description

A Windows security descriptor (SID) that is automatically freed on destruct.

This class can be moved but not copied.

Note
This class is only available under Windows

Member Typedef Documentation

◆ NativeType

A native Windows SID pointer.

Constructor & Destructor Documentation

◆ Sid() [1/3]

constexpr xentara::utils::windows::Sid::Sid ( )
constexprdefaultnoexcept

Default constructor.

Creates an empty object that does not contain an SID.

◆ Sid() [2/3]

constexpr xentara::utils::windows::Sid::Sid ( PSID  sid)
constexprnoexcept

Conversion from a native SID pointer.

Parameters
sidThe native SID, or nullptr for none.

◆ Sid() [3/3]

constexpr xentara::utils::windows::Sid::Sid ( Sid &&  other)
constexprnoexcept

Move constructor.

Takes ownership of the other object’s SID, if any.

Parameters
otherThe object to move. Will be reset and no longer contain an SID afterwards.

◆ ~Sid()

xentara::utils::windows::Sid::~Sid ( )

Destructor. Frees the SID.

Member Function Documentation

◆ operator bool()

constexpr xentara::utils::windows::Sid::operator bool ( ) const
explicitconstexprnoexcept

Checks whether the object contains an SID.

◆ operator PSID()

xentara::utils::windows::Sid::operator PSID ( ) const

Conversion to a native SID pointer.

Returns
The contained SID, or nullptr for none.

◆ operator=() [1/2]

auto xentara::utils::windows::Sid::operator= ( PSID  sid) -> Sid &
noexcept

Assignment from a native SID pointer.

Any existing SID is freed.

Parameters
sidThe native SID pointer, or nullptr for none.

◆ operator=() [2/2]

auto xentara::utils::windows::Sid::operator= ( Sid &&  rhs) -> Sid &
noexcept

Move assignment operator.

Takes ownership of the other SID’s value. Any existing SID pointer is freed.

Parameters
rhsThe object to move. Will be reset and no longer contain an SID afterwards.

◆ release()

constexpr auto xentara::utils::windows::Sid::release ( ) -> PSID
constexprnoexcept

Removes the SID and passes ownership to the caller.

After this call, this object will no longer contain an SID.

Returns
The native SID pointer, or nullptr for none. The caller must assume ownership of the SID and free it when it is no longer needed.

◆ reset()

auto xentara::utils::windows::Sid::reset ( ) -> void
noexcept

Frees the SID, if any.

◆ setter()

auto xentara::utils::windows::Sid::setter ( ) -> Setter
noexcept

Gets a setter for use as an output parameter for C functions.

This function returns a helper object that can be passed to a function that takes an PSID * as output parameter, like e.g. AllocateAndInitializeSid (). This provides a safe way of creating SIDs using such a function without running the risk of leaking the created objects.

AllocateAndInitializeSid() can be called like this, for example:

AllocateAndInitializeSid(&worldAuthority, 1, SECURITY_WORLD_RID, 0, 0, 0, 0, 0, 0, 0, newSid.setter());
A Windows security descriptor (SID) that is automatically freed on destruct.
Definition Sid.hpp:27
auto setter() noexcept -> Setter
Gets a setter for use as an output parameter for C functions.
Definition Sid.hpp:164