The branch, master has been updated
       via  c871c224611 s3:netapi: Add libnetapi_set_creds()
       via  6968a325d9d s3:netapi: Get rid of set_cmdline_auth_info_*()
       via  4e82150dc14 auth:creds: Use our own 
cli_credentials_set_cmdline_callbacks()
       via  9e5ac70a7e4 auth:creds: Add command line function for standard 
password callback
       via  ca57356b78f s4:lib:cmdline: Rename 
cli_credentials_set_cmdline_callbacks()
       via  3f3093933a2 s3:netapi: Remove use_ccache from 'struct libnetapi_ctx'
       via  67d49ac1480 s3:netapi: Remove use_kerberos from struct libnetapi_ctx
       via  dd7adbfa8f2 s3:netapi: Remove workgroup from 'struct libnetapi_ctx'
       via  51d5bebcc15 s3:netapi: Remove password from 'struct libnetapi_ctx'
       via  d94053f9d8b s3:netapi: Remove username from 'struct libnetapi_ctx'
       via  fd78554d11a s3:netapi: Use public functions for username/password
       via  0aeca4e5a13 s3:netapi: Get username/password from cli_credentials 
in joindomain.c
       via  3506800d3ef s3:netapi: Get username/password from cli_credentials 
in netapi.c
       via  9285e64a623 s3:netapi: Fill also cli_credentials with netapi setters
       via  7bb70f701e4 s3:netapi: Add a cli_credentials pointer to struct 
libnetapi_ctx
       via  517f94f5bff s3:netapi: Remove unused ctx->krb5_cc_env
       via  e79b067e239 s3:netapi: Make 'struct libnetapi_ctx' opaque
       via  bcc3945e538 s3:netapi: Use public getters in getjoinableous example
       via  44ef7f96e16 s3:netapi: Use public getters in remote_machine example
       via  c9222ab8388 s3:netapi: Implement public 
libnetapi_get_(username|password) functions
      from  17283de8fd9 netcmd: Fix typos in offline domain backup test

https://git.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit c871c224611296ee922a508129913aca93a38a16
Author: Andreas Schneider <[email protected]>
Date:   Thu Mar 18 13:34:15 2021 +0100

    s3:netapi: Add libnetapi_set_creds()
    
    This will be used by the 'net' command in future!
    
    Signed-off-by: Andreas Schneider <[email protected]>
    Reviewed-by: Guenther Deschner <[email protected]>
    
    Autobuild-User(master): Günther Deschner <[email protected]>
    Autobuild-Date(master): Wed Mar 24 02:07:20 UTC 2021 on sn-devel-184

commit 6968a325d9d5c9d68634b10d9ee080004865bcd8
Author: Andreas Schneider <[email protected]>
Date:   Thu Mar 18 13:49:27 2021 +0100

    s3:netapi: Get rid of set_cmdline_auth_info_*()
    
    Signed-off-by: Andreas Schneider <[email protected]>
    Reviewed-by: Guenther Deschner <[email protected]>

commit 4e82150dc14cb8852a7a20c1d57b0db4a4cf82e1
Author: Andreas Schneider <[email protected]>
Date:   Thu Dec 3 17:07:53 2020 +0100

    auth:creds: Use our own cli_credentials_set_cmdline_callbacks()
    
    Signed-off-by: Andreas Schneider <[email protected]>
    Reviewed-by: Guenther Deschner <[email protected]>

commit 9e5ac70a7e49ecd0e61e9546ccdf0ad863f1177a
Author: Andreas Schneider <[email protected]>
Date:   Wed Aug 7 11:36:28 2019 +0200

    auth:creds: Add command line function for standard password callback
    
    Pair-Programmed-With: Stefan Metzmacher <[email protected]>
    Signed-off-by: Stefan Metzmacher <[email protected]>
    Signed-off-by: Andreas Schneider <[email protected]>
    Reviewed-by: Guenther Deschner <[email protected]>

commit ca57356b78f095c20685c4b510d20b1efedb5882
Author: Andreas Schneider <[email protected]>
Date:   Tue Mar 23 16:27:38 2021 +0100

    s4:lib:cmdline: Rename cli_credentials_set_cmdline_callbacks()
    
    Signed-off-by: Andreas Schneider <[email protected]>
    Reviewed-by: Guenther Deschner <[email protected]>

