nscd_nswconfig.c revision ad0e80f7538b612141768bfda60009eb76550ee7
/*
* 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 <stdlib.h>
#include <libscf_priv.h>
#include <string.h>
#include <assert.h>
#include "nscd_switch.h"
#include "nscd_log.h"
#include "nscd_db.h"
/*
* nscd database for each source. It contains backend
* info (nscd_be_info_t) for each naming database.
* Protected by nscd_src_backend_db_lock.
*/
/*
* nsswitch config monitored by nscd. Protected by
*/
/*
*/
#define NSCD_NUM_SRC_UDEF 16
static void
{
char *me = "free_nscd_nsw_config";
return;
}
void
{
}
void
{
int i;
char *me = "_nscd_free_all_nsw_config";
(me, "freeing all nscd nsw config \n");
(void) rw_wrlock(&nscd_nsw_config_lock);
for (i = 0; i < NSCD_NUM_DB; i++) {
continue;
}
(void) rw_unlock(&nscd_nsw_config_lock);
}
static void
{
char *me = "free_nsw_backend_info_db";
return;
}
void
{
int i;
char *me = " _nscd_free_all_nsw_backend_info_db";
(me, "freeing all nsw backend info db\n");
(void) rw_wrlock(&nscd_src_backend_db_lock);
for (i = 0; i < NSCD_NUM_SRC; i++) {
continue;
}
(void) rw_unlock(&nscd_src_backend_db_lock);
}
/*
* Populate the backend info db for the 'NSCD_NSW_SRC_NAME(srci)'
* (e.g., ldap:passwd, nis:hosts, etc).
*/
static nscd_rc_t
{
int i, size;
const char *dbn;
char *me = "_nscd_populate_nsw_backend_info_db";
for (i = 0; i < NSCD_NUM_DB; i++) {
if (nscd_nsw_config[i] == NULL)
continue;
nsw_cfg = *nscd_nsw_config[i];
dbn = NSCD_NSW_DB_NAME(i);
if (c != 0) {
break;
}
}
/*
* Couldn't find the backend anywhere.
* This is fine, some backend just don't
* support certain databases.
*/
(me, "unable to find backend info "
}
size = sizeof (nscd_be_info_t);
(me, "unable to allocate db entry for "
return (NSCD_NO_MEMORY);
}
(me, "adding be db entry %p for <%s : %s> to db %p: "
(void) _nscd_rdlock((nscd_acc_data_t *)
(void) _nscd_rw_unlock((nscd_acc_data_t *)
}
return (NSCD_SUCCESS);
}
/*
* create data structures (used by the switch engine) based
* on the input switch policy configuration and database
* name and indexes
*/
int dbi,
int compat_basei,
const char *dbn,
const char *cfgstr,
void *swcfgv1,
{
char *me = "_nscd_create_sw_struct";
struct __nsw_lookup_v1 *lkp;
enum __nsw_parse_err err;
int maxsrc;
int j, k;
/*
* if the nsw config string has been parsed into
* a struct __nsw_switchconfig_v1, use it. If not,
* create the struct.
*/
else {
char *cstr;
return (NSCD_NO_MEMORY);
/*
* parse the nsw config string and create
* a struct __nsw_switchconfig_v1
*/
(me, "error: unable to process nsw config string\n");
goto error_exit;
}
}
/* allocate the space for a nscd_nsw_config_t */
rc = NSCD_NO_MEMORY;
(me, "error: unable to allocate an nscd_nsw_config_t\n");
goto error_exit;
}
/* need to know how many backends (sources) */
/*
* allocate an array to store the index for each
* backend (source)
*/
rc = NSCD_NO_MEMORY;
(me, "error: unable to allocate an array for source index\n");
goto error_exit;
}
/*
* set the index for each backend (source)
*/
for (j = 0; j < maxsrc; j++) {
char *usrc;
for (k = 0; k < NSCD_NUM_SRC &&
NSCD_NSW_SRC_NAME(k) != NULL &&
NSCD_NSW_SRC_NAME(k)) != 0; k++);
(me, "unknown nsw source name %s\n",
lkp->service_name);
rc = NSCD_NO_MEMORY;
(me, "unable to strdup() source name\n");
goto error_exit;
}
NSCD_NSW_SRC_NAME(k) = usrc;
if (rc != NSCD_SUCCESS) {
NSCD_NSW_SRC_NAME(k) = NULL;
goto error_exit;
}
} else if (NSCD_NSW_SRC_NAME(k) == NULL) {
/*
* number of user-defined source exceeded
*/
(me, "error: number of user_defined source exceeded\n");
goto error_exit;
}
(me, "setting source index array [%d] = %d (%s)\n",
j, k, lkp->service_name);
src_idx_a[j] = k;
}
/* set it up to reference count the switch policy config */
sizeof (nscd_nsw_config_t **),
rc = NSCD_NO_MEMORY;
(me, "unable to allocate a new nsw config DB\n");
goto error_exit;
}
/* save all the data in the new nscd_nsw_config_t */
rc = NSCD_NO_MEMORY;
goto error_exit;
}
(me, "switch policy \"%s\" for database is \"%s\"\n",
/*
* set default frontend params and if necessary call initf()
* to initialize or override
*/
/*
* this nsw_cfg is not meant to last long, no need
* to set up the nsw state and getent bases, just
* exit with NSCD_SUCCESS
*/
goto error_exit;
}
} else
/*
* activate the new nscd_nsw_config_t, the old one
* will either be deleted or left on the side (and be
* deleted eventually)
*/
(nscd_acc_data_t *)nsw_cfg_p);
/*
* also create a new nsw state base
*/
NSCD_SUCCESS) {
goto error_exit;
}
/*
* also create a new getent context base
*/
goto error_exit;
}
(me, "new nsw config created (database = %s, "
if (rc != NSCD_SUCCESS) {
(void) __nsw_freeconfig_v1(swcfg);
if (nsw_cfg_p)
}
return (rc);
} else
return (NSCD_SUCCESS);
}
static nscd_rc_t
create_nsw_config(int dbi)
{
char *me = "create_nsw_config";
/*
* if pseudo-databases (initf function not defined),
* don't bother now
*/
return (NSCD_SUCCESS);
/* allocate the space for a nscd_nsw_config_t */
(me, "unable to allocate a nsw config structure\n");
return (NSCD_NO_MEMORY);
}
sizeof (nscd_nsw_config_t **),
(me, "unable to allocate a pointer to nsw config structure\n");
return (NSCD_NO_MEMORY);
}
(me, "unable to strdup the db name\n");
return (NSCD_NO_MEMORY);
}
/*
* set default frontend params and then call initf()
* to initialize or override
*/
/*
* activate the new nscd_nsw_config_t
*/
(nscd_acc_data_t *)nsw_cfg_p);
return (NSCD_SUCCESS);
}
{
int i;
char *me = "_nscd_init_all_nsw_config";
(me, "initializing all nsw config\n");
for (i = 0; i < NSCD_NUM_DB; i++) {
return (rc);
}
return (NSCD_SUCCESS);
}
static nscd_rc_t
init_nsw_be_info_db(int srci)
{
char *me = "init_nsw_be_info_db";
(me, "unable to allocate a nsw be info database\n");
return (NSCD_NO_MEMORY);
}
/* set up to reference count the backend info db */
sizeof (nscd_db_t **),
(me, "unable to allocate the pointer to the nsw "
"be info database\n");
return (NSCD_NO_MEMORY);
}
(nscd_acc_data_t *)db_p);
return (NSCD_SUCCESS);
}
{
int i;
char *me = "_nscd_init_all_nsw_be_info_db";
(me, "initializing all nsw be info databases\n");
for (i = 0; i < NSCD_NUM_SRC; i++) {
return (rc);
}
return (NSCD_SUCCESS);
}
{
if (nscd_nsw_config == NULL)
return (NSCD_NO_MEMORY);
return (NSCD_SUCCESS);
}
{
int i;
if (nscd_src_backend_db == NULL)
return (NSCD_NO_MEMORY);
for (i = 0; i < _nscd_cfg_num_nsw_src_all + 1; i++)
_nscd_cfg_num_nsw_src * sizeof (nscd_cfg_id_t));
return (NSCD_SUCCESS);
}
{
int i;
for (i = 0; i < NSCD_NUM_SRC; i++) {
if (NSCD_NSW_SRC_NAME(i) == NULL)
continue;
if (rc != NSCD_SUCCESS)
return (rc);
}
return (NSCD_SUCCESS);
}