--- a/src/main.c
+++ b/src/main.c
@@ -5,7 +5,6 @@
 #include <unistd.h>
 #include <string.h>
 #include <locale.h>
-#include <signal.h>
 #include <sys/mman.h>
 #include <sys/types.h>
 #include <sys/socket.h>
@@ -17,90 +16,34 @@
 #include "common.h"
 #include "smbitem.h"
 #include "auth.h"
-#include "auth-gnome-keyring.h"
 #include "process.h"
 #include "samba.h"
 #include "function.h"
 #include "event.h"
 #include "reconfigure.h"
 
-
-static void check_samba_version(void){
+void check_samba_version(void){
     const char	*samba_version;
-    int		major, minor;
 
     samba_version = smbc_version();
-    if (sscanf(samba_version, "%d.%d.%*d", &major, &minor) != 2){
-	fprintf(stderr, "ERROR: Can't parse libsmbclient version: %s\n",
-	                samba_version);
+    if (strncmp(samba_version, "3.", 2) != 0){
+	fprintf(stderr, "Unknown libsmbclient version: %s\n", samba_version);
 	exit(EXIT_FAILURE);
     }
-
-  #ifndef HAVE_LIBSMBCLIENT_3_2
-    if (major < 3) goto unsupported;
-    if ((major == 3) && (minor < 2)) goto no_truncate;
-    else goto please_recompile;
-  #else
-    if (major >= 5) goto to_new;
-    if (major == 4) goto ok;
-    if (major == 3){
-	if (minor >= 2) goto ok;
-	else goto unsupported;
-    }
-  #endif
-
-  unsupported:
-    fprintf(stderr, "ERROR: Unsupported libsmbclient version: %s\n"
-                    "       Please consider upgrade to libsmbclient >= 3.2\n"
-                    "\n",
-                     samba_version);
-    exit(EXIT_FAILURE);
-
-#ifndef HAVE_LIBSMBCLIENT_3_2
-  no_truncate:
-    fprintf(stderr, "WARNING: Too old libsmbclient version: %s\n"
-                    "         truncate() and ftruncate() operations are not supported."
-                    "         Please consider upgrade to libsmbclient >= 3.2\n"
-                    "\n",
-                     samba_version);
-    return;
-
-  please_recompile:
-    fprintf(stderr, "WARNING: " PACKAGE_NAME " was compiled against libsmbclient < 3.2,\n"
-                    "         thus truncate() and ftruncate() operations are not supported.\n"
-                    "         Current libsmbclient version is %s. Please recompile " PACKAGE_NAME "\n"
-                    "         to get support of truncate() and ftruncate() operations.\n"
-                    "\n",
-                    samba_version);
-    return;
-
-#else
-  ok:
-    /* libsmbclient >= 3.2 is perfectly OK */
-    return;
-
-  to_new:
-    fprintf(stderr, "WARNING: Unknown libsmbclient version: %s\n"
-                    "         " PACKAGE_NAME " may not work as expected.\n"
-                    "\n",
-                    samba_version);
-    /* Hm... libsmbclient version is too new, trying to continue anyway. */
-    return;
-#endif
 }
 
-static inline size_t get_default_rw_block_size(void){
+inline size_t get_default_rw_block_size(void){
     return (strncmp(smbc_version(), "3.0.", 4) == 0) ? 48 : 128;
 }
 
-static void sig_handler(int signum){
+void sig_handler(int signum){
     fprintf(stderr, "%d->%s: signal %d received\n",
 	getpid(), __FUNCTION__, signum);
     common_print_backtrace();
     exit(signum);
 }
 
-static void set_signal_reactions(void){
+void set_signal_reactions(void){
     struct{
 	int	signum;
 	char	*name;
@@ -130,89 +73,63 @@
     }
 }
 
-static void print_help(struct fuse_args *outargs){
-    fprintf(stderr,
-	"usage: %s mountpoint [options]\n"
-	"\n"
-	"general options:\n"
-	"    -o opt,[opt...]        mount options\n"
-	"    -h   --help            print help\n"
-	"    -V   --version         print version\n"
-	"\n"
-	"SMBNetFS options:\n"
-	"%s"
-	"\n", outargs->argv[0], smbnetfs_option_list);
-    fuse_opt_add_arg(outargs, "-ho");
-    fuse_main(outargs->argc, outargs->argv, &smb_oper, NULL);
-}
+void set_default_login_and_configdir(void){
+    char			buf[1024];
+    register struct passwd	*pwd;
+    const char			*home, *user, *dir;
 
-static int smbnetfs_opt_proc(void *data, const char *arg, int key, struct fuse_args *outargs){
-    const char	*value;
-    char	*name;
-    int		result;
+    pwd = getpwuid(getuid());
 
-    (void) data;
-    (void) key;
+    user = getenv("USER");
+    if ((user == NULL) || (*user == '\0')) user = getenv("LOGNAME");
+    if ((user == NULL) || (*user == '\0')){
+	user = ((pwd != NULL) && 
+	        (pwd->pw_name != NULL) &&
+	        (pwd->pw_name != '\0')) ? pwd->pw_name : "anonymous";
+	setenv("USER", user, 1);
+	setenv("LOGNAME", user, 1);
+    }
+    auth_set_default_login_name(user);
 
-    if ((strcmp(arg, "--version") == 0) || (strcmp(arg, "-V") == 0)){
-	fprintf(stderr, "SMBNetFS version " PACKAGE_VERSION "\n");
-	fprintf(stderr, "libsmbclient version %s\n", smbc_version());
-	fuse_opt_add_arg(outargs, "--version");
-	fuse_main(outargs->argc, outargs->argv, &smb_oper, NULL);
-	exit(EXIT_SUCCESS);
-    }
-    if ((strcmp(arg, "--help") == 0) || (strcmp(arg, "-h") == 0)){
-	print_help(outargs);
-	exit(EXIT_FAILURE);
+    home = getenv("HOME");
+    if ((home == NULL) || (*home != '/')){
+	home = ((pwd != NULL) && 
+	        (pwd->pw_dir  != NULL) &&
+	        (*pwd->pw_dir == '/')) ? pwd->pw_dir : "/";
+	setenv("HOME", home, 1);
     }
 
-    if ((value = strchr(arg, '=')) == NULL) return 1;
-    if (value++ == arg) return 1;
-    if (strlen(value) == 0) return 1;
-    if ((name = strndup(arg, value - arg - 1)) == NULL) return 1;
-
-    /* check for specific SMBNetFS options */
-    result = reconfigure_analyse_cmdline_option(name, (char*) value);
-
-    free(name);
-    return result ? 0 : 1;
+    dir = config_dir_posfix;
+    if (strlen(home) + strlen(dir) + 1 > sizeof(buf)) home = "/";
+    strcpy(buf, home);
+    strcat(buf, (home[strlen(home) - 1] == '/') ? dir + 1 : dir);
+    reconfigure_set_config_dir(buf);
 }
 
 int main(int argc, char *argv[]){
-    struct fuse_args	args = FUSE_ARGS_INIT(argc, argv);
-
     setlocale(LC_ALL, "");
     check_samba_version();
+    set_default_login_and_configdir();
     set_signal_reactions();
 
     /* init all subsystems with their default values */
-    reconfigure_set_default_login_and_configdir();
-#ifdef HAVE_GNOME_KEYRING
-    gnome_keyring_init();
-#endif /* HAVE_GNOME_KEYRING */
     smbitem_init();
     process_init();
     samba_init(1024 * get_default_rw_block_size());
     event_set_event_handler(&smb_oper);
 
-    /* parse command line options */
-    if (fuse_opt_parse(&args, NULL, NULL, smbnetfs_opt_proc) == -1){
-	fprintf(stderr, "Can't parse command line, please verify it.\n");
-	exit(EXIT_FAILURE);
-    }
+//    reconfigure_set_config_dir("/home/kl/smbnetfs/conf/");
 
-    reconfigure_read_config(CONFIG_OPT_STARTUP);
+    /* read configuration */
+    reconfigure_read_config_file(config_file, 1);
     samba_allocate_ctxs();
 
-    fuse_main(args.argc, args.argv, &smb_oper, NULL);
+    fuse_main(argc, argv, &smb_oper, NULL);
     samba_destroy_unused_ctxs();
     smbitem_delete_obsolete(time(NULL) + 10, SMBITEM_SAMBA_TREE);
     smbitem_delete_obsolete(time(NULL) + 10, SMBITEM_USER_TREE);
     auth_delete_obsolete(time(NULL) + 10);
     smbitem_done();
     process_cleanup_from_zombies();
-#ifdef HAVE_GNOME_KEYRING
-    gnome_keyring_done();
-#endif /* HAVE_GNOME_KEYRING */
     return 0;
 }