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