nisplus_common.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright (c) 1991-1999 by Sun Microsystems, Inc.
* All rights reserved.
*/
/*
*
* Common code used by name-service-switch "nisplus" backends
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include "nisplus_common.h"
#include "nisplus_tables.h"
#include <string.h>
#include <stdlib.h>
#define ORGDIR1 ".org_dir"
#define ORGDIR2 ".org_dir."
#define ORGDIRLEN 7
extern u_int __nis_force_hard_lookups;
extern int inet_pton(int, const char *, void *);
static nss_status_t
{
if (nis_res == 0) {
return (NSS_UNAVAIL);
}
switch (NIS_RES_STATUS(nis_res)) {
case NIS_SUCCESS:
case NIS_S_SUCCESS:
case NIS_CBRESULTS:
return (NSS_SUCCESS);
case NIS_NOTFOUND:
case NIS_PARTIAL:
case NIS_NOSUCHNAME:
return (NSS_NOTFOUND);
case NIS_NAMEUNREACHABLE:
case NIS_S_NOTFOUND:
case NIS_TRYAGAIN:
return (NSS_TRYAGAIN);
default:
return (NSS_UNAVAIL);
}
}
const char *name;
int extra_flags;
nis_result **res_p;
{
__nis_force_hard_lookups, 0, 0);
return (switch_err(*res_p));
}
{
int parsestat;
return (res);
}
if (NIS_RES_OBJECT(result) == 0) {
return (NSS_NOTFOUND);
}
if (parsestat == NSS_STR_PARSE_SUCCESS) {
res = NSS_SUCCESS;
} else if (parsestat == NSS_STR_PARSE_ERANGE) {
/* We won't find this otherwise, anyway */
res = NSS_NOTFOUND;
} else if (parsestat == NSS_STR_PARSE_PARSE) {
res = NSS_NOTFOUND;
}
return (res);
}
const char *column_name;
const char *keyname;
{
nis_result *r;
/* make sure we don't overflow stack: 1223320 */
4 /* size of '[' + '=' + ']' + '\0' */
> sizeof (namebuf)) { /* BUFSIZ for array */
return (NSS_NOTFOUND);
}
/*
* Assumes that "keyname" is a null-terminated string.
*/
be->table_name);
__nis_force_hard_lookups, 0, 0);
if (r != 0)
nis_freeresult(r);
return (res);
}
/*
* _nss_nisplus_expand_lookup() -- Takes an unqualified or partially
* qualified name as a key and uses EXPAND_NAME to do a DNS-style lookup.
* Map <name>.<domain> => [<column_name>=<name>]<table>.org_dir.<domain>
* and in the (common) degenerate case
* <name> => [<column_name>=<name>]<table>.org_dir
*
* Can also take a hostaddr as a key. In that case, use the degenerate
* mapping described above.
*/
const char *column_name;
const char *keyname;
const char *table; /* one component table name (no dots) */
{
nis_result *r;
const char *directory;
char *p;
/* make sure we don't overflow stack: 1223320 */
4 /* size of '[' + '=' + ']' + '\0' */
> sizeof (namebuf)) { /* BUFSIZ for array */
return (NSS_NOTFOUND);
}
/*
* Assumes that "keyname" is a null-terminated string.
*/
if (((directory = nis_local_directory()) == 0) ||
return (0);
}
if (p == 0) {
} else {
}
} else {
p = 0;
}
if (p != 0) {
}
__nis_force_hard_lookups, 0, 0);
if (r != 0)
nis_freeresult(r);
return (res);
}
int n_ops;
const char *tblname; /* (Unqualified) name of */
/* NIS+ table */
{
const char *directory = nis_local_directory();
#ifdef DEBUG
#endif /* DEBUG */
if (directory == 0 ||
return (0);
}
return (0);
/* this indicates that the path_list stuff is not initialized */
be->table_path = 0;
be->path_index = 0;
return ((nss_backend_t *)be);
}
/*ARGSUSED*/
void *dummy;
{
if (be != 0) {
/* === Should change to invoke ops[ENDENT] ? */
_nss_nisplus_endent(be, 0);
if (be->table_name != 0) {
}
}
return (NSS_SUCCESS); /* In case anyone is dumb enough to check */
}
static void
{
/*
* Grunge to treat netobj with n_len == 0 as a distinct netobj
*/
/*
* Could trust malloc(0) to do the right thing;
* would rather not.
*/
}
} else {
}
}
}
}
void *a;
{
nis_result *r;
return (NSS_NOTFOUND);
} else {
}
be->path_index++;
nis_freeresult(r);
r = 0;
goto next_table;
}
if (switch_err(r) == NSS_SUCCESS) {
}
if (r != 0)
nis_freeresult(r);
return (res);
}
/*ARGSUSED*/
void *dummy;
{
size_t n;
char *table_name;
char *table_path;
char *p;
if (res)
return (ns_status);
}
return (NSS_UNAVAIL);
}
/*
* If the name is actually a link to a table, then
* the table name will be different (since we followed
* links). We get the name of the real table here.
*/
table_name = (char *)malloc(n);
if (table_name == 0) {
return (NSS_UNAVAIL);
}
/* save table path */
/* find approximate number of path entries */
n = 2; /* +1 for table itself, +1 for path with no colons */
p = table_path;
while ((p = strchr(p, ':')) != 0) {
n++;
p++; /* skip ':' */
}
/* allocate path list to hold 'n' entries */
return (NSS_UNAVAIL);
}
/* steal table_path from res so it is not freed */
}
be->path_index = 0;
/*
* Don't bother freeing no.n_bytes, because we'll
* probably need it
*/
return (NSS_SUCCESS);
}
/*ARGSUSED*/
void *dummy;
{
}
if (be->table_path)
}
be->table_path = 0;
be->path_index = 0;
return (NSS_SUCCESS);
}
/*
* returns NSS_STR_PARSE_PARSE if no aliases found.
*
* Overly loaded interface. Trying to do to many things using one common
* code. Main purpose is to extract cname and aliases from NIS+ entry object(s)
* for netdb databases: hosts, networks, protocols, rpc and services.
*
* hosts have always been special. We have special case code to deal with
* multiple addresses. cnamep is overloaded to indicate this special case,
* when NULL, otherwise it is set to point to the cname field in the caller's
* structure to be populated.
*
* services are weird since they sometimes use 1-1/2 keys, e.g. name and proto
* or port and proto. The NIS+ services table also has an extra column. The
* special argument, proto, when non-NULL, serves the purpose of indicating
* that we are parsing a services entry, and have specified the protocol which
* must be used for screening. It is also non-NULL, and set to the proto field
* of the first NIS+ entry by nis_obj2ent(), in case of enumeration on
* services, and getservbyname/port calls where caller used a null proto,
* which implies the caller can accept "any" protocol with the matching
*/
int
/* IN */
int nobj;
const char *proto;
/* IN-OUT */
char **alias_list; /* beginning of the buffer and alias vector */
char **aliaspp; /* end of the buffer + 1 */
char **cnamep;
/* OUT */
{
}
int
/* IN */
int nobj;
const char *proto;
int af_type; /* address family for host mapping only */
/* IN-OUT */
char **alias_list; /* beginning of the buffer and alias vector */
char **aliaspp; /* end of the buffer + 1 */
char **cnamep;
/* OUT */
{
*count = 0;
if ((char *)alias_list >= *aliaspp) {
/*
* Input condition not met. We must get a contiguous
* area (alias_list, *aliaspp - 1).
*/
return (NSS_STR_PARSE_PARSE);
}
/*
* in every iteration, pull the
* the pointers vector if it is not a duplicate.
*/
char *val;
int len;
return (NSS_STR_PARSE_PARSE);
}
/*
* ASSUMPTION: cname and name field in NIS+ tables are
* null terminated and the len includes the null char.
*/
if (isaddr) {
} else {
if (proto) {
/*
* indicates we screen for a desired proto
* in the case of getservbyname/port()
* with a non-null proto arg
*/
if (len < 2)
return (NSS_STR_PARSE_PARSE);
continue; /* ignore this entry */
}
if (*cnamep == 0) {
/* canonical name, hasn't been set so far */
if (len < 2)
return (NSS_STR_PARSE_PARSE);
if (*aliaspp <=
/*
* Has to be room for the pointer to
* the name we're about to add, as
* well as the final NULL ptr.
*/
return (NSS_STR_PARSE_ERANGE);
}
}
}
if (len > 0) {
int i;
if (isaddr) { /* special case for host addresses */
(void *) &addr) != 1)
continue; /* skip entry */
} else {
/*
* We now allow IPv4 and IPv6 addrs in the
* ipnodes table. If found, convert it to a
* v4 mapped IPv6 address.
*/
(void *) &addr6) != 1) {
(void *) &addr) != 1) {
continue;
/* skip entry */
} else {
&addr,
&addr6);
}
}
}
/* Check for duplicate address */
for (i = 0; i < *count; i++) {
sizeof (struct in_addr))
== 0) {
goto next_obj;
}
} else {
if (memcmp(alias_list[i],
&addr6,
sizeof (struct in6_addr))
== 0) {
goto next_obj;
}
}
}
/*
* Hope nobody treats an h_addr_list[i] as a
* null terminated string. We are not storing
* that here.
*/
else
} else {
/* Check for duplicate alias */
for (i = 0; i < *count; i++) {
goto next_obj;
}
}
}
alias_list[i] = *aliaspp;
/*
* Has to be room for the pointer to
* the address we're about to add, as
* well as the final NULL ptr.
*/
return (NSS_STR_PARSE_ERANGE);
}
if (isaddr) {
sizeof (struct in_addr));
else
sizeof (struct in6_addr));
} else {
}
++(*count);
}
;
}
if (*count == 0)
return (NSS_STR_PARSE_PARSE);
else
return (NSS_STR_PARSE_SUCCESS);
}