wil

Crates.iowil
lib.rswil
version0.0.6
sourcesrc
created_at2020-05-20 08:24:30.449945
updated_at2020-05-21 21:12:01.703014
descriptionThis crates is a demonstrator of what a Windows Implementation Library in Rust could look like
homepage
repositoryhttps://github.com/jeanga/wil-rs
max_upload_size
id243724
size15,221
Jean Gautier (jeanga)

documentation

README

wil-rs

Windows Implementation Library for Rust

Documentation

This crate does not provide raw FFI bindings to Windows API (the winapi crate is what you are looking for). This crate does demonstrate what a Windows Implementation Library could look like in Rust ("à la" https://github.com/microsoft/wil in C++).

The winapi crate is doing a great job in providing the bindings for Windows APIs. What winapi does not provide is a safety wrapper arroung those APIs (with error handling, resource management, ...).

This "wil" crate aims to present what could be a safe wrapper for Windows API.

If this crate is massively missing that something you need. Feel free to create an issue, open a pull request.

Frequently asked questions

Example

Cargo.toml:

[target.'cfg(windows)'.dependencies]
wil = "0.0.3" 
winapi = "0.3.8"

main.rs:


use wil::token::Token;
use wil::errorhandling::WinAPIError;

use winapi::um::winnt::{TokenImpersonation, TokenPrimary};
use winapi::um::winnt::{TOKEN_DUPLICATE, TOKEN_QUERY, TOKEN_QUERY_SOURCE};

fn main() -> Result<(), WinAPIError> {

    let token =
        Token::from_current_process(TOKEN_DUPLICATE | TOKEN_QUERY | TOKEN_QUERY_SOURCE)?;

    let token = if token.token_type()? == TokenPrimary {
        token.duplicate(TokenImpersonation)?
    } else {
        token
    };

    if !token.is_admin()? {
        if token.can_elevate()? {
            println!("user is not an admin but can elevate to one");
        } else {
            println!("user is not an admin");
        }
    }
    else {
        println!("user is an admin");
    }
    Ok(())
}


Commit count: 20

cargo fmt