privs.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Zebra privileges header.
  3. *
  4. * Copyright (C) 2003 Paul Jakma.
  5. *
  6. * This file is part of GNU Zebra.
  7. *
  8. * GNU Zebra is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation; either version 2, or (at your option) any
  11. * later version.
  12. *
  13. * GNU Zebra is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with GNU Zebra; see the file COPYING. If not, write to the Free
  20. * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  21. * 02111-1307, USA.
  22. */
  23. #ifndef _ZEBRA_PRIVS_H
  24. #define _ZEBRA_PRIVS_H
  25. /* list of zebra capabilities */
  26. typedef enum
  27. {
  28. ZCAP_SETID,
  29. ZCAP_BIND,
  30. ZCAP_NET_ADMIN,
  31. ZCAP_SYS_ADMIN,
  32. ZCAP_NET_RAW,
  33. ZCAP_CHROOT,
  34. ZCAP_NICE,
  35. ZCAP_PTRACE,
  36. ZCAP_DAC_OVERRIDE,
  37. ZCAP_READ_SEARCH,
  38. ZCAP_FOWNER,
  39. ZCAP_MAX
  40. } zebra_capabilities_t;
  41. typedef enum
  42. {
  43. ZPRIVS_LOWERED,
  44. ZPRIVS_RAISED,
  45. ZPRIVS_UNKNOWN,
  46. } zebra_privs_current_t;
  47. typedef enum
  48. {
  49. ZPRIVS_RAISE,
  50. ZPRIVS_LOWER,
  51. } zebra_privs_ops_t;
  52. struct zebra_privs_t
  53. {
  54. zebra_capabilities_t *caps_p; /* caps required for operation */
  55. zebra_capabilities_t *caps_i; /* caps to allow inheritance of */
  56. int cap_num_p; /* number of caps in arrays */
  57. int cap_num_i;
  58. const char *user; /* user and group to run as */
  59. const char *group;
  60. const char *vty_group; /* group to chown vty socket to */
  61. /* methods */
  62. int
  63. (*change) (zebra_privs_ops_t); /* change privileges, 0 on success */
  64. zebra_privs_current_t
  65. (*current_state) (void); /* current privilege state */
  66. };
  67. struct zprivs_ids_t
  68. {
  69. /* -1 is undefined */
  70. uid_t uid_priv; /* privileged uid */
  71. uid_t uid_normal; /* normal uid */
  72. gid_t gid_priv; /* privileged uid */
  73. gid_t gid_normal; /* normal uid */
  74. gid_t gid_vty; /* vty gid */
  75. };
  76. /* initialise zebra privileges */
  77. extern void zprivs_init (struct zebra_privs_t *zprivs);
  78. /* drop all and terminate privileges */
  79. extern void zprivs_terminate (struct zebra_privs_t *);
  80. /* query for runtime uid's and gid's, eg vty needs this */
  81. extern void zprivs_get_ids(struct zprivs_ids_t *);
  82. #endif /* _ZEBRA_PRIVS_H */