capability.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. #include <sys/xattr.h>
  26. #include <linux/xattr.h>
  27. /*
  28. * POSIX capability types
  29. */
  30. /*
  31. * Opaque capability handle (defined internally by libcap)
  32. * internal capability representation
  33. */
  34. typedef struct _cap_struct *cap_t;
  35. /* "external" capability representation is a (void *) */
  36. /*
  37. * This is the type used to identify capabilities
  38. */
  39. typedef int cap_value_t;
  40. /*
  41. * Set identifiers
  42. */
  43. typedef enum {
  44. CAP_EFFECTIVE=0, /* Specifies the effective flag */
  45. CAP_PERMITTED=1, /* Specifies the permitted flag */
  46. CAP_INHERITABLE=2 /* Specifies the inheritable flag */
  47. } cap_flag_t;
  48. /*
  49. * These are the states available to each capability
  50. */
  51. typedef enum {
  52. CAP_CLEAR=0, /* The flag is cleared/disabled */
  53. CAP_SET=1 /* The flag is set/enabled */
  54. } cap_flag_value_t;
  55. /*
  56. * User-space capability manipulation routines
  57. */
  58. /* libcap/cap_alloc.c */
  59. extern cap_t cap_dup(cap_t);
  60. extern int cap_free(void *);
  61. extern cap_t cap_init(void);
  62. /* libcap/cap_flag.c */
  63. extern int cap_get_flag(cap_t, cap_value_t, cap_flag_t, cap_flag_value_t *);
  64. extern int cap_set_flag(cap_t, cap_flag_t, int, const cap_value_t *,
  65. cap_flag_value_t);
  66. extern int cap_clear(cap_t);
  67. extern int cap_clear_flag(cap_t, cap_flag_t);
  68. /* libcap/cap_file.c */
  69. extern cap_t cap_get_fd(int);
  70. extern cap_t cap_get_file(const char *);
  71. extern int cap_set_fd(int, cap_t);
  72. extern int cap_set_file(const char *, cap_t);
  73. /* libcap/cap_proc.c */
  74. extern cap_t cap_get_proc(void);
  75. extern cap_t cap_get_pid(pid_t);
  76. extern int cap_set_proc(cap_t);
  77. extern int cap_get_bound(cap_value_t);
  78. extern int cap_drop_bound(cap_value_t);
  79. #define CAP_IS_SUPPORTED(cap) (cap_get_bound(cap) >= 0)
  80. /* libcap/cap_extint.c */
  81. extern ssize_t cap_size(cap_t);
  82. extern ssize_t cap_copy_ext(void *, cap_t, ssize_t);
  83. extern cap_t cap_copy_int(const void *);
  84. /* libcap/cap_text.c */
  85. extern cap_t cap_from_text(const char *);
  86. extern char * cap_to_text(cap_t, ssize_t *);
  87. extern int cap_from_name(const char *, cap_value_t *);
  88. extern char * cap_to_name(cap_value_t);
  89. #define CAP_DIFFERS(result, flag) (((result) & (1 << (flag))) != 0)
  90. extern int cap_compare(cap_t, cap_t);
  91. /* system calls - look to libc for function to system call mapping */
  92. extern int capset(cap_user_header_t header, cap_user_data_t data);
  93. extern int capget(cap_user_header_t header, const cap_user_data_t data);
  94. /* deprecated - use cap_get_pid() */
  95. extern int capgetp(pid_t pid, cap_t cap_d);
  96. /* not valid with filesystem capability support - use cap_set_proc() */
  97. extern int capsetp(pid_t pid, cap_t cap_d);
  98. #ifdef __cplusplus
  99. }
  100. #endif
  101. #endif /* _SYS_CAPABILITY_H */