keyutils.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /* keyutils.h: key utility library interface
  2. *
  3. * Copyright (C) 2005 Red Hat, Inc. All Rights Reserved.
  4. * Written by David Howells (dhowells@redhat.com)
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. */
  11. #ifndef KEYUTILS_H
  12. #define KEYUTILS_H
  13. #include <stdint.h>
  14. /* key serial number */
  15. typedef int32_t key_serial_t;
  16. /* special process keyring shortcut IDs */
  17. #define KEY_SPEC_THREAD_KEYRING -1 /* - key ID for thread-specific keyring */
  18. #define KEY_SPEC_PROCESS_KEYRING -2 /* - key ID for process-specific keyring */
  19. #define KEY_SPEC_SESSION_KEYRING -3 /* - key ID for session-specific keyring */
  20. #define KEY_SPEC_USER_KEYRING -4 /* - key ID for UID-specific keyring */
  21. #define KEY_SPEC_USER_SESSION_KEYRING -5 /* - key ID for UID-session keyring */
  22. #define KEY_SPEC_GROUP_KEYRING -6 /* - key ID for GID-specific keyring */
  23. #define KEY_SPEC_REQKEY_AUTH_KEY -7 /* - key ID for assumed request_key auth key */
  24. /* request-key default keyrings */
  25. #define KEY_REQKEY_DEFL_NO_CHANGE -1
  26. #define KEY_REQKEY_DEFL_DEFAULT 0
  27. #define KEY_REQKEY_DEFL_THREAD_KEYRING 1
  28. #define KEY_REQKEY_DEFL_PROCESS_KEYRING 2
  29. #define KEY_REQKEY_DEFL_SESSION_KEYRING 3
  30. #define KEY_REQKEY_DEFL_USER_KEYRING 4
  31. #define KEY_REQKEY_DEFL_USER_SESSION_KEYRING 5
  32. #define KEY_REQKEY_DEFL_GROUP_KEYRING 6
  33. /* key handle permissions mask */
  34. typedef uint32_t key_perm_t;
  35. #define KEY_POS_VIEW 0x01000000 /* possessor can view a key's attributes */
  36. #define KEY_POS_READ 0x02000000 /* possessor can read key payload / view keyring */
  37. #define KEY_POS_WRITE 0x04000000 /* possessor can update key payload / add link to keyring */
  38. #define KEY_POS_SEARCH 0x08000000 /* possessor can find a key in search / search a keyring */
  39. #define KEY_POS_LINK 0x10000000 /* possessor can create a link to a key/keyring */
  40. #define KEY_POS_SETATTR 0x20000000 /* possessor can set key attributes */
  41. #define KEY_POS_ALL 0x3f000000
  42. #define KEY_USR_VIEW 0x00010000 /* user permissions... */
  43. #define KEY_USR_READ 0x00020000
  44. #define KEY_USR_WRITE 0x00040000
  45. #define KEY_USR_SEARCH 0x00080000
  46. #define KEY_USR_LINK 0x00100000
  47. #define KEY_USR_SETATTR 0x00200000
  48. #define KEY_USR_ALL 0x003f0000
  49. #define KEY_GRP_VIEW 0x00000100 /* group permissions... */
  50. #define KEY_GRP_READ 0x00000200
  51. #define KEY_GRP_WRITE 0x00000400
  52. #define KEY_GRP_SEARCH 0x00000800
  53. #define KEY_GRP_LINK 0x00001000
  54. #define KEY_GRP_SETATTR 0x00002000
  55. #define KEY_GRP_ALL 0x00003f00
  56. #define KEY_OTH_VIEW 0x00000001 /* third party permissions... */
  57. #define KEY_OTH_READ 0x00000002
  58. #define KEY_OTH_WRITE 0x00000004
  59. #define KEY_OTH_SEARCH 0x00000008
  60. #define KEY_OTH_LINK 0x00000010
  61. #define KEY_OTH_SETATTR 0x00000010
  62. #define KEY_OTH_ALL 0x0000003f
  63. /* keyctl commands */
  64. #define KEYCTL_GET_KEYRING_ID 0 /* ask for a keyring's ID */
  65. #define KEYCTL_JOIN_SESSION_KEYRING 1 /* join or start named session keyring */
  66. #define KEYCTL_UPDATE 2 /* update a key */
  67. #define KEYCTL_REVOKE 3 /* revoke a key */
  68. #define KEYCTL_CHOWN 4 /* set ownership of a key */
  69. #define KEYCTL_SETPERM 5 /* set perms on a key */
  70. #define KEYCTL_DESCRIBE 6 /* describe a key */
  71. #define KEYCTL_CLEAR 7 /* clear contents of a keyring */
  72. #define KEYCTL_LINK 8 /* link a key into a keyring */
  73. #define KEYCTL_UNLINK 9 /* unlink a key from a keyring */
  74. #define KEYCTL_SEARCH 10 /* search for a key in a keyring */
  75. #define KEYCTL_READ 11 /* read a key or keyring's contents */
  76. #define KEYCTL_INSTANTIATE 12 /* instantiate a partially constructed key */
  77. #define KEYCTL_NEGATE 13 /* negate a partially constructed key */
  78. #define KEYCTL_SET_REQKEY_KEYRING 14 /* set default request-key keyring */
  79. #define KEYCTL_SET_TIMEOUT 15 /* set timeout on a key */
  80. #define KEYCTL_ASSUME_AUTHORITY 16 /* assume authority to instantiate key */
  81. #define KEYCTL_GET_SECURITY 17 /* get key security label */
  82. #define KEYCTL_SESSION_TO_PARENT 18 /* set my session keyring on my parent process */
  83. /*
  84. * syscall wrappers
  85. */
  86. extern key_serial_t add_key(const char *type,
  87. const char *description,
  88. const void *payload,
  89. size_t plen,
  90. key_serial_t ringid);
  91. extern key_serial_t request_key(const char *type,
  92. const char *description,
  93. const char *callout_info,
  94. key_serial_t destringid);
  95. extern long keyctl(int cmd, ...);
  96. /*
  97. * keyctl function wrappers
  98. */
  99. extern key_serial_t keyctl_get_keyring_ID(key_serial_t id, int create);
  100. extern key_serial_t keyctl_join_session_keyring(const char *name);
  101. extern long keyctl_update(key_serial_t id, const void *payload, size_t plen);
  102. extern long keyctl_revoke(key_serial_t id);
  103. extern long keyctl_chown(key_serial_t id, uid_t uid, gid_t gid);
  104. extern long keyctl_setperm(key_serial_t id, key_perm_t perm);
  105. extern long keyctl_describe(key_serial_t id, char *buffer, size_t buflen);
  106. extern long keyctl_clear(key_serial_t ringid);
  107. extern long keyctl_link(key_serial_t id, key_serial_t ringid);
  108. extern long keyctl_unlink(key_serial_t id, key_serial_t ringid);
  109. extern long keyctl_search(key_serial_t ringid,
  110. const char *type,
  111. const char *description,
  112. key_serial_t destringid);
  113. extern long keyctl_read(key_serial_t id, char *buffer, size_t buflen);
  114. extern long keyctl_instantiate(key_serial_t id,
  115. const void *payload,
  116. size_t plen,
  117. key_serial_t ringid);
  118. extern long keyctl_negate(key_serial_t id, unsigned timeout, key_serial_t ringid);
  119. extern long keyctl_set_reqkey_keyring(int reqkey_defl);
  120. extern long keyctl_set_timeout(key_serial_t key, unsigned timeout);
  121. extern long keyctl_assume_authority(key_serial_t key);
  122. extern long keyctl_get_security(key_serial_t key, char *buffer, size_t buflen);
  123. extern long keyctl_session_to_parent(void);
  124. /*
  125. * utilities
  126. */
  127. extern int keyctl_describe_alloc(key_serial_t id, char **_buffer);
  128. extern int keyctl_read_alloc(key_serial_t id, void **_buffer);
  129. extern int keyctl_get_security_alloc(key_serial_t id, char **_buffer);
  130. #endif /* KEYUTILS_H */