All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/4] keyutils: fix compilation error with C++
@ 2020-07-02  8:57 Christophe Vu-Brugier
  2020-07-02  8:57 ` [PATCH 1/4] man: fix typos Christophe Vu-Brugier
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Christophe Vu-Brugier @ 2020-07-02  8:57 UTC (permalink / raw)
  To: keyrings

These patches are for the userspace keyutils program and library.

While working on a C++ program that could take advantage of the
keyutils library, I observed that the compilation fails because the
"keyutils.h" header file contains a parameter named "private" which is
a C++ reserved keyword.

* Patch #1 fixes a few typos in the man pages.
* Patch #2 fixes the aforementioned issue.
* Patch #3 helps prevent a similar issue from happening in the future.
* Patch #4 fixes an issue reported by C++ compilers at link time.

With best regards,

Christophe Vu-Brugier (4):
  man: fix typos
  Fix compilation error when keyutils.h is used in C++
  Check that keyutils.h has valid C++ syntax at build time
  Fix error when a C++ program is linked with libkeyutils

 Makefile                  | 16 +++++++++++++++-
 keyutils.c                |  4 ++--
 keyutils.h                | 10 +++++++++-
 man/keyctl.3              |  4 ++--
 man/keyctl_capabilities.3 |  2 +-
 man/keyctl_chown.3        |  2 +-
 man/keyctl_clear.3        |  3 +--
 man/keyctl_link.3         |  3 +--
 man/keyctl_move.3         |  3 +--
 man/keyctl_read.3         |  3 +--
 man/keyctl_revoke.3       |  2 +-
 man/keyctl_set_timeout.3  |  2 +-
 man/keyctl_setperm.3      |  2 +-
 man/keyctl_update.3       |  2 +-
 14 files changed, 38 insertions(+), 20 deletions(-)

-- 
2.27.0

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/4] man: fix typos
  2020-07-02  8:57 [PATCH 0/4] keyutils: fix compilation error with C++ Christophe Vu-Brugier
@ 2020-07-02  8:57 ` Christophe Vu-Brugier
  2020-07-02  8:57 ` [PATCH 2/4] Fix compilation error when keyutils.h is used in C++ Christophe Vu-Brugier
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Christophe Vu-Brugier @ 2020-07-02  8:57 UTC (permalink / raw)
  To: keyrings; +Cc: David Howells, Stephan Müller, Christophe Vu-Brugier

Signed-off-by: Christophe Vu-Brugier <cvubrugier@fastmail.fm>
---
 man/keyctl.3              | 4 ++--
 man/keyctl_capabilities.3 | 2 +-
 man/keyctl_chown.3        | 2 +-
 man/keyctl_clear.3        | 3 +--
 man/keyctl_link.3         | 3 +--
 man/keyctl_move.3         | 3 +--
 man/keyctl_read.3         | 3 +--
 man/keyctl_revoke.3       | 2 +-
 man/keyctl_set_timeout.3  | 2 +-
 man/keyctl_setperm.3      | 2 +-
 man/keyctl_update.3       | 2 +-
 11 files changed, 12 insertions(+), 16 deletions(-)

diff --git a/man/keyctl.3 b/man/keyctl.3
index b0f5fdc..cb0449c 100644
--- a/man/keyctl.3
+++ b/man/keyctl.3
@@ -71,9 +71,9 @@ and then telling the linker it should link in the library:
 .br
 .BR keyctl_negate (3)
 .br
-.BR keyctl_pkey_dec (3)
+.BR keyctl_pkey_decrypt (3)
 .br
-.BR keyctl_pkey_enc (3)
+.BR keyctl_pkey_encrypt (3)
 .br
 .BR keyctl_pkey_query (3)
 .br
diff --git a/man/keyctl_capabilities.3 b/man/keyctl_capabilities.3
index 63cee3c..f816df6 100644
--- a/man/keyctl_capabilities.3
+++ b/man/keyctl_capabilities.3
@@ -29,7 +29,7 @@ of the amount of buffer space available.  If the buffer is shorter than the
 data, a short copy will be made; if the buffer is larger than the data, the
 excess space will be cleared.
 .P
-If this operation is not available in the kernel, the keyutils library will be
+If this operation is not available in the kernel, the keyutils library will
 emulate it as best it can and the capability bit that indicates if the kernel
 operation is available will be cleared.
 .P
diff --git a/man/keyctl_chown.3 b/man/keyctl_chown.3
index 286bded..f85840a 100644
--- a/man/keyctl_chown.3
+++ b/man/keyctl_chown.3
@@ -37,7 +37,7 @@ does not match the process's GID or one of its group list.
 .P
 The caller must have
 .B setattr
-permission on a key to be able change its ownership.
+permission on a key to be able to change its ownership.
 .\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
 .SH RETURN VALUE
 On success
diff --git a/man/keyctl_clear.3 b/man/keyctl_clear.3
index 21e0c26..8da699e 100644
--- a/man/keyctl_clear.3
+++ b/man/keyctl_clear.3
@@ -25,7 +25,7 @@ clears the contents of a
 .P
 The caller must have
 .B write
-permission on a keyring to be able clear it.
+permission on a keyring to be able to clear it.
 .\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
 .SH RETURN VALUE
 On success
@@ -71,4 +71,3 @@ should be specified to the linker.
 .BR keyctl (3),
 .BR keyrings (7),
 .BR keyutils (7)
-
diff --git a/man/keyctl_link.3 b/man/keyctl_link.3
index 1185874..2cbc104 100644
--- a/man/keyctl_link.3
+++ b/man/keyctl_link.3
@@ -38,7 +38,7 @@ if it exists.
 .P
 The caller must have
 .B write
-permission on a keyring to be able create or remove links in it.
+permission on a keyring to be able to create or remove links in it.
 .P
 The caller must have
 .B link
@@ -105,4 +105,3 @@ should be specified to the linker.
 .BR keyctl (3),
 .BR keyrings (7),
 .BR keyutils (7)
-
diff --git a/man/keyctl_move.3 b/man/keyctl_move.3
index b241f70..6f144df 100644
--- a/man/keyctl_move.3
+++ b/man/keyctl_move.3
@@ -41,7 +41,7 @@ an error.
 .P
 The caller must have
 .B write
-permission on both keyring to be able create or remove links in them.
+permission on both keyring to be able to create or remove links in them.
 .P
 The caller must have
 .B link
@@ -106,4 +106,3 @@ should be specified to the linker.
 .BR keyctl (3),
 .BR keyrings (7),
 .BR keyutils (7)
-
diff --git a/man/keyctl_read.3 b/man/keyctl_read.3
index 852bc05..97b0e24 100644
--- a/man/keyctl_read.3
+++ b/man/keyctl_read.3
@@ -16,8 +16,7 @@ keyctl_read \- read a key
 .nf
 .B #include <keyutils.h>
 .sp
-.BI "long keyctl_read(key_serial_t " key ", char *" buffer ,
-.BI "size_t" buflen ");"
+.BI "long keyctl_read(key_serial_t " key ", char *" buffer ", size_t " buflen ");"
 .sp
 .BI "long keyctl_read_alloc(key_serial_t " key ", void **" _buffer ");"
 .\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
diff --git a/man/keyctl_revoke.3 b/man/keyctl_revoke.3
index 914a253..622f1ac 100644
--- a/man/keyctl_revoke.3
+++ b/man/keyctl_revoke.3
@@ -28,7 +28,7 @@ meet with error
 .P
 The caller must have
 .B write
-permission on a key to be able revoke it.
+permission on a key to be able to revoke it.
 .\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
 .SH RETURN VALUE
 On success
diff --git a/man/keyctl_set_timeout.3 b/man/keyctl_set_timeout.3
index 1b7ec94..24c7049 100644
--- a/man/keyctl_set_timeout.3
+++ b/man/keyctl_set_timeout.3
@@ -33,7 +33,7 @@ When the key expires, further attempts to access it will be met with error
 .P
 The caller must have
 .B setattr
-permission on a key to be able change its permissions mask.
+permission on a key to be able to change its permissions mask.
 .\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
 .SH RETURN VALUE
 On success
diff --git a/man/keyctl_setperm.3 b/man/keyctl_setperm.3
index 0a4426d..d5d9015 100644
--- a/man/keyctl_setperm.3
+++ b/man/keyctl_setperm.3
@@ -29,7 +29,7 @@ same UID as the caller.
 .P
 The caller must have
 .B setattr
-permission on a key to be able change its permissions mask.
+permission on a key to be able to change its permissions mask.
 .P
 The permissions mask is a bitwise-OR of the following flags:
 .TP
diff --git a/man/keyctl_update.3 b/man/keyctl_update.3
index 17fbdb4..2d44740 100644
--- a/man/keyctl_update.3
+++ b/man/keyctl_update.3
@@ -25,7 +25,7 @@ updates the payload of a key if the key type permits it.
 .P
 The caller must have
 .B write
-permission on a key to be able update it.
+permission on a key to be able to update it.
 .P
 .I payload
 and
-- 
2.27.0

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/4] Fix compilation error when keyutils.h is used in C++
  2020-07-02  8:57 [PATCH 0/4] keyutils: fix compilation error with C++ Christophe Vu-Brugier
  2020-07-02  8:57 ` [PATCH 1/4] man: fix typos Christophe Vu-Brugier
