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 "CAGetUsersGroupName.h"
24 #include "lkuprid.h"
25 
26 
27 #define CUSTOMACTION_NAME               _T("CAGetUsersGroupName")
28 #define CUSTOMACTION_PROGRESSTITLE      _T("Retrieving the Users group name")
29 
30 
31 /////////////////////////////////////////////////////////////////////
32 //
33 // Function:
34 //
35 // Description:
36 //
37 /////////////////////////////////////////////////////////////////////
CAGetUsersGroupName(MSIHANDLE hMSIHandle)38 CAGetUsersGroupName::CAGetUsersGroupName(MSIHANDLE hMSIHandle) :
39     BOINCCABase(hMSIHandle, CUSTOMACTION_NAME, CUSTOMACTION_PROGRESSTITLE)
40 {}
41 
42 
43 /////////////////////////////////////////////////////////////////////
44 //
45 // Function:
46 //
47 // Description:
48 //
49 /////////////////////////////////////////////////////////////////////
~CAGetUsersGroupName()50 CAGetUsersGroupName::~CAGetUsersGroupName()
51 {
52     BOINCCABase::~BOINCCABase();
53 }
54 
55 
56 /////////////////////////////////////////////////////////////////////
57 //
58 // Function:
59 //
60 // Description:
61 //
62 /////////////////////////////////////////////////////////////////////
OnExecution()63 UINT CAGetUsersGroupName::OnExecution()
64 {
65     tstring     strGroupAlias;
66     WCHAR       szName[UNLEN+1];
67     DWORD       cchName = UNLEN;
68     UINT        uiReturnValue = -1;
69 
70 
71     uiReturnValue = GetProperty( _T("GROUPALIAS_USERS"), strGroupAlias );
72     if ( uiReturnValue ) return uiReturnValue;
73 
74 
75     // If something is already defined then don't override it.
76     if( strGroupAlias.empty() )
77     {
78         if( !LookupAliasFromRid( NULL, DOMAIN_ALIAS_RID_USERS, szName, &cchName) )
79         {
80             LogMessage(
81                 INSTALLMESSAGE_ERROR,
82                 NULL,
83                 NULL,
84                 NULL,
85                 GetLastError(),
86                 _T("Setup was unable to determine the Users group name.")
87             );
88             return ERROR_INSTALL_FAILURE;
89         }
90 
91         uiReturnValue = SetProperty( _T("GROUPALIAS_USERS"), szName);
92         if ( uiReturnValue ) return uiReturnValue;
93     }
94 
95 
96     return ERROR_SUCCESS;
97 }
98 
99 
100 /////////////////////////////////////////////////////////////////////
101 //
102 // Function:    GetUsersGroupName
103 //
104 // Description: This custom action looks up the users group
105 //                name.
106 //
107 /////////////////////////////////////////////////////////////////////
GetUsersGroupName(MSIHANDLE hInstall)108 UINT __stdcall GetUsersGroupName(MSIHANDLE hInstall)
109 {
110     UINT uiReturnValue = 0;
111 
112     CAGetUsersGroupName* pCA = new CAGetUsersGroupName(hInstall);
113     uiReturnValue = pCA->Execute();
114     delete pCA;
115 
116     return uiReturnValue;
117 }
118