auth:creds: Add cli_credentials_init_server()
authorAndreas Schneider <asn@samba.org>
Fri, 4 Sep 2020 10:21:21 +0000 (12:21 +0200)
committerStefan Metzmacher <metze@samba.org>
Mon, 7 Sep 2020 12:02:15 +0000 (12:02 +0000)
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
auth/credentials/credentials.c
auth/credentials/credentials.h

index 9168b92d3ecc4da4d65360cfdda21f384ee4fcbe..77c35dd104b593113bcc58a9841e48bd54018c2f 100644 (file)
@@ -56,6 +56,31 @@ _PUBLIC_ struct cli_credentials *cli_credentials_init(TALLOC_CTX *mem_ctx)
        return cred;
 }
 
+_PUBLIC_
+struct cli_credentials *cli_credentials_init_server(TALLOC_CTX *mem_ctx,
+                                                   struct loadparm_context *lp_ctx)
+{
+       struct cli_credentials *server_creds = NULL;
+       NTSTATUS status;
+
+       server_creds = cli_credentials_init(mem_ctx);
+       if (server_creds == NULL) {
+               return NULL;
+       }
+
+       cli_credentials_set_conf(server_creds, lp_ctx);
+
+       status = cli_credentials_set_machine_account(server_creds, lp_ctx);
+       if (!NT_STATUS_IS_OK(status)) {
+               DEBUG(1, ("Failed to obtain server credentials: %s\n",
+                         nt_errstr(status)));
+               TALLOC_FREE(server_creds);
+               return NULL;
+       }
+
+       return server_creds;
+}
+
 _PUBLIC_ void cli_credentials_set_callback_data(struct cli_credentials *cred,
                                                void *callback_data)
 {
index 1a3e611fee84ae0e59879dae19e47783023ed192..4c1406157513861afc8a06e0355462681c1f4ee6 100644 (file)
@@ -76,6 +76,8 @@ bool cli_credentials_set_workstation(struct cli_credentials *cred,
                                     enum credentials_obtained obtained);
 bool cli_credentials_is_anonymous(struct cli_credentials *cred);
 struct cli_credentials *cli_credentials_init(TALLOC_CTX *mem_ctx);
+struct cli_credentials *cli_credentials_init_server(TALLOC_CTX *mem_ctx,
+                                                   struct loadparm_context *lp_ctx);
 void cli_credentials_set_anonymous(struct cli_credentials *cred);
 bool cli_credentials_wrong_password(struct cli_credentials *cred);
 const char *cli_credentials_get_password(struct cli_credentials *cred);