@ 2020-07-02  8:57 ` Christophe Vu-Brugier
  2020-07-02  8:57 ` [PATCH 3/4] Check that keyutils.h has valid C++ syntax at build time Christophe Vu-Brugier
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Christophe Vu-Brugier @ 2020-07-02  8:57 UTC (permalink / raw)
  To: keyrings; +Cc: David Howells, Stephan Müller, Christophe Vu-Brugier

The declaration of the keyctl_dh_compute_kdf() function contains a
parameter named "private". Unfortunately, "private" is a C++ reserved
keyword. As a consequence, compiling a C++ program that includes
keyutils.h fails.

This patch renames the "private" variable to "priv" since a similar
parameter is named this way in the nearby keyctl_dh_compute()
function.

Signed-off-by: Christophe Vu-Brugier <cvubrugier@fastmail.fm>
---
 keyutils.c | 4 ++--
 keyutils.h | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/keyutils.c b/keyutils.c
index 9c37256..9877fdb 100644
--- a/keyutils.c
+++ b/keyutils.c
@@ -244,11 +244,11 @@ long keyctl_dh_compute(key_serial_t priv, key_serial_t prime,
 	return keyctl(KEYCTL_DH_COMPUTE, &params, buffer, buflen, 0);
 }
 
-long keyctl_dh_compute_kdf(key_serial_t private, key_serial_t prime,
+long keyctl_dh_compute_kdf(key_serial_t priv, key_serial_t prime,
 			   key_serial_t base, char *hashname, char *otherinfo,
 			   size_t otherinfolen, char *buffer, size_t buflen)
 {
-	struct keyctl_dh_params params = { .priv = private,
+	struct keyctl_dh_params params = { .priv = priv,
 					   .prime = prime,
 					   .base = base };
 	struct keyctl_kdf_params kdfparams = { .hashname = hashname,
diff --git a/keyutils.h b/keyutils.h
index d50119e..bdecf15 100644
--- a/keyutils.h
+++ b/keyutils.h
@@ -220,7 +220,7 @@ extern long keyctl_invalidate(key_serial_t id);
 extern long keyctl_get_persistent(uid_t uid, key_serial_t id);
 extern long keyctl_dh_compute(key_serial_t priv, key_serial_t prime,
 			      key_serial_t base, char *buffer, size_t buflen);
-extern long keyctl_dh_compute_kdf(key_serial_t private, key_serial_t prime,
+extern long keyctl_dh_compute_kdf(key_serial_t priv, key_serial_t prime,
 				  key_serial_t base, char *hashname,
 				  char *otherinfo, size_t otherinfolen,
 				  char *buffer, size_t buflen);
-- 
2.27.0

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/4] Check that keyutils.h has valid C++ syntax at build time
  2020-07-02  8:57 [PATCH 0/4] keyutils: fix compilation error with C++ Christophe Vu-Brugier
  2020-07-02  8:57 ` [PATCH 1/4] man: fix typos Christophe Vu-Brugier
  2020-07-02  8:57 ` [PATCH 2/4] Fix compilation error when keyutils.h is used in C++ Christophe Vu-Brugier
@ 2020-07-02  8:57 ` Christophe Vu-Brugier
  2020-07-02  8:57 ` [PATCH 4/4] Fix error when a C++ program is linked with libkeyutils Christophe Vu-Brugier
  2020-07-06 20:27 ` [PATCH 0/4] keyutils: fix compilation error with C++ David Howells
  4 siblings, 0 replies; 6+ messages in thread
From: Christophe Vu-Brugier @ 2020-07-02  8:57 UTC (permalink / raw)
  To: keyrings; +Cc: David Howells, Stephan Müller, Christophe Vu-Brugier

Signed-off-by: Christophe Vu-Brugier <cvubrugier@fastmail.fm>
---
 Makefile | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index 6f79446..949ad7c 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,6 @@
 CPPFLAGS	:= -I.
 CFLAGS		:= -g -Wall -Werror
+CXXFLAGS	:= -g -Wall -Werror
 INSTALL		:= install
 DESTDIR		: SPECFILE	:= keyutils.spec
@@ -99,7 +100,7 @@ endif
 # Normal build rule
 #
 ###############################################################################
-all: keyctl request-key key.dns_resolver
+all: keyctl request-key key.dns_resolver cxx
 
 ###############################################################################
 #
@@ -163,6 +164,18 @@ key.dns_resolver: key.dns_resolver.o dns.afsdb.o $(LIB_DEPENDENCY)
 key.dns_resolver.o: key.dns_resolver.c key.dns.h
 dns.afsdb.o: dns.afsdb.c key.dns.h
 
+###############################################################################
+#
+# Check that the header file has valid C++ syntax
+#
+###############################################################################
+cxx.stamp: keyutils.h Makefile
+	$(CXX) $(CPPFLAGS) $(CXXFLAGS) -x c++-header -fsyntax-only $<
+	touch $@
+
+cxx: cxx.stamp
+.PHONY: cxx
+
 ###############################################################################
 #
 # Install everything
@@ -244,6 +257,7 @@ clean:
 	$(RM) keyctl request-key key.dns_resolver
 	$(RM) *.o *.os *~
 	$(RM) debugfiles.list debugsources.list
+	$(RM) cxx.stamp
 
 distclean: clean
 	$(RM) -r rpmbuild $(TARBALL)
-- 
2.27.0

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 4/4] Fix error when a C++ program is linked with libkeyutils
  2020-07-02  8:57 [PATCH 0/4] keyutils: fix compilation error with C++ Christophe Vu-Brugier
                   ` (2 preceding siblings ...)
  2020-07-02  8:57 ` [PATCH 3/4] Check that keyutils.h has valid C++ syntax at build time Christophe Vu-Brugier
@ 2020-07-02  8:57 ` Christophe Vu-Brugier
  2020-07-06 20:27 ` [PATCH 0/4] keyutils: fix compilation error with C++ David Howells
  4 siblings, 0 replies; 6+ messages in thread
From: Christophe Vu-Brugier @ 2020-07-02  8:57 UTC (permalink / raw)
  To: keyrings; +Cc: David Howells, Stephan Müller, Christophe Vu-Brugier

Declare all the functions as extern "C" in keyutils.h to instruct a
C++ compiler that these functions are not mangled.

Signed-off-by: Christophe Vu-Brugier <cvubrugier@fastmail.fm>
---
 keyutils.h | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/keyutils.h b/keyutils.h
index bdecf15..4ae81d3 100644
--- a/keyutils.h
+++ b/keyutils.h
@@ -15,6 +15,10 @@
 #include <sys/types.h>
 #include <stdint.h>
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 extern const char keyutils_version_string[];
 extern const char keyutils_build_string[];
 
@@ -268,4 +272,8 @@ extern int recursive_session_key_scan(recursive_key_scanner_t func, void *data);
 extern key_serial_t find_key_by_type_and_desc(const char *type, const char *desc,
 					      key_serial_t destringid);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /* KEYUTILS_H */
-- 
2.27.0

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/4] keyutils: fix compilation error with C++
  2020-07-02  8:57 [PATCH 0/4] keyutils: fix compilation error with C++ Christophe Vu-Brugier
                   ` (3 preceding siblings ...)
  2020-07-02  8:57 ` [PATCH 4/4] Fix error when a C++ program is linked with libkeyutils Christophe Vu-Brugier
@ 2020-07-06 20:27 ` David Howells
  4 siblings, 0 replies; 6+ messages in thread
From: David Howells @ 2020-07-06 20:27 UTC (permalink / raw)
  To: keyrings

Christophe Vu-Brugier <cvubrugier@fastmail.fm> wrote:

> * Patch #1 fixes a few typos in the man pages.
> * Patch #2 fixes the aforementioned issue.
> * Patch #3 helps prevent a similar issue from happening in the future.
> * Patch #4 fixes an issue reported by C++ compilers at link time.

Applied.

David

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-07-06 20:27 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-02  8:57 [PATCH 0/4] keyutils: fix compilation error with C++ Christophe Vu-Brugier
2020-07-02  8:57 ` [PATCH 1/4] man: fix typos Christophe Vu-Brugier
2020-07-02  8:57 ` [PATCH 2/4] Fix compilation error when keyutils.h is used in C++ Christophe Vu-Brugier
2020-07-02  8:57 ` [PATCH 3/4] Check that keyutils.h has valid C++ syntax at build time Christophe Vu-Brugier
2020-07-02  8:57 ` [PATCH 4/4] Fix error when a C++ program is linked with libkeyutils Christophe Vu-Brugier
2020-07-06 20:27 ` [PATCH 0/4] keyutils: fix compilation error with C++ David Howells

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.