map_ctrl.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 2003 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 <syslog.h>
#include <ndbm.h>
#include <string.h>
#include "ypsym.h"
#include "ypdefs.h"
#include "shim.h"
#include "yptol.h"
#include "../ldap_util.h"
/* 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);
}