lists.arthurdejong.org
RSS feed

nss-pam-ldapd branch master updated. 0.9.9-6-gd5a25cf

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

nss-pam-ldapd branch master updated. 0.9.9-6-gd5a25cf



This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "nss-pam-ldapd".

The branch, master has been updated
       via  d5a25cfd70a13f40547bee3b9e7288e4e248976f (commit)
      from  d8b16407408ae2caef46ffef3abbc59266f476ba (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
https://arthurdejong.org/git/nss-pam-ldapd/commit/?id=d5a25cfd70a13f40547bee3b9e7288e4e248976f

commit d5a25cfd70a13f40547bee3b9e7288e4e248976f
Author: HWLin <hwlin1414@gmail.com>
Date:   Tue Feb 6 22:43:47 2018 +0800

    Add FreeBSD netgroup support
    
    Closes: https://github.com/arthurdejong/nss-pam-ldapd/pull/29

diff --git a/configure.ac b/configure.ac
index 3fb18c0..1af2b1e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -545,7 +545,7 @@ then
     case "$with_nss_flavour" in
       glibc)   
with_nss_maps="aliases,ethers,group,hosts,netgroup,networks,passwd,protocols,rpc,services,shadow"
 ;;
       solaris) 
with_nss_maps="ethers,group,hosts,netgroup,networks,passwd,protocols,rpc,services,shadow"
 ;;
-      freebsd) with_nss_maps="group,hosts,passwd" ;;
+      freebsd) with_nss_maps="group,hosts,passwd,netgroup" ;;
     esac
   fi
   AC_MSG_RESULT($with_nss_maps)
diff --git a/nss/bsdnss.c b/nss/bsdnss.c
index b1c8803..341c564 100644
--- a/nss/bsdnss.c
+++ b/nss/bsdnss.c
@@ -27,6 +27,7 @@
 
 #include "config.h"
 
+#include <string.h>
 #include <errno.h>
 #include <sys/param.h>
 #include <netinet/in.h>
@@ -37,6 +38,11 @@
 
 #define BUFFER_SIZE 1024
 
+struct name_list {
+  struct name_list *next;
+  char *name;
+};
+
 NSS_METHOD_PROTOTYPE(__nss_compat_getgrnam_r);
 NSS_METHOD_PROTOTYPE(__nss_compat_getgrgid_r);
 NSS_METHOD_PROTOTYPE(__nss_compat_getgrent_r);
@@ -54,6 +60,10 @@ NSS_METHOD_PROTOTYPE(__nss_compat_gethostbyname);
 NSS_METHOD_PROTOTYPE(__nss_compat_gethostbyname2);
 NSS_METHOD_PROTOTYPE(__nss_compat_gethostbyaddr);
 
