diff options
Diffstat (limited to 'source3/utils/net_rpc_printer.c')
-rw-r--r-- | source3/utils/net_rpc_printer.c | 284 |
1 files changed, 83 insertions, 201 deletions
diff --git a/source3/utils/net_rpc_printer.c b/source3/utils/net_rpc_printer.c index 950ca72ed8..8a2ebfb01f 100644 --- a/source3/utils/net_rpc_printer.c +++ b/source3/utils/net_rpc_printer.c @@ -77,62 +77,6 @@ static void display_print_driver3(struct spoolss_DriverInfo3 *r) printf("\tDefaultdatatype: [%s]\n\n", r->default_datatype); } -static void display_print_driver_3(DRIVER_INFO_3 *i1) -{ - fstring name = ""; - fstring architecture = ""; - fstring driverpath = ""; - fstring datafile = ""; - fstring configfile = ""; - fstring helpfile = ""; - fstring dependentfiles = ""; - fstring monitorname = ""; - fstring defaultdatatype = ""; - - int length=0; - bool valid = true; - - if (i1 == NULL) - return; - - rpcstr_pull(name, i1->name.buffer, sizeof(name), -1, STR_TERMINATE); - rpcstr_pull(architecture, i1->architecture.buffer, sizeof(architecture), -1, STR_TERMINATE); - rpcstr_pull(driverpath, i1->driverpath.buffer, sizeof(driverpath), -1, STR_TERMINATE); - rpcstr_pull(datafile, i1->datafile.buffer, sizeof(datafile), -1, STR_TERMINATE); - rpcstr_pull(configfile, i1->configfile.buffer, sizeof(configfile), -1, STR_TERMINATE); - rpcstr_pull(helpfile, i1->helpfile.buffer, sizeof(helpfile), -1, STR_TERMINATE); - rpcstr_pull(monitorname, i1->monitorname.buffer, sizeof(monitorname), -1, STR_TERMINATE); - rpcstr_pull(defaultdatatype, i1->defaultdatatype.buffer, sizeof(defaultdatatype), -1, STR_TERMINATE); - - d_printf ("Printer Driver Info 3:\n"); - d_printf ("\tVersion: [%x]\n", i1->version); - d_printf ("\tDriver Name: [%s]\n",name); - d_printf ("\tArchitecture: [%s]\n", architecture); - d_printf ("\tDriver Path: [%s]\n", driverpath); - d_printf ("\tDatafile: [%s]\n", datafile); - d_printf ("\tConfigfile: [%s]\n", configfile); - d_printf ("\tHelpfile: [%s]\n\n", helpfile); - - while (valid) { - rpcstr_pull(dependentfiles, i1->dependentfiles+length, sizeof(dependentfiles), -1, STR_TERMINATE); - - length+=strlen(dependentfiles)+1; - - if (strlen(dependentfiles) > 0) { - d_printf ("\tDependentfiles: [%s]\n", dependentfiles); - } else { - valid = false; - } - } - - printf ("\n"); - - d_printf ("\tMonitorname: [%s]\n", monitorname); - d_printf ("\tDefaultdatatype: [%s]\n\n", defaultdatatype); - - return; -} - static void display_reg_value(const char *subkey, REGISTRY_VALUE value) { char *text; @@ -713,14 +657,19 @@ static bool net_spoolss_enum_printers(struct rpc_pipe_client *pipe_hnd, uint32 flags, uint32 level, uint32 *num_printers, - PRINTER_INFO_CTR *ctr) + union spoolss_PrinterInfo **info) { WERROR result; /* enum printers */ - result = rpccli_spoolss_enum_printers(pipe_hnd, mem_ctx, name, flags, - level, num_printers, ctr); + result = rpccli_spoolss_enumprinters(pipe_hnd, mem_ctx, + flags, + name, + level, + 0, + num_printers, + info); if (!W_ERROR_IS_OK(result)) { printf("cannot enum printers: %s\n", win_errstr(result)); return false; @@ -978,16 +927,19 @@ static bool net_spoolss_enumforms(struct rpc_pipe_client *pipe_hnd, static bool net_spoolss_enumprinterdrivers (struct rpc_pipe_client *pipe_hnd, TALLOC_CTX *mem_ctx, uint32 level, const char *env, - uint32 *num_drivers, - PRINTER_DRIVER_CTR *ctr) + uint32 *count, + union spoolss_DriverInfo **info) { WERROR result; /* enumprinterdrivers call */ - result = rpccli_spoolss_enumprinterdrivers( - pipe_hnd, mem_ctx, level, - env, num_drivers, ctr); - + result = rpccli_spoolss_enumprinterdrivers(pipe_hnd, mem_ctx, + pipe_hnd->srv_name_slash, + env, + level, + 0, + count, + info); if (!W_ERROR_IS_OK(result)) { printf("cannot enum drivers: %s\n", win_errstr(result)); return false; @@ -1082,26 +1034,21 @@ static bool get_printer_info(struct rpc_pipe_client *pipe_hnd, int argc, const char **argv, uint32 *num_printers, - PRINTER_INFO_CTR *ctr) + union spoolss_PrinterInfo **info_p) { - POLICY_HND hnd; - union spoolss_PrinterInfo info; /* no arguments given, enumerate all printers */ if (argc == 0) { if (!net_spoolss_enum_printers(pipe_hnd, mem_ctx, NULL, PRINTER_ENUM_LOCAL|PRINTER_ENUM_SHARED, - level, num_printers, ctr)) + level, num_printers, info_p)) return false; 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], MAXIMUM_ALLOWED_ACCESS, @@ -1109,7 +1056,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, &info)) { + if (!net_spoolss_getprinter(pipe_hnd, mem_ctx, &hnd, level, *info_p)) { rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd, NULL); return false; } @@ -1154,26 +1101,19 @@ NTSTATUS rpc_printer_list_internals(struct net_context *c, NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; uint32 i, num_printers; uint32 level = 2; - char *printername, *sharename; - PRINTER_INFO_CTR ctr; + const char *printername, *sharename; + union spoolss_PrinterInfo *info; printf("listing printers\n"); - if (!get_printer_info(pipe_hnd, mem_ctx, level, argc, argv, &num_printers, &ctr)) + if (!get_printer_info(pipe_hnd, mem_ctx, level, argc, argv, &num_printers, &info)) return nt_status; for (i = 0; i < num_printers; i++) { + /* do some initialization */ - rpcstr_pull_talloc(mem_ctx, - &printername, - ctr.printers_2[i].printername.buffer, - -1, - STR_TERMINATE); - rpcstr_pull_talloc(mem_ctx, - &sharename, - ctr.printers_2[i].sharename.buffer, - -1, - STR_TERMINATE); + printername = info[i].info2.printername; + sharename = info[i].info2.sharename; if (printername && sharename) { d_printf("printer %d: %s, shared as: %s\n", @@ -1213,11 +1153,9 @@ NTSTATUS rpc_printer_driver_list_internals(struct net_context *c, NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; uint32 i; uint32 level = 3; - PRINTER_DRIVER_CTR drv_ctr_enum; + union spoolss_DriverInfo *info; int d; - ZERO_STRUCT(drv_ctr_enum); - printf("listing printer-drivers\n"); for (i=0; archi_table[i].long_archi!=NULL; i++) { @@ -1227,7 +1165,7 @@ NTSTATUS rpc_printer_driver_list_internals(struct net_context *c, /* enum remote drivers */ if (!net_spoolss_enumprinterdrivers(pipe_hnd, mem_ctx, level, archi_table[i].long_archi, - &num_drivers, &drv_ctr_enum)) { + &num_drivers, &info)) { nt_status = NT_STATUS_UNSUCCESSFUL; goto done; } @@ -1244,7 +1182,7 @@ NTSTATUS rpc_printer_driver_list_internals(struct net_context *c, /* do something for all drivers for architecture */ for (d = 0; d < num_drivers; d++) { - display_print_driver_3(&(drv_ctr_enum.info3[d])); + display_print_driver3(&info[d].info3); } } @@ -1277,8 +1215,8 @@ static NTSTATUS rpc_printer_publish_internals_args(struct rpc_pipe_client *pipe_ NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; uint32 i, num_printers; uint32 level = 7; - char *printername, *sharename; - PRINTER_INFO_CTR ctr; + const char *printername, *sharename; + union spoolss_PrinterInfo *info_enum; union spoolss_PrinterInfo info; struct spoolss_SetPrinterInfoCtr info_ctr; struct spoolss_DevmodeContainer devmode_ctr; @@ -1287,21 +1225,14 @@ static NTSTATUS rpc_printer_publish_internals_args(struct rpc_pipe_client *pipe_ WERROR result; const char *action_str; - if (!get_printer_info(pipe_hnd, mem_ctx, 2, argc, argv, &num_printers, &ctr)) + if (!get_printer_info(pipe_hnd, mem_ctx, 2, argc, argv, &num_printers, &info_enum)) return nt_status; for (i = 0; i < num_printers; i++) { + /* do some initialization */ - rpcstr_pull_talloc(mem_ctx, - &printername, - ctr.printers_2[i].printername.buffer, - -1, - STR_TERMINATE); - rpcstr_pull_talloc(mem_ctx, - &sharename, - ctr.printers_2[i].sharename.buffer, - -1, - STR_TERMINATE); + printername = info_enum[i].info2.printername; + sharename = info_enum[i].info2.sharename; if (!printername || !sharename) { goto done; } @@ -1429,29 +1360,21 @@ NTSTATUS rpc_printer_publish_list_internals(struct net_context *c, NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; uint32 i, num_printers; uint32 level = 7; - char *printername, *sharename; - PRINTER_INFO_CTR ctr, ctr_pub; + const char *printername, *sharename; + union spoolss_PrinterInfo *info_enum; union spoolss_PrinterInfo info; POLICY_HND hnd; int state; - if (!get_printer_info(pipe_hnd, mem_ctx, 2, argc, argv, &num_printers, &ctr)) + if (!get_printer_info(pipe_hnd, mem_ctx, 2, argc, argv, &num_printers, &info_enum)) return nt_status; for (i = 0; i < num_printers; i++) { - ZERO_STRUCT(ctr_pub); /* do some initialization */ - rpcstr_pull_talloc(mem_ctx, - &printername, - ctr.printers_2[i].printername.buffer, - -1, - STR_TERMINATE); - rpcstr_pull_talloc(mem_ctx, - &sharename, - ctr.printers_2[i].sharename.buffer, - -1, - STR_TERMINATE); + printername = info_enum[i].info2.printername; + sharename = info_enum[i].info2.sharename; + if (!printername || !sharename) { goto done; } @@ -1530,15 +1453,13 @@ NTSTATUS rpc_printer_migrate_security_internals(struct net_context *c, uint32 i = 0; uint32 num_printers; uint32 level = 2; - char *printername, *sharename; + const char *printername, *sharename; struct rpc_pipe_client *pipe_hnd_dst = NULL; POLICY_HND hnd_src, hnd_dst; - PRINTER_INFO_CTR ctr_src, ctr_enum; + union spoolss_PrinterInfo *info_enum; struct cli_state *cli_dst = NULL; union spoolss_PrinterInfo info_src, info_dst; - ZERO_STRUCT(ctr_src); - DEBUG(3,("copying printer ACLs\n")); /* connect destination PI_SPOOLSS */ @@ -1549,7 +1470,7 @@ NTSTATUS rpc_printer_migrate_security_internals(struct net_context *c, /* enum source printers */ - if (!get_printer_info(pipe_hnd, mem_ctx, level, argc, argv, &num_printers, &ctr_enum)) { + if (!get_printer_info(pipe_hnd, mem_ctx, level, argc, argv, &num_printers, &info_enum)) { nt_status = NT_STATUS_UNSUCCESSFUL; goto done; } @@ -1562,17 +1483,11 @@ NTSTATUS rpc_printer_migrate_security_internals(struct net_context *c, /* do something for all printers */ for (i = 0; i < num_printers; i++) { + /* do some initialization */ - rpcstr_pull_talloc(mem_ctx, - &printername, - ctr_enum.printers_2[i].printername.buffer, - -1, - STR_TERMINATE); - rpcstr_pull_talloc(mem_ctx, - &sharename, - ctr_enum.printers_2[i].sharename.buffer, - -1, - STR_TERMINATE); + printername = info_enum[i].info2.printername; + sharename = info_enum[i].info2.sharename; + if (!printername || !sharename) { nt_status = NT_STATUS_UNSUCCESSFUL; goto done; @@ -1684,17 +1599,15 @@ NTSTATUS rpc_printer_migrate_forms_internals(struct net_context *c, uint32 i, f; uint32 num_printers; uint32 level = 1; - char *printername, *sharename; + const char *printername, *sharename; struct rpc_pipe_client *pipe_hnd_dst = NULL; POLICY_HND hnd_src, hnd_dst; - PRINTER_INFO_CTR ctr_enum; + union spoolss_PrinterInfo *info_enum; union spoolss_PrinterInfo info_dst; uint32_t num_forms; union spoolss_FormInfo *forms; struct cli_state *cli_dst = NULL; - ZERO_STRUCT(ctr_enum); - DEBUG(3,("copying forms\n")); /* connect destination PI_SPOOLSS */ @@ -1704,7 +1617,7 @@ NTSTATUS rpc_printer_migrate_forms_internals(struct net_context *c, return nt_status; /* enum src printers */ - if (!get_printer_info(pipe_hnd, mem_ctx, 2, argc, argv, &num_printers, &ctr_enum)) { + if (!get_printer_info(pipe_hnd, mem_ctx, 2, argc, argv, &num_printers, &info_enum)) { nt_status = NT_STATUS_UNSUCCESSFUL; goto done; } @@ -1717,17 +1630,11 @@ NTSTATUS rpc_printer_migrate_forms_internals(struct net_context *c, /* do something for all printers */ for (i = 0; i < num_printers; i++) { + /* do some initialization */ - rpcstr_pull_talloc(mem_ctx, - &printername, - ctr_enum.printers_2[i].printername.buffer, - -1, - STR_TERMINATE); - rpcstr_pull_talloc(mem_ctx, - &sharename, - ctr_enum.printers_2[i].sharename.buffer, - -1, - STR_TERMINATE); + printername = info_enum[i].info2.printername; + sharename = info_enum[i].info2.sharename; + if (!printername || !sharename) { nt_status = NT_STATUS_UNSUCCESSFUL; goto done; @@ -1852,22 +1759,19 @@ NTSTATUS rpc_printer_migrate_drivers_internals(struct net_context *c, uint32 i, p; uint32 num_printers; uint32 level = 3; - char *printername, *sharename; + const char *printername, *sharename; bool got_src_driver_share = false; bool got_dst_driver_share = false; struct rpc_pipe_client *pipe_hnd_dst = NULL; 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_enum; 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; const char *drivername = NULL; - ZERO_STRUCT(info_ctr_enum); - ZERO_STRUCT(info_ctr_dst); - DEBUG(3,("copying printer-drivers\n")); nt_status = connect_dst_pipe(c, &cli_dst, &pipe_hnd_dst, @@ -1894,7 +1798,7 @@ NTSTATUS rpc_printer_migrate_drivers_internals(struct net_context *c, /* enum src printers */ - if (!get_printer_info(pipe_hnd, mem_ctx, 2, argc, argv, &num_printers, &info_ctr_enum)) { + if (!get_printer_info(pipe_hnd, mem_ctx, 2, argc, argv, &num_printers, &info_enum)) { nt_status = NT_STATUS_UNSUCCESSFUL; goto done; } @@ -1908,17 +1812,11 @@ NTSTATUS rpc_printer_migrate_drivers_internals(struct net_context *c, /* do something for all printers */ for (p = 0; p < num_printers; p++) { + /* do some initialization */ - rpcstr_pull_talloc(mem_ctx, - &printername, - info_ctr_enum.printers_2[p].printername.buffer, - -1, - STR_TERMINATE); - rpcstr_pull_talloc(mem_ctx, - &sharename, - info_ctr_enum.printers_2[p].sharename.buffer, - -1, - STR_TERMINATE); + printername = info_enum[p].info2.printername; + sharename = info_enum[p].info2.sharename; + if (!printername || !sharename) { nt_status = NT_STATUS_UNSUCCESSFUL; goto done; @@ -2072,11 +1970,11 @@ 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_enum; union spoolss_PrinterInfo info_dst, info_src; + union spoolss_PrinterInfo *info_enum; struct cli_state *cli_dst = NULL; POLICY_HND hnd_dst, hnd_src; - char *printername, *sharename; + const char *printername, *sharename; struct rpc_pipe_client *pipe_hnd_dst = NULL; struct spoolss_SetPrinterInfoCtr info_ctr; @@ -2089,7 +1987,7 @@ NTSTATUS rpc_printer_migrate_printers_internals(struct net_context *c, return nt_status; /* enum printers */ - if (!get_printer_info(pipe_hnd, mem_ctx, level, argc, argv, &num_printers, &ctr_enum)) { + if (!get_printer_info(pipe_hnd, mem_ctx, level, argc, argv, &num_printers, &info_enum)) { nt_status = NT_STATUS_UNSUCCESSFUL; goto done; } @@ -2102,17 +2000,11 @@ NTSTATUS rpc_printer_migrate_printers_internals(struct net_context *c, /* do something for all printers */ for (i = 0; i < num_printers; i++) { + /* do some initialization */ - rpcstr_pull_talloc(mem_ctx, - &printername, - ctr_enum.printers_2[i].printername.buffer, - -1, - STR_TERMINATE); - rpcstr_pull_talloc(mem_ctx, - &sharename, - ctr_enum.printers_2[i].sharename.buffer, - -1, - STR_TERMINATE); + printername = info_enum[i].info2.printername; + sharename = info_enum[i].info2.sharename; + if (!printername || !sharename) { nt_status = NT_STATUS_UNSUCCESSFUL; goto done; @@ -2235,11 +2127,12 @@ NTSTATUS rpc_printer_migrate_settings_internals(struct net_context *c, uint32 i = 0, p = 0, j = 0; uint32 num_printers, val_needed, data_needed; uint32 level = 2; - char *printername, *sharename; + const char *printername, *sharename; struct rpc_pipe_client *pipe_hnd_dst = NULL; POLICY_HND hnd_src, hnd_dst; - PRINTER_INFO_CTR ctr_enum; - union spoolss_PrinterInfo info_dst_publish, info_dst; + union spoolss_PrinterInfo *info_enum; + union spoolss_PrinterInfo info_dst_publish; + union spoolss_PrinterInfo info_dst; REGVAL_CTR *reg_ctr; struct cli_state *cli_dst = NULL; char *devicename = NULL, *unc_name = NULL, *url = NULL; @@ -2247,7 +2140,6 @@ 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); @@ -2260,7 +2152,7 @@ NTSTATUS rpc_printer_migrate_settings_internals(struct net_context *c, return nt_status; /* enum src printers */ - if (!get_printer_info(pipe_hnd, mem_ctx, level, argc, argv, &num_printers, &ctr_enum)) { + if (!get_printer_info(pipe_hnd, mem_ctx, level, argc, argv, &num_printers, &info_enum)) { nt_status = NT_STATUS_UNSUCCESSFUL; goto done; } @@ -2281,17 +2173,11 @@ NTSTATUS rpc_printer_migrate_settings_internals(struct net_context *c, /* do something for all printers */ for (i = 0; i < num_printers; i++) { + /* do some initialization */ - rpcstr_pull_talloc(mem_ctx, - &printername, - ctr_enum.printers_2[i].printername.buffer, - -1, - STR_TERMINATE); - rpcstr_pull_talloc(mem_ctx, - &sharename, - ctr_enum.printers_2[i].sharename.buffer, - -1, - STR_TERMINATE); + printername = info_enum[i].info2.printername; + sharename = info_enum[i].info2.sharename; + if (!printername || !sharename) { nt_status = NT_STATUS_UNSUCCESSFUL; goto done; @@ -2319,20 +2205,19 @@ NTSTATUS rpc_printer_migrate_settings_internals(struct net_context *c, level, &info_dst)) goto done; -#if 0 /* FIXME GD */ /* STEP 1: COPY DEVICE-MODE and other PRINTER_INFO_2-attributes */ - info_dst.info2 = &ctr_enum.printers_2[i]; + info_dst.info2 = info_enum[i].info2; /* why is the port always disconnected when the printer is correctly installed (incl. driver ???) */ info_dst.info2.portname = SAMBA_PRINTER_PORT_NAME; /* check if printer is published */ - if (ctr_enum.printers_2[i].attributes & PRINTER_ATTRIBUTE_PUBLISHED) { + if (info_enum[i].info2.attributes & PRINTER_ATTRIBUTE_PUBLISHED) { /* check for existing dst printer */ if (!net_spoolss_getprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, 7, &info_dst_publish)) @@ -2346,13 +2231,10 @@ NTSTATUS rpc_printer_migrate_settings_internals(struct net_context *c, DEBUG(3,("republished printer\n")); } - if (ctr_enum.printers_2[i].devmode != NULL) { + if (info_enum[i].info2.devmode != NULL) { /* copy devmode (info level 2) */ - info_dst.info2.devmode = (DEVICEMODE *) - TALLOC_MEMDUP(mem_ctx, - ctr_enum.printers_2[i].devmode, - sizeof(DEVICEMODE)); + info_dst.info2.devmode = info_enum[i].info2.devmode; /* do not copy security descriptor (we have another * command for that) */ @@ -2374,7 +2256,7 @@ NTSTATUS rpc_printer_migrate_settings_internals(struct net_context *c, DEBUGADD(1,("\tSetPrinter of DEVICEMODE succeeded\n")); } -#endif + /* STEP 2: COPY REGISTRY VALUES */ /* please keep in mind that samba parse_spools gives horribly |