[Pvfs2-cvs] commit by sampson in
pvfs2/src/client/windows/client-service: cert.c config.c
dokan-interface.c service-main.c user-cache.c
CVS commit program
cvs at parl.clemson.edu
Wed May 18 17:37:13 EDT 2011
Update of /projects/cvsroot/pvfs2/src/client/windows/client-service
In directory parlweb1:/tmp/cvs-serv6139/src/client/windows/client-service
Modified Files:
Tag: windows-client
cert.c config.c dokan-interface.c service-main.c user-cache.c
Log Message:
Windows certificate support
Index: cert.c
===================================================================
RCS file: /projects/cvsroot/pvfs2/src/client/windows/client-service/Attic/cert.c,v
diff -p -u -r1.1.2.7 -r1.1.2.8
--- cert.c 17 May 2011 21:32:45 -0000 1.1.2.7
+++ cert.c 18 May 2011 21:37:12 -0000 1.1.2.8
@@ -22,7 +22,7 @@ extern wchar_t *convert_mbstring(const c
extern PORANGEFS_OPTIONS goptions;
/* initialize OpenSSL */
-static void openssl_init()
+void openssl_init()
{
SSL_library_init();
SSL_load_error_strings();
@@ -31,7 +31,7 @@ static void openssl_init()
}
/* cleanup OpenSSL */
-static void openssl_cleanup()
+void openssl_cleanup()
{
CRYPTO_cleanup_all_ex_data();
ERR_free_strings();
@@ -231,7 +231,7 @@ verify_cert_exit:
static unsigned int get_profile_dir(char *userid,
char *profile_dir)
{
- USER_INFO_4 user_info;
+ LPUSER_INFO_4 user_info;
LPWSTR wuserid;
int ret;
char *mbstr;
@@ -246,16 +246,18 @@ static unsigned int get_profile_dir(char
if (ret == 0)
{
- mbstr = convert_wstring(user_info.usri4_profile);
+ mbstr = convert_wstring(user_info->usri4_profile);
if (mbstr == NULL)
{
free(wuserid);
- return -1;
+ ret = -1;
}
strncpy(profile_dir, mbstr, MAX_PATH);
free(mbstr);
+
+ NetApiBufferFree(user_info);
}
free(wuserid);
@@ -275,9 +277,9 @@ static time_t get_cert_expires(X509 *cer
}
/* retrieve OrangeFS credentials from cert */
-static int get_cert_credentials(char *userid,
- PVFS_credentials *credentials,
- time_t *expires)
+int get_cert_credentials(char *userid,
+ PVFS_credentials *credentials,
+ time_t *expires)
{
char cert_dir[MAX_PATH], cert_path[MAX_PATH],
cert_pattern[MAX_PATH];
@@ -285,7 +287,7 @@ static int get_cert_credentials(char *us
WIN32_FIND_DATA find_data;
X509 *cert = NULL, *chain_cert = NULL, *ca_cert = NULL;
STACK_OF(X509) *chain;
- int ret, i;
+ int ret;
if (userid == NULL || credentials == NULL)
return -1;
Index: config.c
===================================================================
RCS file: /projects/cvsroot/pvfs2/src/client/windows/client-service/Attic/config.c,v
diff -p -u -r1.1.2.6 -r1.1.2.7
--- config.c 13 May 2011 21:37:02 -0000 1.1.2.6
+++ config.c 18 May 2011 21:37:12 -0000 1.1.2.7
@@ -48,6 +48,10 @@ FILE *open_config_file()
if (ret == 0)
f = fopen(file_name, "r");
+ if (f == NULL)
+ fprintf(stderr, "Fatal: could not open file %s\n",
+ file_name == NULL ? "(null)" : file_name);
+
if (malloc_flag)
free(file_name);
@@ -147,8 +151,8 @@ int get_config(PORANGEFS_OPTIONS options
config_file = open_config_file();
if (config_file == NULL)
- /* do not return an error -- config file is not required */
- return 0;
+ /* config file is required */
+ return 1;
/* parse options from the file */
while (!feof(config_file))
@@ -280,6 +284,12 @@ int get_config(PORANGEFS_OPTIONS options
}
close_config_file(config_file);
+
+ if (options->user_mode == USER_MODE_NONE)
+ {
+ fprintf(stderr, "Must specify user-mode (list, certificate or ldap)\n");
+ return 1;
+ }
return 0;
}
Index: dokan-interface.c
===================================================================
RCS file: /projects/cvsroot/pvfs2/src/client/windows/client-service/Attic/dokan-interface.c,v
diff -p -u -r1.1.2.38 -r1.1.2.39
--- dokan-interface.c 17 May 2011 21:32:45 -0000 1.1.2.38
+++ dokan-interface.c 18 May 2011 21:37:12 -0000 1.1.2.39
@@ -51,7 +51,7 @@ extern PORANGEFS_OPTIONS goptions;
#define DEBUG_PATH(path) DbgPrint(" resolved path: %s\n", path)
-static void DbgInit()
+void DbgInit()
{
char exe_path[MAX_PATH], *p;
int ret;
@@ -74,7 +74,7 @@ static void DbgInit()
}
}
-static void DbgPrint(char *format, ...)
+void DbgPrint(char *format, ...)
{
if (g_DebugMode)
{
@@ -108,7 +108,7 @@ static void DbgPrint(char *format, ...)
}
}
-static void DbgClose()
+void DbgClose()
{
if (g_DebugFile != NULL) {
fprintf(g_DebugFile, "\n");
@@ -246,7 +246,7 @@ static int error_map(int fs_err)
}
/* convert string from wide char (Unicode) to multi-byte string */
-static char *convert_wstring(const wchar_t *wcstr)
+char *convert_wstring(const wchar_t *wcstr)
{
errno_t err;
size_t ret, mb_size;
@@ -282,7 +282,7 @@ static char *convert_wstring(const wchar
}
-static wchar_t *convert_mbstring(const char *mbstr)
+wchar_t *convert_mbstring(const char *mbstr)
{
errno_t err;
size_t ret, w_size;
@@ -2016,7 +2016,7 @@ int __cdecl dokan_loop(PORANGEFS_OPTIONS
(PDOKAN_OPTIONS) malloc(sizeof(DOKAN_OPTIONS));
/* init credential cache */
- context_cache = qhash_init(cred_compare, quickhash_64bit_hash, 1023);
+ context_cache = qhash_init(cred_compare, quickhash_64bit_hash, 257);
gen_mutex_init(&context_cache_mutex);
g_DebugMode = g_UseStdErr = options->debug;
Index: service-main.c
===================================================================
RCS file: /projects/cvsroot/pvfs2/src/client/windows/client-service/Attic/service-main.c,v
diff -p -u -r1.1.2.12 -r1.1.2.13
--- service-main.c 17 May 2011 21:32:45 -0000 1.1.2.12
+++ service-main.c 18 May 2011 21:37:12 -0000 1.1.2.13
@@ -12,6 +12,7 @@
#include "client-service.h"
#include "config.h"
#include "fs.h"
+#include "cert.h"
#include "user-cache.h"
#define WIN32ServiceName "orangefs-client"
@@ -30,11 +31,14 @@ BOOL debug = FALSE;
int is_running = 0;
int run_service = 0;
-HANDLE hthread;
+HANDLE hthread, hcache_thread;
DWORD thread_start(PORANGEFS_OPTIONS options);
DWORD thread_stop();
+DWORD cache_thread_start();
+DWORD cache_thread_stop();
+
DWORD WINAPI main_loop(LPVOID poptions);
FILE *debug_log = NULL;
@@ -301,7 +305,7 @@ void WINAPI service_main(DWORD argc, cha
options = (PORANGEFS_OPTIONS) calloc(1, sizeof(ORANGEFS_OPTIONS));
/* init user cache */
- user_cache = qhash_init(user_compare, quickhash_64bit_hash, 1023);
+ user_cache = qhash_init(user_compare, quickhash_string_hash, 257);
gen_mutex_init(&user_cache_mutex);
@@ -312,8 +316,7 @@ void WINAPI service_main(DWORD argc, cha
ret = get_config(options);
/* point global options */
- goptions = options;
-
+ goptions = options;
#ifndef _DEBUG
debug = options->debug;
@@ -339,6 +342,17 @@ void WINAPI service_main(DWORD argc, cha
{
service_debug("Service registered\n");
+ /* run the user cache thread */
+ ret = cache_thread_start();
+ if (ret != 0)
+ {
+ service_debug("Could not start cache thread: %u\n", ret);
+ close_service_log();
+ free(options);
+
+ return;
+ }
+
/* run the service */
service_status.dwCurrentState = SERVICE_RUNNING;
service_status.dwControlsAccepted = SERVICE_ACCEPT_STOP;
@@ -353,6 +367,12 @@ void WINAPI service_main(DWORD argc, cha
service_debug("Starting thread\n");
thread_start(options);
}
+
+ /* stop cache thread */
+ cache_thread_stop();
+
+ /* cleanup OpenSSL */
+ openssl_cleanup();
/* shut down service */
service_status.dwCurrentState = SERVICE_STOPPED;
@@ -363,6 +383,8 @@ void WINAPI service_main(DWORD argc, cha
service_debug("RegisterServiceCtrlHandler failed: %u\n", GetLastError());
/* TODO: error reporting */
}
+
+ qhash_destroy_and_finalize(user_cache, struct user_entry, hash_link, free);
close_service_log();
@@ -415,6 +437,35 @@ DWORD thread_stop()
return err;
}
+DWORD cache_thread_start()
+{
+ DWORD err = 0;
+
+ /* create and run the user cache thread */
+ hcache_thread = CreateThread(NULL,
+ 0,
+ (LPTHREAD_START_ROUTINE) user_cache_thread,
+ NULL,
+ 0,
+ NULL);
+
+ if (hcache_thread == NULL)
+ err = GetLastError();
+
+ return err;
+}
+
+DWORD cache_thread_stop()
+{
+ DWORD err = 0;
+
+ if (hcache_thread != NULL)
+ if (!TerminateThread(hcache_thread, 0))
+ err = GetLastError();
+
+ return err;
+}
+
DWORD WINAPI main_loop(LPVOID poptions)
{
PORANGEFS_OPTIONS options = (PORANGEFS_OPTIONS) poptions;
@@ -532,6 +583,9 @@ int main(int argc, char **argv, char **e
}
}
+ /* initialize OpenSSL */
+ openssl_init();
+
if (run_service)
{
/* dispatch the main service thread */
@@ -542,7 +596,7 @@ int main(int argc, char **argv, char **e
options = (PORANGEFS_OPTIONS) calloc(1, sizeof(ORANGEFS_OPTIONS));
/* init user list */
- user_cache = qhash_init(user_compare, quickhash_64bit_hash, 1023);
+ user_cache = qhash_init(user_compare, quickhash_string_hash, 257);
gen_mutex_init(&user_cache_mutex);
@@ -565,20 +619,35 @@ int main(int argc, char **argv, char **e
if (debug)
options->debug = TRUE;
- is_running = 1;
-
if (!check_mount_point(options->mount_point))
{
fprintf(stderr, "Drive already in use\n");
return -1;
}
+ /* start user cache thread */
+ err = cache_thread_start();
+ if (err != 0)
+ {
+ fprintf(stderr, "User cache thread did not start: %u\n", err);
+ free(options);
+ return err;
+ }
+
+ is_running = 1;
+
/* process requests */
err = main_loop(options);
printf("main_loop exited: %d\n", err);
gen_mutex_destroy(&user_cache_mutex);
+
+ cache_thread_stop();
+
+ qhash_destroy_and_finalize(user_cache, struct user_entry, hash_link, free);
+
+ openssl_cleanup();
free(options);
}
Index: user-cache.c
===================================================================
RCS file: /projects/cvsroot/pvfs2/src/client/windows/client-service/Attic/user-cache.c,v
diff -p -u -r1.1.2.2 -r1.1.2.3
--- user-cache.c 17 May 2011 21:32:45 -0000 1.1.2.2
+++ user-cache.c 18 May 2011 21:37:12 -0000 1.1.2.3
@@ -11,6 +11,9 @@
#include "client-service.h"
#include "user-cache.h"
+/* amount of time cache mgmt thread sleeps */
+#define USER_THREAD_SLEEP_TIME 60000
+
struct qhash_table *user_cache;
gen_mutex_t user_cache_mutex;
@@ -27,14 +30,26 @@ int add_user(char *user_name,
PVFS_credentials *credentials,
time_t expires)
{
+ struct qhash_head *link;
struct user_entry *entry;
+ /* search for existing entry -- delete if found */
+ gen_mutex_lock(&user_cache_mutex);
+ link = qhash_search(user_cache, user_name);
+ if (link != NULL)
+ {
+ DbgPrint(" add_user: deleting user %s\n", user_name);
+ qhash_del(link);
+ free(qhash_entry(link, struct user_entry, hash_link));
+ }
+ gen_mutex_unlock(&user_cache_mutex);
+
/* allocate entry */
entry = (struct user_entry *) calloc(1, sizeof(struct user_entry));
if (entry == NULL)
{
- DbgPrint(" add_credentials: out of memory\n");
- return;
+ DbgPrint(" add_user: out of memory\n");
+ return -1;
}
/* add to hash table */
@@ -45,6 +60,8 @@ int add_user(char *user_name,
gen_mutex_lock(&user_cache_mutex);
qhash_add(user_cache, &entry->user_name, &entry->hash_link);
+ DbgPrint(" add_user: adding user %s (%u:%u) expires %u\n", user_name,
+ credentials->uid, credentials->gid, expires);
gen_mutex_unlock(&user_cache_mutex);
return 0;
@@ -53,19 +70,22 @@ int add_user(char *user_name,
int get_cached_user(char *user_name,
PVFS_credentials *credentials)
{
- qhash_head *item;
+ struct qhash_head *link;
struct user_entry *entry;
/* locate user by user_name */
gen_mutex_lock(&user_cache_mutex);
- item = qhash_search(user_cache, user_name);
- if (item != NULL)
+ link = qhash_search(user_cache, user_name);
+ if (link != NULL)
{
/* if cache hit -- return credentials */
- entry = qhash_entry(item, struct user_entry, hash_link);
+ entry = qhash_entry(link, struct user_entry, hash_link);
credentials->uid = entry->credentials.uid;
credentials->gid = entry->credentials.gid;
+ DbgPrint(" get_cached_user: hit for %s (%u:%u)\n", user_name,
+ credentials->uid, credentials->gid);
+
gen_mutex_unlock(&user_cache_mutex);
return 0;
@@ -77,24 +97,59 @@ int get_cached_user(char *user_name,
return 1;
}
-/* remove user entry */
+/* remove user entry -- note user_cache_mutex
+ should be locked */
+/* *** not currently needed
int remove_user(char *user_name)
{
struct qhash_head *link;
- gen_mutex_lock(&user_cache_mutex);
link = qhash_search_and_remove(user_cache, user_name);
if (link != NULL)
{
free(qhash_entry(link, struct user_entry, hash_link));
}
- gen_mutex_unlock(&user_cache_mutex);
return 0;
}
+*/
unsigned int user_cache_thread(void *options)
{
+ int i;
+ struct qhash_head *head, *link, *temp;
+ struct user_entry *entry;
+ time_t now;
+
+ /* remove expired user entries from user cache */
+ do
+ {
+ Sleep(USER_THREAD_SLEEP_TIME);
+
+ DbgPrint("user_cache_thread: checking\n");
+
+ now = time(NULL);
+
+ gen_mutex_lock(&user_cache_mutex);
+ for (i = 0; i < user_cache->table_size; i++)
+ {
+ head = qhash_search_at_index(user_cache, i);
+ qhash_for_each_safe(link, temp, head)
+ {
+ entry = qhash_entry(link, struct user_entry, hash_link);
+ if (entry->expires != 0 && entry->expires < now)
+ {
+ DbgPrint("user_cache_thread: removing %s\n", entry->user_name);
+ qhash_del(link);
+ free(entry);
+ }
+ }
+ }
+ gen_mutex_unlock(&user_cache_mutex);
+
+ DbgPrint("user_cache_thread: check complete\n");
+
+ } while (1);
return 0;
}
More information about the Pvfs2-cvs
mailing list