1 /* Copyright (C) 1997-2018 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Mark Kettenis <kettenis@phys.uva.nl>, 1997.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
27 /* Get the declaration of the parser function. */
29 #define STRUCTURE passwd
31 #include <nss/nss_files/files-parse.c>
34 _nss_hesiod_setpwent (int stayopen
)
36 return NSS_STATUS_SUCCESS
;
40 _nss_hesiod_endpwent (void)
42 return NSS_STATUS_SUCCESS
;
45 static enum nss_status
46 lookup (const char *name
, const char *type
, struct passwd
*pwd
,
47 char *buffer
, size_t buflen
, int *errnop
)
49 struct parser_data
*data
= (void *) buffer
;
57 if (hesiod_init (&context
) < 0)
58 return NSS_STATUS_UNAVAIL
;
60 list
= hesiod_resolve (context
, name
, type
);
66 return err
== ENOENT
? NSS_STATUS_NOTFOUND
: NSS_STATUS_UNAVAIL
;
69 linebuflen
= buffer
+ buflen
- data
->linebuffer
;
70 len
= strlen (*list
) + 1;
73 hesiod_free_list (context
, list
);
76 return NSS_STATUS_TRYAGAIN
;
79 memcpy (data
->linebuffer
, *list
, len
);
80 hesiod_free_list (context
, list
);
83 parse_res
= _nss_files_parse_pwent (buffer
, pwd
, data
, buflen
, errnop
);
87 return parse_res
== -1 ? NSS_STATUS_TRYAGAIN
: NSS_STATUS_NOTFOUND
;
90 return NSS_STATUS_SUCCESS
;
94 _nss_hesiod_getpwnam_r (const char *name
, struct passwd
*pwd
,
95 char *buffer
, size_t buflen
, int *errnop
)
97 return lookup (name
, "passwd", pwd
, buffer
, buflen
, errnop
);
101 _nss_hesiod_getpwuid_r (uid_t uid
, struct passwd
*pwd
,
102 char *buffer
, size_t buflen
, int *errnop
)
104 char uidstr
[21]; /* We will probably never have a gid_t with more
107 snprintf (uidstr
, sizeof uidstr
, "%d", uid
);
109 return lookup (uidstr
, "uid", pwd
, buffer
, buflen
, errnop
);