1 /* Copyright (C) 1997-2022 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 Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the 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 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
26 NSS_DECLARE_MODULE_FUNCTIONS (hesiod
)
28 /* Get the declaration of the parser function. */
30 #define STRUCTURE passwd
32 #include <nss/nss_files/files-parse.c>
35 _nss_hesiod_setpwent (int stayopen
)
37 return NSS_STATUS_SUCCESS
;
41 _nss_hesiod_endpwent (void)
43 return NSS_STATUS_SUCCESS
;
46 static enum nss_status
47 lookup (const char *name
, const char *type
, struct passwd
*pwd
,
48 char *buffer
, size_t buflen
, int *errnop
)
50 struct parser_data
*data
= (void *) buffer
;
58 if (hesiod_init (&context
) < 0)
59 return NSS_STATUS_UNAVAIL
;
61 list
= hesiod_resolve (context
, name
, type
);
67 return err
== ENOENT
? NSS_STATUS_NOTFOUND
: NSS_STATUS_UNAVAIL
;
70 linebuflen
= buffer
+ buflen
- data
->linebuffer
;
71 len
= strlen (*list
) + 1;
74 hesiod_free_list (context
, list
);
77 return NSS_STATUS_TRYAGAIN
;
80 memcpy (data
->linebuffer
, *list
, len
);
81 hesiod_free_list (context
, list
);
84 parse_res
= _nss_files_parse_pwent (buffer
, pwd
, data
, buflen
, errnop
);
88 return parse_res
== -1 ? NSS_STATUS_TRYAGAIN
: NSS_STATUS_NOTFOUND
;
91 return NSS_STATUS_SUCCESS
;
95 _nss_hesiod_getpwnam_r (const char *name
, struct passwd
*pwd
,
96 char *buffer
, size_t buflen
, int *errnop
)
98 return lookup (name
, "passwd", pwd
, buffer
, buflen
, errnop
);
102 _nss_hesiod_getpwuid_r (uid_t uid
, struct passwd
*pwd
,
103 char *buffer
, size_t buflen
, int *errnop
)
105 char uidstr
[21]; /* We will probably never have a gid_t with more
108 snprintf (uidstr
, sizeof uidstr
, "%d", uid
);
110 return lookup (uidstr
, "uid", pwd
, buffer
, buflen
, errnop
);