You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ma...@apache.org on 2022/04/29 16:29:10 UTC
[commons-daemon] 01/02: Improve error message to always explicitly report file path
This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-daemon.git
commit 5a4cd562add68a73da64b6841d7fbfe9116055a1
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Fri Apr 29 17:18:40 2022 +0100
Improve error message to always explicitly report file path
---
src/native/windows/apps/prunsrv/prunsrv.c | 34 +++++++++++++++++++++++--------
1 file changed, 26 insertions(+), 8 deletions(-)
diff --git a/src/native/windows/apps/prunsrv/prunsrv.c b/src/native/windows/apps/prunsrv/prunsrv.c
index cfe3b30..f109678 100644
--- a/src/native/windows/apps/prunsrv/prunsrv.c
+++ b/src/native/windows/apps/prunsrv/prunsrv.c
@@ -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) {