apr_user.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /* Licensed to the Apache Software Foundation (ASF) under one or more
  2. * contributor license agreements. See the NOTICE file distributed with
  3. * this work for additional information regarding copyright ownership.
  4. * The ASF licenses this file to You under the Apache License, Version 2.0
  5. * (the "License"); you may not use this file except in compliance with
  6. * the License. You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef APR_USER_H
  17. #define APR_USER_H
  18. /**
  19. * @file apr_user.h
  20. * @brief APR User ID Services
  21. */
  22. #include "apr.h"
  23. #include "apr_errno.h"
  24. #include "apr_pools.h"
  25. #ifdef __cplusplus
  26. extern "C" {
  27. #endif /* __cplusplus */
  28. /**
  29. * @defgroup apr_user User and Group ID Services
  30. * @ingroup APR
  31. * @{
  32. */
  33. /**
  34. * Structure for determining user ownership.
  35. */
  36. #ifdef WIN32
  37. typedef PSID apr_uid_t;
  38. #else
  39. typedef uid_t apr_uid_t;
  40. #endif
  41. /**
  42. * Structure for determining group ownership.
  43. */
  44. #ifdef WIN32
  45. typedef PSID apr_gid_t;
  46. #else
  47. typedef gid_t apr_gid_t;
  48. #endif
  49. #if APR_HAS_USER
  50. /**
  51. * Get the userid (and groupid) of the calling process
  52. * @param userid Returns the user id
  53. * @param groupid Returns the user's group id
  54. * @param p The pool from which to allocate working space
  55. * @remark This function is available only if APR_HAS_USER is defined.
  56. */
  57. APR_DECLARE(apr_status_t) apr_uid_current(apr_uid_t *userid,
  58. apr_gid_t *groupid,
  59. apr_pool_t *p);
  60. /**
  61. * Get the user name for a specified userid
  62. * @param username Pointer to new string containing user name (on output)
  63. * @param userid The userid
  64. * @param p The pool from which to allocate the string
  65. * @remark This function is available only if APR_HAS_USER is defined.
  66. */
  67. APR_DECLARE(apr_status_t) apr_uid_name_get(char **username, apr_uid_t userid,
  68. apr_pool_t *p);
  69. /**
  70. * Get the userid (and groupid) for the specified username
  71. * @param userid Returns the user id
  72. * @param groupid Returns the user's group id
  73. * @param username The username to look up
  74. * @param p The pool from which to allocate working space
  75. * @remark This function is available only if APR_HAS_USER is defined.
  76. */
  77. APR_DECLARE(apr_status_t) apr_uid_get(apr_uid_t *userid, apr_gid_t *groupid,
  78. const char *username, apr_pool_t *p);
  79. /**
  80. * Get the home directory for the named user
  81. * @param dirname Pointer to new string containing directory name (on output)
  82. * @param username The named user
  83. * @param p The pool from which to allocate the string
  84. * @remark This function is available only if APR_HAS_USER is defined.
  85. */
  86. APR_DECLARE(apr_status_t) apr_uid_homepath_get(char **dirname,
  87. const char *username,
  88. apr_pool_t *p);
  89. /**
  90. * Compare two user identifiers for equality.
  91. * @param left One uid to test
  92. * @param right Another uid to test
  93. * @return APR_SUCCESS if the apr_uid_t structures identify the same user,
  94. * APR_EMISMATCH if not, APR_BADARG if an apr_uid_t is invalid.
  95. * @remark This function is available only if APR_HAS_USER is defined.
  96. */
  97. #if defined(WIN32)
  98. APR_DECLARE(apr_status_t) apr_uid_compare(apr_uid_t left, apr_uid_t right);
  99. #else
  100. #define apr_uid_compare(left,right) (((left) == (right)) ? APR_SUCCESS : APR_EMISMATCH)
  101. #endif
  102. /**
  103. * Get the group name for a specified groupid
  104. * @param groupname Pointer to new string containing group name (on output)
  105. * @param groupid The groupid
  106. * @param p The pool from which to allocate the string
  107. * @remark This function is available only if APR_HAS_USER is defined.
  108. */
  109. APR_DECLARE(apr_status_t) apr_gid_name_get(char **groupname,
  110. apr_gid_t groupid, apr_pool_t *p);
  111. /**
  112. * Get the groupid for a specified group name
  113. * @param groupid Pointer to the group id (on output)
  114. * @param groupname The group name to look up
  115. * @param p The pool from which to allocate the string
  116. * @remark This function is available only if APR_HAS_USER is defined.
  117. */
  118. APR_DECLARE(apr_status_t) apr_gid_get(apr_gid_t *groupid,
  119. const char *groupname, apr_pool_t *p);
  120. /**
  121. * Compare two group identifiers for equality.
  122. * @param left One gid to test
  123. * @param right Another gid to test
  124. * @return APR_SUCCESS if the apr_gid_t structures identify the same group,
  125. * APR_EMISMATCH if not, APR_BADARG if an apr_gid_t is invalid.
  126. * @remark This function is available only if APR_HAS_USER is defined.
  127. */
  128. #if defined(WIN32)
  129. APR_DECLARE(apr_status_t) apr_gid_compare(apr_gid_t left, apr_gid_t right);
  130. #else
  131. #define apr_gid_compare(left,right) (((left) == (right)) ? APR_SUCCESS : APR_EMISMATCH)
  132. #endif
  133. #endif /* ! APR_HAS_USER */
  134. /** @} */
  135. #ifdef __cplusplus
  136. }
  137. #endif
  138. #endif /* ! APR_USER_H */