⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 secext.pas

📁 详细Windows API大全有关知识以及相关问题
💻 PAS
字号:
{******************************************************************}
{                                                       	   }
{       Borland Delphi Runtime Library                  	   }
{       SSPI Context Management interface unit                     }
{ 								   }
{ Portions created by Microsoft are 				   }
{ Copyright (C) 1995-1999 Microsoft Corporation. 		   }
{ All Rights Reserved. 						   }
{ 								   }
{ The original file is: secext.h, released June 2000. 	           }
{ The original Pascal code is: SecExt.pas, released December 2000  }
{ The initial developer of the Pascal code is Marcel van Brakel    }
{ (brakelm@bart.nl).                      			   }
{ 								   }
{ Portions created by Marcel van Brakel are			   }
{ Copyright (C) 1999 Marcel van Brakel.				   }
{ 								   }
{ Obtained through:                               	           }
{ Joint Endeavour of Delphi Innovators (Project JEDI)              }
{								   }
{ You may retrieve the latest version of this file at the Project  }
{ JEDI home page, located at http://delphi-jedi.org                }
{								   }
{ The contents of this file are used with permission, subject to   }
{ the Mozilla Public License Version 1.1 (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.mozilla.org/MPL/MPL-1.1.html 	                   }
{                                                                  }
{ Software distributed under the License is distributed on an 	   }
{ "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or   }
{ implied. See the License for the specific language governing     }
{ rights and limitations under the License. 			   }
{ 								   }
{******************************************************************}

unit SecExt;

{$WEAKPACKAGEUNIT}

{$HPPEMIT ''}
{$HPPEMIT '#include "secext.h"'}
{$HPPEMIT ''}

{$I WINDEFINES.INC}

interface

uses
  SSPI, WinType;

//
// This is the combined authentication identity structure that may be
// used with the negotiate package, NTLM, Kerberos, or SCHANNEL
//

const
  SEC_WINNT_AUTH_IDENTITY_VERSION = $200;
  {$EXTERNALSYM SEC_WINNT_AUTH_IDENTITY_VERSION}

type
  PSEC_WINNT_AUTH_IDENTITY_EXW = ^_SEC_WINNT_AUTH_IDENTITY_EXW;
  {$EXTERNALSYM PSEC_WINNT_AUTH_IDENTITY_EXW}
  _SEC_WINNT_AUTH_IDENTITY_EXW = record
    Version: Cardinal;
    Length: Cardinal;
    User: PWord;
    UserLength: Cardinal;
    Domain: PWord;
    DomainLength: Cardinal;
    Password: PWord;
    PasswordLength: Cardinal;
    Flags: Cardinal;
    PackageList: PWord;
    PackageListLength: Cardinal;
  end;
  {$EXTERNALSYM _SEC_WINNT_AUTH_IDENTITY_EXW}
  SEC_WINNT_AUTH_IDENTITY_EXW = _SEC_WINNT_AUTH_IDENTITY_EXW;
  {$EXTERNALSYM SEC_WINNT_AUTH_IDENTITY_EXW}
  TSecWinNTAuthIdentityExW = SEC_WINNT_AUTH_IDENTITY_EXW;
  PSecWinNTAuthIdentityExW = PSEC_WINNT_AUTH_IDENTITY_EXW;

  PSEC_WINNT_AUTH_IDENTITY_EXA = ^SEC_WINNT_AUTH_IDENTITY_EXA;
  {$EXTERNALSYM PSEC_WINNT_AUTH_IDENTITY_EXA}
  _SEC_WINNT_AUTH_IDENTITY_EXA = record
    Version: Cardinal;
    Length: Cardinal;
    User: PByte;
    UserLength: Cardinal;
    Domain: PByte;
    DomainLength: Cardinal;
    Password: PByte;
    PasswordLength: Cardinal;
    Flags: Cardinal;
    PackageList: PByte;
    PackageListLength: Cardinal;
  end;
  {$EXTERNALSYM _SEC_WINNT_AUTH_IDENTITY_EXA}
  SEC_WINNT_AUTH_IDENTITY_EXA = _SEC_WINNT_AUTH_IDENTITY_EXA;
  {$EXTERNALSYM SEC_WINNT_AUTH_IDENTITY_EXA}
  TSecWinNTAuthIdentityExA = SEC_WINNT_AUTH_IDENTITY_EXA;
  PSecWinNTAuthIdentityExA = PSEC_WINNT_AUTH_IDENTITY_EXA;

{$IFDEF UNICODE}
  SEC_WINNT_AUTH_IDENTITY_EX = SEC_WINNT_AUTH_IDENTITY_EXW;
  {$EXTERNALSYM SEC_WINNT_AUTH_IDENTITY_EX}
  TSecWinNTAuthIdentityEx = TSecWinNTAuthIdentityExW;
  PSecWinNTAuthIdentityEx = PSecWinNTAuthIdentityExW;
{$ELSE}
  SEC_WINNT_AUTH_IDENTITY_EX = SEC_WINNT_AUTH_IDENTITY_EXA;
  {$EXTERNALSYM SEC_WINNT_AUTH_IDENTITY_EX}
  TSecWinNTAuthIdentityEx = TSecWinNTAuthIdentityExA;
  PSecWinNTAuthIdentityEx = PSecWinNTAuthIdentityExA;
{$ENDIF}

//
// Common types used by negotiable security packages
//

const
  SEC_WINNT_AUTH_IDENTITY_MARSHALLED = $4; // all data is in one buffer
  {$EXTERNALSYM SEC_WINNT_AUTH_IDENTITY_MARSHALLED}
  SEC_WINNT_AUTH_IDENTITY_ONLY       = $8; // these credentials are for identity only - no PAC needed
  {$EXTERNALSYM SEC_WINNT_AUTH_IDENTITY_ONLY}

//
// Routines for manipulating packages
//

type
  PSECURITY_PACKAGE_OPTIONS = ^SECURITY_PACKAGE_OPTIONS;
  {$EXTERNALSYM PSECURITY_PACKAGE_OPTIONS}
  _SECURITY_PACKAGE_OPTIONS = record
    Size: Cardinal;
    Type_: Cardinal;
    Flags: Cardinal;
    SignatureSize: Cardinal;
    Signature: Pointer;
  end;
  {$EXTERNALSYM _SECURITY_PACKAGE_OPTIONS}
  SECURITY_PACKAGE_OPTIONS = _SECURITY_PACKAGE_OPTIONS;
  {$EXTERNALSYM SECURITY_PACKAGE_OPTIONS}
  TSecurityPackageOptions = SECURITY_PACKAGE_OPTIONS;
  PSecurityPackageOptions = PSECURITY_PACKAGE_OPTIONS;

const
  SECPKG_OPTIONS_TYPE_UNKNOWN = 0;
  {$EXTERNALSYM SECPKG_OPTIONS_TYPE_UNKNOWN}
  SECPKG_OPTIONS_TYPE_LSA     = 1;
  {$EXTERNALSYM SECPKG_OPTIONS_TYPE_LSA}
  SECPKG_OPTIONS_TYPE_SSPI    = 2;
  {$EXTERNALSYM SECPKG_OPTIONS_TYPE_SSPI}

  SECPKG_OPTIONS_PERMANENT = $00000001;
  {$EXTERNALSYM SECPKG_OPTIONS_PERMANENT}

function AddSecurityPackageA(pszPackageName: PSecChar;
  Options: PSECURITY_PACKAGE_OPTIONS): SECURITY_STATUS; stdcall;
{$EXTERNALSYM AddSecurityPackageA}
function AddSecurityPackageW(pszPackageName: PSecWChar;
  Options: PSECURITY_PACKAGE_OPTIONS): SECURITY_STATUS; stdcall;
{$EXTERNALSYM AddSecurityPackageW}

{$IFDEF UNICODE}
function AddSecurityPackage(pszPackageName: PSecWChar;
  Options: PSECURITY_PACKAGE_OPTIONS): SECURITY_STATUS; stdcall;
{$EXTERNALSYM AddSecurityPackage}
{$ELSE}
function AddSecurityPackage(pszPackageName: PSecChar;
  Options: PSECURITY_PACKAGE_OPTIONS): SECURITY_STATUS; stdcall;
{$EXTERNALSYM AddSecurityPackage}
{$ENDIF}

function DeleteSecurityPackageA(pszPackageName: PSecChar): SECURITY_STATUS; stdcall;
{$EXTERNALSYM DeleteSecurityPackageA}
function DeleteSecurityPackageW(pszPackageName: PSecWChar): SECURITY_STATUS; stdcall;
{$EXTERNALSYM DeleteSecurityPackageW}

{$IFDEF UNICODE}
function DeleteSecurityPackage(pszPackageName: PSecWChar): SECURITY_STATUS; stdcall;
{$EXTERNALSYM DeleteSecurityPackage}
{$ELSE}
function DeleteSecurityPackage(pszPackageName: PSecChar): SECURITY_STATUS; stdcall;
{$EXTERNALSYM DeleteSecurityPackage}
{$ENDIF}

//
// Extended Name APIs for ADS
//

const
  // Examples for the following formats assume a fictitous company
  // which hooks into the global X.500 and DNS name spaces as follows.
  //
  // Enterprise root domain in DNS is
  //
  //      widget.com
  //
  // Enterprise root domain in X.500 (RFC 1779 format) is
  //
  //      O=Widget, C=US
  //
  // There exists the child domain
  //
  //      engineering.widget.com
  //
  // equivalent to
  //
  //      OU=Engineering, O=Widget, C=US
  //
  // There exists a container within the Engineering domain
  //
  //      OU=Software, OU=Engineering, O=Widget, C=US
  //
  // There exists the user
  //
  //      CN=John Doe, OU=Software, OU=Engineering, O=Widget, C=US
  //
  // And this user's downlevel (pre-ADS) user name is
  //
  //      Engineering\JohnDoe

  // unknown name type
  NameUnknown = 0;
  {$EXTERNALSYM NameUnknown}

  // CN=John Doe, OU=Software, OU=Engineering, O=Widget, C=US
  NameFullyQualifiedDN = 1;
  {$EXTERNALSYM NameFullyQualifiedDN}

  // Engineering\JohnDoe
  NameSamCompatible = 2;
  {$EXTERNALSYM NameSamCompatible}

  // Probably "John Doe" but could be something else.  I.e. The
  // display name is not necessarily the defining RDN.
  NameDisplay = 3;
  {$EXTERNALSYM NameDisplay}

  // String-ized GUID as returned by IIDFromString().
  // eg: {4fa050f0-f561-11cf-bdd9-00aa003a77b6}
  NameUniqueId = 6;
  {$EXTERNALSYM NameUniqueId}

  // engineering.widget.com/software/John Doe
  NameCanonical = 7;
  {$EXTERNALSYM NameCanonical}

  // johndoe@engineering.com
  NameUserPrincipal = 8;
  {$EXTERNALSYM NameUserPrincipal}

  // Same as NameCanonical except that rightmost '/' is
  // replaced with '\n' - even in domain-only case.
  // eg: engineering.widget.com/software\nJohn Doe
  NameCanonicalEx = 9;
  {$EXTERNALSYM NameCanonicalEx}

  // www/srv.engineering.com/engineering.com
  NameServicePrincipal = 10;
  {$EXTERNALSYM NameServicePrincipal}

type
  EXTENDED_NAME_FORMAT = DWORD;
  {$EXTERNALSYM EXTENDED_NAME_FORMAT}
  PEXTENDED_NAME_FORMAT = ^EXTENDED_NAME_FORMAT;
  {$EXTERNALSYM PEXTENDED_NAME_FORMAT}
  TExtendedNameFormat = EXTENDED_NAME_FORMAT;
  PExtendedNameFormat = PEXTENDED_NAME_FORMAT;

function GetUserNameExA(NameFormat: EXTENDED_NAME_FORMAT; lpNameBuffer: LPSTR;
  var nSize: ULONG): ByteBool; stdcall;
{$EXTERNALSYM GetUserNameExA}
function GetUserNameExW(NameFormat: EXTENDED_NAME_FORMAT; lpNameBuffer: LPWSTR;
  var nSize: ULONG): ByteBool; stdcall;
{$EXTERNALSYM GetUserNameExW}

{$IFDEF UNICODE}
function GetUserNameEx(NameFormat: EXTENDED_NAME_FORMAT; lpNameBuffer: LPWSTR;
  var nSize: ULONG): ByteBool; stdcall;
{$EXTERNALSYM GetUserNameEx}
{$ELSE}
function GetUserNameEx(NameFormat: EXTENDED_NAME_FORMAT; lpNameBuffer: LPSTR;
  var nSize: ULONG): ByteBool; stdcall;
{$EXTERNALSYM GetUserNameEx}
{$ENDIF}

function GetComputerObjectNameA(NameFormat: EXTENDED_NAME_FORMAT;
  lpNameBuffer: LPSTR; var nSize: ULONG): ByteBool; stdcall;
{$EXTERNALSYM GetComputerObjectNameA}
function GetComputerObjectNameW(NameFormat: EXTENDED_NAME_FORMAT;
  lpNameBuffer: LPWSTR; var nSize: ULONG): ByteBool; stdcall;
{$EXTERNALSYM GetComputerObjectNameW}

{$IFDEF UNICODE}
function GetComputerObjectName(NameFormat: EXTENDED_NAME_FORMAT;
  lpNameBuffer: LPWSTR; var nSize: ULONG): ByteBool; stdcall;
{$EXTERNALSYM GetComputerObjectName}
{$ELSE}
function GetComputerObjectName(NameFormat: EXTENDED_NAME_FORMAT;
  lpNameBuffer: LPSTR; var nSize: ULONG): ByteBool; stdcall;
{$EXTERNALSYM GetComputerObjectName}
{$ENDIF}

function TranslateNameA(lpAccountName: LPCSTR; AccountNameFormat,
  DesiredNameFormat: EXTENDED_NAME_FORMAT; lpTranslatedName: LPSTR;
  var nSize: ULONG): ByteBool; stdcall;
{$EXTERNALSYM TranslateNameA}
function TranslateNameW(lpAccountName: LPCWSTR; AccountNameFormat,
  DesiredNameFormat: EXTENDED_NAME_FORMAT; lpTranslatedName: LPWSTR;
  var nSize: ULONG): ByteBool; stdcall;
{$EXTERNALSYM TranslateNameW}

{$IFDEF UNICODE}
function TranslateName(lpAccountName: LPCWSTR; AccountNameFormat,
  DesiredNameFormat: EXTENDED_NAME_FORMAT; lpTranslatedName: LPWSTR;
  var nSize: ULONG): ByteBool; stdcall;
{$EXTERNALSYM TranslateName}
{$ELSE}
function TranslateName(lpAccountName: LPCSTR; AccountNameFormat,
  DesiredNameFormat: EXTENDED_NAME_FORMAT; lpTranslatedName: LPSTR;
  var nSize: ULONG): ByteBool; stdcall;
{$EXTERNALSYM TranslateName}
{$ENDIF}

implementation

const
  secur32 = 'secur32.dll';

function AddSecurityPackageA; external secur32 name 'AddSecurityPackageA';
function AddSecurityPackageW; external secur32 name 'AddSecurityPackageW';
{$IFDEF UNICODE}
function AddSecurityPackage; external secur32 name 'AddSecurityPackageW';
{$ELSE}
function AddSecurityPackage; external secur32 name 'AddSecurityPackageA';
{$ENDIF}
function DeleteSecurityPackageA; external secur32 name 'DeleteSecurityPackageA';
function DeleteSecurityPackageW; external secur32 name 'DeleteSecurityPackageW';
{$IFDEF UNICODE}
function DeleteSecurityPackage; external secur32 name 'DeleteSecurityPackageW';
{$ELSE}
function DeleteSecurityPackage; external secur32 name 'DeleteSecurityPackageA';
{$ENDIF}
function GetUserNameExA; external secur32 name 'GetUserNameExA';
function GetUserNameExW; external secur32 name 'GetUserNameExW';
{$IFDEF UNICODE}
function GetUserNameEx; external secur32 name 'GetUserNameExW';
{$ELSE}
function GetUserNameEx; external secur32 name 'GetUserNameExA';
{$ENDIF}
function GetComputerObjectNameA; external secur32 name 'GetComputerObjectNameA';
function GetComputerObjectNameW; external secur32 name 'GetComputerObjectNameW';
{$IFDEF UNICODE}
function GetComputerObjectName; external secur32 name 'GetComputerObjectNameW';
{$ELSE}
function GetComputerObjectName; external secur32 name 'GetComputerObjectNameA';
{$ENDIF}
function TranslateNameA; external secur32 name 'TranslateNameA';
function TranslateNameW; external secur32 name 'TranslateNameW';
{$IFDEF UNICODE}
function TranslateName; external secur32 name 'TranslateNameW';
{$ELSE}
function TranslateName; external secur32 name 'TranslateNameA';
{$ENDIF}

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -