s3:net: add net_context->explicit_credentials to check if credentials were passed
authorStefan Metzmacher <metze@samba.org>
Thu, 7 Mar 2024 13:40:10 +0000 (14:40 +0100)
committerStefan Metzmacher <metze@samba.org>
Tue, 14 May 2024 10:18:31 +0000 (10:18 +0000)
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
source3/utils/net.c
source3/utils/net.h
source3/utils/net_util.c
source3/utils/py_net.c

index a4726c1ca17241ba618f68944ef97650c3cc29ef..2d9df0a5723d4ed307764a8263e84d28cfa27ef3 100644 (file)
@@ -1369,6 +1369,10 @@ static struct functable net_func[] = {
        c->creds = samba_cmdline_get_creds();
 
        {
+               enum credentials_obtained principal_obtained =
+                       cli_credentials_get_principal_obtained(c->creds);
+               enum credentials_obtained password_obtained =
+                       cli_credentials_get_password_obtained(c->creds);
                enum credentials_obtained username_obtained =
                        CRED_UNINITIALISED;
                enum smb_encryption_setting encrypt_state =
@@ -1377,6 +1381,13 @@ static struct functable net_func[] = {
                        cli_credentials_get_kerberos_state(c->creds);
                uint32_t gensec_features;
 
+               if (principal_obtained == CRED_SPECIFIED) {
+                       c->explicit_credentials = true;
+               }
+               if (password_obtained == CRED_SPECIFIED) {
+                       c->explicit_credentials = true;
+               }
+
                c->opt_user_name = cli_credentials_get_username_and_obtained(
                                c->creds,
                                &username_obtained);
index 559e97930a65ae62cf37b20f9eb4310d25bd1b8c..c14ec35915bebb1efce1aa4cae48139e88096a36 100644 (file)
@@ -45,6 +45,7 @@ struct net_context {
        const char *opt_password;
        const char *opt_user_name;
        bool opt_user_specified;
+       bool explicit_credentials;
        const char *opt_workgroup;
        int opt_long_list_entries;
        int opt_reboot;
index 9c7c74b52926a17b8c26335c87faad354ef7df69..757228a72e2f82482ee3a3d7d12081dd058468bc 100644 (file)
@@ -275,6 +275,7 @@ int net_use_krb_machine_account(struct net_context *c)
        c->opt_user_specified = true;
 
        cli_credentials_set_machine_account(c->creds, c->lp_ctx);
+       c->explicit_credentials = true;
        return 0;
 }
 
index 86c210fd4ee149b68f55ab50e85aecf016b7639a..90c570de03e38aa7f06b31a3e7e1e1a5db938594 100644 (file)
@@ -127,6 +127,7 @@ static PyObject *py_net_join_member(py_net_Object *self, PyObject *args, PyObjec
        r->in.debug             = debug;
 
        c->creds = self->creds;
+       c->explicit_credentials = true;
        c->opt_user_name = cli_credentials_get_username(self->creds);
        c->opt_password = cli_credentials_get_password(self->creds);
        c->opt_kerberos = cli_credentials_get_kerberos_state(self->creds);