TEST: Key invalidation

Test the key invalidation functionality.

Signed-off-by: David Howells <dhowells@redhat.com>
TEST: Check depth of tree output by "keyctl show"

Check depth of tree output by "keyctl show" to make sure it shows the full
depth and not an abbreviated tree.

Also, whilst we're at it, check that we can show the contents of a nominated
keyring.

Signed-off-by: David Howells <dhowells@redhat.com>
TEST: Check maximum size of payload to add_key()

Check maximum size of payload to add_key() using the keyctl padd function.

Signed-off-by: David Howells <dhowells@redhat.com>
TEST: Make search/valid aware that the behaviour of the kernel changed

The kernel changed its behaviour with regard to the error code it returns when
the first key a search found was revoked and no valid key was found.  It used
to return ENOKEY and now returns EKEYREVOKED.

Signed-off-by: David Howells <dhowells@redhat.com>
Lib: Fix error-path memory leaks

Fix some memory leaks in error paths where a previously allocated buffer is
not freed if we get an error.

Signed-off-by: David Howells <dhowells@redhat.com>
Use keyctl_describe_alloc() in dump_key_tree_aux()

Use the keyctl_describe_alloc() library function in dump_key_tree_aux() in the
keyctl program rather than open coding it.

Signed-off-by: David Howells <dhowells@redhat.com>
keyctl: Exit rather than returning from act_xxx() functions

Exit rather than returning from act_xxx() functions so that the Coverity
checker doesn't think that memory is leaked from functions that allocate
memory.

Signed-off-by: David Howells <dhowells@redhat.com>
Fix memory leak in dump_key_tree_aux() in the keyctl program

Fix a leak of the description string memory from each key visited in
dump_key_tree_aux() in the keyctl program.

Signed-off-by: David Howells <dhowells@redhat.com>
Only get the groups list if calc_perms() is called

Only get the groups list if calc_perms() is called as there's no point
grabbing the list otherwise.

Signed-off-by: David Howells <dhowells@redhat.com>
Lib: Don't trust sscanf()'s %n argument

Don't trust sscanf()'s %n argument just in case the space immediately before
it didn't match anything as sscanf() doesn't tell you if it was set.

Signed-off-by: David Howells <dhowells@redhat.com>
Lib: Check the description string is NUL-terminated when retrieved

Check the description string is NUL-terminated retrieved by keyctl_describe()
included a NUL-terminator in its length.

Signed-off-by: David Howells <dhowells@redhat.com>
spec: Use the correct path macros in the specfile

Use the correct path macros in the specfile.

Signed-off-by: David Howells <dhowells@redhat.com>
Lib: Don't use realloc() in keyctl_{describe,read,get_security}_alloc()

Don't use realloc() in keyctl_{describe,read,get_security}_alloc() as it
doesn't free the argument buffer if it fails and it will copy the empty buffer
if it moves it.

Use malloc+free instead.

Reported-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: David Howells <dhowells@redhat.com>
Fix some issues in key.dns_resolver.c:

 (1) Check the success of strtol() correctly when parsing the key ID - and
     make sure the key ID isn't blank beforehand.

 (2) buf and callout_info in main() are guaranteed to be NULL at the point
     they're tested prior to calling keyctl_describe_alloc() and
     keyctl_read_alloc() so the if-statements are redundant.

 (3) In append_address_to_payload() remove an if-statement that can never
     trigger, given the if-statement it's embedded within.

 (4) usage() doesn't know of a key ID to negate, so don't do that.

 (5) The 'key' argument to dns_query_*() is redundant given the global
     variable of the same name holding the same value.

 (6) dns_query_a_or_aaaa() declares a local variable masking the 'key'
     argument and global variable in an inner scope.

 (7) DNS_EXPIRY_PREFIX, DNS_EXPIRY_TIME_LEN and AFSDB_MAX_DATA_LEN are all
     unused and LIST_MULTIPLE_ITEMS is only set, never read, so delete them
     all.

 (8) Make append_address_to_payload() copy the argument if it's not a
     duplicate rather than copying it in the caller then discarding when we
     find out it is a duplicate.

 (9) Move vllist[] and vlsnum into afsdb_hosts_to_addrs() rather than passing
     them in from the caller where they aren't otherwise used.

Reported-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: David Howells <dhowells@redhat.com>
cc: Wang Lei <wang840925@gmail.com>
keyctl: Fix command table searching

In the keyctl program, when searching the command table, don't trust that an
overlong argument name won't cause memcpy() to segfault.  This is unlikely to
be a problem as any efficient memcpy() is going to start scanning from the
lowest address, given that it has to report on the lowest-addressed difference
if there is one.

Reported-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: David Howells <dhowells@redhat.com>
Revert "Lib: Check the description string is NUL-terminated when retrieved"

This reverts commit ed72a1dfc56a4f5428affb1659d6812d54e392c5.

The problem is that the buffer argument might validly be NULL, leading to a
SEGV when we try to check for the NUL termination.

Signed-off-by: David Howells <dhowells@redhat.com>
Lib: Fix typo in permission mask.

The KEY_OTH_SETATTR constant macro is defined incorrectly.

Signed-off-by: James Muir <james.muir@graphitesoftware.com>
Signed-off-by: David Howells <dhowells@redhat.com>
Doc: Move manual pages to their own subdir

Move manual pages to their own subdir to tidy the sources up.

Signed-off-by: David Howells <dhowells@redhat.com>
Doc: Add a Developer's Certificate of Origin

Add a Developer's Certificate of Origin for the use of people submitting
patches.

Signed-off-by: David Howells <dhowells@redhat.com>
Doc: Improve the keyctl_read[_alloc]() manpage

Improve the keyctl_read[_alloc]() manpage.

Signed-off-by: David Howells <dhowells@redhat.com>