diff mbox

nfsidmap: keyctl_invalidate kernel compatibility

Message ID 643db7f6caed9ec25c0067aec85b97190bfbe174.1415026355.git.bcodding@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Benjamin Coddington Nov. 3, 2014, 2:54 p.m. UTC
Change the keyctl_invalidate call to use the syscall interface directly so
that when building with libkeyutils missing keyctl_invalidate the build succeeds.
Attempt to use _invalidate and fall back to _revoke if the current kernel is
missing _invalidate.

Signed-off-by: Benjamin Coddington <bcodding@redhat.com>
---
 utils/nfsidmap/nfsidmap.c |   15 +++++++++++----
 1 files changed, 11 insertions(+), 4 deletions(-)

Comments

Chuck Lever Nov. 3, 2014, 3:03 p.m. UTC | #1
On Nov 3, 2014, at 9:54 AM, Benjamin Coddington <bcodding@redhat.com> wrote:

> Change the keyctl_invalidate call to use the syscall interface directly so
> that when building with libkeyutils missing keyctl_invalidate the build succeeds.
> Attempt to use _invalidate and fall back to _revoke if the current kernel is
> missing _invalidate.
> 
> Signed-off-by: Benjamin Coddington <bcodding@redhat.com>
> ---
> utils/nfsidmap/nfsidmap.c |   15 +++++++++++----
> 1 files changed, 11 insertions(+), 4 deletions(-)
> 
> diff --git a/utils/nfsidmap/nfsidmap.c b/utils/nfsidmap/nfsidmap.c
> index e0d31e7..99ae07e 100644
> --- a/utils/nfsidmap/nfsidmap.c
> +++ b/utils/nfsidmap/nfsidmap.c
> @@ -209,10 +209,17 @@ static int key_invalidate(char *keystr, int keymask)
> 		*(strchr(buf, ' ')) = '\0';
> 		sscanf(buf, "%x", &key);
> 
> -		if (keyctl_invalidate(key) < 0) {
> -			xlog_err("keyctl_invalidate(0x%x) failed: %m", key);
> -			fclose(fp);
> -			return 1;
> +/* older libkeyutils compatibility */
> +#ifndef KEYCTL_INVALIDATE
> +#define KEYCTL_INVALIDATE 21      /* invalidate a key */
> +#endif
> +		if (keyctl(KEYCTL_INVALIDATE, key) < 0 && errno == EOPNOTSUPP) {
> +			/* older kernel compatibility attempt: */
> +			if (keyctl_revoke(key) < 0) {
> +				xlog_err("keyctl_invalidate(0x%x) failed: %m", key);
> +				fclose(fp);
> +				return 1;
> +			}

Thanks, Ben.

This logic handles and reports errors only from keyctl_revoke().
Can it be updated to report errors (other than EOPNOTSUPP) from
either function, display the name of the keyctl function it
tried to invoke, and close fp and exit appropriately?


> 		}
> 
> 		keymask &= ~mask;
> -- 
> 1.7.1
> 

--
Chuck Lever
chuck[dot]lever[at]oracle[dot]com



--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Benjamin Coddington Nov. 3, 2014, 5:07 p.m. UTC | #2
On Mon, 3 Nov 2014, Chuck Lever wrote:

>
> On Nov 3, 2014, at 9:54 AM, Benjamin Coddington <bcodding@redhat.com> wrote:
>
>> Change the keyctl_invalidate call to use the syscall interface directly so
>> that when building with libkeyutils missing keyctl_invalidate the build succeeds.
>> Attempt to use _invalidate and fall back to _revoke if the current kernel is
>> missing _invalidate.
>>
>> Signed-off-by: Benjamin Coddington <bcodding@redhat.com>
>> ---
>> utils/nfsidmap/nfsidmap.c |   15 +++++++++++----
>> 1 files changed, 11 insertions(+), 4 deletions(-)
>>
>> diff --git a/utils/nfsidmap/nfsidmap.c b/utils/nfsidmap/nfsidmap.c
>> index e0d31e7..99ae07e 100644
>> --- a/utils/nfsidmap/nfsidmap.c
>> +++ b/utils/nfsidmap/nfsidmap.c
>> @@ -209,10 +209,17 @@ static int key_invalidate(char *keystr, int keymask)
>> 		*(strchr(buf, ' ')) = '\0';
>> 		sscanf(buf, "%x", &key);
>>
>> -		if (keyctl_invalidate(key) < 0) {
>> -			xlog_err("keyctl_invalidate(0x%x) failed: %m", key);
>> -			fclose(fp);
>> -			return 1;
>> +/* older libkeyutils compatibility */
>> +#ifndef KEYCTL_INVALIDATE
>> +#define KEYCTL_INVALIDATE 21      /* invalidate a key */
>> +#endif
>> +		if (keyctl(KEYCTL_INVALIDATE, key) < 0 && errno == EOPNOTSUPP) {
>> +			/* older kernel compatibility attempt: */
>> +			if (keyctl_revoke(key) < 0) {
>> +				xlog_err("keyctl_invalidate(0x%x) failed: %m", key);
>> +				fclose(fp);
>> +				return 1;
>> +			}
>
> Thanks, Ben.
>
> This logic handles and reports errors only from keyctl_revoke().
> Can it be updated to report errors (other than EOPNOTSUPP) from
> either function, display the name of the keyctl function it
> tried to invoke, and close fp and exit appropriately?

Oh.. right.  Of course.

Ben
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/utils/nfsidmap/nfsidmap.c b/utils/nfsidmap/nfsidmap.c
index e0d31e7..99ae07e 100644
--- a/utils/nfsidmap/nfsidmap.c
+++ b/utils/nfsidmap/nfsidmap.c
@@ -209,10 +209,17 @@  static int key_invalidate(char *keystr, int keymask)
 		*(strchr(buf, ' ')) = '\0';
 		sscanf(buf, "%x", &key);
 
-		if (keyctl_invalidate(key) < 0) {
-			xlog_err("keyctl_invalidate(0x%x) failed: %m", key);
-			fclose(fp);
-			return 1;
+/* older libkeyutils compatibility */
+#ifndef KEYCTL_INVALIDATE
+#define KEYCTL_INVALIDATE 21      /* invalidate a key */
+#endif
+		if (keyctl(KEYCTL_INVALIDATE, key) < 0 && errno == EOPNOTSUPP) {
+			/* older kernel compatibility attempt: */
+			if (keyctl_revoke(key) < 0) {
+				xlog_err("keyctl_invalidate(0x%x) failed: %m", key);
+				fclose(fp);
+				return 1;
+			}
 		}
 
 		keymask &= ~mask;