mapping.c revision 269e59f9a28bf47e0f463e64fc5af4a408b73b21
/*
* 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
*
*
* This file implements the KMF certificate to name mapping framework.
*/
#include <stdlib.h>
#include <string.h>
#include <dlfcn.h>
#include <libgen.h>
#include <kmftypes.h>
#include <kmfapiP.h>
/* Mappers go in the same dir as plugins. */
#define DEFAULT_MAPPER_DIR KMF_PLUGIN_PATH
static void
{
void (*finalize)(KMF_HANDLE_T);
}
}
/* Optional, not an error if it does not exist. */
}
}
/* The caller is expected to free the returned string. */
char *
{
int len;
return (NULL);
/*
* MAPPER_NAME_TEMPLATE has 2 extra characters (%s) which make up for
* the "/" and the terminating NULL when computing the total length.
*/
return (NULL);
/* Avoid double forward slash if the dir's last character is "/". */
return (pathname);
}
static KMF_RETURN
{
return (KMF_ERR_MAPPER_OPEN);
return (ret);
}
/*
* The mapping framework uses either attributes or the policy file. Those two
* sources are never mixed. We always need a mapper name or a mapper pathname
* but these two are mutually exclusive. Directory can be set only if name is
* set.
*/
{
char *old_curpathname = NULL;
char *old_curoptions = NULL;
return (KMF_ERR_BAD_PARAMETER);
/* Mutually exclusive. */
return (KMF_ERR_BAD_PARAMETER);
return (KMF_ERR_MEMORY);
/* If we only have a name and possibly a dir, we can find the path. */
/*
* If we were given name but the returned path is still NULL,
* return an error.
*/
return (KMF_ERR_MEMORY);
/* Can not exist standalone. */
return (KMF_ERR_BAD_PARAMETER);
/* No attributes define the mapper so let's use the policy database. */
return (KMF_ERR_MEMORY);
/*
* If we were given name but the returned path is still NULL,
* return an error.
*/
return (KMF_ERR_MEMORY);
} else {
/*
* Either a name or a full pathname must be provided whether
* from attributes or the policy database.
*/
return (KMF_ERR_BAD_PARAMETER);
}
/*
* Dlopen the mapper specified by the policy. If anything goes wrong
* just return an error. We do not have to worry about resetting
* curpathname and curoptions to the previous values since there was no
* mapper initialized beforehand.
*
* No mapper was open so stored curoptions and curpathname are
* already NULL and need not to be freed.
*/
return (KMF_ERR_MEMORY);
}
} else
}
return (ret);
}
goto end;
}
/*
* We already have an open mapper, let's see if this is a new mapper
* library.
*/
/* No change in mapper pathname. */
/* New options are empty while we had some before. */
/* We have some options now while we had none before. */
goto err_mem;
/* We got different options. */
goto err_mem;
} else {
/*
* Same options, no free() of current options is
* required.
*/
}
/* Free old options if applicable. */
if (old_curoptions != NULL)
} else {
/*
* This is a new mapper path, clean up the old data and open the
* new mapper.
*/
/* These two are no longer valid. */
goto err_mem;
}
/*
* This will cleanup curoptions and curpathname, and
* ignores the dldesc since it is NULL. Do not free
* tmppath, it will be freed through map->curpathname.
*/
return (ret);
}
}
end:
/* Optional, not an error if it does not exist. */
if (initialize != NULL)
return (ret);
/*
* Try to put the old curpathname and curoptions back there. In theory,
* the application might be able to continue to use the old mapping
* unless we already called cleanup_mapper(). However, it's neither
* recommended nor officially supported. The app should initialize the
* old mapping again.
*/
return (KMF_ERR_MEMORY);
}
{
return (KMF_ERR_BAD_PARAMETER);
return (KMF_OK);
}
{
return (KMF_ERR_BAD_PARAMETER);
return (KMF_ERR_MAPPER_NOT_FOUND);
return (KMF_ERR_FUNCTION_NOT_FOUND);
}
/*
* If mapped_name is non-NULL the caller is later expected to free its Data
* after use.
*/
{
KMF_DATA *);
return (KMF_ERR_BAD_PARAMETER);
return (KMF_ERR_MAPPER_NOT_FOUND);
return (KMF_ERR_FUNCTION_NOT_FOUND);
}
/*
* The caller is responsible for freeing the error string (ie., *errstr) when
* done with it.
*/
{
KMF_HANDLE *h = NULL;
return (KMF_ERR_BAD_PARAMETER);
h = (KMF_HANDLE *)handle;
return (KMF_ERR_MAPPER_NOT_FOUND);
if (err2string == NULL)
return (KMF_ERR_FUNCTION_NOT_FOUND);
return (err2string(h, errstr));
}
void
{
}
{
}
void
{
}
void *
{
}