summaryrefslogtreecommitdiffstats
path: root/src/util/support/plugins.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/support/plugins.c')
-rw-r--r--src/util/support/plugins.c164
1 files changed, 82 insertions, 82 deletions
diff --git a/src/util/support/plugins.c b/src/util/support/plugins.c
index 26ec3912f..8c7fb5ffe 100644
--- a/src/util/support/plugins.c
+++ b/src/util/support/plugins.c
@@ -8,7 +8,7 @@
* require a specific license from the United States Government.
* It is the responsibility of any person or organization contemplating
* export to obtain such a license before exporting.
- *
+ *
* WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
* distribute this software and its documentation for any purpose and
* without fee is hereby granted, provided that the above copyright
@@ -22,7 +22,7 @@
* M.I.T. makes no representations about the suitability of
* this software for any purpose. It is provided "as is" without express
* or implied warranty.
- *
+ *
*
* Plugin module support, and shims around dlopen/whatever.
*/
@@ -192,10 +192,10 @@ krb5int_open_plugin (const char *filepath, struct plugin_file_handle **h, struct
#endif /* USE_CFBUNDLE */
)) {
void *handle = NULL;
-
+
#if USE_CFBUNDLE
char executablepath[MAXPATHLEN];
-
+
if ((statbuf.st_mode & S_IFMT) == S_IFDIR) {
int lock_err = 0;
CFStringRef pluginString = NULL;
@@ -208,51 +208,51 @@ krb5int_open_plugin (const char *filepath, struct plugin_file_handle **h, struct
* because this code is Mac-specific */
lock_err = pthread_mutex_lock(&krb5int_bundle_mutex);
if (lock_err) { err = lock_err; }
-
+
if (!err) {
- pluginString = CFStringCreateWithCString (kCFAllocatorDefault,
- filepath,
+ pluginString = CFStringCreateWithCString (kCFAllocatorDefault,
+ filepath,
kCFStringEncodingASCII);
if (pluginString == NULL) { err = ENOMEM; }
}
-
+
if (!err) {
- pluginURL = CFURLCreateWithFileSystemPath (kCFAllocatorDefault,
- pluginString,
- kCFURLPOSIXPathStyle,
+ pluginURL = CFURLCreateWithFileSystemPath (kCFAllocatorDefault,
+ pluginString,
+ kCFURLPOSIXPathStyle,
true);
if (pluginURL == NULL) { err = ENOMEM; }
}
-
+
if (!err) {
pluginBundle = CFBundleCreate (kCFAllocatorDefault, pluginURL);
if (pluginBundle == NULL) { err = ENOENT; } /* XXX need better error */
}
-
+
if (!err) {
executableURL = CFBundleCopyExecutableURL (pluginBundle);
if (executableURL == NULL) { err = ENOMEM; }
}
-
+
if (!err) {
if (!CFURLGetFileSystemRepresentation (executableURL,
true, /* absolute */
- (UInt8 *)executablepath,
+ (UInt8 *)executablepath,
sizeof (executablepath))) {
err = ENOMEM;
}
}
-
+
if (!err) {
/* override the path the caller passed in */
filepath = executablepath;
}
-
+
if (executableURL != NULL) { CFRelease (executableURL); }
if (pluginBundle != NULL) { CFRelease (pluginBundle); }
if (pluginURL != NULL) { CFRelease (pluginURL); }
if (pluginString != NULL) { CFRelease (pluginString); }
-
+
/* unlock after CFRelease calls since they modify refcounts */
if (!lock_err) { pthread_mutex_unlock (&krb5int_bundle_mutex); }
}
@@ -282,7 +282,7 @@ krb5int_open_plugin (const char *filepath, struct plugin_file_handle **h, struct
if (handle != NULL) { dlclose (handle); }
}
#endif /* USE_DLOPEN */
-
+
#ifdef _WIN32
if (!err && (statbuf.st_mode & S_IFMT) == S_IFREG) {
HMODULE handle = NULL;
@@ -300,33 +300,33 @@ krb5int_open_plugin (const char *filepath, struct plugin_file_handle **h, struct
handle = NULL;
}
- if (handle != NULL)
- FreeLibrary(handle);
+ if (handle != NULL)
+ FreeLibrary(handle);
}
#endif
if (!err && !got_plugin) {
err = ENOENT; /* no plugin or no way to load plugins */
}
-
+
if (!err) {
*h = htmp;
htmp = NULL; /* h takes ownership */
}
-
+
if (htmp != NULL) { free (htmp); }
-
+
return err;
}
static long
-krb5int_get_plugin_sym (struct plugin_file_handle *h,
+krb5int_get_plugin_sym (struct plugin_file_handle *h,
const char *csymname, int isfunc, void **ptr,
struct errinfo *ep)
{
long err = 0;
void *sym = NULL;
-
+
#if USE_DLOPEN
if (!err && !sym && (h->dlhandle != NULL)) {
/* XXX Do we need to add a leading "_" to the symbol name on any
@@ -340,7 +340,7 @@ krb5int_get_plugin_sym (struct plugin_file_handle *h,
}
}
#endif
-
+
#ifdef _WIN32
LPVOID lpMsgBuf;
DWORD dw;
@@ -354,7 +354,7 @@ krb5int_get_plugin_sym (struct plugin_file_handle *h,
krb5int_set_error(ep, err, "%s", e);
dw = GetLastError();
- if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
+ if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
dw,
@@ -372,11 +372,11 @@ krb5int_get_plugin_sym (struct plugin_file_handle *h,
if (!err && (sym == NULL)) {
err = ENOENT; /* unimplemented */
}
-
+
if (!err) {
*ptr = sym;
}
-
+
return err;
}
@@ -391,7 +391,7 @@ long KRB5_CALLCONV
krb5int_get_plugin_func (struct plugin_file_handle *h, const char *csymname,
void (**ptr)(), struct errinfo *ep)
{
- void *dptr = NULL;
+ void *dptr = NULL;
long err = krb5int_get_plugin_sym (h, csymname, 1, &dptr, ep);
if (!err) {
/* Cast function pointers to avoid code duplication */
@@ -453,15 +453,15 @@ krb5int_plugin_file_handle_array_init (struct plugin_file_handle ***harray)
}
static long
-krb5int_plugin_file_handle_array_add (struct plugin_file_handle ***harray, size_t *count,
+krb5int_plugin_file_handle_array_add (struct plugin_file_handle ***harray, size_t *count,
struct plugin_file_handle *p)
{
long err = 0;
struct plugin_file_handle **newharray = NULL;
size_t newcount = *count + 1;
-
+
newharray = realloc (*harray, ((newcount + 1) * sizeof (**harray))); /* +1 for NULL */
- if (newharray == NULL) {
+ if (newharray == NULL) {
err = ENOMEM;
} else {
newharray[newcount - 1] = p;
@@ -470,7 +470,7 @@ krb5int_plugin_file_handle_array_add (struct plugin_file_handle ***harray, size_
*harray = newharray;
}
- return err;
+ return err;
}
static void
@@ -494,20 +494,20 @@ krb5int_plugin_file_handle_array_free (struct plugin_file_handle **harray)
#endif
-static void
+static void
krb5int_free_plugin_filenames (char **filenames)
{
- if (filenames != NULL) {
+ if (filenames != NULL) {
int i;
for (i = 0; filenames[i] != NULL; i++) {
free (filenames[i]);
}
- free (filenames);
- }
+ free (filenames);
+ }
}
-static long
+static long
krb5int_get_plugin_filenames (const char * const *filebases, char ***filenames)
{
long err = 0;
@@ -519,7 +519,7 @@ krb5int_get_plugin_filenames (const char * const *filebases, char ***filenames)
if (!filebases) { err = EINVAL; }
if (!filenames) { err = EINVAL; }
-
+
if (!err) {
for (i = 0; filebases[i]; i++) { bases_count++; }
for (i = 0; fileexts[i]; i++) { exts_count++; }
@@ -531,7 +531,7 @@ krb5int_get_plugin_filenames (const char * const *filebases, char ***filenames)
size_t j;
for (i = 0; !err && filebases[i]; i++) {
for (j = 0; !err && fileexts[j]; j++) {
- if (asprintf(&tempnames[(i*exts_count)+j], "%s%s",
+ if (asprintf(&tempnames[(i*exts_count)+j], "%s%s",
filebases[i], fileexts[j]) < 0) {
tempnames[(i*exts_count)+j] = NULL;
err = ENOMEM;
@@ -540,20 +540,20 @@ krb5int_get_plugin_filenames (const char * const *filebases, char ***filenames)
}
tempnames[bases_count * exts_count] = NULL; /* NUL-terminate */
}
-
+
if (!err) {
*filenames = tempnames;
tempnames = NULL;
}
-
+
if (tempnames) { krb5int_free_plugin_filenames (tempnames); }
-
+
return err;
}
/* Takes a NULL-terminated list of directories. If filebases is NULL, filebases is ignored
- * all plugins in the directories are loaded. If filebases is a NULL-terminated array of names,
+ * all plugins in the directories are loaded. If filebases is a NULL-terminated array of names,
* only plugins in the directories with those name (plus any platform extension) are loaded. */
long KRB5_CALLCONV
@@ -571,52 +571,52 @@ krb5int_open_plugin_dirs (const char * const *dirnames,
if (!err) {
err = krb5int_plugin_file_handle_array_init (&h);
}
-
+
if (!err && (filebases != NULL)) {
err = krb5int_get_plugin_filenames (filebases, &filenames);
}
-
+
for (i = 0; !err && dirnames[i] != NULL; i++) {
if (filenames != NULL) {
/* load plugins with names from filenames from each directory */
int j;
-
+
for (j = 0; !err && filenames[j] != NULL; j++) {
struct plugin_file_handle *handle = NULL;
char *filepath = NULL;
-
+
if (!err) {
if (asprintf(&filepath, "%s/%s", dirnames[i], filenames[j]) < 0) {
filepath = NULL;
err = ENOMEM;
}
}
-
+
if (krb5int_open_plugin (filepath, &handle, ep) == 0) {
err = krb5int_plugin_file_handle_array_add (&h, &count, handle);
if (!err) { handle = NULL; } /* h takes ownership */
}
-
+
if (filepath != NULL) { free (filepath); }
if (handle != NULL) { krb5int_close_plugin (handle); }
}
} else {
/* load all plugins in each directory */
DIR *dir = opendir (dirnames[i]);
-
+
while (dir != NULL && !err) {
struct dirent *d = NULL;
char *filepath = NULL;
struct plugin_file_handle *handle = NULL;
-
+
d = readdir (dir);
if (d == NULL) { break; }
-
- if ((strcmp (d->d_name, ".") == 0) ||
+
+ if ((strcmp (d->d_name, ".") == 0) ||
(strcmp (d->d_name, "..") == 0)) {
continue;
}
-
+
if (!err) {
int len = NAMELEN (d);
if (asprintf(&filepath, "%s/%*s", dirnames[i], len, d->d_name) < 0) {
@@ -624,34 +624,34 @@ krb5int_open_plugin_dirs (const char * const *dirnames,
err = ENOMEM;
}
}
-
- if (!err) {
+
+ if (!err) {
if (krb5int_open_plugin (filepath, &handle, ep) == 0) {
err = krb5int_plugin_file_handle_array_add (&h, &count, handle);
if (!err) { handle = NULL; } /* h takes ownership */
}
}
-
+
if (filepath != NULL) { free (filepath); }
if (handle != NULL) { krb5int_close_plugin (handle); }
}
-
+
if (dir != NULL) { closedir (dir); }
}
}
-
+
if (err == ENOENT) {
err = 0; /* ran out of plugins -- do nothing */
}
-
+
if (!err) {
dirhandle->files = h;
h = NULL; /* dirhandle->files takes ownership */
}
-
+
if (filenames != NULL) { krb5int_free_plugin_filenames (filenames); }
if (h != NULL) { krb5int_plugin_file_handle_array_free (h); }
-
+
return err;
}
@@ -687,14 +687,14 @@ krb5int_get_plugin_dir_data (struct plugin_dir_handle *dirhandle,
/* XXX Do we need to add a leading "_" to the symbol name on any
modern platforms? */
-
+
Tprintf("get_plugin_data_sym(%s)\n", symname);
if (!err) {
p = calloc (1, sizeof (*p)); /* calloc initializes to NULL */
if (p == NULL) { err = ENOMEM; }
}
-
+
if (!err && (dirhandle != NULL) && (dirhandle->files != NULL)) {
int i = 0;
@@ -706,8 +706,8 @@ krb5int_get_plugin_dir_data (struct plugin_dir_handle *dirhandle,
count++;
newp = realloc (p, ((count + 1) * sizeof (*p))); /* +1 for NULL */
- if (newp == NULL) {
- err = ENOMEM;
+ if (newp == NULL) {
+ err = ENOMEM;
} else {
p = newp;
p[count - 1] = sym;
@@ -716,14 +716,14 @@ krb5int_get_plugin_dir_data (struct plugin_dir_handle *dirhandle,
}
}
}
-
+
if (!err) {
*ptrs = p;
p = NULL; /* ptrs takes ownership */
}
-
+
if (p != NULL) { free (p); }
-
+
return err;
}
@@ -743,29 +743,29 @@ krb5int_get_plugin_dir_func (struct plugin_dir_handle *dirhandle,
long err = 0;
void (**p)() = NULL;
size_t count = 0;
-
+
/* XXX Do we need to add a leading "_" to the symbol name on any
modern platforms? */
-
+
Tprintf("get_plugin_data_sym(%s)\n", symname);
-
+
if (!err) {
p = calloc (1, sizeof (*p)); /* calloc initializes to NULL */
if (p == NULL) { err = ENOMEM; }
}
-
+
if (!err && (dirhandle != NULL) && (dirhandle->files != NULL)) {
int i = 0;
-
+
for (i = 0; !err && (dirhandle->files[i] != NULL); i++) {
void (*sym)() = NULL;
-
+
if (krb5int_get_plugin_func (dirhandle->files[i], symname, &sym, ep) == 0) {
void (**newp)() = NULL;
count++;
newp = realloc (p, ((count + 1) * sizeof (*p))); /* +1 for NULL */
- if (newp == NULL) {
+ if (newp == NULL) {
err = ENOMEM;
} else {
p = newp;
@@ -775,13 +775,13 @@ krb5int_get_plugin_dir_func (struct plugin_dir_handle *dirhandle,
}
}
}
-
+
if (!err) {
*ptrs = p;
p = NULL; /* ptrs takes ownership */
}
-
+
if (p != NULL) { free (p); }
-
+
return err;
}