13725d33fb2f64a3401db53232b90b8ca4d35a1e
[reactos.git] / reactos / ntoskrnl / io / symlink.c
1 /* $Id: symlink.c,v 1.33 2003/07/10 15:47:00 royce Exp $
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: ntoskrnl/io/symlink.c
6 * PURPOSE: Implements symbolic links
7 * PROGRAMMER: David Welch (welch@mcmail.com)
8 * UPDATE HISTORY:
9 * Created 22/05/98
10 */
11
12 /* INCLUDES *****************************************************************/
13
14 #include <ddk/ntddk.h>
15 #include <internal/se.h>
16
17 #define NDEBUG
18 #include <internal/debug.h>
19
20
21 /* FUNCTIONS ****************************************************************/
22
23 /**********************************************************************
24 * NAME EXPORTED
25 * IoCreateSymbolicLink
26 *
27 * DESCRIPTION
28 *
29 * ARGUMENTS
30 *
31 * RETURN VALUE
32 *
33 * REVISIONS
34 *
35 * @implemented
36 */
37 NTSTATUS STDCALL
38 IoCreateSymbolicLink(PUNICODE_STRING SymbolicLinkName,
39 PUNICODE_STRING DeviceName)
40 {
41 OBJECT_ATTRIBUTES ObjectAttributes;
42 HANDLE Handle;
43 NTSTATUS Status;
44
45 assert_irql(PASSIVE_LEVEL);
46
47 DPRINT("IoCreateSymbolicLink(SymbolicLinkName %wZ, DeviceName %wZ)\n",
48 SymbolicLinkName,
49 DeviceName);
50
51 InitializeObjectAttributes(&ObjectAttributes,
52 SymbolicLinkName,
53 OBJ_PERMANENT,
54 NULL,
55 SePublicDefaultSd);
56
57 Status = NtCreateSymbolicLinkObject(&Handle,
58 SYMBOLIC_LINK_ALL_ACCESS,
59 &ObjectAttributes,
60 DeviceName);
61 if (!NT_SUCCESS(Status))
62 {
63 DPRINT1("NtCreateSymbolicLinkObject() failed (Status %lx)\n", Status);
64 return(Status);
65 }
66
67 NtClose(Handle);
68
69 return(STATUS_SUCCESS);
70 }
71
72
73 /**********************************************************************
74 * NAME EXPORTED
75 * IoCreateUnprotectedSymbolicLink
76 *
77 * DESCRIPTION
78 *
79 * ARGUMENTS
80 *
81 * RETURN VALUE
82 *
83 * REVISIONS
84 *
85 * @implemented
86 */
87 NTSTATUS STDCALL
88 IoCreateUnprotectedSymbolicLink(PUNICODE_STRING SymbolicLinkName,
89 PUNICODE_STRING DeviceName)
90 {
91 SECURITY_DESCRIPTOR SecurityDescriptor;
92 OBJECT_ATTRIBUTES ObjectAttributes;
93 HANDLE Handle;
94 NTSTATUS Status;
95
96 assert_irql(PASSIVE_LEVEL);
97
98 DPRINT("IoCreateUnprotectedSymbolicLink(SymbolicLinkName %wZ, DeviceName %wZ)\n",
99 SymbolicLinkName,
100 DeviceName);
101
102 Status = RtlCreateSecurityDescriptor(&SecurityDescriptor,
103 SECURITY_DESCRIPTOR_REVISION);
104 if (!NT_SUCCESS(Status))
105 {
106 DPRINT1("RtlCreateSecurityDescriptor() failed (Status %lx)\n", Status);
107 return(Status);
108 }
109
110 Status = RtlSetDaclSecurityDescriptor(&SecurityDescriptor,
111 TRUE,
112 NULL,
113 TRUE);
114 if (!NT_SUCCESS(Status))
115 {
116 DPRINT1("RtlSetDaclSecurityDescriptor() failed (Status %lx)\n", Status);
117 return(Status);
118 }
119
120 InitializeObjectAttributes(&ObjectAttributes,
121 SymbolicLinkName,
122 OBJ_PERMANENT,
123 NULL,
124 &SecurityDescriptor);
125
126 Status = NtCreateSymbolicLinkObject(&Handle,
127 SYMBOLIC_LINK_ALL_ACCESS,
128 &ObjectAttributes,
129 DeviceName);
130 if (!NT_SUCCESS(Status))
131 {
132 DPRINT1("NtCreateSymbolicLinkObject() failed (Status %lx)\n", Status);
133 return(Status);
134 }
135
136 NtClose(Handle);
137
138 return(STATUS_SUCCESS);
139 }
140
141
142 /**********************************************************************
143 * NAME EXPORTED
144 * IoDeleteSymbolicLink
145 *
146 * DESCRIPTION
147 *
148 * ARGUMENTS
149 *
150 * RETURN VALUE
151 *
152 * REVISIONS
153 *
154 * @implemented
155 */
156 NTSTATUS STDCALL
157 IoDeleteSymbolicLink(PUNICODE_STRING SymbolicLinkName)
158 {
159 OBJECT_ATTRIBUTES ObjectAttributes;
160 HANDLE Handle;
161 NTSTATUS Status;
162
163 assert_irql(PASSIVE_LEVEL);
164
165 DPRINT("IoDeleteSymbolicLink (SymbolicLinkName %S)\n",
166 SymbolicLinkName->Buffer);
167
168 InitializeObjectAttributes(&ObjectAttributes,
169 SymbolicLinkName,
170 OBJ_OPENLINK,
171 NULL,
172 NULL);
173
174 Status = NtOpenSymbolicLinkObject(&Handle,
175 SYMBOLIC_LINK_ALL_ACCESS,
176 &ObjectAttributes);
177 if (!NT_SUCCESS(Status))
178 return(Status);
179
180 Status = NtMakeTemporaryObject(Handle);
181 NtClose(Handle);
182
183 return(Status);
184 }
185
186 /* EOF */