Skip to contentSkip to conversation

Move nfs.conf to a shared library

PATCH In review Justin Mitchell 5 participants 13 messages Aug 30, 2017 – Sep 5, 2017

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

cover Move nfs.conf to a shared library

A series of small patches to nfs-utils and libnfsidmap in part to continue my work into making an API for accessing nfs.conf and its related config files, but also to address issues brought to light by my previous patches.

nfs-utils and libnfsidmap were using almost identical code to parse their config files, with identical function definitions, which was unmasked when the prototypes changed on one set.

A problem with spaces in config arguments was recently highlighted, this has already been fixed by my previous cleanups in nfs-utils but not in libnfsidmap where it was reported.

Moving the config parsing code out to a shared library fixes both of these issues with minimal code changes. I appreciate that the API this library presents is less than ideal, it was left this way to reduce code changes at this point, and i welcome suggestions for a sympathetic approach to improving it.

#1 lore raw

PATCH 1/7 nfs-utils: const-ify all the config handling functions

Following recent cleanup patches by others, constify all the function arguments that are appropriate.

---
 support/include/conffile.h | 22 +++++++++++-----------
 support/nfs/conffile.c     | 38 +++++++++++++++++++-------------------
 2 files changed, 30 insertions(+), 30 deletions(-)
support/include/conffile.h +11 -11
index 2d11a52..0e7fa8b 100644
@@ -49,21 +49,21 @@ struct conf_list {
 };
 
 extern int      conf_begin(void);
-extern int      conf_decode_base64(uint8_t *, uint32_t *, unsigned char *);
+extern int      conf_decode_base64(uint8_t *, uint32_t *, const unsigned char *);
 extern int      conf_end(int, int);
 extern void     conf_free_list(struct conf_list *);
-extern struct sockaddr *conf_get_address(char *, char *);
-extern struct conf_list *conf_get_list(char *, char *);
-extern struct conf_list *conf_get_tag_list(char *, char *);
-extern int      conf_get_num(char *, char *, int);
-extern _Bool    conf_get_bool(char *, char *, _Bool);
-extern char    *conf_get_str(char *, char *);
-extern char    *conf_get_section(char *, char *, char *);
+extern struct sockaddr *conf_get_address(const char *, const char *);
+extern struct conf_list *conf_get_list(const char *, const char *);
+extern struct conf_list *conf_get_tag_list(const char *, const char *);
+extern int      conf_get_num(const char *, const char *, int);
+extern _Bool    conf_get_bool(const char *, const char *, _Bool);
+extern char    *conf_get_str(const char *, const char *);
+extern char    *conf_get_section(const char *, const char *, const char *);
 extern void     conf_init(const char *);
 extern void     conf_cleanup(void);
-extern int      conf_match_num(char *, char *, int);
-extern int      conf_remove(int, char *, char *);
-extern int      conf_remove_section(int, char *);
+extern int      conf_match_num(const char *, const char *, int);
+extern int      conf_remove(int, const char *, const char *);
+extern int      conf_remove_section(int, const char *);
 extern void     conf_report(void);
 
 /*
support/nfs/conffile.c +19 -19
index 05e0a6f..527a63e 100644
@@ -57,8 +57,8 @@
 
 static void conf_load_defaults(void);
 static char * conf_load(const char *path);
-static int conf_set(int , char *, char *, char *, 
-	char *, int , int );
+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);
 
@@ -114,7 +114,7 @@ struct conf_binding {
 LIST_HEAD (conf_bindings, conf_binding) conf_bindings[256];
 
 static __inline__ uint8_t
-conf_hash(char *s)
+conf_hash(const char *s)
 {
 	uint8_t hash = 0;
 
@@ -129,7 +129,7 @@ conf_hash(char *s)
  * Insert a tag-value combination from LINE (the equal sign is at POS)
  */
 static int
-conf_remove_now(char *section, char *tag)
+conf_remove_now(const char *section, const char *tag)
 {
 	struct conf_binding *cb, *next;
 
@@ -152,7 +152,7 @@ conf_remove_now(char *section, char *tag)
 }
 
 static int
