]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3:libsmb: Use lpcfg_set_cmdline()
authorPavel Kalugin <pkalugin@inno.tech>
Sun, 3 Sep 2023 20:21:35 +0000 (23:21 +0300)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 14 Sep 2023 21:35:29 +0000 (21:35 +0000)
Signed-off-by: Pavel Kalugin <pkalugin@inno.tech>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
source3/include/libsmb_internal.h
source3/libsmb/libsmb_context.c
source3/libsmb/libsmb_setget.c

index 5588f9df66a8c506f45a8d2974d7c0928df17984..6ca265ad38a76d6be8916248acd5e0d116fb0405 100644 (file)
@@ -254,7 +254,9 @@ struct SMBC_internal_data {
         }               smb;
 
        uint16_t        port;
-};     
+
+       struct loadparm_context *lp_ctx;
+};
 
 /* Functions in libsmb_cache.c */
 int
index 783889a952d726d8831b0aade320148259824eac..a4c4c84a83107ab0f1909462c7d5c7a2f064a0b6 100644 (file)
@@ -169,6 +169,16 @@ smbc_new_context(void)
         /* Initialize the context and establish reasonable defaults */
         ZERO_STRUCTP(context->internal);
 
+       context->internal->lp_ctx = loadparm_init_s3(NULL,
+                                                    loadparm_s3_helpers());
+       if (context->internal->lp_ctx == NULL) {
+               SAFE_FREE(context->internal);
+               SAFE_FREE(context);
+               TALLOC_FREE(frame);
+               errno = ENOMEM;
+               return NULL;
+       }
+
         smbc_setDebug(context, 0);
         smbc_setTimeout(context, 20000);
         smbc_setPort(context, 0);
@@ -324,6 +334,7 @@ smbc_free_context(SMBCCTX *context,
        /* Free any DFS auth context. */
        TALLOC_FREE(context->internal->creds);
 
+       TALLOC_FREE(context->internal->lp_ctx);
        SAFE_FREE(context->internal);
         SAFE_FREE(context);
 
@@ -737,7 +748,6 @@ void smbc_set_credentials_with_fallback(SMBCCTX *context,
                                        const char *user,
                                        const char *password)
 {
-       struct loadparm_context *lp_ctx = NULL;
        struct cli_credentials *creds = NULL;
        enum credentials_use_kerberos kerberos_state =
                CRED_USE_KERBEROS_DISABLED;
@@ -765,13 +775,7 @@ void smbc_set_credentials_with_fallback(SMBCCTX *context,
                return;
        }
 
-       lp_ctx = loadparm_init_s3(creds, loadparm_s3_helpers());
-       if (lp_ctx == NULL) {
-               TALLOC_FREE(creds);
-               return;
-       }
-
-       cli_credentials_set_conf(creds, lp_ctx);
+       cli_credentials_set_conf(creds, context->internal->lp_ctx);
 
        if (smbc_getOptionUseKerberos(context)) {
                kerberos_state = CRED_USE_KERBEROS_REQUIRED;
index 9a8ef97f9feb55c7395fef8463c62344e7a24afd..2d7717e40c22a38f3e11d22187b07ae9b2f0ee69 100644 (file)
@@ -26,6 +26,7 @@
 #define __LIBSMBCLIENT_INTERNAL__
 #include "libsmbclient.h"
 #include "libsmb_internal.h"
+#include "lib/param/param.h"
 
 
 /** Get the netbios name used for making connections */
@@ -94,7 +95,7 @@ smbc_setDebug(SMBCCTX *c, int debug)
        TALLOC_CTX *frame = talloc_stackframe();
        snprintf(buf, sizeof(buf), "%d", debug);
         c->debug = debug;
-       lp_set_cmdline("log level", buf);
+       lpcfg_set_cmdline(c->internal->lp_ctx, "log level", buf);
        TALLOC_FREE(frame);
 }
 
@@ -534,11 +535,15 @@ smbc_setOptionProtocols(SMBCCTX *c,
        bool ok = true;
 
        if (min_proto != NULL) {
-               ok = lp_set_cmdline("client min protocol", min_proto);
+               ok = lpcfg_set_cmdline(c->internal->lp_ctx,
+                                      "client min protocol",
+                                      min_proto);
        }
 
        if (max_proto != NULL) {
-               ok &= lp_set_cmdline("client max protocol", max_proto);
+               ok &= lpcfg_set_cmdline(c->internal->lp_ctx,
+                                       "client max protocol",
+                                       max_proto);
        }
 
        return ok;