ldap_common.c revision 45916cd2fec6e79bca5dee0421bd39e3c2910d1e
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (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 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include "ldap_common.h"
#include <malloc.h>
#include <synch.h>
#include <syslog.h>
#include <thread.h>
#include <ctype.h>
#include <stdlib.h>
#include <signal.h>
/* getent attributes filters */
#define _F_GETALIASENT "(objectClass=rfc822MailGroup)"
#define _F_GETAUTHNAME "(objectClass=SolarisAuthAttr)"
#define _F_GETAUUSERNAME "(objectClass=SolarisAuditUser)"
#define _F_GETEXECNAME "(objectClass=SolarisExecAttr)"
#define _F_GETGRENT "(objectClass=posixGroup)"
#define _F_GETHOSTENT "(objectClass=ipHost)"
#define _F_GETNETENT "(objectClass=ipNetwork)"
#define _F_GETPROFNAME "(objectClass=SolarisProfAttr)"
#define _F_GETPROTOENT "(objectClass=ipProtocol)"
#define _F_GETPWENT "(objectClass=posixAccount)"
#define _F_GETPRINTERENT "(objectClass=sunPrinter)"
#define _F_GETRPCENT "(objectClass=oncRpc)"
#define _F_GETSERVENT "(objectClass=ipService)"
#define _F_GETSPENT "(objectclass=shadowAccount)"
#define _F_GETUSERNAME "(objectClass=SolarisUserAttr)"
#define _F_GETPROJENT "(objectClass=SolarisProject)"
#define _F_GETTNRHDB "(objectClass=ipTnetHost)"
#define _F_GETTNRHTP "(&(objectClass=ipTnetTemplate)"\
"(SolarisAttrKeyValue=*))"
#define _F_GETENT_SSD "(%s)"
static struct gettablefilter {
char *tablename;
char *tablefilter;
} gettablefilterent[] = {
{(char *)_PASSWD, (char *)_F_GETPWENT},
{(char *)_SHADOW, (char *)_F_GETSPENT},
{(char *)_GROUP, (char *)_F_GETGRENT},
{(char *)_HOSTS, (char *)_F_GETHOSTENT},
{(char *)_NETWORKS, (char *)_F_GETNETENT},
{(char *)_PROTOCOLS, (char *)_F_GETPROTOENT},
{(char *)_RPC, (char *)_F_GETRPCENT},
{(char *)_ALIASES, (char *)_F_GETALIASENT},
{(char *)_SERVICES, (char *)_F_GETSERVENT},
{(char *)_AUUSER, (char *)_F_GETAUUSERNAME},
{(char *)_AUTHATTR, (char *)_F_GETAUTHNAME},
{(char *)_EXECATTR, (char *)_F_GETEXECNAME},
{(char *)_PROFATTR, (char *)_F_GETPROFNAME},
{(char *)_USERATTR, (char *)_F_GETUSERNAME},
{(char *)_PROJECT, (char *)_F_GETPROJENT},
{(char *)_PRINTERS, (char *)_F_GETPRINTERENT},
{(char *)_TNRHDB, (char *)_F_GETTNRHDB},
{(char *)_TNRHTP, (char *)_F_GETTNRHTP},
};
{
switch (rc) {
case NS_LDAP_SUCCESS:
return (NSS_SUCCESS);
case NS_LDAP_NOTFOUND:
return (NSS_NOTFOUND);
case NS_LDAP_PARTIAL:
return (NSS_TRYAGAIN);
case NS_LDAP_INTERNAL:
return (NSS_TRYAGAIN);
else
return (NSS_UNAVAIL);
default:
return (NSS_UNAVAIL);
}
}
char **realfilter, const void *userdata),
const void *userdata)
{
int callbackstat = 0;
int rc;
#ifdef DEBUG
#endif /* DEBUG */
userdata)) != NS_LDAP_SUCCESS) {
(void) __ns_ldap_freeError(&error);
return (rc);
}
/* callback function */
if ((callbackstat =
return ((nss_status_t)NSS_SUCCESS);
}
/* error */
if (callbackstat == NSS_STR_PARSE_PARSE) {
return ((nss_status_t)NSS_NOTFOUND);
}
if (callbackstat == NSS_STR_PARSE_ERANGE) {
return ((nss_status_t)NSS_NOTFOUND);
}
if (callbackstat == NSS_STR_PARSE_NO_ADDR) {
/* No IPV4 address is found */
return ((nss_status_t)NSS_NOTFOUND);
}
return ((nss_status_t)NSS_UNAVAIL);
}
/*
* This function is similar to _nss_ldap_lookup except it does not
* do a callback. It is only used by getnetgrent.c
*/
char **realfilter, const void *userdata),
const void *userdata)
{
int rc;
#ifdef DEBUG
#endif /* DEBUG */
userdata)) != NS_LDAP_SUCCESS) {
(void) __ns_ldap_freeError(&error);
return (rc);
}
return ((nss_status_t)NSS_SUCCESS);
}
/*
*
*/
void
{
#ifdef DEBUG
#endif /* DEBUG */
}
}
/*
* _nss_ldap_destr will free all smalloc'ed variable strings and structures
* before exiting this nsswitch shared backend library. This function is
* called before returning control back to nsswitch.
*/
/*ARGSUSED1*/
{
#ifdef DEBUG
#endif /* DEBUG */
(void) _clean_ldap_backend(be);
return ((nss_status_t)NSS_SUCCESS);
}
/*
* _nss_ldap_setent called before _nss_ldap_getent. This function is
* required by POSIX.
*/
{
struct gettablefilter *gtf;
#ifdef DEBUG
#endif /* DEBUG */
(void) _nss_ldap_endent(be, a);
continue;
break;
}
return ((nss_status_t)NSS_SUCCESS);
}
/*
* _nss_ldap_endent called after _nss_ldap_getent. This function is
* required by POSIX.
*/
/*ARGSUSED1*/
{
#ifdef DEBUG
#endif /* DEBUG */
(void) __ns_ldap_freeError(&error);
}
}
}
return ((nss_status_t)NSS_SUCCESS);
}
/*
*
*/
{
int parsestat = 0;
int retcode = 0;
#ifdef DEBUG
#endif /* DEBUG */
(void) _nss_ldap_setent(be, a);
0, &be->enumcookie,
} else {
}
}
if (retcode != NS_LDAP_SUCCESS) {
(void) __ns_ldap_freeError(&error);
(void) _nss_ldap_endent(be, a);
return (retcode);
} else {
== NSS_STR_PARSE_SUCCESS) {
return ((nss_status_t)NSS_SUCCESS);
}
if (parsestat == NSS_STR_PARSE_PARSE) {
(void) _nss_ldap_endent(be, a);
return ((nss_status_t)NSS_NOTFOUND);
}
if (parsestat == NSS_STR_PARSE_ERANGE) {
(void) _nss_ldap_endent(be, a);
return ((nss_status_t)NSS_NOTFOUND);
}
if (parsestat == NSS_STR_PARSE_NO_ADDR)
/*
* No IPV4 address is found in the current entry.
* It indicates that the entry contains IPV6 addresses
* only. Instead of calling _nss_ldap_endent to
* terminate, get next entry to continue enumeration.
* If it returned NSS_NOTFOUND here,
* gethostent() would return NULL
* and the enumeration would stop prematurely.
*/
goto next_entry;
}
return ((nss_status_t)NSS_SUCCESS);
}
/*
*
*/
{
#ifdef DEBUG
#endif /* DEBUG */
return (0);
return ((nss_backend_t *)be);
}
/*
*
*/
int
{
char *dot;
return (-1);
return (0);
}
*dot = '\0';
return (0);
}
/*
*
*/
int
{
int domainlen, subdomainlen;
/* sanity check */
return (-1);
/* is afterdot a substring of domain? */
return (-1);
if (domainlen == subdomainlen)
return (1);
if (subdomainlen > domainlen)
return (-1);
return (-1);
return (1);
}