From ed7a5848778aa1e5b32d395544a9e73caf2c5583 Mon Sep 17 00:00:00 2001 From: Max Qian <64824374+AstroAir@users.noreply.github.com> Date: Tue, 1 Aug 2023 20:37:12 +0800 Subject: [PATCH] Fix build bug on Windows (#1917) --- libs/indicore/indidevapi.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/libs/indicore/indidevapi.c b/libs/indicore/indidevapi.c index c78b340c54..5f35e95c56 100644 --- a/libs/indicore/indidevapi.c +++ b/libs/indicore/indidevapi.c @@ -11,6 +11,11 @@ #include #include +#ifdef _WIN32 +#include +#include +#endif + /** \section IUSave */ void IUSaveConfigNumber(FILE *fp, const INumberVectorProperty *nvp) @@ -72,14 +77,33 @@ XMLEle *configRootFP(const char *device) if (stat(configDir, &st) != 0) { +#ifdef _WIN32 + if (mkdir(configDir) != 0) +#else if (mkdir(configDir, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) < 0) +#endif return NULL; } stat(configFileName, &st); + +#ifdef _WIN32 + BOOL isAdmin = FALSE; + SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY; + PSID AdministratorsGroup; + if (AllocateAndInitializeSid(&NtAuthority, 2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, &AdministratorsGroup)) + { + if (CheckTokenMembership(NULL, AdministratorsGroup, &isAdmin) == FALSE) + isAdmin = FALSE; + FreeSid(AdministratorsGroup); + } + if ((st.st_uid == 0 && st.st_mode & S_IFDIR) || (st.st_gid == 0 && isAdmin == TRUE)) + return NULL; +#else /* If file is owned by root and current user is NOT root then abort */ if ( (st.st_uid == 0 && getuid() != 0) || (st.st_gid == 0 && getgid() != 0) ) return NULL; +#endif fp = fopen(configFileName, "r"); if (fp == NULL)