1 // Berkeley Open Infrastructure for Network Computing
2 // http://boinc.berkeley.edu
3 // Copyright (C) 2005 University of California
4 //
5 // This is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation;
8 // either version 2.1 of the License, or (at your option) any later version.
9 //
10 // This software is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 // See the GNU Lesser General Public License for more details.
14 //
15 // To view the GNU Lesser General Public License visit
16 // http://www.gnu.org/copyleft/lesser.html
17 // or write to the Free Software Foundation, Inc.,
18 // 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19 //
20 
21 #include "stdafx.h"
22 #include "boinccas.h"
23 #include "CAGetAdministratorsGroupName.h"
24 #include "lkuprid.h"
25 
26 #define CUSTOMACTION_NAME               _T("CAGetAdministratorsGroupName")
27 #define CUSTOMACTION_PROGRESSTITLE      _T("Retrieving the Administrators group name")
28 
29 
30 /////////////////////////////////////////////////////////////////////
31 //
32 // Function:
33 //
34 // Description:
35 //
36 /////////////////////////////////////////////////////////////////////
CAGetAdministratorsGroupName(MSIHANDLE hMSIHandle)37 CAGetAdministratorsGroupName::CAGetAdministratorsGroupName(MSIHANDLE hMSIHandle) :
38     BOINCCABase(hMSIHandle, CUSTOMACTION_NAME, CUSTOMACTION_PROGRESSTITLE)
39 {}
40 
41 
42 /////////////////////////////////////////////////////////////////////
43 //
44 // Function:
45 //
46 // Description:
47 //
48 /////////////////////////////////////////////////////////////////////
~CAGetAdministratorsGroupName()49 CAGetAdministratorsGroupName::~CAGetAdministratorsGroupName()
50 {
51     BOINCCABase::~BOINCCABase();
52 }
53 
54 
55 /////////////////////////////////////////////////////////////////////
56 //
57 // Function:
58 //
59 // Description:
60 //
61 /////////////////////////////////////////////////////////////////////
OnExecution()62 UINT CAGetAdministratorsGroupName::OnExecution()
63 {
64     tstring     strGroupAlias;
65     WCHAR       szName[UNLEN+1];
66     DWORD       cchName = UNLEN;
67     UINT        uiReturnValue = -1;
68 
69 
70     uiReturnValue = GetProperty( _T("GROUPALIAS_ADMINISTRATORS"), strGroupAlias );
71     if ( uiReturnValue ) return uiReturnValue;
72 
73 
74     // If something is already defined then don't override it.
75     if( strGroupAlias.empty() )
76     {
77         if( !LookupAliasFromRid( NULL, DOMAIN_ALIAS_RID_ADMINS, szName, &cchName) )
78         {
79             LogMessage(
80                 INSTALLMESSAGE_ERROR,
81                 NULL,
82                 NULL,
83                 NULL,
84                 GetLastError(),
85                 _T("Setup was unable to determine the Administrators group name.")
86             );
87             return ERROR_INSTALL_FAILURE;
88         }
89 
90         uiReturnValue = SetProperty( _T("GROUPALIAS_ADMINISTRATORS"), szName);
91         if ( uiReturnValue ) return uiReturnValue;
92     }
93 
94 
95     return ERROR_SUCCESS;
96 }
97 
98 
99 /////////////////////////////////////////////////////////////////////
100 //
101 // Function:    GetAdministratorsGroupName
102 //
103 // Description: This custom action looks up the administrators group
104 //                name.
105 //
106 /////////////////////////////////////////////////////////////////////
GetAdministratorsGroupName(MSIHANDLE hInstall)107 UINT __stdcall GetAdministratorsGroupName(MSIHANDLE hInstall)
108 {
109     UINT uiReturnValue = 0;
110 
111     CAGetAdministratorsGroupName* pCA = new CAGetAdministratorsGroupName(hInstall);
112     uiReturnValue = pCA->Execute();
113     delete pCA;
114 
115     return uiReturnValue;
116 }
117