Source code pulled from OpenBSD for OpenNTPD. The place to contribute to this code is via the OpenBSD CVS tree.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

143 lines
4.3 KiB

28 years ago
28 years ago
28 years ago
28 years ago
28 years ago
28 years ago
28 years ago
28 years ago
28 years ago
28 years ago
  1. .\" $OpenBSD: pw_lock.3,v 1.9 2002/05/01 08:03:30 mpech Exp $
  2. .\"
  3. .\" Copyright (c) 1995
  4. .\" The Regents of the University of California. All rights reserved.
  5. .\"
  6. .\" This code is derived from software developed by the Computer Systems
  7. .\" Engineering group at Lawrence Berkeley Laboratory under DARPA contract
  8. .\" BG 91-66 and contributed to Berkeley.
  9. .\"
  10. .\" Redistribution and use in source and binary forms, with or without
  11. .\" modification, are permitted provided that the following conditions
  12. .\" are met:
  13. .\" 1. Redistributions of source code must retain the above copyright
  14. .\" notice, this list of conditions and the following disclaimer.
  15. .\" 2. Redistributions in binary form must reproduce the above copyright
  16. .\" notice, this list of conditions and the following disclaimer in the
  17. .\" documentation and/or other materials provided with the distribution.
  18. .\" 3. All advertising materials mentioning features or use of this software
  19. .\" must display the following acknowledgement:
  20. .\" This product includes software developed by the University of
  21. .\" California, Berkeley and its contributors.
  22. .\" 4. Neither the name of the University nor the names of its contributors
  23. .\" may be used to endorse or promote products derived from this software
  24. .\" without specific prior written permission.
  25. .\"
  26. .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  27. .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  28. .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  29. .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  30. .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  31. .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  32. .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  33. .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  34. .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  35. .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  36. .\" SUCH DAMAGE.
  37. .\"
  38. .Dd August 20, 2001
  39. .Dt PW_LOCK 3
  40. .Os
  41. .Sh NAME
  42. .Nm pw_lock ,
  43. .Nm pw_mkdb ,
  44. .Nm pw_abort
  45. .Nd passwd file update functions
  46. .Sh SYNOPSIS
  47. .Fd #include <util.h>
  48. .Ft int
  49. .Fn pw_lock "int retries"
  50. .Ft int
  51. .Fn pw_mkdb "char *username" "int pwflags"
  52. .Ft void
  53. .Fn pw_abort
  54. .Sh DESCRIPTION
  55. The
  56. .Fn pw_lock ,
  57. .Fn pw_mkdb ,
  58. and
  59. .Fn pw_abort
  60. functions allow a program to update the system passwd database.
  61. .Pp
  62. The
  63. .Fn pw_lock
  64. function attempts to lock the passwd database by creating the file
  65. .Pa /etc/ptmp
  66. with an exclusive lock (using
  67. .Xr flock 2
  68. semantics) and returns the file descriptor of that file.
  69. If
  70. .Fa retries
  71. is greater than zero,
  72. .Fn pw_lock
  73. will try multiple times to open
  74. .Pa /etc/ptmp ,
  75. waiting one second between tries.
  76. In addition to being a lock file,
  77. .Pa /etc/ptmp
  78. will also hold the contents of the new passwd file.
  79. .Pp
  80. The
  81. .Fn pw_mkdb
  82. function updates the passwd file from the contents of
  83. .Pa /etc/ptmp
  84. via
  85. .Xr pwd_mkdb 8 .
  86. If a
  87. .Fa username
  88. is specified, only the record for the specified user will be updated.
  89. The
  90. .Fa pwflags
  91. are specified by
  92. .Tn OR Ns 'ing
  93. the following values:
  94. .Pp
  95. .Bl -tag -width _PASSWORD_SECUREONLY -offset "xxxx" -compact
  96. .It Dv _PASSWORD_SECUREONLY
  97. only update the secure database file
  98. .Po Pa /etc/spwd.db Pc .
  99. .It Dv _PASSWORD_OMITV7
  100. do not update the Version 7 format password file
  101. .Po Pa /etc/passwd Pc .
  102. .El
  103. .Pp
  104. By default the secure, insecure and Version 7 format password databases
  105. are updated.
  106. You should finish writing to and close the file descriptor returned by
  107. .Fn pw_lock
  108. before calling
  109. .Fn pw_mkdb .
  110. If
  111. .Fn pw_mkdb
  112. fails and you do not wish to retry, you should make sure to call
  113. .Fn pw_abort
  114. to clean up the lock file.
  115. .Pp
  116. The
  117. .Fn pw_abort
  118. function aborts a passwd file update by deleting
  119. .Pa /etc/ptmp .
  120. The passwd database remains unchanged.
  121. .Sh RETURN VALUES
  122. The
  123. .Fn pw_lock
  124. and
  125. .Fn pw_mkdb
  126. functions return \-1 if they are unable to complete properly.
  127. .Sh FILES
  128. .Bl -tag -width /etc/master.passwd -compact
  129. .It Pa /etc/master.passwd
  130. current password file
  131. .It Pa /etc/ptmp
  132. password lock file
  133. .It Pa /etc/passwd
  134. a Version 7 format password file
  135. .It Pa /etc/pwd.db
  136. insecure password database file
  137. .It Pa /etc/spwd.db
  138. secure password database file
  139. .El
  140. .Sh SEE ALSO
  141. .Xr flock 2 ,
  142. .Xr pw_init 3 ,
  143. .Xr pwd_mkdb 8