--- plugin/auth_pam/mapper/pam_user_map.c.orig	2020-11-11 07:02:45 +0000
+++ plugin/auth_pam/mapper/pam_user_map.c	2020-11-11 07:04:01 +0000
@@ -50,6 +50,54 @@
 
 #include <security/pam_modules.h>
 
+static int getgrouplist(const char *user, gid_t gid, gid_t *groups,
+                 int *grpcnt)
+{
+    char *grplist;
+    char *grp;
+    gid_t temp_gid;
+    int num_gids = 1;
+    int ret = 0;
+    long l;
+
+    grplist = getgrset(user);
+
+    if (grplist == NULL) {
+        return -1;
+    }
+
+    if (*grpcnt > 0) {
+        groups[0] = gid;
+    }
+
+    while ((grp = strsep(&grplist, ",")) != NULL) {
+        l = strtol(grp, NULL, 10);
+        temp_gid = (gid_t) l;
+        if (temp_gid == gid) {
+            continue;
+        }
+
+        if (num_gids + 1 > *grpcnt) {
+            num_gids++;
+            continue;
+        }
+        groups[num_gids++] = temp_gid;
+    }
+    free(grplist);
+
+    if (num_gids > *grpcnt) {
+        ret = -1;
+    }
+    *grpcnt = num_gids;
+
+    return ret;
+}
+
+/*
+ * function taken from samba sources tree as of Aug 20 2009,
+ * file source4/lib/ldb/pyldb.c
+ */
+
 #ifndef HAVE_PAM_SYSLOG
 #include <stdarg.h>
 static void
