1#include "key_control.h" 2 3#include <stdarg.h> 4#include <unistd.h> 5#include <sys/syscall.h> 6 7/* keyring keyctl commands */ 8#define KEYCTL_REVOKE 3 /* revoke a key */ 9#define KEYCTL_SETPERM 5 /* set permissions for a key in a keyring */ 10#define KEYCTL_SEARCH 10 /* search for a key in a keyring */ 11 12static long keyctl(int cmd, ...) 13{ 14 va_list va; 15 unsigned long arg2, arg3, arg4, arg5; 16 17 va_start(va, cmd); 18 arg2 = va_arg(va, unsigned long); 19 arg3 = va_arg(va, unsigned long); 20 arg4 = va_arg(va, unsigned long); 21 arg5 = va_arg(va, unsigned long); 22 va_end(va); 23 return syscall(__NR_keyctl, cmd, arg2, arg3, arg4, arg5); 24} 25 26key_serial_t add_key(const char *type, 27 const char *description, 28 const void *payload, 29 size_t plen, 30 key_serial_t ringid) 31{ 32 return syscall(__NR_add_key, type, description, payload, plen, ringid); 33} 34 35long keyctl_revoke(key_serial_t id) 36{ 37 return keyctl(KEYCTL_REVOKE, id); 38} 39 40long keyctl_setperm(key_serial_t id, int permissions) 41{ 42 return keyctl(KEYCTL_SETPERM, id, permissions); 43} 44 45long keyctl_search(key_serial_t ringid, const char *type, 46 const char *description, key_serial_t destringid) 47{ 48 return keyctl(KEYCTL_SEARCH, ringid, type, description, destringid); 49} 50