Determine case sensitivity based on file system attributes.
[tprouty/samba.git] / source3 / libsmb / libsmb_context.c
index 3e67943c83ce1730d989453d5a54525055d74b31..c2c33e53025903c6a3a2ff02c4cd781f8fdebee2 100644 (file)
@@ -30,9 +30,8 @@
 /*
  * Is the logging working / configfile read ? 
  */
-static int SMBC_initialized = 0;
-
-
+static bool SMBC_initialized;
+static unsigned int initialized_ctx_count;
 
 /*
  * Get a new empty handle to fill in with your own info
@@ -70,6 +69,7 @@ smbc_new_context(void)
         smbc_setOptionFullTimeNames(context, False);
         smbc_setOptionOpenShareMode(context, SMBC_SHAREMODE_DENY_NONE);
         smbc_setOptionSmbEncryptionLevel(context, SMBC_ENCRYPTLEVEL_NONE);
+        smbc_setOptionCaseSensitive(context, False);
         smbc_setOptionBrowseMaxLmbCount(context, 3);    /* # LMBs to query */
         smbc_setOptionUrlEncodeReaddirEntries(context, False);
         smbc_setOptionOneSharePerServer(context, False);
@@ -200,7 +200,20 @@ smbc_free_context(SMBCCTX *context,
         smbc_setUser(context, NULL);
         
         DEBUG(3, ("Context %p successfully freed\n", context));
+
+       SAFE_FREE(context->internal);
         SAFE_FREE(context);
+
+       if (initialized_ctx_count) {
+               initialized_ctx_count--;
+       }
+
+       if (initialized_ctx_count == 0 && SMBC_initialized) {
+               gencache_shutdown();
+               secrets_shutdown();
+               gfree_all();
+               SMBC_initialized = false;
+       }
         return 0;
 }
 
@@ -421,7 +434,8 @@ smbc_init_context(SMBCCTX *context)
                 return NULL;
         }
         
-        if (!smbc_getFunctionAuthData(context) ||
+        if ((!smbc_getFunctionAuthData(context) &&
+             !smbc_getFunctionAuthDataWithContext(context)) ||
             smbc_getDebug(context) < 0 ||
             smbc_getDebug(context) > 100) {
                 
@@ -507,7 +521,7 @@ smbc_init_context(SMBCCTX *context)
                 BlockSignals(True, SIGPIPE);
                 
                 /* Done with one-time initialisation */
-                SMBC_initialized = 1;
+                SMBC_initialized = true;
                 
                 TALLOC_FREE(frame);
         }
@@ -596,7 +610,8 @@ smbc_init_context(SMBCCTX *context)
          */
         
         context->internal->initialized = True;
-        
+       initialized_ctx_count++;
+
         return context;
 }
 
@@ -609,3 +624,29 @@ smbc_version(void)
 }
 
 
+/*
+ * Set the credentials so DFS will work when following referrals.
+ */
+void
+smbc_set_credentials(char *workgroup,
+                     char *user,
+                     char *password,
+                     smbc_bool use_kerberos,
+                     char *signing_state)
+{
+        struct user_auth_info *auth_info;
+
+       auth_info = user_auth_info_init(talloc_tos());
+       if (auth_info == NULL) {
+               return;
+       }
+        set_cmdline_auth_info_username(auth_info, user);
+        set_cmdline_auth_info_password(auth_info, password);
+        set_cmdline_auth_info_use_kerberos(auth_info, use_kerberos);
+        if (! set_cmdline_auth_info_signing_state(auth_info, signing_state)) {
+                DEBUG(0, ("Invalid signing state: %s", signing_state));
+        }
+        set_global_myworkgroup(workgroup);
+        cli_cm_set_credentials(auth_info);
+       TALLOC_FREE(auth_info);
+}