map_ctrl.c revision 4a19049349b8aa3a6f741b8303a0a60e1fa770c9
/*
* 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"
/*
* DESCRIPTION: Contains functions relating to the creation and manipulation
* of map_ctrl structures. These are used to hold information
* specific to one NIS map.
*
* Because each of these contains a significant amount of state
* information about an individual map they are created (on the
* heap) when a map is opened and destroyed when it is closed.
* The overhead of doing this is less than maintaining a pool
* of map_ctrls.
*
* If two processes access the same map two map_ctrls will be
* created with similar contents (but differing DBM pointers).
* Both will have the same hash value so when one is locked
* access to the other will also be prevented.
*/
#include <unistd.h>
#include <stdlib.h>
#include <syslog.h>
#include <ndbm.h>
#include <string.h>
#include "ypsym.h"
#include "ypdefs.h"
#include "shim.h"
#include "yptol.h"
#include "../ldap_util.h"
extern int hash(char *s);
/*
* Static variables for locking mechanism in
* N2L mode.
* map_id_list: hash table for map lists
* max_map: max number of maps in map_id_list
* it is also used as the map ID for
* unknown maps, see get_map_id()
*/
static int max_map = 0;
/* Switch on parts of ypdefs.h */
/*
* FUNCTION: create_map_ctrl();
*
* DESCRIPTION: Create and a new map_ctrl in a non opened state.
*
* INPUTS: Fully qualified map name
*
* OUTPUTS: Pointer to map_ctrl
* NULL on failure.
*
*/
map_ctrl *
create_map_ctrl(char *name)
{
char *myself = "create_map_ctrl";
return (NULL);
}
/* Clear new map (in case we have to free it) */
map->open_flags = 0;
/*
* Initialize the fields of the map_ctrl. By doing this once here we
* can save a lot of work as map entries are accessed.
*/
"Could not initialize map_ctrl for %s", name);
return (NULL);
}
return (map);
}
/*
* FUNCTION : map_ctrl_init()
*
* DESCRIPTION: Initializes the fields of a map_ctrl structure.
*
* By doing this once (when the map_ctrl is created) we avoid
* numerous other function having to repeat this string
* manipulation.
*
* GIVEN : Pointer to the structure
* Fully qualified name of the map
*
* RETURNS : SUCCESS = map_ctrl fully set up.
* FAILURE = map_ctrl not set up CALLER MUST FREE.
*/
{
char *myself = "map_ctrl_init";
char *p, *q;
/* Save map path for future reference */
"Could not duplicate map path %s", map);
return (FAILURE);
}
/* Work out map's unqualified name from path */
if (NULL == p) {
/* Must be at least a domain and name */
"Could not find separator in map path %s", map);
return (FAILURE);
}
q = p + 1;
/* Check for and remove N2L prefix */
if (yptol_mode) {
/*
* Check for and remove N2L prefix. If not found not a problem
* we open some old style maps during DIT initialization.
*/
q += strlen(NTOL_PREFIX);
} else {
"Working in non N2L mode and path %s "
"contains N2L prefix", name);
}
/* Save unqualified map name */
"Could not duplicate map name %s", q);
return (FAILURE);
}
/* Work out map's domain name from path */
if (q <= name) {
/* Didn't find separator */
"Could not find domain in map path %s", name);
return (FAILURE);
}
"Could not alloc memory for domain in path %s", name);
return (FAILURE);
}
/* Work out extra names required by N2L */
if (yptol_mode) {
/*
* Work out what old style NIS path would have been. This is
* used to check for date of DBM file so add the DBM
* extension.
*/
"Could not alocate memory for "
"traditional map path derived from %s", name);
return (FAILURE);
}
/* Generate qualified TTL file name */
"Could not alocate memory for "
"ttl path derived from %s", name);
return (FAILURE);
}
}
/* Work out hash value */
/* Set up magic number */
/* Null out pointers */
/* No key data yet */
return (SUCCESS);
}
/*
* FUNCTION: get_map_crtl();
*
* DESCRIPTION: Find an existing map_ctrl for a map of a given DBM * (i.e.
* handle) . If none exists return an error.
*
* INPUTS: Map handle
*
* OUTPUTS: Pointer to map_ctrl
* NULL on failure.
*
*/
map_ctrl *
{
/* Check that this really is a map_ctrl not a DBM */
"SHIM called with DBM ptr not map_crtl ptr");
return (NULL);
}
/* Since this is an opaque pointer just cast it */
}
/*
* FUNCTION: dup_map_ctrl()
*
* DESCRIPTION: Duplicates a map_ctrl structure
*
* GIVEN : Map_ctrl to duplicate
*
* RETURNS : Pointer to a new malloced map_ctrl. CALLER MUST FREE
* NULL on failure.
*/
map_ctrl *
{
/*
* Could save a little bit of time by duplicating the static parts
* of the old map but on balance it is cleaner to just make a new one
* from scratch
*/
return (NULL);
/* If old map had open handles duplicate them */
return (NULL);
}
}
return (new_map);
}
/*
* FUNCTION: free_map_crtl();
*
* DESCRIPTION: Free contents of a map_ctr structure and closed any open
* DBM files.
*
* INPUTS: Pointer to pointer to a map_ctrl.
*
* OUTPUTS: Nothing
*
*/
void
{
}
}
}
}
if (yptol_mode) {
}
}
}
}
}
/* Since map_ctrls are now always in malloced memory */
}
/*
* FUNCTION : get_map_name()
*
* DESCRIPTION: Get the name of a map from its map_ctrl. This could be done
* as a simple dereference but this function hides the internal
* implementation of map_ctrl from higher layers.
*
* GIVEN : A map_ctrl pointer
*
* RETURNS : A pointer to the map_ctrl. Higher levels treat this as an
* opaque DBM pointer.
* NULL on failure.
*/
char *
{
return (NULL);
}
/*
* FUNCTION : set_key_data()
*
* DESCRIPTION: Sets up the key data freeing any that already exists.
*
* GIVEN : Pointer to the map_ctrl to set up.
* Datum containing the key. The dptr of this will be set to
* point to the key data.
*
* RETURNS : Nothing
*/
void
{
char *myself = "set_key_data";
/*
* Free up any existing key data. Because each dbm file can only have
* one enumeration going at a time this is safe.
*/
}
/* If nothing in key just return */
return;
/* Something is in the key so must duplicate out of static memory */
} else {
}
/* Set datum to point to malloced version of the data */
return;
}
/*
* FUNCTION : open_yptol_files()
*
* DESCRIPTION: Opens both yptol files for a map. This is called both when a
* map is opened and when it is reopened as a result of an update
* operation. Must be called with map locked.
*
* GIVEN : Initialized map_ctrl
*
* RETURNS : SUCCESS = Maps opened
* FAILURE = Maps not opened (and mess tidied up)
*/
{
/* Open entries map */
/* Maybe we were asked to open a non-existent map. No problem */
return (FAILURE);
}
if (yptol_mode) {
/* Open TTLs map. Must always be writable */
return (FAILURE);
}
}
return (SUCCESS);
}
/*
* FUNCTION : insert_map_in_list()
*
* DESCRIPTION: add a map in map_id_list[]
*
* GIVEN : map name
* map unique ID
*
* RETURNS : SUCCESS = map added
* FAILURE = map not added
*/
{
int index;
/*
* Index in the hash table is computed from the original
* hash function: make sure yptol_newlock is set to false.
*/
return (FAILURE);
}
return (FAILURE);
}
} else {
}
/* insert at begining */
return (SUCCESS);
}
#ifdef NISDB_LDAP_DEBUG
/*
* FUNCTION : dump_map_id_list()
*
* DESCRIPTION: display max_map and dump map_id_list[]
* not called, here for debug convenience only
*
* GIVEN : nothing
*
* RETURNS : nothing
*/
void
{
int i;
"dump_map_id_list: max_map is: %d, dumping map_idlist ...",
max_map);
for (i = 0; i < MAXHASH; i++) {
if (map_id_list[i] == NULL) {
"no map for index %d", i);
} else {
"index %d has the following maps", i);
cur_elt = map_id_list[i];
do {
"%s, unique id: %d",
}
}
}
#endif
/*
* FUNCTION : free_map_id_list()
*
* DESCRIPTION: free all previously allocated elements of map_id_list[]
* reset max_map to 0
*
* GIVEN : nothing
*
* RETURNS : nothing
*/
void
{
int i;
for (i = 0; i < MAXHASH; i++) {
if (map_id_list[i] != NULL) {
cur_elt = map_id_list[i];
do {
map_id_list[i] = NULL;
}
}
max_map = 0;
}
/*
* FUNCTION : map_id_list_init()
*
* DESCRIPTION: initializes map_id_list[] and max_map
*
* GIVEN : nothing
*
* RETURNS : 0 if OK
* -1 if failure
*/
int
{
int domain_num;
int i, j;
char *myself = "map_id_list_init";
char mapbuf[MAXPATHLEN];
int mapbuf_len = sizeof (mapbuf);
int map_name_len;
int seqnum = 0;
int rc = 0;
for (i = 0; i < MAXHASH; i++) {
map_id_list[i] = NULL;
}
for (i = 0; i < domain_num; i++) {
if (map_list) {
}
/* get map list from mapping file */
/* no map for this domain in mapping file */
"%s: get_mapping_map_list()"
" found no map for domain %s",
myself, domain_list[i]);
}
FALSE) {
"%s: add_map_domain_to_list() failed", myself);
return (-1);
}
"%s: no map in domain %s",
myself, domain_list[i]);
continue;
}
/* build long name */
if (map_name_len > mapbuf_len) {
"%s: map name too long for %s",
domain_list[i]);
return (-1);
}
NTOL_PREFIX, map_list[j]);
== FAILURE) {
"%s: failed to insert map %s",
return (-1);
}
seqnum++;
}
}
#ifdef NISDB_LDAP_DEBUG
#endif
/*
* If more maps than allocated spaces in shared memory, that's a failure
* probably need to free previously allocated memory if failure,
* before returning.
*/
rc = -1;
"%s: too many maps (%d)",
}
return (rc);
}
/*
* FUNCTION : get_list_max()
*
* DESCRIPTION: return references to static variables map_id_list
* and max_map;
*
* GIVEN : address for referencing map_id_list
* address for referencing max_map
*
* RETURNS : nothing
*/
void
{
*list = map_id_list;
}