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