2 * Copyright (c) 2008, 2009, 2010, 2011 Kernel Drivers, LLC.
3 * Copyright (c) 2009, 2010, 2011 Your File System, Inc.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * - Redistributions of source code must retain the above copyright notice,
11 * this list of conditions and the following disclaimer.
12 * - Redistributions in binary form must reproduce the above copyright
14 * this list of conditions and the following disclaimer in the
16 * and/or other materials provided with the distribution.
17 * - Neither the names of Kernel Drivers, LLC and Your File System, Inc.
18 * nor the names of their contributors may be used to endorse or promote
19 * products derived from this software without specific prior written
20 * permission from Kernel Drivers, LLC and Your File System, Inc.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
24 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
25 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
26 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 #include "AFSCommon.h"
44 // This is the initial entry point for the driver.
47 // DriverObject Pointer to Driver Object created by I/O manager
48 // RegistryPath Pointer to registry path representing this Driver
51 // Success To indicate Driver's inituaialization processing
53 // NT ERROR STATUS Otherwise -- Driver does not remain loaded
57 DriverEntry( PDRIVER_OBJECT DriverObject,
58 PUNICODE_STRING RegistryPath)
61 NTSTATUS ntStatus = STATUS_SUCCESS;
62 AFSDeviceExt *pDeviceExt;
63 UNICODE_STRING uniDeviceName;
65 UNICODE_STRING uniRoutine;
66 RTL_OSVERSIONINFOW sysVersion;
68 BOOLEAN bExit = FALSE;
73 AFSPrint("AFSLibrary DriverEntry Initialization build %s:%s\n", __DATE__, __TIME__);
76 // Our backdoor to not let the driver load
83 // Return a failure so we can update the binary and manually start it without
84 // having to do a reboot
87 try_return( ntStatus = STATUS_UNSUCCESSFUL);
91 // Perform some initialization
94 AFSLibraryDriverObject = DriverObject;
97 // Setup the registry string
100 AFSRegistryPath.MaximumLength = RegistryPath->MaximumLength;
101 AFSRegistryPath.Length = RegistryPath->Length;
103 AFSRegistryPath.Buffer = (PWSTR)AFSLibExAllocatePoolWithTag( PagedPool,
104 AFSRegistryPath.Length,
105 AFS_GENERIC_MEMORY_13_TAG);
107 if( AFSRegistryPath.Buffer == NULL)
110 AFSPrint("AFS DriverEntry Failed to allocate registry path buffer\n");
112 try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
115 RtlCopyMemory( AFSRegistryPath.Buffer,
116 RegistryPath->Buffer,
117 RegistryPath->Length);
119 RtlZeroMemory( &sysVersion,
120 sizeof( RTL_OSVERSIONINFOW));
122 sysVersion.dwOSVersionInfoSize = sizeof( RTL_OSVERSIONINFOW);
124 RtlGetVersion( &sysVersion);
128 // By not fetching the RtlSetSaclSecurityDescriptor function
129 // pointer it disables the additional of a mandatory label
130 // to the default acl which is returned by AFSRedir for all
131 // security information queries. The addition of the
132 // mandatory label appears to have a negative consequence
133 // for roaming profiles and redirected folders. All links
134 // become untrusted and IE9 is unable to open a new instance
135 // to a non-default home page.
138 // Only retrieve this function for Vista and above since
139 // Mandatory Labels only exist on those operating systems.
142 if( sysVersion.dwMajorVersion >= 6)
144 RtlInitUnicodeString( &uniRoutine,
145 L"RtlSetSaclSecurityDescriptor");
147 AFSRtlSetSaclSecurityDescriptor = (PAFSRtlSetSaclSecurityDescriptor)MmGetSystemRoutineAddress( &uniRoutine);
152 RtlInitUnicodeString( &uniRoutine,
153 L"RtlSetGroupSecurityDescriptor");
155 AFSRtlSetGroupSecurityDescriptor = (PAFSRtlSetGroupSecurityDescriptor)MmGetSystemRoutineAddress( &uniRoutine);
157 ntStatus = AFSCreateDefaultSecurityDescriptor();
159 if( !NT_SUCCESS( ntStatus))
162 AFSPrint("AFS DriverEntry AFSCreateDefaultSecurityDescriptor failed Status %08lX\n", ntStatus);
164 ntStatus = STATUS_SUCCESS;
168 // Initialize the control device
171 RtlInitUnicodeString( &uniDeviceName,
172 AFS_LIBRARY_CONTROL_DEVICE_NAME);
174 ntStatus = IoCreateDevice( DriverObject,
175 sizeof( AFSDeviceExt),
177 FILE_DEVICE_NETWORK_FILE_SYSTEM,
180 &AFSLibraryDeviceObject);
182 if( !NT_SUCCESS( ntStatus))
185 AFSPrint("AFS DriverEntry - Failed to allocate device control object Status %08lX\n", ntStatus);
187 try_return( ntStatus);
191 // Setup the device extension
194 pDeviceExt = (AFSDeviceExt *)AFSLibraryDeviceObject->DeviceExtension;
197 // Now initialize the control device
200 ntStatus = AFSInitializeLibraryDevice();
202 if( !NT_SUCCESS( ntStatus))
205 try_return( ntStatus);
209 // Initialize the worker thread pool counts.
212 pDeviceExt->Specific.Library.WorkerCount = 0;
214 pDeviceExt->Specific.Library.IOWorkerCount = 0;
217 // Fill in the dispatch table
220 for( ulIndex = 0; ulIndex <= IRP_MJ_MAXIMUM_FUNCTION; ulIndex++)
223 DriverObject->MajorFunction[ ulIndex] = AFSDefaultDispatch;
226 DriverObject->MajorFunction[IRP_MJ_CREATE] = AFSCreate;
227 DriverObject->MajorFunction[IRP_MJ_CLOSE] = AFSClose;
228 DriverObject->MajorFunction[IRP_MJ_READ] = AFSRead;
229 DriverObject->MajorFunction[IRP_MJ_WRITE] = AFSWrite;
230 DriverObject->MajorFunction[IRP_MJ_QUERY_INFORMATION] = AFSQueryFileInfo;
231 DriverObject->MajorFunction[IRP_MJ_SET_INFORMATION] = AFSSetFileInfo;
232 DriverObject->MajorFunction[IRP_MJ_QUERY_EA] = AFSQueryEA;
233 DriverObject->MajorFunction[IRP_MJ_SET_EA] = AFSSetEA;
234 DriverObject->MajorFunction[IRP_MJ_FLUSH_BUFFERS] = AFSFlushBuffers;
235 DriverObject->MajorFunction[IRP_MJ_QUERY_VOLUME_INFORMATION] = AFSQueryVolumeInfo;
236 DriverObject->MajorFunction[IRP_MJ_SET_VOLUME_INFORMATION] = AFSSetVolumeInfo;
237 DriverObject->MajorFunction[IRP_MJ_DIRECTORY_CONTROL] = AFSDirControl;
238 DriverObject->MajorFunction[IRP_MJ_FILE_SYSTEM_CONTROL] = AFSFSControl;
239 DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = AFSDevControl;
240 DriverObject->MajorFunction[IRP_MJ_INTERNAL_DEVICE_CONTROL] = AFSInternalDevControl;
241 DriverObject->MajorFunction[IRP_MJ_SHUTDOWN] = AFSShutdown;
242 DriverObject->MajorFunction[IRP_MJ_LOCK_CONTROL] = AFSLockControl;
243 DriverObject->MajorFunction[IRP_MJ_CLEANUP] = AFSCleanup;
244 DriverObject->MajorFunction[IRP_MJ_QUERY_SECURITY] = AFSQuerySecurity;
245 DriverObject->MajorFunction[IRP_MJ_SET_SECURITY] = AFSSetSecurity;
246 DriverObject->MajorFunction[IRP_MJ_SYSTEM_CONTROL] = AFSSystemControl;
247 //DriverObject->MajorFunction[IRP_MJ_QUERY_QUOTA] = AFSQueryQuota;
248 //DriverObject->MajorFunction[IRP_MJ_SET_QUOTA] = AFSSetQuota;
250 DriverObject->DriverUnload = AFSUnload;
252 AFSSysProcess = PsGetCurrentProcessId();
256 if( !NT_SUCCESS( ntStatus))
259 AFSPrint("AFSLibrary DriverEntry failed to initialize %08lX\n", ntStatus);
261 if( AFSRegistryPath.Buffer != NULL)
264 ExFreePool( AFSRegistryPath.Buffer);
267 if( AFSLibraryDeviceObject != NULL)
270 AFSRemoveLibraryDevice();
272 IoDeleteDevice( AFSLibraryDeviceObject);
276 __except( AFSExceptionFilter( __FUNCTION__, GetExceptionCode(), GetExceptionInformation()) )
279 AFSPrint( "EXCEPTION - AFS DriverEntry\n");
281 AFSDumpTraceFilesFnc();
288 AFSUnload( IN PDRIVER_OBJECT DriverObject)
291 UNREFERENCED_PARAMETER(DriverObject);
292 if( AFSGlobalRoot != NULL)
295 AFSInvalidateVolume( AFSGlobalRoot,
296 AFS_INVALIDATE_CALLBACK);
298 ClearFlag( AFSGlobalRoot->Flags, AFS_VOLUME_ACTIVE_GLOBAL_ROOT);
300 AFSShutdownVolumeWorker( AFSGlobalRoot);
303 if( AFSLibraryDeviceObject != NULL)
306 AFSRemoveWorkerPool();
309 if( AFSRegistryPath.Buffer != NULL)
312 ExFreePool( AFSRegistryPath.Buffer);
317 if( AFSDefaultSD != NULL)
319 ExFreePool( AFSDefaultSD);
322 if( AFSLibraryDeviceObject != NULL)
325 AFSRemoveLibraryDevice();
327 IoDeleteDevice( AFSLibraryDeviceObject);