forked from BOINC/boinc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCAGrantBOINCProjectRights.cpp
232 lines (203 loc) · 7.91 KB
/
CAGrantBOINCProjectRights.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
// Berkeley Open Infrastructure for Network Computing
// http://boinc.berkeley.edu
// Copyright (C) 2005 University of California
//
// This is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation;
// either version 2.1 of the License, or (at your option) any later version.
//
// This software is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU Lesser General Public License for more details.
//
// To view the GNU Lesser General Public License visit
// http://www.gnu.org/copyleft/lesser.html
// or write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
#include "stdafx.h"
#include "boinccas.h"
#include "CAGrantBOINCProjectRights.h"
#include "lsaprivs.h"
#define CUSTOMACTION_NAME _T("CAGrantBOINCProjectRights")
#define CUSTOMACTION_PROGRESSTITLE _T("Validating BOINC Project's privileges")
/////////////////////////////////////////////////////////////////////
//
// Function:
//
// Description:
//
/////////////////////////////////////////////////////////////////////
CAGrantBOINCProjectRights::CAGrantBOINCProjectRights(MSIHANDLE hMSIHandle) :
BOINCCABase(hMSIHandle, CUSTOMACTION_NAME, CUSTOMACTION_PROGRESSTITLE)
{}
/////////////////////////////////////////////////////////////////////
//
// Function:
//
// Description:
//
/////////////////////////////////////////////////////////////////////
CAGrantBOINCProjectRights::~CAGrantBOINCProjectRights()
{
BOINCCABase::~BOINCCABase();
}
/////////////////////////////////////////////////////////////////////
//
// Function:
//
// Description:
//
/////////////////////////////////////////////////////////////////////
UINT CAGrantBOINCProjectRights::OnExecution()
{
PSID pSid;
tstring strBOINCProjectAccountUsername;
tstring strOSVersion;
UINT uiReturnValue = -1;
uiReturnValue = GetProperty( _T("BOINC_PROJECT_USERNAME"), strBOINCProjectAccountUsername );
if ( uiReturnValue ) return uiReturnValue;
uiReturnValue = GetProperty( _T("VersionNT"), strOSVersion );
if ( uiReturnValue ) return uiReturnValue;
//
// Obtain the SID of the user/group.
// Note that we could target a specific machine, but we don't.
// Specifying NULL for target machine searches for the SID in the
// following order: well-known, Built-in and local, primary domain,
// trusted domains.
//
if(
GetAccountSid(
NULL, // default lookup logic
strBOINCProjectAccountUsername.c_str(), // account to obtain SID
&pSid // buffer to allocate to contain resultant SID
)
)
{
//
// We only grant the privilege if we succeeded in obtaining the
// SID. We can actually add SIDs which cannot be looked up, but
// looking up the SID is a good sanity check which is suitable for
// most cases.
// User Rights
GrantUserRight(pSid, L"SeNetworkLogonRight", FALSE);
GrantUserRight(pSid, L"SeRemoteInteractiveLogonRight", FALSE);
GrantUserRight(pSid, L"SeBatchLogonRight", FALSE);
GrantUserRight(pSid, L"SeInteractiveLogonRight", FALSE);
if (!GrantUserRight(pSid, L"SeServiceLogonRight", TRUE))
{
LogMessage(
INSTALLMESSAGE_ERROR,
NULL,
NULL,
NULL,
NULL,
_T("Failed call to GrantUserRight - SeServiceLogonRight")
);
}
if (!GrantUserRight(pSid, L"SeDenyNetworkLogonRight", TRUE))
{
LogMessage(
INSTALLMESSAGE_ERROR,
NULL,
NULL,
NULL,
NULL,
_T("Failed call to GrantUserRight - SeDenyNetworkLogonRight")
);
}
if (!GrantUserRight(pSid, L"SeDenyInteractiveLogonRight", TRUE))
{
LogMessage(
INSTALLMESSAGE_ERROR,
NULL,
NULL,
NULL,
NULL,
_T("Failed call to GrantUserRight - SeDenyInteractiveLogonRight")
);
}
GrantUserRight(pSid, L"SeDenyBatchLogonRight", FALSE);
GrantUserRight(pSid, L"SeDenyServiceLogonRight", FALSE);
// Windows 2000 and older does not have the SeDenyRemoteInteractiveLogonRight user right
//
if (strOSVersion > _T("500")) {
if (!GrantUserRight(pSid, L"SeDenyRemoteInteractiveLogonRight", TRUE))
{
LogMessage(
INSTALLMESSAGE_ERROR,
NULL,
NULL,
NULL,
NULL,
_T("Failed call to GrantUserRight - SeDenyRemoteInteractiveLogonRight")
);
}
}
// Privileges
GrantUserRight(pSid, L"SeTcbPrivilege", FALSE);
GrantUserRight(pSid, L"SeMachineAccountPrivilege", FALSE);
GrantUserRight(pSid, L"SeIncreaseQuotaPrivilege", FALSE);
GrantUserRight(pSid, L"SeBackupPrivilege", FALSE);
GrantUserRight(pSid, L"SeChangeNotifyPrivilege", FALSE);
GrantUserRight(pSid, L"SeSystemTimePrivilege", FALSE);
GrantUserRight(pSid, L"SeCreateTokenPrivilege", FALSE);
GrantUserRight(pSid, L"SeCreatePagefilePrivilege", FALSE);
GrantUserRight(pSid, L"SeCreateGlobalPrivilege", FALSE);
GrantUserRight(pSid, L"SeDebugPrivilege", FALSE);
GrantUserRight(pSid, L"SeEnableDelegationPrivilege", FALSE);
GrantUserRight(pSid, L"SeRemoteShutdownPrivilege", FALSE);
GrantUserRight(pSid, L"SeAuditPrivilege", FALSE);
GrantUserRight(pSid, L"SeImpersonatePrivilege", FALSE);
GrantUserRight(pSid, L"SeIncreaseBasePriorityPrivilege", FALSE);
GrantUserRight(pSid, L"SeLoadDriverPrivilege", FALSE);
GrantUserRight(pSid, L"SeLockMemoryPrivilege", FALSE);
GrantUserRight(pSid, L"SeSecurityPrivilege", FALSE);
GrantUserRight(pSid, L"SeSystemEnvironmentPrivilege", FALSE);
GrantUserRight(pSid, L"SeManageVolumePrivilege", FALSE);
GrantUserRight(pSid, L"SeProfileSingleProcessPrivilege", FALSE);
GrantUserRight(pSid, L"SeSystemProfilePrivilege", FALSE);
GrantUserRight(pSid, L"SeUndockPrivilege", FALSE);
GrantUserRight(pSid, L"SeAssignPrimaryTokenPrivilege", FALSE);
GrantUserRight(pSid, L"SeRestorePrivilege", FALSE);
GrantUserRight(pSid, L"SeShutdownPrivilege", FALSE);
GrantUserRight(pSid, L"SeSynchAgentPrivilege", FALSE);
GrantUserRight(pSid, L"SeTakeOwnershipPrivilege", FALSE);
}
else
{
LogMessage(
INSTALLMESSAGE_ERROR,
NULL,
NULL,
NULL,
NULL,
_T("Failed to be able to obtain the SID for the selected user on the localhost")
);
return ERROR_INSTALL_FAILURE;
}
//
// Cleanup any handles and memory allocated during the custom action
//
if(pSid != NULL) HeapFree(GetProcessHeap(), 0, pSid);
return ERROR_SUCCESS;
}
/////////////////////////////////////////////////////////////////////
//
// Function: GrantBOINCProjectRights
//
// Description: This custom action reads the BOINC_PROJECT_USERNAME
// public property and grants that user the
// required rights.
//
/////////////////////////////////////////////////////////////////////
UINT __stdcall GrantBOINCProjectRights(MSIHANDLE hInstall)
{
UINT uiReturnValue = 0;
CAGrantBOINCProjectRights* pCA = new CAGrantBOINCProjectRights(hInstall);
uiReturnValue = pCA->Execute();
delete pCA;
return uiReturnValue;
}