internal.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /* internal.h: authentication token and access key management internal defs
  2. *
  3. * Copyright (C) 2003 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 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 _INTERNAL_H
  12. #define _INTERNAL_H
  13. #include <linux/key.h>
  14. #include <linux/key-ui.h>
  15. extern struct key_type key_type_dead;
  16. extern struct key_type key_type_user;
  17. /*****************************************************************************/
  18. /*
  19. * keep track of keys for a user
  20. * - this needs to be separate to user_struct to avoid a refcount-loop
  21. * (user_struct pins some keyrings which pin this struct)
  22. * - this also keeps track of keys under request from userspace for this UID
  23. */
  24. struct key_user {
  25. struct rb_node node;
  26. struct list_head consq; /* construction queue */
  27. spinlock_t lock;
  28. atomic_t usage; /* for accessing qnkeys & qnbytes */
  29. atomic_t nkeys; /* number of keys */
  30. atomic_t nikeys; /* number of instantiated keys */
  31. uid_t uid;
  32. int qnkeys; /* number of keys allocated to this user */
  33. int qnbytes; /* number of bytes allocated to this user */
  34. };
  35. #define KEYQUOTA_MAX_KEYS 100
  36. #define KEYQUOTA_MAX_BYTES 10000
  37. #define KEYQUOTA_LINK_BYTES 4 /* a link in a keyring is worth 4 bytes */
  38. extern struct rb_root key_user_tree;
  39. extern spinlock_t key_user_lock;
  40. extern struct key_user root_key_user;
  41. extern struct key_user *key_user_lookup(uid_t uid);
  42. extern void key_user_put(struct key_user *user);
  43. extern struct rb_root key_serial_tree;
  44. extern spinlock_t key_serial_lock;
  45. extern struct semaphore key_alloc_sem;
  46. extern struct rw_semaphore key_construction_sem;
  47. extern wait_queue_head_t request_key_conswq;
  48. extern void keyring_publish_name(struct key *keyring);
  49. extern int __key_link(struct key *keyring, struct key *key);
  50. extern struct key *__keyring_search_one(struct key *keyring,
  51. const struct key_type *type,
  52. const char *description,
  53. key_perm_t perm);
  54. typedef int (*key_match_func_t)(const struct key *, const void *);
  55. extern struct key *keyring_search_aux(struct key *keyring,
  56. struct key_type *type,
  57. const void *description,
  58. key_match_func_t match);
  59. extern struct key *search_process_keyrings_aux(struct key_type *type,
  60. const void *description,
  61. key_match_func_t match);
  62. extern struct key *find_keyring_by_name(const char *name, key_serial_t bound);
  63. extern int install_thread_keyring(struct task_struct *tsk);
  64. /*
  65. * keyctl functions
  66. */
  67. extern long keyctl_get_keyring_ID(key_serial_t, int);
  68. extern long keyctl_join_session_keyring(const char __user *);
  69. extern long keyctl_update_key(key_serial_t, const void __user *, size_t);
  70. extern long keyctl_revoke_key(key_serial_t);
  71. extern long keyctl_keyring_clear(key_serial_t);
  72. extern long keyctl_keyring_link(key_serial_t, key_serial_t);
  73. extern long keyctl_keyring_unlink(key_serial_t, key_serial_t);
  74. extern long keyctl_describe_key(key_serial_t, char __user *, size_t);
  75. extern long keyctl_keyring_search(key_serial_t, const char __user *,
  76. const char __user *, key_serial_t);
  77. extern long keyctl_read_key(key_serial_t, char __user *, size_t);
  78. extern long keyctl_chown_key(key_serial_t, uid_t, gid_t);
  79. extern long keyctl_setperm_key(key_serial_t, key_perm_t);
  80. extern long keyctl_instantiate_key(key_serial_t, const void __user *,
  81. size_t, key_serial_t);
  82. extern long keyctl_negate_key(key_serial_t, unsigned, key_serial_t);
  83. /*
  84. * debugging key validation
  85. */
  86. #ifdef KEY_DEBUGGING
  87. extern void __key_check(const struct key *);
  88. static inline void key_check(const struct key *key)
  89. {
  90. if (key && (IS_ERR(key) || key->magic != KEY_DEBUG_MAGIC))
  91. __key_check(key);
  92. }
  93. #else
  94. #define key_check(key) do {} while(0)
  95. #endif
  96. #endif /* _INTERNAL_H */