lib:cmdline: Add client credentials
authorAndreas Schneider <asn@samba.org>
Mon, 27 Jul 2020 14:13:53 +0000 (16:13 +0200)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 28 Apr 2021 03:43:34 +0000 (03:43 +0000)
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
lib/cmdline/cmdline.c
lib/cmdline/cmdline.h
lib/cmdline/cmdline_private.h
lib/cmdline/cmdline_s3.c
lib/cmdline/cmdline_s4.c
lib/cmdline/wscript

index b64a6ea3e205e0bab35d8ea006d8aa023a508ee6..9623a9c10b7682c2cf9e17f0c62f1ad7c607c3e3 100644 (file)
@@ -21,6 +21,7 @@
 
 static TALLOC_CTX *cmdline_mem_ctx;
 static struct loadparm_context *cmdline_lp_ctx;
+static struct cli_credentials *cmdline_creds;
 
 /* PRIVATE */
 bool samba_cmdline_set_talloc_ctx(TALLOC_CTX *mem_ctx)
@@ -81,3 +82,20 @@ struct loadparm_context *samba_cmdline_get_lp_ctx(void)
 {
        return cmdline_lp_ctx;
 }
+
+bool samba_cmdline_set_creds(struct cli_credentials *creds)
+{
+       if (creds == NULL) {
+               return false;
+       }
+
+       TALLOC_FREE(cmdline_creds);
+       cmdline_creds = creds;
+
+       return true;
+}
+
+struct cli_credentials *samba_cmdline_get_creds(void)
+{
+       return cmdline_creds;
+}
index 1a90237f4219e51e69766a51899602192ca0aecd..c184fc9efd3e1bc9d9bc4ea6aa1fa433872389f8 100644 (file)
@@ -18,6 +18,8 @@
 #ifndef _CMDLINE_H
 #define _CMDLINE_H
 
+#include "auth/credentials/credentials.h"
+
 /**
  * @brief Initialize the commandline interface for parsing options.
  *
@@ -42,4 +44,11 @@ bool samba_cmdline_init(TALLOC_CTX *mem_ctx, bool require_smbconf);
  */
 struct loadparm_context *samba_cmdline_get_lp_ctx(void);
 
+/**
+ * @brief Get the client credentials of the command line interface.
+ *
+ * @return A pointer to the client credentials.
+ */
+struct cli_credentials *samba_cmdline_get_creds(void);
+
 #endif /* _CMDLINE_H */
index 050aff97361c0406c16d35644c32e5bb872b19e9..7a1f5824b5e6a797837f878edeeb6848928aa794 100644 (file)
@@ -73,4 +73,15 @@ TALLOC_CTX *samba_cmdline_get_talloc_ctx(void);
  */
 bool samba_cmdline_set_lp_ctx(struct loadparm_context *lp_ctx);
 
+/**
+ * @internal
+ *
+ * @brief Set the client credentials for the commandline interface.
+ *
+ * @param[in]  creds   The client credentials to use.
+ *
+ * @return true on success, false if an error occured.
+ */
+bool samba_cmdline_set_creds(struct cli_credentials *creds);
+
 #endif /* _CMDLINE_PRIVATE_H */
index b95e917ab362535e0f34feb121c617be64aca562..5dcf1ef8e125b22a24f8f38af848dd423bfd59f0 100644 (file)
@@ -21,6 +21,7 @@
 #include "lib/util/debug.h"
 #include "lib/util/fault.h"
 #include "source3/param/loadparm.h"
+#include "auth/credentials/credentials.h"
 #include "cmdline_private.h"
 
 static bool _require_smbconf;
@@ -28,6 +29,7 @@ static bool _require_smbconf;
 bool samba_cmdline_init(TALLOC_CTX *mem_ctx, bool require_smbconf)
 {
        struct loadparm_context *lp_ctx = NULL;
+       struct cli_credentials *creds = NULL;
        bool ok;
 
        ok = samba_cmdline_init_common(mem_ctx);
@@ -46,5 +48,14 @@ bool samba_cmdline_init(TALLOC_CTX *mem_ctx, bool require_smbconf)
 
        _require_smbconf = require_smbconf;
 
+       creds = cli_credentials_init(mem_ctx);
+       if (creds == NULL) {
+               return false;
+       }
+       ok = samba_cmdline_set_creds(creds);
+       if (!ok) {
+               return false;
+       }
+
        return true;
 }
index 266c044301c409bbe71a7fac727b8ba1277c6f16..938a83bca58c395ae19f71f55f88d84a955b9daf 100644 (file)
@@ -20,6 +20,7 @@
 #include "lib/param/param.h"
 #include "lib/util/debug.h"
 #include "lib/util/fault.h"
+#include "auth/credentials/credentials.h"
 #include "cmdline_private.h"
 
 static bool _require_smbconf;
@@ -27,6 +28,7 @@ static bool _require_smbconf;
 bool samba_cmdline_init(TALLOC_CTX *mem_ctx, bool require_smbconf)
 {
        struct loadparm_context *lp_ctx = NULL;
+       struct cli_credentials *creds = NULL;
        bool ok;
 
        ok = samba_cmdline_init_common(mem_ctx);
@@ -45,5 +47,14 @@ bool samba_cmdline_init(TALLOC_CTX *mem_ctx, bool require_smbconf)
        }
        _require_smbconf = require_smbconf;
 
+       creds = cli_credentials_init(mem_ctx);
+       if (creds == NULL) {
+               return false;
+       }
+       ok = samba_cmdline_set_creds(creds);
+       if (!ok) {
+               return false;
+       }
+
        return true;
 }
index 912c89b246fdbf03cfe8174a6f93b94aa392e8bb..87c7260ea199f51fde4cbc15d6110f58cedbf9f2 100644 (file)
@@ -10,6 +10,7 @@ def build(bld):
                       deps='''
                            talloc
                            samba-hostconfig
+                           samba-credentials
                            popt
                            ''',
                       private_library=True)