1 /* Copyright (C) 1991, 1992, 1995 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
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.
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.
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. */
27 #include <sys/types.h>
30 /* This is the function that all the others are based on.
31 The format of the password file is known only here. */
33 /* Structure containing info kept by each __pwdread caller. */
42 /* Return a chunk of memory containing a pre-initialized `pwdread_info'. */
44 DEFUN_VOID(__pwdalloc
)
46 pwdread_info
*info
= (PTR
) malloc (sizeof(pwdread_info
));
54 /* Read a password entry from STREAM, filling in P. */
56 DEFUN(__pwdread
, (stream
, p
), FILE *stream AND PTR CONST p
)
58 register pwdread_info
*CONST info
= (pwdread_info
*) p
;
69 if (__getline (&info
->buf
, &info
->buflen
, stream
) == -1)
71 while (info
->buf
[0] == '#');
74 end
= strchr (start
, ':');
78 info
->p
.pw_name
= start
;
81 end
= strchr (start
, ':');
85 info
->p
.pw_passwd
= start
;
87 info
->p
.pw_uid
= (uid_t
) strtol (end
+ 1, &end
, 10);
90 info
->p
.pw_gid
= (gid_t
) strtol (end
+ 1, &end
, 10);
95 end
= strchr (start
, ':');
99 info
->p
.pw_gecos
= start
;
102 end
= strchr (start
, ':');
106 info
->p
.pw_dir
= start
;
109 end
= strchr (start
, '\n');
113 info
->p
.pw_shell
= start
;
120 __pwdscan (void **info
, int (*selector
) (struct passwd
*))
127 *info
= __pwdalloc ();
132 stream
= __pwdopen ();
137 while (! feof (stream
))
139 p
= __pwdread (stream
, *info
);
140 if (p
&& (*selector
) (p
))
145 (void) fclose (stream
);