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