Example #1
0
            private static uint ChangeUserId(uint userId)
            {
                var oldId = UnixInterop.setfsuid(userId);

                if (oldId == userId)
                {
                    return(oldId);
                }

                // This will always fail and is required, because no
                // error status gets set by this function.
                var currentId = UnixInterop.setfsuid(uint.MaxValue);

                if (currentId != userId)
                {
                    if (currentId != oldId)
                    {
                        UnixInterop.setfsuid(oldId);
                    }

                    throw new InvalidOperationException();
                }

                // Set again, because WSL seems to be buggy and accepts
                // uint.MaxValue even though it's not a valid user id.
                UnixInterop.setfsuid(userId);

                return(oldId);
            }
Example #2
0
 /// <inheritdoc />
 public void Dispose()
 {
     if (_hasUserInfo)
     {
         var restoreUid = _defaultUserId;
         var restoreGid = _defaultGroupId;
         var prevGid    = UnixInterop.setfsgid(restoreGid);
         var prevUid    = UnixInterop.setfsuid(restoreUid);
         if (prevUid != _setUserId || prevGid != _setGroupId)
         {
             _logger?.LogWarning(
                 "Reverted to user id={oldUserId} (was set to: {prevUserId}) and group id={oldGroupId} (was set to: {prevGroupId})",
                 restoreUid,
                 prevUid,
                 restoreGid,
                 prevGid);
         }
     }
 }