]> git.saurik.com Git - apple/mdnsresponder.git/blob - mDNSWindows/ControlPanel/SharedSecret.cpp
mDNSResponder-878.270.2.tar.gz
[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
18
19 // SharedSecret.cpp : implementation file
20 //
21
22
23 #include <Secret.h>
24 #include "stdafx.h"
25 #include "SharedSecret.h"
26 #include <WinServices.h>
27
28 #include <DebugServices.h>
29
30
31 // SharedSecret dialog
32
33 IMPLEMENT_DYNAMIC(CSharedSecret, CDialog)
34
35
36 //---------------------------------------------------------------------------------------------------------------------------
37 // CSharedSecret::CSharedSecret
38 //---------------------------------------------------------------------------------------------------------------------------
39
40 CSharedSecret::CSharedSecret(CWnd* pParent /*=NULL*/)
41 : CDialog(CSharedSecret::IDD, pParent)
42 , m_key(_T(""))
43 , m_secret(_T(""))
44 {
45 }
46
47
48 //---------------------------------------------------------------------------------------------------------------------------
49 // CSharedSecret::~CSharedSecret
50 //---------------------------------------------------------------------------------------------------------------------------
51
52 CSharedSecret::~CSharedSecret()
53 {
54 }
55
56
57 //---------------------------------------------------------------------------------------------------------------------------
58 // CSharedSecret::DoDataExchange
59 //---------------------------------------------------------------------------------------------------------------------------
60
61 void CSharedSecret::DoDataExchange(CDataExchange* pDX)
62 {
63 CDialog::DoDataExchange(pDX);
64 DDX_Text(pDX, IDC_KEY, m_key );
65 DDX_Text(pDX, IDC_SECRET, m_secret );
66 }
67
68
69 BEGIN_MESSAGE_MAP(CSharedSecret, CDialog)
70 END_MESSAGE_MAP()
71
72
73 //---------------------------------------------------------------------------------------------------------------------------
74 // CSharedSecret::Load
75 //---------------------------------------------------------------------------------------------------------------------------
76
77 void
78 CSharedSecret::Load( CString zone )
79 {
80 char zoneUTF8[ 256 ];
81 char outDomain[ 256 ];
82 char outKey[ 256 ];
83 char outSecret[ 256 ];
84
85 StringObjectToUTF8String( zone, zoneUTF8, sizeof( zoneUTF8 ) );
86
87 if ( LsaGetSecret( zoneUTF8, outDomain, sizeof( outDomain ) / sizeof( TCHAR ), outKey, sizeof( outKey ) / sizeof( TCHAR ), outSecret, sizeof( outSecret ) / sizeof( TCHAR ) ) )
88 {
89 m_key = outKey;
90 m_secret = outSecret;
91 }
92 else
93 {
94 m_key = zone;
95 }
96 }
97
98
99 //---------------------------------------------------------------------------------------------------------------------------
100 // CSharedSecret::Commit
101 //---------------------------------------------------------------------------------------------------------------------------
102
103 void
104 CSharedSecret::Commit( CString zone )
105 {
106 char zoneUTF8[ 256 ];
107 char keyUTF8[ 256 ];
108 char secretUTF8[ 256 ];
109
110 StringObjectToUTF8String( zone, zoneUTF8, sizeof( zoneUTF8 ) );
111 StringObjectToUTF8String( m_key, keyUTF8, sizeof( keyUTF8 ) );
112 StringObjectToUTF8String( m_secret, secretUTF8, sizeof( secretUTF8 ) );
113
114 LsaSetSecret( zoneUTF8, keyUTF8, secretUTF8 );
115 }