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