key-type.h 3.8 KB

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