init_os_ctx.c revision 159d09a20817016f09b3ea28d1bdada4a336bb91
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* 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"
#ifndef _KERNEL
#include "os-proto.h"
#if 0 /* Solaris Kerberos */
#include "prof_int.h" /* XXX for profile_copy, not public yet */
#endif
#endif
#ifdef USE_LOGIN_LIBRARY
#include "KerberosLoginPrivate.h"
#endif
#if defined(_WIN32)
#include <winsock.h>
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 /* _WIN32 */
#ifndef _KERNEL
static void
{
char **cp;
if (files == 0)
return;
}
/* This function is needed by KfM's KerberosPreferences API
* because it needs to be able to specify "secure" */
{
#if defined(_WIN32)
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 /* !_WIN32 */
char* filepath = 0;
int n_entries, i;
unsigned int ent_len;
const char *s, *t;
#ifdef USE_LOGIN_LIBRARY
/* If __KLAllowHomeDirectoryAccess() == FALSE, we are probably
trying to authenticate to a fileserver for the user's homedir. */
if (!__KLAllowHomeDirectoryAccess ())
secure = 1;
#endif
if (secure) {
} else {
}
/* 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 /* !_WIN32 */
return 0;
}
static krb5_error_code
{
char *file;
;
count += 2;
return errno;
int e = errno;
return e;
}
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).
If kdc is TRUE, include kdc.conf from whereever we expect to find
it. */
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 */
/*ARGSUSED1*/
{
krb5_error_code retval = 0;
#ifdef _WIN32
#endif /* _WIN32 */
os_ctx->time_offset = 0;
os_ctx->usec_offset = 0;
os_ctx->default_ccname = 0;
#ifndef _KERNEL
/*
* If there's an error in the profile, return an error. Just
* ignoring the error is a Bad Thing (tm).
*/
if (!retval) {
#ifdef _WIN32
/* We initialize winsock to version 1.1 but
* we do not care if we succeed or fail.
*/
wVersionRequested = 0x0101;
#endif /* _WIN32 */
}
#endif
return retval;
}
#ifndef _KERNEL
{
}
#endif
#ifndef _KERNEL
{
if (retval)
return retval;
return 0;
}
krb5_get_default_config_files(char ***pfilenames)
{
if (!pfilenames)
return EINVAL;
}
void KRB5_CALLCONV
krb5_free_config_files(char **filenames)
{
}
#endif /* _KERNEL */
#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->default_ccname) {
os_ctx->default_ccname = 0;
}
#ifndef _KERNEL
}
if (ctx->preauth_context) {
}
#endif
}
#ifdef _WIN32
WSACleanup();
#endif /* _WIN32 */