]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3:rpc_client: remember rpc_pipe_client->print_username
authorStefan Metzmacher <metze@samba.org>
Thu, 19 Sep 2024 04:27:22 +0000 (06:27 +0200)
committerJule Anger <janger@samba.org>
Thu, 12 Jun 2025 11:27:15 +0000 (11:27 +0000)
This is ugly, but it's less ugly than doing it deep
inside of cli_spoolss.c and other code.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
(cherry picked from commit 344e45507e122137c357fc177bb024f09fff8b01)

source3/rpc_client/cli_pipe.c
source3/rpc_client/cli_spoolss.c
source3/rpc_client/rpc_client.h
source3/rpcclient/cmd_iremotewinspool.c
source3/utils/net_rpc_printer.c

index 9e9b9fe38b2c8083dd299c29958093b56ea7a33b..44e84dc62307b312e6fe312046c2f36f13abbfae 100644 (file)
@@ -1807,6 +1807,8 @@ struct tevent_req *rpc_pipe_bind_send(TALLOC_CTX *mem_ctx,
 {
        struct tevent_req *req, *subreq;
        struct rpc_pipe_bind_state *state;
+       struct cli_credentials *creds = NULL;
+       const char *username = NULL;
        NTSTATUS status;
 
        req = tevent_req_create(mem_ctx, &state, struct rpc_pipe_bind_state);
@@ -1827,6 +1829,13 @@ struct tevent_req *rpc_pipe_bind_send(TALLOC_CTX *mem_ctx,
 
        cli->auth = talloc_move(cli, &auth);
 
+       creds = gensec_get_credentials(cli->auth->auth_ctx);
+       username = cli_credentials_get_username(creds);
+       cli->printer_username = talloc_strdup(cli, username);
+       if (tevent_req_nomem(cli->printer_username, req)) {
+               return tevent_req_post(req, ev);
+       }
+
        /* Marshall the outgoing data. */
        status = create_rpc_bind_req(state, cli,
                                     cli->auth,
index 094381c4fbaa1563bd1336704d30174ed5aa15b7..62747d8c6400f22abcbdcaed7f20cdfd71aa1eec 100644 (file)
@@ -46,12 +46,11 @@ WERROR rpccli_spoolss_openprinter_ex(struct rpc_pipe_client *cli,
        struct spoolss_UserLevelCtr userlevel_ctr;
        struct spoolss_UserLevel1 level1;
        struct dcerpc_binding_handle *b = cli->binding_handle;
-       struct cli_credentials *creds = gensec_get_credentials(cli->auth->auth_ctx);
 
        ZERO_STRUCT(devmode_ctr);
 
        werror = spoolss_init_spoolss_UserLevel1(mem_ctx,
-                                                cli_credentials_get_username(creds),
+                                                cli->printer_username,
                                                 &level1);
        if (!W_ERROR_IS_OK(werror)) {
                return werror;
@@ -223,13 +222,12 @@ WERROR rpccli_spoolss_addprinterex(struct rpc_pipe_client *cli,
        struct spoolss_UserLevel1 level1;
        struct policy_handle handle;
        struct dcerpc_binding_handle *b = cli->binding_handle;
-       struct cli_credentials *creds = gensec_get_credentials(cli->auth->auth_ctx);
 
        ZERO_STRUCT(devmode_ctr);
        ZERO_STRUCT(secdesc_ctr);
 
        result = spoolss_init_spoolss_UserLevel1(mem_ctx,
-                                                cli_credentials_get_username(creds),
+                                                cli->printer_username,
                                                 &level1);
        if (!W_ERROR_IS_OK(result)) {
                return result;
index b2f02b01b3d4e7ae9638e5ef4045c429ceb62136..b1c3db5245190347bd1753cb89d08a120c7f6ee8 100644 (file)
@@ -55,6 +55,7 @@ struct rpc_pipe_client {
        struct ndr_syntax_id transfer_syntax;
        bool verified_pcontext;
 
+       char *printer_username;
        char *desthost;
        char *srv_name_slash;
 
index 5a8096b6d97cbd2835d88cb983c9f4ac764323bf..7162605696f0f155c5fb2998927ac074816b38f1 100644 (file)
@@ -43,7 +43,6 @@ static WERROR cmd_iremotewinspool_async_open_printer(struct rpc_pipe_client *cli
        struct dcerpc_binding_handle *b = cli->binding_handle;
        struct GUID uuid;
        struct winspool_AsyncOpenPrinter r;
-       struct cli_credentials *creds = gensec_get_credentials(cli->auth->auth_ctx);
 
        if (argc < 2) {
                printf("Usage: %s <printername> [access_mask]\n", argv[0]);
@@ -62,7 +61,7 @@ static WERROR cmd_iremotewinspool_async_open_printer(struct rpc_pipe_client *cli
        ZERO_STRUCT(devmode_ctr);
 
         werror = spoolss_init_spoolss_UserLevel1(mem_ctx,
-                                                cli_credentials_get_username(creds),
+                                                cli->printer_username,
                                                 &level1);
        if (!W_ERROR_IS_OK(werror)) {
                return werror;
index f72203f688f367fad63f6c463665cbc135c407da..5434c5628f5e048757e29e255047c3947b04c5bf 100644 (file)
@@ -704,8 +704,7 @@ static bool net_spoolss_open_printer_ex(struct rpc_pipe_client *pipe_hnd,
                                        uint32_t access_required,
                                        struct policy_handle *hnd)
 {
-       struct cli_credentials *creds = gensec_get_credentials(pipe_hnd->auth->auth_ctx);
-       const char *username = cli_credentials_get_username(creds);
+       const char *username = pipe_hnd->printer_username;
        WERROR result;
        fstring printername2;