|
Packit |
6bd9ab |
/*
|
|
Packit |
6bd9ab |
aliases.c - NSS lookup functions for aliases database
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
Copyright (C) 2006 West Consulting
|
|
Packit |
6bd9ab |
Copyright (C) 2006-2015 Arthur de Jong
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
This library is free software; you can redistribute it and/or
|
|
Packit |
6bd9ab |
modify it under the terms of the GNU Lesser General Public
|
|
Packit |
6bd9ab |
License as published by the Free Software Foundation; either
|
|
Packit |
6bd9ab |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
This library is distributed in the hope that it will be useful,
|
|
Packit |
6bd9ab |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
6bd9ab |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
6bd9ab |
Lesser General Public License for more details.
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
You should have received a copy of the GNU Lesser General Public
|
|
Packit |
6bd9ab |
License along with this library; if not, write to the Free Software
|
|
Packit |
6bd9ab |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
Packit |
6bd9ab |
02110-1301 USA
|
|
Packit |
6bd9ab |
*/
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
#include "config.h"
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
#include <string.h>
|
|
Packit |
6bd9ab |
#include <errno.h>
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
#include "prototypes.h"
|
|
Packit |
6bd9ab |
#include "common.h"
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
/* read an alias entry from the stream */
|
|
Packit |
6bd9ab |
static nss_status_t read_aliasent(TFILE *fp, struct aliasent *result,
|
|
Packit |
6bd9ab |
char *buffer, size_t buflen, int *errnop)
|
|
Packit |
6bd9ab |
{
|
|
Packit |
6bd9ab |
int32_t tmpint32, tmp2int32, tmp3int32;
|
|
Packit |
6bd9ab |
size_t bufptr = 0;
|
|
Packit |
6bd9ab |
memset(result, 0, sizeof(struct aliasent));
|
|
Packit |
6bd9ab |
/* read the name of the alias */
|
|
Packit |
6bd9ab |
READ_BUF_STRING(fp, result->alias_name);
|
|
Packit |
6bd9ab |
/* read the members */
|
|
Packit |
6bd9ab |
READ_BUF_STRINGLIST(fp, result->alias_members);
|
|
Packit |
6bd9ab |
/* tmp3int32 holds the number of entries read */
|
|
Packit |
6bd9ab |
result->alias_members_len = tmp3int32;
|
|
Packit |
6bd9ab |
/* fill in remaining gaps in struct */
|
|
Packit |
6bd9ab |
result->alias_local = 0;
|
|
Packit |
6bd9ab |
/* we're done */
|
|
Packit |
6bd9ab |
return NSS_STATUS_SUCCESS;
|
|
Packit |
6bd9ab |
}
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
/* get an alias entry by name */
|
|
Packit |
6bd9ab |
nss_status_t NSS_NAME(getaliasbyname_r)(const char *name,
|
|
Packit |
6bd9ab |
struct aliasent *result,
|
|
Packit |
6bd9ab |
char *buffer, size_t buflen,
|
|
Packit |
6bd9ab |
int *errnop)
|
|
Packit |
6bd9ab |
{
|
|
Packit |
6bd9ab |
NSS_GETONE(NSLCD_ACTION_ALIAS_BYNAME,
|
|
Packit |
6bd9ab |
WRITE_STRING(fp, name),
|
|
Packit |
6bd9ab |
read_aliasent(fp, result, buffer, buflen, errnop));
|
|
Packit |
6bd9ab |
}
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
/* thread-local file pointer to an ongoing request */
|
|
Packit |
6bd9ab |
static TLS TFILE *aliasentfp;
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
/* start a request to read all aliases */
|
|
Packit |
6bd9ab |
nss_status_t NSS_NAME(setaliasent)(void)
|
|
Packit |
6bd9ab |
{
|
|
Packit |
6bd9ab |
NSS_SETENT(aliasentfp);
|
|
Packit |
6bd9ab |
}
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
/* read a single alias entry from the stream */
|
|
Packit |
6bd9ab |
nss_status_t NSS_NAME(getaliasent_r)(struct aliasent *result,
|
|
Packit |
6bd9ab |
char *buffer, size_t buflen, int *errnop)
|
|
Packit |
6bd9ab |
{
|
|
Packit |
6bd9ab |
NSS_GETENT(aliasentfp, NSLCD_ACTION_ALIAS_ALL,
|
|
Packit |
6bd9ab |
read_aliasent(aliasentfp, result, buffer, buflen, errnop));
|
|
Packit |
6bd9ab |
}
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
/* close the stream opened with setaliasent() above */
|
|
Packit |
6bd9ab |
nss_status_t NSS_NAME(endaliasent)(void)
|
|
Packit |
6bd9ab |
{
|
|
Packit |
6bd9ab |
NSS_ENDENT(aliasentfp);
|
|
Packit |
6bd9ab |
}
|