init_os_ctx.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* Copyright 2001-2003 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* lib/krb5/os/init_ctx.c
*
* Copyright 1994 by the Massachusetts Institute of Technology.
* All Rights Reserved.
*
* Export of this software from the United States of America may
* require a specific license from the United States Government.
* It is the responsibility of any person or organization contemplating
* export to obtain such a license before exporting.
*
* WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
* distribute this software and its documentation for any purpose and
* without fee is hereby granted, provided that the above copyright
* notice appear in all copies and that both that copyright notice and
* this permission notice appear in supporting documentation, and that
* the name of M.I.T. not be used in advertising or publicity pertaining
* to distribution of the software without specific, written prior
* permission. Furthermore if you modify this software you must label
* your software as modified software and not distribute it in such a
* fashion that it might be confused with the original M.I.T. software.
* M.I.T. makes no representations about the suitability of
* this software for any purpose. It is provided "as is" without express
* or implied warranty.
*
* krb5_init_contex()
*/
#define NEED_WINDOWS
#include <k5-int.h>
#ifdef macintosh
#include <PreferencesLib.h>
#endif /* macintosh */
static krb5_error_code
char **pname
)
{
if (*pname)
{
return 0;
} else {
return KRB5_CONFIG_CANTOPEN;
}
}
static krb5_error_code
char **pname
)
{
int found = 0;
char *p;
char *name;
struct _stat s;
*pname = 0;
if (!name)
return ENOMEM;
goto cleanup;
if (p < name)
goto cleanup;
p++;
if (found)
else
return 0;
}
/*
* get_from_registry
*
* This will find a profile in the registry. *pbuffer != 0 if we
* found something. Make sure to free(*pbuffer) when done. It will
* return an error code if there is an error the user should know
* about. We maintain the invariant: return value != 0 =>
* *pbuffer == 0.
*/
static krb5_error_code
char** pbuffer,
)
{
krb5_error_code retval = 0;
const char *key_path = "Software\\MIT\\Kerberos5";
const char *value_name = "config";
/* a wannabe assertion */
if (!pbuffer)
{
/*
* We have a programming error! For now, we segfault :)
* There is no good mechanism to deal.
*/
}
*pbuffer = 0;
&hKey)) != ERROR_SUCCESS)
{
/* not a real error */
goto cleanup;
}
{
/* not a real error */
goto cleanup;
}
if (!*pbuffer)
{
goto cleanup;
}
{
/*
* Let's not call it a real error in case it disappears, but
* we need to free so that we say we did not find anything.
*/
*pbuffer = 0;
goto cleanup;
}
if (hKey)
{
/* Let's say we did not find anything: */
*pbuffer = 0;
}
return retval;
}
#endif /* _MSDOS || _WIN32 */
#ifndef _KERNEL
static void
{
#ifndef macintosh
char **cp;
if (files == 0)
return;
#endif
}
static krb5_error_code
{
#ifdef macintosh
UInt32 i;
Boolean foundPreferences = false;
Boolean writtenPreferences = false;
/* After we get the list of files, check whether any of them contain any useful information */
for (i = 0; i < numPreferencesFiles; i++) {
/* It's readable, check if it has anything in the data fork */
}
if (refNum != -1) {
}
if (length != 0) {
foundPreferences = true;
break;
}
}
}
if (!foundPreferences) {
/* We found no profile data in any of those files; try to initialize one */
/* If we are running "secure" do not try to initialize preferences */
if (!secure) {
err = KPGetListOfPreferencesFiles (kpUserPreferences, &preferencesFilesToInit, &numPreferencesFilesToInit);
for (i = 0; i < numPreferencesFilesToInit; i++) {
/* If not readable, create it */
}
/* Initialize it */
}
break;
}
}
}
}
}
}
err = memFullErr;
}
for (i = 0; i < numPreferencesFiles; i++) {
files [i] = preferencesFiles [i];
}
}
if (preferencesFiles != nil)
if (preferencesFilesToInit != nil)
if (err == memFullErr)
return ENOMEM;
return ENOENT;
#else /* !macintosh */
krb5_error_code retval = 0;
char *name = 0;
if (!secure)
{
if (env)
{
}
}
{
/* HKCU */
}
if (!name)
{
/* HKLM */
}
{
/* module dir */
}
if (!name)
{
/* windows dir */
}
if (retval)
return retval;
if (!name)
return KRB5_CONFIG_CANTOPEN; /* should never happen */
files[1] = 0;
#else /* !_MSDOS && !_WIN32 */
char* filepath = 0;
int n_entries, i;
int ent_len;
const char *s, *t;
/* count the distinct filename components */
if (*s == ':')
n_entries++;
}
/* the array is NULL terminated */
if (files == 0)
return ENOMEM;
/* measure, copy, and skip each one */
/*LINTED*/
{
ent_len = t-s;
if (files[i] == 0) {
/* if malloc fails, free the ones that worked */
return ENOMEM;
}
if (*t == 0) {
i++;
break;
}
}
/* cap the array */
files[i] = 0;
#endif /* !_MSDOS && !_WIN32 */
#endif /* !macintosh */
return 0;
}
/* Set the profile paths in the context. If secure is set to TRUE then
do not include user paths (from environment variables, etc.)
*/
static krb5_error_code
{
krb5_error_code retval = 0;
profile_filespec_t *files = 0;
#ifdef KRB5_DNS_LOOKUP
ctx->profile_in_memory = 0;
#endif /* KRB5_DNS_LOOKUP */
if (!retval) {
#ifdef KRB5_DNS_LOOKUP
/* if none of the filenames can be opened use an empty profile */
if (!retval)
}
#endif /* KRB5_DNS_LOOKUP */
}
if (files)
if (retval)
return KRB5_CONFIG_CANTOPEN;
if ((retval == PROF_SECTION_NOTOP) ||
(retval == PROF_SECTION_SYNTAX) ||
(retval == PROF_RELATION_SYNTAX) ||
(retval == PROF_EXTRA_CBRACE) ||
(retval == PROF_MISSING_OBRACE))
return KRB5_CONFIG_BADFORMAT;
return retval;
}
#endif /* !_KERNEL */
{
krb5_error_code retval = 0;
if (ctx->os_context)
return 0;
if (!os_ctx)
return ENOMEM;
os_ctx->time_offset = 0;
os_ctx->usec_offset = 0;
os_ctx->default_ccname = 0;
os_ctx->default_ccprincipal = 0;
#ifndef _KERNEL
#endif
/*
* If there's an error in the profile, return an error. Just
* ignoring the error is a Bad Thing (tm).
*/
return retval;
}
#ifndef _KERNEL
{
krb5_error_code retval = 0;
profile_filespec_t *files = 0;
if (!retval)
if (files)
return KRB5_CONFIG_CANTOPEN;
if ((retval == PROF_SECTION_NOTOP) ||
(retval == PROF_SECTION_SYNTAX) ||
(retval == PROF_RELATION_SYNTAX) ||
(retval == PROF_EXTRA_CBRACE) ||
(retval == PROF_MISSING_OBRACE))
return KRB5_CONFIG_BADFORMAT;
return retval;
}
#endif
#ifndef macintosh
#ifndef _KERNEL
const char **filenames;
{
if (retval)
return retval;
return 0;
}
char ***pfilenames;
{
if (!pfilenames)
return EINVAL;
}
KRB5_DLLIMP void KRB5_CALLCONV
char **filenames;
{
}
#endif /* _KERNEL */
#endif /* macintosh */
#ifndef _KERNEL
{
/* Obsolete interface; always return an error.
This function should be removed next time a major version
number change happens. */
}
if (retval)
return retval;
return KRB5_OBSOLETE_FN;
}
#endif /* _KERNEL */
void
{
if (!os_ctx)
return;
if (os_ctx->default_ccname) {
os_ctx->default_ccname = 0;
}
if (os_ctx->default_ccprincipal) {
os_ctx->default_ccprincipal = 0;
}
ctx->os_context = 0;
#ifndef _KERNEL
}
#endif
}