From 05a77eb8ff6e85236422e99f2386d590d22475c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Moreau?= Date: Tue, 19 Jun 2012 10:19:53 -0400 Subject: [PATCH] libwinpr-sspicli: initial commit --- include/winpr/sspicli.h | 90 +++++++++++++++++++++++++++++++ winpr/CMakeLists.txt | 1 + winpr/sspicli/CMakeLists.txt | 28 ++++++++++ winpr/sspicli/sspicli.c | 101 +++++++++++++++++++++++++++++++++++ 4 files changed, 220 insertions(+) create mode 100644 include/winpr/sspicli.h create mode 100644 winpr/sspicli/CMakeLists.txt create mode 100644 winpr/sspicli/sspicli.c diff --git a/include/winpr/sspicli.h b/include/winpr/sspicli.h new file mode 100644 index 000000000..602da2931 --- /dev/null +++ b/include/winpr/sspicli.h @@ -0,0 +1,90 @@ +/** + * WinPR: Windows Portable Runtime + * Security Support Provider Interface + * + * Copyright 2012 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef WINPR_SSPICLI_H +#define WINPR_SSPICLI_H + +#include +#include +#include +#include +#include + +#ifndef _WIN32 + +typedef enum +{ + /* An unknown name type */ + NameUnknown = 0, + + /* The fully qualified distinguished name (for example, CN=Jeff Smith,OU=Users,DC=Engineering,DC=Microsoft,DC=Com) */ + NameFullyQualifiedDN = 1, + + /* + * A legacy account name (for example, Engineering\JSmith). + * The domain-only version includes trailing backslashes (\\) + */ + NameSamCompatible = 2, + + /* + * A "friendly" display name (for example, Jeff Smith). + * The display name is not necessarily the defining relative distinguished name (RDN) + */ + NameDisplay = 3, + + /* A GUID string that the IIDFromString function returns (for example, {4fa050f0-f561-11cf-bdd9-00aa003a77b6}) */ + NameUniqueId = 6, + + /* + * The complete canonical name (for example, engineering.microsoft.com/software/someone). + * The domain-only version includes a trailing forward slash (/) + */ + NameCanonical = 7, + + /* The user principal name (for example, someone@example.com) */ + NameUserPrincipal = 8, + + /* + * The same as NameCanonical except that the rightmost forward slash (/) + * is replaced with a new line character (\n), even in a domain-only case + * (for example, engineering.microsoft.com/software\nJSmith) + */ + NameCanonicalEx = 9, + + /* The generalized service principal name (for example, www/www.microsoft.com@microsoft.com) */ + NameServicePrincipal = 10, + + /* The DNS domain name followed by a backward-slash and the SAM user name */ + NameDnsDomain = 12 + +} EXTENDED_NAME_FORMAT, *PEXTENDED_NAME_FORMAT; + +WINPR_API BOOL GetUserNameExA(EXTENDED_NAME_FORMAT NameFormat, LPSTR lpNameBuffer, PULONG nSize); +WINPR_API BOOL GetUserNameExW(EXTENDED_NAME_FORMAT NameFormat, LPWSTR lpNameBuffer, PULONG nSize); + +#ifdef UNICODE +#define GetUserNameEx GetUserNameExW +#else +#define GetUserNameEx GetUserNameExA +#endif + +#endif + +#endif /* WINPR_SSPICLI_H */ + diff --git a/winpr/CMakeLists.txt b/winpr/CMakeLists.txt index d03ecc192..177734588 100644 --- a/winpr/CMakeLists.txt +++ b/winpr/CMakeLists.txt @@ -26,6 +26,7 @@ add_subdirectory(sysinfo) add_subdirectory(bcrypt) add_subdirectory(dsparse) add_subdirectory(rpc) +add_subdirectory(sspicli) add_subdirectory(sspi) add_subdirectory(registry) diff --git a/winpr/sspicli/CMakeLists.txt b/winpr/sspicli/CMakeLists.txt new file mode 100644 index 000000000..b747a9d2f --- /dev/null +++ b/winpr/sspicli/CMakeLists.txt @@ -0,0 +1,28 @@ +# WinPR: Windows Portable Runtime +# libwinpr-sspicli cmake build script +# +# Copyright 2011 O.S. Systems Software Ltda. +# Copyright 2011 Otavio Salvador +# Copyright 2011 Marc-Andre Moreau +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set(WINPR_SSPICLI_SRCS + sspicli.c) + +add_library(winpr-sspicli ${WINPR_SSPICLI_SRCS}) + +set_target_properties(winpr-sspicli PROPERTIES VERSION ${FREERDP_VERSION_FULL} SOVERSION ${FREERDP_VERSION} PREFIX "lib") + +install(TARGETS winpr-sspicli DESTINATION ${CMAKE_INSTALL_LIBDIR}) + diff --git a/winpr/sspicli/sspicli.c b/winpr/sspicli/sspicli.c new file mode 100644 index 000000000..ef18f7e0c --- /dev/null +++ b/winpr/sspicli/sspicli.c @@ -0,0 +1,101 @@ +/** + * WinPR: Windows Portable Runtime + * Security Support Provider Interface + * + * Copyright 2012 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +/** + * sspicli.dll: + * + * EnumerateSecurityPackagesA + * EnumerateSecurityPackagesW + * GetUserNameExW + * ImportSecurityContextA + * LogonUserExExW + * SspiCompareAuthIdentities + * SspiCopyAuthIdentity + * SspiDecryptAuthIdentity + * SspiEncodeAuthIdentityAsStrings + * SspiEncodeStringsAsAuthIdentity + * SspiEncryptAuthIdentity + * SspiExcludePackage + * SspiFreeAuthIdentity + * SspiGetTargetHostName + * SspiIsAuthIdentityEncrypted + * SspiLocalFree + * SspiMarshalAuthIdentity + * SspiPrepareForCredRead + * SspiPrepareForCredWrite + * SspiUnmarshalAuthIdentity + * SspiValidateAuthIdentity + * SspiZeroAuthIdentity + */ + +#ifndef _WIN32 + +#include +#include + +BOOL GetUserNameExA(EXTENDED_NAME_FORMAT NameFormat, LPSTR lpNameBuffer, PULONG nSize) +{ + int length; + char* login; + + switch (NameFormat) + { + case NameSamCompatible: + + login = getlogin(); + length = strlen(login); + + if (*nSize >= length) + { + CopyMemory(lpNameBuffer, login, length + 1); + return 1; + } + else + { + *nSize = length + 1; + } + + break; + + case NameFullyQualifiedDN: + case NameDisplay: + case NameUniqueId: + case NameCanonical: + case NameUserPrincipal: + case NameCanonicalEx: + case NameServicePrincipal: + case NameDnsDomain: + break; + + default: + break; + } + + return 0; +} + +BOOL GetUserNameExW(EXTENDED_NAME_FORMAT NameFormat, LPWSTR lpNameBuffer, PULONG nSize) +{ + return 0; +} + +#endif +