Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

0 lines
14 KiB

  1. // =========================================================================== // UAMKeychain.c � 1999-2000 Microsoft Corp. All rights reserved. // =========================================================================== // Keychain support routines for the MS UAM. // // =========================================================================== #include "UAMDebug.h" #include "UAMUtils.h" #include "UAMMain.h" #include "UAMDialogs.h" #include "UAMNetwork.h" #include "UAMKeychain.h" Boolean gKeychainAvailable = false; Boolean gAllowedToSavePswd = false; extern Str32 gServerName; extern Str32 gUserName; extern Str32 gZoneName; extern OTAddress* gServerAddress; extern long gSupportedUAMs; // --------------------------------------------------------------------------- // � UAM_KCInitialize() // --------------------------------------------------------------------------- // See if the keychain is supported on this machine as well as perform some // initialization for our keychain support. void UAM_KCInitialize(UAMArgs* inUAMArgs) { UInt32 theVersion; SInt32 theResponse; OSErr theError; gKeychainAvailable = false; gAllowedToSavePswd = false; // //Do a check here to make sure that we're running on a //system version that we support. // theError = Gestalt(gestaltSystemVersion, &theResponse); if (theError != noErr) { // //If there's an error calling Gestalt(), we're in real trouble. // return; } if (LoWord(theResponse) < 0x0900) { // //We don't support any OS older than MacOS 9.0. This is //because the old Keychain (v1.01) on older systems is //not stable enough and crashes often. // return; } // //Let's see if the Apple KeyChain manager is available and //remember it. // gKeychainAvailable = KeychainManagerAvailable(); if (gKeychainAvailable) { // //Get the version of the keychain manager. OS9 uses //v2.0 and is the first shipping version. However, v1.0 //was available to pre-OS9 macs. // KCGetKeychainManagerVersion(&theVersion); // //The version is kept in the hi-word of the return. // if (HiWord(theVersion) >= 0x0200) { // //Just in case someone else turned it off, we make sure //interaction is enabled. This call is only supported in //Keychain 2.0 or later. // KCSetInteractionAllowed(true); } } // //For debug, print out the availability. // DbgPrint_((DBGBUFF, "Keychain Manager available = %d", gKeychainAvailable)); // //BIT_2 of the srvr flags tells us if the user is allowed //to save their passwords in the keychain. // gAllowedToSavePswd = ((inUAMArgs->Opt.open.srvrInfo->fFlags & BIT_2) == 0); } // --------------------------------------------------------------------------- // � UAM_KCAvailable() // --------------------------------------------------------------------------- // Returns TRUE if the keychain is available on this machine as well as if // the AFP server allows clients to save passwords on the workstation. Boolean UAM_KCAvailable(void) { return(((gKeychainAvailable) && (gAllowedToSavePswd)) ? true : false); } // --------------------------------------------------------------------------- // � UAM_KCDeleteItem() // --------------------------------------------------------------------------- // Deletes a keychain item that pertains to this username & server. OSStatus UAM_KCDeleteItem( StringPtr inUserName, Str255 inServerName ) { OSStatus theStatus; KCItemRef theItem = NULL; theStatus = UAM_KCFindAppleSharePassword( inUserName, NULL, inServerName, &theItem ); if (theStatus != noErr) { // //We couldn't find an existing keychain item matching //the criteria. Bail. // return(theStatus); } Assert_(theItem != NULL); if (theItem != NULL) { // //We found the item, remove it from the keychain. // theStatus = KCDeleteItem(theItem); // //The keychain manager allocated this memory, we need to //free it. For free builds, we don't do anything if this //fails since there's nothing we or the user can do about it.