From 2cc81abed2ca5b2dd3275e7a73eb2e29939d08ca Mon Sep 17 00:00:00 2001 From: Josh Stillerman Date: Thu, 26 Aug 2021 10:00:58 -0400 Subject: [PATCH] Fix: on some systems UIDs are > 16 bits On systems using active directory uids can be constructed from AD SIDs and may have bits in their high word set. This PR addresses https://github.com/MDSplus/mdsplus/issues/2375 If their are bits set in the high word of the UID then do not or in the group. When displaying in TCL, if the the low 16 bits of the owner do not translate to a user, then try to translate all 32 bits to an owner --- tcl/tcl_directory.c | 3 +++ treeshr/TreePutRecord.c | 6 +++++- treeshr/TreeSegments.c | 9 ++++++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/tcl/tcl_directory.c b/tcl/tcl_directory.c index deb9e7a0d1..1ae9687cf4 100644 --- a/tcl/tcl_directory.c +++ b/tcl/tcl_directory.c @@ -81,6 +81,9 @@ static char *mds_owner( /* Return: ptr to "user" string #endif #ifdef HAVE_GETPWUID struct passwd *p = getpwuid(uid); + if (!p) { + p = getpwuid(owner); + } if (p) { username = alloca(strlen(p->pw_name) + 3); diff --git a/treeshr/TreePutRecord.c b/treeshr/TreePutRecord.c index 44cb67fb26..a1b24d3018 100644 --- a/treeshr/TreePutRecord.c +++ b/treeshr/TreePutRecord.c @@ -127,7 +127,11 @@ int _TreePutRecord(void *dbid, int nid, struct descriptor *descriptor_ptr, int compress_utility = utility_update == 2; #ifndef _WIN32 if (!saved_uic) - saved_uic = (getgid() << 16) | getuid(); + { + saved_uic = getuid(); + if (!(saved_uic & 0xFFFF0000)) + saved_uic = (getgid() << 16) | (saved_uic); + } #endif if (!(IS_OPEN(dblist))) return TreeNOT_OPEN; diff --git a/treeshr/TreeSegments.c b/treeshr/TreeSegments.c index 712a704a13..4c3cef6669 100644 --- a/treeshr/TreeSegments.c +++ b/treeshr/TreeSegments.c @@ -985,7 +985,14 @@ inline static int begin_finish(vars_t *vars) #ifndef _WIN32 static int saved_uic = 0; -static void init_saved_uic() { saved_uic = (getgid() << 16) | getuid(); } +static void init_saved_uic() { + if (!saved_uic) + { + saved_uic = getuid(); + if (!(saved_uic & 0xFFFF0000)) + saved_uic = (getgid() << 16) | (saved_uic); + } +} #endif inline static void begin_local_nci(vars_t *vars, const mdsdsc_a_t *initialValue)