Skip to contentSkip to conversation

nfs-utils: Tidy up libnfsidmap exported symbols list and API

PATCH New Justin Mitchell 1 participant 1 message Nov 27, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nfs-utils: Tidy up libnfsidmap exported symbols list and API

Prior to its merger with nfs-utils the libnfsidmap library leaked a lot of internal functions and variables that were not defined in its API, some of which were used by its various plugins. This created an accidentally large ABI which restricts attempts to clean up the code base.

These patches aim to trim the ABI down, whilst adding to the API only the minimal required to still support both bundled and 3rd party plugins.

---
This adds nfsidmap_plugin.h which packagers will want to pick up, this can be included by 3rd party plugins to replace copies of nfsidmap_internal.h and cfg.h taken from the libnfsidmap source.

Patches for sssd and libnfsidmap-regex available separately which are the only 3rd party plugins i have found.

 configure.ac                         |  2 +
 support/nfs/Makefile.am              |  4 +-
 support/nfs/conffile.c               | 20 +++------
 support/nfsidmap/Makefile.am         | 12 +++---
 support/nfsidmap/gums.c              |  5 +--
 support/nfsidmap/libnfsidmap.c       | 67 +++++++++++++-----------------
 support/nfsidmap/nfsidmap_common.c   | 33 +++++++++++++++
 support/nfsidmap/nfsidmap_internal.h | 79 ------------------------------------
 support/nfsidmap/nfsidmap_plugin.h   | 68 +++++++++++++++++++++++++++++++
 support/nfsidmap/nfsidmap_private.h  | 55 +++++++++++++++++++++++++
 support/nfsidmap/nss.c               | 13 +++++-
 support/nfsidmap/static.c            |  2 +-
 support/nfsidmap/umich_ldap.c        |  3 +-
 13 files changed, 217 insertions(+), 146 deletions(-)
 create mode 100644 support/nfsidmap/nfsidmap_common.c
 delete mode 100644 support/nfsidmap/nfsidmap_internal.h
 create mode 100644 support/nfsidmap/nfsidmap_plugin.h
 create mode 100644 support/nfsidmap/nfsidmap_private.h
configure.ac +2 -0
index c7651f2..a09c1df 100644
@@ -442,6 +442,8 @@ fi
 AM_CONDITIONAL(PATH_PLUGINS, test -n "$path_plugins")
 
 AC_SUBST(AM_CPPFLAGS, "$AM_CPPFLAGS -I../../support/nfsidmap")
