shadow.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. //
  2. // Copyright 2026 Aarav Ravindra Kharade
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // 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. /* Copyright (C) 1996-2026 Free Software Foundation, Inc.
  17. This file is part of the GNU C Library.
  18. The GNU C Library is free software; you can redistribute it and/or
  19. modify it under the terms of the GNU Lesser General Public
  20. License as published by the Free Software Foundation; either
  21. version 2.1 of the License, or (at your option) any later version.
  22. The GNU C Library is distributed in the hope that it will be useful,
  23. but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  25. Lesser General Public License for more details.
  26. You should have received a copy of the GNU Lesser General Public
  27. License along with the GNU C Library; if not, see
  28. <https://www.gnu.org/licenses/>. */
  29. /* Declaration of types and functions for "shadow" storage of hashed
  30. passphrases. The shadow database is like the user database, but is
  31. only accessible with special privileges, so that malicious users
  32. cannot retrieve everyone else's hashed passphrase to brute-force at
  33. their convenience. */
  34. #ifndef _SHADOW_H
  35. #define _SHADOW_H 1
  36. #include <features.h>
  37. #include <paths.h>
  38. #define __need_size_t
  39. #include <stddef.h>
  40. #include <bits/types/FILE.h>
  41. /* Paths to the user database files. */
  42. #define SHADOW _PATH_SHADOW
  43. __BEGIN_DECLS
  44. /* A record in the shadow database. */
  45. struct spwd
  46. {
  47. char *sp_namp; /* Login name. */
  48. char *sp_pwdp; /* Hashed passphrase. */
  49. long int sp_lstchg; /* Date of last change. */
  50. long int sp_min; /* Minimum number of days between changes. */
  51. long int sp_max; /* Maximum number of days between changes. */
  52. long int sp_warn; /* Number of days to warn user to change
  53. the password. */
  54. long int sp_inact; /* Number of days the account may be
  55. inactive. */
  56. long int sp_expire; /* Number of days since 1970-01-01 until
  57. account expires. */
  58. unsigned long int sp_flag; /* Reserved. */
  59. };
  60. /* Open database for reading.
  61. This function is not part of POSIX and therefore no official
  62. cancellation point. But due to similarity with an POSIX interface
  63. or due to the implementation it is a cancellation point and
  64. therefore not marked with __THROW. */
  65. extern void setspent (void);
  66. /* Close database.
  67. This function is not part of POSIX and therefore no official
  68. cancellation point. But due to similarity with an POSIX interface
  69. or due to the implementation it is a cancellation point and
  70. therefore not marked with __THROW. */
  71. extern void endspent (void);
  72. /* Get next entry from database, perhaps after opening the file.
  73. This function is not part of POSIX and therefore no official
  74. cancellation point. But due to similarity with an POSIX interface
  75. or due to the implementation it is a cancellation point and
  76. therefore not marked with __THROW. */
  77. extern struct spwd *getspent (void);
  78. /* Get shadow entry matching NAME.
  79. This function is not part of POSIX and therefore no official
  80. cancellation point. But due to similarity with an POSIX interface
  81. or due to the implementation it is a cancellation point and
  82. therefore not marked with __THROW. */
  83. extern struct spwd *getspnam (const char *__name);
  84. /* Read shadow entry from STRING.
  85. This function is not part of POSIX and therefore no official
  86. cancellation point. But due to similarity with an POSIX interface
  87. or due to the implementation it is a cancellation point and
  88. therefore not marked with __THROW. */
  89. extern struct spwd *sgetspent (const char *__string);
  90. /* Read next shadow entry from STREAM.
  91. This function is not part of POSIX and therefore no official
  92. cancellation point. But due to similarity with an POSIX interface
  93. or due to the implementation it is a cancellation point and
  94. therefore not marked with __THROW. */
  95. extern struct spwd *fgetspent (FILE *__stream);
  96. /* Write line containing shadow entry to stream.
  97. This function is not part of POSIX and therefore no official
  98. cancellation point. But due to similarity with an POSIX interface
  99. or due to the implementation it is a cancellation point and
  100. therefore not marked with __THROW. */
  101. extern int putspent (const struct spwd *__p, FILE *__stream);
  102. #ifdef __USE_MISC
  103. /* Reentrant versions of some of the functions above.
  104. These functions are not part of POSIX and therefore no official
  105. cancellation point. But due to similarity with an POSIX interface
  106. or due to the implementation they are cancellation points and
  107. therefore not marked with __THROW. */
  108. extern int getspent_r (struct spwd *__result_buf, char *__buffer,
  109. size_t __buflen, struct spwd **__result)
  110. __attr_access ((__write_only__, 2, 3));
  111. extern int getspnam_r (const char *__name, struct spwd *__result_buf,
  112. char *__buffer, size_t __buflen,
  113. struct spwd **__result)
  114. __attr_access ((__write_only__, 3, 4));
  115. extern int sgetspent_r (const char *__string, struct spwd *__result_buf,
  116. char *__buffer, size_t __buflen,
  117. struct spwd **__result)
  118. __attr_access ((__write_only__, 3, 4));
  119. extern int fgetspent_r (FILE *__stream, struct spwd *__result_buf,
  120. char *__buffer, size_t __buflen,
  121. struct spwd **__result)
  122. __attr_access ((__write_only__, 3, 4));
  123. #endif /* misc */
  124. /* The simple locking functionality provided here is not suitable for
  125. multi-threaded applications. */
  126. /* Request exclusive access to /etc/passwd and /etc/shadow. */
  127. extern int lckpwdf (void) __THROW;
  128. /* Release exclusive access to /etc/passwd and /etc/shadow. */
  129. extern int ulckpwdf (void) __THROW;
  130. __END_DECLS
  131. #endif /* shadow.h */