1 /* -*- Mode: C; tab-width: 4 -*-
3 * Copyright (c) 2002-2004 Apple Computer, Inc. All rights reserved.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 Change History (most recent first):
19 $Log: SharedSecret.cpp,v $
20 Revision 1.6 2007/06/12 20:06:06 herscher
21 <rdar://problem/5263387> ControlPanel was inadvertently adding a trailing dot to all key names.
23 Revision 1.5 2006/08/14 23:25:28 cheshire
24 Re-licensed mDNSResponder daemon source code under Apache License, Version 2.0
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() - 1 ) )
126 if ( m_key
.ReverseFind( '.' ) != ( m_key
.GetLength() - 1 ) )
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
);