summaryrefslogtreecommitdiff
path: root/source3/utils
diff options
context:
space:
mode:
authorGünther Deschner <gd@samba.org>2009-02-25 10:58:53 +0100
committerGünther Deschner <gd@samba.org>2009-02-25 11:16:29 +0100
commitf8af5130d5515e017330a2123b933109599e072c (patch)
treef19b15f54deb45a52bef3ee3dbb0f76feee84913 /source3/utils
parent1a77218dca0222aafff81aae6cd17462706e226e (diff)
downloadsamba-f8af5130d5515e017330a2123b933109599e072c.tar.gz
samba-f8af5130d5515e017330a2123b933109599e072c.tar.bz2
samba-f8af5130d5515e017330a2123b933109599e072c.zip
s3-net: use rpccli_spoolss_getprinter and rpccli_spoolss_SetPrinter.
Guenther
Diffstat (limited to 'source3/utils')
-rw-r--r--source3/utils/net_rpc_printer.c169
1 files changed, 123 insertions, 46 deletions
diff --git a/source3/utils/net_rpc_printer.c b/source3/utils/net_rpc_printer.c
index 17df69597f..0f21e1758b 100644
--- a/source3/utils/net_rpc_printer.c
+++ b/source3/utils/net_rpc_printer.c
@@ -775,13 +775,16 @@ static bool net_spoolss_getprinter(struct rpc_pipe_client *pipe_hnd,
TALLOC_CTX *mem_ctx,
POLICY_HND *hnd,
uint32 level,
- PRINTER_INFO_CTR *ctr)
+ union spoolss_PrinterInfo *info)
{
WERROR result;
/* getprinter call */
- result = rpccli_spoolss_getprinter(pipe_hnd, mem_ctx, hnd, level, ctr);
-
+ result = rpccli_spoolss_getprinter(pipe_hnd, mem_ctx,
+ hnd,
+ level,
+ 0, /* offered */
+ info);
if (!W_ERROR_IS_OK(result)) {
printf("cannot get printer-info: %s\n", win_errstr(result));
return false;
@@ -794,12 +797,64 @@ static bool net_spoolss_setprinter(struct rpc_pipe_client *pipe_hnd,
TALLOC_CTX *mem_ctx,
POLICY_HND *hnd,
uint32 level,
- PRINTER_INFO_CTR *ctr)
+ union spoolss_PrinterInfo *info)
{
WERROR result;
+ NTSTATUS status;
+ struct spoolss_SetPrinterInfoCtr info_ctr;
+ struct spoolss_DevmodeContainer devmode_ctr;
+ struct sec_desc_buf secdesc_ctr;
+
+ ZERO_STRUCT(devmode_ctr);
+ ZERO_STRUCT(secdesc_ctr);
/* setprinter call */
- result = rpccli_spoolss_setprinter(pipe_hnd, mem_ctx, hnd, level, ctr, 0);
+
+ info_ctr.level = level;
+ switch (level) {
+ case 0:
+ info_ctr.info.info0 = (struct spoolss_SetPrinterInfo0 *)&info->info0;
+ break;
+ case 1:
+ info_ctr.info.info1 = (struct spoolss_SetPrinterInfo1 *)&info->info1;
+ break;
+ case 2:
+ info_ctr.info.info2 = (struct spoolss_SetPrinterInfo2 *)&info->info2;
+ break;
+ case 3:
+ info_ctr.info.info3 = (struct spoolss_SetPrinterInfo3 *)&info->info3;
+ break;
+ case 4:
+ info_ctr.info.info4 = (struct spoolss_SetPrinterInfo4 *)&info->info4;
+ break;
+ case 5:
+ info_ctr.info.info5 = (struct spoolss_SetPrinterInfo5 *)&info->info5;
+ break;
+ case 6:
+ info_ctr.info.info6 = (struct spoolss_SetPrinterInfo6 *)&info->info6;
+ break;
+ case 7:
+ info_ctr.info.info7 = (struct spoolss_SetPrinterInfo7 *)&info->info7;
+ break;
+#if 0 /* FIXME GD */
+ case 8:
+ info_ctr.info.info8 = (struct spoolss_SetPrinterInfo8 *)&info->info8;
+ break;
+ case 9:
+ info_ctr.info.info9 = (struct spoolss_SetPrinterInfo9 *)&info->info9;
+ break;
+#endif
+ default:
+ break; /* FIXME */
+ }
+
+ status = rpccli_spoolss_SetPrinter(pipe_hnd, mem_ctx,
+ hnd,
+ &info_ctr,
+ &devmode_ctr,
+ &secdesc_ctr,
+ 0, /* command */
+ &result);
if (!W_ERROR_IS_OK(result)) {
printf("cannot set printer-info: %s\n", win_errstr(result));
@@ -1027,6 +1082,7 @@ static bool get_printer_info(struct rpc_pipe_client *pipe_hnd,
{
POLICY_HND hnd;
+ union spoolss_PrinterInfo info;
/* no arguments given, enumerate all printers */
if (argc == 0) {
@@ -1039,6 +1095,8 @@ static bool get_printer_info(struct rpc_pipe_client *pipe_hnd,
goto out;
}
+ /* FIXME GD */
+ return false;
/* argument given, get a single printer by name */
if (!net_spoolss_open_printer_ex(pipe_hnd, mem_ctx, argv[0],
@@ -1047,7 +1105,7 @@ static bool get_printer_info(struct rpc_pipe_client *pipe_hnd,
&hnd))
return false;
- if (!net_spoolss_getprinter(pipe_hnd, mem_ctx, &hnd, level, ctr)) {
+ if (!net_spoolss_getprinter(pipe_hnd, mem_ctx, &hnd, level, &info)) {
rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd, NULL);
return false;
}
@@ -1216,7 +1274,11 @@ static NTSTATUS rpc_printer_publish_internals_args(struct rpc_pipe_client *pipe_
uint32 i, num_printers;
uint32 level = 7;
char *printername, *sharename;
- PRINTER_INFO_CTR ctr, ctr_pub;
+ PRINTER_INFO_CTR ctr;
+ union spoolss_PrinterInfo info;
+ struct spoolss_SetPrinterInfoCtr info_ctr;
+ struct spoolss_DevmodeContainer devmode_ctr;
+ struct sec_desc_buf secdesc_ctr;
POLICY_HND hnd;
bool got_hnd = false;
WERROR result;
@@ -1249,7 +1311,7 @@ static NTSTATUS rpc_printer_publish_internals_args(struct rpc_pipe_client *pipe_
got_hnd = true;
/* check for existing dst printer */
- if (!net_spoolss_getprinter(pipe_hnd, mem_ctx, &hnd, level, &ctr_pub))
+ if (!net_spoolss_getprinter(pipe_hnd, mem_ctx, &hnd, level, &info))
goto done;
/* check action and set string */
@@ -1269,9 +1331,21 @@ static NTSTATUS rpc_printer_publish_internals_args(struct rpc_pipe_client *pipe_
break;
}
- ctr_pub.printers_7->action = action;
+ info.info7.action = action;
+ info_ctr.level = 7;
+ info_ctr.info.info7 = (struct spoolss_SetPrinterInfo7 *)&info.info7;
+
+ ZERO_STRUCT(devmode_ctr);
+ ZERO_STRUCT(secdesc_ctr);
+
+ nt_status = rpccli_spoolss_SetPrinter(pipe_hnd, mem_ctx,
+ &hnd,
+ &info_ctr,
+ &devmode_ctr,
+ &secdesc_ctr,
+ 0, /* command */
+ &result);
- result = rpccli_spoolss_setprinter(pipe_hnd, mem_ctx, &hnd, level, &ctr_pub, 0);
if (!W_ERROR_IS_OK(result) && (W_ERROR_V(result) != W_ERROR_V(WERR_IO_PENDING))) {
printf("cannot set printer-info: %s\n", win_errstr(result));
goto done;
@@ -1355,8 +1429,8 @@ NTSTATUS rpc_printer_publish_list_internals(struct net_context *c,
uint32 i, num_printers;
uint32 level = 7;
char *printername, *sharename;
- char *guid;
PRINTER_INFO_CTR ctr, ctr_pub;
+ union spoolss_PrinterInfo info;
POLICY_HND hnd;
bool got_hnd = false;
int state;
@@ -1390,23 +1464,18 @@ NTSTATUS rpc_printer_publish_list_internals(struct net_context *c,
got_hnd = true;
/* check for existing dst printer */
- if (!net_spoolss_getprinter(pipe_hnd, mem_ctx, &hnd, level, &ctr_pub))
+ if (!net_spoolss_getprinter(pipe_hnd, mem_ctx, &hnd, level, &info))
goto done;
- rpcstr_pull_talloc(mem_ctx,
- &guid,
- ctr_pub.printers_7->guid.buffer,
- -1,
- STR_TERMINATE);
- if (!guid) {
+ if (!info.info7.guid) {
goto done;
}
- state = ctr_pub.printers_7->action;
+ state = info.info7.action;
switch (state) {
case SPOOL_DS_PUBLISH:
printf("printer [%s] is published", sharename);
if (c->opt_verbose)
- printf(", guid: %s", guid);
+ printf(", guid: %s", info.info7.guid);
printf("\n");
break;
case SPOOL_DS_UNPUBLISH:
@@ -1468,8 +1537,9 @@ NTSTATUS rpc_printer_migrate_security_internals(struct net_context *c,
bool got_hnd_dst = false;
struct rpc_pipe_client *pipe_hnd_dst = NULL;
POLICY_HND hnd_src, hnd_dst;
- PRINTER_INFO_CTR ctr_src, ctr_dst, ctr_enum;
+ PRINTER_INFO_CTR ctr_src, ctr_enum;
struct cli_state *cli_dst = NULL;
+ union spoolss_PrinterInfo info_src, info_dst;
ZERO_STRUCT(ctr_src);
@@ -1540,23 +1610,23 @@ NTSTATUS rpc_printer_migrate_security_internals(struct net_context *c,
got_hnd_dst = true;
/* check for existing dst printer */
- if (!net_spoolss_getprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, level, &ctr_dst))
+ if (!net_spoolss_getprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, level, &info_dst))
goto done;
/* check for existing src printer */
- if (!net_spoolss_getprinter(pipe_hnd, mem_ctx, &hnd_src, 3, &ctr_src))
+ if (!net_spoolss_getprinter(pipe_hnd, mem_ctx, &hnd_src, 3, &info_src))
goto done;
/* Copy Security Descriptor */
/* copy secdesc (info level 2) */
- ctr_dst.printers_2->devmode = NULL;
- ctr_dst.printers_2->secdesc = dup_sec_desc(mem_ctx, ctr_src.printers_3->secdesc);
+ info_dst.info2.devmode = NULL;
+ info_dst.info2.secdesc = dup_sec_desc(mem_ctx, info_src.info3.secdesc);
if (c->opt_verbose)
- display_sec_desc(ctr_dst.printers_2->secdesc);
+ display_sec_desc(info_dst.info2.secdesc);
- if (!net_spoolss_setprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, 2, &ctr_dst))
+ if (!net_spoolss_setprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, 2, &info_dst))
goto done;
DEBUGADD(1,("\tSetPrinter of SECDESC succeeded\n"));
@@ -1629,7 +1699,8 @@ NTSTATUS rpc_printer_migrate_forms_internals(struct net_context *c,
bool got_hnd_dst = false;
struct rpc_pipe_client *pipe_hnd_dst = NULL;
POLICY_HND hnd_src, hnd_dst;
- PRINTER_INFO_CTR ctr_enum, ctr_dst;
+ PRINTER_INFO_CTR ctr_enum;
+ union spoolss_PrinterInfo info_dst;
uint32 num_forms;
FORM_1 *forms;
struct cli_state *cli_dst = NULL;
@@ -1698,7 +1769,7 @@ NTSTATUS rpc_printer_migrate_forms_internals(struct net_context *c,
/* check for existing dst printer */
- if (!net_spoolss_getprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, level, &ctr_dst))
+ if (!net_spoolss_getprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, level, &info_dst))
goto done;
/* finally migrate forms */
@@ -1824,6 +1895,7 @@ NTSTATUS rpc_printer_migrate_drivers_internals(struct net_context *c,
POLICY_HND hnd_src, hnd_dst;
union spoolss_DriverInfo drv_info_src;
PRINTER_INFO_CTR info_ctr_enum, info_ctr_dst;
+ union spoolss_PrinterInfo info_dst;
struct cli_state *cli_dst = NULL;
struct cli_state *cli_share_src = NULL;
struct cli_state *cli_share_dst = NULL;
@@ -1903,7 +1975,7 @@ NTSTATUS rpc_printer_migrate_drivers_internals(struct net_context *c,
got_hnd_dst = true;
/* check for existing dst printer */
- if (!net_spoolss_getprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, 2, &info_ctr_dst))
+ if (!net_spoolss_getprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, 2, &info_dst))
goto done;
@@ -1965,9 +2037,9 @@ NTSTATUS rpc_printer_migrate_drivers_internals(struct net_context *c,
}
/* setdriver dst */
- init_unistr(&info_ctr_dst.printers_2->drivername, drivername);
+ info_dst.info2.drivername = drivername;
- if (!net_spoolss_setprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, 2, &info_ctr_dst)) {
+ if (!net_spoolss_setprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, 2, &info_dst)) {
nt_status = NT_STATUS_UNSUCCESSFUL;
goto done;
}
@@ -2043,7 +2115,8 @@ NTSTATUS rpc_printer_migrate_printers_internals(struct net_context *c,
NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
uint32 i = 0, num_printers;
uint32 level = 2;
- PRINTER_INFO_CTR ctr_src, ctr_dst, ctr_enum;
+ PRINTER_INFO_CTR ctr_enum;
+ union spoolss_PrinterInfo info_dst, info_src;
struct cli_state *cli_dst = NULL;
POLICY_HND hnd_dst, hnd_src;
char *printername, *sharename;
@@ -2105,7 +2178,7 @@ NTSTATUS rpc_printer_migrate_printers_internals(struct net_context *c,
}
/* check for existing dst printer */
- if (!net_spoolss_getprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, level, &ctr_dst)) {
+ if (!net_spoolss_getprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, level, &info_dst)) {
printf ("could not get printer, creating printer.\n");
} else {
DEBUG(1,("printer already exists: %s\n", sharename));
@@ -2128,7 +2201,7 @@ NTSTATUS rpc_printer_migrate_printers_internals(struct net_context *c,
got_hnd_src = true;
/* getprinter on the src server */
- if (!net_spoolss_getprinter(pipe_hnd, mem_ctx, &hnd_src, level, &ctr_src))
+ if (!net_spoolss_getprinter(pipe_hnd, mem_ctx, &hnd_src, level, &info_src))
goto done;
/* copy each src printer to a dst printer 1:1,
@@ -2212,7 +2285,8 @@ NTSTATUS rpc_printer_migrate_settings_internals(struct net_context *c,
bool got_hnd_dst = false;
struct rpc_pipe_client *pipe_hnd_dst = NULL;
POLICY_HND hnd_src, hnd_dst;
- PRINTER_INFO_CTR ctr_enum, ctr_dst, ctr_dst_publish;
+ PRINTER_INFO_CTR ctr_enum;
+ union spoolss_PrinterInfo info_dst_publish, info_dst;
REGVAL_CTR *reg_ctr;
struct cli_state *cli_dst = NULL;
char *devicename = NULL, *unc_name = NULL, *url = NULL;
@@ -2221,6 +2295,8 @@ NTSTATUS rpc_printer_migrate_settings_internals(struct net_context *c,
uint16 *keylist = NULL, *curkey;
ZERO_STRUCT(ctr_enum);
+ /* FIXME GD */
+ ZERO_STRUCT(info_dst_publish);
DEBUG(3,("copying printer settings\n"));
@@ -2293,31 +2369,32 @@ NTSTATUS rpc_printer_migrate_settings_internals(struct net_context *c,
/* check for existing dst printer */
if (!net_spoolss_getprinter(pipe_hnd_dst, mem_ctx, &hnd_dst,
- level, &ctr_dst))
+ level, &info_dst))
goto done;
+#if 0 /* FIXME GD */
/* STEP 1: COPY DEVICE-MODE and other
PRINTER_INFO_2-attributes
*/
- ctr_dst.printers_2 = &ctr_enum.printers_2[i];
+ info_dst.info2 = &ctr_enum.printers_2[i];
/* why is the port always disconnected when the printer
is correctly installed (incl. driver ???) */
- init_unistr( &ctr_dst.printers_2->portname, SAMBA_PRINTER_PORT_NAME);
+ info_dst.info2.portname = SAMBA_PRINTER_PORT_NAME;
/* check if printer is published */
if (ctr_enum.printers_2[i].attributes & PRINTER_ATTRIBUTE_PUBLISHED) {
/* check for existing dst printer */
- if (!net_spoolss_getprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, 7, &ctr_dst_publish))
+ if (!net_spoolss_getprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, 7, &info_dst_publish))
goto done;
- ctr_dst_publish.printers_7->action = SPOOL_DS_PUBLISH;
+ info_dst_publish.info7.action = SPOOL_DS_PUBLISH;
/* ignore false from setprinter due to WERR_IO_PENDING */
- net_spoolss_setprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, 7, &ctr_dst_publish);
+ net_spoolss_setprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, 7, &info_dst_publish);
DEBUG(3,("republished printer\n"));
}
@@ -2325,14 +2402,14 @@ NTSTATUS rpc_printer_migrate_settings_internals(struct net_context *c,
if (ctr_enum.printers_2[i].devmode != NULL) {
/* copy devmode (info level 2) */
- ctr_dst.printers_2->devmode = (DEVICEMODE *)
+ info_dst.info2.devmode = (DEVICEMODE *)
TALLOC_MEMDUP(mem_ctx,
ctr_enum.printers_2[i].devmode,
sizeof(DEVICEMODE));
/* do not copy security descriptor (we have another
* command for that) */
- ctr_dst.printers_2->secdesc = NULL;
+ info_dst.info2.secdesc = NULL;
#if 0
if (asprintf(&devicename, "\\\\%s\\%s", longname,
@@ -2345,12 +2422,12 @@ NTSTATUS rpc_printer_migrate_settings_internals(struct net_context *c,
devicename);
#endif
if (!net_spoolss_setprinter(pipe_hnd_dst, mem_ctx, &hnd_dst,
- level, &ctr_dst))
+ level, &info_dst))
goto done;
DEBUGADD(1,("\tSetPrinter of DEVICEMODE succeeded\n"));
}
-
+#endif
/* STEP 2: COPY REGISTRY VALUES */
/* please keep in mind that samba parse_spools gives horribly