2  * Copyright (c) 2002-2004 Apple Computer, Inc. All rights reserved. 
   4  * @APPLE_LICENSE_HEADER_START@ 
   6  * This file contains Original Code and/or Modifications of Original Code 
   7  * as defined in and that are subject to the Apple Public Source License 
   8  * Version 2.0 (the 'License'). You may not use this file except in 
   9  * compliance with the License. Please obtain a copy of the License at 
  10  * http://www.opensource.apple.com/apsl/ and read it before using this 
  13  * The Original Code and all software distributed under the License are 
  14  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 
  15  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 
  16  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 
  17  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 
  18  * Please see the License for the specific language governing rights and 
  19  * limitations under the License. 
  21  * @APPLE_LICENSE_HEADER_END@ 
  23     Change History (most recent first): 
  25 $Log: SharedSecret.cpp,v $ 
  26 Revision 1.4  2005/10/18 06:13:41  herscher 
  27 <rdar://problem/4192119> Prepend "$" to key name to ensure that secure updates work if the domain name and key name are the same 
  29 Revision 1.3  2005/04/06 02:04:49  shersche 
  30 <rdar://problem/4066485> Registering with shared secret doesn't work 
  32 Revision 1.2  2005/03/03 19:55:22  shersche 
  33 <rdar://problem/4034481> ControlPanel source code isn't saving CVS log info 
  39 // SharedSecret.cpp : implementation file 
  43 #include "SharedSecret.h" 
  45 #include <DebugServices.h> 
  48 //--------------------------------------------------------------------------------------------------------------------------- 
  49 //      Private declarations 
  50 //--------------------------------------------------------------------------------------------------------------------------- 
  55                         PLSA_UNICODE_STRING     pLsaString
, 
  59 // SharedSecret dialog 
  61 IMPLEMENT_DYNAMIC(CSharedSecret
, CDialog
) 
  64 //--------------------------------------------------------------------------------------------------------------------------- 
  65 //      CSharedSecret::CSharedSecret 
  66 //--------------------------------------------------------------------------------------------------------------------------- 
  68 CSharedSecret::CSharedSecret(CWnd
* pParent 
/*=NULL*/) 
  69         : CDialog(CSharedSecret::IDD
, pParent
) 
  76 //--------------------------------------------------------------------------------------------------------------------------- 
  77 //      CSharedSecret::~CSharedSecret 
  78 //--------------------------------------------------------------------------------------------------------------------------- 
  80 CSharedSecret::~CSharedSecret() 
  85 //--------------------------------------------------------------------------------------------------------------------------- 
  86 //      CSharedSecret::DoDataExchange 
  87 //--------------------------------------------------------------------------------------------------------------------------- 
  89 void CSharedSecret::DoDataExchange(CDataExchange
* pDX
) 
  91         CDialog::DoDataExchange(pDX
); 
  92         DDX_Text(pDX
, IDC_KEY
, m_key 
); 
  93         DDX_Text(pDX
, IDC_SECRET
, m_secret 
); 
  97 BEGIN_MESSAGE_MAP(CSharedSecret
, CDialog
) 
 102 //--------------------------------------------------------------------------------------------------------------------------- 
 103 //      CSharedSecret::Commit 
 104 //--------------------------------------------------------------------------------------------------------------------------- 
 107 CSharedSecret::Commit( CString zone 
) 
 109         LSA_OBJECT_ATTRIBUTES   attrs
; 
 110         LSA_HANDLE                              handle 
= NULL
; 
 112         LSA_UNICODE_STRING              lucZoneName
; 
 113         LSA_UNICODE_STRING              lucKeyName
; 
 114         LSA_UNICODE_STRING              lucSecretName
; 
 118         // If there isn't a trailing dot, add one because the mDNSResponder 
 119         // presents names with the trailing dot. 
 121         if ( zone
.ReverseFind( '.' ) != zone
.GetLength() ) 
 126         if ( m_key
.ReverseFind( '.' ) != m_key
.GetLength() ) 
 131         // <rdar://problem/4192119> 
 133         // Prepend "$" to the key name, so that there will 
 134         // be no conflict between the zone name and the key 
 137         m_key
.Insert( 0, L
"$" ); 
 139         // attrs are reserved, so initialize to zeroes. 
 141         ZeroMemory( &attrs
, sizeof( attrs 
) ); 
 143         // Get a handle to the Policy object on the local system 
 145         res 
= LsaOpenPolicy( NULL
, &attrs
, POLICY_ALL_ACCESS
, &handle 
); 
 146         err 
= translate_errno( res 
== 0, LsaNtStatusToWinError( res 
), kUnknownErr 
); 
 147         require_noerr( err
, exit 
); 
 149         // Intializing PLSA_UNICODE_STRING structures 
 151         ok 
= InitLsaString( &lucZoneName
, zone 
); 
 152         err 
= translate_errno( ok
, errno_compat(), kUnknownErr 
); 
 153         require_noerr( err
, exit 
); 
 155         ok 
= InitLsaString( &lucKeyName
, m_key 
); 
 156         err 
= translate_errno( ok
, errno_compat(), kUnknownErr 
); 
 157         require_noerr( err
, exit 
); 
 159         ok 
= InitLsaString( &lucSecretName
, m_secret 
); 
 160         err 
= translate_errno( ok
, errno_compat(), kUnknownErr 
); 
 161         require_noerr( err
, exit 
); 
 163         // Store the private data. 
 165         res 
= LsaStorePrivateData( handle
, &lucZoneName
, &lucKeyName 
); 
 166         err 
= translate_errno( res 
== 0, LsaNtStatusToWinError( res 
), kUnknownErr 
); 
 167         require_noerr( err
, exit 
); 
 169         res 
= LsaStorePrivateData( handle
, &lucKeyName
, &lucSecretName 
); 
 170         err 
= translate_errno( res 
== 0, LsaNtStatusToWinError( res 
), kUnknownErr 
); 
 171         require_noerr( err
, exit 
); 
 185 //--------------------------------------------------------------------------------------------------------------------------- 
 187 //--------------------------------------------------------------------------------------------------------------------------- 
 192                 PLSA_UNICODE_STRING     pLsaString
, 
 199         if ( pLsaString 
== NULL 
) 
 204         if ( pwszString 
!= NULL 
)  
 206                 dwLen 
= wcslen(pwszString
); 
 208                 // String is too large 
 217         pLsaString
->Buffer                      
= (WCHAR 
*) pwszString
; 
 218         pLsaString
->Length                      
= (USHORT
) dwLen 
* sizeof(WCHAR
); 
 219         pLsaString
->MaximumLength       
= (USHORT
)(dwLen
+1) * sizeof(WCHAR
);