diff --git a/src/libpsl-native/src/CMakeLists.txt b/src/libpsl-native/src/CMakeLists.txt index b830e5d..889ba7b 100644 --- a/src/libpsl-native/src/CMakeLists.txt +++ b/src/libpsl-native/src/CMakeLists.txt @@ -8,10 +8,8 @@ add_library(psl-native SHARED getfileowner.cpp getcurrentthreadid.cpp getcurrentprocessorid.cpp - getusername.cpp getcomputername.cpp getlinkcount.cpp - getfullyqualifiedname.cpp geterrorcategory.cpp getinodedata.cpp isfile.cpp diff --git a/src/libpsl-native/src/getfullyqualifiedname.cpp b/src/libpsl-native/src/getfullyqualifiedname.cpp deleted file mode 100644 index 51df25a..0000000 --- a/src/libpsl-native/src/getfullyqualifiedname.cpp +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -//! @brief Implements GetFullyQualifiedName on Linux - -#include "getcomputername.h" -#include "getfullyqualifiedname.h" - -#include -#include -#include -#include - -//! @brief GetFullyQualifiedName retrieves the fully qualified dns name of the host -//! -//! @retval username as UTF-8 string, or null if unsuccessful -char *GetFullyQualifiedName() -{ - errno = 0; - - char *computerName = GetComputerName(); - if (computerName == NULL) - { - return NULL; - } - - struct addrinfo hints, *info; - - memset(&hints, 0, sizeof hints); - hints.ai_family = AF_UNSPEC; /*either IPV4 or IPV6*/ - hints.ai_socktype = SOCK_STREAM; - hints.ai_flags = AI_CANONNAME; - - /* There are several ways to get the domain name: - * uname(2), gethostbyname(3), resolver(3), getdomainname(2), - * and getaddrinfo(3). Some of these are not portable, some aren't - * POSIX compliant, and some are being deprecated. getaddrinfo seems - * to be the best choice. - */ - char *fullName = NULL; - if (getaddrinfo(computerName, "http", &hints, &info) != 0) - { - goto exit; - } - - // return the first canonical name in the list - fullName = strndup(info->ai_canonname, strnlen(info->ai_canonname, NI_MAXHOST)); - - // only free info if getaddrinfo was successful - freeaddrinfo(info); -exit: - free(computerName); - return fullName; -} diff --git a/src/libpsl-native/src/getfullyqualifiedname.h b/src/libpsl-native/src/getfullyqualifiedname.h deleted file mode 100644 index a9fb263..0000000 --- a/src/libpsl-native/src/getfullyqualifiedname.h +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#pragma once - -#include "pal.h" - -PAL_BEGIN_EXTERNC - -char *GetFullyQualifiedName(); - -PAL_END_EXTERNC diff --git a/src/libpsl-native/src/getusername.cpp b/src/libpsl-native/src/getusername.cpp deleted file mode 100644 index ed694f1..0000000 --- a/src/libpsl-native/src/getusername.cpp +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -//! @brief Implements GetUserName for Linux - -#include "getpwuid.h" -#include "getusername.h" - -#include - -//! @brief GetUserName retrieves the name of the user associated with -//! the current thread. -//! -//! @retval username as UTF-8 string, or null if unsuccessful -char* GetUserName() -{ - // geteuid() gets the effective user ID of the calling process, and is always successful - return GetPwUid(geteuid()); -} diff --git a/src/libpsl-native/src/getusername.h b/src/libpsl-native/src/getusername.h deleted file mode 100644 index e9461c7..0000000 --- a/src/libpsl-native/src/getusername.h +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#pragma once - -#include "pal.h" - -PAL_BEGIN_EXTERNC - -char* GetUserName(); - -PAL_END_EXTERNC diff --git a/src/libpsl-native/test/CMakeLists.txt b/src/libpsl-native/test/CMakeLists.txt index 2f57741..eb496e0 100644 --- a/src/libpsl-native/test/CMakeLists.txt +++ b/src/libpsl-native/test/CMakeLists.txt @@ -5,10 +5,8 @@ add_executable(psl-native-test test-locale.cpp test-getuserfrompid.cpp test-getcurrentprocessid.cpp - test-getusername.cpp test-getcomputername.cpp test-getlinkcount.cpp - test-getfullyqualifiedname.cpp test-isdirectory.cpp test-isfile.cpp test-issymlink.cpp diff --git a/src/libpsl-native/test/test-getfullyqualifiedname.cpp b/src/libpsl-native/test/test-getfullyqualifiedname.cpp deleted file mode 100644 index 8378f3a..0000000 --- a/src/libpsl-native/test/test-getfullyqualifiedname.cpp +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -//! @brief Unit tests for GetFullyQualifiedName - -#include -#include "getcomputername.h" -#include "getfullyqualifiedname.h" -#include -#include -#include -#include - -TEST(GetFullyQualifiedNameTest, ValidateLinuxGetFullyQualifiedDomainName) -{ - char *hostname = GetComputerName(); - ASSERT_STRNE(NULL, hostname); - - // this might be fail - errno = 0; - char *actual = GetFullyQualifiedName(); - int fqdnErrno = errno; - - struct addrinfo hints, *info; - memset(&hints, 0, sizeof(hints)); - hints.ai_family = AF_UNSPEC; - hints.ai_socktype = SOCK_STREAM; - hints.ai_flags = AI_CANONNAME; - errno = 0; - if (getaddrinfo(hostname, "http", &hints, &info) != 0) - { - // test that getaddrinfo failed the same way - EXPECT_EQ(fqdnErrno, errno); - goto exit; - } - - // Compare canonical name to FQDN - EXPECT_STREQ(info->ai_canonname, actual); - freeaddrinfo(info); -exit: - free(hostname); -} diff --git a/src/libpsl-native/test/test-getusername.cpp b/src/libpsl-native/test/test-getusername.cpp deleted file mode 100644 index f3adf3b..0000000 --- a/src/libpsl-native/test/test-getusername.cpp +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -//! @brief Unit tests for GetUserName - -#include -#include -#include "getusername.h" - -TEST(GetUserName, Success) -{ - char* expected = getpwuid(geteuid())->pw_name; - EXPECT_STREQ(GetUserName(), expected); -}