⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 symlink.c

📁 ReactOS是一些高手根据Windows XP的内核编写出的类XP。内核实现机理和API函数调用几乎相同。甚至可以兼容XP的程序。喜欢研究系统内核的人可以看一看。
💻 C
字号:
/*
 * PROJECT:         ReactOS Kernel
 * LICENSE:         GPL - See COPYING in the top level directory
 * FILE:            ntoskrnl/io/symlink.c
 * PURPOSE:         I/O Wrappers for Symbolic Links
 * PROGRAMMERS:     Alex Ionescu (alex.ionescu@reactos.org)
 *                  Eric Kohl
 */

/* INCLUDES *****************************************************************/

#include <ntoskrnl.h>
#define NDEBUG
#include <internal/debug.h>

/* FUNCTIONS ****************************************************************/

/*
 * @implemented
 */
NTSTATUS
NTAPI
IoCreateSymbolicLink(IN PUNICODE_STRING SymbolicLinkName,
                     IN PUNICODE_STRING DeviceName)
{
    OBJECT_ATTRIBUTES ObjectAttributes;
    HANDLE Handle;
    NTSTATUS Status;
    PAGED_CODE();

    /* Initialize the object attributes and create the link */
    InitializeObjectAttributes(&ObjectAttributes,
                               SymbolicLinkName,
                               OBJ_PERMANENT | OBJ_CASE_INSENSITIVE,
                               NULL,
                               SePublicDefaultSd);
    Status = ZwCreateSymbolicLinkObject(&Handle,
                                        SYMBOLIC_LINK_ALL_ACCESS,
                                        &ObjectAttributes,
                                        DeviceName);
    if (NT_SUCCESS(Status)) ZwClose(Handle);

    /* Return status */
    return Status;
}

/*
 * @implemented
 */
NTSTATUS
NTAPI
IoCreateUnprotectedSymbolicLink(IN PUNICODE_STRING SymbolicLinkName,
                                IN PUNICODE_STRING DeviceName)
{
    SECURITY_DESCRIPTOR SecurityDescriptor;
    OBJECT_ATTRIBUTES ObjectAttributes;
    HANDLE Handle;
    NTSTATUS Status;
    PAGED_CODE();

    /* Create an SD */
    Status = RtlCreateSecurityDescriptor(&SecurityDescriptor,
                                         SECURITY_DESCRIPTOR_REVISION);
    if (!NT_SUCCESS(Status)) return Status;

    /* Set the DACL */
    Status = RtlSetDaclSecurityDescriptor(&SecurityDescriptor,
                                          TRUE,
                                          NULL,
                                          TRUE);
    if (!NT_SUCCESS(Status)) return Status;

    /* Initialize the object attributes and create the link */
    InitializeObjectAttributes(&ObjectAttributes,
                               SymbolicLinkName,
                               OBJ_PERMANENT | OBJ_CASE_INSENSITIVE,
                               NULL,
                               &SecurityDescriptor);
    Status = ZwCreateSymbolicLinkObject(&Handle,
                                        SYMBOLIC_LINK_ALL_ACCESS,
                                        &ObjectAttributes,
                                        DeviceName);
    if (NT_SUCCESS(Status)) ZwClose(Handle);

    /* Return status */
    return Status;
}

/*
 * @implemented
 */
NTSTATUS
NTAPI
IoDeleteSymbolicLink(IN PUNICODE_STRING SymbolicLinkName)
{
    OBJECT_ATTRIBUTES ObjectAttributes;
    HANDLE Handle;
    NTSTATUS Status;
    PAGED_CODE();

    /* Initialize the object attributes and open the link */
    InitializeObjectAttributes(&ObjectAttributes,
                               SymbolicLinkName,
                               OBJ_CASE_INSENSITIVE,
                               NULL,
                               NULL);
    Status = ZwOpenSymbolicLinkObject(&Handle, DELETE, &ObjectAttributes);
    if (!NT_SUCCESS(Status)) return Status;

    /* Make the link temporary and close its handle */
    Status = ZwMakeTemporaryObject(Handle);
    if (NT_SUCCESS(Status)) ZwClose(Handle);

    /* Return status */
    return Status;
}

/* EOF */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -