From: Stefan Metzmacher Date: Thu, 19 Sep 2024 04:27:22 +0000 (+0200) Subject: s3:rpc_client: remember rpc_pipe_client->print_username X-Git-Tag: samba-4.21.7~33 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2f753ed81ce8c3b077d02fbcc82dfb165a4403f5;p=thirdparty%2Fsamba.git s3:rpc_client: remember rpc_pipe_client->print_username 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 Reviewed-by: Ralph Boehme (cherry picked from commit 344e45507e122137c357fc177bb024f09fff8b01) --- diff --git a/source3/rpc_client/cli_pipe.c b/source3/rpc_client/cli_pipe.c index 9e9b9fe38b2..44e84dc6230 100644 --- a/source3/rpc_client/cli_pipe.c +++ b/source3/rpc_client/cli_pipe.c @@ -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, diff --git a/source3/rpc_client/cli_spoolss.c b/source3/rpc_client/cli_spoolss.c index 094381c4fba..62747d8c640 100644 --- a/source3/rpc_client/cli_spoolss.c +++ b/source3/rpc_client/cli_spoolss.c @@ -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; diff --git a/source3/rpc_client/rpc_client.h b/source3/rpc_client/rpc_client.h index b2f02b01b3d..b1c3db52451 100644 --- a/source3/rpc_client/rpc_client.h +++ b/source3/rpc_client/rpc_client.h @@ -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; diff --git a/source3/rpcclient/cmd_iremotewinspool.c b/source3/rpcclient/cmd_iremotewinspool.c index 5a8096b6d97..7162605696f 100644 --- a/source3/rpcclient/cmd_iremotewinspool.c +++ b/source3/rpcclient/cmd_iremotewinspool.c @@ -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 [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; diff --git a/source3/utils/net_rpc_printer.c b/source3/utils/net_rpc_printer.c index f72203f688f..5434c5628f5 100644 --- a/source3/utils/net_rpc_printer.c +++ b/source3/utils/net_rpc_printer.c @@ -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;