-conf_remove_section_now(char *section)
+conf_remove_section_now(const char *section)
 {
   struct conf_binding *cb, *next;
   int unseen = 1;
@@ -179,8 +179,8 @@ conf_remove_section_now(char *section)
  * into SECTION of our configuration database.
  */
 static int
-conf_set_now(char *section, char *arg, char *tag, 
-	char *value, int override, int is_default)
+conf_set_now(const char *section, const char *arg, const char *tag, 
+	const char *value, int override, int is_default)
 {
 	struct conf_binding *node = 0;
 
@@ -563,7 +563,7 @@ conf_cleanup(void)
  * if that tag does not exist.
  */
 int
-conf_get_num(char *section, char *tag, int def)
+conf_get_num(const char *section, const char *tag, int def)
 {
 	char *value = conf_get_str(section, tag);
 
@@ -581,7 +581,7 @@ conf_get_num(char *section, char *tag, int def)
  * A failure to match one of these results in DEF
  */
 _Bool
-conf_get_bool(char *section, char *tag, _Bool def)
+conf_get_bool(const char *section, const char *tag, _Bool def)
 {
 	char *value = conf_get_str(section, tag);
 
@@ -607,7 +607,7 @@ conf_get_bool(char *section, char *tag, _Bool def)
 
 /* Validate X according to the range denoted by TAG in section SECTION.  */
 int
-conf_match_num(char *section, char *tag, int x)
+conf_match_num(const char *section, const char *tag, int x)
 {
 	char *value = conf_get_str (section, tag);
 	int val, min, max, n;
@@ -632,7 +632,7 @@ conf_match_num(char *section, char *tag, int x)
 
 /* Return the string value denoted by TAG in section SECTION.  */
 char *
-conf_get_str(char *section, char *tag)
+conf_get_str(const char *section, const char *tag)
 {
 	struct conf_binding *cb;
 retry:
@@ -660,7 +660,7 @@ retry:
  * Find a section that may or may not have an argument
  */
 char *
-conf_get_section(char *section, char *arg, char *tag)
+conf_get_section(const char *section, const char *arg, const char *tag)
 {
 	struct conf_binding *cb;
 
@@ -682,7 +682,7 @@ conf_get_section(char *section, char *arg, char *tag)
  * TAG in SECTION.
  */
 struct conf_list *
-conf_get_list(char *section, char *tag)
+conf_get_list(const char *section, const char *tag)
 {
 	char *liststr = 0, *p, *field, *t;
 	struct conf_list *list = 0;
@@ -736,7 +736,7 @@ cleanup:
 }
 
 struct conf_list *
-conf_get_tag_list(char *section, char *arg)
+conf_get_tag_list(const char *section, const char *arg)
 {
 	struct conf_list *list = 0;
 	struct conf_list_node *node;
@@ -774,7 +774,7 @@ cleanup:
 
 /* Decode a PEM encoded buffer.  */
 int
-conf_decode_base64 (uint8_t *out, uint32_t *len, unsigned char *buf)
+conf_decode_base64 (uint8_t *out, uint32_t *len, const unsigned char *buf)
 {
 	uint32_t c = 0;
 	uint8_t c1, c2, c3, c4;
@@ -871,8 +871,8 @@ conf_trans_node(int transaction, enum conf_op op)
 
 /* Queue a set operation.  */
 static int
-conf_set(int transaction, char *section, char *arg,
-	char *tag, char *value, int override, int is_default)
+conf_set(int transaction, const char *section, const char *arg,
+	const char *tag, const char *value, int override, int is_default)
 {
 	struct conf_trans *node;
 
@@ -924,7 +924,7 @@ fail:
 
 /* Queue a remove operation.  */
 int
-conf_remove(int transaction, char *section, char *tag)
+conf_remove(int transaction, const char *section, const char *tag)
 {
 	struct conf_trans *node;
 
@@ -953,7 +953,7 @@ fail:
 
 /* Queue a remove section operation.  */
 int
-conf_remove_section(int transaction, char *section)
+conf_remove_section(int transaction, const char *section)
 {
 	struct conf_trans *node;
 
Signature · 1 line
1.8.3.1
#2 lore raw

PATCH 2/7 nfs-utils: Merge conf_get_str and conf_get_section

In reply to Justin Mitchell

conf_get_section() started as conf_get_str() with one extra search parameter, subsequent patches have not maintained feature parity, combine the code to make a single more generic function and just call that differently where required.

---
 support/nfs/conffile.c | 36 ++++++++++++++----------------------
 1 file changed, 14 insertions(+), 22 deletions(-)
support/nfs/conffile.c +14 -22
index 527a63e..d8c4374 100644
@@ -634,28 +634,9 @@ conf_match_num(const char *section, const char *tag, int x)
 char *
 conf_get_str(const char *section, const char *tag)
 {
-	struct conf_binding *cb;
-retry:
-	cb = LIST_FIRST (&conf_bindings[conf_hash (section)]);
-	for (; cb; cb = LIST_NEXT (cb, link)) {
-		if (strcasecmp (section, cb->section) == 0
-		    && strcasecmp (tag, cb->tag) == 0) {
-			if (cb->value[0] == '$') {
-				/* expand $name from [environment] section,
-				 * or from environment
-				 */
-				char *env = getenv(cb->value+1);
-				if (env && *env)
-					return env;
-				section = "environment";
-				tag = cb->value + 1;
-				goto retry;
-			}
-			return cb->value;
-		}
-	}
-	return 0;
+	return conf_get_section(section, NULL, tag);
 }
+
 /*
  * Find a section that may or may not have an argument
  */
@@ -663,7 +644,7 @@ char *
 conf_get_section(const char *section, const char *arg, const char *tag)
 {
 	struct conf_binding *cb;
-
+retry:
 	cb = LIST_FIRST (&conf_bindings[conf_hash (section)]);
 	for (; cb; cb = LIST_NEXT (cb, link)) {
 		if (strcasecmp(section, cb->section) != 0)
@@ -672,6 +653,17 @@ conf_get_section(const char *section, const char *arg, const char *tag)
 			continue;
 		if (strcasecmp(tag, cb->tag) != 0)
 			continue;
+		if (cb->value[0] == '$') {
+			/* expand $name from [environment] section,
+			 * or from environment
+			 */
+			char *env = getenv(cb->value+1);
+			if (env && *env)
+				return env;
+			section = "environment";
+			tag = cb->value + 1;
+			goto retry;
+		}
 		return cb->value;
 	}
 	return 0;
Signature · 1 line
1.8.3.1
#3 lore raw

PATCH 3/7 nfs-utils: Move nfs.conf handling into a shared lib

In reply to Justin Mitchell

Move the config handling code that is common to all nfs-utils and make it a shared library so that other projects like libnfsidmap can also use it. No attempt is made to improve the API at this point so as to minimize the change size.

---
 support/include/Makefile.am   | 5 ++++-
 support/nfs/Makefile.am       | 8 +++++++-
 support/nfs/conffile.c        | 4 +---
 utils/blkmapd/Makefile.am     | 3 ++-
 utils/exportfs/Makefile.am    | 1 +
 utils/gssd/Makefile.am        | 2 ++
 utils/mount/Makefile.am       | 1 +
 utils/mountd/Makefile.am      | 1 +
 utils/nfsd/Makefile.am        | 3 ++-
 utils/nfsdcltrack/Makefile.am | 3 ++-
 utils/statd/Makefile.am       | 2 ++
 11 files changed, 25 insertions(+), 8 deletions(-)
support/include/Makefile.am +4 -1
index 5c80c8b..c46a340 100644
@@ -21,7 +21,10 @@ noinst_HEADERS = \
 	xio.h \
 	xlog.h \
 	xmalloc.h \
-	xcommon.h \
+	xcommon.h
+
+include_HEADERS = \
 	conffile.h
 
+
 MAINTAINERCLEANFILES = Makefile.in
support/nfs/Makefile.am +7 -1
index b74c870..e06ebd6 100644
@@ -4,8 +4,14 @@ noinst_LIBRARIES = libnfs.a
 libnfs_a_SOURCES = exports.c rmtab.c xio.c rpcmisc.c rpcdispatch.c \
 		   xlog.c xcommon.c wildmat.c mydaemon.c \
 		   rpc_socket.c getport.c \
-		   svc_socket.c cacheio.c closeall.c nfs_mntent.c conffile.c \
+		   svc_socket.c cacheio.c closeall.c nfs_mntent.c \
 		   svc_create.c atomicio.c strlcpy.c strlcat.c
+libnfs_a_CFLAGS = -fPIC
+
+lib_LTLIBRARIES = libnfsconf.la
+libnfsconf_la_SOURCES = conffile.c
+libnfsconf_la_LIBADD = libnfs.a
+
 
 MAINTAINERCLEANFILES = Makefile.in
 
support/nfs/conffile.c +1 -3
index d8c4374..9c0fad9 100644
@@ -53,8 +53,6 @@
 #include "conffile.h"
 #include "xlog.h"
 
-#pragma GCC visibility push(hidden)
-
 static void conf_load_defaults(void);
 static char * conf_load(const char *path);
 static int conf_set(int , const char *, const char *, const char *, 
@@ -74,7 +72,7 @@ struct conf_trans {
 	int is_default;
 };
 
-TAILQ_HEAD (conf_trans_head, conf_trans) conf_trans_queue;
+static TAILQ_HEAD (conf_trans_head, conf_trans) conf_trans_queue;
 
 /*
  * Radix-64 Encoding.
utils/blkmapd/Makefile.am +2 -1
index 203f9f2..c04fb2e 100644
@@ -13,7 +13,8 @@ blkmapd_SOURCES = \
 	dm-device.c \
 	device-discovery.h
 
-blkmapd_LDADD = -ldevmapper ../../support/nfs/libnfs.a
+blkmapd_LDADD = -ldevmapper ../../support/nfs/libnfs.a \
+	        -L../../support/nfs/ -lnfsconf
 
 MAINTAINERCLEANFILES = Makefile.in
 
utils/exportfs/Makefile.am +1 -0
index d0226fc..09e5229 100644
@@ -10,6 +10,7 @@ exportfs_SOURCES = exportfs.c
 exportfs_LDADD = ../../support/export/libexport.a \
 	       	 ../../support/nfs/libnfs.a \
 		 ../../support/misc/libmisc.a \
+		 -L../../support/nfs/ -lnfsconf \
 		 $(LIBWRAP) $(LIBNSL)
 
 MAINTAINERCLEANFILES = Makefile.in
utils/gssd/Makefile.am +2 -0
index 3f5f59a..b3b8234 100644
@@ -45,6 +45,7 @@ gssd_SOURCES = \
 
 gssd_LDADD = \
 	../../support/nfs/libnfs.a \
+	-L../../support/nfs/ -lnfsconf \
 	$(LIBEVENT) \
 	$(RPCSECGSS_LIBS) \
 	$(KRBLIBS) \
@@ -75,6 +76,7 @@ svcgssd_SOURCES = \
 
 svcgssd_LDADD = \
 	../../support/nfs/libnfs.a \
+	-L../../support/nfs/ -lnfsconf \
 	$(RPCSECGSS_LIBS) $(LIBNFSIDMAP) \
 	$(KRBLIBS) $(GSSAPI_LIBS) $(LIBTIRPC)
 
utils/mount/Makefile.am +1 -0
index e24f3bd..0d8ef08 100644
@@ -27,6 +27,7 @@ endif
 
 mount_nfs_LDADD = ../../support/nfs/libnfs.a \
 		  ../../support/export/libexport.a \
+	          -L../../support/nfs/ -lnfsconf \
 		  $(LIBTIRPC)
 
 mount_nfs_SOURCES = $(mount_common)
utils/mountd/Makefile.am +1 -0
index 9e1ab5c..4e822d0 100644
@@ -13,6 +13,7 @@ mountd_SOURCES = mountd.c mount_dispatch.c auth.c rmtab.c cache.c \
 mountd_LDADD = ../../support/export/libexport.a \
 	       ../../support/nfs/libnfs.a \
 	       ../../support/misc/libmisc.a \
+	       -L../../support/nfs/ -lnfsconf \
 	       $(LIBBSD) $(LIBWRAP) $(LIBNSL) $(LIBBLKID) $(LIBDL) $(LIBTIRPC)
 mountd_CPPFLAGS = $(AM_CPPFLAGS) $(CPPFLAGS) \
 		  -I$(top_builddir)/support/include \
utils/nfsd/Makefile.am +2 -1
index 39a6e6f..9908f1b 100644
@@ -9,7 +9,8 @@ sbin_PROGRAMS	= nfsd
 
 noinst_HEADERS = nfssvc.h
 nfsd_SOURCES = nfsd.c nfssvc.c
-nfsd_LDADD = ../../support/nfs/libnfs.a $(LIBTIRPC)
+nfsd_LDADD = ../../support/nfs/libnfs.a $(LIBTIRPC) \
+	     -L../../support/nfs/ -lnfsconf
 
 MAINTAINERCLEANFILES = Makefile.in
 
utils/nfsdcltrack/Makefile.am +2 -1
index 0a2858f..91d45c8 100644
@@ -13,7 +13,8 @@ sbin_PROGRAMS	= nfsdcltrack
 noinst_HEADERS	= sqlite.h
 
 nfsdcltrack_SOURCES = nfsdcltrack.c sqlite.c
-nfsdcltrack_LDADD = ../../support/nfs/libnfs.a $(LIBSQLITE) $(LIBCAP)
+nfsdcltrack_LDADD = ../../support/nfs/libnfs.a $(LIBSQLITE) $(LIBCAP) \
+	            -L../../support/nfs/ -lnfsconf
 
 MAINTAINERCLEANFILES = Makefile.in
 
utils/statd/Makefile.am +2 -0
index ea32075..ccaf3a6 100644
@@ -15,10 +15,12 @@ BUILT_SOURCES = $(GENFILES)
 statd_LDADD = ../../support/nsm/libnsm.a \
 	      ../../support/nfs/libnfs.a \
 	      ../../support/misc/libmisc.a \
+	      -L../../support/nfs/ -lnfsconf \
 	      $(LIBWRAP) $(LIBNSL) $(LIBCAP) $(LIBTIRPC)
 sm_notify_LDADD = ../../support/nsm/libnsm.a \
 		  ../../support/nfs/libnfs.a \
 	          ../../support/misc/libmisc.a \
+	          -L../../support/nfs/ -lnfsconf \
 		  $(LIBNSL) $(LIBCAP) $(LIBTIRPC)
 
 EXTRA_DIST = sim_sm_inter.x $(man8_MANS) simulate.c
Signature · 1 line
1.8.3.1
#4 lore raw

PATCH 4/7 nfs-utils: Add get_str with default value

In reply to Justin Mitchell

The similar config code in libnfsidmap had one additional feature of a get_str function with a default value option, include an equivalent function here to maintain compatibility.

---
 support/include/conffile.h |  1 +
 support/nfs/conffile.c     | 11 +++++++++++
 2 files changed, 12 insertions(+)
support/include/conffile.h +1 -0
index 0e7fa8b..d4cb6b4 100644
@@ -58,6 +58,7 @@ extern struct conf_list *conf_get_tag_list(const char *, const char *);
 extern int      conf_get_num(const char *, const char *, int);
 extern _Bool    conf_get_bool(const char *, const char *, _Bool);
 extern char    *conf_get_str(const char *, const char *);
+extern char    *conf_get_str_with_def(const char *, const char *, char *);
 extern char    *conf_get_section(const char *, const char *, const char *);
 extern void     conf_init(const char *);
 extern void     conf_cleanup(void);
support/nfs/conffile.c +11 -0
index 9c0fad9..c97f82a 100644
@@ -635,6 +635,17 @@ conf_get_str(const char *section, const char *tag)
 	return conf_get_section(section, NULL, tag);
 }
 
+/* Return the string value denoted by TAG in section SECTION,
+ * unless it is not set, in which case return def
+ */
+char *
+conf_get_str_with_def(const char *section, const char *tag, char *def)
+{
+	char * result = conf_get_section(section, NULL, tag);
+	if (!result) return def;
+	return result;
+}
+
 /*
  * Find a section that may or may not have an argument
  */
Signature · 1 line
1.8.3.1
#5 lore raw

PATCH 5/7 nfs-utils: Add pkgconf data for libnfsconf

In reply to Justin Mitchell

Generate pkgconf files for the nfsconf shared library

---
 Makefile.am      |  5 +++++
 configure.ac     |  1 +
 libnfsconf.pc.in | 11 +++++++++++
 3 files changed, 17 insertions(+)
 create mode 100644 libnfsconf.pc.in
Makefile.am +5 -0
index e1f39aa..a3109d9 100644
@@ -35,3 +35,8 @@ uninstall-hook:
 	rm $(DESTDIR)$(statedir)/etab
 	rm $(DESTDIR)$(statedir)/rmtab
 	rm $(DESTDIR)$(statdpath)/state
+
+pkgconfigdir=$(libdir)/pkgconfig
+pkgconfig_DATA=libnfsconf.pc
+
+$(pkgconfig_DATA): $(top_builddir)/config.status
configure.ac +1 -0
index 1ca1603..0b2e8fc 100644
@@ -525,6 +525,7 @@ AC_CONFIG_COMMANDS_PRE([eval eval _sysconfdir=$sysconfdir])
 
 AC_CONFIG_FILES([
 	Makefile
+	libnfsconf.pc
 	systemd/rpc-gssd.service
 	linux-nfs/Makefile
 	support/Makefile
libnfsconf.pc.in new file +11 -0
new file mode 100644
index 0000000..f134e32
@@ -0,0 +1,11 @@
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+
+Name: libnfsconf
+Description: Library that parses nfs.conf and related config files.
+Requires:
+Version: @PACKAGE_VERSION@
+Libs: -L@libdir@ -lnfsconf
+Cflags: -I@includedir@
Signature · 1 line
1.8.3.1
#6 lore raw

PATCH 6/7 libnfsidmap: Use libnfsconf instead of builtin cfg

In reply to Justin Mitchell

libnfsidmap contained almost identical config parsing code to that in nfs-utils which caused issues when that code got updated, it also suffered from issues with parsing spaces in tag names which has been fixed in nfs-utils, so solve both issues by removing the local config parsing code and linking to the nfsconf shared library instead.

---
 Makefile.am   |  11 +-
 cfg.c         | 913 ----------------------------------------------------------
 cfg.h         |  68 -----
 configure.ac  |   3 +
 gums.c        |   2 +-
 libnfsidmap.c |   5 +-
 nss.c         |   2 +-
 queue.h       | 499 --------------------------------
 static.c      |   5 +-
 umich_ldap.c  |   2 +-
 10 files changed, 18 insertions(+), 1492 deletions(-)
 delete mode 100644 cfg.c
 delete mode 100644 cfg.h
 delete mode 100644 queue.h
Makefile.am +7 -4
index 85f19c8..ffb6717 100644
@@ -25,15 +25,18 @@ pkglib_LTLIBRARIES = nsswitch.la static.la $(UMICH_LDAP_LIB) $(GUMS_MAPPING_LIB)
 #  <age> 	The number of previous additional interfaces supported
 #  		by this library.
 
-libnfsidmap_la_SOURCES = libnfsidmap.c cfg.c strlcpy.c cfg.h nfsidmap_internal.h queue.h
+libnfsidmap_la_SOURCES = libnfsidmap.c strlcpy.c nfsidmap_internal.h queue.h
 libnfsidmap_la_LDFLAGS = -version-info 3:0:3
-libnfsidmap_la_LIBADD = -ldl
+libnfsidmap_la_LIBADD = -ldl $(NFSCONF_LIBS)
+libnfsidmap_la_CPPFLAGS = $(NFSCONF_CFLAGS)
 
 nsswitch_la_SOURCES = nss.c
-nsswitch_la_LDFLAGS = -module -avoid-version
+nsswitch_la_LDFLAGS = -module -avoid-version $(NFSCONF_LIBS)
+nsswitch_la_CPPFLAGS = $(NFSCONF_CFLAGS)
 
 static_la_SOURCES = static.c
-static_la_LDFLAGS = -module -avoid-version
+static_la_LDFLAGS = -module -avoid-version $(NFSCONF_LIBS)
+static_la_CPPFLAGS = $(NFSCONF_CFLAGS)
 
 umich_ldap_la_SOURCES = umich_ldap.c
 umich_ldap_la_LDFLAGS = -module -avoid-version
cfg.c deleted +0 -913

913 lines not on this page · raw message

cfg.h deleted +0 -68

68 lines not on this page · raw message

configure.ac +3 -0
index dd1b365..35445bc 100644
@@ -52,6 +52,9 @@ if test -n "$path_plugins" ; then
 fi
 AM_CONDITIONAL(PATH_PLUGINS, test -n "$path_plugins")
 
+# where is nfsconf library
+PKG_CHECK_MODULES(NFSCONF, libnfsconf)
+
 AC_CONFIG_HEADERS([./config.h])
 # Checks for header files.
 AC_HEADER_STDC
gums.c +1 -1
index 2b12d95..5c16dd0 100644
@@ -43,7 +43,7 @@
 #include <syslog.h>
 #include "nfsidmap.h"
 #include "nfsidmap_internal.h"
-#include "cfg.h"
+#include <conffile.h>
 
 #include <voms_apic.h>
 
libnfsidmap.c +3 -2
index d484101..afe84ef 100644
@@ -59,7 +59,7 @@
 
 #include "nfsidmap.h"
 #include "nfsidmap_internal.h"
-#include "cfg.h"
+#include <conffile.h>
 
 static char *default_domain;
 static struct conf_list *local_realms;
@@ -340,6 +340,7 @@ int nfs4_init_name_mapping(char *conffile)
 	char *nobody_user, *nobody_group;
 	char *nostrip;
 	char *reformatgroup;
+	char *conf_path;
 
 	/* XXX: need to be able to reload configurations... */
 	if (nfs4_plugins) /* already succesfully initialized */
@@ -348,7 +349,7 @@ int nfs4_init_name_mapping(char *conffile)
 		conf_path = conffile;
 	else
 		conf_path = PATH_IDMAPDCONF;
-	conf_init();
+	conf_init(conf_path);
 	default_domain = conf_get_str("General", "Domain");
 	if (default_domain == NULL) {
 		dflt = 1;
nss.c +1 -1
index 82799ce..6c090bc 100644
@@ -48,7 +48,7 @@
 #include <ctype.h>
 #include "nfsidmap.h"
 #include "nfsidmap_internal.h"
-#include "cfg.h"
+#include <conffile.h>
 #include <syslog.h>
 
 /*
queue.h deleted +0 -499

499 lines not on this page · raw message

static.c +2 -3
index 9f587af..ff4179b 100644
@@ -41,8 +41,7 @@
 #include <errno.h>
 #include <err.h>
 
-#include "queue.h"
-#include "cfg.h"
+#include <conffile.h>
 #include "nfsidmap.h"
 #include "nfsidmap_internal.h"
 
@@ -317,7 +316,7 @@ static int static_init() {
 		LIST_INIT (&uid_mappings[i]);
 
 	//get all principals for which we have mappings
-	princ_list = conf_get_tag_list("Static");
+	princ_list = conf_get_tag_list("Static", NULL);
 
 	if (!princ_list) {
 		return -ENOENT;
umich_ldap.c +1 -1
index 886fa0c..6e01cc3 100644
@@ -48,7 +48,7 @@
 #include <ldap.h>
 #include "nfsidmap.h"
 #include "nfsidmap_internal.h"
-#include "cfg.h"
+#include <conffile.h>
 
 /* attribute/objectclass default mappings */
 #define DEFAULT_UMICH_OBJCLASS_REMOTE_PERSON	"NFSv4RemotePerson"
Signature · 1 line
1.8.3.1
#7 lore raw

PATCH 7/7 libnfsidmap: use conf_get_bool()

In reply to Justin Mitchell

We can improve code readability by using conf_get_bool() from libnfsconf instead of comparing the string values ourselves

---
 libnfsidmap.c |  6 +-----
 umich_ldap.c  | 21 ++++++---------------
 2 files changed, 7 insertions(+), 20 deletions(-)
libnfsidmap.c +1 -5
index afe84ef..bacb0e3 100644
@@ -339,7 +339,6 @@ int nfs4_init_name_mapping(char *conffile)
 	struct conf_list *nfs4_methods, *gss_methods;
 	char *nobody_user, *nobody_group;
 	char *nostrip;
-	char *reformatgroup;
 	char *conf_path;
 
 	/* XXX: need to be able to reload configurations... */
@@ -424,10 +423,7 @@ int nfs4_init_name_mapping(char *conffile)
 		no_strip = 0;
 
 	if (no_strip & IDTYPE_GROUP) {
-		reformatgroup = conf_get_str_with_def("General", "Reformat-Group", "false");
-		if ((strcasecmp(reformatgroup, "true") == 0) ||
-		    (strcasecmp(reformatgroup, "on") == 0) ||
-		    (strcasecmp(reformatgroup, "yes") == 0))
+		if (conf_get_bool("General", "Reformat-Group", false))
 			reformat_group = 1;
 		else
 			reformat_group = 0;
umich_ldap.c +6 -15
index 6e01cc3..6ddce32 100644
@@ -1095,9 +1095,9 @@ out_err:
 static int
 umichldap_init(void)
 {
-	char *tssl, *canonicalize, *memberof;
 	char missing_msg[128] = "";
 	char *server_in, *canon_name;
+	bool canonicalize = false;
 
 	server_in = conf_get_str(LDAP_SECTION, "LDAP_server");
 	ldap_info.base = conf_get_str(LDAP_SECTION, "LDAP_base");
@@ -1105,10 +1105,7 @@ umichldap_init(void)
 	ldap_info.group_tree = conf_get_str(LDAP_SECTION, "LDAP_group_base");
 	ldap_info.user_dn = conf_get_str(LDAP_SECTION, "LDAP_user_dn");
 	ldap_info.passwd = conf_get_str(LDAP_SECTION, "LDAP_passwd");
-	tssl = conf_get_str_with_def(LDAP_SECTION, "LDAP_use_ssl", "false");
-	if ((strcasecmp(tssl, "true") == 0) ||
-	    (strcasecmp(tssl, "on") == 0) ||
-	    (strcasecmp(tssl, "yes") == 0))
+	if (conf_get_bool(LDAP_SECTION, "LDAP_use_ssl", false))
 		ldap_info.use_ssl = 1;
 	else
 		ldap_info.use_ssl = 0;
@@ -1130,10 +1127,8 @@ umichldap_init(void)
 	}
 
 	ldap_info.server = server_in;
-	canonicalize = conf_get_str_with_def(LDAP_SECTION, "LDAP_canonicalize_name", "yes");
-	if ((strcasecmp(canonicalize, "true") == 0) ||
-	    (strcasecmp(canonicalize, "on") == 0) ||
-	    (strcasecmp(canonicalize, "yes") == 0)) {
+	if (conf_get_bool(LDAP_SECTION, "LDAP_canonicalize_name", true)) {
+		canonicalize = true;
 		canon_name = get_canonical_hostname(server_in);
 		if (canon_name == NULL)
 			IDMAP_LOG(0, ("umichldap_init: Warning! Unable to "
@@ -1202,11 +1197,7 @@ umichldap_init(void)
 	 * will use the memberof lists of the account and search through
 	 * only those groups to obtain gids.
 	 */
-	memberof = conf_get_str_with_def(LDAP_SECTION,
-				"LDAP_use_memberof_for_groups", "false");
-        if ((strcasecmp(memberof, "true") == 0) ||
-            (strcasecmp(memberof, "on") == 0) ||
-            (strcasecmp(memberof, "yes") == 0))
+	if (conf_get_bool(LDAP_SECTION, "LDAP_use_memberof_for_groups", false))
                 ldap_info.memberof_for_groups = 1;
         else
                 ldap_info.memberof_for_groups = 0;
@@ -1233,7 +1224,7 @@ umichldap_init(void)
 
 	/* print out some good debugging info */
 	IDMAP_LOG(1, ("umichldap_init: canonicalize_name: %s",
-		  canonicalize));
+		  canonicalize ? "yes" : "no"));
 	IDMAP_LOG(1, ("umichldap_init: server  : %s (from config value '%s')",
 		  ldap_info.server, server_in));
 	IDMAP_LOG(1, ("umichldap_init: port    : %d", ldap_info.port));
Signature · 1 line
1.8.3.1
#8 lore raw
In reply to Justin Mitchell
Quoted 5 lines · Justin Mitchell

Moving the config parsing code out to a shared library fixes both of these issues with minimal code changes. I appreciate that the API this library presents is less than ideal, it was left this way to reduce code changes at this point, and i welcome suggestions for a sympathetic approach to improving it.

The general shard code approach look good, but is there any good reason not to merge libnfsidmap into nfs-utils and make it a static (or at least a private shared) library instead of introducing a new ABI?

#9 lore raw
Quoted 10 lines · Christoph Hellwig
Quoted 5 lines · Justin Mitchell

Moving the config parsing code out to a shared library fixes both of these issues with minimal code changes. I appreciate that the API this library presents is less than ideal, it was left this way to reduce code changes at this point, and i welcome suggestions for a sympathetic approach to improving it.

Quoted 4 lines

The general shard code approach look good, but is there any good reason not to merge libnfsidmap into nfs-utils and make it a static (or at least a private shared) library instead of introducing a new ABI?

Agreed: who else is using libnfsidmap? Is there currently a packaging requirement that keeps it outside of nfs-utils?

--
Chuck Lever

#10 lore raw
Quoted 10 lines · Chuck Lever
Quoted 10 lines · Christoph Hellwig
Quoted 5 lines · Justin Mitchell

Moving the config parsing code out to a shared library fixes both of these issues with minimal code changes. I appreciate that the API this library presents is less than ideal, it was left this way to reduce code changes at this point, and i welcome suggestions for a sympathetic approach to improving it.

Quoted 7 lines
Quoted 4 lines

The general shard code approach look good, but is there any good reason not to merge libnfsidmap into nfs-utils and make it a static (or at least a private shared) library instead of introducing a new ABI?

Agreed: who else is using libnfsidmap? Is there currently a packaging requirement that keeps it outside of nfs-utils?

I hope not... and I agree... lets use this effort to roll libnfsidmap into nfs-utils as static library.

The pain is more of a logistics issue for distro... IMHO...

steved.

#11 lore raw
Quoted 19 lines · Steve Dickson
Quoted 17 lines · Chuck Lever
Quoted 16 lines

On Aug 30, 2017, at 8:15 AM, Christoph Hellwig <[email protected]

Quoted 1 line

wrote:

Quoted 5 lines · Justin Mitchell

Moving the config parsing code out to a shared library fixes both of these issues with minimal code changes. I appreciate that the API this library presents is less than ideal, it was left this way to reduce code changes at this point, and i welcome suggestions for a sympathetic approach to improving it.

The general shard code approach look good, but is there any good reason not to merge libnfsidmap into nfs-utils and make it a static (or at least a private shared) library instead of introducing
a new ABI?

Quoted 7 lines
Quoted 2 lines

Agreed: who else is using libnfsidmap? Is there currently a packaging requirement that keeps it outside of nfs-utils?

I hope not... and I agree... lets use this effort to roll libnfsidmap into nfs-utils as static library.

The pain is more of a logistics issue for distro... IMHO...

afaics the three things that depend on libnfsidmap are nfs-ganesha, freeipa-client, and sssd-nfs-idmap. the first two pull in nfs-utils anyway, the latter would gain a few extra dependencies from pulling in nfs-utils instead of just libnfsidmap.

Although that is somewhat academic as a merged tree could still be packaged out as separate items, just as it is now, but internally can share the code.

So I will look at doing that instead.

--
Justin Mitchell

#12 lore raw
Quoted 33 lines · Justin Mitchell
Quoted 19 lines · Steve Dickson
Quoted 17 lines · Chuck Lever
Quoted 16 lines

On Aug 30, 2017, at 8:15 AM, Christoph Hellwig <[email protected]

Quoted 1 line

wrote:

Quoted 5 lines · Justin Mitchell

Moving the config parsing code out to a shared library fixes both of these issues with minimal code changes. I appreciate that the API this library presents is less than ideal, it was left this way to reduce code changes at this point, and i welcome suggestions for a sympathetic approach to improving it.

The general shard code approach look good, but is there any good reason not to merge libnfsidmap into nfs-utils and make it a static (or at least a private shared) library instead of introducing
a new ABI?

Quoted 7 lines
Quoted 2 lines

Agreed: who else is using libnfsidmap? Is there currently a packaging requirement that keeps it outside of nfs-utils?

I hope not... and I agree... lets use this effort to roll libnfsidmap into nfs-utils as static library.

The pain is more of a logistics issue for distro... IMHO...

afaics the three things that depend on libnfsidmap are nfs-ganesha, freeipa-client, and sssd-nfs-idmap. the first two pull in nfs-utils anyway, the latter would gain a few extra dependencies from pulling in nfs-utils instead of just libnfsidmap.

Quoted 5 lines

Although that is somewhat academic as a merged tree could still be packaged out as separate items, just as it is now, but internally can share the code.

So I will look at doing that instead.

Originally we tried to make it possible to manipulate NFSv4 ACLs using setfacl/getfacl, by patching in NFSv4<->POSIX ACL mapping into libacl. That added a libacl->libnfsidmap dependency. I think that was the only original motivation. And, yeah, that's not necessarily an argument for building it from a separate source tree. I think it was just a mistake. I'm fine with merging it into nfs-utils.

--b.