commit 3f3093933a2341da5329647b843ef8f06fc9e30b
Author: Andreas Schneider <[email protected]>
Date:   Thu Mar 18 13:39:54 2021 +0100

    s3:netapi: Remove use_ccache from 'struct libnetapi_ctx'
    
    Signed-off-by: Andreas Schneider <[email protected]>
    Reviewed-by: Guenther Deschner <[email protected]>

commit 67d49ac14805d6cb6fbc87904173aaeaf5f859c5
Author: Andreas Schneider <[email protected]>
Date:   Thu Mar 18 13:39:54 2021 +0100

    s3:netapi: Remove use_kerberos from struct libnetapi_ctx
    
    Signed-off-by: Andreas Schneider <[email protected]>
    Reviewed-by: Guenther Deschner <[email protected]>

commit dd7adbfa8f277932eeed17eceaaa7713fc23829b
Author: Andreas Schneider <[email protected]>
Date:   Thu Mar 18 11:37:50 2021 +0100

    s3:netapi: Remove workgroup from 'struct libnetapi_ctx'
    
    Signed-off-by: Andreas Schneider <[email protected]>
    Reviewed-by: Guenther Deschner <[email protected]>

commit 51d5bebcc156ee9b93937deefc534e44911245a7
Author: Andreas Schneider <[email protected]>
Date:   Thu Mar 18 11:37:03 2021 +0100

    s3:netapi: Remove password from 'struct libnetapi_ctx'
    
    Signed-off-by: Andreas Schneider <[email protected]>
    Reviewed-by: Guenther Deschner <[email protected]>

commit d94053f9d8b1fdce61e90d3942e75b02e2d3209c
Author: Andreas Schneider <[email protected]>
Date:   Thu Mar 18 11:36:37 2021 +0100

    s3:netapi: Remove username from 'struct libnetapi_ctx'
    
    Signed-off-by: Andreas Schneider <[email protected]>
    Reviewed-by: Guenther Deschner <[email protected]>

commit fd78554d11a60c75c0e6d2c8606a82bc20526c8a
Author: Andreas Schneider <[email protected]>
Date:   Thu Mar 18 11:14:39 2021 +0100

    s3:netapi: Use public functions for username/password
    
    Signed-off-by: Andreas Schneider <[email protected]>
    Reviewed-by: Guenther Deschner <[email protected]>

commit 0aeca4e5a131c38328c7768e173b845f594c3470
Author: Andreas Schneider <[email protected]>
Date:   Thu Mar 18 11:08:57 2021 +0100

    s3:netapi: Get username/password from cli_credentials in joindomain.c
    
    Signed-off-by: Andreas Schneider <[email protected]>
    Reviewed-by: Guenther Deschner <[email protected]>

commit 3506800d3effca667235eabf185a93274cc78901
Author: Andreas Schneider <[email protected]>
Date:   Thu Mar 18 11:12:09 2021 +0100

    s3:netapi: Get username/password from cli_credentials in netapi.c
    
    Signed-off-by: Andreas Schneider <[email protected]>
    Reviewed-by: Guenther Deschner <[email protected]>

commit 9285e64a623c1a9a65e6d74ef26bf48d25d2be6b
Author: Andreas Schneider <[email protected]>
Date:   Thu Mar 18 10:57:10 2021 +0100

    s3:netapi: Fill also cli_credentials with netapi setters
    
    Signed-off-by: Andreas Schneider <[email protected]>
    Reviewed-by: Guenther Deschner <[email protected]>

commit 7bb70f701e49e11d41583369737522f3db9b9382
Author: Andreas Schneider <[email protected]>
Date:   Thu Mar 18 10:43:26 2021 +0100

    s3:netapi: Add a cli_credentials pointer to struct libnetapi_ctx
    
    Signed-off-by: Andreas Schneider <[email protected]>
    Reviewed-by: Guenther Deschner <[email protected]>

commit 517f94f5bff154bb73b46645c0beb74350450cb1
Author: Andreas Schneider <[email protected]>
Date:   Thu Mar 18 11:00:05 2021 +0100

    s3:netapi: Remove unused ctx->krb5_cc_env
    
    Signed-off-by: Andreas Schneider <[email protected]>
    Reviewed-by: Guenther Deschner <[email protected]>

