Changeset 745 for trunk/server/source3/rpcclient/cmd_spoolss.c
- Timestamp:
- Nov 27, 2012, 4:43:17 PM (13 years ago)
- Location:
- trunk/server
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/server
- Property svn:mergeinfo changed
/vendor/current merged: 581,587,591,594,597,600,615,618,740
- Property svn:mergeinfo changed
-
trunk/server/source3/rpcclient/cmd_spoolss.c
r596 r745 25 25 #include "includes.h" 26 26 #include "rpcclient.h" 27 #include "../librpc/gen_ndr/cli_spoolss.h" 27 #include "../librpc/gen_ndr/ndr_spoolss_c.h" 28 #include "rpc_client/cli_spoolss.h" 29 #include "rpc_client/init_spoolss.h" 30 #include "registry/reg_objects.h" 31 #include "nt_printing.h" 32 #include "../libcli/security/display_sec.h" 33 #include "../libcli/security/security_descriptor.h" 34 #include "../libcli/registry/util_reg.h" 35 #include "libsmb/libsmb.h" 28 36 29 37 #define RPCCLIENT_PRINTERNAME(_printername, _cli, _arg) \ … … 72 80 int i=-1; 73 81 74 DEBUG(107,("Getting architecture depend ant directory\n"));82 DEBUG(107,("Getting architecture dependent directory\n")); 75 83 do { 76 84 i++; … … 102 110 WERROR werror; 103 111 struct policy_handle hnd; 104 105 if (argc != 2) { 106 printf("Usage: %s <printername>\n", argv[0]); 112 uint32_t access_mask = PRINTER_ALL_ACCESS; 113 struct dcerpc_binding_handle *b = cli->binding_handle; 114 115 if (argc < 2) { 116 printf("Usage: %s <printername> [access_mask]\n", argv[0]); 107 117 return WERR_OK; 108 118 } 109 119 110 if (!cli) 111 return WERR_GENERAL_FAILURE; 120 if (argc >= 3) { 121 sscanf(argv[2], "%x", &access_mask); 122 } 112 123 113 124 /* Open the printer handle */ … … 115 126 werror = rpccli_spoolss_openprinter_ex(cli, mem_ctx, 116 127 argv[1], 117 PRINTER_ALL_ACCESS,128 access_mask, 118 129 &hnd); 119 130 if (W_ERROR_IS_OK(werror)) { 120 131 printf("Printer %s opened successfully\n", argv[1]); 121 rpccli_spoolss_ClosePrinter(cli, mem_ctx, &hnd, &werror);132 dcerpc_spoolss_ClosePrinter(b, mem_ctx, &hnd, &werror); 122 133 123 134 if (!W_ERROR_IS_OK(werror)) { … … 130 141 } 131 142 143 /**************************************************************************** 144 ****************************************************************************/ 145 146 static WERROR cmd_spoolss_open_printer(struct rpc_pipe_client *cli, 147 TALLOC_CTX *mem_ctx, 148 int argc, const char **argv) 149 { 150 WERROR werror; 151 struct policy_handle hnd; 152 uint32_t access_mask = PRINTER_ALL_ACCESS; 153 NTSTATUS status; 154 struct spoolss_DevmodeContainer devmode_ctr; 155 struct dcerpc_binding_handle *b = cli->binding_handle; 156 157 ZERO_STRUCT(devmode_ctr); 158 159 if (argc < 2) { 160 printf("Usage: %s <printername> [access_mask]\n", argv[0]); 161 return WERR_OK; 162 } 163 164 if (argc >= 3) { 165 sscanf(argv[2], "%x", &access_mask); 166 } 167 168 /* Open the printer handle */ 169 170 status = dcerpc_spoolss_OpenPrinter(b, mem_ctx, 171 argv[1], 172 NULL, 173 devmode_ctr, 174 access_mask, 175 &hnd, 176 &werror); 177 if (!NT_STATUS_IS_OK(status)) { 178 return ntstatus_to_werror(status); 179 } 180 if (W_ERROR_IS_OK(werror)) { 181 printf("Printer %s opened successfully\n", argv[1]); 182 dcerpc_spoolss_ClosePrinter(b, mem_ctx, &hnd, &werror); 183 184 if (!W_ERROR_IS_OK(werror)) { 185 printf("Error closing printer handle! (%s)\n", 186 get_dos_error_msg(werror)); 187 } 188 } 189 190 return werror; 191 } 132 192 133 193 /**************************************************************************** … … 467 527 struct spoolss_DevmodeContainer devmode_ctr; 468 528 struct sec_desc_buf secdesc_ctr; 529 struct dcerpc_binding_handle *b = cli->binding_handle; 469 530 470 531 if (argc == 1 || argc > 3) { … … 509 570 info_ctr.info.info2 = &info2; 510 571 511 status = rpccli_spoolss_SetPrinter(cli, mem_ctx,572 status = dcerpc_spoolss_SetPrinter(b, mem_ctx, 512 573 &pol, 513 574 &info_ctr, … … 516 577 0, /* command */ 517 578 &result); 579 if (!NT_STATUS_IS_OK(status)) { 580 result = ntstatus_to_werror(status); 581 goto done; 582 } 518 583 if (W_ERROR_IS_OK(result)) 519 584 printf("Success in setting comment.\n"); 520 585 521 586 done: 522 if (is_valid_policy_hnd(&pol)) 523 rpccli_spoolss_ClosePrinter(cli, mem_ctx, &pol, NULL); 587 if (is_valid_policy_hnd(&pol)) { 588 WERROR _result; 589 dcerpc_spoolss_ClosePrinter(b, mem_ctx, &pol, &_result); 590 } 524 591 525 592 return result; … … 544 611 struct spoolss_DevmodeContainer devmode_ctr; 545 612 struct sec_desc_buf secdesc_ctr; 613 struct dcerpc_binding_handle *b = cli->binding_handle; 546 614 547 615 ZERO_STRUCT(devmode_ctr); … … 585 653 info_ctr.info.info2 = &info2; 586 654 587 status = rpccli_spoolss_SetPrinter(cli, mem_ctx,655 status = dcerpc_spoolss_SetPrinter(b, mem_ctx, 588 656 &pol, 589 657 &info_ctr, … … 592 660 0, /* command */ 593 661 &result); 662 if (!NT_STATUS_IS_OK(status)) { 663 result = ntstatus_to_werror(status); 664 goto done; 665 } 594 666 if (W_ERROR_IS_OK(result)) 595 667 printf("Success in setting printername.\n"); 596 668 597 669 done: 598 if (is_valid_policy_hnd(&pol)) 599 rpccli_spoolss_ClosePrinter(cli, mem_ctx, &pol, NULL); 670 if (is_valid_policy_hnd(&pol)) { 671 WERROR _result; 672 dcerpc_spoolss_ClosePrinter(b, mem_ctx, &pol, &_result); 673 } 600 674 601 675 return result; … … 614 688 const char *printername; 615 689 union spoolss_PrinterInfo info; 690 struct dcerpc_binding_handle *b = cli->binding_handle; 616 691 617 692 if (argc == 1 || argc > 3) { … … 680 755 done: 681 756 if (is_valid_policy_hnd(&pol)) { 682 rpccli_spoolss_ClosePrinter(cli, mem_ctx, &pol, NULL); 757 WERROR _result; 758 dcerpc_spoolss_ClosePrinter(b, mem_ctx, &pol, &_result); 683 759 } 684 760 … … 689 765 ****************************************************************************/ 690 766 691 static void display_reg_value(struct regval_blob value)767 static void display_reg_value(struct regval_blob *value) 692 768 { 693 769 const char *text = NULL; 694 770 DATA_BLOB blob; 695 771 696 switch( value.type) {772 switch(regval_type(value)) { 697 773 case REG_DWORD: 698 printf("%s: REG_DWORD: 0x%08x\n", value.valuename,699 *((uint32_t *) value.data_p));774 printf("%s: REG_DWORD: 0x%08x\n", regval_name(value), 775 *((uint32_t *) regval_data_p(value))); 700 776 break; 701 777 case REG_SZ: 702 blob = data_blob_const( value.data_p, value.size);778 blob = data_blob_const(regval_data_p(value), regval_size(value)); 703 779 pull_reg_sz(talloc_tos(), &blob, &text); 704 printf("%s: REG_SZ: %s\n", value.valuename, text ? text : "");780 printf("%s: REG_SZ: %s\n", regval_name(value), text ? text : ""); 705 781 break; 706 782 case REG_BINARY: { 707 char *hex = hex_encode_talloc(NULL, value.data_p, value.size);783 char *hex = hex_encode_talloc(NULL, regval_data_p(value), regval_size(value)); 708 784 size_t i, len; 709 printf("%s: REG_BINARY:", value.valuename);785 printf("%s: REG_BINARY:", regval_name(value)); 710 786 len = strlen(hex); 711 787 for (i=0; i<len; i++) { … … 725 801 uint32_t i; 726 802 const char **values; 727 blob = data_blob_const( value.data_p, value.size);803 blob = data_blob_const(regval_data_p(value), regval_size(value)); 728 804 729 805 if (!pull_reg_multi_sz(NULL, &blob, &values)) { … … 732 808 } 733 809 734 printf("%s: REG_MULTI_SZ: \n", value.valuename);810 printf("%s: REG_MULTI_SZ: \n", regval_name(value)); 735 811 for (i=0; values[i] != NULL; i++) { 736 812 d_printf("%s\n", values[i]); … … 740 816 } 741 817 default: 742 printf("%s: unknown type %d\n", value.valuename, value.type);818 printf("%s: unknown type %d\n", regval_name(value), regval_type(value)); 743 819 } 744 820 … … 816 892 uint8_t *data; 817 893 uint32_t needed; 894 struct dcerpc_binding_handle *b = cli->binding_handle; 818 895 819 896 if (argc != 3) { … … 858 935 859 936 done: 860 if (is_valid_policy_hnd(&pol)) 861 rpccli_spoolss_ClosePrinter(cli, mem_ctx, &pol, NULL); 937 if (is_valid_policy_hnd(&pol)) { 938 WERROR _result; 939 dcerpc_spoolss_ClosePrinter(b, mem_ctx, &pol, &_result); 940 } 862 941 863 942 return result; … … 881 960 uint32_t offered = 0; 882 961 uint32_t needed; 962 struct dcerpc_binding_handle *b = cli->binding_handle; 883 963 884 964 if (argc != 4) { … … 915 995 } 916 996 917 status = rpccli_spoolss_GetPrinterDataEx(cli, mem_ctx,997 status = dcerpc_spoolss_GetPrinterDataEx(b, mem_ctx, 918 998 &pol, 919 999 keyname, … … 924 1004 &needed, 925 1005 &result); 1006 if (!NT_STATUS_IS_OK(status)) { 1007 result = ntstatus_to_werror(status); 1008 goto done; 1009 } 926 1010 if (W_ERROR_EQUAL(result, WERR_MORE_DATA)) { 927 1011 offered = needed; … … 930 1014 goto done; 931 1015 } 932 status = rpccli_spoolss_GetPrinterDataEx(cli, mem_ctx,1016 status = dcerpc_spoolss_GetPrinterDataEx(b, mem_ctx, 933 1017 &pol, 934 1018 keyname, … … 942 1026 943 1027 if (!NT_STATUS_IS_OK(status)) { 1028 result = ntstatus_to_werror(status); 944 1029 goto done; 945 1030 } … … 954 1039 955 1040 done: 956 if (is_valid_policy_hnd(&pol)) 957 rpccli_spoolss_ClosePrinter(cli, mem_ctx, &pol, NULL); 1041 if (is_valid_policy_hnd(&pol)) { 1042 WERROR _result; 1043 dcerpc_spoolss_ClosePrinter(b, mem_ctx, &pol, &_result); 1044 } 958 1045 959 1046 return result; … … 1187 1274 uint32_t server_major_version; 1188 1275 uint32_t server_minor_version; 1276 struct dcerpc_binding_handle *b = cli->binding_handle; 1189 1277 1190 1278 if ((argc == 1) || (argc > 3)) { … … 1267 1355 1268 1356 if (is_valid_policy_hnd(&pol)) { 1269 rpccli_spoolss_ClosePrinter(cli, mem_ctx, &pol, NULL); 1357 WERROR _result; 1358 dcerpc_spoolss_ClosePrinter(b, mem_ctx, &pol, &_result); 1270 1359 } 1271 1360 … … 1429 1518 union spoolss_DriverDirectoryInfo info; 1430 1519 uint32_t needed; 1520 struct dcerpc_binding_handle *b = cli->binding_handle; 1431 1521 1432 1522 if (argc > 2) { … … 1443 1533 /* Get the directory. Only use Info level 1 */ 1444 1534 1445 status = rpccli_spoolss_GetPrinterDriverDirectory(cli, mem_ctx,1535 status = dcerpc_spoolss_GetPrinterDriverDirectory(b, mem_ctx, 1446 1536 cli->srv_name_slash, 1447 1537 env, … … 1452 1542 &needed, 1453 1543 &result); 1544 if (!NT_STATUS_IS_OK(status)) { 1545 return ntstatus_to_werror(status); 1546 } 1454 1547 if (W_ERROR_EQUAL(result, WERR_INSUFFICIENT_BUFFER)) { 1455 1548 offered = needed; 1456 1549 buffer = data_blob_talloc_zero(mem_ctx, needed); 1457 1550 1458 status = rpccli_spoolss_GetPrinterDriverDirectory(cli, mem_ctx,1551 status = dcerpc_spoolss_GetPrinterDriverDirectory(b, mem_ctx, 1459 1552 cli->srv_name_slash, 1460 1553 env, … … 1465 1558 &needed, 1466 1559 &result); 1560 if (!NT_STATUS_IS_OK(status)) { 1561 return ntstatus_to_werror(status); 1562 } 1467 1563 } 1468 1564 … … 1610 1706 const char *arch; 1611 1707 char *driver_args; 1708 struct dcerpc_binding_handle *b = cli->binding_handle; 1612 1709 1613 1710 /* parse the command arguments */ … … 1628 1725 arch = cmd_spoolss_get_short_archi(argv[1]); 1629 1726 if (!arch) { 1630 printf ("Error Unknown architec hture [%s]\n", argv[1]);1727 printf ("Error Unknown architecture [%s]\n", argv[1]); 1631 1728 return WERR_INVALID_PARAM; 1632 1729 } … … 1653 1750 info_ctr.info.info3 = &info3; 1654 1751 1655 status = rpccli_spoolss_AddPrinterDriver(cli, mem_ctx,1752 status = dcerpc_spoolss_AddPrinterDriver(b, mem_ctx, 1656 1753 cli->srv_name_slash, 1657 1754 &info_ctr, … … 1741 1838 struct spoolss_DevmodeContainer devmode_ctr; 1742 1839 struct sec_desc_buf secdesc_ctr; 1840 struct dcerpc_binding_handle *b = cli->binding_handle; 1743 1841 1744 1842 ZERO_STRUCT(devmode_ctr); … … 1783 1881 info_ctr.info.info2 = &info2; 1784 1882 1785 status = rpccli_spoolss_SetPrinter(cli, mem_ctx,1883 status = dcerpc_spoolss_SetPrinter(b, mem_ctx, 1786 1884 &pol, 1787 1885 &info_ctr, … … 1790 1888 0, /* command */ 1791 1889 &result); 1890 if (!NT_STATUS_IS_OK(status)) { 1891 result = ntstatus_to_werror(status); 1892 goto done; 1893 } 1792 1894 if (!W_ERROR_IS_OK(result)) { 1793 1895 printf("SetPrinter call failed!\n"); 1794 goto done; ;1896 goto done; 1795 1897 } 1796 1898 … … 1800 1902 /* Cleanup */ 1801 1903 1802 if (is_valid_policy_hnd(&pol)) 1803 rpccli_spoolss_ClosePrinter(cli, mem_ctx, &pol, NULL); 1904 if (is_valid_policy_hnd(&pol)) { 1905 WERROR _result; 1906 dcerpc_spoolss_ClosePrinter(b, mem_ctx, &pol, &_result); 1907 } 1804 1908 1805 1909 return result; … … 1816 1920 WERROR result, ret = WERR_UNKNOWN_PRINTER_DRIVER; 1817 1921 NTSTATUS status; 1922 struct dcerpc_binding_handle *b = cli->binding_handle; 1818 1923 1819 1924 int i; … … 1848 1953 1849 1954 /* make the call to remove the driver */ 1850 status = rpccli_spoolss_DeletePrinterDriverEx(cli, mem_ctx,1955 status = dcerpc_spoolss_DeletePrinterDriverEx(b, mem_ctx, 1851 1956 cli->srv_name_slash, 1852 1957 archi_table[i].long_archi, … … 1855 1960 archi_table[i].version, 1856 1961 &result); 1857 1962 if (!NT_STATUS_IS_OK(status)) { 1963 return ntstatus_to_werror(status); 1964 } 1858 1965 if ( !W_ERROR_IS_OK(result) ) 1859 1966 { … … 1885 1992 NTSTATUS status; 1886 1993 int i; 1994 struct dcerpc_binding_handle *b = cli->binding_handle; 1887 1995 1888 1996 /* parse the command arguments */ … … 1897 2005 1898 2006 /* make the call to remove the driver */ 1899 status = rpccli_spoolss_DeletePrinterDriver(cli, mem_ctx,2007 status = dcerpc_spoolss_DeletePrinterDriver(b, mem_ctx, 1900 2008 cli->srv_name_slash, 1901 2009 archi_table[i].long_archi, … … 1903 2011 &result); 1904 2012 if (!NT_STATUS_IS_OK(status)) { 1905 if (W_ERROR_IS_OK(result)) { 1906 result = ntstatus_to_werror(status); 1907 } 2013 result = ntstatus_to_werror(status); 2014 continue; 1908 2015 } 1909 2016 if ( !W_ERROR_IS_OK(result) ) { 1910 2017 if ( !W_ERROR_EQUAL(result, WERR_UNKNOWN_PRINTER_DRIVER) ) { 1911 printf ("Failed to remove driver %s for arch [%s] - error 0x%x!\n",2018 printf ("Failed to remove driver %s for arch [%s] - error %s!\n", 1912 2019 argv[1], archi_table[i].long_archi, 1913 W_ERROR_V(result));2020 win_errstr(result)); 1914 2021 } 1915 2022 } else { … … 1936 2043 union spoolss_PrintProcessorDirectoryInfo info; 1937 2044 uint32_t needed; 2045 struct dcerpc_binding_handle *b = cli->binding_handle; 1938 2046 1939 2047 /* parse the command arguments */ … … 1947 2055 } 1948 2056 1949 status = rpccli_spoolss_GetPrintProcessorDirectory(cli, mem_ctx,2057 status = dcerpc_spoolss_GetPrintProcessorDirectory(b, mem_ctx, 1950 2058 cli->srv_name_slash, 1951 2059 environment, … … 1956 2064 &needed, 1957 2065 &result); 2066 if (!NT_STATUS_IS_OK(status)) { 2067 return ntstatus_to_werror(status); 2068 } 1958 2069 if (W_ERROR_EQUAL(result, WERR_INSUFFICIENT_BUFFER)) { 1959 2070 offered = needed; 1960 2071 buffer = data_blob_talloc_zero(mem_ctx, needed); 1961 2072 1962 status = rpccli_spoolss_GetPrintProcessorDirectory(cli, mem_ctx,2073 status = dcerpc_spoolss_GetPrintProcessorDirectory(b, mem_ctx, 1963 2074 cli->srv_name_slash, 1964 2075 environment, … … 1969 2080 &needed, 1970 2081 &result); 2082 if (!NT_STATUS_IS_OK(status)) { 2083 return ntstatus_to_werror(status); 2084 } 1971 2085 } 1972 2086 … … 1992 2106 struct spoolss_AddFormInfo2 info2; 1993 2107 uint32_t level = 1; 2108 struct dcerpc_binding_handle *b = cli->binding_handle; 1994 2109 1995 2110 /* Parse the command arguments */ … … 2050 2165 2051 2166 break; 2167 default: 2168 werror = WERR_INVALID_PARAM; 2169 goto done; 2052 2170 } 2053 2171 … … 2055 2173 2056 2174 2057 status = rpccli_spoolss_AddForm(cli, mem_ctx,2175 status = dcerpc_spoolss_AddForm(b, mem_ctx, 2058 2176 &handle, 2059 2177 level, 2060 2178 info, 2061 2179 &werror); 2062 2180 if (!NT_STATUS_IS_OK(status)) { 2181 werror = ntstatus_to_werror(status); 2182 goto done; 2183 } 2063 2184 done: 2064 if (is_valid_policy_hnd(&handle)) 2065 rpccli_spoolss_ClosePrinter(cli, mem_ctx, &handle, NULL); 2185 if (is_valid_policy_hnd(&handle)) { 2186 WERROR _result; 2187 dcerpc_spoolss_ClosePrinter(b, mem_ctx, &handle, &_result); 2188 } 2066 2189 2067 2190 return werror; … … 2080 2203 union spoolss_AddFormInfo info; 2081 2204 struct spoolss_AddFormInfo1 info1; 2205 struct dcerpc_binding_handle *b = cli->binding_handle; 2082 2206 2083 2207 /* Parse the command arguments */ … … 2114 2238 /* Set the form */ 2115 2239 2116 status = rpccli_spoolss_SetForm(cli, mem_ctx,2240 status = dcerpc_spoolss_SetForm(b, mem_ctx, 2117 2241 &handle, 2118 2242 argv[2], … … 2120 2244 info, 2121 2245 &werror); 2122 2246 if (!NT_STATUS_IS_OK(status)) { 2247 werror = ntstatus_to_werror(status); 2248 goto done; 2249 } 2123 2250 done: 2124 if (is_valid_policy_hnd(&handle)) 2125 rpccli_spoolss_ClosePrinter(cli, mem_ctx, &handle, NULL); 2251 if (is_valid_policy_hnd(&handle)) { 2252 WERROR _result; 2253 dcerpc_spoolss_ClosePrinter(b, mem_ctx, &handle, &_result); 2254 } 2126 2255 2127 2256 return werror; … … 2197 2326 uint32_t needed; 2198 2327 uint32_t level = 1; 2328 struct dcerpc_binding_handle *b = cli->binding_handle; 2199 2329 2200 2330 /* Parse the command arguments */ … … 2222 2352 /* Get the form */ 2223 2353 2224 status = rpccli_spoolss_GetForm(cli, mem_ctx,2354 status = dcerpc_spoolss_GetForm(b, mem_ctx, 2225 2355 &handle, 2226 2356 argv[2], … … 2231 2361 &needed, 2232 2362 &werror); 2363 if (!NT_STATUS_IS_OK(status)) { 2364 werror = ntstatus_to_werror(status); 2365 goto done; 2366 } 2233 2367 if (W_ERROR_EQUAL(werror, WERR_INSUFFICIENT_BUFFER)) { 2234 2368 buffer = data_blob_talloc_zero(mem_ctx, needed); 2235 2369 offered = needed; 2236 status = rpccli_spoolss_GetForm(cli, mem_ctx,2370 status = dcerpc_spoolss_GetForm(b, mem_ctx, 2237 2371 &handle, 2238 2372 argv[2], … … 2243 2377 &needed, 2244 2378 &werror); 2245 } 2246 2247 if (!NT_STATUS_IS_OK(status)) { 2248 return werror; 2379 if (!NT_STATUS_IS_OK(status)) { 2380 werror = ntstatus_to_werror(status); 2381 goto done; 2382 } 2383 } 2384 2385 if (!W_ERROR_IS_OK(werror)) { 2386 goto done; 2249 2387 } 2250 2388 … … 2259 2397 2260 2398 done: 2261 if (is_valid_policy_hnd(&handle)) 2262 rpccli_spoolss_ClosePrinter(cli, mem_ctx, &handle, NULL); 2399 if (is_valid_policy_hnd(&handle)) { 2400 WERROR _result; 2401 dcerpc_spoolss_ClosePrinter(b, mem_ctx, &handle, &_result); 2402 } 2263 2403 2264 2404 return werror; … … 2276 2416 NTSTATUS status; 2277 2417 const char *printername; 2418 struct dcerpc_binding_handle *b = cli->binding_handle; 2278 2419 2279 2420 /* Parse the command arguments */ … … 2297 2438 /* Delete the form */ 2298 2439 2299 status = rpccli_spoolss_DeleteForm(cli, mem_ctx,2440 status = dcerpc_spoolss_DeleteForm(b, mem_ctx, 2300 2441 &handle, 2301 2442 argv[2], 2302 2443 &werror); 2303 2444 if (!NT_STATUS_IS_OK(status)) { 2304 return ntstatus_to_werror(status); 2445 werror = ntstatus_to_werror(status); 2446 goto done; 2305 2447 } 2306 2448 2307 2449 done: 2308 if (is_valid_policy_hnd(&handle)) 2309 rpccli_spoolss_ClosePrinter(cli, mem_ctx, &handle, NULL); 2450 if (is_valid_policy_hnd(&handle)) { 2451 WERROR _result; 2452 dcerpc_spoolss_ClosePrinter(b, mem_ctx, &handle, &_result); 2453 } 2310 2454 2311 2455 return werror; … … 2324 2468 uint32_t num_forms, level = 1, i; 2325 2469 union spoolss_FormInfo *forms; 2470 struct dcerpc_binding_handle *b = cli->binding_handle; 2326 2471 2327 2472 /* Parse the command arguments */ … … 2373 2518 2374 2519 done: 2375 if (is_valid_policy_hnd(&handle)) 2376 rpccli_spoolss_ClosePrinter(cli, mem_ctx, &handle, NULL); 2520 if (is_valid_policy_hnd(&handle)) { 2521 WERROR _result; 2522 dcerpc_spoolss_ClosePrinter(b, mem_ctx, &handle, &_result); 2523 } 2377 2524 2378 2525 return werror; … … 2394 2541 union spoolss_PrinterData data; 2395 2542 DATA_BLOB blob; 2543 struct dcerpc_binding_handle *b = cli->binding_handle; 2396 2544 2397 2545 /* parse the command arguments */ … … 2400 2548 " <value> <data>\n", 2401 2549 argv[0]); 2402 result = WERR_INVALID_PARAM; 2403 goto done; 2550 return WERR_OK; 2404 2551 } 2405 2552 … … 2501 2648 } 2502 2649 2503 status = rpccli_spoolss_SetPrinterData(cli, mem_ctx,2650 status = dcerpc_spoolss_SetPrinterData(b, mem_ctx, 2504 2651 &pol, 2505 2652 argv[3], /* value_name */ … … 2508 2655 blob.length, 2509 2656 &result); 2657 if (!NT_STATUS_IS_OK(status)) { 2658 printf ("Unable to set [%s=%s]!\n", argv[3], argv[4]); 2659 result = ntstatus_to_werror(status); 2660 goto done; 2661 } 2510 2662 if (!W_ERROR_IS_OK(result)) { 2511 2663 printf ("Unable to set [%s=%s]!\n", argv[3], argv[4]); … … 2529 2681 /* cleanup */ 2530 2682 if (is_valid_policy_hnd(&pol)) { 2531 rpccli_spoolss_ClosePrinter(cli, mem_ctx, &pol, NULL); 2683 WERROR _result; 2684 dcerpc_spoolss_ClosePrinter(b, mem_ctx, &pol, &_result); 2532 2685 } 2533 2686 … … 2588 2741 struct policy_handle hnd; 2589 2742 union spoolss_JobInfo *info; 2743 struct dcerpc_binding_handle *b = cli->binding_handle; 2590 2744 2591 2745 if (argc < 2 || argc > 3) { … … 2639 2793 done: 2640 2794 if (is_valid_policy_hnd(&hnd)) { 2641 rpccli_spoolss_ClosePrinter(cli, mem_ctx, &hnd, NULL); 2795 WERROR _result; 2796 dcerpc_spoolss_ClosePrinter(b, mem_ctx, &hnd, &_result); 2642 2797 } 2643 2798 … … 2658 2813 uint32_t level = 1; 2659 2814 union spoolss_JobInfo info; 2815 struct dcerpc_binding_handle *b = cli->binding_handle; 2660 2816 2661 2817 if (argc < 3 || argc > 4) { … … 2715 2871 done: 2716 2872 if (is_valid_policy_hnd(&hnd)) { 2717 rpccli_spoolss_ClosePrinter(cli, mem_ctx, &hnd, NULL); 2873 WERROR _result; 2874 dcerpc_spoolss_ClosePrinter(b, mem_ctx, &hnd, &_result); 2718 2875 } 2719 2876 … … 2723 2880 /**************************************************************************** 2724 2881 ****************************************************************************/ 2882 2883 static struct { 2884 const char *name; 2885 enum spoolss_JobControl val; 2886 } cmdvals[] = { 2887 {"PAUSE", SPOOLSS_JOB_CONTROL_PAUSE}, 2888 {"RESUME", SPOOLSS_JOB_CONTROL_RESUME}, 2889 {"CANCEL", SPOOLSS_JOB_CONTROL_CANCEL}, 2890 {"RESTART", SPOOLSS_JOB_CONTROL_RESTART}, 2891 {"DELETE", SPOOLSS_JOB_CONTROL_DELETE}, 2892 {"SEND_TO_PRINTER", SPOOLSS_JOB_CONTROL_SEND_TO_PRINTER}, 2893 {"EJECTED", SPOOLSS_JOB_CONTROL_LAST_PAGE_EJECTED}, 2894 {"RETAIN", SPOOLSS_JOB_CONTROL_RETAIN}, 2895 {"RELEASE", SPOOLSS_JOB_CONTROL_RELEASE} 2896 }; 2897 2898 static enum spoolss_JobControl parse_setjob_command(const char *cmd) 2899 { 2900 int i; 2901 2902 for (i = 0; i < sizeof(cmdvals)/sizeof(cmdvals[0]); i++) { 2903 if (strequal(cmdvals[i].name, cmd)) { 2904 return cmdvals[i].val; 2905 } 2906 } 2907 return (enum spoolss_JobControl)atoi(cmd); 2908 } 2725 2909 2726 2910 static WERROR cmd_spoolss_set_job(struct rpc_pipe_client *cli, … … 2734 2918 uint32_t job_id; 2735 2919 enum spoolss_JobControl command; 2920 struct dcerpc_binding_handle *b = cli->binding_handle; 2736 2921 2737 2922 if (argc != 4) { 2738 2923 printf("Usage: %s printername job_id command\n", argv[0]); 2924 printf("command = [PAUSE|RESUME|CANCEL|RESTART|DELETE|" 2925 "SEND_TO_PRINTER|EJECTED|RETAIN|RELEASE]\n"); 2739 2926 return WERR_OK; 2740 2927 } 2741 2928 2742 2929 job_id = atoi(argv[2]); 2743 command = atoi(argv[3]);2930 command = parse_setjob_command(argv[3]); 2744 2931 2745 2932 /* Open printer handle */ … … 2757 2944 /* Set Job */ 2758 2945 2759 status = rpccli_spoolss_SetJob(cli, mem_ctx,2946 status = dcerpc_spoolss_SetJob(b, mem_ctx, 2760 2947 &hnd, 2761 2948 job_id, … … 2763 2950 command, 2764 2951 &result); 2765 2952 if (!NT_STATUS_IS_OK(status)) { 2953 result = ntstatus_to_werror(status); 2954 goto done; 2955 } 2766 2956 if (!W_ERROR_IS_OK(result)) { 2767 2957 goto done; … … 2770 2960 done: 2771 2961 if (is_valid_policy_hnd(&hnd)) { 2772 rpccli_spoolss_ClosePrinter(cli, mem_ctx, &hnd, NULL); 2962 WERROR _result; 2963 dcerpc_spoolss_ClosePrinter(b, mem_ctx, &hnd, &_result); 2773 2964 } 2774 2965 … … 2785 2976 WERROR result; 2786 2977 NTSTATUS status; 2787 uint32_t i = 0;2788 2978 const char *printername; 2789 2979 struct policy_handle hnd; 2790 uint32_t value_offered = 0;2791 const char *value_name = NULL;2792 2980 uint32_t value_needed; 2793 2981 enum winreg_Type type; 2794 uint8_t *data = NULL;2795 uint32_t data_offered = 0;2796 2982 uint32_t data_needed; 2983 struct dcerpc_binding_handle *b = cli->binding_handle; 2984 struct spoolss_EnumPrinterData r; 2797 2985 2798 2986 if (argc != 2) { … … 2815 3003 /* Enumerate data */ 2816 3004 2817 status = rpccli_spoolss_EnumPrinterData(cli, mem_ctx, 2818 &hnd, 2819 i, 2820 value_name, 2821 value_offered, 2822 &value_needed, 2823 &type, 2824 data, 2825 data_offered, 2826 &data_needed, 2827 &result); 2828 2829 data_offered = data_needed; 2830 value_offered = value_needed; 2831 data = talloc_zero_array(mem_ctx, uint8_t, data_needed); 2832 value_name = talloc_zero_array(mem_ctx, char, value_needed); 2833 2834 while (NT_STATUS_IS_OK(status) && W_ERROR_IS_OK(result)) { 2835 2836 status = rpccli_spoolss_EnumPrinterData(cli, mem_ctx, 2837 &hnd, 2838 i++, 2839 value_name, 2840 value_offered, 2841 &value_needed, 2842 &type, 2843 data, 2844 data_offered, 2845 &data_needed, 2846 &result); 2847 if (NT_STATUS_IS_OK(status) && W_ERROR_IS_OK(result)) { 2848 struct regval_blob v; 2849 fstrcpy(v.valuename, value_name); 2850 v.type = type; 2851 v.size = data_offered; 2852 v.data_p = data; 3005 r.in.handle = &hnd; 3006 r.in.enum_index = 0; 3007 r.in.value_offered = 0; 3008 r.in.data_offered = 0; 3009 r.out.value_name = NULL; 3010 r.out.value_needed = &value_needed; 3011 r.out.type = &type; 3012 r.out.data = NULL; 3013 r.out.data_needed = &data_needed; 3014 3015 status = dcerpc_spoolss_EnumPrinterData_r(b, mem_ctx, &r); 3016 if (!NT_STATUS_IS_OK(status)) { 3017 result = ntstatus_to_werror(status); 3018 goto done; 3019 } 3020 3021 if (!W_ERROR_IS_OK(r.out.result)) { 3022 result = r.out.result; 3023 goto done; 3024 } 3025 3026 r.in.data_offered = *r.out.data_needed; 3027 r.in.value_offered = *r.out.value_needed; 3028 r.out.data = talloc_zero_array(mem_ctx, uint8_t, r.in.data_offered); 3029 r.out.value_name = talloc_zero_array(mem_ctx, char, r.in.value_offered); 3030 3031 do { 3032 3033 status = dcerpc_spoolss_EnumPrinterData_r(b, mem_ctx, &r); 3034 if (!NT_STATUS_IS_OK(status)) { 3035 result = ntstatus_to_werror(status); 3036 goto done; 3037 } 3038 3039 if (W_ERROR_EQUAL(r.out.result, WERR_NO_MORE_ITEMS)) { 3040 result = WERR_OK; 3041 break; 3042 } 3043 3044 r.in.enum_index++; 3045 3046 { 3047 struct regval_blob *v; 3048 3049 v = regval_compose(talloc_tos(), 3050 r.out.value_name, 3051 *r.out.type, 3052 r.out.data, 3053 r.in.data_offered); 3054 if (v == NULL) { 3055 result = WERR_NOMEM; 3056 goto done; 3057 } 3058 2853 3059 display_reg_value(v); 2854 } 2855 } 2856 2857 if (W_ERROR_V(result) == ERRnomoreitems) { 2858 result = W_ERROR(ERRsuccess); 2859 } 3060 talloc_free(v); 3061 } 3062 3063 } while (W_ERROR_IS_OK(r.out.result)); 2860 3064 2861 3065 done: 2862 3066 if (is_valid_policy_hnd(&hnd)) { 2863 rpccli_spoolss_ClosePrinter(cli, mem_ctx, &hnd, NULL); 3067 WERROR _result; 3068 dcerpc_spoolss_ClosePrinter(b, mem_ctx, &hnd, &_result); 2864 3069 } 2865 3070 … … 2880 3085 uint32_t count; 2881 3086 struct spoolss_PrinterEnumValues *info; 3087 struct dcerpc_binding_handle *b = cli->binding_handle; 2882 3088 2883 3089 if (argc != 3) { … … 2919 3125 done: 2920 3126 if (is_valid_policy_hnd(&hnd)) { 2921 rpccli_spoolss_ClosePrinter(cli, mem_ctx, &hnd, NULL); 3127 WERROR _result; 3128 dcerpc_spoolss_ClosePrinter(b, mem_ctx, &hnd, &_result); 2922 3129 } 2923 3130 … … 2939 3146 int i; 2940 3147 uint32_t offered = 0; 3148 struct dcerpc_binding_handle *b = cli->binding_handle; 2941 3149 2942 3150 if (argc < 2 || argc > 4) { … … 2986 3194 2987 3195 if (is_valid_policy_hnd(&hnd)) { 2988 rpccli_spoolss_ClosePrinter(cli, mem_ctx, &hnd, NULL); 3196 WERROR _result; 3197 dcerpc_spoolss_ClosePrinter(b, mem_ctx, &hnd, &_result); 2989 3198 } 2990 3199 … … 3005 3214 NTSTATUS status; 3006 3215 struct spoolss_NotifyOption option; 3216 struct dcerpc_binding_handle *b = cli->binding_handle; 3007 3217 3008 3218 if (argc != 2) { … … 3062 3272 /* Send rffpcnex */ 3063 3273 3064 status = rpccli_spoolss_RemoteFindFirstPrinterChangeNotifyEx(cli, mem_ctx,3274 status = dcerpc_spoolss_RemoteFindFirstPrinterChangeNotifyEx(b, mem_ctx, 3065 3275 &hnd, 3066 3276 0, … … 3070 3280 &option, 3071 3281 &result); 3282 if (!NT_STATUS_IS_OK(status)) { 3283 result = ntstatus_to_werror(status); 3284 goto done; 3285 } 3072 3286 if (!W_ERROR_IS_OK(result)) { 3073 3287 printf("Error rffpcnex %s\n", argv[1]); … … 3076 3290 3077 3291 done: 3078 if (is_valid_policy_hnd(&hnd)) 3079 rpccli_spoolss_ClosePrinter(cli, mem_ctx, &hnd, NULL); 3292 if (is_valid_policy_hnd(&hnd)) { 3293 WERROR _result; 3294 dcerpc_spoolss_ClosePrinter(b, mem_ctx, &hnd, &_result); 3295 } 3080 3296 3081 3297 return result; … … 3132 3348 WERROR werror; 3133 3349 TALLOC_CTX *mem_ctx = talloc_init("compare_printer_secdesc"); 3134 SEC_DESC*sd1, *sd2;3350 struct security_descriptor *sd1, *sd2; 3135 3351 bool result = true; 3136 3352 … … 3221 3437 get_cmdline_auth_info_password(rpcclient_auth_info), 3222 3438 get_cmdline_auth_info_use_kerberos(rpcclient_auth_info) ? CLI_FULL_CONNECTION_USE_KERBEROS : 0, 3223 get_cmdline_auth_info_signing_state(rpcclient_auth_info) , NULL);3439 get_cmdline_auth_info_signing_state(rpcclient_auth_info)); 3224 3440 3225 3441 if ( !NT_STATUS_IS_OK(nt_status) ) … … 3274 3490 3275 3491 printf("Closing printers..."); 3276 rpccli_spoolss_ClosePrinter( cli, mem_ctx, &hPrinter1, NULL ); 3277 rpccli_spoolss_ClosePrinter( cli2, mem_ctx, &hPrinter2, NULL ); 3492 { 3493 WERROR _result; 3494 dcerpc_spoolss_ClosePrinter(cli->binding_handle, mem_ctx, &hPrinter1, &_result); 3495 dcerpc_spoolss_ClosePrinter(cli2->binding_handle, mem_ctx, &hPrinter2, &_result); 3496 } 3278 3497 printf("ok\n"); 3279 3498 … … 3463 3682 const char *printername; 3464 3683 struct spoolss_DevmodeContainer devmode_ctr; 3684 struct dcerpc_binding_handle *b = cli->binding_handle; 3465 3685 3466 3686 RPCCLIENT_PRINTERNAME(printername, cli, argv[1]); … … 3476 3696 ZERO_STRUCT(devmode_ctr); 3477 3697 3478 status = rpccli_spoolss_CreatePrinterIC(cli, mem_ctx,3698 status = dcerpc_spoolss_CreatePrinterIC(b, mem_ctx, 3479 3699 &handle, 3480 3700 &gdi_handle, 3481 3701 &devmode_ctr, 3482 3702 &result); 3703 if (!NT_STATUS_IS_OK(status)) { 3704 result = ntstatus_to_werror(status); 3705 goto done; 3706 } 3483 3707 if (!W_ERROR_IS_OK(result)) { 3484 3708 goto done; … … 3487 3711 done: 3488 3712 if (is_valid_policy_hnd(&gdi_handle)) { 3489 rpccli_spoolss_DeletePrinterIC(cli, mem_ctx, &gdi_handle, NULL); 3713 WERROR _result; 3714 dcerpc_spoolss_DeletePrinterIC(b, mem_ctx, &gdi_handle, &_result); 3490 3715 } 3491 3716 if (is_valid_policy_hnd(&handle)) { 3492 rpccli_spoolss_ClosePrinter(cli, mem_ctx, &handle, NULL); 3717 WERROR _result; 3718 dcerpc_spoolss_ClosePrinter(b, mem_ctx, &handle, &_result); 3493 3719 } 3494 3720 … … 3519 3745 { "getdriverdir", RPC_RTYPE_WERROR, NULL, cmd_spoolss_getdriverdir, &ndr_table_spoolss.syntax_id, NULL, "Get print driver upload directory", "" }, 3520 3746 { "getprinter", RPC_RTYPE_WERROR, NULL, cmd_spoolss_getprinter, &ndr_table_spoolss.syntax_id, NULL, "Get printer info", "" }, 3521 { "openprinter", RPC_RTYPE_WERROR, NULL, cmd_spoolss_open_printer_ex, &ndr_table_spoolss.syntax_id, NULL, "Open printer handle", "" }, 3747 { "openprinter", RPC_RTYPE_WERROR, NULL, cmd_spoolss_open_printer, &ndr_table_spoolss.syntax_id, NULL, "Open printer handle", "" }, 3748 { "openprinter_ex", RPC_RTYPE_WERROR, NULL, cmd_spoolss_open_printer_ex, &ndr_table_spoolss.syntax_id, NULL, "Open printer handle", "" }, 3522 3749 { "setdriver", RPC_RTYPE_WERROR, NULL, cmd_spoolss_setdriver, &ndr_table_spoolss.syntax_id, NULL, "Set printer driver", "" }, 3523 3750 { "getprintprocdir", RPC_RTYPE_WERROR, NULL, cmd_spoolss_getprintprocdir, &ndr_table_spoolss.syntax_id, NULL, "Get print processor directory", "" },
Note:
See TracChangeset
for help on using the changeset viewer.