+AC_DEFINE([HAVE_NFS4_SET_DEBUG], 1,
+          [Bundled lib always has the `nfs4_set_debug' function.])
 
 dnl Check for IPv6 support
 AC_IPV6
support/nfs/Makefile.am +2 -2
index e573b69..67e3a8e 100644
@@ -7,10 +7,10 @@ libnfs_la_SOURCES = exports.c rmtab.c xio.c rpcmisc.c rpcdispatch.c \
 		   xcommon.c wildmat.c mydaemon.c \
 		   rpc_socket.c getport.c \
 		   svc_socket.c cacheio.c closeall.c nfs_mntent.c \
-		   svc_create.c atomicio.c strlcat.c
+		   svc_create.c atomicio.c strlcat.c strlcpy.c
 libnfs_la_LIBADD = libnfsconf.la
 
-libnfsconf_la_SOURCES = conffile.c xlog.c strlcpy.c
+libnfsconf_la_SOURCES = conffile.c xlog.c
 
 MAINTAINERCLEANFILES = Makefile.in
 
support/nfs/conffile.c +5 -15
index dce8148..29f132d 100644
@@ -53,9 +53,11 @@
 #include "conffile.h"
 #include "xlog.h"
 
+#pragma GCC visibility push(hidden)
+
 static void conf_load_defaults(void);
 static char * conf_readfile(const char *path);
-int conf_set(int , const char *, const char *, const char *, 
+static int conf_set(int , const char *, const char *, const char *, 
 	const char *, int , int );
 static void conf_parse(int trans, char *buf, 
 	char **section, char **subsection);
@@ -77,10 +79,8 @@ TAILQ_HEAD (conf_trans_head, conf_trans) conf_trans_queue;
 /*
  * Radix-64 Encoding.
  */
-const uint8_t bin2asc[]
-  = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
 
-const uint8_t asc2bin[] =
+static const uint8_t asc2bin[] =
 {
   255, 255, 255, 255, 255, 255, 255, 255,
   255, 255, 255, 255, 255, 255, 255, 255,
@@ -489,10 +489,6 @@ static void conf_free_bindings(void)
 	}
 }
 
-#pragma GCC visibility push(hidden)
-/* these are the real fuinctions, hidden from being exported
- * by libnfsidmap ABI compatability */
-
 /* Open the config file and map it into our address space, then parse it.  */
 static void
 conf_load_file(const char *conf_file)
@@ -560,8 +556,6 @@ conf_cleanup(void)
 	TAILQ_INIT(&conf_trans_queue);
 }
 
-#pragma GCC visibility pop
-
 /*
  * Return the numeric value denoted by TAG in section SECTION or DEF
  * if that tag does not exist.
@@ -577,7 +571,6 @@ conf_get_num(const char *section, const char *tag, int def)
 	return def;
 }
 
-#pragma GCC visibility push(hidden)
 /*
  * Return the Boolean value denoted by TAG in section SECTION, or DEF
  * if that tags does not exist.
@@ -609,7 +602,6 @@ conf_get_bool(const char *section, const char *tag, _Bool def)
 		return false;
 	return def;
 }
-#pragma GCC visibility pop
 
 /* Validate X according to the range denoted by TAG in section SECTION.  */
 int
@@ -655,7 +647,6 @@ conf_get_str_with_def(const char *section, const char *tag, char *def)
 	return result;
 }
 
-#pragma GCC visibility push(hidden)
 /*
  * Find a section that may or may not have an argument
  */
@@ -687,7 +678,6 @@ retry:
 	}
 	return 0;
 }
-#pragma GCC visibility pop
 
 /*
  * Build a list of string values out of the comma separated value denoted by
@@ -882,7 +872,7 @@ conf_trans_node(int transaction, enum conf_op op)
 }
 
 /* Queue a set operation.  */
-int
+static int
 conf_set(int transaction, const char *section, const char *arg,
 	const char *tag, const char *value, int override, int is_default)
 {
support/nfsidmap/Makefile.am +7 -5
index 32eb8cf..9466f92 100644
@@ -25,26 +25,28 @@ pkgplugin_LTLIBRARIES = nsswitch.la static.la $(UMICH_LDAP_LIB) $(GUMS_MAPPING_L
 #  <age> 	The number of previous additional interfaces supported
 #  		by this library.
 
-libnfsidmap_la_SOURCES = libnfsidmap.c nfsidmap_internal.h
-libnfsidmap_la_LDFLAGS = -version-info 3:0:3
+libnfsidmap_la_SOURCES = libnfsidmap.c nfsidmap_internal.h nfsidmap_common.c
+libnfsidmap_la_LDFLAGS = -version-info 1:0:0
 libnfsidmap_la_LIBADD = -ldl ../../support/nfs/libnfsconf.la
 
-nsswitch_la_SOURCES = nss.c
+nsswitch_la_SOURCES = nss.c nfsidmap_common.c
 nsswitch_la_LDFLAGS = -module -avoid-version
+nsswitch_la_LIBADD = ../../support/nfs/libnfsconf.la
 
 static_la_SOURCES = static.c
 static_la_LDFLAGS = -module -avoid-version
+static_la_LIBADD = ../../support/nfs/libnfsconf.la
 
 umich_ldap_la_SOURCES = umich_ldap.c
 umich_ldap_la_LDFLAGS = -module -avoid-version
-umich_ldap_la_LIBADD = -lldap
+umich_ldap_la_LIBADD = -lldap ../../support/nfs/libnfsconf.la
 
 gums_la_SOURCES = gums.c
 gums_la_LDFLAGS = -module -avoid-version
 
 man3_MANS = nfs4_uid_to_name.3
 man5_MANS	= idmapd.conf.5
-include_HEADERS = nfsidmap.h
+include_HEADERS = nfsidmap.h nfsidmap_plugin.h
 
 EXTRA_DIST = $(man3_MANS) \
 	     $(man5_MANS) \
support/nfsidmap/gums.c +2 -3
index 2b12d95..1d6eb31 100644
@@ -42,8 +42,7 @@
 #include <err.h>
 #include <syslog.h>
 #include "nfsidmap.h"
-#include "nfsidmap_internal.h"
-#include "cfg.h"
+#include "nfsidmap_plugin.h"
 
 #include <voms_apic.h>
 
@@ -232,7 +231,7 @@ static int gums_init(void)
 	char buf[512], type[128], value[256];
 	char *alt_conf = NULL;
 
-	alt_conf = conf_get_str("GUMS", "Conf_File");
+	alt_conf = nfsidmap_config_get("GUMS", "Conf_File");
 	if (alt_conf == NULL)
 		f = fopen(prima_conf, "r");
 	else
support/nfsidmap/libnfsidmap.c +29 -38

120 lines not on this page · raw message

support/nfsidmap/nfsidmap_common.c new file +33 -0
new file mode 100644
index 0000000..891c855
@@ -0,0 +1,33 @@
+/*
+ *  nfsidmap_common.c
+ *
+ *  nfs idmapping library, primarily for nfs4 client/server kernel idmapping
+ *  and for userland nfs4 idmapping by acl libraries.
+ *
+ *  Code common to libnfsidmap and some of its bundled plugins
+ *
+ */
+
+#include "config.h"
+
+#include <sys/types.h>
+#include <unistd.h>
+#include <stdlib.h>
+
+#include "nfsidmap.h"
+#include "nfsidmap_private.h"
+#include "nfsidmap_plugin.h"
+#include "conffile.h"
+
+#pragma GCC visibility push(hidden)
+
+int reformat_group = 0;
+int no_strip = 0;
+
+struct conf_list *local_realms;
+
+struct conf_list *get_local_realms(void)
+{
+	return local_realms;
+}
+
support/nfsidmap/nfsidmap_internal.h deleted +0 -79

79 lines not on this page · raw message

support/nfsidmap/nfsidmap_plugin.h new file +68 -0

68 lines not on this page · raw message

support/nfsidmap/nfsidmap_private.h new file +55 -0

55 lines not on this page · raw message

support/nfsidmap/nss.c +11 -2
index a86d768..6f024dc 100644
@@ -47,10 +47,19 @@
 #include <limits.h>
 #include <ctype.h>
 #include "nfsidmap.h"
-#include "nfsidmap_internal.h"
-#include "conffile.h"
+#include "nfsidmap_plugin.h"
+#include "nfsidmap_private.h"
 #include <syslog.h>
 
+static char *get_default_domain(void)
+{
+	static char default_domain[NFS4_MAX_DOMAIN_LEN] = "";
+	if (default_domain[0] == 0) {
+		nfs4_get_default_domain(NULL, default_domain, NFS4_MAX_DOMAIN_LEN);
+	}
+	return default_domain;
+}
+
 /*
  * NSS Translation Methods
  *
support/nfsidmap/static.c +1 -1
index c82d7f3..0b1173f 100644
@@ -43,7 +43,7 @@
 
 #include "conffile.h"
 #include "nfsidmap.h"
-#include "nfsidmap_internal.h"
+#include "nfsidmap_plugin.h"
 
 /*
  * Static Translation Methods
support/nfsidmap/umich_ldap.c +2 -1
index 2258aa8..e82828c 100644
@@ -47,7 +47,8 @@
 #define LDAP_DEPRECATED 1
 #include <ldap.h>
 #include "nfsidmap.h"
-#include "nfsidmap_internal.h"
+#include "nfsidmap_plugin.h"
+#include "nfsidmap_private.h"
 #include "conffile.h"
 
 /* attribute/objectclass default mappings */
Signature · 1 line
1.8.3.1