+NSS_METHOD_PROTOTYPE(__nss_compat_getnetgrent_r);
+NSS_METHOD_PROTOTYPE(__nss_compat_setnetgrent);
+NSS_METHOD_PROTOTYPE(__nss_compat_endnetgrent);
+
 static ns_mtab methods[] = {
   { NSDB_GROUP, "getgrnam_r", __nss_compat_getgrnam_r, (void 
*)NSS_NAME(getgrnam_r) },
   { NSDB_GROUP, "getgrgid_r", __nss_compat_getgrgid_r, (void 
*)NSS_NAME(getgrgid_r) },
@@ -83,6 +93,10 @@ static ns_mtab methods[] = {
   { NSDB_PASSWD_COMPAT, "getpwent_r", __nss_compat_getpwent_r, (void 
*)NSS_NAME(getpwent_r) },
   { NSDB_PASSWD_COMPAT, "setpwent",   __nss_compat_setpwent,   (void 
*)NSS_NAME(setpwent) },
   { NSDB_PASSWD_COMPAT, "endpwent",   __nss_compat_endpwent,   (void 
*)NSS_NAME(endpwent) },
+
+  { NSDB_NETGROUP, "getnetgrent_r", __nss_compat_getnetgrent_r, (void 
*)NSS_NAME(getnetgrent_r) },
+  { NSDB_NETGROUP, "setnetgrent", __nss_compat_setnetgrent, (void 
*)NSS_NAME(setnetgrent) },
+  { NSDB_NETGROUP, "endnetgrent", __nss_compat_endnetgrent, (void 
*)NSS_NAME(endnetgrent) },
 };
 
 typedef nss_status_t (*gethbn_t)(const char *, struct hostent *, char *, 
size_t, int *, int *);
@@ -210,3 +224,95 @@ ns_mtab *nss_module_register(const char UNUSED(*source), 
unsigned int *mtabsize,
   *unreg = NULL;
   return methods;
 }
+
+static void *_netgr_result;
+
+int __nss_compat_getnetgrent_r(void UNUSED(*retval), void *mdata, va_list ap)
+{
+  nss_status_t (*fn)(struct __netgrent *, char *, size_t, int *);
+  char **hostp, **userp, **domp;
+  char *buffer;
+  size_t bufsize;
+  enum nss_status rv;
+  int *errorp;
+  int ret;
+  struct name_list *netlist;
+  struct __netgrent *netgr;
+
+  fn = (nss_status_t (*)(struct __netgrent *, char *, size_t, int *))mdata;
+  hostp = va_arg(ap, char **);
+  userp = va_arg(ap, char **);
+  domp = va_arg(ap, char **);
+  buffer = va_arg(ap, char *);
+  bufsize = va_arg(ap, size_t);
+  errorp = va_arg(ap, int *);
+
+  do {
+    *errorp = 0;
+    rv = fn(_netgr_result, buffer, bufsize,
+        errorp);
+
+    ret = __nss_compat_result(rv, *errorp);
+    netgr = (struct __netgrent *)_netgr_result;
+
+    switch (ret){
+      case NS_SUCCESS:
+        if (netgr->type == group_val){
+          netlist = (struct name_list *)malloc(sizeof(struct name_list));
+          netlist->next = netgr->needed_groups;
+          netlist->name = strdup(netgr->val.group);
+          netgr->needed_groups = netlist;
+          ret = NS_TRYAGAIN;
+        }else{
+          *hostp = (char *)netgr->val.triple.host;
+          *userp = (char *)netgr->val.triple.user;
+          *domp = (char *)netgr->val.triple.domain;
+          return (NS_SUCCESS);
+        }
+        break;
+      case NS_RETURN:
+        netlist = netgr->needed_groups;
+        if(netlist != NULL){
+          NSS_NAME(setnetgrent)(netlist->name, netgr);
+          netgr->needed_groups = netlist->next;
+          free(netlist->name);
+          free(netlist);
+          ret = NS_TRYAGAIN;
+        }
+        break;
+      default:
+        ;
+    }
+  } while (ret == NS_TRYAGAIN);
+
+  return ret;
+}
+
+int __nss_compat_setnetgrent(void UNUSED(*retval), void *mdata, va_list ap)
+{
+  nss_status_t (*fn)(const char *, struct __netgrent *);
+  const char *netgroup;
+
+  fn = (nss_status_t (*)(const char *, struct __netgrent *))mdata;
+  netgroup = va_arg(ap, const char *);
+
+  if (_netgr_result != NULL)
+    free(_netgr_result);
+  _netgr_result = calloc(1, sizeof(struct __netgrent));
+  if (_netgr_result == NULL)
+    return (NS_TRYAGAIN);
+
+  return (fn(netgroup, _netgr_result));
+}
+
+int __nss_compat_endnetgrent(void UNUSED(*retval), void *mdata, va_list 
UNUSED(ap))
+{
+  nss_status_t (*fn)(struct __netgrent *);
+  int ret;
+
+  fn = (nss_status_t (*)(struct __netgrent *))mdata;
+  ret = fn(_netgr_result);
+  free(_netgr_result);
+  _netgr_result = NULL;
+  return (ret);
+}

-----------------------------------------------------------------------

Summary of changes:
 configure.ac |   2 +-
 nss/bsdnss.c | 106 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 107 insertions(+), 1 deletion(-)


hooks/post-receive
-- 
nss-pam-ldapd
-- 
To unsubscribe send an email to
nss-pam-ldapd-commits-unsubscribe@lists.arthurdejong.org or see
https://lists.arthurdejong.org/nss-pam-ldapd-commits/