?? net_rpc_printer.c
字號:
done: if (got_hnd) rpccli_spoolss_close_printer(pipe_hnd, mem_ctx, &hnd); return nt_status;}/** * Migrate Printer-ACLs from a source server to the destination server * * All parameters are provided by the run_rpc_command function, except for * argc, argv which are passed through. * * @param domain_sid The domain sid aquired from the remote server * @param cli A cli_state connected to the server. * @param mem_ctx Talloc context, destoyed on compleation of the function. * @param argc Standard main() style argc * @param argv Standard main() style argv. Initial components are already * stripped * * @return Normal NTSTATUS return. **/NTSTATUS rpc_printer_migrate_security_internals(const DOM_SID *domain_sid, const char *domain_name, struct cli_state *cli, struct rpc_pipe_client *pipe_hnd, TALLOC_CTX *mem_ctx, int argc, const char **argv){ /* TODO: what now, info2 or info3 ? convince jerry that we should add clientside setacls level 3 at least */ NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; uint32 i = 0; uint32 num_printers; uint32 level = 2; pstring printername = "", sharename = ""; BOOL got_hnd_src = False; 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; struct cli_state *cli_dst = NULL; ZERO_STRUCT(ctr_src); DEBUG(3,("copying printer ACLs\n")); /* connect destination PI_SPOOLSS */ nt_status = connect_dst_pipe(&cli_dst, &pipe_hnd_dst, PI_SPOOLSS); if (!NT_STATUS_IS_OK(nt_status)) return nt_status; /* enum source printers */ if (!get_printer_info(pipe_hnd, mem_ctx, level, argc, argv, &num_printers, &ctr_enum)) { nt_status = NT_STATUS_UNSUCCESSFUL; goto done; } if (!num_printers) { printf ("no printers found on server.\n"); nt_status = NT_STATUS_OK; goto done; } /* do something for all printers */ for (i = 0; i < num_printers; i++) { /* do some initialization */ rpcstr_pull(printername, ctr_enum.printers_2[i].printername.buffer, sizeof(printername), -1, STR_TERMINATE); rpcstr_pull(sharename, ctr_enum.printers_2[i].sharename.buffer, sizeof(sharename), -1, STR_TERMINATE); /* we can reset NT_STATUS here because we do not get any real NT_STATUS-codes anymore from now on */ nt_status = NT_STATUS_UNSUCCESSFUL; d_printf("migrating printer ACLs for: [%s] / [%s]\n", printername, sharename); /* according to msdn you have specify these access-rights to see the security descriptor - READ_CONTROL (DACL) - ACCESS_SYSTEM_SECURITY (SACL) */ /* open src printer handle */ if (!net_spoolss_open_printer_ex(pipe_hnd, mem_ctx, sharename, MAXIMUM_ALLOWED_ACCESS, cli->user_name, &hnd_src)) goto done; got_hnd_src = True; /* open dst printer handle */ if (!net_spoolss_open_printer_ex(pipe_hnd_dst, mem_ctx, sharename, PRINTER_ALL_ACCESS, cli_dst->user_name, &hnd_dst)) goto done; got_hnd_dst = True; /* check for existing dst printer */ if (!net_spoolss_getprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, level, &ctr_dst)) goto done; /* check for existing src printer */ if (!net_spoolss_getprinter(pipe_hnd, mem_ctx, &hnd_src, 3, &ctr_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); if (opt_verbose) display_sec_desc(ctr_dst.printers_2->secdesc); if (!net_spoolss_setprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, 2, &ctr_dst)) goto done; DEBUGADD(1,("\tSetPrinter of SECDESC succeeded\n")); /* close printer handles here */ if (got_hnd_src) { rpccli_spoolss_close_printer(pipe_hnd, mem_ctx, &hnd_src); got_hnd_src = False; } if (got_hnd_dst) { rpccli_spoolss_close_printer(pipe_hnd_dst, mem_ctx, &hnd_dst); got_hnd_dst = False; } } nt_status = NT_STATUS_OK;done: if (got_hnd_src) { rpccli_spoolss_close_printer(pipe_hnd, mem_ctx, &hnd_src); } if (got_hnd_dst) { rpccli_spoolss_close_printer(pipe_hnd_dst, mem_ctx, &hnd_dst); } if (cli_dst) { cli_shutdown(cli_dst); } return nt_status;}/** * Migrate printer-forms from a src server to the dst server * * All parameters are provided by the run_rpc_command function, except for * argc, argv which are passed through. * * @param domain_sid The domain sid aquired from the remote server * @param cli A cli_state connected to the server. * @param mem_ctx Talloc context, destoyed on compleation of the function. * @param argc Standard main() style argc * @param argv Standard main() style argv. Initial components are already * stripped * * @return Normal NTSTATUS return. **/NTSTATUS rpc_printer_migrate_forms_internals(const DOM_SID *domain_sid, const char *domain_name, struct cli_state *cli, struct rpc_pipe_client *pipe_hnd, TALLOC_CTX *mem_ctx, int argc, const char **argv){ NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; WERROR result; uint32 i, f; uint32 num_printers; uint32 level = 1; pstring printername = "", sharename = ""; BOOL got_hnd_src = False; 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; uint32 num_forms; FORM_1 *forms; struct cli_state *cli_dst = NULL; ZERO_STRUCT(ctr_enum); DEBUG(3,("copying forms\n")); /* connect destination PI_SPOOLSS */ nt_status = connect_dst_pipe(&cli_dst, &pipe_hnd_dst, PI_SPOOLSS); if (!NT_STATUS_IS_OK(nt_status)) return nt_status; /* enum src printers */ if (!get_printer_info(pipe_hnd, mem_ctx, 2, argc, argv, &num_printers, &ctr_enum)) { nt_status = NT_STATUS_UNSUCCESSFUL; goto done; } if (!num_printers) { printf ("no printers found on server.\n"); nt_status = NT_STATUS_OK; goto done; } /* do something for all printers */ for (i = 0; i < num_printers; i++) { /* do some initialization */ rpcstr_pull(printername, ctr_enum.printers_2[i].printername.buffer, sizeof(printername), -1, STR_TERMINATE); rpcstr_pull(sharename, ctr_enum.printers_2[i].sharename.buffer, sizeof(sharename), -1, STR_TERMINATE); /* we can reset NT_STATUS here because we do not get any real NT_STATUS-codes anymore from now on */ nt_status = NT_STATUS_UNSUCCESSFUL; d_printf("migrating printer forms for: [%s] / [%s]\n", printername, sharename); /* open src printer handle */ if (!net_spoolss_open_printer_ex(pipe_hnd, mem_ctx, sharename, MAXIMUM_ALLOWED_ACCESS, cli->user_name, &hnd_src)) goto done; got_hnd_src = True; /* open dst printer handle */ if (!net_spoolss_open_printer_ex(pipe_hnd_dst, mem_ctx, sharename, PRINTER_ALL_ACCESS, cli->user_name, &hnd_dst)) goto done; got_hnd_dst = True; /* check for existing dst printer */ if (!net_spoolss_getprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, level, &ctr_dst)) goto done; /* finally migrate forms */ if (!net_spoolss_enumforms(pipe_hnd, mem_ctx, &hnd_src, level, &num_forms, &forms)) goto done; DEBUG(1,("got %d forms for printer\n", num_forms)); for (f = 0; f < num_forms; f++) { FORM form; fstring form_name; /* only migrate FORM_PRINTER types, according to jerry FORM_BUILTIN-types are hard-coded in samba */ if (forms[f].flag != FORM_PRINTER) continue; if (forms[f].name.buffer) rpcstr_pull(form_name, forms[f].name.buffer, sizeof(form_name), -1, STR_TERMINATE); if (opt_verbose) d_printf("\tmigrating form # %d [%s] of type [%d]\n", f, form_name, forms[f].flag); /* is there a more elegant way to do that ? */ form.flags = FORM_PRINTER; form.size_x = forms[f].width; form.size_y = forms[f].length; form.left = forms[f].left; form.top = forms[f].top; form.right = forms[f].right; form.bottom = forms[f].bottom; init_unistr2(&form.name, form_name, UNI_STR_TERMINATE); /* FIXME: there might be something wrong with samba's builtin-forms */ result = rpccli_spoolss_addform(pipe_hnd_dst, mem_ctx, &hnd_dst, 1, &form); if (!W_ERROR_IS_OK(result)) { d_printf("\tAddForm form %d: [%s] refused.\n", f, form_name); continue; } DEBUGADD(1,("\tAddForm of [%s] succeeded\n", form_name)); } /* close printer handles here */ if (got_hnd_src) { rpccli_spoolss_close_printer(pipe_hnd, mem_ctx, &hnd_src); got_hnd_src = False; } if (got_hnd_dst) { rpccli_spoolss_close_printer(pipe_hnd_dst, mem_ctx, &hnd_dst); got_hnd_dst = False; } } nt_status = NT_STATUS_OK;done: if (got_hnd_src) rpccli_spoolss_close_printer(pipe_hnd, mem_ctx, &hnd_src); if (got_hnd_dst) rpccli_spoolss_close_printer(pipe_hnd_dst, mem_ctx, &hnd_dst); if (cli_dst) { cli_shutdown(cli_dst); } return nt_status;}/** * Migrate printer-drivers from a src server to the dst server * * All parameters are provided by the run_rpc_command function, except for * argc, argv which are passed through. * * @param domain_sid The domain sid aquired from the remote server * @param cli A cli_state connected to the server. * @param mem_ctx Talloc context, destoyed on compleation of the function. * @param argc Standard main() style argc * @param argv Standard main() style argv. Initial components are already * stripped * * @return Normal NTSTATUS return. **/NTSTATUS rpc_printer_migrate_drivers_internals(const DOM_SID *domain_sid, const char *domain_name, struct cli_state *cli, struct rpc_pipe_client *pipe_hnd, TALLOC_CTX *mem_ctx, int argc, const char **argv){ NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; uint32 i, p; uint32 num_printers; uint32 level = 3; pstring printername = "", sharename = ""; BOOL got_hnd_src = False; BOOL got_hnd_dst = False; 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; PRINTER_DRIVER_CTR drv_ctr_src, drv_ctr_dst; PRINTER_INFO_CTR info_ctr_enum, info_ctr_dst; struct cli_state *cli_dst = NULL; struct cli_state *cli_share_src = NULL; struct cli_state *cli_share_dst = NULL; fstring drivername = ""; ZERO_STRUCT(drv_ctr_src); ZERO_STRUCT(drv_ctr_dst); ZERO_STRUCT(info_ctr_enum); ZERO_STRUCT(info_ctr_dst); DEBUG(3,("copying printer-drivers\n")); nt_status = connect_dst_pipe(&cli_dst, &pipe_hnd_dst, PI_SPOOLSS); if (!NT_STATUS_IS_OK(nt_status)) return nt_status; /* open print$-share on the src server */ nt_status = connect_to_service(&cli_share_src, &cli->dest_ip, cli->desthost, "print$", "A:"); if (!NT_STATUS_IS_OK(nt_status)) goto done; got_src_driver_share = True; /* open print$-share on the dst server */ nt_status = connect_to_service(&cli_share_dst, &cli_dst->dest_ip, cli_dst->desthost, "print$", "A:"); if (!NT_STATUS_IS_OK(nt_status)) return nt_status; got_dst_driver_share = True; /* enum src printers */ if (!get_printer_info(pipe_hnd, mem_ctx, 2, argc, argv, &num_printers, &info_ctr_enum)) { nt_status = NT_STATUS_UNSUCCESSFUL; goto done; } if (num_printers == 0) { printf ("no printers found on server.\n"); nt_status = NT_STATUS_OK; goto done; } /* do something for all printers */ for (p = 0; p < num_printers; p++) { /* do some initialization */ rpcstr_pull(printername, info_ctr_enum.printers_2[p].printername.buffer, sizeof(printername), -1, STR_TERMINATE); rpcstr_pull(sharename, info_ctr_enum.printers_2[p].sharename.buffer, sizeof(sharename), -1, STR_TERMINATE); /* we can reset NT_STATUS here because we do not get any real NT_STATUS-codes anymore from now on */ nt_status = NT_STATUS_UNSUCCESSFUL; d_printf("migrating printer driver for: [%s] / [%s]\n", printername, sharename); /* open dst printer handle */ if (!net_spoolss_open_printer_ex(pipe_hnd_dst, mem_ctx, sharename, PRINTER_ALL_ACCESS, cli->user_name, &hnd_dst)) goto done; got_hnd_dst = True; /* check for existing dst printer */ if (!net_spoolss_getprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, 2, &info_ctr_dst)) goto done; /* open src printer handle */ if (!net_spoolss_open_printer_ex(pipe_hnd, mem_ctx, sharename, MAXIMUM_ALLOWED_ACCESS, pipe_hnd->cli->user_name, &hnd_src)) goto done; got_hnd_src = True; /* in a first step call getdriver for each shared printer (per arch) to get a list of all files that have to be copied */ for (i=0; archi_table[i].long_archi!=NULL; i++) { /* getdriver src */ if (!net_spoolss_getprinterdriver(pipe_hnd, mem_ctx, &hnd_src, level, archi_table[i].long_archi, archi_table[i].version, &drv_ctr_src)) continue; rpcstr_pull(drivername, drv_ctr_src.info3->name.buffer, sizeof(drivername), -1, STR_TERMINATE); if (opt_verbose) display_print_driver_3(drv_ctr_src.info3); /* check arch dir */ nt_status = check_arch_dir(cli_share_dst, archi_table[i].short_archi); if (!NT_STATUS_IS_OK(nt_status)) goto done; /* copy driver-files */ nt_status = copy_print_driver_3(mem_ctx, cli_share_src, cli_share_dst, archi_table[i].short_archi, drv_ctr_src.info3); if (!NT_STATUS_IS_OK(nt_status)) goto done;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -