]> git.saurik.com Git - apple/mdnsresponder.git/blob - mDNSWindows/ControlPanel/SharedSecret.cpp
b74366ebfda0d03261c64fc42d6bf2099400f33b
[apple/mdnsresponder.git] / mDNSWindows / ControlPanel / SharedSecret.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: SharedSecret.cpp,v $
20 Revision 1.7 2009/06/22 23:25:11 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 2007/06/12 20:06:06 herscher
24 <rdar://problem/5263387> ControlPanel was inadvertently adding a trailing dot to all key names.
25
26 Revision 1.5 2006/08/14 23:25:28 cheshire
27 Re-licensed mDNSResponder daemon source code under Apache License, Version 2.0
28
29 Revision 1.4 2005/10/18 06:13:41 herscher
30 <rdar://problem/4192119> Prepend "$" to key name to ensure that secure updates work if the domain name and key name are the same
31
32 Revision 1.3 2005/04/06 02:04:49 shersche
33 <rdar://problem/4066485> Registering with shared secret doesn't work
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
42 // SharedSecret.cpp : implementation file
43 //
44
45
46 #include <Secret.h>
47 #include "stdafx.h"
48 #include "SharedSecret.h"
49 #include <WinServices.h>
50
51 #include <DebugServices.h>
52
53
54 // SharedSecret dialog
55
56 IMPLEMENT_DYNAMIC(CSharedSecret, CDialog)
57
58
59 //---------------------------------------------------------------------------------------------------------------------------
60 // CSharedSecret::CSharedSecret
61 //---------------------------------------------------------------------------------------------------------------------------
62
63 CSharedSecret::CSharedSecret(CWnd* pParent /*=NULL*/)
64 : CDialog(CSharedSecret::IDD, pParent)
65 , m_key(_T(""))
66 , m_secret(_T(""))
67 {
68 }
69
70
71 //---------------------------------------------------------------------------------------------------------------------------
72 // CSharedSecret::~CSharedSecret
73 //---------------------------------------------------------------------------------------------------------------------------
74
75 CSharedSecret::~CSharedSecret()
76 {
77 }
78
79
80 //---------------------------------------------------------------------------------------------------------------------------
81 // CSharedSecret::DoDataExchange
82 //---------------------------------------------------------------------------------------------------------------------------
83
84 void CSharedSecret::DoDataExchange(CDataExchange* pDX)
85 {
86 CDialog::DoDataExchange(pDX);
87 DDX_Text(pDX, IDC_KEY, m_key );
88 DDX_Text(pDX, IDC_SECRET, m_secret );
89 }
90
91
92 BEGIN_MESSAGE_MAP(CSharedSecret, CDialog)
93 END_MESSAGE_MAP()
94
95
96 //---------------------------------------------------------------------------------------------------------------------------
97 // CSharedSecret::Load
98 //---------------------------------------------------------------------------------------------------------------------------
99
100 void
101 CSharedSecret::Load( CString zone )
102 {
103 char zoneUTF8[ 256 ];
104 char outDomain[ 256 ];
105 char outKey[ 256 ];
106 char outSecret[ 256 ];
107
108 StringObjectToUTF8String( zone, zoneUTF8, sizeof( zoneUTF8 ) );
109
110 if ( LsaGetSecret( zoneUTF8, outDomain, sizeof( outDomain ) / sizeof( TCHAR ), outKey, sizeof( outKey ) / sizeof( TCHAR ), outSecret, sizeof( outSecret ) / sizeof( TCHAR ) ) )
111 {
112 m_key = outKey;
113 m_secret = outSecret;
114 }
115 else
116 {
117 m_key = zone;
118 }
119 }
120
121
122 //---------------------------------------------------------------------------------------------------------------------------
123 // CSharedSecret::Commit
124 //---------------------------------------------------------------------------------------------------------------------------
125
126 void
127 CSharedSecret::Commit( CString zone )
128 {
129 char zoneUTF8[ 256 ];
130 char keyUTF8[ 256 ];
131 char secretUTF8[ 256 ];
132
133 StringObjectToUTF8String( zone, zoneUTF8, sizeof( zoneUTF8 ) );
134 StringObjectToUTF8String( m_key, keyUTF8, sizeof( keyUTF8 ) );
135 StringObjectToUTF8String( m_secret, secretUTF8, sizeof( secretUTF8 ) );
136
137 LsaSetSecret( zoneUTF8, keyUTF8, secretUTF8 );
138 }