7个版本

使用旧Rust 2015

0.3.0 2021年1月11日
0.2.2 2020年6月29日
0.2.1 2020年5月15日
0.2.0 2020年3月16日
0.1.0 2018年8月20日

Windows API 中排名 30

Download history 5145/week @ 2024-03-14 5214/week @ 2024-03-21 4235/week @ 2024-03-28 4429/week @ 2024-04-04 5847/week @ 2024-04-11 5142/week @ 2024-04-18 5583/week @ 2024-04-25 4015/week @ 2024-05-02 4583/week @ 2024-05-09 5517/week @ 2024-05-16 4270/week @ 2024-05-23 3008/week @ 2024-05-30 4558/week @ 2024-06-06 3778/week @ 2024-06-13 3802/week @ 2024-06-20 2535/week @ 2024-06-27

每月下载 15,358
12 个crate中使用 (直接使用2个)

MIT 协议

610KB
2K SLoC

包含 (WOFF字体,120KB) docs/Heuristica-Italic.woff,(WOFF字体,90KB) docs/FiraSans-Medium.woff,(WOFF字体,92KB) docs/FiraSans-Regular.woff,(WOFF字体,56KB) docs/SourceCodePro-Regular.woff,(WOFF字体,56KB) docs/SourceCodePro-Semibold.woff,(WOFF字体,49KB) docs/SourceSerifPro-Bold.woff 以及更多

windows-acl

Build Status Crates.io

简化Windows ACL操作的Rust库。

使用windows-acl

首先,将以下行添加到项目Cargo.toml文件的依赖关系部分。

winapi =0.3.5”
windows-acl =0.1.0

在主Rust源代码文件中,添加windows-acl外部crate并按如下方式导入符号

extern crate winapi;
extern crate windows_acl;

use winapi::um::winnt::{
    PSID, FILE_GENERIC_READ, FILE_GENERIC_EXECUTE, FILE_GENERIC_WRITE,
    FILE_ALL_ACCESS, SYSTEM_MANDATORY_LABEL_NO_WRITE_UP,
    SYSTEM_MANDATORY_LABEL_NO_READ_UP, SYSTEM_MANDATORY_LABEL_NO_EXECUTE_UP
};
use windows_acl::acl::ACL;

注意: 修改系统ACL条目需要管理员权限或获取SeSecurityPrivilege权限。

添加强制完整性标签

    let high_integrity_level_sid = string_to_sid("S-1-16-12288").unwrap();

    let mut acl = ACL::from_file_path("C:\\Users\\andy\\work\\high_il", true).unwrap();

    // Set high_il to be a high integrity level directory
    match acl.integrity_level(
                high_integrity_level_sid.as_ptr() as PSID,
                true,
                SYSTEM_MANDATORY_LABEL_NO_WRITE_UP |
                    SYSTEM_MANDATORY_LABEL_NO_READ_UP |
                    SYSTEM_MANDATORY_LABEL_NO_EXECUTE_UP
            ) {
        Ok(status) => {
            if !status {
                println!("We had an internal issue trying to add high integrity level to high_il");
            }
        },
        Err(code) => {
            println!("Failed to add high integrity level to high_il: error={}", code);
        }
    }

添加审计条目

    let world_sid = string_to_sid("S-1-1-0").unwrap();

    let mut acl = ACL::from_file_path("C:\\Users\\andy\\work\\sensitive_files", true).unwrap();

    // Audit every file operation in sensitive_files from anyone in the Everyone group
    match acl.audit(
                world_sid.as_ptr() as PSID,
                true,
                FILE_ALL_ACCESS,
                true,
                true
            ) {
        Ok(status) => {
            if !status {
                println!("We had an internal issue trying to add audit entry to sensitive_files");
            }
        },
        Err(code) => {
            println!("Failed to add audit entry to sensitive_files: error={}", code);
        }
    }

拒绝访客对目录的访问

    let guests = string_to_sid("S-1-5-32-546").unwrap();

    let mut acl = ACL::from_file_path("C:\\Users\\andy\\work\\sensitive_files", false).unwrap();

    // Guests cannot read anything in this directory. However, they can still drop files there
    match acl.deny(guests.as_ptr() as PSID, true, FILE_GENERIC_READ) {
        Ok(status) => {
            if !status {
                println!("We had an internal issue trying to add a deny entry to sensitive_files");
            }
        },
        Err(code) => {
            println!("Failed to add deny entry: error={}", code);
        }
    }

删除条目

    let world_sid = string_to_sid("S-1-1-0").unwrap();

    let mut acl = ACL::from_file_path("C:\\Users\\andy\\work\\sensitive_files", true).unwrap();

    // Remove a SystemAudit entry; remove() can also remove DACL entries as well
    match acl.remove(world_sid.as_ptr() as PSID, Some(AceType::SystemAudit), None) {
        Ok(removed) => {
            println!("Removed {} entries", removed);
        },
        Err(code) => {
            println!("Failed to remove entry: error={}", code);
        }
    }

示例应用程序

查看query_acl.rs文件,位于example/目录中。

单元测试

当前的单元测试期望在具有提升权限的单线程环境中运行。默认情况下,Rust使用多个线程执行单元测试。为了成功运行测试,必须执行以下操作

  1. 打开具有提升权限的管理员命令提示符或PowerShell终端。
  2. RUST_TEST_THREADS环境变量设置为1。
  3. 运行cargo test

依赖关系