2 * Copyright (c) 2002-2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
23 Change History (most recent first):
25 $Log: SharedSecret.cpp,v $
26 Revision 1.2 2005/03/03 19:55:22 shersche
27 <rdar://problem/4034481> ControlPanel source code isn't saving CVS log info
33 // SharedSecret.cpp : implementation file
37 #include "SharedSecret.h"
39 #include <DebugServices.h>
42 //---------------------------------------------------------------------------------------------------------------------------
43 // Private declarations
44 //---------------------------------------------------------------------------------------------------------------------------
49 PLSA_UNICODE_STRING pLsaString
,
53 // SharedSecret dialog
55 IMPLEMENT_DYNAMIC(CSharedSecret
, CDialog
)
58 //---------------------------------------------------------------------------------------------------------------------------
59 // CSharedSecret::CSharedSecret
60 //---------------------------------------------------------------------------------------------------------------------------
62 CSharedSecret::CSharedSecret(CWnd
* pParent
/*=NULL*/)
63 : CDialog(CSharedSecret::IDD
, pParent
)
65 , m_secretName(_T(""))
70 //---------------------------------------------------------------------------------------------------------------------------
71 // CSharedSecret::~CSharedSecret
72 //---------------------------------------------------------------------------------------------------------------------------
74 CSharedSecret::~CSharedSecret()
79 //---------------------------------------------------------------------------------------------------------------------------
80 // CSharedSecret::DoDataExchange
81 //---------------------------------------------------------------------------------------------------------------------------
83 void CSharedSecret::DoDataExchange(CDataExchange
* pDX
)
85 CDialog::DoDataExchange(pDX
);
86 DDX_Text(pDX
, IDC_SECRET
, m_secret
);
87 DDX_Text(pDX
, IDC_SECRET_NAME
, m_secretName
);
91 BEGIN_MESSAGE_MAP(CSharedSecret
, CDialog
)
96 //---------------------------------------------------------------------------------------------------------------------------
97 // CSharedSecret::Commit
98 //---------------------------------------------------------------------------------------------------------------------------
101 CSharedSecret::Commit()
103 LSA_OBJECT_ATTRIBUTES attrs
;
104 LSA_HANDLE handle
= NULL
;
106 LSA_UNICODE_STRING lucKeyName
;
107 LSA_UNICODE_STRING lucPrivateData
;
111 // If there isn't a trailing dot, add one because the mDNSResponder
112 // presents names with the trailing dot.
114 if ( m_secretName
.ReverseFind( '.' ) != m_secretName
.GetLength() )
119 // attrs are reserved, so initialize to zeroes.
121 ZeroMemory(&attrs
, sizeof( attrs
) );
123 // Get a handle to the Policy object on the local system
125 res
= LsaOpenPolicy( NULL
, &attrs
, POLICY_ALL_ACCESS
, &handle
);
126 err
= translate_errno( res
== 0, LsaNtStatusToWinError( res
), kUnknownErr
);
127 require_noerr( err
, exit
);
129 // Intializing PLSA_UNICODE_STRING structures
131 ok
= InitLsaString( &lucKeyName
, m_secretName
);
132 err
= translate_errno( ok
, errno_compat(), kUnknownErr
);
133 require_noerr( err
, exit
);
135 ok
= InitLsaString( &lucPrivateData
, m_secret
);
136 err
= translate_errno( ok
, errno_compat(), kUnknownErr
);
137 require_noerr( err
, exit
);
139 // Store the private data.
141 res
= LsaStorePrivateData( handle
, &lucKeyName
, &lucPrivateData
);
142 err
= translate_errno( res
== 0, LsaNtStatusToWinError( res
), kUnknownErr
);
143 require_noerr( err
, exit
);
157 //---------------------------------------------------------------------------------------------------------------------------
159 //---------------------------------------------------------------------------------------------------------------------------
164 PLSA_UNICODE_STRING pLsaString
,
171 if ( pLsaString
== NULL
)
176 if ( pwszString
!= NULL
)
178 dwLen
= wcslen(pwszString
);
180 // String is too large
189 pLsaString
->Buffer
= (WCHAR
*) pwszString
;
190 pLsaString
->Length
= (USHORT
) dwLen
* sizeof(WCHAR
);
191 pLsaString
->MaximumLength
= (USHORT
)(dwLen
+1) * sizeof(WCHAR
);