|
Packit |
6c4009 |
/* Copyright (C) 1997-2018 Free Software Foundation, Inc.
|
|
Packit |
6c4009 |
This file is part of the GNU C Library.
|
|
Packit |
6c4009 |
Contributed by Mark Kettenis <kettenis@phys.uva.nl>, 1997.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit |
6c4009 |
modify it under the terms of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License as published by the Free Software Foundation; either
|
|
Packit |
6c4009 |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit |
6c4009 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
6c4009 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
6c4009 |
Lesser General Public License for more details.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
You should have received a copy of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License along with the GNU C Library; if not, see
|
|
Packit |
6c4009 |
<http://www.gnu.org/licenses/>. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <errno.h>
|
|
Packit |
6c4009 |
#include <hesiod.h>
|
|
Packit |
6c4009 |
#include <pwd.h>
|
|
Packit |
6c4009 |
#include <nss.h>
|
|
Packit |
6c4009 |
#include <stdio.h>
|
|
Packit |
6c4009 |
#include <stdlib.h>
|
|
Packit |
6c4009 |
#include <string.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Get the declaration of the parser function. */
|
|
Packit |
6c4009 |
#define ENTNAME pwent
|
|
Packit |
6c4009 |
#define STRUCTURE passwd
|
|
Packit |
6c4009 |
#define EXTERN_PARSER
|
|
Packit |
6c4009 |
#include <nss/nss_files/files-parse.c>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
enum nss_status
|
|
Packit |
6c4009 |
_nss_hesiod_setpwent (int stayopen)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
return NSS_STATUS_SUCCESS;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
enum nss_status
|
|
Packit |
6c4009 |
_nss_hesiod_endpwent (void)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
return NSS_STATUS_SUCCESS;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
static enum nss_status
|
|
Packit |
6c4009 |
lookup (const char *name, const char *type, struct passwd *pwd,
|
|
Packit |
6c4009 |
char *buffer, size_t buflen, int *errnop)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
struct parser_data *data = (void *) buffer;
|
|
Packit |
6c4009 |
size_t linebuflen;
|
|
Packit |
6c4009 |
void *context;
|
|
Packit |
6c4009 |
char **list;
|
|
Packit |
6c4009 |
int parse_res;
|
|
Packit |
6c4009 |
size_t len;
|
|
Packit |
6c4009 |
int olderr = errno;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
if (hesiod_init (&context) < 0)
|
|
Packit |
6c4009 |
return NSS_STATUS_UNAVAIL;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
list = hesiod_resolve (context, name, type);
|
|
Packit |
6c4009 |
if (list == NULL)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
int err = errno;
|
|
Packit |
6c4009 |
hesiod_end (context);
|
|
Packit |
6c4009 |
__set_errno (olderr);
|
|
Packit |
6c4009 |
return err == ENOENT ? NSS_STATUS_NOTFOUND : NSS_STATUS_UNAVAIL;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
linebuflen = buffer + buflen - data->linebuffer;
|
|
Packit |
6c4009 |
len = strlen (*list) + 1;
|
|
Packit |
6c4009 |
if (linebuflen < len)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
hesiod_free_list (context, list);
|
|
Packit |
6c4009 |
hesiod_end (context);
|
|
Packit |
6c4009 |
*errnop = ERANGE;
|
|
Packit |
6c4009 |
return NSS_STATUS_TRYAGAIN;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
memcpy (data->linebuffer, *list, len);
|
|
Packit |
6c4009 |
hesiod_free_list (context, list);
|
|
Packit |
6c4009 |
hesiod_end (context);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
parse_res = _nss_files_parse_pwent (buffer, pwd, data, buflen, errnop);
|
|
Packit |
6c4009 |
if (parse_res < 1)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
__set_errno (olderr);
|
|
Packit |
6c4009 |
return parse_res == -1 ? NSS_STATUS_TRYAGAIN : NSS_STATUS_NOTFOUND;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
return NSS_STATUS_SUCCESS;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
enum nss_status
|
|
Packit |
6c4009 |
_nss_hesiod_getpwnam_r (const char *name, struct passwd *pwd,
|
|
Packit |
6c4009 |
char *buffer, size_t buflen, int *errnop)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
return lookup (name, "passwd", pwd, buffer, buflen, errnop);
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
enum nss_status
|
|
Packit |
6c4009 |
_nss_hesiod_getpwuid_r (uid_t uid, struct passwd *pwd,
|
|
Packit |
6c4009 |
char *buffer, size_t buflen, int *errnop)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
char uidstr[21]; /* We will probably never have a gid_t with more
|
|
Packit |
6c4009 |
than 64 bits. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
snprintf (uidstr, sizeof uidstr, "%d", uid);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
return lookup (uidstr, "uid", pwd, buffer, buflen, errnop);
|
|
Packit |
6c4009 |
}
|