xref: /reactos/ntoskrnl/io/iomgr/symlink.c (revision c2c66aff)
1 /*
2  * PROJECT:         ReactOS Kernel
3  * LICENSE:         GPL - See COPYING in the top level directory
4  * FILE:            ntoskrnl/io/iomgr/symlink.c
5  * PURPOSE:         I/O Wrappers for Symbolic Links
6  * PROGRAMMERS:     Alex Ionescu (alex.ionescu@reactos.org)
7  *                  Eric Kohl
8  */
9 
10 /* INCLUDES *****************************************************************/
11 
12 #include <ntoskrnl.h>
13 #define NDEBUG
14 #include <debug.h>
15 
16 /* FUNCTIONS ****************************************************************/
17 
18 /*
19  * @implemented
20  */
21 NTSTATUS
22 NTAPI
IoCreateSymbolicLink(IN PUNICODE_STRING SymbolicLinkName,IN PUNICODE_STRING DeviceName)23 IoCreateSymbolicLink(IN PUNICODE_STRING SymbolicLinkName,
24                      IN PUNICODE_STRING DeviceName)
25 {
26     OBJECT_ATTRIBUTES ObjectAttributes;
27     HANDLE Handle;
28     NTSTATUS Status;
29     PAGED_CODE();
30 
31     /* Initialize the object attributes and create the link */
32     InitializeObjectAttributes(&ObjectAttributes,
33                                SymbolicLinkName,
34                                OBJ_KERNEL_HANDLE | OBJ_PERMANENT | OBJ_CASE_INSENSITIVE,
35                                NULL,
36                                SePublicDefaultSd);
37     Status = ZwCreateSymbolicLinkObject(&Handle,
38                                         SYMBOLIC_LINK_ALL_ACCESS,
39                                         &ObjectAttributes,
40                                         DeviceName);
41     if (NT_SUCCESS(Status)) ZwClose(Handle);
42 
43     /* Return status */
44     return Status;
45 }
46 
47 /*
48  * @implemented
49  */
50 NTSTATUS
51 NTAPI
IoCreateUnprotectedSymbolicLink(IN PUNICODE_STRING SymbolicLinkName,IN PUNICODE_STRING DeviceName)52 IoCreateUnprotectedSymbolicLink(IN PUNICODE_STRING SymbolicLinkName,
53                                 IN PUNICODE_STRING DeviceName)
54 {
55     SECURITY_DESCRIPTOR SecurityDescriptor;
56     OBJECT_ATTRIBUTES ObjectAttributes;
57     HANDLE Handle;
58     NTSTATUS Status;
59     PAGED_CODE();
60 
61     /* Create an SD */
62     Status = RtlCreateSecurityDescriptor(&SecurityDescriptor,
63                                          SECURITY_DESCRIPTOR_REVISION);
64     if (!NT_SUCCESS(Status)) return Status;
65 
66     /* Set the DACL */
67     Status = RtlSetDaclSecurityDescriptor(&SecurityDescriptor,
68                                           TRUE,
69                                           NULL,
70                                           TRUE);
71     if (!NT_SUCCESS(Status)) return Status;
72 
73     /* Initialize the object attributes and create the link */
74     InitializeObjectAttributes(&ObjectAttributes,
75                                SymbolicLinkName,
76                                OBJ_KERNEL_HANDLE | OBJ_PERMANENT | OBJ_CASE_INSENSITIVE,
77                                NULL,
78                                &SecurityDescriptor);
79     Status = ZwCreateSymbolicLinkObject(&Handle,
80                                         SYMBOLIC_LINK_ALL_ACCESS,
81                                         &ObjectAttributes,
82                                         DeviceName);
83     if (NT_SUCCESS(Status)) ZwClose(Handle);
84 
85     /* Return status */
86     return Status;
87 }
88 
89 /*
90  * @implemented
91  */
92 NTSTATUS
93 NTAPI
IoDeleteSymbolicLink(IN PUNICODE_STRING SymbolicLinkName)94 IoDeleteSymbolicLink(IN PUNICODE_STRING SymbolicLinkName)
95 {
96     OBJECT_ATTRIBUTES ObjectAttributes;
97     HANDLE Handle;
98     NTSTATUS Status;
99     PAGED_CODE();
100 
101     /* Initialize the object attributes and open the link */
102     InitializeObjectAttributes(&ObjectAttributes,
103                                SymbolicLinkName,
104                                OBJ_KERNEL_HANDLE | OBJ_CASE_INSENSITIVE,
105                                NULL,
106                                NULL);
107     Status = ZwOpenSymbolicLinkObject(&Handle, DELETE, &ObjectAttributes);
108     if (!NT_SUCCESS(Status)) return Status;
109 
110     /* Make the link temporary and close its handle */
111     Status = ZwMakeTemporaryObject(Handle);
112     if (NT_SUCCESS(Status)) ZwClose(Handle);
113 
114     /* Return status */
115     return Status;
116 }
117 
118 /* EOF */
119