commit e79b067e2396bd950f444518bbaad5a2fd7e2da4
Author: Andreas Schneider <[email protected]>
Date:   Thu Mar 18 10:06:53 2021 +0100

    s3:netapi: Make 'struct libnetapi_ctx' opaque
    
    Signed-off-by: Andreas Schneider <[email protected]>
    Reviewed-by: Guenther Deschner <[email protected]>

commit bcc3945e5384e6f39dc03eaeeee2382a6a7d52be
Author: Andreas Schneider <[email protected]>
Date:   Thu Mar 18 10:05:26 2021 +0100

    s3:netapi: Use public getters in getjoinableous example
    
    Signed-off-by: Andreas Schneider <[email protected]>
    Reviewed-by: Guenther Deschner <[email protected]>

commit 44ef7f96e16f26780272a5638c009fcd79c21ed2
Author: Andreas Schneider <[email protected]>
Date:   Thu Mar 18 10:04:23 2021 +0100

    s3:netapi: Use public getters in remote_machine example
    
    Signed-off-by: Andreas Schneider <[email protected]>
    Reviewed-by: Guenther Deschner <[email protected]>

commit c9222ab838844bca698a64b2125a19244ee6f008
Author: Andreas Schneider <[email protected]>
Date:   Thu Mar 18 09:59:08 2021 +0100

    s3:netapi: Implement public libnetapi_get_(username|password) functions
    
    Signed-off-by: Andreas Schneider <[email protected]>
    Reviewed-by: Guenther Deschner <[email protected]>

-----------------------------------------------------------------------

Summary of changes:
 auth/credentials/credentials.h                    |   2 +
 auth/credentials/credentials_cmdline.c            |  73 +++++++++++
 auth/credentials/pycredentials.c                  |   1 -
 auth/credentials/wscript_build                    |   6 +-
 source3/lib/netapi/cm.c                           |  41 +++----
 source3/lib/netapi/examples/join/getjoinableous.c |  19 ++-
 source3/lib/netapi/examples/join/rename_machine.c |  19 ++-
 source3/lib/netapi/joindomain.c                   |  18 ++-
 source3/lib/netapi/netapi.c                       | 142 +++++++++++++++++-----
 source3/lib/netapi/netapi.h                       |  26 ++--
 source3/lib/netapi/netapi_private.h               |  14 ++-
 source3/wscript_build                             |   4 +-
 source4/lib/cmdline/credentials.c                 |   2 +-
 source4/lib/cmdline/popt_credentials.c            |   2 +-
 14 files changed, 289 insertions(+), 80 deletions(-)
 create mode 100644 auth/credentials/credentials_cmdline.c


Changeset truncated at 500 lines:

diff --git a/auth/credentials/credentials.h b/auth/credentials/credentials.h
index 1fff37e8154..1802e383594 100644
--- a/auth/credentials/credentials.h
+++ b/auth/credentials/credentials.h
@@ -315,6 +315,8 @@ bool cli_credentials_set_smb_encryption(struct 
cli_credentials *cred,
 enum smb_encryption_setting
 cli_credentials_get_smb_encryption(struct cli_credentials *cred);
 
+bool cli_credentials_set_cmdline_callbacks(struct cli_credentials *cred);
+
 void cli_credentials_dump(struct cli_credentials *creds);
 
 /**
diff --git a/auth/credentials/credentials_cmdline.c 
b/auth/credentials/credentials_cmdline.c
new file mode 100644
index 00000000000..11b1ab9ecd2
--- /dev/null
+++ b/auth/credentials/credentials_cmdline.c
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2005      Jelmer Vernooij <[email protected]>
+ * Copyright (c) 2016      Stefan Metzmacher <[email protected]>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "includes.h"
+#include "system/filesys.h"
+#include "auth/credentials/credentials.h"
+
+static const char *cmdline_get_userpassword(struct cli_credentials *creds)
+{
+       TALLOC_CTX *frame = talloc_stackframe();
+       const char *name = NULL;
+       char *label = NULL;
+       char *ret = NULL;
+       char pwd[256] = {0};
+       int rc;
+
+       name = cli_credentials_get_unparsed_name(creds, frame);
+       if (name == NULL) {
+               goto fail;
+       }
+       label = talloc_asprintf(frame, "Password for [%s]:", name);
+       if (label == NULL) {
+               goto fail;
+       }
+       rc = samba_getpass(label, pwd, sizeof(pwd), false, false);
+       if (rc != 0) {
+               goto fail;
+       }
+       ret = talloc_strdup(creds, pwd);
+       if (ret == NULL) {
+               goto fail;
+       }
+       talloc_set_name_const(ret, __location__);
+fail:
+       ZERO_STRUCT(pwd);
+       TALLOC_FREE(frame);
+       return ret;
+}
+
+/**
+ * @brief Set the command line password callback.
+ *
+ * This will set the callback to get the password from the command prompt or
+ * read it from 'stdin'.
+ *
+ * @param[in]  cred   The credential context.
+ *
+ * @return On success true, false otherwise.
+ */
+bool cli_credentials_set_cmdline_callbacks(struct cli_credentials *cred)
+{
+       /*
+        * The there is no tty, then we will try to read the password from
+        * stdin.
+        */
+       return cli_credentials_set_password_callback(cred,
+                                                    cmdline_get_userpassword);
+}
diff --git a/auth/credentials/pycredentials.c b/auth/credentials/pycredentials.c
index 95dde276ef7..23048c37276 100644
--- a/auth/credentials/pycredentials.c
+++ b/auth/credentials/pycredentials.c
@@ -22,7 +22,6 @@
 #include "python/modules.h"
 #include "pycredentials.h"
 #include "param/param.h"
-#include "lib/cmdline/credentials.h"
 #include "auth/credentials/credentials_internal.h"
 #include "librpc/gen_ndr/samr.h" /* for struct samr_Password */
 #include "librpc/gen_ndr/netlogon.h"
diff --git a/auth/credentials/wscript_build b/auth/credentials/wscript_build
index 46111164b36..7568554df4d 100644
--- a/auth/credentials/wscript_build
+++ b/auth/credentials/wscript_build
@@ -23,12 +23,16 @@ bld.SAMBA_SUBSYSTEM('CREDENTIALS_NTLM',
        source='credentials_ntlm.c',
        deps='samba-credentials GNUTLS_HELPERS')
 
+bld.SAMBA_SUBSYSTEM('CREDENTIALS_CMDLINE',
+                    source='credentials_cmdline.c',
+                    deps='samba-credentials')
+
 pytalloc_util = bld.pyembed_libname('pytalloc-util')
 pyparam_util = bld.pyembed_libname('pyparam_util')
 
 bld.SAMBA_PYTHON('pycredentials',
     source='pycredentials.c',
-    public_deps='samba-credentials cmdline-credentials %s %s CREDENTIALS_KRB5 
CREDENTIALS_SECRETS' % (pytalloc_util, pyparam_util),
+    public_deps='samba-credentials %s %s CREDENTIALS_CMDLINE CREDENTIALS_KRB5 
CREDENTIALS_SECRETS' % (pytalloc_util, pyparam_util),
     realname='samba/credentials.so'
 )
 
diff --git a/source3/lib/netapi/cm.c b/source3/lib/netapi/cm.c
index 3f4e188b396..a2468de4ccc 100644
--- a/source3/lib/netapi/cm.c
+++ b/source3/lib/netapi/cm.c
@@ -67,11 +67,13 @@ static WERROR libnetapi_open_ipc_connection(struct 
libnetapi_ctx *ctx,
                                            struct client_ipc_connection **pp)
 {
        struct libnetapi_private_ctx *priv_ctx;
-       struct user_auth_info *auth_info = NULL;
        struct cli_state *cli_ipc = NULL;
        struct client_ipc_connection *p;
        NTSTATUS status;
-       struct cli_credentials *creds = NULL;
+       const char *username = NULL;
+       const char *password = NULL;
+       NET_API_STATUS rc;
+       enum credentials_use_kerberos krb5_state;
 
        if (!ctx || !pp || !server_name) {
                return WERR_INVALID_PARAMETER;
@@ -85,38 +87,35 @@ static WERROR libnetapi_open_ipc_connection(struct 
libnetapi_ctx *ctx,
                return WERR_OK;
        }
 
-       auth_info = user_auth_info_init(ctx);
-       if (!auth_info) {
-               return WERR_NOT_ENOUGH_MEMORY;
+       rc = libnetapi_get_username(ctx, &username);
+       if (rc != 0) {
+               return WERR_INTERNAL_ERROR;
        }
-       set_cmdline_auth_info_signing_state_raw(auth_info, 
SMB_SIGNING_IPC_DEFAULT);
-       set_cmdline_auth_info_use_kerberos(auth_info, ctx->use_kerberos);
-       set_cmdline_auth_info_username(auth_info, ctx->username);
-       if (ctx->password) {
-               set_cmdline_auth_info_password(auth_info, ctx->password);
-       } else {
-               set_cmdline_auth_info_getpass(auth_info);
+
+       rc = libnetapi_get_password(ctx, &password);
+       if (rc != 0) {
+               return WERR_INTERNAL_ERROR;
        }
 
-       if (ctx->username && ctx->username[0] &&
-           ctx->password && ctx->password[0] &&
-           ctx->use_kerberos) {
-               set_cmdline_auth_info_fallback_after_kerberos(auth_info, true);
+       if (password == NULL) {
+               cli_credentials_set_cmdline_callbacks(ctx->creds);
        }
 
-       if (ctx->use_ccache) {
-               set_cmdline_auth_info_use_ccache(auth_info, true);
+       krb5_state = cli_credentials_get_kerberos_state(ctx->creds);
+
+       if (username != NULL && username[0] != '\0' &&
+           password != NULL && password[0] != '\0' &&
+           krb5_state == CRED_USE_KERBEROS_REQUIRED) {
+               cli_credentials_set_kerberos_state(ctx->creds, 
CRED_USE_KERBEROS_DESIRED);
        }
-       creds = get_cmdline_auth_info_creds(auth_info);
 
        status = cli_cm_open(ctx, NULL,
                             server_name, "IPC$",
-                            creds,
+                            ctx->creds,
                             NULL, 0, 0x20, &cli_ipc);
        if (!NT_STATUS_IS_OK(status)) {
                cli_ipc = NULL;
        }
-       TALLOC_FREE(auth_info);
 
        if (!cli_ipc) {
                libnetapi_set_error_string(ctx,
diff --git a/source3/lib/netapi/examples/join/getjoinableous.c 
b/source3/lib/netapi/examples/join/getjoinableous.c
index 732f73dd572..c0fba576eae 100644
--- a/source3/lib/netapi/examples/join/getjoinableous.c
+++ b/source3/lib/netapi/examples/join/getjoinableous.c
@@ -35,6 +35,8 @@ int main(int argc, const char **argv)
        uint32_t num_ous = 0;
        struct libnetapi_ctx *ctx = NULL;
        int i;
+       const char *username = NULL;
+       const char *password = NULL;
 
        poptContext pc;
        int opt;
@@ -70,10 +72,23 @@ int main(int argc, const char **argv)
 
        /* NetGetJoinableOUs */
 
+       status = libnetapi_get_username(ctx, &username);
+       if (status != 0) {
+               printf("failed with: %s\n",
+                       libnetapi_get_error_string(ctx, status));
+               goto out;
+       }
+       status = libnetapi_get_password(ctx, &password);
+       if (status != 0) {
+               printf("failed with: %s\n",
+                       libnetapi_get_error_string(ctx, status));
+               goto out;
+       }
+
        status = NetGetJoinableOUs(host_name,
                                   domain_name,
-                                  ctx->username,
-                                  ctx->password,
+                                  username,
+                                  password,
                                   &num_ous,
                                   &ous);
        if (status != 0) {
diff --git a/source3/lib/netapi/examples/join/rename_machine.c 
b/source3/lib/netapi/examples/join/rename_machine.c
index a21f9198d87..7be6dc2bf2a 100644
--- a/source3/lib/netapi/examples/join/rename_machine.c
+++ b/source3/lib/netapi/examples/join/rename_machine.c
@@ -33,6 +33,8 @@ int main(int argc, const char **argv)
        const char *new_machine_name = NULL;
        uint32_t rename_opt = 0;
        struct libnetapi_ctx *ctx = NULL;
+       const char *username = NULL;
+       const char *password = NULL;
 
        poptContext pc;
        int opt;
@@ -68,10 +70,23 @@ int main(int argc, const char **argv)
 
        /* NetRenameMachineInDomain */
 
+       status = libnetapi_get_username(ctx, &username);
+       if (status != 0) {
+               printf("failed with: %s\n",
+                       libnetapi_get_error_string(ctx, status));
+               goto out;
+       }
+       status = libnetapi_get_password(ctx, &password);
+       if (status != 0) {
+               printf("failed with: %s\n",
+                       libnetapi_get_error_string(ctx, status));
+               goto out;
+       }
+
        status = NetRenameMachineInDomain(host_name,
                                          new_machine_name,
-                                         ctx->username,
-                                         ctx->password,
+                                         username,
+                                         password,
                                          rename_opt);
        if (status != 0) {
                printf("failed with: %s\n",
diff --git a/source3/lib/netapi/joindomain.c b/source3/lib/netapi/joindomain.c
index f2d36fc00db..90a58824fe5 100644
--- a/source3/lib/netapi/joindomain.c
+++ b/source3/lib/netapi/joindomain.c
@@ -428,15 +428,25 @@ WERROR NetGetJoinableOUs_l(struct libnetapi_ctx *ctx,
        SAFE_FREE(ads->auth.user_name);
        if (r->in.account) {
                ads->auth.user_name = SMB_STRDUP(r->in.account);
-       } else if (ctx->username) {
-               ads->auth.user_name = SMB_STRDUP(ctx->username);
+       } else {
+               const char *username = NULL;
+
+               libnetapi_get_username(ctx, &username);
+               if (username != NULL) {
+                       ads->auth.user_name = SMB_STRDUP(username);
+               }
        }
 
        SAFE_FREE(ads->auth.password);
        if (r->in.password) {
                ads->auth.password = SMB_STRDUP(r->in.password);
-       } else if (ctx->password) {
-               ads->auth.password = SMB_STRDUP(ctx->password);
+       } else {
+               const char *password = NULL;
+
+               libnetapi_get_password(ctx, &password);
+               if (password != NULL) {
+                       ads->auth.password = SMB_STRDUP(password);
+               }
        }
 
        ads_status = ads_connect_user_creds(ads);
diff --git a/source3/lib/netapi/netapi.c b/source3/lib/netapi/netapi.c
index fb8b4bc6113..a56651d100f 100644
--- a/source3/lib/netapi/netapi.c
+++ b/source3/lib/netapi/netapi.c
@@ -23,6 +23,9 @@
 #include "lib/netapi/netapi_private.h"
 #include "secrets.h"
 #include "krb5_env.h"
+#include "source3/param/loadparm.h"
+#include "lib/param/param.h"
+#include "auth/gensec/gensec.h"
 
 struct libnetapi_ctx *stat_ctx = NULL;
 static bool libnetapi_initialized = false;
@@ -104,6 +107,7 @@ NET_API_STATUS libnetapi_net_init(struct libnetapi_ctx 
**context)
        NET_API_STATUS status;
        struct libnetapi_ctx *ctx = NULL;
        TALLOC_CTX *frame = talloc_stackframe();
+       struct loadparm_context *lp_ctx = NULL;
 
        ctx = talloc_zero(frame, struct libnetapi_ctx);
        if (!ctx) {
@@ -111,19 +115,22 @@ NET_API_STATUS libnetapi_net_init(struct libnetapi_ctx 
**context)
                return W_ERROR_V(WERR_NOT_ENOUGH_MEMORY);
        }
 
-       BlockSignals(True, SIGPIPE);
-
-       if (getenv("USER")) {
-               ctx->username = talloc_strdup(ctx, getenv("USER"));
-       } else {
-               ctx->username = talloc_strdup(ctx, "");
+       ctx->creds = cli_credentials_init(ctx);
+       if (ctx->creds == NULL) {
+               TALLOC_FREE(frame);
+               return W_ERROR_V(WERR_NOT_ENOUGH_MEMORY);
        }
-       if (!ctx->username) {
+
+       lp_ctx = loadparm_init_s3(frame, loadparm_s3_helpers());
+       if (lp_ctx == NULL) {
                TALLOC_FREE(frame);
-               fprintf(stderr, "libnetapi_init: out of memory\n");
                return W_ERROR_V(WERR_NOT_ENOUGH_MEMORY);
        }
 
+       BlockSignals(True, SIGPIPE);
+
+       cli_credentials_guess(ctx->creds, lp_ctx);
+
        status = libnetapi_init_private_context(ctx);
        if (status != 0) {
                TALLOC_FREE(frame);
@@ -170,13 +177,6 @@ NET_API_STATUS libnetapi_free(struct libnetapi_ctx *ctx)
 
        libnetapi_shutdown_cm(ctx);
 
-       if (ctx->krb5_cc_env) {
-               char *env = getenv(KRB5_ENV_CCNAME);
-               if (env && (strequal(ctx->krb5_cc_env, env))) {
-                       unsetenv(KRB5_ENV_CCNAME);
-               }
-       }
-
        gfree_loadparm();
        gfree_charcnv();
        gfree_interfaces();
@@ -227,37 +227,112 @@ NET_API_STATUS libnetapi_get_debuglevel(struct 
libnetapi_ctx *ctx,
 /****************************************************************
 ****************************************************************/
 
+/**
+ * @brief Get the username of the libnet context
+ *
+ * @param[in]  ctx      The netapi context
+ *
+ * @param[in]  username A pointer to hold the username.
+ *
+ * @return 0 on success, an werror code otherwise.
+ */
+NET_API_STATUS libnetapi_get_username(struct libnetapi_ctx *ctx,
+                                     const char **username)
+{
+       if (ctx == NULL) {
+               return W_ERROR_V(WERR_INVALID_PARAMETER);
+       }
+
+       if (username != NULL) {
+               *username = cli_credentials_get_username(ctx->creds);
+       }
+
+       return NET_API_STATUS_SUCCESS;
+}
+
+/**
+ * @brief Get the password of the libnet context
+ *
+ * @param[in]  ctx      The netapi context
+ *
+ * @param[in]  password A pointer to hold the password.
+ *
+ * @return 0 on success, an werror code otherwise.
+ */
+NET_API_STATUS libnetapi_get_password(struct libnetapi_ctx *ctx,
+                                     const char **password)
+{
+       if (ctx == NULL) {
+               return W_ERROR_V(WERR_INVALID_PARAMETER);
+       }
+
+       if (password != NULL) {
+               *password = cli_credentials_get_password(ctx->creds);
+       }
+
+       return NET_API_STATUS_SUCCESS;
+}
+
 NET_API_STATUS libnetapi_set_username(struct libnetapi_ctx *ctx,
                                      const char *username)
 {
-       TALLOC_FREE(ctx->username);
-       ctx->username = talloc_strdup(ctx, username ? username : "");
-
-       if (!ctx->username) {
-               return W_ERROR_V(WERR_NOT_ENOUGH_MEMORY);
+       if (ctx == NULL || username == NULL) {
+               return W_ERROR_V(WERR_INVALID_PARAMETER);
        }
+
+       cli_credentials_parse_string(ctx->creds, username, CRED_SPECIFIED);
+
        return NET_API_STATUS_SUCCESS;
 }
 
 NET_API_STATUS libnetapi_set_password(struct libnetapi_ctx *ctx,
                                      const char *password)
 {
-       TALLOC_FREE(ctx->password);
-       ctx->password = talloc_strdup(ctx, password);
-       if (!ctx->password) {
-               return W_ERROR_V(WERR_NOT_ENOUGH_MEMORY);
+       bool ok;
+
+       if (ctx == NULL || password == NULL) {
+               return W_ERROR_V(WERR_INVALID_PARAMETER);
+       }
+
+       ok = cli_credentials_set_password(ctx->creds, password, CRED_SPECIFIED);
+       if (!ok) {
+               return W_ERROR_V(WERR_INTERNAL_ERROR);
        }
+
        return NET_API_STATUS_SUCCESS;
 }
 
 NET_API_STATUS libnetapi_set_workgroup(struct libnetapi_ctx *ctx,
                                       const char *workgroup)
 {
-       TALLOC_FREE(ctx->workgroup);
-       ctx->workgroup = talloc_strdup(ctx, workgroup);
-       if (!ctx->workgroup) {
-               return W_ERROR_V(WERR_NOT_ENOUGH_MEMORY);
+       bool ok;
+
+       ok = cli_credentials_set_domain(ctx->creds, workgroup, CRED_SPECIFIED);
+       if (!ok) {
+               return W_ERROR_V(WERR_INTERNAL_ERROR);
        }
+
+       return NET_API_STATUS_SUCCESS;
+}
+
+/**
+ * @brief Set the cli_credentials to be used in the netapi context
+ *
+ * @param[in]  ctx    The netapi context
+ *
+ * @param[in]  creds  The cli_credentials which should be used by netapi.
+ *
+ * @return 0 on success, an werror code otherwise.
+ */
+NET_API_STATUS libnetapi_set_creds(struct libnetapi_ctx *ctx,
+                                  struct cli_credentials *creds)
+{
+       if (ctx == NULL || creds == NULL) {
+               return W_ERROR_V(WERR_INVALID_PARAMETER);
+       }


-- 
Samba Shared Repository

Reply via email to