]>
Commit | Line | Data |
---|---|---|
267ca16a UD |
1 | /* Copyright (C) 1991, 1992, 1996 Free Software Foundation, Inc. |
2 | This file is part of the GNU C Library. | |
3 | ||
4 | The GNU C Library is free software; you can redistribute it and/or | |
5 | modify it under the terms of the GNU Library General Public License as | |
6 | published by the Free Software Foundation; either version 2 of the | |
7 | License, or (at your option) any later version. | |
8 | ||
9 | The GNU C Library is distributed in the hope that it will be useful, | |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
12 | Library General Public License for more details. | |
13 | ||
14 | You should have received a copy of the GNU Library General Public | |
15 | License along with the GNU C Library; see the file COPYING.LIB. If | |
16 | not, write to the Free Software Foundation, Inc., 675 Mass Ave, | |
17 | Cambridge, MA 02139, USA. */ | |
18 | ||
267ca16a UD |
19 | #include <stdio.h> |
20 | #include <shadow.h> | |
21 | ||
22 | ||
23 | /* Write an entry to the given stream. | |
24 | This must know the format of the password file. */ | |
25 | int | |
26 | putspent (const struct spwd *p, FILE *stream) | |
27 | { | |
28 | int errors = 0; | |
29 | ||
569c558c | 30 | if (fprintf (stream, "%s:%s:", p->sp_namp, p->sp_pwdp) < 0) |
267ca16a UD |
31 | ++errors; |
32 | ||
c4029823 | 33 | if ((p->sp_lstchg != (long int) -1 |
569c558c | 34 | && fprintf (stream, "%ld:", p->sp_lstchg) < 0) |
c4029823 | 35 | || (p->sp_lstchg == (long int) -1 |
267ca16a UD |
36 | && putc (':', stream) == EOF)) |
37 | ++errors; | |
38 | ||
c4029823 | 39 | if ((p->sp_min != (long int) -1 |
569c558c | 40 | && fprintf (stream, "%ld:", p->sp_min) < 0) |
c4029823 | 41 | || (p->sp_min == (long int) -1 |
267ca16a UD |
42 | && putc (':', stream) == EOF)) |
43 | ++errors; | |
44 | ||
c4029823 | 45 | if ((p->sp_max != (long int) -1 |
569c558c | 46 | && fprintf (stream, "%ld:", p->sp_max) < 0) |
c4029823 | 47 | || (p->sp_max == (long int) -1 |
267ca16a UD |
48 | && putc (':', stream) == EOF)) |
49 | ++errors; | |
50 | ||
c4029823 | 51 | if ((p->sp_warn != (long int) -1 |
569c558c | 52 | && fprintf (stream, "%ld:", p->sp_warn) < 0) |
c4029823 | 53 | || (p->sp_warn == (long int) -1 |
267ca16a UD |
54 | && putc (':', stream) == EOF)) |
55 | ++errors; | |
56 | ||
c4029823 | 57 | if ((p->sp_inact != (long int) -1 |
569c558c | 58 | && fprintf (stream, "%ld:", p->sp_inact) < 0) |
c4029823 | 59 | || (p->sp_inact == (long int) -1 |
267ca16a UD |
60 | && putc (':', stream) == EOF)) |
61 | ++errors; | |
62 | ||
c4029823 | 63 | if ((p->sp_expire != (long int) -1 |
569c558c | 64 | && fprintf (stream, "%ld:", p->sp_expire) < 0) |
c4029823 | 65 | || (p->sp_expire == (long int) -1 |
267ca16a UD |
66 | && putc (':', stream) == EOF)) |
67 | ++errors; | |
68 | ||
11336c16 UD |
69 | if (p->sp_flag != ~0ul |
70 | && fprintf (stream, "%ld", p->sp_flag) < 0) | |
267ca16a UD |
71 | ++errors; |
72 | ||
73 | if (putc ('\n', stream) == EOF) | |
74 | ++errors; | |
75 | ||
76 | return errors ? -1 : 0; | |
77 | } |