@@ -62,7 +62,6 @@ DWORD SharedMemoryException::GetErrorCode() const
62
62
// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
63
63
// SharedMemoryHelpers
64
64
65
- const mode_t SharedMemoryHelpers::PermissionsMask_CurrentUser_ReadWrite = S_IRUSR | S_IWUSR;
66
65
const mode_t SharedMemoryHelpers::PermissionsMask_CurrentUser_ReadWriteExecute = S_IRUSR | S_IWUSR | S_IXUSR;
67
66
const mode_t SharedMemoryHelpers::PermissionsMask_AllUsers_ReadWrite =
68
67
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
@@ -97,22 +96,13 @@ SIZE_T SharedMemoryHelpers::AlignUp(SIZE_T value, SIZE_T alignment)
97
96
bool SharedMemoryHelpers::EnsureDirectoryExists (
98
97
const char *path,
99
98
bool isGlobalLockAcquired,
100
- bool hasCurrentUserAccessOnly,
101
- bool setStickyFlag,
102
99
bool createIfNotExist,
103
100
bool isSystemDirectory)
104
101
{
105
102
_ASSERTE (path != nullptr );
106
103
_ASSERTE (!(isSystemDirectory && createIfNotExist)); // should not create or change permissions on system directories
107
104
_ASSERTE (SharedMemoryManager::IsCreationDeletionProcessLockAcquired ());
108
105
_ASSERTE (!isGlobalLockAcquired || SharedMemoryManager::IsCreationDeletionFileLockAcquired ());
109
- _ASSERTE (!(setStickyFlag && hasCurrentUserAccessOnly)); // Sticky bit doesn't make sense with current user access only
110
-
111
- mode_t mode = hasCurrentUserAccessOnly ? PermissionsMask_CurrentUser_ReadWriteExecute : PermissionsMask_AllUsers_ReadWriteExecute;
112
- if (setStickyFlag)
113
- {
114
- mode |= S_ISVTX;
115
- }
116
106
117
107
// Check if the path already exists
118
108
struct stat statInfo;
@@ -133,11 +123,11 @@ bool SharedMemoryHelpers::EnsureDirectoryExists(
133
123
134
124
if (isGlobalLockAcquired)
135
125
{
136
- if (mkdir (path, mode ) != 0 )
126
+ if (mkdir (path, PermissionsMask_AllUsers_ReadWriteExecute ) != 0 )
137
127
{
138
128
throw SharedMemoryException (static_cast <DWORD>(SharedMemoryError::IO));
139
129
}
140
- if (chmod (path, mode ) != 0 )
130
+ if (chmod (path, PermissionsMask_AllUsers_ReadWriteExecute ) != 0 )
141
131
{
142
132
rmdir (path);
143
133
throw SharedMemoryException (static_cast <DWORD>(SharedMemoryError::IO));
@@ -152,7 +142,7 @@ bool SharedMemoryHelpers::EnsureDirectoryExists(
152
142
{
153
143
throw SharedMemoryException (static_cast <DWORD>(SharedMemoryError::IO));
154
144
}
155
- if (chmod (tempPath, mode ) != 0 )
145
+ if (chmod (tempPath, PermissionsMask_AllUsers_ReadWriteExecute ) != 0 )
156
146
{
157
147
rmdir (tempPath);
158
148
throw SharedMemoryException (static_cast <DWORD>(SharedMemoryError::IO));
@@ -192,11 +182,11 @@ bool SharedMemoryHelpers::EnsureDirectoryExists(
192
182
// For non-system directories (such as gSharedFilesPath/SHARED_MEMORY_RUNTIME_TEMP_DIRECTORY_NAME),
193
183
// require sufficient permissions for all users and try to update them if requested to create the directory, so that
194
184
// shared memory files may be shared by all processes on the system.
195
- if ((statInfo.st_mode & mode ) == mode )
185
+ if ((statInfo.st_mode & PermissionsMask_AllUsers_ReadWriteExecute ) == PermissionsMask_AllUsers_ReadWriteExecute )
196
186
{
197
187
return true ;
198
188
}
199
- if (!createIfNotExist || chmod (path, mode ) != 0 )
189
+ if (!createIfNotExist || chmod (path, PermissionsMask_AllUsers_ReadWriteExecute ) != 0 )
200
190
{
201
191
// We were not asked to create the path or we weren't able to set the new permissions.
202
192
// As a last resort, check that at least the current user has full access.
@@ -253,7 +243,7 @@ int SharedMemoryHelpers::OpenDirectory(LPCSTR path)
253
243
return fileDescriptor;
254
244
}
255
245
256
- int SharedMemoryHelpers::CreateOrOpenFile (LPCSTR path, bool createIfNotExist, bool isSessionScope, bool *createdRef)
246
+ int SharedMemoryHelpers::CreateOrOpenFile (LPCSTR path, bool createIfNotExist, bool *createdRef)
257
247
{
258
248
_ASSERTE (path != nullptr );
259
249
_ASSERTE (path[0 ] != ' \0 ' );
@@ -283,13 +273,12 @@ int SharedMemoryHelpers::CreateOrOpenFile(LPCSTR path, bool createIfNotExist, bo
283
273
284
274
// File does not exist, create the file
285
275
openFlags |= O_CREAT | O_EXCL;
286
- mode_t mode = isSessionScope ? PermissionsMask_CurrentUser_ReadWrite : PermissionsMask_AllUsers_ReadWrite;
287
- fileDescriptor = Open (path, openFlags, mode);
276
+ fileDescriptor = Open (path, openFlags, PermissionsMask_AllUsers_ReadWrite);
288
277
_ASSERTE (fileDescriptor != -1 );
289
278
290
279
// The permissions mask passed to open() is filtered by the process' permissions umask, so open() may not set all of
291
280
// the requested permissions. Use chmod() to set the proper permissions.
292
- if (chmod (path, mode ) != 0 )
281
+ if (chmod (path, PermissionsMask_AllUsers_ReadWrite ) != 0 )
293
282
{
294
283
CloseFile (fileDescriptor);
295
284
unlink (path);
@@ -675,7 +664,7 @@ SharedMemoryProcessDataHeader *SharedMemoryProcessDataHeader::CreateOrOpen(
675
664
SharedMemoryHelpers::VerifyStringOperation (SharedMemoryManager::CopySharedMemoryBasePath (filePath));
676
665
SharedMemoryHelpers::VerifyStringOperation (filePath.Append (' /' ));
677
666
SharedMemoryHelpers::VerifyStringOperation (id.AppendSessionDirectoryName (filePath));
678
- if (!SharedMemoryHelpers::EnsureDirectoryExists (filePath, true /* isGlobalLockAcquired */ , id. IsSessionScope (), false /* setStickyFlag */ , createIfNotExist))
667
+ if (!SharedMemoryHelpers::EnsureDirectoryExists (filePath, true /* isGlobalLockAcquired */ , createIfNotExist))
679
668
{
680
669
_ASSERTE (!createIfNotExist);
681
670
return nullptr ;
@@ -688,7 +677,7 @@ SharedMemoryProcessDataHeader *SharedMemoryProcessDataHeader::CreateOrOpen(
688
677
SharedMemoryHelpers::VerifyStringOperation (filePath.Append (id.GetName (), id.GetNameCharCount ()));
689
678
690
679
bool createdFile;
691
- int fileDescriptor = SharedMemoryHelpers::CreateOrOpenFile (filePath, createIfNotExist, id. IsSessionScope (), &createdFile);
680
+ int fileDescriptor = SharedMemoryHelpers::CreateOrOpenFile (filePath, createIfNotExist, &createdFile);
692
681
if (fileDescriptor == -1 )
693
682
{
694
683
_ASSERTE (!createIfNotExist);
@@ -1163,23 +1152,17 @@ void SharedMemoryManager::AcquireCreationDeletionFileLock()
1163
1152
if (!SharedMemoryHelpers::EnsureDirectoryExists (
1164
1153
*gSharedFilesPath ,
1165
1154
false /* isGlobalLockAcquired */ ,
1166
- false /* hasCurrentUserAccessOnly */ ,
1167
- true /* setStickyFlag */ ,
1168
1155
false /* createIfNotExist */ ,
1169
1156
true /* isSystemDirectory */ ))
1170
1157
{
1171
1158
throw SharedMemoryException (static_cast <DWORD>(SharedMemoryError::IO));
1172
1159
}
1173
1160
SharedMemoryHelpers::EnsureDirectoryExists (
1174
1161
*s_runtimeTempDirectoryPath,
1175
- false /* isGlobalLockAcquired */ ,
1176
- false /* hasCurrentUserAccessOnly */ ,
1177
- false /* setStickyFlag */ );
1162
+ false /* isGlobalLockAcquired */ );
1178
1163
SharedMemoryHelpers::EnsureDirectoryExists (
1179
1164
*s_sharedMemoryDirectoryPath,
1180
- false /* isGlobalLockAcquired */ ,
1181
- false /* hasCurrentUserAccessOnly */ ,
1182
- true /* setStickyFlag */ );
1165
+ false /* isGlobalLockAcquired */ );
1183
1166
s_creationDeletionLockFileDescriptor = SharedMemoryHelpers::OpenDirectory (*s_sharedMemoryDirectoryPath);
1184
1167
if (s_creationDeletionLockFileDescriptor == -1 )
1185
1168
{
0 commit comments