Skip to content
Permalink
Browse files
Improve error message to always explicitly report file path
  • Loading branch information
markt-asf committed Apr 29, 2022
1 parent 9d3cff5 commit 5a4cd562add68a73da64b6841d7fbfe9116055a1
Showing 1 changed file with 26 additions and 8 deletions.
@@ -720,6 +720,30 @@ static BOOL printConfig(LPAPXCMDLINE lpCmdline)
return TRUE;
}

/* Common error reporting */
static void logGrantFileAccessFail(LPCWSTR szUser, LPCWSTR szPath, DWORD dwError)
{
WCHAR sPath[SIZ_PATHLEN];

/*
* Both user and path may be null indicating that the default should be
* used. Strictly, the default for path isn't fixed so it needs to be
* calculated. The default for user is a constant so use that directly.
*/
if (!szPath) {
if (GetSystemDirectoryW(sPath, MAX_PATH) == 0) {
lstrlcpyW(sPath, MAX_PATH, L"%windir%\\system32");
}
lstrlcatW(sPath, MAX_PATH, LOG_PATH_DEFAULT);
}
else {
lstrlcpyW(sPath, MAX_PATH, szPath);
}

apxLogWrite(APXLOG_MARK_WARN "Failed to grant service user '%S' write permissions to log path '%S' due to error '%d'",
(szUser ? szUser : DEFAULT_SERVICE_USER), sPath, dwError);
}

/* Operations */
static BOOL docmdInstallService(LPAPXCMDLINE lpCmdline)
{
@@ -832,10 +856,7 @@ static BOOL docmdInstallService(LPAPXCMDLINE lpCmdline)
apxServiceSetNames(hService, NULL, NULL, sd, su, sp);
dwResult = apxSecurityGrantFileAccessToUser(SO_LOGPATH, su);
if (dwResult) {
apxLogWrite(APXLOG_MARK_WARN "Failed to grant service user '%S' write permissions to log path '%S' due to error '%d'",
su ? su : DEFAULT_SERVICE_USER,
SO_LOGPATH ? SO_LOGPATH : L"<default>",
dwResult);
logGrantFileAccessFail(su, SO_LOGPATH, dwResult);
}
}
apxCloseHandle(hService);
@@ -1026,10 +1047,7 @@ static BOOL docmdUpdateService(LPAPXCMDLINE lpCmdline)
sp));
dwResult = apxSecurityGrantFileAccessToUser(SO_LOGPATH, su);
if (dwResult) {
apxLogWrite(APXLOG_MARK_WARN "Failed to grant service user '%S' write permissions to log path '%S' due to error '%d'",
su ? su : DEFAULT_SERVICE_USER,
SO_LOGPATH ? SO_LOGPATH : L"<default>",
dwResult);
logGrantFileAccessFail(su, SO_LOGPATH, dwResult);
}
/* Update the --Startup mode */
if (ST_STARTUP & APXCMDOPT_FOUND) {

0 comments on commit 5a4cd56

Please sign in to comment.