00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
#include "precomp.h"
00022
#pragma hdrstop
00023
00024
NTSTATUS
00025 ConsoleAddShare(
00026 IN ACCESS_MASK DesiredAccess,
00027 IN ULONG DesiredShareAccess,
00028 IN OUT
PCONSOLE_SHARE_ACCESS ShareAccess,
00029 IN OUT
PHANDLE_DATA HandleData
00030 )
00031
00032 {
00033 ULONG Ocount;
00034 ULONG ReadAccess;
00035 ULONG WriteAccess;
00036 ULONG SharedRead;
00037 ULONG SharedWrite;
00038
00039
00040
00041
00042
00043 ReadAccess = (DesiredAccess & GENERIC_READ) != 0;
00044 WriteAccess = (DesiredAccess & GENERIC_WRITE) != 0;
00045
00046 SharedRead = (DesiredShareAccess & FILE_SHARE_READ) != 0;
00047 SharedWrite = (DesiredShareAccess & FILE_SHARE_WRITE) != 0;
00048
00049
00050
00051
00052
00053
00054 Ocount = ShareAccess->OpenCount;
00055
00056
if ( (ReadAccess && (ShareAccess->SharedRead < Ocount))
00057 ||
00058 (WriteAccess && (ShareAccess->SharedWrite < Ocount))
00059 ||
00060 ((ShareAccess->Readers != 0) && !SharedRead)
00061 ||
00062 ((ShareAccess->Writers != 0) && !SharedWrite)
00063 ) {
00064
00065
00066
00067
00068
00069
00070
return STATUS_SHARING_VIOLATION;
00071
00072 }
else {
00073
00074
00075
00076
00077
00078
00079
00080 ShareAccess->OpenCount++;
00081
00082 ShareAccess->Readers += ReadAccess;
00083 ShareAccess->Writers += WriteAccess;
00084
00085 ShareAccess->SharedRead += SharedRead;
00086 ShareAccess->SharedWrite += SharedWrite;
00087 HandleData->Access = DesiredAccess;
00088 HandleData->ShareAccess = DesiredShareAccess;
00089
00090
return STATUS_SUCCESS;
00091 }
00092 }
00093
00094
NTSTATUS
00095 ConsoleDupShare(
00096 IN ACCESS_MASK DesiredAccess,
00097 IN ULONG DesiredShareAccess,
00098 IN OUT
PCONSOLE_SHARE_ACCESS ShareAccess,
00099 IN OUT
PHANDLE_DATA TargetHandleData
00100 )
00101
00102 {
00103 ULONG ReadAccess;
00104 ULONG WriteAccess;
00105 ULONG SharedRead;
00106 ULONG SharedWrite;
00107
00108
00109
00110
00111
00112 ReadAccess = (DesiredAccess & GENERIC_READ) != 0;
00113 WriteAccess = (DesiredAccess & GENERIC_WRITE) != 0;
00114
00115 SharedRead = (DesiredShareAccess & FILE_SHARE_READ) != 0;
00116 SharedWrite = (DesiredShareAccess & FILE_SHARE_WRITE) != 0;
00117
00118
if (ShareAccess->OpenCount == 0) {
00119
ASSERT (
FALSE);
00120
return STATUS_SHARING_VIOLATION;
00121 }
00122
00123 ShareAccess->OpenCount++;
00124
00125 ShareAccess->Readers += ReadAccess;
00126 ShareAccess->Writers += WriteAccess;
00127
00128 ShareAccess->SharedRead += SharedRead;
00129 ShareAccess->SharedWrite += SharedWrite;
00130
00131 TargetHandleData->Access = DesiredAccess;
00132 TargetHandleData->ShareAccess = DesiredShareAccess;
00133
00134
return STATUS_SUCCESS;
00135 }
00136
00137
NTSTATUS
00138 ConsoleRemoveShare(
00139 IN ULONG DesiredAccess,
00140 IN ULONG DesiredShareAccess,
00141 IN OUT
PCONSOLE_SHARE_ACCESS ShareAccess
00142 )
00143
00144 {
00145 ULONG ReadAccess;
00146 ULONG WriteAccess;
00147 ULONG SharedRead;
00148 ULONG SharedWrite;
00149
00150
00151
00152
00153
00154 ReadAccess = (DesiredAccess & GENERIC_READ) != 0;
00155 WriteAccess = (DesiredAccess & GENERIC_WRITE) != 0;
00156
00157 SharedRead = (DesiredShareAccess & FILE_SHARE_READ) != 0;
00158 SharedWrite = (DesiredShareAccess & FILE_SHARE_WRITE) != 0;
00159
00160
if (ShareAccess->OpenCount == 0) {
00161
ASSERT (
FALSE);
00162
return STATUS_UNSUCCESSFUL;
00163 }
00164
00165 ShareAccess->OpenCount--;
00166
00167 ShareAccess->Readers -= ReadAccess;
00168 ShareAccess->Writers -= WriteAccess;
00169
00170 ShareAccess->SharedRead -= SharedRead;
00171 ShareAccess->SharedWrite -= SharedWrite;
00172
00173
return STATUS_SUCCESS;
00174 }