lists.arthurdejong.org
RSS feed

fixes for getpeercred.c

[Date Prev][Date Next] [Thread Prev][Thread Next]

fixes for getpeercred.c



Folks,

In preparation for hacking on the code more I tried building the code on
NetBSD.  The attached diff is a part of the fixes required to build.  I
am working on getting the FreeBSD nss compat headers into NetBSD so the
nss-pam-ldapd builds.

The diff cleans up some errors that stop the code building and also
fixes a bug where pointers to stack based variables are returned which
could result in chaos.

-- 
Brett Lymn
--
Sent from my NetBSD device.

"We are were wolves",
"You mean werewolves?",
"No we were wolves, now we are something else entirely",
"Oh"
--- getpeercred.c       2022-10-11 07:54:45.000000000 +1030
+++ ../../nss-pam-ldapd-master.modified/compat/getpeercred.c    2023-05-30 
07:52:10.429723839 +0930
@@ -37,6 +37,11 @@
 
 #include "getpeercred.h"
 
+#if defined(HAVE_GETPEEREID)
+static uid_t tuid;
+static gid_t tgid;
+#endif
+
 /* Note: most of this code is untested, except for the first
          implementation (it may even fail to compile) */
 
@@ -96,19 +101,12 @@
   ucred_free(cred);
   return 0;
 #elif defined(HAVE_GETPEEREID)
-  uid_t tuid;
-  gid_t tgid;
   if (uid == NULL)
     uid = &tuid;
   if (gid == NULL)
-    gid = &tguid;
+    gid = &tgid;
   if (getpeereid(sock, uid, gid))
     return -1;
-  /* return the data */
-  if (uid != NULL)
-    *uid = cred.uid;
-  if (gid != NULL)
-    *gid = cred.gid;
   if (pid != NULL)
     *pid = -1; /* we return a -1 pid because we have no usable pid */
   return 0;