key-type.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /* Definitions for key type implementations
  2. *
  3. * Copyright (C) 2007 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 General Public Licence
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the Licence, or (at your option) any later version.
  10. */
  11. #ifndef _LINUX_KEY_TYPE_H
  12. #define _LINUX_KEY_TYPE_H
  13. #include <linux/key.h>
  14. #include <linux/errno.h>
  15. #ifdef CONFIG_KEYS
  16. /*
  17. * key under-construction record
  18. * - passed to the request_key actor if supplied
  19. */
  20. struct key_construction {
  21. struct key *key; /* key being constructed */
  22. struct key *authkey;/* authorisation for key being constructed */
  23. };
  24. typedef int (*request_key_actor_t)(struct key_construction *key,
  25. const char *op, void *aux);
  26. /*
  27. * kernel managed key type definition
  28. */
  29. struct key_type {
  30. /* name of the type */
  31. const char *name;
  32. /* default payload length for quota precalculation (optional)
  33. * - this can be used instead of calling key_payload_reserve(), that
  34. * function only needs to be called if the real datalen is different
  35. */
  36. size_t def_datalen;
  37. /* vet a description */
  38. int (*vet_description)(const char *description);
  39. /* instantiate a key of this type
  40. * - this method should call key_payload_reserve() to determine if the
  41. * user's quota will hold the payload
  42. */
  43. int (*instantiate)(struct key *key, const void *data, size_t datalen);
  44. /* update a key of this type (optional)
  45. * - this method should call key_payload_reserve() to recalculate the
  46. * quota consumption
  47. * - the key must be locked against read when modifying
  48. */
  49. int (*update)(struct key *key, const void *data, size_t datalen);
  50. /* match a key against a description */
  51. int (*match)(const struct key *key, const void *desc);
  52. /* clear some of the data from a key on revokation (optional)
  53. * - the key's semaphore will be write-locked by the caller
  54. */
  55. void (*revoke)(struct key *key);
  56. /* clear the data from a key (optional) */
  57. void (*destroy)(struct key *key);
  58. /* describe a key */
  59. void (*describe)(const struct key *key, struct seq_file *p);
  60. /* read a key's data (optional)
  61. * - permission checks will be done by the caller
  62. * - the key's semaphore will be readlocked by the caller
  63. * - should return the amount of data that could be read, no matter how
  64. * much is copied into the buffer
  65. * - shouldn't do the copy if the buffer is NULL
  66. */
  67. long (*read)(const struct key *key, char __user *buffer, size_t buflen);
  68. /* handle request_key() for this type instead of invoking
  69. * /sbin/request-key (optional)
  70. * - key is the key to instantiate
  71. * - authkey is the authority to assume when instantiating this key
  72. * - op is the operation to be done, usually "create"
  73. * - the call must not return until the instantiation process has run
  74. * its course
  75. */
  76. request_key_actor_t request_key;
  77. /* internal fields */
  78. struct list_head link; /* link in types list */
  79. struct lock_class_key lock_class; /* key->sem lock class */
  80. };
  81. extern struct key_type key_type_keyring;
  82. extern int register_key_type(struct key_type *ktype);
  83. extern void unregister_key_type(struct key_type *ktype);
  84. extern int key_payload_reserve(struct key *key, size_t datalen);
  85. extern int key_instantiate_and_link(struct key *key,
  86. const void *data,
  87. size_t datalen,
  88. struct key *keyring,
  89. struct key *instkey);
  90. extern int key_reject_and_link(struct key *key,
  91. unsigned timeout,
  92. unsigned error,
  93. struct key *keyring,
  94. struct key *instkey);
  95. extern void complete_request_key(struct key_construction *cons, int error);
  96. static inline int key_negate_and_link(struct key *key,
  97. unsigned timeout,
  98. struct key *keyring,
  99. struct key *instkey)
  100. {
  101. return key_reject_and_link(key, timeout, ENOKEY, keyring, instkey);
  102. }
  103. #endif /* CONFIG_KEYS */
  104. #endif /* _LINUX_KEY_TYPE_H */