diff options
author | Tim Potter <tpot@samba.org> | 2002-01-06 03:54:40 +0000 |
---|---|---|
committer | Tim Potter <tpot@samba.org> | 2002-01-06 03:54:40 +0000 |
commit | cd0772e51e0c5344fdeba70f8dc5b227854910df (patch) | |
tree | fde340dc79d8d3c31cd3b11aef4d375e9a605007 /source3 | |
parent | 009d7414d2f4dfbc681d3bcfadbe4e8fee6df62d (diff) | |
download | samba-cd0772e51e0c5344fdeba70f8dc5b227854910df.tar.gz samba-cd0772e51e0c5344fdeba70f8dc5b227854910df.tar.bz2 samba-cd0772e51e0c5344fdeba70f8dc5b227854910df.zip |
spoolss rpc client cleanup:
- converted OpenPrinterEx and ClosePrinter to WERROR instead of NT_STATUS
- doc
(This used to be commit 248d114f856f1adb76c903b683e0927530771443)
Diffstat (limited to 'source3')
-rw-r--r-- | source3/libsmb/cli_spoolss.c | 116 | ||||
-rw-r--r-- | source3/rpcclient/cmd_spoolss.c | 97 |
2 files changed, 122 insertions, 91 deletions
diff --git a/source3/libsmb/cli_spoolss.c b/source3/libsmb/cli_spoolss.c index e6a6bf5258..ceb82ef3ec 100644 --- a/source3/libsmb/cli_spoolss.c +++ b/source3/libsmb/cli_spoolss.c @@ -1,13 +1,12 @@ /* Unix SMB/Netbios implementation. - Version 2.2 RPC pipe client Copyright (C) Gerald Carter 2001, - Copyright (C) Tim Potter 2000, - Copyright (C) Andrew Tridgell 1994-2000 - Copyright (C) Luke Kenneth Casson Leighton 1996-2000 - Copyright (C) Jean-Francois Micouleau 1999-2000 + Copyright (C) Tim Potter 2000-2001, + Copyright (C) Andrew Tridgell 1994-2000, + Copyright (C) Luke Kenneth Casson Leighton 1996-2000, + Copyright (C) Jean-Francois Micouleau 1999-2000. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -26,33 +25,43 @@ #include "includes.h" -extern pstring global_myname; +/** @defgroup spoolss SPOOLSS - NT printing routines + * @ingroup rpc_client + * + * @{ + **/ + +/** Return a handle to the specified printer or print server. + * + * @param cli Pointer to client state structure which is open + * on the SPOOLSS pipe. + * + * @param mem_ctx Pointer to an initialised talloc context. + * + * @param printername The name of the printer or print server to be + * opened in UNC format. + * + * @param datatype Specifies the default data type for the printer. + * + * @param access_required The access rights requested on the printer or + * print server. + * + * @param station The UNC name of the requesting workstation. + * + * @param username The name of the user requesting the open. + * + * @param pol Returned policy handle. + */ -/* Opens a SMB connection to the SPOOLSS pipe */ -struct cli_state *cli_spoolss_initialise(struct cli_state *cli, - char *system_name, - struct ntuser_creds *creds) -{ - return cli_pipe_initialise(cli, system_name, PIPE_SPOOLSS, creds); -} - -/* Open printer ex */ - -NTSTATUS cli_spoolss_open_printer_ex( - struct cli_state *cli, - TALLOC_CTX *mem_ctx, - char *printername, - char *datatype, - uint32 access_required, - char *station, - char *username, - POLICY_HND *pol -) +WERROR cli_spoolss_open_printer_ex(struct cli_state *cli, TALLOC_CTX *mem_ctx, + char *printername, char *datatype, + uint32 access_required, char *station, + char *username, POLICY_HND *pol) { prs_struct qbuf, rbuf; SPOOL_Q_OPEN_PRINTER_EX q; SPOOL_R_OPEN_PRINTER_EX r; - NTSTATUS result; + WERROR result = W_ERROR(ERRgeneral); ZERO_STRUCT(q); ZERO_STRUCT(r); @@ -70,26 +79,20 @@ NTSTATUS cli_spoolss_open_printer_ex( /* Marshall data and send request */ if (!spoolss_io_q_open_printer_ex("", &q, &qbuf, 0) || - !rpc_api_pipe_req(cli, SPOOLSS_OPENPRINTEREX, &qbuf, &rbuf)) { - result = NT_STATUS_UNSUCCESSFUL; + !rpc_api_pipe_req(cli, SPOOLSS_OPENPRINTEREX, &qbuf, &rbuf)) goto done; - } /* Unmarshall response */ - if (!spoolss_io_r_open_printer_ex("", &r, &rbuf, 0)) { - result = NT_STATUS_UNSUCCESSFUL; + if (!spoolss_io_r_open_printer_ex("", &r, &rbuf, 0)) goto done; - } /* Return output parameters */ - if (W_ERROR_IS_OK(r.status)) { - result = NT_STATUS_OK; + result = r.status; + + if (W_ERROR_IS_OK(result)) *pol = r.handle; - } else { - result = werror_to_ntstatus(r.status); - } done: prs_mem_free(&qbuf); @@ -98,18 +101,23 @@ NTSTATUS cli_spoolss_open_printer_ex( return result; } -/* Close a printer handle */ +/** Close a printer handle + * + * @param cli Pointer to client state structure which is open + * on the SPOOLSS pipe. + * + * @param mem_ctx Pointer to an initialised talloc context. + * + * @param pol Policy handle of printer or print server to close. + */ -NTSTATUS cli_spoolss_close_printer( - struct cli_state *cli, - TALLOC_CTX *mem_ctx, - POLICY_HND *pol -) +WERROR cli_spoolss_close_printer(struct cli_state *cli, TALLOC_CTX *mem_ctx, + POLICY_HND *pol) { prs_struct qbuf, rbuf; SPOOL_Q_CLOSEPRINTER q; SPOOL_R_CLOSEPRINTER r; - NTSTATUS result; + WERROR result = W_ERROR(ERRgeneral); ZERO_STRUCT(q); ZERO_STRUCT(r); @@ -126,26 +134,20 @@ NTSTATUS cli_spoolss_close_printer( /* Marshall data and send request */ if (!spoolss_io_q_closeprinter("", &q, &qbuf, 0) || - !rpc_api_pipe_req(cli, SPOOLSS_CLOSEPRINTER, &qbuf, &rbuf)) { - result = NT_STATUS_UNSUCCESSFUL; + !rpc_api_pipe_req(cli, SPOOLSS_CLOSEPRINTER, &qbuf, &rbuf)) goto done; - } /* Unmarshall response */ - if (!spoolss_io_r_closeprinter("", &r, &rbuf, 0)) { - result = NT_STATUS_UNSUCCESSFUL; + if (!spoolss_io_r_closeprinter("", &r, &rbuf, 0)) goto done; - } /* Return output parameters */ - if (W_ERROR_IS_OK(r.status)) { + result = r.status; + + if (W_ERROR_IS_OK(result)) *pol = r.handle; - result = NT_STATUS_OK; - } else { - result = werror_to_ntstatus(r.status); - } done: prs_mem_free(&qbuf); @@ -1134,3 +1136,5 @@ NTSTATUS cli_spoolss_getprintprocessordirectory(struct cli_state *cli, return result; } + +/** @} **/ diff --git a/source3/rpcclient/cmd_spoolss.c b/source3/rpcclient/cmd_spoolss.c index a654737d2b..7daa336cc6 100644 --- a/source3/rpcclient/cmd_spoolss.c +++ b/source3/rpcclient/cmd_spoolss.c @@ -89,7 +89,7 @@ static NTSTATUS cmd_spoolss_open_printer_ex(struct cli_state *cli, TALLOC_CTX *mem_ctx, int argc, char **argv) { - NTSTATUS result = NT_STATUS_UNSUCCESSFUL; + WERROR werror; pstring printername; fstring servername, user; POLICY_HND hnd; @@ -108,18 +108,22 @@ static NTSTATUS cmd_spoolss_open_printer_ex(struct cli_state *cli, fstrcpy (printername, argv[1]); /* Open the printer handle */ - result = cli_spoolss_open_printer_ex (cli, mem_ctx, printername, "", - MAXIMUM_ALLOWED_ACCESS, servername, user, &hnd); - if (NT_STATUS_IS_OK(result)) { - printf ("Printer %s opened successfully\n", printername); - result = cli_spoolss_close_printer (cli, mem_ctx, &hnd); - if (!NT_STATUS_IS_OK(result)) { - printf ("Error closing printer handle! (%s)\n", get_nt_error_msg(result)); + werror = cli_spoolss_open_printer_ex(cli, mem_ctx, printername, + "", MAXIMUM_ALLOWED_ACCESS, + servername, user, &hnd); + + if (W_ERROR_IS_OK(werror)) { + printf("Printer %s opened successfully\n", printername); + werror = cli_spoolss_close_printer(cli, mem_ctx, &hnd); + + if (!W_ERROR_IS_OK(werror)) { + printf("Error closing printer handle! (%s)\n", + get_dos_error_msg(werror)); } } - return result; + return werror_to_ntstatus(werror); } @@ -436,6 +440,7 @@ static NTSTATUS cmd_spoolss_getprinter(struct cli_state *cli, int argc, char **argv) { POLICY_HND pol; + WERROR werror; NTSTATUS result; uint32 info_level = 1; BOOL opened_hnd = False; @@ -460,20 +465,24 @@ static NTSTATUS cmd_spoolss_getprinter(struct cli_state *cli, fstrcpy (user, cli->user_name); /* get a printer handle */ - result = cli_spoolss_open_printer_ex( - cli, mem_ctx, printername, "", MAXIMUM_ALLOWED_ACCESS, servername, - user, &pol); - if (!NT_STATUS_IS_OK(result)) { + + werror = cli_spoolss_open_printer_ex(cli, mem_ctx, printername, + "", MAXIMUM_ALLOWED_ACCESS, + servername, user, &pol); + + result = werror_to_ntstatus(werror); + + if (!NT_STATUS_IS_OK(result)) goto done; - } opened_hnd = True; /* Get printer info */ + result = cli_spoolss_getprinter(cli, mem_ctx, &pol, info_level, &ctr); - if (!NT_STATUS_IS_OK(result)) { + + if (!NT_STATUS_IS_OK(result)) goto done; - } /* Display printer info */ @@ -620,6 +629,7 @@ static NTSTATUS cmd_spoolss_getdriver(struct cli_state *cli, int argc, char **argv) { POLICY_HND pol; + WERROR werror; NTSTATUS result; uint32 info_level = 3; BOOL opened_hnd = False; @@ -644,10 +654,15 @@ static NTSTATUS cmd_spoolss_getdriver(struct cli_state *cli, info_level = atoi(argv[2]); /* Open a printer handle */ - result=cli_spoolss_open_printer_ex (cli, mem_ctx, printername, "", - MAXIMUM_ALLOWED_ACCESS, servername, user, &pol); + + werror = cli_spoolss_open_printer_ex(cli, mem_ctx, printername, "", + MAXIMUM_ALLOWED_ACCESS, + servername, user, &pol); + + result = werror_to_ntstatus(werror); + if (!NT_STATUS_IS_OK(result)) { - printf ("Error opening printer handle for %s!\n", printername); + printf("Error opening printer handle for %s!\n", printername); return result; } @@ -682,12 +697,12 @@ static NTSTATUS cmd_spoolss_getdriver(struct cli_state *cli, } } - /* cleanup */ + /* Cleanup */ + if (opened_hnd) cli_spoolss_close_printer (cli, mem_ctx, &pol); return result; - } /*********************************************************************** @@ -1036,7 +1051,8 @@ static NTSTATUS cmd_spoolss_setdriver(struct cli_state *cli, int argc, char **argv) { POLICY_HND pol; - NTSTATUS result; + WERROR result; + NTSTATUS nt_status; uint32 level = 2; BOOL opened_hnd = False; PRINTER_INFO_CTR ctr; @@ -1057,40 +1073,51 @@ static NTSTATUS cmd_spoolss_setdriver(struct cli_state *cli, slprintf (printername, sizeof(fstring)-1, "%s\\%s", servername, argv[1]); fstrcpy (user, cli->user_name); - /* get a printer handle */ + /* Get a printer handle */ + result = cli_spoolss_open_printer_ex(cli, mem_ctx, printername, "", - MAXIMUM_ALLOWED_ACCESS, servername, user, &pol); - if (!NT_STATUS_IS_OK(result)) { + MAXIMUM_ALLOWED_ACCESS, + servername, user, &pol); + + nt_status = werror_to_ntstatus(result); + + if (!NT_STATUS_IS_OK(nt_status)) goto done; - } opened_hnd = True; /* Get printer info */ + ZERO_STRUCT (info2); ctr.printers_2 = &info2; - result = cli_spoolss_getprinter(cli, mem_ctx, &pol, level, &ctr); - if (!NT_STATUS_IS_OK(result)) { + + nt_status = cli_spoolss_getprinter(cli, mem_ctx, &pol, level, &ctr); + + if (!NT_STATUS_IS_OK(nt_status)) { printf ("Unable to retrieve printer information!\n"); goto done; } - /* set the printer driver */ + /* Set the printer driver */ + init_unistr(&ctr.printers_2->drivername, argv[2]); - result = cli_spoolss_setprinter(cli, mem_ctx, &pol, level, &ctr, 0); - if (!NT_STATUS_IS_OK(result)) { - printf ("SetPrinter call failed!\n"); + + nt_status = cli_spoolss_setprinter(cli, mem_ctx, &pol, level, &ctr, 0); + + if (!NT_STATUS_IS_OK(nt_status)) { + printf("SetPrinter call failed!\n"); goto done;; } - printf ("Succesfully set %s to driver %s.\n", argv[1], argv[2]); + printf("Succesfully set %s to driver %s.\n", argv[1], argv[2]); done: - /* cleanup */ + /* Cleanup */ + if (opened_hnd) cli_spoolss_close_printer(cli, mem_ctx, &pol); - return result; + return nt_status; } |