capability.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * <sys/capability.h>
  3. *
  4. * Copyright (C) 1997 Aleph One
  5. * Copyright (C) 1997-8,2008 Andrew G. Morgan <morgan@kernel.org>
  6. *
  7. * defunct POSIX.1e Standard: 25.2 Capabilities <sys/capability.h>
  8. */
  9. #ifndef _SYS_CAPABILITY_H
  10. #define _SYS_CAPABILITY_H
  11. #ifdef __cplusplus
  12. extern "C" {
  13. #endif
  14. /*
  15. * This file complements the kernel file by providing prototype
  16. * information for the user library.
  17. */
  18. #include <sys/types.h>
  19. #include <stdint.h>
  20. #include <linux/types.h>
  21. #ifndef __user
  22. #define __user
  23. #endif
  24. #include <linux/capability.h>
  25. /*
  26. * POSIX capability types
  27. */
  28. /*
  29. * Opaque capability handle (defined internally by libcap)
  30. * internal capability representation
  31. */
  32. typedef struct _cap_struct *cap_t;
  33. /* "external" capability representation is a (void *) */
  34. /*
  35. * This is the type used to identify capabilities
  36. */
  37. typedef int cap_value_t;
  38. /*
  39. * Set identifiers
  40. */
  41. typedef enum {
  42. CAP_EFFECTIVE=0, /* Specifies the effective flag */
  43. CAP_PERMITTED=1, /* Specifies the permitted flag */
  44. CAP_INHERITABLE=2 /* Specifies the inheritable flag */
  45. } cap_flag_t;
  46. /*
  47. * These are the states available to each capability
  48. */
  49. typedef enum {
  50. CAP_CLEAR=0, /* The flag is cleared/disabled */
  51. CAP_SET=1 /* The flag is set/enabled */
  52. } cap_flag_value_t;
  53. /*
  54. * User-space capability manipulation routines
  55. */
  56. /* libcap/cap_alloc.c */
  57. extern cap_t cap_dup(cap_t);
  58. extern int cap_free(void *);
  59. extern cap_t cap_init(void);
  60. /* libcap/cap_flag.c */
  61. extern int cap_get_flag(cap_t, cap_value_t, cap_flag_t, cap_flag_value_t *);
  62. extern int cap_set_flag(cap_t, cap_flag_t, int, const cap_value_t *,
  63. cap_flag_value_t);
  64. extern int cap_clear(cap_t);
  65. extern int cap_clear_flag(cap_t, cap_flag_t);
  66. /* libcap/cap_file.c */
  67. extern cap_t cap_get_fd(int);
  68. extern cap_t cap_get_file(const char *);
  69. extern int cap_set_fd(int, cap_t);
  70. extern int cap_set_file(const char *, cap_t);
  71. /* libcap/cap_proc.c */
  72. extern cap_t cap_get_proc(void);
  73. extern cap_t cap_get_pid(pid_t);
  74. extern int cap_set_proc(cap_t);
  75. extern int cap_get_bound(cap_value_t);
  76. extern int cap_drop_bound(cap_value_t);
  77. #define CAP_IS_SUPPORTED(cap) (cap_get_bound(cap) >= 0)
  78. /* libcap/cap_extint.c */
  79. extern ssize_t cap_size(cap_t);
  80. extern ssize_t cap_copy_ext(void *, cap_t, ssize_t);
  81. extern cap_t cap_copy_int(const void *);
  82. /* libcap/cap_text.c */
  83. extern cap_t cap_from_text(const char *);
  84. extern char * cap_to_text(cap_t, ssize_t *);
  85. extern int cap_from_name(const char *, cap_value_t *);
  86. extern char * cap_to_name(cap_value_t);
  87. #define CAP_DIFFERS(result, flag) (((result) & (1 << (flag))) != 0)
  88. extern int cap_compare(cap_t, cap_t);
  89. /* system calls - look to libc for function to system call mapping */
  90. extern int capget(cap_user_header_t header, cap_user_data_t data);
  91. extern int capset(cap_user_header_t header, const cap_user_data_t data);
  92. /* deprecated - use cap_get_pid() */
  93. extern int capgetp(pid_t pid, cap_t cap_d);
  94. /* not valid with filesystem capability support - use cap_set_proc() */
  95. extern int capsetp(pid_t pid, cap_t cap_d);
  96. #ifdef __cplusplus
  97. }
  98. #endif
  99. #endif /* _SYS_CAPABILITY_H */