s4:torture: Set credentials for libsmbclient correctly
authorAndreas Schneider <asn@samba.org>
Mon, 3 Sep 2018 14:36:54 +0000 (16:36 +0200)
committerJeremy Allison <jra@samba.org>
Wed, 5 Sep 2018 16:22:24 +0000 (18:22 +0200)
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source4/torture/libsmbclient/libsmbclient.c

index fb27ddd032699c1c5d0ebaba2d86984d2c9e92f8..853d002aa8d2405c090efb2f06311e24fe134c92 100644 (file)
@@ -40,9 +40,39 @@ static void debug_callback(void *private_ptr, int level, const char *msg)
        return;
 }
 
+static void auth_callback(const char *srv,
+                         const char *shr,
+                         char *wg, int wglen,
+                         char *un, int unlen,
+                         char *pw, int pwlen)
+{
+       const char *workgroup =
+               cli_credentials_get_domain(popt_get_cmdline_credentials());
+       const char *username =
+               cli_credentials_get_username(popt_get_cmdline_credentials());
+       const char *password =
+               cli_credentials_get_password(popt_get_cmdline_credentials());
+
+       if (workgroup != NULL) {
+               snprintf(wg, wglen, "%s", workgroup);
+       }
+
+       if (username != NULL) {
+               snprintf(un, unlen, "%s", username);
+       }
+
+       if (password != NULL) {
+               snprintf(pw, pwlen, "%s", password);
+       }
+};
+
 bool torture_libsmbclient_init_context(struct torture_context *tctx,
                                       SMBCCTX **ctx_p)
 {
+       const char *workgroup =
+               cli_credentials_get_domain(popt_get_cmdline_credentials());
+       const char *username =
+               cli_credentials_get_username(popt_get_cmdline_credentials());
        SMBCCTX *ctx = NULL;
        SMBCCTX *p = NULL;
        bool ok = true;
@@ -64,8 +94,14 @@ bool torture_libsmbclient_init_context(struct torture_context *tctx,
        smbc_setDebug(ctx, DEBUGLEVEL);
        smbc_setOptionDebugToStderr(ctx, 1);
 
-       smbc_setUser(ctx,
-                    cli_credentials_get_username(popt_get_cmdline_credentials()));
+       if (workgroup != NULL) {
+               smbc_setWorkgroup(ctx, workgroup);
+       }
+       if (username != NULL) {
+               smbc_setUser(ctx, username);
+       }
+
+       smbc_setFunctionAuthData(ctx, auth_callback);
 
        *ctx_p = ctx;