Move some infra bits of lib/krb5/ to lib/base/ (2)
This is the second of two commits in a series that must be picked together. This series of two commits moves parts of lib/krb5/ infrastructure functionality to lib/base/, leaving behind wrappers. Some parts of libkrb5 are entirely generic or easily made so, and could be useful in various parts of Heimdal that are not specific to the krb5 API, such as: - lib/gssapi/ (especially since the integration of NegoEx) - lib/hx509/ - bx509d (which should really move out of kdc/) For the above we need to move these bits of lib/krb5/: - lib/krb5/config_file.c (all of it, leaving forwardings behind) - lib/krb5/config_reg.c (all of it) - lib/krb5/plugin.c (all of it, leaving forwardings behind) - lib/krb5/log.c (all of it, ditto) - lib/krb5/heim_err.et (all of it) And because of those two, these too must also move: - lib/krb5/expand_path.c (all of it, leaving forwardings behind) - lib/krb5/warn.c (just the warning functions, ditto) The changes to the moved files are mostly quite straightforward and are best reviewed with --word-diff=color. We're also creating a heim_context and a heim API to go with it. But it's as thin as possible, with as little state as necessary to enable this move. Functions for dealing with error messages use callbacks. Moving plugin.c does have one knock-on effect on all users of the old krb5 plugin API (which remains), which is that a global search and replace of struct krb5_plugin_data to struct heim_plugin_data was needed, though the layout and size of that structure doesn't change, so the ABI doesn't either. As well, we now build lib/vers/ and lib/com_err/ before lib/base/ so as to be able to move lib/krb5/heim_err.et to lib/base/ so that we can make use of HEIM_ERR_* in lib/base/, specifically in the files that moved. Once this is all done we'll be able to use config files and plugins in lib/hx509/, we'll be able to move bx509d out of kdc/, and so on. Most if not all of the new functions in lib/base/ are Heimdal-private, thus calling conventions for them are not declared. Status: - builds and passes CIs (Travis, Appveyor) - ran make check-valgrind and no new leaks or other memory errors - ready for review HOW TO REVIEW: $ # Review file moves: $ git log --stat -n1 HEAD^ $ $ # Review changes to moved files using --word-diff=color $ git log -p -b -w --word-diff=color HEAD^..HEAD \ lib/base/config_file.c \ lib/base/config_reg.c \ lib/base/expand_path.c \ lib/base/warn.c \ lib/krb5/config_file.c \ lib/krb5/config_reg.c \ lib/krb5/expand_path.c \ lib/krb5/warn.c $ $ # Review the whole thing, possibly adding -b and/or -w, and $ # maybe --word-diff=color: $ git log -p origin/master..HEAD $ git log -p -b -w origin/master..HEAD $ git log -p -b -w --word-diff=color origin/master..HEAD TBD (future commits): - make lib/gssapi use the new heimbase functions - move kx509/bx509d common code to lib/hx509/ or other approp. location - move bx509d out of kdc/
This commit is contained in:
@@ -11,42 +11,67 @@ IMPLEMENT_TLS += dll.c
|
||||
AM_CPPFLAGS += -DHEIM_BASE_MAINTAINER
|
||||
endif
|
||||
|
||||
AM_CPPFLAGS += $(ROKEN_RENAME)
|
||||
AM_CPPFLAGS += $(ROKEN_RENAME) -I../com_err -I$(srcdir)/../com_err
|
||||
|
||||
lib_LTLIBRARIES = libheimbase.la
|
||||
check_PROGRAMS = test_base
|
||||
|
||||
libheimbase_la_LDFLAGS = -version-info 1:0:0
|
||||
|
||||
if FRAMEWORK_COREFOUNDATION
|
||||
libheimbase_la_LDFLAGS += -framework CoreFoundation
|
||||
endif
|
||||
|
||||
TESTS = test_base
|
||||
|
||||
if versionscript
|
||||
libheimbase_la_LDFLAGS += $(LDFLAGS_VERSION_SCRIPT)$(srcdir)/version-script.map
|
||||
endif
|
||||
|
||||
libheimbase_la_LIBADD = $(PTHREAD_LIBADD)
|
||||
libheimbase_la_LIBADD = $(PTHREAD_LIBADD) $(LIB_dlopen) $(LIB_com_err)
|
||||
|
||||
include_HEADERS = heimbase.h
|
||||
include_HEADERS = heimbase.h common_plugin.h
|
||||
|
||||
ERR_FILES = heim_err.c
|
||||
|
||||
dist_libheimbase_la_SOURCES = \
|
||||
array.c \
|
||||
baselocl.h \
|
||||
bsearch.c \
|
||||
bool.c \
|
||||
common_plugin.h \
|
||||
config_file.c \
|
||||
context.c \
|
||||
data.c \
|
||||
db.c \
|
||||
dict.c \
|
||||
$(IMPLEMENT_TLS) \
|
||||
error.c \
|
||||
expand_path.c \
|
||||
heimbase.c \
|
||||
heimbasepriv.h \
|
||||
json.c \
|
||||
log.c \
|
||||
null.c \
|
||||
number.c \
|
||||
plugin.c \
|
||||
roken_rename.h \
|
||||
string.c
|
||||
string.c \
|
||||
warn.c
|
||||
|
||||
nodist_libheimbase_la_SOURCES = $(ES)
|
||||
nodist_libheimbase_la_SOURCES = $(ES) $(ERR_FILES)
|
||||
|
||||
$(libheimbase_la_OBJECTS): $(srcdir)/heimbase-protos.h heim_err.h
|
||||
|
||||
$(srcdir)/heimbase-protos.h: $(dist_libheimbase_la_SOURCES)
|
||||
cd $(srcdir) && \
|
||||
perl ../../cf/make-proto.pl -q -P comment -o heimbase-protos.h $(dist_libheimbase_la_SOURCES) || \
|
||||
rm -f heimbase-protos.h
|
||||
|
||||
$(srcdir)/heimbase-private.h: $(dist_libheimbase_la_SOURCES)
|
||||
cd $(srcdir) && \
|
||||
perl ../../cf/make-proto.pl -q -P comment -p heimbase-private.h $(dist_libheimbase_la_SOURCES) || \
|
||||
rm -f heimbase-private.h
|
||||
|
||||
# install these?
|
||||
|
||||
@@ -54,9 +79,15 @@ libheimbase_la_DEPENDENCIES = version-script.map
|
||||
|
||||
test_base_LDADD = libheimbase.la $(LIB_roken)
|
||||
|
||||
CLEANFILES = base64.c test_db.json
|
||||
CLEANFILES = base64.c test_db.json heim_err.c heim_err.h
|
||||
|
||||
EXTRA_DIST = NTMakefile version-script.map
|
||||
EXTRA_DIST = NTMakefile version-script.map config_reg.c heim_err.et
|
||||
|
||||
dist_include_HEADERS = heimbase-protos.h
|
||||
|
||||
nodist_include_HEADERS = heim_err.h
|
||||
|
||||
heim_err.h: heim_err.et
|
||||
|
||||
base64.c:
|
||||
rm -f base64.c
|
||||
|
@@ -35,31 +35,79 @@ intcflags=-I$(SRCDIR) -I$(OBJ)
|
||||
|
||||
!include ../../windows/NTMakefile.w32
|
||||
|
||||
INCFILES=$(INCDIR)\heimbase.h
|
||||
INCFILES= \
|
||||
$(INCDIR)\heimbase.h \
|
||||
$(INCDIR)\heimbase-protos.h \
|
||||
$(INCDIR)\heim_err.h \
|
||||
$(INCDIR)\common_plugin.h
|
||||
|
||||
test_binaries = $(OBJ)\test_base.exe
|
||||
|
||||
libheimbase_SOURCES = \
|
||||
array.c \
|
||||
bool.c \
|
||||
bsearch.c \
|
||||
config_file.c \
|
||||
config_reg.c \
|
||||
context.c \
|
||||
data.c \
|
||||
db.c \
|
||||
dict.c \
|
||||
dll.c \
|
||||
error.c \
|
||||
expand_path.c \
|
||||
heimbase.c \
|
||||
json.c \
|
||||
log.c \
|
||||
null.c \
|
||||
number.c \
|
||||
plugin.c \
|
||||
string.c \
|
||||
warn.c
|
||||
|
||||
libheimbase_OBJS = \
|
||||
$(OBJ)\array.obj \
|
||||
$(OBJ)\bool.obj \
|
||||
$(OBJ)\bsearch.obj \
|
||||
$(OBJ)\config_file.obj \
|
||||
$(OBJ)\config_reg.obj \
|
||||
$(OBJ)\context.obj \
|
||||
$(OBJ)\data.obj \
|
||||
$(OBJ)\db.obj \
|
||||
$(OBJ)\dict.obj \
|
||||
$(OBJ)\dll.obj \
|
||||
$(OBJ)\error.obj \
|
||||
$(OBJ)\expand_path.obj \
|
||||
$(OBJ)\heimbase.obj \
|
||||
$(OBJ)\json.obj \
|
||||
$(OBJ)\log.obj \
|
||||
$(OBJ)\null.obj \
|
||||
$(OBJ)\number.obj \
|
||||
$(OBJ)\string.obj
|
||||
$(OBJ)\plugin.obj \
|
||||
$(OBJ)\string.obj \
|
||||
$(OBJ)\warn.obj
|
||||
|
||||
$(LIBHEIMBASE): $(libheimbase_OBJS)
|
||||
$(LIBCON_C) -OUT:$@ $(LIBROKEN) @<<
|
||||
libheimbase_gen_OBJS= $(OBJ)\heim_err.obj
|
||||
|
||||
$(LIBHEIMBASE): $(libheimbase_OBJS) $(libheimbase_gen_OBJS)
|
||||
$(LIBCON_C) -OUT:$@ $(LIBROKEN) $(PTHREAD_LIB) Secur32.lib Shell32.lib Advapi32.lib @<<
|
||||
$(libheimbase_OBJS: =
|
||||
)
|
||||
$(libheimbase_gen_OBJS: =
|
||||
)
|
||||
<<
|
||||
|
||||
$(OBJ)\heimbase-protos.h: $(libheimbase_SOURCES)
|
||||
$(PERL) ..\..\cf\make-proto.pl -E KRB5_LIB -q -P remove -o $(OBJ)\heimbase-protos.h $(libheimbase_SOURCES) || $(RM) -f $(OBJ)\heimbase-protos.h
|
||||
|
||||
$(OBJ)\heimbase-private.h: $(libheimbase_SOURCES)
|
||||
$(PERL) ..\..\cf\make-proto.pl -q -P remove -p $(OBJ)\heimbase-private.h $(libheimbase_SOURCES) || $(RM) -f $(OBJ)\heimbase-private.h
|
||||
|
||||
$(OBJ)\heim_err.c $(OBJ)\heim_err.h: heim_err.et
|
||||
cd $(OBJ)
|
||||
$(BINDIR)\compile_et.exe $(SRCDIR)\heim_err.et
|
||||
cd $(SRCDIR)
|
||||
|
||||
test:: test-binaries test-run
|
||||
|
||||
test-run:
|
||||
|
@@ -37,6 +37,13 @@
|
||||
|
||||
#include <roken.h>
|
||||
|
||||
#define ISTILDE(x) (x == '~')
|
||||
#ifdef _WIN32
|
||||
# define ISPATHSEP(x) (x == '/' || x =='\\')
|
||||
#else
|
||||
# define ISPATHSEP(x) (x == '/')
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYS_SELECT_H
|
||||
#include <sys/select.h>
|
||||
#endif
|
||||
|
95
lib/base/common_plugin.h
Normal file
95
lib/base/common_plugin.h
Normal file
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Copyright (c) 2006 - 2020 Kungliga Tekniska Högskolan
|
||||
* (Royal Institute of Technology, Stockholm, Sweden).
|
||||
* All rights reserved.
|
||||
*
|
||||
* Portions Copyright (c) 2018 AuriStor, Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef HEIMDAL_BASE_COMMON_PLUGIN_H
|
||||
#define HEIMDAL_BASE_COMMON_PLUGIN_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#ifndef HEIM_CALLCONV
|
||||
#define HEIM_CALLCONV __stdcall
|
||||
#endif
|
||||
#ifndef HEIM_LIB_CALL
|
||||
#define HEIM_LIB_CALL __stdcall
|
||||
#endif
|
||||
#else
|
||||
#ifndef HEIM_CALLCONV
|
||||
#define HEIM_CALLCONV
|
||||
#endif
|
||||
#ifndef HEIM_LIB_CALL
|
||||
#define HEIM_LIB_CALL
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* For krb5 plugins, this is a krb5_context */
|
||||
typedef struct heim_pcontext_s *heim_pcontext;
|
||||
|
||||
/*
|
||||
* All plugin function tables extend the following structure.
|
||||
*/
|
||||
struct heim_plugin_common_ftable_desc {
|
||||
int version;
|
||||
int (HEIM_LIB_CALL *init)(heim_pcontext, void **);
|
||||
void (HEIM_LIB_CALL *fini)(void *);
|
||||
};
|
||||
typedef struct heim_plugin_common_ftable_desc heim_plugin_common_ftable;
|
||||
typedef struct heim_plugin_common_ftable_desc *heim_plugin_common_ftable_p;
|
||||
typedef struct heim_plugin_common_ftable_desc * const heim_plugin_common_ftable_cp;
|
||||
|
||||
typedef int
|
||||
(HEIM_CALLCONV heim_plugin_load_ft)(heim_pcontext context,
|
||||
heim_get_instance_func_t *func,
|
||||
size_t *n_ftables,
|
||||
heim_plugin_common_ftable_cp **ftables);
|
||||
|
||||
typedef heim_plugin_load_ft *heim_plugin_load_t;
|
||||
|
||||
/* For source backwards-compatibility */
|
||||
typedef struct heim_plugin_common_ftable_desc krb5_plugin_common_ftable;
|
||||
typedef struct heim_plugin_common_ftable_desc *krb5_plugin_common_ftable_p;
|
||||
typedef struct heim_plugin_common_ftable_desc * const krb5_plugin_common_ftable_cp;
|
||||
typedef heim_plugin_load_ft krb5_plugin_load_ft;
|
||||
typedef heim_plugin_load_ft *krb5_plugin_load_t;
|
||||
|
||||
/*
|
||||
* All plugins must export a function named "<type>_plugin_load" with
|
||||
* a signature of:
|
||||
*
|
||||
* int HEIM_CALLCONV
|
||||
* <type>_plugin_load(heim_pcontext context,
|
||||
* heim_get_instance_func_t *func,
|
||||
* size_t *n_ftables,
|
||||
* const heim_plugin_common_ftable *const **ftables);
|
||||
*/
|
||||
#endif /* HEIMDAL_BASE_COMMON_PLUGIN_H */
|
File diff suppressed because it is too large
Load Diff
@@ -29,7 +29,7 @@
|
||||
*
|
||||
**********************************************************************/
|
||||
|
||||
#include "krb5_locl.h"
|
||||
#include "baselocl.h"
|
||||
|
||||
#ifndef _WIN32
|
||||
#error config_reg.c is only for Windows
|
||||
@@ -41,9 +41,6 @@
|
||||
#define MAX_DWORD 0xFFFFFFFF
|
||||
#endif
|
||||
|
||||
#define REGPATH_KERBEROS "SOFTWARE\\Kerberos"
|
||||
#define REGPATH_HEIMDAL "SOFTWARE\\Heimdal"
|
||||
|
||||
/**
|
||||
* Store a string as a registry value of the specified type
|
||||
*
|
||||
@@ -83,14 +80,14 @@
|
||||
*
|
||||
* @retval 0 if success or non-zero on error.
|
||||
* If non-zero is returned, an error message has been set using
|
||||
* krb5_set_error_message().
|
||||
* heim_set_error_message().
|
||||
*
|
||||
*/
|
||||
KRB5_LIB_FUNCTION int KRB5_LIB_CALL
|
||||
_krb5_store_string_to_reg_value(krb5_context context,
|
||||
HKEY key, const char * valuename,
|
||||
DWORD type, const char *data, DWORD cb_data,
|
||||
const char * separator)
|
||||
int
|
||||
heim_store_string_to_reg_value(heim_context context,
|
||||
HKEY key, const char *valuename,
|
||||
DWORD type, const char *data, DWORD cb_data,
|
||||
const char *separator)
|
||||
{
|
||||
LONG rcode;
|
||||
DWORD dwData;
|
||||
@@ -100,7 +97,7 @@ _krb5_store_string_to_reg_value(krb5_context context,
|
||||
if (data == NULL)
|
||||
{
|
||||
if (context)
|
||||
krb5_set_error_message(context, 0,
|
||||
heim_set_error_message(context, 0,
|
||||
"'data' must not be NULL");
|
||||
return -1;
|
||||
}
|
||||
@@ -113,7 +110,7 @@ _krb5_store_string_to_reg_value(krb5_context context,
|
||||
cb_data >= sizeof(static_buffer))
|
||||
{
|
||||
if (context)
|
||||
krb5_set_error_message(context, 0, "cb_data too big");
|
||||
heim_set_error_message(context, 0, "cb_data too big");
|
||||
return -1;
|
||||
}
|
||||
else if (data[cb_data-1] != '\0')
|
||||
@@ -146,7 +143,7 @@ _krb5_store_string_to_reg_value(krb5_context context,
|
||||
if (rcode)
|
||||
{
|
||||
if (context)
|
||||
krb5_set_error_message(context, 0,
|
||||
heim_set_error_message(context, 0,
|
||||
"Unexpected error when setting registry value %s gle 0x%x",
|
||||
valuename,
|
||||
GetLastError());
|
||||
@@ -171,7 +168,7 @@ _krb5_store_string_to_reg_value(krb5_context context,
|
||||
if (rcode)
|
||||
{
|
||||
if (context)
|
||||
krb5_set_error_message(context, 0,
|
||||
heim_set_error_message(context, 0,
|
||||
"Unexpected error when setting registry value %s gle 0x%x",
|
||||
valuename,
|
||||
GetLastError());
|
||||
@@ -183,7 +180,7 @@ _krb5_store_string_to_reg_value(krb5_context context,
|
||||
if ( !StrToIntExA( data, STIF_SUPPORT_HEX, &dwData) )
|
||||
{
|
||||
if (context)
|
||||
krb5_set_error_message(context, 0,
|
||||
heim_set_error_message(context, 0,
|
||||
"Unexpected error when parsing %s as number gle 0x%x",
|
||||
data,
|
||||
GetLastError());
|
||||
@@ -193,7 +190,7 @@ _krb5_store_string_to_reg_value(krb5_context context,
|
||||
if (rcode)
|
||||
{
|
||||
if (context)
|
||||
krb5_set_error_message(context, 0,
|
||||
heim_set_error_message(context, 0,
|
||||
"Unexpected error when setting registry value %s gle 0x%x",
|
||||
valuename,
|
||||
GetLastError());
|
||||
@@ -210,15 +207,15 @@ _krb5_store_string_to_reg_value(krb5_context context,
|
||||
/**
|
||||
* Parse a registry value as a string
|
||||
*
|
||||
* @see _krb5_parse_reg_value_as_multi_string()
|
||||
* @see heim_parse_reg_value_as_multi_string()
|
||||
*/
|
||||
KRB5_LIB_FUNCTION char * KRB5_LIB_CALL
|
||||
_krb5_parse_reg_value_as_string(krb5_context context,
|
||||
HKEY key, const char * valuename,
|
||||
DWORD type, DWORD cb_data)
|
||||
char *
|
||||
heim_parse_reg_value_as_string(heim_context context,
|
||||
HKEY key, const char * valuename,
|
||||
DWORD type, DWORD cb_data)
|
||||
{
|
||||
return _krb5_parse_reg_value_as_multi_string(context, key, valuename,
|
||||
type, cb_data, " ");
|
||||
return heim_parse_reg_value_as_multi_string(context, key, valuename,
|
||||
type, cb_data, " ");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -249,12 +246,12 @@ _krb5_parse_reg_value_as_string(krb5_context context,
|
||||
*
|
||||
* @retval The registry value string, or NULL if there was an error.
|
||||
* If NULL is returned, an error message has been set using
|
||||
* krb5_set_error_message().
|
||||
* heim_set_error_message().
|
||||
*/
|
||||
KRB5_LIB_FUNCTION char * KRB5_LIB_CALL
|
||||
_krb5_parse_reg_value_as_multi_string(krb5_context context,
|
||||
HKEY key, const char * valuename,
|
||||
DWORD type, DWORD cb_data, char *separator)
|
||||
char *
|
||||
heim_parse_reg_value_as_multi_string(heim_context context,
|
||||
HKEY key, const char * valuename,
|
||||
DWORD type, DWORD cb_data, char *separator)
|
||||
{
|
||||
LONG rcode = ERROR_MORE_DATA;
|
||||
|
||||
@@ -293,7 +290,7 @@ _krb5_parse_reg_value_as_multi_string(krb5_context context,
|
||||
case REG_DWORD:
|
||||
if (cb_data != sizeof(DWORD)) {
|
||||
if (context)
|
||||
krb5_set_error_message(context, 0,
|
||||
heim_set_error_message(context, 0,
|
||||
"Unexpected size while reading registry value %s",
|
||||
valuename);
|
||||
return NULL;
|
||||
@@ -322,7 +319,7 @@ _krb5_parse_reg_value_as_multi_string(krb5_context context,
|
||||
|
||||
default:
|
||||
if (context)
|
||||
krb5_set_error_message(context, 0,
|
||||
heim_set_error_message(context, 0,
|
||||
"Unexpected type while reading registry value %s",
|
||||
valuename);
|
||||
return NULL;
|
||||
@@ -347,7 +344,7 @@ _krb5_parse_reg_value_as_multi_string(krb5_context context,
|
||||
* its value. Ideally we would retry the query in a loop. */
|
||||
|
||||
if (context)
|
||||
krb5_set_error_message(context, 0,
|
||||
heim_set_error_message(context, 0,
|
||||
"Unexpected error while reading registry value %s",
|
||||
valuename);
|
||||
goto done;
|
||||
@@ -355,7 +352,7 @@ _krb5_parse_reg_value_as_multi_string(krb5_context context,
|
||||
|
||||
if (cb_data > cb_alloc || cb_data == 0) {
|
||||
if (context)
|
||||
krb5_set_error_message(context, 0,
|
||||
heim_set_error_message(context, 0,
|
||||
"Unexpected size while reading registry value %s",
|
||||
valuename);
|
||||
goto done;
|
||||
@@ -405,7 +402,7 @@ have_data:
|
||||
ret_string = strdup(expsz);
|
||||
} else {
|
||||
if (context)
|
||||
krb5_set_error_message(context, 0,
|
||||
heim_set_error_message(context, 0,
|
||||
"Overflow while expanding environment strings "
|
||||
"for registry value %s", valuename);
|
||||
}
|
||||
@@ -441,7 +438,7 @@ have_data:
|
||||
|
||||
default:
|
||||
if (context)
|
||||
krb5_set_error_message(context, 0,
|
||||
heim_set_error_message(context, 0,
|
||||
"Unexpected type while reading registry value %s",
|
||||
valuename);
|
||||
}
|
||||
@@ -458,21 +455,21 @@ done:
|
||||
*
|
||||
* @see parse_reg_value_as_string()
|
||||
*/
|
||||
static krb5_error_code
|
||||
parse_reg_value(krb5_context context,
|
||||
static heim_error_code
|
||||
parse_reg_value(heim_context context,
|
||||
HKEY key, const char * valuename,
|
||||
DWORD type, DWORD cbdata, krb5_config_section ** parent)
|
||||
DWORD type, DWORD cbdata, heim_config_section ** parent)
|
||||
{
|
||||
char *reg_string = NULL;
|
||||
krb5_config_section *value;
|
||||
krb5_error_code code = 0;
|
||||
heim_config_section *value;
|
||||
heim_error_code code = 0;
|
||||
|
||||
reg_string = _krb5_parse_reg_value_as_string(context, key, valuename, type, cbdata);
|
||||
reg_string = heim_parse_reg_value_as_string(context, key, valuename, type, cbdata);
|
||||
|
||||
if (reg_string == NULL)
|
||||
return KRB5_CONFIG_BADFORMAT;
|
||||
return HEIM_ERR_CONFIG_BADFORMAT;
|
||||
|
||||
value = _krb5_config_get_entry(parent, valuename, krb5_config_string);
|
||||
value = heim_config_get_entry(parent, valuename, heim_config_string);
|
||||
if (value == NULL) {
|
||||
code = ENOMEM;
|
||||
goto done;
|
||||
@@ -491,10 +488,10 @@ done:
|
||||
return code;
|
||||
}
|
||||
|
||||
static krb5_error_code
|
||||
parse_reg_values(krb5_context context,
|
||||
static heim_error_code
|
||||
parse_reg_values(heim_context context,
|
||||
HKEY key,
|
||||
krb5_config_section ** parent)
|
||||
heim_config_section ** parent)
|
||||
{
|
||||
DWORD index;
|
||||
LONG rcode;
|
||||
@@ -504,7 +501,7 @@ parse_reg_values(krb5_context context,
|
||||
DWORD cch = sizeof(name)/sizeof(name[0]);
|
||||
DWORD type;
|
||||
DWORD cbdata = 0;
|
||||
krb5_error_code code;
|
||||
heim_error_code code;
|
||||
|
||||
rcode = RegEnumValue(key, index, name, &cch, NULL,
|
||||
&type, NULL, &cbdata);
|
||||
@@ -522,10 +519,10 @@ parse_reg_values(krb5_context context,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static krb5_error_code
|
||||
parse_reg_subkeys(krb5_context context,
|
||||
static heim_error_code
|
||||
parse_reg_subkeys(heim_context context,
|
||||
HKEY key,
|
||||
krb5_config_section ** parent)
|
||||
heim_config_section ** parent)
|
||||
{
|
||||
DWORD index;
|
||||
LONG rcode;
|
||||
@@ -534,8 +531,8 @@ parse_reg_subkeys(krb5_context context,
|
||||
HKEY subkey = NULL;
|
||||
char name[256];
|
||||
DWORD cch = sizeof(name)/sizeof(name[0]);
|
||||
krb5_config_section *section = NULL;
|
||||
krb5_error_code code;
|
||||
heim_config_section *section = NULL;
|
||||
heim_error_code code;
|
||||
|
||||
rcode = RegEnumKeyEx(key, index, name, &cch, NULL, NULL, NULL, NULL);
|
||||
if (rcode != ERROR_SUCCESS)
|
||||
@@ -545,7 +542,7 @@ parse_reg_subkeys(krb5_context context,
|
||||
if (rcode != ERROR_SUCCESS)
|
||||
continue;
|
||||
|
||||
section = _krb5_config_get_entry(parent, name, krb5_config_list);
|
||||
section = heim_config_get_entry(parent, name, heim_config_list);
|
||||
if (section == NULL) {
|
||||
RegCloseKey(subkey);
|
||||
return ENOMEM;
|
||||
@@ -569,17 +566,17 @@ parse_reg_subkeys(krb5_context context,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static krb5_error_code
|
||||
parse_reg_root(krb5_context context,
|
||||
static heim_error_code
|
||||
parse_reg_root(heim_context context,
|
||||
HKEY key,
|
||||
krb5_config_section ** parent)
|
||||
heim_config_section ** parent)
|
||||
{
|
||||
krb5_config_section *libdefaults = NULL;
|
||||
krb5_error_code code = 0;
|
||||
heim_config_section *libdefaults = NULL;
|
||||
heim_error_code code = 0;
|
||||
|
||||
libdefaults = _krb5_config_get_entry(parent, "libdefaults", krb5_config_list);
|
||||
libdefaults = heim_config_get_entry(parent, "libdefaults", heim_config_list);
|
||||
if (libdefaults == NULL)
|
||||
return krb5_enomem(context);
|
||||
return heim_enomem(context);
|
||||
|
||||
code = parse_reg_values(context, key, &libdefaults->u.list);
|
||||
if (code)
|
||||
@@ -588,15 +585,15 @@ parse_reg_root(krb5_context context,
|
||||
return parse_reg_subkeys(context, key, parent);
|
||||
}
|
||||
|
||||
static krb5_error_code
|
||||
load_config_from_regpath(krb5_context context,
|
||||
static heim_error_code
|
||||
load_config_from_regpath(heim_context context,
|
||||
HKEY hk_root,
|
||||
const char* key_path,
|
||||
krb5_config_section ** res)
|
||||
heim_config_section ** res)
|
||||
{
|
||||
HKEY key = NULL;
|
||||
LONG rcode;
|
||||
krb5_error_code code = 0;
|
||||
heim_error_code code = 0;
|
||||
|
||||
rcode = RegOpenKeyEx(hk_root, key_path, 0, KEY_READ, &key);
|
||||
if (rcode == ERROR_SUCCESS) {
|
||||
@@ -620,30 +617,43 @@ load_config_from_regpath(krb5_context context,
|
||||
*
|
||||
* @see parse_reg_value() for details about how each type of value is handled.
|
||||
*/
|
||||
KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
|
||||
_krb5_load_config_from_registry(krb5_context context,
|
||||
krb5_config_section ** res)
|
||||
heim_error_code
|
||||
heim_load_config_from_registry(heim_context context,
|
||||
const char *path0,
|
||||
const char *path1,
|
||||
heim_config_section **res)
|
||||
{
|
||||
krb5_error_code code;
|
||||
heim_error_code code;
|
||||
|
||||
code = load_config_from_regpath(context, HKEY_LOCAL_MACHINE,
|
||||
REGPATH_KERBEROS, res);
|
||||
if (code)
|
||||
return code;
|
||||
if (!path0 && !path1)
|
||||
return EINVAL;
|
||||
|
||||
code = load_config_from_regpath(context, HKEY_LOCAL_MACHINE,
|
||||
REGPATH_HEIMDAL, res);
|
||||
if (code)
|
||||
return code;
|
||||
if (path0) {
|
||||
code = load_config_from_regpath(context, HKEY_LOCAL_MACHINE,
|
||||
path0, res);
|
||||
if (code)
|
||||
return code;
|
||||
}
|
||||
|
||||
code = load_config_from_regpath(context, HKEY_CURRENT_USER,
|
||||
REGPATH_KERBEROS, res);
|
||||
if (code)
|
||||
return code;
|
||||
if (path1) {
|
||||
code = load_config_from_regpath(context, HKEY_LOCAL_MACHINE,
|
||||
path1, res);
|
||||
if (code)
|
||||
return code;
|
||||
}
|
||||
|
||||
code = load_config_from_regpath(context, HKEY_CURRENT_USER,
|
||||
REGPATH_HEIMDAL, res);
|
||||
if (code)
|
||||
return code;
|
||||
if (path0) {
|
||||
code = load_config_from_regpath(context, HKEY_CURRENT_USER,
|
||||
path0, res);
|
||||
if (code)
|
||||
return code;
|
||||
}
|
||||
|
||||
if (path0) {
|
||||
code = load_config_from_regpath(context, HKEY_CURRENT_USER,
|
||||
path1, res);
|
||||
if (code)
|
||||
return code;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
234
lib/base/context.c
Normal file
234
lib/base/context.c
Normal file
@@ -0,0 +1,234 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Kungliga Tekniska Högskolan
|
||||
* (Royal Institute of Technology, Stockholm, Sweden).
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "baselocl.h"
|
||||
|
||||
#undef __attribute__
|
||||
#define __attribute__(X)
|
||||
|
||||
struct heim_context_s {
|
||||
heim_log_facility *warn_dest; /* XXX Move warn.c into lib/base as well */
|
||||
heim_log_facility *debug_dest;
|
||||
char *time_fmt;
|
||||
unsigned int log_utc:1;
|
||||
unsigned int homedir_access:1;
|
||||
heim_err_cb_context error_context;
|
||||
heim_err_cb_clear_msg clear_error_message;
|
||||
heim_err_cb_free_msg free_error_message;
|
||||
heim_err_cb_get_msg get_error_message;
|
||||
heim_err_cb_set_msg set_error_message;
|
||||
const char *unknown_error;
|
||||
const char *success;
|
||||
};
|
||||
|
||||
heim_context
|
||||
heim_context_init(void)
|
||||
{
|
||||
heim_context context;
|
||||
|
||||
if ((context = calloc(1, sizeof(*context))) == NULL)
|
||||
return NULL;
|
||||
|
||||
context->log_utc = 1;
|
||||
context->clear_error_message = NULL;
|
||||
context->free_error_message = NULL;
|
||||
context->get_error_message = NULL;
|
||||
context->set_error_message = NULL;
|
||||
context->error_context = NULL;
|
||||
context->unknown_error = "Unknown error";
|
||||
context->success = "Success";
|
||||
context->debug_dest = NULL;
|
||||
context->warn_dest = NULL;
|
||||
context->time_fmt = NULL;
|
||||
return context;
|
||||
}
|
||||
|
||||
void
|
||||
heim_context_free(heim_context *contextp)
|
||||
{
|
||||
heim_context context = *contextp;
|
||||
|
||||
*contextp = NULL;
|
||||
if (!context)
|
||||
return;
|
||||
heim_closelog(context, context->debug_dest);
|
||||
heim_closelog(context, context->warn_dest);
|
||||
free(context->time_fmt);
|
||||
free(context);
|
||||
}
|
||||
|
||||
void
|
||||
heim_context_set_msg_cb(heim_context context,
|
||||
heim_err_cb_context cb_context,
|
||||
heim_err_cb_clear_msg cb_clear_msg,
|
||||
heim_err_cb_free_msg cb_free_msg,
|
||||
heim_err_cb_get_msg cb_get_msg,
|
||||
heim_err_cb_set_msg cb_set_msg)
|
||||
{
|
||||
context->error_context = cb_context;
|
||||
context->clear_error_message = cb_clear_msg;
|
||||
context->free_error_message = cb_free_msg;
|
||||
context->set_error_message = cb_set_msg;
|
||||
context->get_error_message = cb_get_msg;
|
||||
}
|
||||
|
||||
heim_error_code
|
||||
heim_context_set_time_fmt(heim_context context, const char *fmt)
|
||||
{
|
||||
char *s;
|
||||
|
||||
if (fmt == NULL) {
|
||||
free(context->time_fmt);
|
||||
return 0;
|
||||
}
|
||||
if ((s = strdup(fmt)) == NULL)
|
||||
return heim_enomem(context);
|
||||
free(context->time_fmt);
|
||||
context->time_fmt = s;
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char *
|
||||
heim_context_get_time_fmt(heim_context context)
|
||||
{
|
||||
return context->time_fmt ? context->time_fmt : "%Y-%m-%dT%H:%M:%S";
|
||||
}
|
||||
|
||||
unsigned int
|
||||
heim_context_set_log_utc(heim_context context, unsigned int log_utc)
|
||||
{
|
||||
unsigned int old = context->log_utc;
|
||||
|
||||
context->log_utc = log_utc ? 1 : 0;
|
||||
return old;
|
||||
}
|
||||
|
||||
int
|
||||
heim_context_get_log_utc(heim_context context)
|
||||
{
|
||||
return context->log_utc;
|
||||
}
|
||||
|
||||
unsigned int
|
||||
heim_context_set_homedir_access(heim_context context, unsigned int homedir_access)
|
||||
{
|
||||
unsigned int old = context->homedir_access;
|
||||
|
||||
context->homedir_access = homedir_access ? 1 : 0;
|
||||
return old;
|
||||
}
|
||||
|
||||
unsigned int
|
||||
heim_context_get_homedir_access(heim_context context)
|
||||
{
|
||||
return context->homedir_access;
|
||||
}
|
||||
|
||||
void
|
||||
heim_clear_error_message(heim_context context)
|
||||
{
|
||||
if (context != NULL && context->clear_error_message != NULL)
|
||||
context->clear_error_message(context->error_context);
|
||||
}
|
||||
|
||||
void
|
||||
heim_free_error_message(heim_context context, const char *msg)
|
||||
{
|
||||
if (context != NULL && context->free_error_message != NULL &&
|
||||
msg != context->unknown_error && msg != context->success)
|
||||
context->free_error_message(context->error_context, msg);
|
||||
}
|
||||
|
||||
const char *
|
||||
heim_get_error_message(heim_context context, heim_error_code ret)
|
||||
{
|
||||
if (context != NULL && context->get_error_message != NULL)
|
||||
return context->get_error_message(context->error_context, ret);
|
||||
if (ret)
|
||||
return context->unknown_error;
|
||||
return context->success;
|
||||
}
|
||||
|
||||
void
|
||||
heim_set_error_message(heim_context context, heim_error_code ret,
|
||||
const char *fmt, ...)
|
||||
__attribute__ ((__format__ (__printf__, 3, 4)))
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
heim_vset_error_message(context, ret, fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void
|
||||
heim_vset_error_message(heim_context context, heim_error_code ret,
|
||||
const char *fmt, va_list args)
|
||||
__attribute__ ((__format__ (__printf__, 3, 0)))
|
||||
{
|
||||
if (context != NULL && context->set_error_message != NULL)
|
||||
context->set_error_message(context->error_context, ret, fmt, args);
|
||||
}
|
||||
|
||||
heim_error_code
|
||||
heim_enomem(heim_context context)
|
||||
{
|
||||
heim_set_error_message(context, ENOMEM, "malloc: out of memory");
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
heim_log_facility *
|
||||
heim_get_warn_dest(heim_context context)
|
||||
{
|
||||
return context->warn_dest;
|
||||
}
|
||||
|
||||
heim_log_facility *
|
||||
heim_get_debug_dest(heim_context context)
|
||||
{
|
||||
return context->debug_dest;
|
||||
}
|
||||
|
||||
heim_error_code
|
||||
heim_set_warn_dest(heim_context context, heim_log_facility *fac)
|
||||
{
|
||||
context->warn_dest = fac;
|
||||
return 0;
|
||||
}
|
||||
|
||||
heim_error_code
|
||||
heim_set_debug_dest(heim_context context, heim_log_facility *fac)
|
||||
{
|
||||
context->debug_dest = fac;
|
||||
return 0;
|
||||
}
|
@@ -1,6 +1,6 @@
|
||||
|
||||
/***********************************************************************
|
||||
* Copyright (c) 2009, Secure Endpoints Inc.
|
||||
* Copyright (c) 2009-2020, Secure Endpoints Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -30,7 +30,7 @@
|
||||
*
|
||||
**********************************************************************/
|
||||
|
||||
#include "krb5_locl.h"
|
||||
#include "baselocl.h"
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
@@ -51,35 +51,35 @@ typedef int PTYPE;
|
||||
* temporary directory until the user profile is loaded. In addition,
|
||||
* the returned path may or may not exist.
|
||||
*/
|
||||
static krb5_error_code
|
||||
_expand_temp_folder(krb5_context context, PTYPE param, const char *postfix,
|
||||
const char *arg, char **ret)
|
||||
static heim_error_code
|
||||
expand_temp_folder(heim_context context, PTYPE param, const char *postfix,
|
||||
const char *arg, char **ret)
|
||||
{
|
||||
TCHAR tpath[MAX_PATH];
|
||||
size_t len;
|
||||
|
||||
if (!GetTempPath(sizeof(tpath)/sizeof(tpath[0]), tpath)) {
|
||||
if (context)
|
||||
krb5_set_error_message(context, EINVAL,
|
||||
"Failed to get temporary path (GLE=%d)",
|
||||
GetLastError());
|
||||
return EINVAL;
|
||||
if (context)
|
||||
heim_set_error_message(context, EINVAL,
|
||||
"Failed to get temporary path (GLE=%d)",
|
||||
GetLastError());
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
len = strlen(tpath);
|
||||
|
||||
if (len > 0 && tpath[len - 1] == '\\')
|
||||
tpath[len - 1] = '\0';
|
||||
tpath[len - 1] = '\0';
|
||||
|
||||
*ret = strdup(tpath);
|
||||
|
||||
if (*ret == NULL)
|
||||
return krb5_enomem(context);
|
||||
return heim_enomem(context);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern HINSTANCE _krb5_hInstance;
|
||||
EXTERN_C IMAGE_DOS_HEADER __ImageBase;
|
||||
|
||||
/*
|
||||
* Expand a %{BINDIR} token
|
||||
@@ -87,40 +87,41 @@ extern HINSTANCE _krb5_hInstance;
|
||||
* This is also used to expand a few other tokens on Windows, since
|
||||
* most of the executable binaries end up in the same directory. The
|
||||
* "bin" directory is considered to be the directory in which the
|
||||
* krb5.dll is located.
|
||||
* containing DLL is located.
|
||||
*/
|
||||
static krb5_error_code
|
||||
_expand_bin_dir(krb5_context context, PTYPE param, const char *postfix,
|
||||
const char *arg, char **ret)
|
||||
static heim_error_code
|
||||
expand_bin_dir(heim_context context, PTYPE param, const char *postfix,
|
||||
const char *arg, char **ret)
|
||||
{
|
||||
TCHAR path[MAX_PATH];
|
||||
TCHAR *lastSlash;
|
||||
DWORD nc;
|
||||
|
||||
nc = GetModuleFileName(_krb5_hInstance, path, sizeof(path)/sizeof(path[0]));
|
||||
nc = GetModuleFileName((HINSTANCE)&__ImageBase, path,
|
||||
sizeof(path)/sizeof(path[0]));
|
||||
if (nc == 0 ||
|
||||
nc == sizeof(path)/sizeof(path[0])) {
|
||||
return EINVAL;
|
||||
nc == sizeof(path)/sizeof(path[0])) {
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
lastSlash = strrchr(path, '\\');
|
||||
if (lastSlash != NULL) {
|
||||
TCHAR *fslash = strrchr(lastSlash, '/');
|
||||
TCHAR *fslash = strrchr(lastSlash, '/');
|
||||
|
||||
if (fslash != NULL)
|
||||
lastSlash = fslash;
|
||||
if (fslash != NULL)
|
||||
lastSlash = fslash;
|
||||
|
||||
*lastSlash = '\0';
|
||||
*lastSlash = '\0';
|
||||
}
|
||||
|
||||
if (postfix) {
|
||||
if (strlcat(path, postfix, sizeof(path)/sizeof(path[0])) >= sizeof(path)/sizeof(path[0]))
|
||||
return EINVAL;
|
||||
if (strlcat(path, postfix, sizeof(path)/sizeof(path[0])) >= sizeof(path)/sizeof(path[0]))
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
*ret = strdup(path);
|
||||
if (*ret == NULL)
|
||||
return krb5_enomem(context);
|
||||
return heim_enomem(context);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -140,9 +141,9 @@ _expand_bin_dir(krb5_context context, PTYPE param, const char *postfix,
|
||||
* SecurityIdentification level the call will fail.
|
||||
*
|
||||
*/
|
||||
static krb5_error_code
|
||||
_expand_userid(krb5_context context, PTYPE param, const char *postfix,
|
||||
const char *arg, char **ret)
|
||||
static heim_error_code
|
||||
expand_userid(heim_context context, PTYPE param, const char *postfix,
|
||||
const char *arg, char **ret)
|
||||
{
|
||||
int rv = EINVAL;
|
||||
HANDLE hThread = NULL;
|
||||
@@ -154,83 +155,83 @@ _expand_userid(krb5_context context, PTYPE param, const char *postfix,
|
||||
hThread = GetCurrentThread();
|
||||
|
||||
if (!OpenThreadToken(hThread, TOKEN_QUERY,
|
||||
FALSE, /* Open the thread token as the
|
||||
current thread user. */
|
||||
&hToken)) {
|
||||
FALSE, /* Open the thread token as the
|
||||
current thread user. */
|
||||
&hToken)) {
|
||||
|
||||
DWORD le = GetLastError();
|
||||
DWORD le = GetLastError();
|
||||
|
||||
if (le == ERROR_NO_TOKEN) {
|
||||
HANDLE hProcess = GetCurrentProcess();
|
||||
if (le == ERROR_NO_TOKEN) {
|
||||
HANDLE hProcess = GetCurrentProcess();
|
||||
|
||||
le = 0;
|
||||
if (!OpenProcessToken(hProcess, TOKEN_QUERY, &hToken))
|
||||
le = GetLastError();
|
||||
}
|
||||
le = 0;
|
||||
if (!OpenProcessToken(hProcess, TOKEN_QUERY, &hToken))
|
||||
le = GetLastError();
|
||||
}
|
||||
|
||||
if (le != 0) {
|
||||
if (context)
|
||||
krb5_set_error_message(context, rv,
|
||||
"Can't open thread token (GLE=%d)", le);
|
||||
goto _exit;
|
||||
}
|
||||
if (le != 0) {
|
||||
if (context)
|
||||
heim_set_error_message(context, rv,
|
||||
"Can't open thread token (GLE=%d)", le);
|
||||
goto _exit;
|
||||
}
|
||||
}
|
||||
|
||||
if (!GetTokenInformation(hToken, TokenOwner, NULL, 0, &len)) {
|
||||
if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
|
||||
if (context)
|
||||
krb5_set_error_message(context, rv,
|
||||
"Unexpected error reading token information (GLE=%d)",
|
||||
GetLastError());
|
||||
goto _exit;
|
||||
}
|
||||
if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
|
||||
if (context)
|
||||
heim_set_error_message(context, rv,
|
||||
"Unexpected error reading token information (GLE=%d)",
|
||||
GetLastError());
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
if (len == 0) {
|
||||
if (context)
|
||||
krb5_set_error_message(context, rv,
|
||||
"GetTokenInformation() returned truncated buffer");
|
||||
goto _exit;
|
||||
}
|
||||
if (len == 0) {
|
||||
if (context)
|
||||
heim_set_error_message(context, rv,
|
||||
"GetTokenInformation() returned truncated buffer");
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
pOwner = malloc(len);
|
||||
if (pOwner == NULL) {
|
||||
if (context)
|
||||
krb5_set_error_message(context, rv, "Out of memory");
|
||||
goto _exit;
|
||||
}
|
||||
pOwner = malloc(len);
|
||||
if (pOwner == NULL) {
|
||||
if (context)
|
||||
heim_set_error_message(context, rv, "Out of memory");
|
||||
goto _exit;
|
||||
}
|
||||
} else {
|
||||
if (context)
|
||||
krb5_set_error_message(context, rv, "GetTokenInformation() returned truncated buffer");
|
||||
goto _exit;
|
||||
if (context)
|
||||
heim_set_error_message(context, rv, "GetTokenInformation() returned truncated buffer");
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
if (!GetTokenInformation(hToken, TokenOwner, pOwner, len, &len)) {
|
||||
if (context)
|
||||
krb5_set_error_message(context, rv, "GetTokenInformation() failed. GLE=%d", GetLastError());
|
||||
goto _exit;
|
||||
if (context)
|
||||
heim_set_error_message(context, rv, "GetTokenInformation() failed. GLE=%d", GetLastError());
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
if (!ConvertSidToStringSid(pOwner->Owner, &strSid)) {
|
||||
if (context)
|
||||
krb5_set_error_message(context, rv, "Can't convert SID to string. GLE=%d", GetLastError());
|
||||
goto _exit;
|
||||
if (context)
|
||||
heim_set_error_message(context, rv, "Can't convert SID to string. GLE=%d", GetLastError());
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
*ret = strdup(strSid);
|
||||
if (*ret == NULL && context)
|
||||
krb5_set_error_message(context, rv, "Out of memory");
|
||||
heim_set_error_message(context, rv, "Out of memory");
|
||||
|
||||
rv = 0;
|
||||
|
||||
_exit:
|
||||
if (hToken != NULL)
|
||||
CloseHandle(hToken);
|
||||
CloseHandle(hToken);
|
||||
|
||||
if (pOwner != NULL)
|
||||
free (pOwner);
|
||||
free (pOwner);
|
||||
|
||||
if (strSid != NULL)
|
||||
LocalFree(strSid);
|
||||
LocalFree(strSid);
|
||||
|
||||
return rv;
|
||||
}
|
||||
@@ -239,129 +240,129 @@ _expand_userid(krb5_context context, PTYPE param, const char *postfix,
|
||||
* Expand a folder identified by a CSIDL
|
||||
*/
|
||||
|
||||
static krb5_error_code
|
||||
_expand_csidl(krb5_context context, PTYPE folder, const char *postfix,
|
||||
const char *arg, char **ret)
|
||||
static heim_error_code
|
||||
expand_csidl(heim_context context, PTYPE folder, const char *postfix,
|
||||
const char *arg, char **ret)
|
||||
{
|
||||
TCHAR path[MAX_PATH];
|
||||
size_t len;
|
||||
|
||||
if (SHGetFolderPath(NULL, folder, NULL, SHGFP_TYPE_CURRENT, path) != S_OK) {
|
||||
if (context)
|
||||
krb5_set_error_message(context, EINVAL, "Unable to determine folder path");
|
||||
return EINVAL;
|
||||
if (context)
|
||||
heim_set_error_message(context, EINVAL, "Unable to determine folder path");
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
len = strlen(path);
|
||||
|
||||
if (len > 0 && path[len - 1] == '\\')
|
||||
path[len - 1] = '\0';
|
||||
path[len - 1] = '\0';
|
||||
|
||||
if (postfix &&
|
||||
strlcat(path, postfix, sizeof(path)/sizeof(path[0])) >= sizeof(path)/sizeof(path[0]))
|
||||
return krb5_enomem(context);
|
||||
strlcat(path, postfix, sizeof(path)/sizeof(path[0])) >= sizeof(path)/sizeof(path[0]))
|
||||
return heim_enomem(context);
|
||||
|
||||
*ret = strdup(path);
|
||||
if (*ret == NULL)
|
||||
return krb5_enomem(context);
|
||||
return heim_enomem(context);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static krb5_error_code
|
||||
_expand_path(krb5_context context, PTYPE param, const char *postfix,
|
||||
const char *arg, char **ret)
|
||||
static heim_error_code
|
||||
expand_path(heim_context context, PTYPE param, const char *postfix,
|
||||
const char *arg, char **ret)
|
||||
{
|
||||
*ret = strdup(postfix);
|
||||
if (*ret == NULL)
|
||||
return krb5_enomem(context);
|
||||
return heim_enomem(context);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static krb5_error_code
|
||||
_expand_temp_folder(krb5_context context, PTYPE param, const char *postfix,
|
||||
const char *arg, char **ret)
|
||||
static heim_error_code
|
||||
expand_temp_folder(heim_context context, PTYPE param, const char *postfix,
|
||||
const char *arg, char **ret)
|
||||
{
|
||||
const char *p = NULL;
|
||||
|
||||
p = secure_getenv("TEMP");
|
||||
|
||||
if (p)
|
||||
*ret = strdup(p);
|
||||
*ret = strdup(p);
|
||||
else
|
||||
*ret = strdup("/tmp");
|
||||
*ret = strdup("/tmp");
|
||||
if (*ret == NULL)
|
||||
return krb5_enomem(context);
|
||||
return heim_enomem(context);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static krb5_error_code
|
||||
_expand_userid(krb5_context context, PTYPE param, const char *postfix,
|
||||
const char *arg, char **str)
|
||||
static heim_error_code
|
||||
expand_userid(heim_context context, PTYPE param, const char *postfix,
|
||||
const char *arg, char **str)
|
||||
{
|
||||
int ret = asprintf(str, "%ld", (unsigned long)getuid());
|
||||
if (ret < 0 || *str == NULL)
|
||||
return krb5_enomem(context);
|
||||
return heim_enomem(context);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static krb5_error_code
|
||||
_expand_euid(krb5_context context, PTYPE param, const char *postfix,
|
||||
const char *arg, char **str)
|
||||
static heim_error_code
|
||||
expand_euid(heim_context context, PTYPE param, const char *postfix,
|
||||
const char *arg, char **str)
|
||||
{
|
||||
int ret = asprintf(str, "%ld", (unsigned long)geteuid());
|
||||
if (ret < 0 || *str == NULL)
|
||||
return krb5_enomem(context);
|
||||
return heim_enomem(context);
|
||||
return 0;
|
||||
}
|
||||
#endif /* _WIN32 */
|
||||
|
||||
static krb5_error_code
|
||||
_expand_username(krb5_context context, PTYPE param, const char *postfix,
|
||||
const char *arg, char **str)
|
||||
static heim_error_code
|
||||
expand_username(heim_context context, PTYPE param, const char *postfix,
|
||||
const char *arg, char **str)
|
||||
{
|
||||
char user[128];
|
||||
const char *username = roken_get_username(user, sizeof(user));
|
||||
|
||||
if (username == NULL) {
|
||||
krb5_set_error_message(context, ENOTTY,
|
||||
N_("unable to figure out current principal",
|
||||
""));
|
||||
return ENOTTY; /* XXX */
|
||||
heim_set_error_message(context, ENOTTY,
|
||||
N_("unable to figure out current principal",
|
||||
""));
|
||||
return ENOTTY; /* XXX */
|
||||
}
|
||||
|
||||
*str = strdup(username);
|
||||
if (*str == NULL)
|
||||
return krb5_enomem(context);
|
||||
return heim_enomem(context);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static krb5_error_code
|
||||
_expand_loginname(krb5_context context, PTYPE param, const char *postfix,
|
||||
const char *arg, char **str)
|
||||
static heim_error_code
|
||||
expand_loginname(heim_context context, PTYPE param, const char *postfix,
|
||||
const char *arg, char **str)
|
||||
{
|
||||
char user[128];
|
||||
const char *username = roken_get_loginname(user, sizeof(user));
|
||||
|
||||
if (username == NULL) {
|
||||
krb5_set_error_message(context, ENOTTY,
|
||||
N_("unable to figure out current principal",
|
||||
""));
|
||||
return ENOTTY; /* XXX */
|
||||
heim_set_error_message(context, ENOTTY,
|
||||
N_("unable to figure out current principal",
|
||||
""));
|
||||
return ENOTTY; /* XXX */
|
||||
}
|
||||
|
||||
*str = strdup(username);
|
||||
if (*str == NULL)
|
||||
return krb5_enomem(context);
|
||||
return heim_enomem(context);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static krb5_error_code
|
||||
_expand_strftime(krb5_context context, PTYPE param, const char *postfix,
|
||||
const char *arg, char **ret)
|
||||
static heim_error_code
|
||||
expand_strftime(heim_context context, PTYPE param, const char *postfix,
|
||||
const char *arg, char **ret)
|
||||
{
|
||||
size_t len;
|
||||
time_t t;
|
||||
@@ -370,7 +371,7 @@ _expand_strftime(krb5_context context, PTYPE param, const char *postfix,
|
||||
t = time(NULL);
|
||||
len = strftime(buf, sizeof(buf), arg, localtime(&t));
|
||||
if (len == 0 || len >= sizeof(buf))
|
||||
return ENOMEM;
|
||||
return ENOMEM;
|
||||
*ret = strdup(buf);
|
||||
return 0;
|
||||
}
|
||||
@@ -379,12 +380,12 @@ _expand_strftime(krb5_context context, PTYPE param, const char *postfix,
|
||||
* Expand an extra token
|
||||
*/
|
||||
|
||||
static krb5_error_code
|
||||
_expand_extra_token(krb5_context context, const char *value, char **ret)
|
||||
static heim_error_code
|
||||
expand_extra_token(heim_context context, const char *value, char **ret)
|
||||
{
|
||||
*ret = strdup(value);
|
||||
if (*ret == NULL)
|
||||
return krb5_enomem(context);
|
||||
return heim_enomem(context);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -394,13 +395,13 @@ _expand_extra_token(krb5_context context, const char *value, char **ret)
|
||||
* The expansion of a %{null} token is always the empty string.
|
||||
*/
|
||||
|
||||
static krb5_error_code
|
||||
_expand_null(krb5_context context, PTYPE param, const char *postfix,
|
||||
const char *arg, char **ret)
|
||||
static heim_error_code
|
||||
expand_null(heim_context context, PTYPE param, const char *postfix,
|
||||
const char *arg, char **ret)
|
||||
{
|
||||
*ret = strdup("");
|
||||
if (*ret == NULL)
|
||||
return krb5_enomem(context);
|
||||
return heim_enomem(context);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -414,14 +415,14 @@ static const struct {
|
||||
PTYPE param;
|
||||
const char * postfix;
|
||||
|
||||
int (*exp_func)(krb5_context, PTYPE, const char *, const char *, char **);
|
||||
int (*exp_func)(heim_context, PTYPE, const char *, const char *, char **);
|
||||
|
||||
#define SPECIALP(f, P) FTYPE_SPECIAL, 0, P, f
|
||||
#define SPECIAL(f) SPECIALP(f, NULL)
|
||||
|
||||
} tokens[] = {
|
||||
#ifdef _WIN32
|
||||
#define CSIDLP(C,P) FTYPE_CSIDL, C, P, _expand_csidl
|
||||
#define CSIDLP(C,P) FTYPE_CSIDL, C, P, expand_csidl
|
||||
#define CSIDL(C) CSIDLP(C, NULL)
|
||||
|
||||
{"APPDATA", CSIDL(CSIDL_APPDATA)}, /* Roaming application data (for current user) */
|
||||
@@ -431,36 +432,36 @@ static const struct {
|
||||
{"WINDOWS", CSIDL(CSIDL_WINDOWS)}, /* Windows folder */
|
||||
{"USERCONFIG", CSIDLP(CSIDL_APPDATA, "\\" PACKAGE)}, /* Per user Heimdal configuration file path */
|
||||
{"COMMONCONFIG", CSIDLP(CSIDL_COMMON_APPDATA, "\\" PACKAGE)}, /* Common Heimdal configuration file path */
|
||||
{"LIBDIR", SPECIAL(_expand_bin_dir)},
|
||||
{"BINDIR", SPECIAL(_expand_bin_dir)},
|
||||
{"LIBEXEC", SPECIAL(_expand_bin_dir)},
|
||||
{"SBINDIR", SPECIAL(_expand_bin_dir)},
|
||||
{"LIBDIR", SPECIAL(expand_bin_dir)},
|
||||
{"BINDIR", SPECIAL(expand_bin_dir)},
|
||||
{"LIBEXEC", SPECIAL(expand_bin_dir)},
|
||||
{"SBINDIR", SPECIAL(expand_bin_dir)},
|
||||
#else
|
||||
{"LOCALSTATEDIR", FTYPE_SPECIAL, 0, LOCALSTATEDIR, _expand_path},
|
||||
{"LIBDIR", FTYPE_SPECIAL, 0, LIBDIR, _expand_path},
|
||||
{"BINDIR", FTYPE_SPECIAL, 0, BINDIR, _expand_path},
|
||||
{"LIBEXEC", FTYPE_SPECIAL, 0, LIBEXECDIR, _expand_path},
|
||||
{"SBINDIR", FTYPE_SPECIAL, 0, SBINDIR, _expand_path},
|
||||
{"euid", SPECIAL(_expand_euid)},
|
||||
{"ruid", SPECIAL(_expand_userid)},
|
||||
{"loginname", SPECIAL(_expand_loginname)},
|
||||
{"LOCALSTATEDIR", FTYPE_SPECIAL, 0, LOCALSTATEDIR, expand_path},
|
||||
{"LIBDIR", FTYPE_SPECIAL, 0, LIBDIR, expand_path},
|
||||
{"BINDIR", FTYPE_SPECIAL, 0, BINDIR, expand_path},
|
||||
{"LIBEXEC", FTYPE_SPECIAL, 0, LIBEXECDIR, expand_path},
|
||||
{"SBINDIR", FTYPE_SPECIAL, 0, SBINDIR, expand_path},
|
||||
{"euid", SPECIAL(expand_euid)},
|
||||
{"ruid", SPECIAL(expand_userid)},
|
||||
{"loginname", SPECIAL(expand_loginname)},
|
||||
#endif
|
||||
{"username", SPECIAL(_expand_username)},
|
||||
{"TEMP", SPECIAL(_expand_temp_folder)},
|
||||
{"USERID", SPECIAL(_expand_userid)},
|
||||
{"uid", SPECIAL(_expand_userid)},
|
||||
{"null", SPECIAL(_expand_null)},
|
||||
{"strftime", SPECIAL(_expand_strftime)}
|
||||
{"username", SPECIAL(expand_username)},
|
||||
{"TEMP", SPECIAL(expand_temp_folder)},
|
||||
{"USERID", SPECIAL(expand_userid)},
|
||||
{"uid", SPECIAL(expand_userid)},
|
||||
{"null", SPECIAL(expand_null)},
|
||||
{"strftime", SPECIAL(expand_strftime)}
|
||||
};
|
||||
|
||||
static krb5_error_code
|
||||
_expand_token(krb5_context context,
|
||||
const char *token,
|
||||
const char *token_end,
|
||||
char **extra_tokens,
|
||||
char **ret)
|
||||
static heim_error_code
|
||||
expand_token(heim_context context,
|
||||
const char *token,
|
||||
const char *token_end,
|
||||
char **extra_tokens,
|
||||
char **ret)
|
||||
{
|
||||
krb5_error_code errcode;
|
||||
heim_error_code errcode;
|
||||
size_t i;
|
||||
char **p;
|
||||
const char *colon;
|
||||
@@ -468,62 +469,70 @@ _expand_token(krb5_context context,
|
||||
*ret = NULL;
|
||||
|
||||
if (token[0] != '%' || token[1] != '{' || token_end[0] != '}' ||
|
||||
token_end - token <= 2) {
|
||||
if (context)
|
||||
krb5_set_error_message(context, EINVAL,"Invalid token.");
|
||||
return EINVAL;
|
||||
token_end - token <= 2) {
|
||||
if (context)
|
||||
heim_set_error_message(context, EINVAL,"Invalid token.");
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
for (p = extra_tokens; p && p[0]; p += 2) {
|
||||
if (strncmp(token+2, p[0], (token_end - token) - 2) == 0)
|
||||
return _expand_extra_token(context, p[1], ret);
|
||||
if (strncmp(token+2, p[0], (token_end - token) - 2) == 0)
|
||||
return expand_extra_token(context, p[1], ret);
|
||||
}
|
||||
|
||||
for (colon=token+2; colon < token_end; colon++)
|
||||
if (*colon == ':')
|
||||
break;
|
||||
if (*colon == ':')
|
||||
break;
|
||||
|
||||
for (i = 0; i < sizeof(tokens)/sizeof(tokens[0]); i++)
|
||||
if (!strncmp(token+2, tokens[i].tok, (colon - token) - 2)) {
|
||||
char *arg = NULL;
|
||||
if (!strncmp(token+2, tokens[i].tok, (colon - token) - 2)) {
|
||||
char *arg = NULL;
|
||||
|
||||
errcode = 0;
|
||||
if (*colon == ':') {
|
||||
asprintf(&arg, "%.*s", (int)(token_end - colon - 1), colon + 1);
|
||||
if (!arg)
|
||||
errcode = ENOMEM;
|
||||
}
|
||||
if (!errcode)
|
||||
errcode = tokens[i].exp_func(context, tokens[i].param,
|
||||
tokens[i].postfix, arg, ret);
|
||||
free(arg);
|
||||
return errcode;
|
||||
}
|
||||
errcode = 0;
|
||||
if (*colon == ':') {
|
||||
asprintf(&arg, "%.*s", (int)(token_end - colon - 1), colon + 1);
|
||||
if (!arg)
|
||||
errcode = ENOMEM;
|
||||
}
|
||||
if (!errcode)
|
||||
errcode = tokens[i].exp_func(context, tokens[i].param,
|
||||
tokens[i].postfix, arg, ret);
|
||||
free(arg);
|
||||
return errcode;
|
||||
}
|
||||
|
||||
if (context)
|
||||
krb5_set_error_message(context, EINVAL, "Invalid token.");
|
||||
heim_set_error_message(context, EINVAL, "Invalid token.");
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal function to expand tokens in paths.
|
||||
*
|
||||
* Inputs:
|
||||
* Params:
|
||||
*
|
||||
* @context A krb5_context
|
||||
* @context A heim_context
|
||||
* @path_in The path to expand tokens from
|
||||
*
|
||||
* Outputs:
|
||||
*
|
||||
* @ppath_out Path with expanded tokens (caller must free() this)
|
||||
* @ppath_out The expanded path
|
||||
* @... Variable number of pairs of strings, the first of each
|
||||
* being a token (e.g., "luser") and the second a string to
|
||||
* replace it with. The list is terminated by a NULL.
|
||||
*/
|
||||
KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
|
||||
_krb5_expand_path_tokens(krb5_context context,
|
||||
const char *path_in,
|
||||
int filepath,
|
||||
char **ppath_out)
|
||||
heim_error_code
|
||||
heim_expand_path_tokens(heim_context context,
|
||||
const char *path_in,
|
||||
int filepath,
|
||||
char **ppath_out,
|
||||
...)
|
||||
{
|
||||
return _krb5_expand_path_tokensv(context, path_in, filepath, ppath_out, NULL);
|
||||
heim_error_code ret;
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, ppath_out);
|
||||
ret = heim_expand_path_tokensv(context, path_in, filepath, ppath_out, ap);
|
||||
va_end(ap);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -532,7 +541,7 @@ free_extra_tokens(char **extra_tokens)
|
||||
char **p;
|
||||
|
||||
for (p = extra_tokens; p && *p; p++)
|
||||
free(*p);
|
||||
free(*p);
|
||||
free(extra_tokens);
|
||||
}
|
||||
|
||||
@@ -541,29 +550,29 @@ free_extra_tokens(char **extra_tokens)
|
||||
*
|
||||
* Inputs:
|
||||
*
|
||||
* @context A krb5_context
|
||||
* @context A heim_context
|
||||
* @path_in The path to expand tokens from
|
||||
* @ppath_out The expanded path
|
||||
* @... Variable number of pairs of strings, the first of each
|
||||
* being a token (e.g., "luser") and the second a string to
|
||||
* replace it with. The list is terminated by a NULL.
|
||||
* @ap A NULL-terminated va_list of pairs of strings, the first of each
|
||||
* being a token (e.g., "luser") and the second a string to replace
|
||||
* it with.
|
||||
*
|
||||
* Outputs:
|
||||
*
|
||||
* @ppath_out Path with expanded tokens (caller must free() this)
|
||||
*/
|
||||
KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
|
||||
_krb5_expand_path_tokensv(krb5_context context,
|
||||
const char *path_in,
|
||||
int filepath,
|
||||
char **ppath_out, ...)
|
||||
heim_error_code
|
||||
heim_expand_path_tokensv(heim_context context,
|
||||
const char *path_in,
|
||||
int filepath,
|
||||
char **ppath_out, va_list ap)
|
||||
{
|
||||
char *tok_begin, *tok_end, *append;
|
||||
char **extra_tokens = NULL;
|
||||
const char *path_left;
|
||||
size_t nargs = 0;
|
||||
size_t len = 0;
|
||||
va_list ap;
|
||||
va_list ap2;
|
||||
|
||||
if (path_in == NULL || *path_in == '\0') {
|
||||
*ppath_out = strdup("");
|
||||
@@ -572,126 +581,128 @@ _krb5_expand_path_tokensv(krb5_context context,
|
||||
|
||||
*ppath_out = NULL;
|
||||
|
||||
va_start(ap, ppath_out);
|
||||
while (va_arg(ap, const char *)) {
|
||||
nargs++;
|
||||
va_arg(ap, const char *);
|
||||
#if defined(_MSC_VER)
|
||||
ap2 = ap; /* Come on! See SO #558223 */
|
||||
#else
|
||||
va_copy(ap2, ap);
|
||||
#endif
|
||||
while (va_arg(ap2, const char *)) {
|
||||
nargs++;
|
||||
va_arg(ap2, const char *);
|
||||
}
|
||||
va_end(ap);
|
||||
va_end(ap2);
|
||||
nargs *= 2;
|
||||
|
||||
/* Get extra tokens */
|
||||
if (nargs) {
|
||||
size_t i;
|
||||
size_t i;
|
||||
|
||||
extra_tokens = calloc(nargs + 1, sizeof (*extra_tokens));
|
||||
if (extra_tokens == NULL)
|
||||
return krb5_enomem(context);
|
||||
va_start(ap, ppath_out);
|
||||
for (i = 0; i < nargs; i++) {
|
||||
const char *s = va_arg(ap, const char *); /* token key */
|
||||
if (s == NULL)
|
||||
break;
|
||||
extra_tokens[i] = strdup(s);
|
||||
if (extra_tokens[i++] == NULL) {
|
||||
va_end(ap);
|
||||
free_extra_tokens(extra_tokens);
|
||||
return krb5_enomem(context);
|
||||
}
|
||||
s = va_arg(ap, const char *); /* token value */
|
||||
if (s == NULL)
|
||||
s = "";
|
||||
extra_tokens[i] = strdup(s);
|
||||
if (extra_tokens[i] == NULL) {
|
||||
va_end(ap);
|
||||
free_extra_tokens(extra_tokens);
|
||||
return krb5_enomem(context);
|
||||
}
|
||||
}
|
||||
va_end(ap);
|
||||
extra_tokens = calloc(nargs + 1, sizeof (*extra_tokens));
|
||||
if (extra_tokens == NULL)
|
||||
return heim_enomem(context);
|
||||
for (i = 0; i < nargs; i++) {
|
||||
const char *s = va_arg(ap, const char *); /* token key */
|
||||
if (s == NULL)
|
||||
break;
|
||||
extra_tokens[i] = strdup(s);
|
||||
if (extra_tokens[i++] == NULL) {
|
||||
va_end(ap);
|
||||
free_extra_tokens(extra_tokens);
|
||||
return heim_enomem(context);
|
||||
}
|
||||
s = va_arg(ap, const char *); /* token value */
|
||||
if (s == NULL)
|
||||
s = "";
|
||||
extra_tokens[i] = strdup(s);
|
||||
if (extra_tokens[i] == NULL) {
|
||||
va_end(ap);
|
||||
free_extra_tokens(extra_tokens);
|
||||
return heim_enomem(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (path_left = path_in; path_left && *path_left; ) {
|
||||
|
||||
tok_begin = strstr(path_left, "%{");
|
||||
tok_begin = strstr(path_left, "%{");
|
||||
|
||||
if (tok_begin && tok_begin != path_left) {
|
||||
if (tok_begin && tok_begin != path_left) {
|
||||
|
||||
append = malloc((tok_begin - path_left) + 1);
|
||||
if (append) {
|
||||
memcpy(append, path_left, tok_begin - path_left);
|
||||
append[tok_begin - path_left] = '\0';
|
||||
}
|
||||
path_left = tok_begin;
|
||||
append = malloc((tok_begin - path_left) + 1);
|
||||
if (append) {
|
||||
memcpy(append, path_left, tok_begin - path_left);
|
||||
append[tok_begin - path_left] = '\0';
|
||||
}
|
||||
path_left = tok_begin;
|
||||
|
||||
} else if (tok_begin) {
|
||||
} else if (tok_begin) {
|
||||
|
||||
tok_end = strchr(tok_begin, '}');
|
||||
if (tok_end == NULL) {
|
||||
free_extra_tokens(extra_tokens);
|
||||
if (*ppath_out)
|
||||
free(*ppath_out);
|
||||
*ppath_out = NULL;
|
||||
if (context)
|
||||
krb5_set_error_message(context, EINVAL, "variable missing }");
|
||||
return EINVAL;
|
||||
}
|
||||
tok_end = strchr(tok_begin, '}');
|
||||
if (tok_end == NULL) {
|
||||
free_extra_tokens(extra_tokens);
|
||||
if (*ppath_out)
|
||||
free(*ppath_out);
|
||||
*ppath_out = NULL;
|
||||
if (context)
|
||||
heim_set_error_message(context, EINVAL, "variable missing }");
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
if (_expand_token(context, tok_begin, tok_end, extra_tokens,
|
||||
&append)) {
|
||||
free_extra_tokens(extra_tokens);
|
||||
if (*ppath_out)
|
||||
free(*ppath_out);
|
||||
*ppath_out = NULL;
|
||||
return EINVAL;
|
||||
}
|
||||
if (expand_token(context, tok_begin, tok_end, extra_tokens,
|
||||
&append)) {
|
||||
free_extra_tokens(extra_tokens);
|
||||
if (*ppath_out)
|
||||
free(*ppath_out);
|
||||
*ppath_out = NULL;
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
path_left = tok_end + 1;
|
||||
} else {
|
||||
path_left = tok_end + 1;
|
||||
} else {
|
||||
|
||||
append = strdup(path_left);
|
||||
path_left = NULL;
|
||||
append = strdup(path_left);
|
||||
path_left = NULL;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (append == NULL) {
|
||||
if (append == NULL) {
|
||||
|
||||
free_extra_tokens(extra_tokens);
|
||||
if (*ppath_out)
|
||||
free(*ppath_out);
|
||||
*ppath_out = NULL;
|
||||
return krb5_enomem(context);
|
||||
free_extra_tokens(extra_tokens);
|
||||
if (*ppath_out)
|
||||
free(*ppath_out);
|
||||
*ppath_out = NULL;
|
||||
return heim_enomem(context);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
size_t append_len = strlen(append);
|
||||
char * new_str = realloc(*ppath_out, len + append_len + 1);
|
||||
{
|
||||
size_t append_len = strlen(append);
|
||||
char * new_str = realloc(*ppath_out, len + append_len + 1);
|
||||
|
||||
if (new_str == NULL) {
|
||||
free_extra_tokens(extra_tokens);
|
||||
free(append);
|
||||
if (*ppath_out)
|
||||
free(*ppath_out);
|
||||
*ppath_out = NULL;
|
||||
return krb5_enomem(context);
|
||||
}
|
||||
if (new_str == NULL) {
|
||||
free_extra_tokens(extra_tokens);
|
||||
free(append);
|
||||
if (*ppath_out)
|
||||
free(*ppath_out);
|
||||
*ppath_out = NULL;
|
||||
return heim_enomem(context);
|
||||
}
|
||||
|
||||
*ppath_out = new_str;
|
||||
memcpy(*ppath_out + len, append, append_len + 1);
|
||||
len = len + append_len;
|
||||
free(append);
|
||||
}
|
||||
*ppath_out = new_str;
|
||||
memcpy(*ppath_out + len, append, append_len + 1);
|
||||
len = len + append_len;
|
||||
free(append);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
/* Also deal with slashes */
|
||||
if (filepath && *ppath_out) {
|
||||
char * c;
|
||||
char * c;
|
||||
|
||||
for (c = *ppath_out; *c; c++)
|
||||
if (*c == '/')
|
||||
*c = '\\';
|
||||
for (c = *ppath_out; *c; c++)
|
||||
if (*c == '/')
|
||||
*c = '\\';
|
||||
}
|
||||
#endif
|
||||
|
||||
|
54
lib/base/heim_err.et
Normal file
54
lib/base/heim_err.et
Normal file
@@ -0,0 +1,54 @@
|
||||
#
|
||||
# Error messages for the krb5 library
|
||||
#
|
||||
# This might look like a com_err file, but is not
|
||||
#
|
||||
id "$Id$"
|
||||
|
||||
error_table heim
|
||||
|
||||
prefix HEIM_ERR
|
||||
|
||||
error_code LOG_PARSE, "Error parsing log destination"
|
||||
error_code V4_PRINC_NO_CONV, "Failed to convert v4 principal"
|
||||
error_code SALTTYPE_NOSUPP, "Salt type is not supported by enctype"
|
||||
error_code NOHOST, "Host not found"
|
||||
error_code OPNOTSUPP, "Operation not supported"
|
||||
error_code EOF, "End of file"
|
||||
error_code BAD_MKEY, "Failed to get the master key"
|
||||
error_code SERVICE_NOMATCH, "Unacceptable service used"
|
||||
error_code NOT_SEEKABLE, "File descriptor not seekable"
|
||||
error_code TOO_BIG, "Offset too large"
|
||||
error_code BAD_HDBENT_ENCODING, "Invalid HDB entry encoding"
|
||||
error_code RANDOM_OFFLINE, "No random source available"
|
||||
error_code CONFIG_BADFORMAT, "Improper format of configuration file"
|
||||
|
||||
index 64
|
||||
prefix HEIM_PKINIT
|
||||
error_code NO_CERTIFICATE, "Certificate missing"
|
||||
error_code NO_PRIVATE_KEY, "Private key missing"
|
||||
error_code NO_VALID_CA, "No valid certificate authority"
|
||||
error_code CERTIFICATE_INVALID, "Certificate invalid"
|
||||
error_code PRIVATE_KEY_INVALID, "Private key invalid"
|
||||
|
||||
index 128
|
||||
prefix HEIM_EAI
|
||||
#error_code NOERROR, "no error"
|
||||
error_code UNKNOWN, "unknown error from getaddrinfo"
|
||||
error_code ADDRFAMILY, "address family for nodename not supported"
|
||||
error_code AGAIN, "temporary failure in name resolution"
|
||||
error_code BADFLAGS, "invalid value for ai_flags"
|
||||
error_code FAIL, "non-recoverable failure in name resolution"
|
||||
error_code FAMILY, "ai_family not supported"
|
||||
error_code MEMORY, "memory allocation failure"
|
||||
error_code NODATA, "no address associated with nodename"
|
||||
error_code NONAME, "nodename nor servname provided, or not known"
|
||||
error_code SERVICE, "servname not supported for ai_socktype"
|
||||
error_code SOCKTYPE, "ai_socktype not supported"
|
||||
error_code SYSTEM, "system error returned in errno"
|
||||
|
||||
index 192
|
||||
prefix HEIM_NET
|
||||
error_code CONN_REFUSED, "connection refused"
|
||||
|
||||
end
|
@@ -55,8 +55,89 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <heim_err.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#define HEIM_CALLCONV __stdcall
|
||||
#define HEIM_LIB_CALL __stdcall
|
||||
#else
|
||||
#define HEIM_CALLCONV
|
||||
#define HEIM_LIB_CALL
|
||||
#endif
|
||||
|
||||
#if !defined(__GNUC__) && !defined(__attribute__)
|
||||
#define __attribute__(x)
|
||||
#endif
|
||||
|
||||
#define HEIM_BASE_API_VERSION 20130210
|
||||
|
||||
typedef int32_t heim_error_code;
|
||||
typedef struct heim_context_s *heim_context;
|
||||
typedef struct heim_pcontext_s *heim_pcontext;
|
||||
|
||||
typedef void (HEIM_CALLCONV *heim_log_log_func_t)(heim_context,
|
||||
const char *,
|
||||
const char *,
|
||||
void *);
|
||||
typedef void (HEIM_CALLCONV *heim_log_close_func_t)(void *);
|
||||
|
||||
struct heim_log_facility_internal {
|
||||
int min;
|
||||
int max;
|
||||
heim_log_log_func_t log_func;
|
||||
heim_log_close_func_t close_func;
|
||||
void *data;
|
||||
};
|
||||
|
||||
|
||||
typedef struct heim_log_facility_s {
|
||||
char *program;
|
||||
int len;
|
||||
struct heim_log_facility_internal *val;
|
||||
} heim_log_facility;
|
||||
|
||||
typedef uintptr_t
|
||||
(HEIM_LIB_CALL *heim_get_instance_func_t)(const char *);
|
||||
|
||||
#define HEIM_PLUGIN_INVOKE_ALL 1
|
||||
|
||||
struct heim_plugin_data {
|
||||
const char *module;
|
||||
const char *name;
|
||||
int min_version;
|
||||
const char **deps;
|
||||
heim_get_instance_func_t get_instance;
|
||||
};
|
||||
|
||||
typedef struct heim_err_cb_context_s *heim_err_cb_context;
|
||||
typedef void (*heim_err_cb_clear_msg)(heim_err_cb_context);
|
||||
typedef void (*heim_err_cb_free_msg)(heim_err_cb_context, const char *);
|
||||
typedef const char * (*heim_err_cb_get_msg)(heim_err_cb_context, int32_t);
|
||||
typedef void (*heim_err_cb_set_msg)(heim_err_cb_context, int32_t,
|
||||
const char *, va_list)
|
||||
__attribute__ ((__format__ (__printf__, 3, 0)));
|
||||
|
||||
typedef struct heim_config_binding heim_config_binding;
|
||||
struct heim_config_binding {
|
||||
enum {
|
||||
heim_config_string,
|
||||
heim_config_list,
|
||||
/* For compatibility in krb5 code */
|
||||
krb5_config_string = heim_config_string,
|
||||
krb5_config_list = heim_config_list,
|
||||
} type;
|
||||
char *name;
|
||||
struct heim_config_binding *next;
|
||||
union {
|
||||
char *string;
|
||||
struct heim_config_binding *list;
|
||||
void *generic;
|
||||
} u;
|
||||
};
|
||||
typedef struct heim_config_binding heim_config_section;
|
||||
|
||||
typedef void * heim_object_t;
|
||||
typedef unsigned int heim_tid_t;
|
||||
typedef heim_object_t heim_bool_t;
|
||||
@@ -572,4 +653,7 @@ heim_base_exchange_pointer(void *target, void *value)
|
||||
#error set SIZEOF_TIME_T for your platform
|
||||
#endif
|
||||
|
||||
#include <heim_threads.h>
|
||||
#include <heimbase-protos.h>
|
||||
|
||||
#endif /* HEIM_BASE_H */
|
||||
|
625
lib/base/log.c
625
lib/base/log.c
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1997-2006 Kungliga Tekniska Högskolan
|
||||
* Copyright (c) 1997-2020 Kungliga Tekniska Högskolan
|
||||
* (Royal Institute of Technology, Stockholm, Sweden).
|
||||
* All rights reserved.
|
||||
*
|
||||
@@ -33,25 +33,19 @@
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "krb5_locl.h"
|
||||
#include "baselocl.h"
|
||||
#include "heim_threads.h"
|
||||
#include <assert.h>
|
||||
#include <stdarg.h>
|
||||
#include <vis.h>
|
||||
|
||||
struct facility {
|
||||
int min;
|
||||
int max;
|
||||
krb5_log_log_func_t log_func;
|
||||
krb5_log_close_func_t close_func;
|
||||
void *data;
|
||||
};
|
||||
|
||||
static struct facility*
|
||||
log_realloc(krb5_log_facility *f)
|
||||
static struct heim_log_facility_internal *
|
||||
log_realloc(heim_log_facility *f)
|
||||
{
|
||||
struct facility *fp;
|
||||
struct heim_log_facility_internal *fp;
|
||||
fp = realloc(f->val, (f->len + 1) * sizeof(*f->val));
|
||||
if(fp == NULL)
|
||||
return NULL;
|
||||
if (fp == NULL)
|
||||
return NULL;
|
||||
f->len++;
|
||||
f->val = fp;
|
||||
fp += f->len - 1;
|
||||
@@ -111,40 +105,40 @@ static struct s2i syslogvals[] = {
|
||||
static int
|
||||
find_value(const char *s, struct s2i *table)
|
||||
{
|
||||
while(table->s && strcasecmp(table->s, s))
|
||||
table++;
|
||||
while (table->s && strcasecmp(table->s, s))
|
||||
table++;
|
||||
return table->val;
|
||||
}
|
||||
|
||||
KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
|
||||
krb5_initlog(krb5_context context,
|
||||
const char *program,
|
||||
krb5_log_facility **fac)
|
||||
heim_error_code
|
||||
heim_initlog(heim_context context,
|
||||
const char *program,
|
||||
heim_log_facility **fac)
|
||||
{
|
||||
krb5_log_facility *f = calloc(1, sizeof(*f));
|
||||
heim_log_facility *f = calloc(1, sizeof(*f));
|
||||
if (f == NULL)
|
||||
return krb5_enomem(context);
|
||||
return heim_enomem(context);
|
||||
f->program = strdup(program);
|
||||
if(f->program == NULL){
|
||||
free(f);
|
||||
return krb5_enomem(context);
|
||||
if (f->program == NULL) {
|
||||
free(f);
|
||||
return heim_enomem(context);
|
||||
}
|
||||
*fac = f;
|
||||
return 0;
|
||||
}
|
||||
|
||||
KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
|
||||
krb5_addlog_func(krb5_context context,
|
||||
krb5_log_facility *fac,
|
||||
int min,
|
||||
int max,
|
||||
krb5_log_log_func_t log_func,
|
||||
krb5_log_close_func_t close_func,
|
||||
void *data)
|
||||
heim_error_code
|
||||
heim_addlog_func(heim_context context,
|
||||
heim_log_facility *fac,
|
||||
int min,
|
||||
int max,
|
||||
heim_log_log_func_t log_func,
|
||||
heim_log_close_func_t close_func,
|
||||
void *data)
|
||||
{
|
||||
struct facility *fp = log_realloc(fac);
|
||||
struct heim_log_facility_internal *fp = log_realloc(fac);
|
||||
if (fp == NULL)
|
||||
return krb5_enomem(context);
|
||||
return heim_enomem(context);
|
||||
fp->min = min;
|
||||
fp->max = max;
|
||||
fp->log_func = log_func;
|
||||
@@ -158,42 +152,42 @@ struct _heimdal_syslog_data{
|
||||
int priority;
|
||||
};
|
||||
|
||||
static void KRB5_CALLCONV
|
||||
log_syslog(krb5_context context, const char *timestr,
|
||||
const char *msg, void *data)
|
||||
static void
|
||||
log_syslog(heim_context context, const char *timestr,
|
||||
const char *msg, void *data)
|
||||
{
|
||||
struct _heimdal_syslog_data *s = data;
|
||||
syslog(s->priority, "%s", msg);
|
||||
}
|
||||
|
||||
static void KRB5_CALLCONV
|
||||
static void
|
||||
close_syslog(void *data)
|
||||
{
|
||||
free(data);
|
||||
closelog();
|
||||
}
|
||||
|
||||
static krb5_error_code
|
||||
open_syslog(krb5_context context,
|
||||
krb5_log_facility *facility, int min, int max,
|
||||
const char *sev, const char *fac)
|
||||
static heim_error_code
|
||||
open_syslog(heim_context context,
|
||||
heim_log_facility *facility, int min, int max,
|
||||
const char *sev, const char *fac)
|
||||
{
|
||||
struct _heimdal_syslog_data *sd = malloc(sizeof(*sd));
|
||||
int i;
|
||||
|
||||
if (sd == NULL)
|
||||
return krb5_enomem(context);
|
||||
return heim_enomem(context);
|
||||
i = find_value(sev, syslogvals);
|
||||
if(i == -1)
|
||||
i = LOG_ERR;
|
||||
if (i == -1)
|
||||
i = LOG_ERR;
|
||||
sd->priority = i;
|
||||
i = find_value(fac, syslogvals);
|
||||
if(i == -1)
|
||||
i = LOG_AUTH;
|
||||
if (i == -1)
|
||||
i = LOG_AUTH;
|
||||
sd->priority |= i;
|
||||
roken_openlog(facility->program, LOG_PID | LOG_NDELAY, i);
|
||||
return krb5_addlog_func(context, facility, min, max,
|
||||
log_syslog, close_syslog, sd);
|
||||
return heim_addlog_func(context, facility, min, max,
|
||||
log_syslog, close_syslog, sd);
|
||||
}
|
||||
|
||||
struct file_data {
|
||||
@@ -202,14 +196,14 @@ struct file_data {
|
||||
struct timeval tv;
|
||||
FILE *fd;
|
||||
int disp;
|
||||
#define FILEDISP_KEEPOPEN 0x1
|
||||
#define FILEDISP_REOPEN 0x2
|
||||
#define FILEDISP_IFEXISTS 0x3
|
||||
#define FILEDISP_KEEPOPEN 0x1
|
||||
#define FILEDISP_REOPEN 0x2
|
||||
#define FILEDISP_IFEXISTS 0x3
|
||||
int freefilename;
|
||||
};
|
||||
|
||||
static void KRB5_CALLCONV
|
||||
log_file(krb5_context context, const char *timestr, const char *msg, void *data)
|
||||
static void
|
||||
log_file(heim_context context, const char *timestr, const char *msg, void *data)
|
||||
{
|
||||
struct timeval tv;
|
||||
struct file_data *f = data;
|
||||
@@ -218,38 +212,38 @@ log_file(krb5_context context, const char *timestr, const char *msg, void *data)
|
||||
size_t j;
|
||||
|
||||
if (f->disp != FILEDISP_KEEPOPEN) {
|
||||
char *filename;
|
||||
int flags = -1;
|
||||
int fd;
|
||||
char *filename;
|
||||
int flags = -1;
|
||||
int fd;
|
||||
|
||||
if (f->mode[0] == 'w' && f->mode[1] == 0)
|
||||
flags = O_WRONLY|O_TRUNC;
|
||||
if (f->mode[0] == 'a' && f->mode[1] == 0)
|
||||
flags = O_WRONLY|O_APPEND;
|
||||
assert(flags != -1);
|
||||
if (f->mode[0] == 'w' && f->mode[1] == 0)
|
||||
flags = O_WRONLY|O_TRUNC;
|
||||
if (f->mode[0] == 'a' && f->mode[1] == 0)
|
||||
flags = O_WRONLY|O_APPEND;
|
||||
assert(flags != -1);
|
||||
|
||||
if (f->disp == FILEDISP_IFEXISTS) {
|
||||
/* Cache failure for 1s */
|
||||
gettimeofday(&tv, NULL);
|
||||
if (tv.tv_sec == f->tv.tv_sec)
|
||||
return;
|
||||
} else {
|
||||
flags |= O_CREAT;
|
||||
}
|
||||
if (f->disp == FILEDISP_IFEXISTS) {
|
||||
/* Cache failure for 1s */
|
||||
gettimeofday(&tv, NULL);
|
||||
if (tv.tv_sec == f->tv.tv_sec)
|
||||
return;
|
||||
} else {
|
||||
flags |= O_CREAT;
|
||||
}
|
||||
|
||||
if (_krb5_expand_path_tokens(context, f->filename, 1, &filename))
|
||||
return;
|
||||
fd = open(filename, flags, 0666);
|
||||
if (fd == -1) {
|
||||
if (f->disp == FILEDISP_IFEXISTS)
|
||||
gettimeofday(&f->tv, NULL);
|
||||
return;
|
||||
}
|
||||
f->fd = fdopen(fd, f->mode);
|
||||
free(filename);
|
||||
if (heim_expand_path_tokens(context, f->filename, 1, &filename, NULL))
|
||||
return;
|
||||
fd = open(filename, flags, 0666);
|
||||
if (fd == -1) {
|
||||
if (f->disp == FILEDISP_IFEXISTS)
|
||||
gettimeofday(&f->tv, NULL);
|
||||
return;
|
||||
}
|
||||
f->fd = fdopen(fd, f->mode);
|
||||
free(filename);
|
||||
}
|
||||
if(f->fd == NULL)
|
||||
return;
|
||||
if (f->fd == NULL)
|
||||
return;
|
||||
/*
|
||||
* make sure the log doesn't contain special chars:
|
||||
* we used to use strvisx(3) to encode the log, but this is
|
||||
@@ -260,40 +254,40 @@ log_file(krb5_context context, const char *timestr, const char *msg, void *data)
|
||||
*/
|
||||
msgclean = strdup(msg);
|
||||
if (msgclean == NULL)
|
||||
goto out;
|
||||
goto out;
|
||||
for (i=0, j=0; msg[i]; i++)
|
||||
if (msg[i] >= 32 || msg[i] == '\t')
|
||||
msgclean[j++] = msg[i];
|
||||
if (msg[i] >= 32 || msg[i] == '\t')
|
||||
msgclean[j++] = msg[i];
|
||||
fprintf(f->fd, "%s %s\n", timestr, msgclean);
|
||||
free(msgclean);
|
||||
out:
|
||||
if(f->disp != FILEDISP_KEEPOPEN) {
|
||||
fclose(f->fd);
|
||||
f->fd = NULL;
|
||||
out:
|
||||
if (f->disp != FILEDISP_KEEPOPEN) {
|
||||
fclose(f->fd);
|
||||
f->fd = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static void KRB5_CALLCONV
|
||||
static void
|
||||
close_file(void *data)
|
||||
{
|
||||
struct file_data *f = data;
|
||||
if(f->disp == FILEDISP_KEEPOPEN && f->filename)
|
||||
fclose(f->fd);
|
||||
if (f->disp == FILEDISP_KEEPOPEN && f->filename)
|
||||
fclose(f->fd);
|
||||
if (f->filename && f->freefilename)
|
||||
free((char *)f->filename);
|
||||
free((char *)f->filename);
|
||||
free(data);
|
||||
}
|
||||
|
||||
static krb5_error_code
|
||||
open_file(krb5_context context, krb5_log_facility *fac, int min, int max,
|
||||
const char *filename, const char *mode, FILE *f, int disp,
|
||||
int freefilename)
|
||||
static heim_error_code
|
||||
open_file(heim_context context, heim_log_facility *fac, int min, int max,
|
||||
const char *filename, const char *mode, FILE *f, int disp,
|
||||
int freefilename)
|
||||
{
|
||||
struct file_data *fd = malloc(sizeof(*fd));
|
||||
if (fd == NULL) {
|
||||
if (freefilename && filename)
|
||||
free((char *)filename);
|
||||
return krb5_enomem(context);
|
||||
if (freefilename && filename)
|
||||
free((char *)filename);
|
||||
return heim_enomem(context);
|
||||
}
|
||||
fd->filename = filename;
|
||||
fd->mode = mode;
|
||||
@@ -301,15 +295,13 @@ open_file(krb5_context context, krb5_log_facility *fac, int min, int max,
|
||||
fd->disp = disp;
|
||||
fd->freefilename = freefilename;
|
||||
|
||||
return krb5_addlog_func(context, fac, min, max, log_file, close_file, fd);
|
||||
return heim_addlog_func(context, fac, min, max, log_file, close_file, fd);
|
||||
}
|
||||
|
||||
|
||||
|
||||
KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
|
||||
krb5_addlog_dest(krb5_context context, krb5_log_facility *f, const char *orig)
|
||||
heim_error_code
|
||||
heim_addlog_dest(heim_context context, heim_log_facility *f, const char *orig)
|
||||
{
|
||||
krb5_error_code ret = 0;
|
||||
heim_error_code ret = 0;
|
||||
int min = 0, max = 3, n;
|
||||
char c;
|
||||
const char *p = orig;
|
||||
@@ -318,149 +310,158 @@ krb5_addlog_dest(krb5_context context, krb5_log_facility *f, const char *orig)
|
||||
#endif
|
||||
|
||||
n = sscanf(p, "%d%c%d/", &min, &c, &max);
|
||||
if(n == 2){
|
||||
if(ISPATHSEP(c)) {
|
||||
if(min < 0){
|
||||
max = -min;
|
||||
min = 0;
|
||||
}else{
|
||||
max = min;
|
||||
}
|
||||
}
|
||||
if (c == '-')
|
||||
max = -1;
|
||||
if (n == 2) {
|
||||
if (ISPATHSEP(c)) {
|
||||
if (min < 0) {
|
||||
max = -min;
|
||||
min = 0;
|
||||
} else {
|
||||
max = min;
|
||||
}
|
||||
}
|
||||
if (c == '-')
|
||||
max = -1;
|
||||
}
|
||||
if(n){
|
||||
if (n) {
|
||||
#ifdef _WIN32
|
||||
q = strrchr(p, '\\');
|
||||
if (q != NULL)
|
||||
p = q;
|
||||
else
|
||||
q = strrchr(p, '\\');
|
||||
if (q != NULL)
|
||||
p = q;
|
||||
else
|
||||
#endif
|
||||
p = strchr(p, '/');
|
||||
if(p == NULL) {
|
||||
krb5_set_error_message(context, HEIM_ERR_LOG_PARSE,
|
||||
N_("failed to parse \"%s\"", ""), orig);
|
||||
return HEIM_ERR_LOG_PARSE;
|
||||
}
|
||||
p++;
|
||||
p = strchr(p, '/');
|
||||
if (p == NULL) {
|
||||
heim_set_error_message(context, EINVAL /*XXX HEIM_ERR_LOG_PARSE*/,
|
||||
N_("failed to parse \"%s\"", ""), orig);
|
||||
return EINVAL /*XXX HEIM_ERR_LOG_PARSE*/;
|
||||
}
|
||||
p++;
|
||||
}
|
||||
if(strcmp(p, "STDERR") == 0){
|
||||
ret = open_file(context, f, min, max, NULL, NULL, stderr, 1, 0);
|
||||
}else if(strcmp(p, "CONSOLE") == 0){
|
||||
ret = open_file(context, f, min, max, "/dev/console", "w", NULL,
|
||||
FILEDISP_REOPEN, 0);
|
||||
}else if (strncmp(p, "EFILE", 5) == 0 && p[5] == ':') {
|
||||
ret = open_file(context, f, min, max, strdup(p+6), "a", NULL,
|
||||
FILEDISP_IFEXISTS, 1);
|
||||
}else if(strncmp(p, "FILE", 4) == 0 && (p[4] == ':' || p[4] == '=')){
|
||||
char *fn;
|
||||
FILE *file = NULL;
|
||||
int disp = FILEDISP_REOPEN;
|
||||
fn = strdup(p + 5);
|
||||
if (fn == NULL)
|
||||
return krb5_enomem(context);
|
||||
if(p[4] == '='){
|
||||
int i = open(fn, O_WRONLY | O_CREAT |
|
||||
O_TRUNC | O_APPEND, 0666);
|
||||
if(i < 0) {
|
||||
ret = errno;
|
||||
krb5_set_error_message(context, ret,
|
||||
N_("open(%s) logfile: %s", ""), fn,
|
||||
strerror(ret));
|
||||
free(fn);
|
||||
return ret;
|
||||
}
|
||||
rk_cloexec(i);
|
||||
file = fdopen(i, "a");
|
||||
if(file == NULL){
|
||||
ret = errno;
|
||||
close(i);
|
||||
krb5_set_error_message(context, ret,
|
||||
N_("fdopen(%s) logfile: %s", ""),
|
||||
fn, strerror(ret));
|
||||
free(fn);
|
||||
return ret;
|
||||
}
|
||||
disp = FILEDISP_KEEPOPEN;
|
||||
}
|
||||
ret = open_file(context, f, min, max, fn, "a", file, disp, 1);
|
||||
}else if(strncmp(p, "DEVICE", 6) == 0 && (p[6] == ':' || p[6] == '=')){
|
||||
ret = open_file(context, f, min, max, strdup(p + 7), "w", NULL,
|
||||
FILEDISP_REOPEN, 1);
|
||||
}else if(strncmp(p, "SYSLOG", 6) == 0 && (p[6] == '\0' || p[6] == ':')){
|
||||
char severity[128] = "";
|
||||
char facility[128] = "";
|
||||
p += 6;
|
||||
if(*p != '\0')
|
||||
p++;
|
||||
if(strsep_copy(&p, ":", severity, sizeof(severity)) != -1)
|
||||
strsep_copy(&p, ":", facility, sizeof(facility));
|
||||
if(*severity == '\0')
|
||||
strlcpy(severity, "ERR", sizeof(severity));
|
||||
if(*facility == '\0')
|
||||
strlcpy(facility, "AUTH", sizeof(facility));
|
||||
ret = open_syslog(context, f, min, max, severity, facility);
|
||||
}else{
|
||||
ret = HEIM_ERR_LOG_PARSE; /* XXX */
|
||||
krb5_set_error_message (context, ret,
|
||||
N_("unknown log type: %s", ""), p);
|
||||
if (strcmp(p, "STDERR") == 0) {
|
||||
ret = open_file(context, f, min, max, NULL, NULL, stderr, 1, 0);
|
||||
} else if (strcmp(p, "CONSOLE") == 0) {
|
||||
ret = open_file(context, f, min, max, "/dev/console", "w", NULL,
|
||||
FILEDISP_REOPEN, 0);
|
||||
} else if (strncmp(p, "EFILE", 5) == 0 && p[5] == ':') {
|
||||
ret = open_file(context, f, min, max, strdup(p+6), "a", NULL,
|
||||
FILEDISP_IFEXISTS, 1);
|
||||
} else if (strncmp(p, "FILE", 4) == 0 && (p[4] == ':' || p[4] == '=')) {
|
||||
char *fn;
|
||||
FILE *file = NULL;
|
||||
int disp = FILEDISP_REOPEN;
|
||||
fn = strdup(p + 5);
|
||||
if (fn == NULL)
|
||||
return heim_enomem(context);
|
||||
if (p[4] == '=') {
|
||||
int i = open(fn, O_WRONLY | O_CREAT |
|
||||
O_TRUNC | O_APPEND, 0666);
|
||||
if (i < 0) {
|
||||
ret = errno;
|
||||
heim_set_error_message(context, ret,
|
||||
N_("open(%s) logfile: %s", ""), fn,
|
||||
strerror(ret));
|
||||
free(fn);
|
||||
return ret;
|
||||
}
|
||||
rk_cloexec(i);
|
||||
file = fdopen(i, "a");
|
||||
if (file == NULL) {
|
||||
ret = errno;
|
||||
close(i);
|
||||
heim_set_error_message(context, ret,
|
||||
N_("fdopen(%s) logfile: %s", ""),
|
||||
fn, strerror(ret));
|
||||
free(fn);
|
||||
return ret;
|
||||
}
|
||||
disp = FILEDISP_KEEPOPEN;
|
||||
}
|
||||
ret = open_file(context, f, min, max, fn, "a", file, disp, 1);
|
||||
} else if (strncmp(p, "DEVICE", 6) == 0 && (p[6] == ':' || p[6] == '=')) {
|
||||
ret = open_file(context, f, min, max, strdup(p + 7), "w", NULL,
|
||||
FILEDISP_REOPEN, 1);
|
||||
} else if (strncmp(p, "SYSLOG", 6) == 0 && (p[6] == '\0' || p[6] == ':')) {
|
||||
char severity[128] = "";
|
||||
char facility[128] = "";
|
||||
p += 6;
|
||||
if (*p != '\0')
|
||||
p++;
|
||||
if (strsep_copy(&p, ":", severity, sizeof(severity)) != -1)
|
||||
strsep_copy(&p, ":", facility, sizeof(facility));
|
||||
if (*severity == '\0')
|
||||
strlcpy(severity, "ERR", sizeof(severity));
|
||||
if (*facility == '\0')
|
||||
strlcpy(facility, "AUTH", sizeof(facility));
|
||||
ret = open_syslog(context, f, min, max, severity, facility);
|
||||
} else {
|
||||
ret = EINVAL; /*XXX HEIM_ERR_LOG_PARSE*/
|
||||
heim_set_error_message(context, ret,
|
||||
N_("unknown log type: %s", ""), p);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
|
||||
krb5_openlog(krb5_context context,
|
||||
const char *program,
|
||||
krb5_log_facility **fac)
|
||||
heim_error_code
|
||||
heim_openlog(heim_context context,
|
||||
const char *program,
|
||||
const char **specs,
|
||||
heim_log_facility **fac)
|
||||
{
|
||||
krb5_error_code ret;
|
||||
char **p, **q;
|
||||
heim_error_code ret;
|
||||
|
||||
ret = krb5_initlog(context, program, fac);
|
||||
if(ret)
|
||||
return ret;
|
||||
ret = heim_initlog(context, program, fac);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
p = krb5_config_get_strings(context, NULL, "logging", program, NULL);
|
||||
if(p == NULL)
|
||||
p = krb5_config_get_strings(context, NULL, "logging", "default", NULL);
|
||||
if(p){
|
||||
for(q = p; *q && ret == 0; q++)
|
||||
ret = krb5_addlog_dest(context, *fac, *q);
|
||||
krb5_config_free_strings(p);
|
||||
}else
|
||||
ret = krb5_addlog_dest(context, *fac, "SYSLOG");
|
||||
if (specs) {
|
||||
size_t i;
|
||||
for (i = 0; specs[i] && ret == 0; i++)
|
||||
ret = heim_addlog_dest(context, *fac, specs[i]);
|
||||
} else {
|
||||
ret = heim_addlog_dest(context, *fac, "SYSLOG");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
|
||||
krb5_closelog(krb5_context context,
|
||||
krb5_log_facility *fac)
|
||||
void
|
||||
heim_closelog(heim_context context, heim_log_facility *fac)
|
||||
{
|
||||
int i;
|
||||
for(i = 0; i < fac->len; i++)
|
||||
(*fac->val[i].close_func)(fac->val[i].data);
|
||||
|
||||
if (!fac)
|
||||
return;
|
||||
for (i = 0; i < fac->len; i++)
|
||||
(*fac->val[i].close_func)(fac->val[i].data);
|
||||
free(fac->val);
|
||||
free(fac->program);
|
||||
fac->val = NULL;
|
||||
fac->len = 0;
|
||||
fac->program = NULL;
|
||||
free(fac);
|
||||
return 0;
|
||||
return;
|
||||
}
|
||||
|
||||
static void
|
||||
format_time(heim_context context, time_t t, char *s, size_t len)
|
||||
{
|
||||
struct tm *tm = heim_context_get_log_utc(context) ?
|
||||
gmtime(&t) : localtime(&t);
|
||||
if (tm && strftime(s, len, heim_context_get_time_fmt(context), tm))
|
||||
return;
|
||||
snprintf(s, len, "%ld", (long)t);
|
||||
}
|
||||
|
||||
#undef __attribute__
|
||||
#define __attribute__(X)
|
||||
|
||||
KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
|
||||
krb5_vlog_msg(krb5_context context,
|
||||
krb5_log_facility *fac,
|
||||
char **reply,
|
||||
int level,
|
||||
const char *fmt,
|
||||
va_list ap)
|
||||
__attribute__ ((__format__ (__printf__, 5, 0)))
|
||||
heim_error_code
|
||||
heim_vlog_msg(heim_context context,
|
||||
heim_log_facility *fac,
|
||||
char **reply,
|
||||
int level,
|
||||
const char *fmt,
|
||||
va_list ap)
|
||||
__attribute__ ((__format__ (__printf__, 5, 0)))
|
||||
{
|
||||
|
||||
char *msg = NULL;
|
||||
@@ -469,114 +470,156 @@ krb5_vlog_msg(krb5_context context,
|
||||
time_t t = 0;
|
||||
int i;
|
||||
|
||||
for(i = 0; fac && i < fac->len; i++)
|
||||
if(fac->val[i].min <= level &&
|
||||
(fac->val[i].max < 0 || fac->val[i].max >= level)) {
|
||||
if(t == 0) {
|
||||
t = time(NULL);
|
||||
krb5_format_time(context, t, buf, sizeof(buf), TRUE);
|
||||
}
|
||||
if(actual == NULL) {
|
||||
int ret = vasprintf(&msg, fmt, ap);
|
||||
if(ret < 0 || msg == NULL)
|
||||
actual = fmt;
|
||||
else
|
||||
actual = msg;
|
||||
}
|
||||
(*fac->val[i].log_func)(context, buf, actual, fac->val[i].data);
|
||||
}
|
||||
if(reply == NULL)
|
||||
free(msg);
|
||||
for (i = 0; fac && i < fac->len; i++)
|
||||
if (fac->val[i].min <= level &&
|
||||
(fac->val[i].max < 0 || fac->val[i].max >= level)) {
|
||||
if (t == 0) {
|
||||
t = time(NULL);
|
||||
format_time(context, t, buf, sizeof(buf));
|
||||
}
|
||||
if (actual == NULL) {
|
||||
int ret = vasprintf(&msg, fmt, ap);
|
||||
if (ret < 0 || msg == NULL)
|
||||
actual = fmt;
|
||||
else
|
||||
actual = msg;
|
||||
}
|
||||
(*fac->val[i].log_func)(context, buf, actual, fac->val[i].data);
|
||||
}
|
||||
if (reply == NULL)
|
||||
free(msg);
|
||||
else
|
||||
*reply = msg;
|
||||
*reply = msg;
|
||||
return 0;
|
||||
}
|
||||
|
||||
KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
|
||||
krb5_vlog(krb5_context context,
|
||||
krb5_log_facility *fac,
|
||||
int level,
|
||||
const char *fmt,
|
||||
va_list ap)
|
||||
__attribute__ ((__format__ (__printf__, 4, 0)))
|
||||
heim_error_code
|
||||
heim_vlog(heim_context context,
|
||||
heim_log_facility *fac,
|
||||
int level,
|
||||
const char *fmt,
|
||||
va_list ap)
|
||||
__attribute__ ((__format__ (__printf__, 4, 0)))
|
||||
{
|
||||
return krb5_vlog_msg(context, fac, NULL, level, fmt, ap);
|
||||
return heim_vlog_msg(context, fac, NULL, level, fmt, ap);
|
||||
}
|
||||
|
||||
KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
|
||||
krb5_log_msg(krb5_context context,
|
||||
krb5_log_facility *fac,
|
||||
int level,
|
||||
char **reply,
|
||||
const char *fmt,
|
||||
...)
|
||||
__attribute__ ((__format__ (__printf__, 5, 6)))
|
||||
heim_error_code
|
||||
heim_log_msg(heim_context context,
|
||||
heim_log_facility *fac,
|
||||
int level,
|
||||
char **reply,
|
||||
const char *fmt,
|
||||
...)
|
||||
__attribute__ ((__format__ (__printf__, 5, 6)))
|
||||
{
|
||||
va_list ap;
|
||||
krb5_error_code ret;
|
||||
heim_error_code ret;
|
||||
|
||||
va_start(ap, fmt);
|
||||
ret = krb5_vlog_msg(context, fac, reply, level, fmt, ap);
|
||||
ret = heim_vlog_msg(context, fac, reply, level, fmt, ap);
|
||||
va_end(ap);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
|
||||
krb5_log(krb5_context context,
|
||||
krb5_log_facility *fac,
|
||||
int level,
|
||||
const char *fmt,
|
||||
...)
|
||||
__attribute__ ((__format__ (__printf__, 4, 5)))
|
||||
heim_error_code
|
||||
heim_log(heim_context context,
|
||||
heim_log_facility *fac,
|
||||
int level,
|
||||
const char *fmt,
|
||||
...)
|
||||
__attribute__ ((__format__ (__printf__, 4, 5)))
|
||||
{
|
||||
va_list ap;
|
||||
krb5_error_code ret;
|
||||
heim_error_code ret;
|
||||
|
||||
va_start(ap, fmt);
|
||||
ret = krb5_vlog(context, fac, level, fmt, ap);
|
||||
ret = heim_vlog(context, fac, level, fmt, ap);
|
||||
va_end(ap);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void KRB5_LIB_FUNCTION
|
||||
_krb5_debug(krb5_context context,
|
||||
int level,
|
||||
const char *fmt,
|
||||
...)
|
||||
__attribute__ ((__format__ (__printf__, 3, 4)))
|
||||
void
|
||||
heim_debug(heim_context context,
|
||||
int level,
|
||||
const char *fmt,
|
||||
...)
|
||||
__attribute__ ((__format__ (__printf__, 3, 4)))
|
||||
{
|
||||
heim_log_facility *fac;
|
||||
va_list ap;
|
||||
|
||||
if (context == NULL || context->debug_dest == NULL)
|
||||
return;
|
||||
if (context == NULL ||
|
||||
(fac = heim_get_debug_dest(context)) == NULL)
|
||||
return;
|
||||
|
||||
va_start(ap, fmt);
|
||||
krb5_vlog(context, context->debug_dest, level, fmt, ap);
|
||||
heim_vlog(context, fac, level, fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL
|
||||
_krb5_have_debug(krb5_context context, int level)
|
||||
void
|
||||
heim_vdebug(heim_context context,
|
||||
int level,
|
||||
const char *fmt,
|
||||
va_list ap)
|
||||
__attribute__ ((__format__ (__printf__, 3, 0)))
|
||||
{
|
||||
if (context == NULL || context->debug_dest == NULL)
|
||||
return 0 ;
|
||||
return 1;
|
||||
heim_log_facility *fac;
|
||||
|
||||
if (context == NULL ||
|
||||
(fac = heim_get_debug_dest(context)) == NULL)
|
||||
return;
|
||||
|
||||
heim_vlog(context, fac, level, fmt, ap);
|
||||
}
|
||||
|
||||
KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
|
||||
krb5_set_debug_dest(krb5_context context, const char *program,
|
||||
const char *log_spec)
|
||||
heim_error_code
|
||||
heim_have_debug(heim_context context, int level)
|
||||
{
|
||||
krb5_error_code ret;
|
||||
heim_log_facility *fac;
|
||||
|
||||
if (context->debug_dest == NULL) {
|
||||
ret = krb5_initlog(context, program, &context->debug_dest);
|
||||
return (context != NULL &&
|
||||
(fac = heim_get_debug_dest(context)) != NULL);
|
||||
}
|
||||
|
||||
heim_error_code
|
||||
heim_add_warn_dest(heim_context context, const char *program,
|
||||
const char *log_spec)
|
||||
{
|
||||
heim_log_facility *fac;
|
||||
|
||||
heim_error_code ret;
|
||||
|
||||
if ((fac = heim_get_warn_dest(context)) == NULL) {
|
||||
ret = heim_initlog(context, program, &fac);
|
||||
if (ret)
|
||||
return ret;
|
||||
heim_set_warn_dest(context, fac);
|
||||
}
|
||||
|
||||
ret = krb5_addlog_dest(context, context->debug_dest, log_spec);
|
||||
ret = heim_addlog_dest(context, fac, log_spec);
|
||||
if (ret)
|
||||
return ret;
|
||||
return 0;
|
||||
}
|
||||
|
||||
heim_error_code
|
||||
heim_add_debug_dest(heim_context context, const char *program,
|
||||
const char *log_spec)
|
||||
{
|
||||
heim_log_facility *fac;
|
||||
heim_error_code ret;
|
||||
|
||||
if ((fac = heim_get_debug_dest(context)) == NULL) {
|
||||
ret = heim_initlog(context, program, &fac);
|
||||
if (ret)
|
||||
return ret;
|
||||
heim_set_debug_dest(context, fac);
|
||||
}
|
||||
|
||||
ret = heim_addlog_dest(context, fac, log_spec);
|
||||
if (ret)
|
||||
return ret;
|
||||
return 0;
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2006 - 2007 Kungliga Tekniska Högskolan
|
||||
* Copyright (c) 2006 - 2020 Kungliga Tekniska Högskolan
|
||||
* (Royal Institute of Technology, Stockholm, Sweden).
|
||||
* All rights reserved.
|
||||
*
|
||||
@@ -33,30 +33,31 @@
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "krb5_locl.h"
|
||||
#include "baselocl.h"
|
||||
#include "common_plugin.h"
|
||||
|
||||
/*
|
||||
* Documentation for the Heimdal plugin system is in lib/krb5/plugin.c and
|
||||
* lib/krb5/krb5-plugin.7.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Definitions:
|
||||
*
|
||||
* module - a category of plugin module, identified by subsystem
|
||||
* (typically "krb5")
|
||||
* dso - a library for a module containing a map of plugin
|
||||
* types to plugins (e.g. "service_locator")
|
||||
* plugin - a set of callbacks and state that follows the
|
||||
* common plugin module definition (version, init, fini)
|
||||
* module - a category of plugin module, identified by subsystem
|
||||
* (e.g., "krb5")
|
||||
* dso - a library for a module containing a map of plugin
|
||||
* types to plugins (e.g. "service_locator")
|
||||
* plugin - a set of callbacks and state that follows the
|
||||
* common plugin module definition (version, init, fini)
|
||||
*
|
||||
* Obviously it would have been clearer to use the term "module" rather than
|
||||
* "DSO" given there is an internal "DSO", but "module" was already taken...
|
||||
*
|
||||
* modules := { module: dsos }
|
||||
* dsos := { path, dsohandle, plugins-by-name }
|
||||
* plugins-by-name := { plugin-name: [plug] }
|
||||
* plug := { ftable, ctx }
|
||||
*
|
||||
* Some existing plugin consumers outside libkrb5 use the "krb5" module
|
||||
* namespace, but going forward the module should match the consumer library
|
||||
* name (e.g. libhdb should use the "hdb" module rather than "krb5").
|
||||
* modules := { module: dsos }
|
||||
* dsos := { path, dsohandle, plugins-by-name }
|
||||
* plugins-by-name := { plugin-name: [plug] }
|
||||
* plug := { ftable, ctx }
|
||||
*/
|
||||
|
||||
/* global module use, use copy_modules() accessor to access */
|
||||
@@ -94,8 +95,8 @@ copy_module(const char *name)
|
||||
|
||||
module = heim_dict_copy_value(modules, module_name);
|
||||
if (module == NULL) {
|
||||
module = heim_dict_create(11);
|
||||
heim_dict_set_value(modules, module_name, module);
|
||||
module = heim_dict_create(11);
|
||||
heim_dict_set_value(modules, module_name, module);
|
||||
}
|
||||
|
||||
heim_release(modules);
|
||||
@@ -105,7 +106,7 @@ copy_module(const char *name)
|
||||
}
|
||||
|
||||
/* DSO helpers */
|
||||
struct krb5_dso {
|
||||
struct heim_dso {
|
||||
heim_string_t path;
|
||||
heim_dict_t plugins_by_name;
|
||||
void *dsohandle;
|
||||
@@ -114,35 +115,35 @@ struct krb5_dso {
|
||||
static void
|
||||
dso_dealloc(void *ptr)
|
||||
{
|
||||
struct krb5_dso *p = ptr;
|
||||
struct heim_dso *p = ptr;
|
||||
|
||||
heim_release(p->path);
|
||||
heim_release(p->plugins_by_name);
|
||||
#ifdef HAVE_DLOPEN
|
||||
if (p->dsohandle)
|
||||
dlclose(p->dsohandle);
|
||||
dlclose(p->dsohandle);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* returns internal "DSO" for name, refcount +1 */
|
||||
static struct krb5_dso *
|
||||
static struct heim_dso *
|
||||
copy_internal_dso(const char *name)
|
||||
{
|
||||
heim_string_t dso_name = HSTR("__HEIMDAL_INTERNAL_DSO__");
|
||||
heim_dict_t module = copy_module(name);
|
||||
struct krb5_dso *dso;
|
||||
struct heim_dso *dso;
|
||||
|
||||
if (module == NULL)
|
||||
return NULL;
|
||||
return NULL;
|
||||
|
||||
dso = heim_dict_copy_value(module, dso_name);
|
||||
if (dso == NULL) {
|
||||
dso = heim_alloc(sizeof(*dso), "krb5-dso", dso_dealloc);
|
||||
dso = heim_alloc(sizeof(*dso), "heim-dso", dso_dealloc);
|
||||
|
||||
dso->path = dso_name;
|
||||
dso->plugins_by_name = heim_dict_create(11);
|
||||
dso->path = dso_name;
|
||||
dso->plugins_by_name = heim_dict_create(11);
|
||||
|
||||
heim_dict_set_value(module, dso_name, dso);
|
||||
heim_dict_set_value(module, dso_name, dso);
|
||||
}
|
||||
|
||||
heim_release(module);
|
||||
@@ -150,21 +151,21 @@ copy_internal_dso(const char *name)
|
||||
return dso;
|
||||
}
|
||||
|
||||
struct krb5_plugin {
|
||||
krb5_plugin_common_ftable_p ftable;
|
||||
struct heim_plugin {
|
||||
heim_plugin_common_ftable_p ftable;
|
||||
void *ctx;
|
||||
};
|
||||
|
||||
static void
|
||||
plugin_free(void *ptr)
|
||||
{
|
||||
struct krb5_plugin *pl = ptr;
|
||||
struct heim_plugin *pl = ptr;
|
||||
|
||||
if (pl->ftable && pl->ftable->fini)
|
||||
pl->ftable->fini(pl->ctx);
|
||||
pl->ftable->fini(pl->ctx);
|
||||
}
|
||||
|
||||
struct krb5_plugin_register_ctx {
|
||||
struct heim_plugin_register_ctx {
|
||||
void *symbol;
|
||||
int is_dup;
|
||||
};
|
||||
@@ -172,82 +173,73 @@ struct krb5_plugin_register_ctx {
|
||||
static void
|
||||
plugin_register_check_dup(heim_object_t value, void *ctx, int *stop)
|
||||
{
|
||||
struct krb5_plugin_register_ctx *pc = ctx;
|
||||
struct krb5_plugin *pl = value;
|
||||
struct heim_plugin_register_ctx *pc = ctx;
|
||||
struct heim_plugin *pl = value;
|
||||
|
||||
if (pl->ftable == pc->symbol) {
|
||||
pc->is_dup = 1;
|
||||
*stop = 1;
|
||||
pc->is_dup = 1;
|
||||
*stop = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a plugin symbol name of specific type.
|
||||
* @param context a Keberos context
|
||||
* @param type type of plugin symbol
|
||||
* @param name name of plugin symbol
|
||||
* @param symbol a pointer to the named symbol
|
||||
* @param module name of plugin module (e.g., "krb5")
|
||||
* @param name name of plugin symbol (e.g., "krb5_plugin_kuserok")
|
||||
* @param ftable a pointer to a function pointer table
|
||||
* @return In case of error a non zero error com_err error is returned
|
||||
* and the Kerberos error string is set.
|
||||
*
|
||||
* @ingroup krb5_support
|
||||
* @ingroup heim_support
|
||||
*/
|
||||
|
||||
KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
|
||||
krb5_plugin_register(krb5_context context,
|
||||
enum krb5_plugin_type type,
|
||||
const char *name,
|
||||
void *symbol)
|
||||
heim_error_code
|
||||
heim_plugin_register(heim_context context,
|
||||
heim_pcontext pcontext,
|
||||
const char *module,
|
||||
const char *name,
|
||||
void *ftable)
|
||||
{
|
||||
krb5_error_code ret;
|
||||
heim_error_code ret;
|
||||
heim_array_t plugins;
|
||||
heim_string_t hname;
|
||||
struct krb5_dso *dso;
|
||||
struct krb5_plugin_register_ctx ctx;
|
||||
struct heim_dso *dso;
|
||||
struct heim_plugin_register_ctx ctx;
|
||||
|
||||
ctx.symbol = symbol;
|
||||
ctx.symbol = ftable;
|
||||
ctx.is_dup = 0;
|
||||
|
||||
/*
|
||||
* It's not clear that PLUGIN_TYPE_FUNC was ever used or supported. It likely
|
||||
* would have caused _krb5_plugin_run_f() to crash as the previous implementation
|
||||
* assumed PLUGIN_TYPE_DATA.
|
||||
*/
|
||||
if (type != PLUGIN_TYPE_DATA) {
|
||||
krb5_warnx(context, "krb5_plugin_register: PLUGIN_TYPE_DATA no longer supported");
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
HEIMDAL_MUTEX_lock(&modules_mutex);
|
||||
|
||||
dso = copy_internal_dso("krb5");
|
||||
dso = copy_internal_dso(module);
|
||||
hname = heim_string_create(name);
|
||||
plugins = heim_dict_copy_value(dso->plugins_by_name, hname);
|
||||
if (plugins != NULL)
|
||||
heim_array_iterate_f(plugins, &ctx, plugin_register_check_dup);
|
||||
heim_array_iterate_f(plugins, &ctx, plugin_register_check_dup);
|
||||
else {
|
||||
plugins = heim_array_create();
|
||||
heim_dict_set_value(dso->plugins_by_name, hname, plugins);
|
||||
plugins = heim_array_create();
|
||||
heim_dict_set_value(dso->plugins_by_name, hname, plugins);
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
if (!ctx.is_dup) {
|
||||
/* Note: refactored plugin API only supports common plugin layout */
|
||||
struct krb5_plugin *pl;
|
||||
/* Note: refactored plugin API only supports common plugin layout */
|
||||
struct heim_plugin *pl;
|
||||
|
||||
pl = heim_alloc(sizeof(*pl), "krb5-plugin", plugin_free);
|
||||
if (pl == NULL) {
|
||||
ret = krb5_enomem(context);
|
||||
} else {
|
||||
pl->ftable = symbol;
|
||||
ret = pl->ftable->init(context, &pl->ctx);
|
||||
if (ret == 0) {
|
||||
heim_array_append_value(plugins, pl);
|
||||
_krb5_debug(context, 5, "Registered %s plugin", name);
|
||||
}
|
||||
heim_release(pl);
|
||||
}
|
||||
} else
|
||||
ret = 0; /* ignore duplicates to match previous behavior */
|
||||
pl = heim_alloc(sizeof(*pl), "heim-plugin", plugin_free);
|
||||
if (pl == NULL) {
|
||||
ret = heim_enomem(context);
|
||||
} else {
|
||||
pl->ftable = ftable;
|
||||
ret = pl->ftable->init(pcontext, &pl->ctx);
|
||||
if (ret == 0) {
|
||||
heim_array_append_value(plugins, pl);
|
||||
heim_debug(context, 5, "Registered %s plugin", name);
|
||||
}
|
||||
heim_release(pl);
|
||||
}
|
||||
}
|
||||
|
||||
HEIMDAL_MUTEX_unlock(&modules_mutex);
|
||||
|
||||
@@ -261,32 +253,34 @@ krb5_plugin_register(krb5_context context,
|
||||
#ifdef HAVE_DLOPEN
|
||||
|
||||
static char *
|
||||
resolve_origin(const char *di)
|
||||
resolve_origin(const char *di, const char *module)
|
||||
{
|
||||
#ifdef HAVE_DLADDR
|
||||
Dl_info dl_info;
|
||||
const char *dname;
|
||||
char *path, *p;
|
||||
#endif
|
||||
|
||||
if (strncmp(di, "$ORIGIN/", sizeof("$ORIGIN/") - 1) &&
|
||||
strcmp(di, "$ORIGIN"))
|
||||
return strdup(di);
|
||||
|
||||
#ifndef HAVE_DLADDR
|
||||
return strdup(LIBDIR "/plugin/krb5");
|
||||
#else /* !HAVE_DLADDR */
|
||||
di += sizeof("$ORIGIN") - 1;
|
||||
|
||||
if (dladdr(_krb5_load_plugins, &dl_info) == 0)
|
||||
return strdup(LIBDIR "/plugin/krb5");
|
||||
if (dladdr(heim_plugin_register, &dl_info) == 0) {
|
||||
char *s = NULL;
|
||||
|
||||
/* dladdr() failed */
|
||||
if (asprintf(&s, LIBDIR "/plugin/%s", module) == -1)
|
||||
return NULL;
|
||||
return s;
|
||||
}
|
||||
|
||||
dname = dl_info.dli_fname;
|
||||
#ifdef _WIN32
|
||||
p = strrchr(dname, '\\');
|
||||
if (p == NULL)
|
||||
#endif
|
||||
p = strrchr(dname, '/');
|
||||
p = strrchr(dname, '/');
|
||||
if (p) {
|
||||
if (asprintf(&path, "%.*s%s", (int) (p - dname), dname, di) == -1)
|
||||
return NULL;
|
||||
@@ -296,29 +290,40 @@ resolve_origin(const char *di)
|
||||
}
|
||||
|
||||
return path;
|
||||
#endif /* !HAVE_DLADDR */
|
||||
#else
|
||||
char *s = NULL;
|
||||
|
||||
if (strncmp(di, "$ORIGIN/", sizeof("$ORIGIN/") - 1) &&
|
||||
strcmp(di, "$ORIGIN"))
|
||||
return strdup(di);
|
||||
if (asprintf(&s, LIBDIR "/plugin/%s", module) == -1)
|
||||
return NULL;
|
||||
return s;
|
||||
#endif /* HAVE_DLADDR */
|
||||
}
|
||||
|
||||
#endif /* HAVE_DLOPEN */
|
||||
|
||||
/**
|
||||
* Load plugins (new system) for the given module @name (typically
|
||||
* "krb5") from the given directory @paths.
|
||||
* Load plugins (new system) for the given module @module from the given
|
||||
* directory @paths.
|
||||
*
|
||||
* Inputs:
|
||||
*
|
||||
* @context A krb5_context
|
||||
* @name Name of plugin module (typically "krb5")
|
||||
* @paths Array of directory paths where to look
|
||||
* @context A heim_context
|
||||
* @module Name of plugin module (typically "krb5")
|
||||
* @paths Array of directory paths where to look
|
||||
*/
|
||||
KRB5_LIB_FUNCTION void KRB5_LIB_CALL
|
||||
_krb5_load_plugins(krb5_context context, const char *name, const char **paths)
|
||||
void
|
||||
heim_load_plugins(heim_context context,
|
||||
const char *module,
|
||||
const char **paths)
|
||||
{
|
||||
#ifdef HAVE_DLOPEN
|
||||
heim_string_t s = heim_string_create(name);
|
||||
heim_dict_t module, modules;
|
||||
heim_string_t s = heim_string_create(module);
|
||||
heim_dict_t mod, modules;
|
||||
struct dirent *entry;
|
||||
krb5_error_code ret;
|
||||
heim_error_code ret;
|
||||
const char **di;
|
||||
char *dirname = NULL;
|
||||
DIR *d;
|
||||
@@ -326,8 +331,8 @@ _krb5_load_plugins(krb5_context context, const char *name, const char **paths)
|
||||
char *plugin_prefix;
|
||||
size_t plugin_prefix_len;
|
||||
|
||||
if (asprintf(&plugin_prefix, "plugin_%s_", name) == -1)
|
||||
return;
|
||||
if (asprintf(&plugin_prefix, "plugin_%s_", module) == -1)
|
||||
return;
|
||||
plugin_prefix_len = (plugin_prefix ? strlen(plugin_prefix) : 0);
|
||||
#endif
|
||||
|
||||
@@ -335,115 +340,119 @@ _krb5_load_plugins(krb5_context context, const char *name, const char **paths)
|
||||
|
||||
modules = copy_modules();
|
||||
|
||||
module = heim_dict_copy_value(modules, s);
|
||||
if (module == NULL) {
|
||||
module = heim_dict_create(11);
|
||||
if (module == NULL) {
|
||||
HEIMDAL_MUTEX_unlock(&modules_mutex);
|
||||
heim_release(s);
|
||||
heim_release(modules);
|
||||
return;
|
||||
}
|
||||
heim_dict_set_value(modules, s, module);
|
||||
mod = heim_dict_copy_value(modules, s);
|
||||
if (mod == NULL) {
|
||||
mod = heim_dict_create(11);
|
||||
if (mod == NULL) {
|
||||
HEIMDAL_MUTEX_unlock(&modules_mutex);
|
||||
heim_release(s);
|
||||
heim_release(modules);
|
||||
return;
|
||||
}
|
||||
heim_dict_set_value(modules, s, mod);
|
||||
}
|
||||
heim_release(s);
|
||||
heim_release(modules);
|
||||
|
||||
for (di = paths; *di != NULL; di++) {
|
||||
free(dirname);
|
||||
dirname = resolve_origin(*di);
|
||||
dirname = resolve_origin(*di, module);
|
||||
if (dirname == NULL)
|
||||
continue;
|
||||
d = opendir(dirname);
|
||||
if (d == NULL)
|
||||
continue;
|
||||
rk_cloexec_dir(d);
|
||||
d = opendir(dirname);
|
||||
if (d == NULL)
|
||||
continue;
|
||||
rk_cloexec_dir(d);
|
||||
|
||||
while ((entry = readdir(d)) != NULL) {
|
||||
char *n = entry->d_name;
|
||||
char *path = NULL;
|
||||
heim_string_t spath;
|
||||
struct krb5_dso *p;
|
||||
while ((entry = readdir(d)) != NULL) {
|
||||
char *n = entry->d_name;
|
||||
char *path = NULL;
|
||||
heim_string_t spath;
|
||||
struct heim_dso *p;
|
||||
|
||||
/* skip . and .. */
|
||||
if (n[0] == '.' && (n[1] == '\0' || (n[1] == '.' && n[2] == '\0')))
|
||||
continue;
|
||||
/* skip . and .. */
|
||||
if (n[0] == '.' && (n[1] == '\0' || (n[1] == '.' && n[2] == '\0')))
|
||||
continue;
|
||||
|
||||
ret = 0;
|
||||
ret = 0;
|
||||
#ifdef _WIN32
|
||||
/*
|
||||
* On Windows, plugins must be loaded from the same directory as
|
||||
* heimdal.dll (typically the assembly directory) and must have
|
||||
* the name form "plugin_<module>_<name>.dll".
|
||||
*/
|
||||
{
|
||||
char *ext;
|
||||
/*
|
||||
* On Windows, plugins must be loaded from the same directory as
|
||||
* heimdal.dll (typically the assembly directory) and must have
|
||||
* the name form "plugin_<module>_<name>.dll".
|
||||
*/
|
||||
{
|
||||
char *ext;
|
||||
|
||||
if (strnicmp(n, plugin_prefix, plugin_prefix_len))
|
||||
continue;
|
||||
ext = strrchr(n, '.');
|
||||
if (ext == NULL || stricmp(ext, ".dll"))
|
||||
continue;
|
||||
if (strnicmp(n, plugin_prefix, plugin_prefix_len))
|
||||
continue;
|
||||
ext = strrchr(n, '.');
|
||||
if (ext == NULL || stricmp(ext, ".dll"))
|
||||
continue;
|
||||
|
||||
ret = asprintf(&path, "%s\\%s", dirname, n);
|
||||
if (ret < 0 || path == NULL)
|
||||
continue;
|
||||
}
|
||||
ret = asprintf(&path, "%s\\%s", dirname, n);
|
||||
if (ret < 0 || path == NULL)
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
#ifdef __APPLE__
|
||||
{ /* support loading bundles on MacOS */
|
||||
size_t len = strlen(n);
|
||||
if (len > 7 && strcmp(&n[len - 7], ".bundle") == 0)
|
||||
ret = asprintf(&path, "%s/%s/Contents/MacOS/%.*s", dirname, n, (int)(len - 7), n);
|
||||
}
|
||||
{ /* support loading bundles on MacOS */
|
||||
size_t len = strlen(n);
|
||||
if (len > 7 && strcmp(&n[len - 7], ".bundle") == 0)
|
||||
ret = asprintf(&path, "%s/%s/Contents/MacOS/%.*s", dirname, n, (int)(len - 7), n);
|
||||
}
|
||||
#endif
|
||||
if (ret < 0 || path == NULL)
|
||||
ret = asprintf(&path, "%s/%s", dirname, n);
|
||||
if (ret < 0 || path == NULL)
|
||||
ret = asprintf(&path, "%s/%s", dirname, n);
|
||||
|
||||
if (ret < 0 || path == NULL)
|
||||
continue;
|
||||
if (ret < 0 || path == NULL)
|
||||
continue;
|
||||
|
||||
spath = heim_string_create(n);
|
||||
if (spath == NULL) {
|
||||
free(path);
|
||||
continue;
|
||||
}
|
||||
spath = heim_string_create(n);
|
||||
if (spath == NULL) {
|
||||
free(path);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* check if already cached */
|
||||
p = heim_dict_copy_value(module, spath);
|
||||
if (p == NULL) {
|
||||
p = heim_alloc(sizeof(*p), "krb5-dso", dso_dealloc);
|
||||
if (p)
|
||||
p->dsohandle = dlopen(path, RTLD_LOCAL|RTLD_LAZY|RTLD_GROUP);
|
||||
if (p && p->dsohandle) {
|
||||
p->path = heim_retain(spath);
|
||||
p->plugins_by_name = heim_dict_create(11);
|
||||
heim_dict_set_value(module, spath, p);
|
||||
}
|
||||
}
|
||||
/* check if already cached */
|
||||
p = heim_dict_copy_value(mod, spath);
|
||||
if (p == NULL) {
|
||||
p = heim_alloc(sizeof(*p), "heim-dso", dso_dealloc);
|
||||
if (p)
|
||||
p->dsohandle = dlopen(path, RTLD_LOCAL|RTLD_LAZY|RTLD_GROUP);
|
||||
if (p && p->dsohandle) {
|
||||
p->path = heim_retain(spath);
|
||||
p->plugins_by_name = heim_dict_create(11);
|
||||
heim_dict_set_value(mod, spath, p);
|
||||
}
|
||||
}
|
||||
heim_release(p);
|
||||
heim_release(spath);
|
||||
free(path);
|
||||
}
|
||||
closedir(d);
|
||||
heim_release(spath);
|
||||
free(path);
|
||||
}
|
||||
closedir(d);
|
||||
}
|
||||
free(dirname);
|
||||
HEIMDAL_MUTEX_unlock(&modules_mutex);
|
||||
heim_release(module);
|
||||
heim_release(mod);
|
||||
#ifdef _WIN32
|
||||
if (plugin_prefix)
|
||||
free(plugin_prefix);
|
||||
free(plugin_prefix);
|
||||
#endif
|
||||
#endif /* HAVE_DLOPEN */
|
||||
}
|
||||
|
||||
/**
|
||||
* Unload plugins (new system)
|
||||
* Unload plugins of the given @module name.
|
||||
*
|
||||
* Params:
|
||||
*
|
||||
* @module Name of module whose plusins to unload.
|
||||
*/
|
||||
KRB5_LIB_FUNCTION void KRB5_LIB_CALL
|
||||
_krb5_unload_plugins(krb5_context context, const char *name)
|
||||
void
|
||||
heim_unload_plugins(heim_context context, const char *module)
|
||||
{
|
||||
heim_string_t sname = heim_string_create(name);
|
||||
heim_string_t sname = heim_string_create(module);
|
||||
heim_dict_t modules;
|
||||
|
||||
HEIMDAL_MUTEX_lock(&modules_mutex);
|
||||
@@ -458,14 +467,16 @@ _krb5_unload_plugins(krb5_context context, const char *name)
|
||||
}
|
||||
|
||||
struct iter_ctx {
|
||||
krb5_context context;
|
||||
heim_context context;
|
||||
heim_pcontext pcontext;
|
||||
heim_string_t n;
|
||||
struct krb5_plugin_data *caller;
|
||||
struct heim_plugin_data *caller;
|
||||
int flags;
|
||||
heim_array_t result;
|
||||
krb5_error_code (KRB5_LIB_CALL *func)(krb5_context, const void *, void *, void *);
|
||||
int32_t (HEIM_LIB_CALL *func)(void *, const void *, void *, void *);
|
||||
void *userctx;
|
||||
krb5_error_code ret;
|
||||
int32_t ret;
|
||||
int32_t plugin_no_handle_retval;
|
||||
};
|
||||
|
||||
#ifdef HAVE_DLOPEN
|
||||
@@ -476,33 +487,34 @@ struct iter_ctx {
|
||||
* instance validation.
|
||||
*/
|
||||
static heim_array_t
|
||||
add_dso_plugin_struct(krb5_context context,
|
||||
const char *dsopath,
|
||||
void *dsohandle,
|
||||
const char *name)
|
||||
add_dso_plugin_struct(heim_context context,
|
||||
heim_pcontext pcontext,
|
||||
const char *dsopath,
|
||||
void *dsohandle,
|
||||
const char *name)
|
||||
{
|
||||
krb5_error_code ret;
|
||||
krb5_plugin_common_ftable_p cpm;
|
||||
struct krb5_plugin *pl;
|
||||
heim_error_code ret;
|
||||
heim_plugin_common_ftable_p cpm;
|
||||
struct heim_plugin *pl;
|
||||
heim_array_t plugins;
|
||||
|
||||
if (dsohandle == NULL)
|
||||
return NULL;
|
||||
return NULL;
|
||||
|
||||
/* suppress error here because we may be looking for a different plugin type */
|
||||
cpm = (krb5_plugin_common_ftable_p)dlsym(dsohandle, name);
|
||||
cpm = (heim_plugin_common_ftable_p)dlsym(dsohandle, name);
|
||||
if (cpm == NULL)
|
||||
return NULL;
|
||||
return NULL;
|
||||
|
||||
krb5_warnx(context, "plugin %s uses deprecated loading mechanism", dsopath);
|
||||
heim_warnx(context, "plugin %s uses deprecated loading mechanism", dsopath);
|
||||
|
||||
pl = heim_alloc(sizeof(*pl), "krb5-plugin", plugin_free);
|
||||
pl = heim_alloc(sizeof(*pl), "heim-plugin", plugin_free);
|
||||
|
||||
ret = cpm->init(context, &pl->ctx);
|
||||
ret = cpm->init(pcontext, &pl->ctx);
|
||||
if (ret) {
|
||||
krb5_warn(context, ret, "plugin %s failed to initialize", dsopath);
|
||||
heim_release(pl);
|
||||
return NULL;
|
||||
heim_warn(context, ret, "plugin %s failed to initialize", dsopath);
|
||||
heim_release(pl);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pl->ftable = cpm;
|
||||
@@ -514,38 +526,38 @@ add_dso_plugin_struct(krb5_context context,
|
||||
return plugins;
|
||||
}
|
||||
|
||||
static krb5_boolean
|
||||
validate_plugin_deps(krb5_context context,
|
||||
struct krb5_plugin_data *caller,
|
||||
const char *dsopath,
|
||||
krb5_get_instance_func_t get_instance)
|
||||
static int
|
||||
validate_plugin_deps(heim_context context,
|
||||
struct heim_plugin_data *caller,
|
||||
const char *dsopath,
|
||||
heim_get_instance_func_t get_instance)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if (get_instance == NULL) {
|
||||
krb5_warnx(context, "plugin %s omitted instance callback",
|
||||
dsopath);
|
||||
return FALSE;
|
||||
heim_warnx(context, "plugin %s omitted instance callback",
|
||||
dsopath);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
for (i = 0; caller->deps[i] != NULL; i++) {
|
||||
uintptr_t heim_instance, plugin_instance;
|
||||
uintptr_t heim_instance, plugin_instance;
|
||||
|
||||
heim_instance = caller->get_instance(caller->deps[i]);
|
||||
plugin_instance = get_instance(caller->deps[i]);
|
||||
heim_instance = caller->get_instance(caller->deps[i]);
|
||||
plugin_instance = get_instance(caller->deps[i]);
|
||||
|
||||
if (heim_instance == 0 || plugin_instance == 0)
|
||||
continue;
|
||||
if (heim_instance == 0 || plugin_instance == 0)
|
||||
continue;
|
||||
|
||||
if (heim_instance != plugin_instance) {
|
||||
krb5_warnx(context, "plugin %s library %s linked against different "
|
||||
"instance of Heimdal (got %zu, us %zu)",
|
||||
dsopath, caller->deps[i],
|
||||
plugin_instance, heim_instance);
|
||||
return FALSE;
|
||||
}
|
||||
_krb5_debug(context, 10, "Validated plugin library dependency %s for %s",
|
||||
caller->deps[i], dsopath);
|
||||
if (heim_instance != plugin_instance) {
|
||||
heim_warnx(context, "plugin %s library %s linked against different "
|
||||
"instance of Heimdal (got %zu, us %zu)",
|
||||
dsopath, caller->deps[i],
|
||||
plugin_instance, heim_instance);
|
||||
return FALSE;
|
||||
}
|
||||
heim_debug(context, 10, "Validated plugin library dependency %s for %s",
|
||||
caller->deps[i], dsopath);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
@@ -553,62 +565,63 @@ validate_plugin_deps(krb5_context context,
|
||||
|
||||
/*
|
||||
* New interface from Heimdal 8 where a DSO can export a load function
|
||||
* that can return both a libkrb5 instance identifier along with an array
|
||||
* of plugins.
|
||||
* that can return both a Heimdal instance identifier along with an
|
||||
* array of plugins.
|
||||
*/
|
||||
static heim_array_t
|
||||
add_dso_plugins_load_fn(krb5_context context,
|
||||
struct krb5_plugin_data *caller,
|
||||
const char *dsopath,
|
||||
void *dsohandle)
|
||||
add_dso_plugins_load_fn(heim_context context,
|
||||
heim_pcontext pcontext,
|
||||
struct heim_plugin_data *caller,
|
||||
const char *dsopath,
|
||||
void *dsohandle)
|
||||
{
|
||||
krb5_error_code ret;
|
||||
heim_error_code ret;
|
||||
heim_array_t plugins;
|
||||
krb5_plugin_load_t load_fn;
|
||||
heim_plugin_load_t load_fn;
|
||||
char *sym;
|
||||
size_t i;
|
||||
krb5_get_instance_func_t get_instance;
|
||||
heim_get_instance_func_t get_instance;
|
||||
size_t n_ftables;
|
||||
krb5_plugin_common_ftable_cp *ftables;
|
||||
heim_plugin_common_ftable_cp *ftables;
|
||||
|
||||
if (asprintf(&sym, "%s_plugin_load", caller->name) == -1)
|
||||
return NULL;
|
||||
return NULL;
|
||||
|
||||
/* suppress error here because we may be looking for a different plugin type */
|
||||
load_fn = (krb5_plugin_load_t)dlsym(dsohandle, sym);
|
||||
load_fn = (heim_plugin_load_t)dlsym(dsohandle, sym);
|
||||
free(sym);
|
||||
if (load_fn == NULL)
|
||||
return NULL;
|
||||
return NULL;
|
||||
|
||||
ret = load_fn(context, &get_instance, &n_ftables, &ftables);
|
||||
ret = load_fn(pcontext, &get_instance, &n_ftables, &ftables);
|
||||
if (ret) {
|
||||
krb5_warn(context, ret, "plugin %s failed to load", dsopath);
|
||||
heim_warn(context, ret, "plugin %s failed to load", dsopath);
|
||||
|
||||
/* fallback to loading structure directly */
|
||||
return add_dso_plugin_struct(context, dsopath,
|
||||
dsohandle, caller->name);
|
||||
/* fallback to loading structure directly */
|
||||
return add_dso_plugin_struct(context, pcontext, dsopath,
|
||||
dsohandle, caller->name);
|
||||
}
|
||||
|
||||
if (!validate_plugin_deps(context, caller, dsopath, get_instance))
|
||||
return NULL;
|
||||
return NULL;
|
||||
|
||||
plugins = heim_array_create();
|
||||
|
||||
for (i = 0; i < n_ftables; i++) {
|
||||
krb5_plugin_common_ftable_cp cpm = ftables[i];
|
||||
struct krb5_plugin *pl;
|
||||
heim_plugin_common_ftable_cp cpm = ftables[i];
|
||||
struct heim_plugin *pl;
|
||||
|
||||
pl = heim_alloc(sizeof(*pl), "krb5-plugin", plugin_free);
|
||||
pl = heim_alloc(sizeof(*pl), "heim-plugin", plugin_free);
|
||||
|
||||
ret = cpm->init(context, &pl->ctx);
|
||||
if (ret) {
|
||||
krb5_warn(context, ret, "plugin %s[%zu] failed to initialize",
|
||||
dsopath, i);
|
||||
} else {
|
||||
pl->ftable = rk_UNCONST(cpm);
|
||||
heim_array_append_value(plugins, pl);
|
||||
}
|
||||
heim_release(pl);
|
||||
ret = cpm->init(pcontext, &pl->ctx);
|
||||
if (ret) {
|
||||
heim_warn(context, ret, "plugin %s[%zu] failed to initialize",
|
||||
dsopath, i);
|
||||
} else {
|
||||
pl->ftable = rk_UNCONST(cpm);
|
||||
heim_array_append_value(plugins, pl);
|
||||
}
|
||||
heim_release(pl);
|
||||
}
|
||||
|
||||
return plugins;
|
||||
@@ -619,56 +632,57 @@ static void
|
||||
reduce_by_version(heim_object_t value, void *ctx, int *stop)
|
||||
{
|
||||
struct iter_ctx *s = ctx;
|
||||
struct krb5_plugin *pl = value;
|
||||
struct heim_plugin *pl = value;
|
||||
|
||||
if (pl->ftable && pl->ftable->version >= s->caller->min_version)
|
||||
heim_array_append_value(s->result, pl);
|
||||
heim_array_append_value(s->result, pl);
|
||||
}
|
||||
|
||||
static void
|
||||
search_modules(heim_object_t key, heim_object_t value, void *ctx)
|
||||
{
|
||||
struct iter_ctx *s = ctx;
|
||||
struct krb5_dso *p = value;
|
||||
struct heim_dso *p = value;
|
||||
heim_array_t plugins = heim_dict_copy_value(p->plugins_by_name, s->n);
|
||||
|
||||
#ifdef HAVE_DLOPEN
|
||||
if (plugins == NULL && p->dsohandle) {
|
||||
const char *path = heim_string_get_utf8(p->path);
|
||||
const char *path = heim_string_get_utf8(p->path);
|
||||
|
||||
plugins = add_dso_plugins_load_fn(s->context,
|
||||
s->caller,
|
||||
path,
|
||||
p->dsohandle);
|
||||
if (plugins) {
|
||||
heim_dict_set_value(p->plugins_by_name, s->n, plugins);
|
||||
_krb5_debug(s->context, 5, "Loaded %zu %s %s plugin%s from %s",
|
||||
heim_array_get_length(plugins),
|
||||
s->caller->module, s->caller->name,
|
||||
heim_array_get_length(plugins) > 1 ? "s" : "",
|
||||
path);
|
||||
}
|
||||
plugins = add_dso_plugins_load_fn(s->context,
|
||||
s->pcontext,
|
||||
s->caller,
|
||||
path,
|
||||
p->dsohandle);
|
||||
if (plugins) {
|
||||
heim_dict_set_value(p->plugins_by_name, s->n, plugins);
|
||||
heim_debug(s->context, 5, "Loaded %zu %s %s plugin%s from %s",
|
||||
heim_array_get_length(plugins),
|
||||
s->caller->module, s->caller->name,
|
||||
heim_array_get_length(plugins) > 1 ? "s" : "",
|
||||
path);
|
||||
}
|
||||
}
|
||||
#endif /* HAVE_DLOPEN */
|
||||
|
||||
if (plugins) {
|
||||
heim_array_iterate_f(plugins, s, reduce_by_version);
|
||||
heim_release(plugins);
|
||||
heim_array_iterate_f(plugins, s, reduce_by_version);
|
||||
heim_release(plugins);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
eval_results(heim_object_t value, void *ctx, int *stop)
|
||||
{
|
||||
struct krb5_plugin *pl = value;
|
||||
struct heim_plugin *pl = value;
|
||||
struct iter_ctx *s = ctx;
|
||||
|
||||
if (s->ret != KRB5_PLUGIN_NO_HANDLE)
|
||||
return;
|
||||
if (s->ret != s->plugin_no_handle_retval)
|
||||
return;
|
||||
|
||||
s->ret = s->func(s->context, pl->ftable, pl->ctx, s->userctx);
|
||||
if (s->ret != KRB5_PLUGIN_NO_HANDLE
|
||||
&& !(s->flags & KRB5_PLUGIN_INVOKE_ALL))
|
||||
s->ret = s->func(s->pcontext, pl->ftable, pl->ctx, s->userctx);
|
||||
if (s->ret != s->plugin_no_handle_retval
|
||||
&& !(s->flags & HEIM_PLUGIN_INVOKE_ALL))
|
||||
*stop = 1;
|
||||
}
|
||||
|
||||
@@ -684,42 +698,47 @@ eval_results(heim_object_t value, void *ctx, int *stop)
|
||||
* outputs, if any, in @userctx.
|
||||
*
|
||||
* All loaded and registered plugins are invoked via @func until @func
|
||||
* returns something other than KRB5_PLUGIN_NO_HANDLE. Plugins that
|
||||
* have nothing to do for the given arguments should return
|
||||
* KRB5_PLUGIN_NO_HANDLE.
|
||||
* returns something other than @nohandle. Plugins that have nothing to
|
||||
* do for the given arguments should return the same value as @nohandle.
|
||||
*
|
||||
* Inputs:
|
||||
*
|
||||
* @context A krb5_context
|
||||
* @context A heim_context
|
||||
* @pcontext A context for the plugin, such as a krb5_context
|
||||
* @module Name of module (typically "krb5")
|
||||
* @name Name of pluggable interface (e.g., "kuserok")
|
||||
* @min_version Lowest acceptable plugin minor version number
|
||||
* @flags Flags (none defined at this time)
|
||||
* @nohandle Flags (none defined at this time)
|
||||
* @userctx Callback data for the callback function @func
|
||||
* @func A callback function, invoked once per-plugin
|
||||
*
|
||||
* Outputs: None, other than the return value and such outputs as are
|
||||
* gathered by @func.
|
||||
*/
|
||||
KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
|
||||
_krb5_plugin_run_f(krb5_context context,
|
||||
struct krb5_plugin_data *caller,
|
||||
int flags,
|
||||
void *userctx,
|
||||
krb5_error_code (KRB5_LIB_CALL *func)(krb5_context, const void *, void *, void *))
|
||||
heim_error_code
|
||||
heim_plugin_run_f(heim_context context,
|
||||
heim_pcontext pcontext,
|
||||
struct heim_plugin_data *caller,
|
||||
int flags,
|
||||
int32_t nohandle,
|
||||
void *userctx,
|
||||
int32_t (HEIM_LIB_CALL *func)(void *, const void *, void *, void *))
|
||||
{
|
||||
heim_string_t m = heim_string_create(caller->module);
|
||||
heim_dict_t modules, dict = NULL;
|
||||
struct iter_ctx s;
|
||||
|
||||
s.context = context;
|
||||
s.pcontext = pcontext;
|
||||
s.caller = caller;
|
||||
s.n = heim_string_create(caller->name);
|
||||
s.flags = flags;
|
||||
s.result = heim_array_create();
|
||||
s.func = func;
|
||||
s.userctx = userctx;
|
||||
s.ret = KRB5_PLUGIN_NO_HANDLE;
|
||||
s.plugin_no_handle_retval = nohandle;
|
||||
s.ret = nohandle;
|
||||
|
||||
HEIMDAL_MUTEX_lock(&modules_mutex);
|
||||
|
||||
@@ -729,7 +748,7 @@ _krb5_plugin_run_f(krb5_context context,
|
||||
|
||||
/* Add loaded plugins to s.result array */
|
||||
if (dict)
|
||||
heim_dict_iterate_f(dict, &s, search_modules);
|
||||
heim_dict_iterate_f(dict, &s, search_modules);
|
||||
|
||||
/* We don't need to hold modules_mutex during plugin invocation */
|
||||
HEIMDAL_MUTEX_unlock(&modules_mutex);
|
||||
@@ -745,27 +764,3 @@ _krb5_plugin_run_f(krb5_context context,
|
||||
|
||||
return s.ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a cookie identifying this instance of a library.
|
||||
*
|
||||
* Inputs:
|
||||
*
|
||||
* @context A krb5_context
|
||||
* @module Our library name or a library we depend on
|
||||
*
|
||||
* Outputs: The instance cookie
|
||||
*
|
||||
* @ingroup krb5_support
|
||||
*/
|
||||
|
||||
KRB5_LIB_FUNCTION uintptr_t KRB5_LIB_CALL
|
||||
krb5_get_instance(const char *libname)
|
||||
{
|
||||
static const char *instance = "libkrb5";
|
||||
|
||||
if (strcmp(libname, "krb5") == 0)
|
||||
return (uintptr_t)instance;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@@ -6,11 +6,16 @@ HEIMDAL_BASE_1.0 {
|
||||
_bsearch_file_info;
|
||||
_bsearch_file_open;
|
||||
_bsearch_text;
|
||||
__heim_string_constant;
|
||||
DllMain;
|
||||
et_heim_error_table;
|
||||
heim_abort;
|
||||
heim_abortv;
|
||||
heim_add_debug_dest;
|
||||
heim_addlog_dest;
|
||||
heim_addlog_func;
|
||||
heim_add_warn_dest;
|
||||
heim_alloc;
|
||||
_heim_alloc_object;
|
||||
heim_array_append_value;
|
||||
heim_array_copy_value;
|
||||
heim_array_create;
|
||||
@@ -19,9 +24,9 @@ HEIMDAL_BASE_1.0 {
|
||||
heim_array_get_length;
|
||||
heim_array_get_type_id;
|
||||
heim_array_get_value;
|
||||
heim_array_insert_value;
|
||||
heim_array_iterate_f;
|
||||
heim_array_iterate_reverse_f;
|
||||
heim_array_insert_value;
|
||||
heim_array_set_value;
|
||||
heim_auto_release;
|
||||
heim_auto_release_create;
|
||||
@@ -29,25 +34,72 @@ HEIMDAL_BASE_1.0 {
|
||||
heim_base_once_f;
|
||||
heim_bool_create;
|
||||
heim_bool_val;
|
||||
heim_clear_error_message;
|
||||
heim_closelog;
|
||||
heim_cmp;
|
||||
heim_config_copy;
|
||||
heim_config_file_free;
|
||||
heim_config_free_strings;
|
||||
heim_config_get;
|
||||
heim_config_get_bool;
|
||||
heim_config_get_bool_default;
|
||||
heim_config_get_entry;
|
||||
heim_config_get_int;
|
||||
heim_config_get_int_default;
|
||||
heim_config_get_list;
|
||||
heim_config_get_next;
|
||||
heim_config_get_string;
|
||||
heim_config_get_string_default;
|
||||
heim_config_get_strings;
|
||||
heim_config_get_time;
|
||||
heim_config_get_time_default;
|
||||
heim_config_parse_dir_multi;
|
||||
heim_config_parse_file;
|
||||
heim_config_parse_file_multi;
|
||||
heim_config_parse_string_multi;
|
||||
heim_config_vget;
|
||||
heim_config_vget_bool;
|
||||
heim_config_vget_bool_default;
|
||||
heim_config_vget_int;
|
||||
heim_config_vget_int_default;
|
||||
heim_config_vget_list;
|
||||
heim_config_vget_next;
|
||||
heim_config_vget_string;
|
||||
heim_config_vget_string_default;
|
||||
heim_config_vget_strings;
|
||||
heim_config_vget_time;
|
||||
heim_config_vget_time_default;
|
||||
heim_context_free;
|
||||
heim_context_get_homedir_access;
|
||||
heim_context_get_log_utc;
|
||||
heim_context_get_time_fmt;
|
||||
heim_context_init;
|
||||
heim_context_set_homedir_access;
|
||||
heim_context_set_log_utc;
|
||||
heim_context_set_msg_cb;
|
||||
heim_context_set_time_fmt;
|
||||
_heim_create_type;
|
||||
heim_data_create;
|
||||
heim_data_ref_create;
|
||||
heim_data_get_data;
|
||||
heim_data_get_length;
|
||||
heim_data_get_ptr;
|
||||
heim_data_get_type_id;
|
||||
heim_data_ref_create;
|
||||
heim_data_ref_get_type_id;
|
||||
heim_db_begin;
|
||||
heim_db_clone;
|
||||
heim_db_commit;
|
||||
heim_db_copy_value;
|
||||
heim_db_create;
|
||||
heim_db_delete_key;
|
||||
heim_db_get_type_id;
|
||||
_heim_db_get_value;
|
||||
heim_db_iterate_f;
|
||||
heim_db_create;
|
||||
heim_db_register;
|
||||
heim_db_rollback;
|
||||
heim_db_set_value;
|
||||
heim_debug;
|
||||
heim_description;
|
||||
heim_dict_copy_value;
|
||||
heim_dict_create;
|
||||
heim_dict_delete_key;
|
||||
@@ -55,40 +107,81 @@ HEIMDAL_BASE_1.0 {
|
||||
heim_dict_get_value;
|
||||
heim_dict_iterate_f;
|
||||
heim_dict_set_value;
|
||||
heim_enomem;
|
||||
heim_error_append;
|
||||
heim_error_copy_string;
|
||||
heim_error_create_opt;
|
||||
heim_error_create;
|
||||
heim_error_createv;
|
||||
heim_error_create_enomem;
|
||||
heim_error_create_opt;
|
||||
heim_error_createv;
|
||||
heim_error_get_code;
|
||||
heim_expand_path_tokens;
|
||||
heim_expand_path_tokensv;
|
||||
heim_free_error_message;
|
||||
heim_get_debug_dest;
|
||||
heim_get_error_message;
|
||||
heim_get_hash;
|
||||
_heim_get_isa;
|
||||
_heim_get_isaextra;
|
||||
heim_get_tid;
|
||||
heim_get_warn_dest;
|
||||
heim_have_debug;
|
||||
heim_initlog;
|
||||
heim_json_copy_serialize;
|
||||
heim_json_create;
|
||||
heim_json_create_with_bytes;
|
||||
heim_json_copy_serialize;
|
||||
heim_load_plugins;
|
||||
heim_log;
|
||||
heim_log_msg;
|
||||
_heim_make_permanent;
|
||||
heim_null_create;
|
||||
heim_number_create;
|
||||
heim_number_get_int;
|
||||
heim_number_get_type_id;
|
||||
heim_openlog;
|
||||
heim_path_copy;
|
||||
heim_path_create;
|
||||
heim_path_delete;
|
||||
heim_path_get;
|
||||
heim_path_copy;
|
||||
heim_path_vcopy;
|
||||
heim_path_vcreate;
|
||||
heim_path_vdelete;
|
||||
heim_path_vget;
|
||||
heim_path_vcopy;
|
||||
heim_plugin_register;
|
||||
heim_plugin_run_f;
|
||||
heim_prepend_error_message;
|
||||
heim_release;
|
||||
heim_retain;
|
||||
heim_set_debug_dest;
|
||||
heim_set_error_message;
|
||||
heim_set_warn_dest;
|
||||
heim_show;
|
||||
heim_sorted_text_file_dbtype;
|
||||
__heim_string_constant;
|
||||
heim_string_create;
|
||||
heim_string_create_with_bytes;
|
||||
heim_string_create_with_format;
|
||||
heim_string_get_type_id;
|
||||
heim_string_get_utf8;
|
||||
heim_string_ref_create;
|
||||
_heim_type_get_tid;
|
||||
heim_unload_plugins;
|
||||
heim_vdebug;
|
||||
heim_vlog;
|
||||
heim_vlog_msg;
|
||||
heim_vprepend_error_message;
|
||||
heim_vset_error_message;
|
||||
heim_vwarn;
|
||||
heim_vwarnx;
|
||||
heim_w32_delete_key;
|
||||
heim_w32_getspecific;
|
||||
heim_w32_key_create;
|
||||
heim_w32_service_thread_detach;
|
||||
heim_w32_setspecific;
|
||||
heim_warn;
|
||||
heim_warnx;
|
||||
initialize_heim_error_table;
|
||||
initialize_heim_error_table_r;
|
||||
local:
|
||||
*;
|
||||
};
|
||||
|
244
lib/base/warn.c
244
lib/base/warn.c
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1997 - 2001 Kungliga Tekniska Högskolan
|
||||
* Copyright (c) 1997 - 2020 Kungliga Tekniska Högskolan
|
||||
* (Royal Institute of Technology, Stockholm, Sweden).
|
||||
* All rights reserved.
|
||||
*
|
||||
@@ -36,22 +36,22 @@
|
||||
# pragma warning(disable: 4716)
|
||||
#endif
|
||||
|
||||
#include "krb5_locl.h"
|
||||
#include "baselocl.h"
|
||||
#include <err.h>
|
||||
|
||||
static krb5_error_code _warnerr(krb5_context context, int do_errtext,
|
||||
krb5_error_code code, int level, const char *fmt, va_list ap)
|
||||
static heim_error_code _warnerr(heim_context context, int do_errtext,
|
||||
heim_error_code code, int level, const char *fmt, va_list ap)
|
||||
__attribute__ ((__format__ (__printf__, 5, 0)));
|
||||
|
||||
static krb5_error_code
|
||||
_warnerr(krb5_context context, int do_errtext,
|
||||
krb5_error_code code, int level, const char *fmt, va_list ap)
|
||||
static heim_error_code
|
||||
_warnerr(heim_context context, int do_errtext,
|
||||
heim_error_code code, int level, const char *fmt, va_list ap)
|
||||
{
|
||||
char xfmt[7] = "";
|
||||
const char *args[2], **arg;
|
||||
char *msg = NULL;
|
||||
const char *err_str = NULL;
|
||||
krb5_error_code ret;
|
||||
heim_error_code ret;
|
||||
|
||||
args[0] = args[1] = NULL;
|
||||
arg = args;
|
||||
@@ -64,10 +64,10 @@ _warnerr(krb5_context context, int do_errtext,
|
||||
return ENOMEM;
|
||||
*arg++ = msg;
|
||||
}
|
||||
if(context && do_errtext){
|
||||
if (context && do_errtext) {
|
||||
strlcat(xfmt, "%s", sizeof(xfmt));
|
||||
|
||||
err_str = krb5_get_error_message(context, code);
|
||||
err_str = heim_get_error_message(context, code);
|
||||
if (err_str != NULL) {
|
||||
*arg = err_str;
|
||||
} else {
|
||||
@@ -75,28 +75,23 @@ _warnerr(krb5_context context, int do_errtext,
|
||||
}
|
||||
}
|
||||
|
||||
if(context && context->warn_dest)
|
||||
krb5_log(context, context->warn_dest, level, xfmt, args[0], args[1]);
|
||||
if (context && heim_get_warn_dest(context))
|
||||
heim_log(context, heim_get_warn_dest(context), level, xfmt, args[0],
|
||||
args[1]);
|
||||
else
|
||||
warnx(xfmt, args[0], args[1]);
|
||||
free(msg);
|
||||
krb5_free_error_message(context, err_str);
|
||||
heim_free_error_message(context, err_str);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define FUNC(ETEXT, CODE, LEVEL) \
|
||||
krb5_error_code ret; \
|
||||
heim_error_code ret; \
|
||||
va_list ap; \
|
||||
va_start(ap, fmt); \
|
||||
ret = _warnerr(context, ETEXT, CODE, LEVEL, fmt, ap); \
|
||||
va_end(ap);
|
||||
|
||||
#define FUNC_NORET(ETEXT, CODE, LEVEL) \
|
||||
va_list ap; \
|
||||
va_start(ap, fmt); \
|
||||
(void) _warnerr(context, ETEXT, CODE, LEVEL, fmt, ap); \
|
||||
va_end(ap);
|
||||
|
||||
#undef __attribute__
|
||||
#define __attribute__(X)
|
||||
|
||||
@@ -109,11 +104,11 @@ _warnerr(krb5_context context, int do_errtext,
|
||||
* @param fmt message to print
|
||||
* @param ap arguments
|
||||
*
|
||||
* @ingroup krb5_error
|
||||
* @ingroup heim_error
|
||||
*/
|
||||
|
||||
KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
|
||||
krb5_vwarn(krb5_context context, krb5_error_code code,
|
||||
heim_error_code
|
||||
heim_vwarn(heim_context context, heim_error_code code,
|
||||
const char *fmt, va_list ap)
|
||||
__attribute__ ((__format__ (__printf__, 3, 0)))
|
||||
{
|
||||
@@ -128,11 +123,11 @@ krb5_vwarn(krb5_context context, krb5_error_code code,
|
||||
* @param code error code of the last error
|
||||
* @param fmt message to print
|
||||
*
|
||||
* @ingroup krb5_error
|
||||
* @ingroup heim_error
|
||||
*/
|
||||
|
||||
KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
|
||||
krb5_warn(krb5_context context, krb5_error_code code, const char *fmt, ...)
|
||||
heim_error_code
|
||||
heim_warn(heim_context context, heim_error_code code, const char *fmt, ...)
|
||||
__attribute__ ((__format__ (__printf__, 3, 4)))
|
||||
{
|
||||
FUNC(1, code, 1);
|
||||
@@ -146,11 +141,11 @@ krb5_warn(krb5_context context, krb5_error_code code, const char *fmt, ...)
|
||||
* @param fmt message to print
|
||||
* @param ap arguments
|
||||
*
|
||||
* @ingroup krb5_error
|
||||
* @ingroup heim_error
|
||||
*/
|
||||
|
||||
KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
|
||||
krb5_vwarnx(krb5_context context, const char *fmt, va_list ap)
|
||||
heim_error_code
|
||||
heim_vwarnx(heim_context context, const char *fmt, va_list ap)
|
||||
__attribute__ ((__format__ (__printf__, 2, 0)))
|
||||
{
|
||||
return _warnerr(context, 0, 0, 1, fmt, ap);
|
||||
@@ -162,198 +157,13 @@ krb5_vwarnx(krb5_context context, const char *fmt, va_list ap)
|
||||
* @param context A Kerberos 5 context.
|
||||
* @param fmt message to print
|
||||
*
|
||||
* @ingroup krb5_error
|
||||
* @ingroup heim_error
|
||||
*/
|
||||
|
||||
KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
|
||||
krb5_warnx(krb5_context context, const char *fmt, ...)
|
||||
heim_error_code
|
||||
heim_warnx(heim_context context, const char *fmt, ...)
|
||||
__attribute__ ((__format__ (__printf__, 2, 3)))
|
||||
{
|
||||
FUNC(0, 0, 1);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a warning to the log, default stderr, include bthe error from
|
||||
* the last failure and then exit.
|
||||
*
|
||||
* @param context A Kerberos 5 context
|
||||
* @param eval the exit code to exit with
|
||||
* @param code error code of the last error
|
||||
* @param fmt message to print
|
||||
* @param ap arguments
|
||||
*
|
||||
* @ingroup krb5_error
|
||||
*/
|
||||
|
||||
KRB5_LIB_NORETURN_FUNCTION krb5_error_code KRB5_LIB_CALL
|
||||
krb5_verr(krb5_context context, int eval, krb5_error_code code,
|
||||
const char *fmt, va_list ap)
|
||||
__attribute__ ((__noreturn__, __format__ (__printf__, 4, 0)))
|
||||
{
|
||||
_warnerr(context, 1, code, 0, fmt, ap);
|
||||
exit(eval);
|
||||
UNREACHABLE(return 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a warning to the log, default stderr, include bthe error from
|
||||
* the last failure and then exit.
|
||||
*
|
||||
* @param context A Kerberos 5 context
|
||||
* @param eval the exit code to exit with
|
||||
* @param code error code of the last error
|
||||
* @param fmt message to print
|
||||
*
|
||||
* @ingroup krb5_error
|
||||
*/
|
||||
|
||||
KRB5_LIB_NORETURN_FUNCTION krb5_error_code KRB5_LIB_CALL
|
||||
krb5_err(krb5_context context, int eval, krb5_error_code code,
|
||||
const char *fmt, ...)
|
||||
__attribute__ ((__noreturn__, __format__ (__printf__, 4, 5)))
|
||||
{
|
||||
FUNC_NORET(1, code, 0);
|
||||
exit(eval);
|
||||
UNREACHABLE(return 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a warning to the log, default stderr, and then exit.
|
||||
*
|
||||
* @param context A Kerberos 5 context
|
||||
* @param eval the exit code to exit with
|
||||
* @param fmt message to print
|
||||
* @param ap arguments
|
||||
*
|
||||
* @ingroup krb5_error
|
||||
*/
|
||||
|
||||
KRB5_LIB_NORETURN_FUNCTION krb5_error_code KRB5_LIB_CALL
|
||||
krb5_verrx(krb5_context context, int eval, const char *fmt, va_list ap)
|
||||
__attribute__ ((__noreturn__, __format__ (__printf__, 3, 0)))
|
||||
{
|
||||
_warnerr(context, 0, 0, 0, fmt, ap);
|
||||
exit(eval);
|
||||
UNREACHABLE(return 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a warning to the log, default stderr, and then exit.
|
||||
*
|
||||
* @param context A Kerberos 5 context
|
||||
* @param eval the exit code to exit with
|
||||
* @param fmt message to print
|
||||
*
|
||||
* @ingroup krb5_error
|
||||
*/
|
||||
|
||||
KRB5_LIB_NORETURN_FUNCTION krb5_error_code KRB5_LIB_CALL
|
||||
krb5_errx(krb5_context context, int eval, const char *fmt, ...)
|
||||
__attribute__ ((__noreturn__, __format__ (__printf__, 3, 4)))
|
||||
{
|
||||
FUNC_NORET(0, 0, 0);
|
||||
exit(eval);
|
||||
UNREACHABLE(return 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a warning to the log, default stderr, include bthe error from
|
||||
* the last failure and then abort.
|
||||
*
|
||||
* @param context A Kerberos 5 context
|
||||
* @param code error code of the last error
|
||||
* @param fmt message to print
|
||||
* @param ap arguments
|
||||
*
|
||||
* @ingroup krb5_error
|
||||
*/
|
||||
|
||||
KRB5_LIB_NORETURN_FUNCTION krb5_error_code KRB5_LIB_CALL
|
||||
krb5_vabort(krb5_context context, krb5_error_code code,
|
||||
const char *fmt, va_list ap)
|
||||
__attribute__ ((__noreturn__, __format__ (__printf__, 3, 0)))
|
||||
{
|
||||
_warnerr(context, 1, code, 0, fmt, ap);
|
||||
abort();
|
||||
UNREACHABLE(return 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a warning to the log, default stderr, include the error from
|
||||
* the last failure and then abort.
|
||||
*
|
||||
* @param context A Kerberos 5 context
|
||||
* @param code error code of the last error
|
||||
* @param fmt message to print
|
||||
* @param ... arguments for format string
|
||||
*
|
||||
* @ingroup krb5_error
|
||||
*/
|
||||
|
||||
KRB5_LIB_NORETURN_FUNCTION krb5_error_code KRB5_LIB_CALL
|
||||
krb5_abort(krb5_context context, krb5_error_code code, const char *fmt, ...)
|
||||
__attribute__ ((__noreturn__, __format__ (__printf__, 3, 4)))
|
||||
{
|
||||
FUNC_NORET(1, code, 0);
|
||||
abort();
|
||||
UNREACHABLE(return 0);
|
||||
}
|
||||
|
||||
KRB5_LIB_NORETURN_FUNCTION krb5_error_code KRB5_LIB_CALL
|
||||
krb5_vabortx(krb5_context context, const char *fmt, va_list ap)
|
||||
__attribute__ ((__noreturn__, __format__ (__printf__, 2, 0)))
|
||||
{
|
||||
_warnerr(context, 0, 0, 0, fmt, ap);
|
||||
abort();
|
||||
UNREACHABLE(return 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a warning to the log, default stderr, and then abort.
|
||||
*
|
||||
* @param context A Kerberos 5 context
|
||||
* @param fmt printf format string of message to print
|
||||
* @param ... arguments for format string
|
||||
*
|
||||
* @ingroup krb5_error
|
||||
*/
|
||||
|
||||
KRB5_LIB_NORETURN_FUNCTION krb5_error_code KRB5_LIB_CALL
|
||||
krb5_abortx(krb5_context context, const char *fmt, ...)
|
||||
__attribute__ ((__noreturn__, __format__ (__printf__, 2, 3)))
|
||||
{
|
||||
FUNC_NORET(0, 0, 0);
|
||||
abort();
|
||||
UNREACHABLE(return 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default logging facility.
|
||||
*
|
||||
* @param context A Kerberos 5 context
|
||||
* @param fac Facility to use for logging.
|
||||
*
|
||||
* @ingroup krb5_error
|
||||
*/
|
||||
|
||||
KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
|
||||
krb5_set_warn_dest(krb5_context context, krb5_log_facility *fac)
|
||||
{
|
||||
context->warn_dest = fac;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default logging facility.
|
||||
*
|
||||
* @param context A Kerberos 5 context
|
||||
*
|
||||
* @ingroup krb5_error
|
||||
*/
|
||||
|
||||
KRB5_LIB_FUNCTION krb5_log_facility * KRB5_LIB_CALL
|
||||
krb5_get_warn_dest(krb5_context context)
|
||||
{
|
||||
return context->warn_dest;
|
||||
}
|
||||
|
Reference in New Issue
Block a user