]> git.saurik.com Git - apple/mdnsresponder.git/blob - mDNSWindows/ControlPanel/FirstPage.cpp
mDNSResponder-214.3.2.tar.gz
[apple/mdnsresponder.git] / mDNSWindows / ControlPanel / FirstPage.cpp
1 /* -*- Mode: C; tab-width: 4 -*-
2 *
3 * Copyright (c) 2002-2004 Apple Computer, Inc. All rights reserved.
4 *
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
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
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.
16
17 Change History (most recent first):
18
19 $Log: FirstPage.cpp,v $
20 Revision 1.7 2009/06/22 23:25:10 herscher
21 <rdar://problem/5265747> ControlPanel doesn't display key and password in dialog box. Refactor Lsa calls into Secret.h and Secret.c, which is used by both the ControlPanel and mDNSResponder system service.
22
23 Revision 1.6 2006/08/14 23:25:28 cheshire
24 Re-licensed mDNSResponder daemon source code under Apache License, Version 2.0
25
26 Revision 1.5 2005/10/05 20:46:50 herscher
27 <rdar://problem/4192011> Move Wide-Area preferences to another part of the registry so they don't removed during an update-install.
28
29 Revision 1.4 2005/04/05 03:52:14 shersche
30 <rdar://problem/4066485> Registering with shared secret key doesn't work. Additionally, mDNSResponder wasn't dynamically re-reading it's DynDNS setup after setting a shared secret key.
31
32 Revision 1.3 2005/03/07 18:27:42 shersche
33 <rdar://problem/4037940> Fix problem when ControlPanel commits changes to the browse domain list
34
35 Revision 1.2 2005/03/03 19:55:22 shersche
36 <rdar://problem/4034481> ControlPanel source code isn't saving CVS log info
37
38
39 */
40
41 #include "FirstPage.h"
42 #include "resource.h"
43
44 #include "ConfigPropertySheet.h"
45 #include "SharedSecret.h"
46
47 #define MAX_KEY_LENGTH 255
48
49
50 IMPLEMENT_DYNCREATE(CFirstPage, CPropertyPage)
51
52 //---------------------------------------------------------------------------------------------------------------------------
53 // CFirstPage::CFirstPage
54 //---------------------------------------------------------------------------------------------------------------------------
55
56 CFirstPage::CFirstPage()
57 :
58 CPropertyPage(CFirstPage::IDD),
59 m_ignoreHostnameChange( false ),
60 m_statusKey( NULL ),
61 m_setupKey( NULL )
62 {
63 //{{AFX_DATA_INIT(CFirstPage)
64 //}}AFX_DATA_INIT
65
66 OSStatus err;
67
68 err = RegCreateKey( HKEY_LOCAL_MACHINE, kServiceParametersNode L"\\DynDNS\\State\\Hostnames", &m_statusKey );
69 check_noerr( err );
70
71 err = RegCreateKey( HKEY_LOCAL_MACHINE, kServiceParametersNode L"\\DynDNS\\Setup\\Hostnames", &m_setupKey );
72 check_noerr( err );
73 }
74
75 CFirstPage::~CFirstPage()
76 {
77 if ( m_statusKey )
78 {
79 RegCloseKey( m_statusKey );
80 m_statusKey = NULL;
81 }
82
83 if ( m_setupKey )
84 {
85 RegCloseKey( m_setupKey );
86 m_setupKey = NULL;
87 }
88 }
89
90
91 //---------------------------------------------------------------------------------------------------------------------------
92 // CFirstPage::DoDataExchange
93 //---------------------------------------------------------------------------------------------------------------------------
94
95 void CFirstPage::DoDataExchange(CDataExchange* pDX)
96 {
97 CPropertyPage::DoDataExchange(pDX);
98 //{{AFX_DATA_MAP(CFirstPage)
99 //}}AFX_DATA_MAP
100 DDX_Control(pDX, IDC_EDIT1, m_hostnameControl);
101 DDX_Control(pDX, IDC_FAILURE, m_failureIcon);
102 DDX_Control(pDX, IDC_SUCCESS, m_successIcon);
103 }
104
105 BEGIN_MESSAGE_MAP(CFirstPage, CPropertyPage)
106 //{{AFX_MSG_MAP(CFirstPage)
107 //}}AFX_MSG_MAP
108 ON_BN_CLICKED(IDC_BUTTON1, OnBnClickedSharedSecret)
109 ON_EN_CHANGE(IDC_EDIT1, OnEnChangeHostname)
110 END_MESSAGE_MAP()
111
112
113 //---------------------------------------------------------------------------------------------------------------------------
114 // CFirstPage::OnEnChangedHostname
115 //---------------------------------------------------------------------------------------------------------------------------
116
117 void CFirstPage::OnEnChangeHostname()
118 {
119 if ( !m_ignoreHostnameChange )
120 {
121 SetModified( TRUE );
122 }
123 }
124
125
126 //---------------------------------------------------------------------------------------------------------------------------
127 // CFirstPage::OnBnClickedSharedSecret
128 //---------------------------------------------------------------------------------------------------------------------------
129
130 void CFirstPage::OnBnClickedSharedSecret()
131 {
132 CString name;
133
134 m_hostnameControl.GetWindowText( name );
135
136 CSharedSecret dlg;
137
138 dlg.Load( name );
139
140 if ( dlg.DoModal() == IDOK )
141 {
142 DWORD wakeup = 0;
143 DWORD dwSize = sizeof( DWORD );
144 OSStatus err;
145
146 dlg.Commit( name );
147
148 // We have now updated the secret, however the system service
149 // doesn't know about it yet. So we're going to update the
150 // registry with a dummy value which will cause the system
151 // service to re-initialize it's DynDNS setup
152 //
153
154 RegQueryValueEx( m_setupKey, L"Wakeup", NULL, NULL, (LPBYTE) &wakeup, &dwSize );
155
156 wakeup++;
157
158 err = RegSetValueEx( m_setupKey, L"Wakeup", 0, REG_DWORD, (LPBYTE) &wakeup, sizeof( DWORD ) );
159 require_noerr( err, exit );
160 }
161
162 exit:
163
164 return;
165 }
166
167
168 //---------------------------------------------------------------------------------------------------------------------------
169 // CFirstPage::SetModified
170 //---------------------------------------------------------------------------------------------------------------------------
171
172 void CFirstPage::SetModified( BOOL bChanged )
173 {
174 m_modified = bChanged ? true : false;
175
176 CPropertyPage::SetModified( bChanged );
177 }
178
179
180 //---------------------------------------------------------------------------------------------------------------------------
181 // CFirstPage::OnSetActive
182 //---------------------------------------------------------------------------------------------------------------------------
183
184 BOOL
185 CFirstPage::OnSetActive()
186 {
187 TCHAR name[kDNSServiceMaxDomainName + 1];
188 DWORD nameLen = ( kDNSServiceMaxDomainName + 1 ) * sizeof( TCHAR );
189 DWORD err;
190
191 BOOL b = CPropertyPage::OnSetActive();
192
193 m_modified = FALSE;
194
195 if ( m_setupKey )
196 {
197 err = RegQueryValueEx( m_setupKey, L"", NULL, NULL, (LPBYTE) name, &nameLen );
198
199 if ( !err )
200 {
201 m_ignoreHostnameChange = true;
202 m_hostnameControl.SetWindowText( name );
203 m_ignoreHostnameChange = false;
204 }
205 }
206
207 // Check the status of this hostname
208
209 err = CheckStatus();
210 check_noerr( err );
211
212 return b;
213 }
214
215
216 //---------------------------------------------------------------------------------------------------------------------------
217 // CFirstPage::OnOK
218 //---------------------------------------------------------------------------------------------------------------------------
219
220 void
221 CFirstPage::OnOK()
222 {
223 if ( m_modified )
224 {
225 Commit();
226 }
227 }
228
229
230 //---------------------------------------------------------------------------------------------------------------------------
231 // CFirstPage::Commit
232 //---------------------------------------------------------------------------------------------------------------------------
233
234 void
235 CFirstPage::Commit()
236 {
237 DWORD enabled = 1;
238 CString name;
239 DWORD err;
240
241 m_hostnameControl.GetWindowText( name );
242
243 // Convert to lower case
244
245 name.MakeLower();
246
247 // Remove trailing dot
248
249 name.TrimRight( '.' );
250
251 err = RegSetValueEx( m_setupKey, L"", 0, REG_SZ, (LPBYTE) (LPCTSTR) name, ( name.GetLength() + 1 ) * sizeof( TCHAR ) );
252 require_noerr( err, exit );
253
254 err = RegSetValueEx( m_setupKey, L"Enabled", 0, REG_DWORD, (LPBYTE) &enabled, sizeof( DWORD ) );
255 require_noerr( err, exit );
256
257 exit:
258
259 return;
260 }
261
262
263 //---------------------------------------------------------------------------------------------------------------------------
264 // CFirstPage::CheckStatus
265 //---------------------------------------------------------------------------------------------------------------------------
266
267 OSStatus
268 CFirstPage::CheckStatus()
269 {
270 DWORD status = 0;
271 DWORD dwSize = sizeof( DWORD );
272 OSStatus err;
273
274 // Get the status field
275
276 err = RegQueryValueEx( m_statusKey, L"Status", NULL, NULL, (LPBYTE) &status, &dwSize );
277 require_noerr( err, exit );
278
279 ShowStatus( status );
280
281 exit:
282
283 return kNoErr;
284 }
285
286
287 //---------------------------------------------------------------------------------------------------------------------------
288 // CFirstPage::ShowStatus
289 //---------------------------------------------------------------------------------------------------------------------------
290
291 void
292 CFirstPage::ShowStatus( DWORD status )
293 {
294 if ( status )
295 {
296 m_failureIcon.ShowWindow( SW_HIDE );
297 m_successIcon.ShowWindow( SW_SHOW );
298 }
299 else
300 {
301 m_failureIcon.ShowWindow( SW_SHOW );
302 m_successIcon.ShowWindow( SW_HIDE );
303 }
304 }
305
306
307 //---------------------------------------------------------------------------------------------------------------------------
308 // CFirstPage::OnRegistryChanged
309 //---------------------------------------------------------------------------------------------------------------------------
310
311 void
312 CFirstPage::OnRegistryChanged()
313 {
314 CheckStatus();
315 }