📄 net_rpc_printer.c
字号:
return True;}static BOOL net_spoolss_setprinterdataex(struct rpc_pipe_client *pipe_hnd, TALLOC_CTX *mem_ctx, POLICY_HND *hnd, char *keyname, REGISTRY_VALUE *value){ WERROR result; /* setprinterdataex call */ result = rpccli_spoolss_setprinterdataex(pipe_hnd, mem_ctx, hnd, keyname, value); if (!W_ERROR_IS_OK(result)) { printf("could not set printerdataex: %s\n", dos_errstr(result)); return False; } return True;}static BOOL net_spoolss_enumforms(struct rpc_pipe_client *pipe_hnd, TALLOC_CTX *mem_ctx, POLICY_HND *hnd, int level, uint32 *num_forms, FORM_1 **forms) { WERROR result; /* enumforms call */ result = rpccli_spoolss_enumforms(pipe_hnd, mem_ctx, hnd, level, num_forms, forms); if (!W_ERROR_IS_OK(result)) { printf("could not enum forms: %s\n", dos_errstr(result)); return False; } return True;}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){ WERROR result; /* enumprinterdrivers call */ result = rpccli_spoolss_enumprinterdrivers( pipe_hnd, mem_ctx, level, env, num_drivers, ctr); if (!W_ERROR_IS_OK(result)) { printf("cannot enum drivers: %s\n", dos_errstr(result)); return False; } return True;}static BOOL net_spoolss_getprinterdriver(struct rpc_pipe_client *pipe_hnd, TALLOC_CTX *mem_ctx, POLICY_HND *hnd, uint32 level, const char *env, int version, PRINTER_DRIVER_CTR *ctr){ WERROR result; /* getprinterdriver call */ result = rpccli_spoolss_getprinterdriver( pipe_hnd, mem_ctx, hnd, level, env, version, ctr); if (!W_ERROR_IS_OK(result)) { DEBUG(1,("cannot get driver (for architecture: %s): %s\n", env, dos_errstr(result))); if (W_ERROR_V(result) != W_ERROR_V(WERR_UNKNOWN_PRINTER_DRIVER) && W_ERROR_V(result) != W_ERROR_V(WERR_INVALID_ENVIRONMENT)) { printf("cannot get driver: %s\n", dos_errstr(result)); } return False; } return True;}static BOOL net_spoolss_addprinterdriver(struct rpc_pipe_client *pipe_hnd, TALLOC_CTX *mem_ctx, uint32 level, PRINTER_DRIVER_CTR *ctr){ WERROR result; /* addprinterdriver call */ result = rpccli_spoolss_addprinterdriver(pipe_hnd, mem_ctx, level, ctr); /* be more verbose */ if (W_ERROR_V(result) == W_ERROR_V(WERR_ACCESS_DENIED)) { printf("You are not allowed to add drivers\n"); return False; } if (!W_ERROR_IS_OK(result)) { printf("cannot add driver: %s\n", dos_errstr(result)); return False; } return True;}/** * abstraction function to get uint32 num_printers and PRINTER_INFO_CTR ctr * for a single printer or for all printers depending on argc/argv **/static BOOL get_printer_info(struct rpc_pipe_client *pipe_hnd, TALLOC_CTX *mem_ctx, int level, int argc, const char **argv, uint32 *num_printers, PRINTER_INFO_CTR *ctr){ POLICY_HND hnd; /* 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)) return False; goto out; } /* argument given, get a single printer by name */ if (!net_spoolss_open_printer_ex(pipe_hnd, mem_ctx, argv[0], MAXIMUM_ALLOWED_ACCESS, pipe_hnd->cli->user_name, &hnd)) return False; if (!net_spoolss_getprinter(pipe_hnd, mem_ctx, &hnd, level, ctr)) { rpccli_spoolss_close_printer(pipe_hnd, mem_ctx, &hnd); return False; } rpccli_spoolss_close_printer(pipe_hnd, mem_ctx, &hnd); *num_printers = 1;out: DEBUG(3,("got %d printers\n", *num_printers)); return True;}/** * List print-queues (including local printers that are not shared) * * 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_list_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, num_printers; uint32 level = 2; pstring printername, sharename; PRINTER_INFO_CTR ctr; printf("listing printers\n"); if (!get_printer_info(pipe_hnd, mem_ctx, level, argc, argv, &num_printers, &ctr)) return nt_status; for (i = 0; i < num_printers; i++) { /* do some initialization */ rpcstr_pull(printername, ctr.printers_2[i].printername.buffer, sizeof(printername), -1, STR_TERMINATE); rpcstr_pull(sharename, ctr.printers_2[i].sharename.buffer, sizeof(sharename), -1, STR_TERMINATE); d_printf("printer %d: %s, shared as: %s\n", i+1, printername, sharename); } return NT_STATUS_OK;}/** * List printer-drivers from a 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_driver_list_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; uint32 level = 3; PRINTER_DRIVER_CTR drv_ctr_enum; int d; ZERO_STRUCT(drv_ctr_enum); printf("listing printer-drivers\n"); for (i=0; archi_table[i].long_archi!=NULL; i++) { uint32 num_drivers; /* enum remote drivers */ if (!net_spoolss_enumprinterdrivers(pipe_hnd, mem_ctx, level, archi_table[i].long_archi, &num_drivers, &drv_ctr_enum)) { nt_status = NT_STATUS_UNSUCCESSFUL; goto done; } if (num_drivers == 0) { d_printf ("no drivers found on server for architecture: [%s].\n", archi_table[i].long_archi); continue; } d_printf("got %d printer-drivers for architecture: [%s]\n", num_drivers, archi_table[i].long_archi); /* do something for all drivers for architecture */ for (d = 0; d < num_drivers; d++) { display_print_driver_3(&(drv_ctr_enum.info3[d])); } } nt_status = NT_STATUS_OK;done: return nt_status;}/** * Publish print-queues with args-wrapper * * @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 * @param action * * @return Normal NTSTATUS return. **/static NTSTATUS rpc_printer_publish_internals_args(struct rpc_pipe_client *pipe_hnd, TALLOC_CTX *mem_ctx, int argc, const char **argv, uint32 action){ NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; uint32 i, num_printers; uint32 level = 7; pstring printername, sharename; PRINTER_INFO_CTR ctr, ctr_pub; POLICY_HND hnd; BOOL got_hnd = False; WERROR result; const char *action_str; if (!get_printer_info(pipe_hnd, mem_ctx, 2, argc, argv, &num_printers, &ctr)) return nt_status; for (i = 0; i < num_printers; i++) { /* do some initialization */ rpcstr_pull(printername, ctr.printers_2[i].printername.buffer, sizeof(printername), -1, STR_TERMINATE); rpcstr_pull(sharename, ctr.printers_2[i].sharename.buffer, sizeof(sharename), -1, STR_TERMINATE); /* open printer handle */ if (!net_spoolss_open_printer_ex(pipe_hnd, mem_ctx, sharename, PRINTER_ALL_ACCESS, pipe_hnd->cli->user_name, &hnd)) goto done; got_hnd = True; /* check for existing dst printer */ if (!net_spoolss_getprinter(pipe_hnd, mem_ctx, &hnd, level, &ctr_pub)) goto done; /* check action and set string */ switch (action) { case SPOOL_DS_PUBLISH: action_str = "published"; break; case SPOOL_DS_UPDATE: action_str = "updated"; break; case SPOOL_DS_UNPUBLISH: action_str = "unpublished"; break; default: action_str = "unknown action"; printf("unkown action: %d\n", action); break; } ctr_pub.printers_7->action = action; 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", dos_errstr(result)); goto done; } printf("successfully %s printer %s in Active Directory\n", action_str, sharename); } nt_status = NT_STATUS_OK;done: if (got_hnd) rpccli_spoolss_close_printer(pipe_hnd, mem_ctx, &hnd); return nt_status;}NTSTATUS rpc_printer_publish_publish_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){ return rpc_printer_publish_internals_args(pipe_hnd, mem_ctx, argc, argv, SPOOL_DS_PUBLISH);}NTSTATUS rpc_printer_publish_unpublish_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){ return rpc_printer_publish_internals_args(pipe_hnd, mem_ctx, argc, argv, SPOOL_DS_UNPUBLISH);}NTSTATUS rpc_printer_publish_update_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){ return rpc_printer_publish_internals_args(pipe_hnd, mem_ctx, argc, argv, SPOOL_DS_UPDATE);}/** * List print-queues w.r.t. their publishing state * * 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_publish_list_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, num_printers; uint32 level = 7; pstring printername, sharename; pstring guid; PRINTER_INFO_CTR ctr, ctr_pub; POLICY_HND hnd; BOOL got_hnd = False; int state; if (!get_printer_info(pipe_hnd, mem_ctx, 2, argc, argv, &num_printers, &ctr)) return nt_status; for (i = 0; i < num_printers; i++) { ZERO_STRUCT(ctr_pub); /* do some initialization */ rpcstr_pull(printername, ctr.printers_2[i].printername.buffer, sizeof(printername), -1, STR_TERMINATE); rpcstr_pull(sharename, ctr.printers_2[i].sharename.buffer, sizeof(sharename), -1, STR_TERMINATE); /* open printer handle */ if (!net_spoolss_open_printer_ex(pipe_hnd, mem_ctx, sharename, PRINTER_ALL_ACCESS, cli->user_name, &hnd)) goto done; got_hnd = True; /* check for existing dst printer */ if (!net_spoolss_getprinter(pipe_hnd, mem_ctx, &hnd, level, &ctr_pub)) goto done; rpcstr_pull(guid, ctr_pub.printers_7->guid.buffer, sizeof(guid), -1, STR_TERMINATE); state = ctr_pub.printers_7->action; switch (state) { case SPOOL_DS_PUBLISH: printf("printer [%s] is published", sharename); if (opt_verbose) printf(", guid: %s", guid); printf("\n"); break; case SPOOL_DS_UNPUBLISH: printf("printer [%s] is unpublished\n", sharename); break; case SPOOL_DS_UPDATE: printf("printer [%s] is currently updating\n", sharename); break; default: printf("unkown state: %d\n", state); break; } } nt_status = NT_STATUS_OK;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -