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.3 2005/04/06 02:04:49 shersche
27 <rdar://problem/4066485> Registering with shared secret doesn't work
29 Revision 1.2 2005/03/03 19:55:22 shersche
30 <rdar://problem/4034481> ControlPanel source code isn't saving CVS log info
36 // SharedSecret.cpp : implementation file
40 #include "SharedSecret.h"
42 #include <DebugServices.h>
45 //---------------------------------------------------------------------------------------------------------------------------
46 // Private declarations
47 //---------------------------------------------------------------------------------------------------------------------------
52 PLSA_UNICODE_STRING pLsaString
,
56 // SharedSecret dialog
58 IMPLEMENT_DYNAMIC(CSharedSecret
, CDialog
)
61 //---------------------------------------------------------------------------------------------------------------------------
62 // CSharedSecret::CSharedSecret
63 //---------------------------------------------------------------------------------------------------------------------------
65 CSharedSecret::CSharedSecret(CWnd
* pParent
/*=NULL*/)
66 : CDialog(CSharedSecret::IDD
, pParent
)
73 //---------------------------------------------------------------------------------------------------------------------------
74 // CSharedSecret::~CSharedSecret
75 //---------------------------------------------------------------------------------------------------------------------------
77 CSharedSecret::~CSharedSecret()
82 //---------------------------------------------------------------------------------------------------------------------------
83 // CSharedSecret::DoDataExchange
84 //---------------------------------------------------------------------------------------------------------------------------
86 void CSharedSecret::DoDataExchange(CDataExchange
* pDX
)
88 CDialog::DoDataExchange(pDX
);
89 DDX_Text(pDX
, IDC_KEY
, m_key
);
90 DDX_Text(pDX
, IDC_SECRET
, m_secret
);
94 BEGIN_MESSAGE_MAP(CSharedSecret
, CDialog
)
99 //---------------------------------------------------------------------------------------------------------------------------
100 // CSharedSecret::Commit
101 //---------------------------------------------------------------------------------------------------------------------------
104 CSharedSecret::Commit( CString zone
)
106 LSA_OBJECT_ATTRIBUTES attrs
;
107 LSA_HANDLE handle
= NULL
;
109 LSA_UNICODE_STRING lucZoneName
;
110 LSA_UNICODE_STRING lucKeyName
;
111 LSA_UNICODE_STRING lucSecretName
;
115 // If there isn't a trailing dot, add one because the mDNSResponder
116 // presents names with the trailing dot.
118 if ( zone
.ReverseFind( '.' ) != zone
.GetLength() )
123 if ( m_key
.ReverseFind( '.' ) != m_key
.GetLength() )
128 // attrs are reserved, so initialize to zeroes.
130 ZeroMemory( &attrs
, sizeof( attrs
) );
132 // Get a handle to the Policy object on the local system
134 res
= LsaOpenPolicy( NULL
, &attrs
, POLICY_ALL_ACCESS
, &handle
);
135 err
= translate_errno( res
== 0, LsaNtStatusToWinError( res
), kUnknownErr
);
136 require_noerr( err
, exit
);
138 // Intializing PLSA_UNICODE_STRING structures
140 ok
= InitLsaString( &lucZoneName
, zone
);
141 err
= translate_errno( ok
, errno_compat(), kUnknownErr
);
142 require_noerr( err
, exit
);
144 ok
= InitLsaString( &lucKeyName
, m_key
);
145 err
= translate_errno( ok
, errno_compat(), kUnknownErr
);
146 require_noerr( err
, exit
);
148 ok
= InitLsaString( &lucSecretName
, m_secret
);
149 err
= translate_errno( ok
, errno_compat(), kUnknownErr
);
150 require_noerr( err
, exit
);
152 // Store the private data.
154 res
= LsaStorePrivateData( handle
, &lucZoneName
, &lucKeyName
);
155 err
= translate_errno( res
== 0, LsaNtStatusToWinError( res
), kUnknownErr
);
156 require_noerr( err
, exit
);
158 res
= LsaStorePrivateData( handle
, &lucKeyName
, &lucSecretName
);
159 err
= translate_errno( res
== 0, LsaNtStatusToWinError( res
), kUnknownErr
);
160 require_noerr( err
, exit
);
174 //---------------------------------------------------------------------------------------------------------------------------
176 //---------------------------------------------------------------------------------------------------------------------------
181 PLSA_UNICODE_STRING pLsaString
,
188 if ( pLsaString
== NULL
)
193 if ( pwszString
!= NULL
)
195 dwLen
= wcslen(pwszString
);
197 // String is too large
206 pLsaString
->Buffer
= (WCHAR
*) pwszString
;
207 pLsaString
->Length
= (USHORT
) dwLen
* sizeof(WCHAR
);
208 pLsaString
->MaximumLength
= (USHORT
)(dwLen
+1) * sizeof(WCHAR
);