Compiling a First Program
Parse a security descriptor, read its owner, and print the owner's security identifier (SID). This example runs entirely in userspace and does not open tokens or change system security.
Before you start #
Prepare these inputs:
- A C compiler and
pkg-config. - The libpeios development package and its matching runtime library.
- A writable directory for the source and executable.
Creating the program #
Save this complete program as first.c:
int
The Security Descriptor Definition Language (SDDL) string sets the owner and group to Administrators. Its discretionary access control list (DACL) grants that group full file access. Parsing this string does not grant any access to the process running the example.
Building and running #
-
Compile the source with the package's compiler and linker options:
-
Run the executable:
Checking the result #
The program prints:
security descriptor: 84 bytes
owner: S-1-5-32-544
The owner SID identifies Administrators. The byte count describes the encoded descriptor produced by this example, including its owner, group, and access control list.
Understanding ownership #
The program probes the output size before allocating each variable-sized buffer. The string allocation adds one byte for the terminating NUL.
The parsed view and owner pointer borrow the descriptor allocation. The program frees that allocation after formatting the owner, so every borrowed pointer remains valid throughout its use.
Read library conventions for the result and ownership rules used by the other SDK functions.