Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NamedPipeServerStream.Unix: GetImpersonationUserName tweaks. #88125

Merged
merged 2 commits into from
Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

4 changes: 2 additions & 2 deletions src/libraries/System.IO.Pipes/src/System.IO.Pipes.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,14 @@
Link="Common\Interop\Unix\Interop.FLock.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.GetHostName.cs"
Link="Common\Interop\Unix\Interop.GetHostName.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.GetPeerUserName.cs"
Link="Common\Interop\Unix\Interop.GetPeerUserName.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.Open.cs"
Link="Common\Interop\Unix\Interop.Open.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.OpenFlags.cs"
Link="Common\Interop\Unix\Interop.OpenFlags.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.Pipe.cs"
Link="Common\Interop\Unix\Interop.Pipe.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.GetPwUid.cs"
Link="Common\Interop\Unix\System.Native\Interop.GetPwUid.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.Read.Pipe.cs"
Link="Common\Interop\Unix\Interop.Read.Pipe.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.Unlink.cs"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,13 @@ public string GetImpersonationUserName()
throw new InvalidOperationException(SR.InvalidOperation_PipeHandleNotSet);
}

string name = Interop.Sys.GetPeerUserName(handle);
if (name != null)
uint peerID;
if (Interop.Sys.GetPeerID(handle, out peerID) == -1)
{
return name;
throw CreateExceptionForLastError(_instance?.PipeName);
}

throw CreateExceptionForLastError(_instance?.PipeName);
return Interop.Sys.GetUserNameFromPasswd(peerID);
}

public override int InBufferSize
Expand Down
1 change: 0 additions & 1 deletion src/native/libs/System.Native/entrypoints.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ static const Entry s_sysNative[] =
DllImportEntry(SystemNative_TryChangeSocketEventRegistration)
DllImportEntry(SystemNative_WaitForSocketEvents)
DllImportEntry(SystemNative_PlatformSupportsDualModeIPv4PacketInfo)
DllImportEntry(SystemNative_GetPeerUserName)
DllImportEntry(SystemNative_GetDomainSocketSizes)
DllImportEntry(SystemNative_GetMaximumAddressSize)
DllImportEntry(SystemNative_SendFile)
Expand Down
45 changes: 0 additions & 45 deletions src/native/libs/System.Native/pal_networking.c
Original file line number Diff line number Diff line change
Expand Up @@ -3036,51 +3036,6 @@ int32_t SystemNative_PlatformSupportsDualModeIPv4PacketInfo(void)
#endif
}

static char* GetNameFromUid(uid_t uid)
{
size_t bufferLength = 512;
while (1)
{
char *buffer = (char*)malloc(bufferLength);
if (buffer == NULL)
return NULL;

struct passwd pw;
struct passwd* result;
if (getpwuid_r(uid, &pw, buffer, bufferLength, &result) == 0)
{
if (result == NULL)
{
errno = ENOENT;
free(buffer);
return NULL;
}
else
{
char* name = strdup(pw.pw_name);
free(buffer);
return name;
}
}

free(buffer);
size_t tmpBufferLength;
if (errno != ERANGE || !multiply_s(bufferLength, (size_t)2, &tmpBufferLength))
{
return NULL;
}
bufferLength = tmpBufferLength;
}
}

char* SystemNative_GetPeerUserName(intptr_t socket)
{
uid_t euid;
return SystemNative_GetPeerID(socket, &euid) == 0 ?
GetNameFromUid(euid) :
NULL;
}

void SystemNative_GetDomainSocketSizes(int32_t* pathOffset, int32_t* pathSize, int32_t* addressSize)
{
assert(pathOffset != NULL);
Expand Down
2 changes: 0 additions & 2 deletions src/native/libs/System.Native/pal_networking.h
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,6 @@ PALEXPORT int32_t SystemNative_WaitForSocketEvents(intptr_t port, SocketEvent* b

PALEXPORT int32_t SystemNative_PlatformSupportsDualModeIPv4PacketInfo(void);

PALEXPORT char* SystemNative_GetPeerUserName(intptr_t socket);

PALEXPORT void SystemNative_GetDomainSocketSizes(int32_t* pathOffset, int32_t* pathSize, int32_t* addressSize);

PALEXPORT int32_t SystemNative_GetMaximumAddressSize(void);
Expand Down
6 changes: 0 additions & 6 deletions src/native/libs/System.Native/pal_networking_wasi.c
Original file line number Diff line number Diff line change
Expand Up @@ -411,12 +411,6 @@ int32_t SystemNative_PlatformSupportsDualModeIPv4PacketInfo(void)
return 0;
}


char* SystemNative_GetPeerUserName(intptr_t socket)
{
return NULL;
}

void SystemNative_GetDomainSocketSizes(int32_t* pathOffset, int32_t* pathSize, int32_t* addressSize)
{
*pathOffset = -1;
Expand Down
Loading