Changeset 740 for vendor/current/source3/utils/net_rpc_printer.c
- Timestamp:
- Nov 14, 2012, 12:59:34 PM (13 years ago)
- File:
-
- 1 edited
-
vendor/current/source3/utils/net_rpc_printer.c (modified) (82 diffs)
Legend:
- Unmodified
- Added
- Removed
-
vendor/current/source3/utils/net_rpc_printer.c
r597 r740 18 18 */ 19 19 #include "includes.h" 20 20 21 #include "utils/net.h" 21 #include "../librpc/gen_ndr/cli_spoolss.h" 22 #include "rpc_client/rpc_client.h" 23 #include "../librpc/gen_ndr/ndr_spoolss_c.h" 24 #include "rpc_client/cli_spoolss.h" 25 #include "rpc_client/init_spoolss.h" 26 #include "nt_printing.h" 27 #include "registry/reg_objects.h" 28 #include "../libcli/security/security.h" 29 #include "../libcli/registry/util_reg.h" 30 #include "libsmb/libsmb.h" 22 31 23 32 /* support itanium as well */ … … 62 71 printf(_("\tHelpfile: [%s]\n\n"), r->help_file); 63 72 64 for (i=0; r->dependent_files [i] != NULL; i++) {73 for (i=0; r->dependent_files[i] != NULL; i++) { 65 74 printf(_("\tDependentfiles: [%s]\n"), r->dependent_files[i]); 66 75 } … … 72 81 } 73 82 74 static void display_reg_value(const char *subkey, struct regval_blob value)83 static void display_reg_value(const char *subkey, struct regval_blob value) 75 84 { 76 85 const char *text; 77 86 DATA_BLOB blob; 78 87 79 switch( value.type) {88 switch() { 80 89 case REG_DWORD: 81 90 d_printf(_("\t[%s:%s]: REG_DWORD: 0x%08x\n"), subkey, 82 value.valuename, *((uint32_t *) value.data_p));91 )); 83 92 break; 84 93 85 94 case REG_SZ: 86 blob = data_blob_const( value.data_p, value.size);95 blob = data_blob_const(); 87 96 pull_reg_sz(talloc_tos(), &blob, &text); 88 97 if (!text) { 89 98 break; 90 99 } 91 d_printf(_("\t[%s:%s]: REG_SZ: %s\n"), subkey, value.valuename,100 d_printf(_("\t[%s:%s]: REG_SZ: %s\n"), subkey, , 92 101 text); 93 102 break; … … 96 105 d_printf(_("\t[%s:%s]: REG_BINARY: unknown length value not " 97 106 "displayed\n"), 98 subkey, value.valuename);107 subkey, ); 99 108 break; 100 109 … … 102 111 uint32_t i; 103 112 const char **values; 104 blob = data_blob_const( value.data_p, value.size);113 blob = data_blob_const(); 105 114 106 115 if (!pull_reg_multi_sz(NULL, &blob, &values)) { … … 109 118 } 110 119 111 printf("%s: REG_MULTI_SZ: \n", value.valuename);120 printf("%s: REG_MULTI_SZ: \n", ); 112 121 for (i=0; values[i] != NULL; i++) { 113 122 d_printf("%s\n", values[i]); … … 118 127 119 128 default: 120 d_printf(_("\t%s: unknown type %d\n"), value.valuename,121 value.type);129 d_printf(_("\t%s: unknown type %d\n"), , 130 ); 122 131 } 123 132 … … 153 162 uint16_t fnum_src = 0; 154 163 uint16_t fnum_dst = 0; 155 SEC_DESC*sd = NULL;164 *sd = NULL; 156 165 uint16_t attr; 157 166 time_t f_atime, f_ctime, f_mtime; … … 226 235 227 236 if (copy_acls) { 237 228 238 229 239 /* set acls */ 230 if (!cli_set_secdesc(cli_share_dst, fnum_dst, sd)) { 231 DEBUG(0,("could not set secdesc on %s: %s\n", 232 dst_name, cli_errstr(cli_share_dst))); 233 nt_status = cli_nt_error(cli_share_dst); 240 status = cli_set_secdesc(cli_share_dst, fnum_dst, sd); 241 if (!NT_STATUS_IS_OK(status)) { 242 DEBUG(0, ("could not set secdesc on %s: %s\n", 243 dst_name, nt_errstr(status))); 244 nt_status = status; 234 245 goto out; 235 246 } … … 377 388 378 389 /* copying file */ 379 int n , ret;390 int n; 380 391 n = cli_read(cli_share_src, fnum_src, data, nread, 381 392 read_size); … … 384 395 break; 385 396 386 ret = cli_write(cli_share_dst, fnum_dst, 0, data,387 nread, n);388 389 if ( n != ret) {397 , 398 ); 399 400 if () { 390 401 d_fprintf(stderr, _("Error writing file: %s\n"), 391 cli_errstr(cli_share_dst)); 392 nt_status = cli_nt_error(cli_share_dst); 402 nt_errstr(nt_status)); 393 403 goto out; 394 404 } … … 487 497 const char *file, const char *short_archi) { 488 498 489 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;490 499 const char *p; 491 500 char *src_name; 492 501 char *dst_name; 493 char *version ;494 char *filename ;502 char *version; 503 char *filename; 495 504 char *tok; 496 505 … … 509 518 } 510 519 520 521 522 523 511 524 /* build source file name */ 512 if (asprintf(&src_name, "\\%s\\%s\\%s", short_archi, version, filename) < 0 ) 525 src_name = talloc_asprintf(mem_ctx, "\\%s\\%s\\%s", 526 short_archi, version, filename); 527 if (src_name == NULL) { 513 528 return NT_STATUS_NO_MEMORY; 514 529 } 515 530 516 531 /* create destination file name */ 517 if (asprintf(&dst_name, "\\%s\\%s", short_archi, filename) < 0 ) 518 return NT_STATUS_NO_MEMORY; 532 dst_name = talloc_asprintf(mem_ctx, "\\%s\\%s", short_archi, filename); 533 if (dst_name == NULL) { 534 return NT_STATUS_NO_MEMORY; 535 } 519 536 520 537 521 538 /* finally copy the file */ 522 nt_status = net_copy_file(c, mem_ctx, cli_share_src, cli_share_dst, 523 src_name, dst_name, false, false, false, true); 524 if (!NT_STATUS_IS_OK(nt_status)) 525 goto out; 526 527 nt_status = NT_STATUS_OK; 528 529 out: 530 SAFE_FREE(src_name); 531 SAFE_FREE(dst_name); 532 533 return nt_status; 539 return net_copy_file(c, mem_ctx, cli_share_src, cli_share_dst, 540 src_name, dst_name, false, false, false, true); 534 541 } 535 542 … … 752 759 union spoolss_PrinterInfo *info) 753 760 { 761 754 762 WERROR result; 755 763 NTSTATUS status; … … 812 820 } 813 821 814 status = rpccli_spoolss_SetPrinter(pipe_hnd, mem_ctx,822 status = , mem_ctx, 815 823 hnd, 816 824 &info_ctr, … … 819 827 0, /* command */ 820 828 &result); 821 829 if (!NT_STATUS_IS_OK(status)) { 830 printf(_("cannot set printer-info: %s\n"), nt_errstr(status)); 831 return false; 832 } 822 833 if (!W_ERROR_IS_OK(result)) { 823 834 printf(_("cannot set printer-info: %s\n"), win_errstr(result)); … … 837 848 uint32_t offered) 838 849 { 850 839 851 WERROR result; 840 852 NTSTATUS status; 841 853 842 854 /* setprinterdata call */ 843 status = rpccli_spoolss_SetPrinterData(pipe_hnd, mem_ctx,855 status = , mem_ctx, 844 856 hnd, 845 857 value_name, … … 848 860 offered, 849 861 &result); 850 862 if (!NT_STATUS_IS_OK(status)) { 863 printf (_("unable to set printerdata: %s\n"), 864 nt_errstr(status)); 865 return false; 866 } 851 867 if (!W_ERROR_IS_OK(result)) { 852 868 printf (_("unable to set printerdata: %s\n"), … … 911 927 struct regval_blob *value) 912 928 { 929 913 930 WERROR result; 914 931 NTSTATUS status; 915 932 916 933 /* setprinterdataex call */ 917 status = rpccli_spoolss_SetPrinterDataEx(pipe_hnd, mem_ctx,934 status = , mem_ctx, 918 935 hnd, 919 936 keyname, 920 value->valuename,921 value->type,922 value->data_p,923 value->size,937 , 938 , 939 , 940 , 924 941 &result); 925 942 if (!NT_STATUS_IS_OK(status)) { 943 printf(_("could not set printerdataex: %s\n"), 944 nt_errstr(status)); 945 return false; 946 } 926 947 if (!W_ERROR_IS_OK(result)) { 927 948 printf(_("could not set printerdataex: %s\n"), … … 974 995 info); 975 996 if (!W_ERROR_IS_OK(result)) { 976 printf(_("cannot enum drivers: %s\n"), win_errstr(result)); 977 return false; 997 if (W_ERROR_V(result) != W_ERROR_V(WERR_INVALID_ENVIRONMENT)) { 998 printf(_("cannot enum drivers for environment %s: %s\n"), env, 999 win_errstr(result)); 1000 return false; 1001 } else { 1002 printf(_("Server does not support environment [%s]\n"), 1003 env); 1004 } 978 1005 } 979 1006 … … 1021 1048 union spoolss_DriverInfo *info) 1022 1049 { 1050 1023 1051 WERROR result; 1024 1052 NTSTATUS status; … … 1042 1070 1043 1071 /* addprinterdriver call */ 1044 status = rpccli_spoolss_AddPrinterDriver(pipe_hnd, mem_ctx,1072 status = , mem_ctx, 1045 1073 pipe_hnd->srv_name_slash, 1046 1074 &info_ctr, 1047 1075 &result); 1076 1077 1078 1079 1048 1080 /* be more verbose */ 1049 1081 if (W_ERROR_V(result) == W_ERROR_V(WERR_ACCESS_DENIED)) { … … 1072 1104 union spoolss_PrinterInfo **info_p) 1073 1105 { 1106 1074 1107 struct policy_handle hnd; 1108 1075 1109 1076 1110 /* no arguments given, enumerate all printers */ … … 1098 1132 1099 1133 if (!net_spoolss_getprinter(pipe_hnd, mem_ctx, &hnd, level, *info_p)) { 1100 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd, NULL);1134 ); 1101 1135 return false; 1102 1136 } 1103 1137 1104 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd, NULL);1138 ); 1105 1139 1106 1140 *num_printers = 1; … … 1131 1165 1132 1166 NTSTATUS rpc_printer_list_internals(struct net_context *c, 1133 const DOM_SID*domain_sid,1167 const *domain_sid, 1134 1168 const char *domain_name, 1135 1169 struct cli_state *cli, … … 1183 1217 1184 1218 NTSTATUS rpc_printer_driver_list_internals(struct net_context *c, 1185 const DOM_SID*domain_sid,1219 const *domain_sid, 1186 1220 const char *domain_name, 1187 1221 struct cli_state *cli, … … 1254 1288 uint32_t action) 1255 1289 { 1290 1256 1291 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; 1257 1292 uint32_t i, num_printers; … … 1301 1336 default: 1302 1337 action_str = N_("unknown action"); 1303 printf(_("unk own action: %d\n"), action);1338 printf(_("unkown action: %d\n"), action); 1304 1339 break; 1305 1340 } … … 1313 1348 ZERO_STRUCT(secdesc_ctr); 1314 1349 1315 nt_status = rpccli_spoolss_SetPrinter(pipe_hnd, mem_ctx,1350 nt_status = , mem_ctx, 1316 1351 &hnd, 1317 1352 &info_ctr, … … 1320 1355 0, /* command */ 1321 1356 &result); 1322 1323 if (!W_ERROR_IS_OK(result) && (W_ERROR_V(result) != W_ERROR_V(WERR_IO_PENDING))) { 1357 if (!NT_STATUS_IS_OK(nt_status)) { 1324 1358 printf(_("cannot set printer-info: %s\n"), 1325 win_errstr(result)); 1359 nt_errstr(nt_status)); 1360 goto done; 1361 } 1362 if (!W_ERROR_IS_OK(result) && !W_ERROR_EQUAL(result, WERR_IO_PENDING)) { 1363 if ((action == DSPRINT_UPDATE) && W_ERROR_EQUAL(result, W_ERROR(0x80070002))) { 1364 printf(_("printer not published yet\n")); 1365 } else { 1366 printf(_("cannot set printer-info: %s\n"), 1367 win_errstr(result)); 1368 } 1369 nt_status = werror_to_ntstatus(result); 1326 1370 goto done; 1327 1371 } … … 1334 1378 1335 1379 done: 1336 if (is_valid_policy_hnd(&hnd)) 1337 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd, NULL); 1380 if (is_valid_policy_hnd(&hnd)) { 1381 dcerpc_spoolss_ClosePrinter(b, mem_ctx, &hnd, &result); 1382 } 1338 1383 1339 1384 return nt_status; … … 1341 1386 1342 1387 NTSTATUS rpc_printer_publish_publish_internals(struct net_context *c, 1343 const DOM_SID*domain_sid,1388 const *domain_sid, 1344 1389 const char *domain_name, 1345 1390 struct cli_state *cli, … … 1353 1398 1354 1399 NTSTATUS rpc_printer_publish_unpublish_internals(struct net_context *c, 1355 const DOM_SID*domain_sid,1400 const *domain_sid, 1356 1401 const char *domain_name, 1357 1402 struct cli_state *cli, … … 1365 1410 1366 1411 NTSTATUS rpc_printer_publish_update_internals(struct net_context *c, 1367 const DOM_SID*domain_sid,1412 const *domain_sid, 1368 1413 const char *domain_name, 1369 1414 struct cli_state *cli, … … 1394 1439 1395 1440 NTSTATUS rpc_printer_publish_list_internals(struct net_context *c, 1396 const DOM_SID*domain_sid,1441 const *domain_sid, 1397 1442 const char *domain_name, 1398 1443 struct cli_state *cli, … … 1402 1447 const char **argv) 1403 1448 { 1449 1404 1450 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; 1405 1451 uint32_t i, num_printers; … … 1410 1456 struct policy_handle hnd; 1411 1457 int state; 1458 1412 1459 1413 1460 if (!get_printer_info(pipe_hnd, mem_ctx, 2, argc, argv, &num_printers, &info_enum)) … … 1454 1501 break; 1455 1502 default: 1456 printf(_("unk own state: %d\n"), state);1503 printf(_("unkown state: %d\n"), state); 1457 1504 break; 1458 1505 } … … 1462 1509 1463 1510 done: 1464 if (is_valid_policy_hnd(&hnd)) 1465 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd, NULL); 1511 if (is_valid_policy_hnd(&hnd)) { 1512 dcerpc_spoolss_ClosePrinter(b, mem_ctx, &hnd, &werr); 1513 } 1466 1514 1467 1515 return nt_status; … … 1486 1534 1487 1535 NTSTATUS rpc_printer_migrate_security_internals(struct net_context *c, 1488 const DOM_SID*domain_sid,1536 const *domain_sid, 1489 1537 const char *domain_name, 1490 1538 struct cli_state *cli, … … 1494 1542 const char **argv) 1495 1543 { 1544 1496 1545 /* TODO: what now, info2 or info3 ? 1497 1546 convince jerry that we should add clientside setacls level 3 at least … … 1503 1552 const char *printername, *sharename; 1504 1553 struct rpc_pipe_client *pipe_hnd_dst = NULL; 1554 1505 1555 struct policy_handle hnd_src, hnd_dst; 1506 1556 union spoolss_PrinterInfo *info_enum; 1507 1557 struct cli_state *cli_dst = NULL; 1508 1558 union spoolss_PrinterInfo info_src, info_dst; 1559 1509 1560 1510 1561 DEBUG(3,("copying printer ACLs\n")); … … 1513 1564 nt_status = connect_dst_pipe(c, &cli_dst, &pipe_hnd_dst, 1514 1565 &ndr_table_spoolss.syntax_id); 1515 if (!NT_STATUS_IS_OK(nt_status)) 1566 if (!NT_STATUS_IS_OK(nt_status)) 1516 1567 return nt_status; 1517 1568 } 1569 b_dst = pipe_hnd_dst->binding_handle; 1518 1570 1519 1571 /* enum source printers */ … … 1589 1641 /* close printer handles here */ 1590 1642 if (is_valid_policy_hnd(&hnd_src)) { 1591 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);1643 ); 1592 1644 } 1593 1645 1594 1646 if (is_valid_policy_hnd(&hnd_dst)) { 1595 rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);1647 ); 1596 1648 } 1597 1649 … … 1603 1655 1604 1656 if (is_valid_policy_hnd(&hnd_src)) { 1605 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);1657 ); 1606 1658 } 1607 1659 1608 1660 if (is_valid_policy_hnd(&hnd_dst)) { 1609 rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);1661 ); 1610 1662 } 1611 1663 … … 1634 1686 1635 1687 NTSTATUS rpc_printer_migrate_forms_internals(struct net_context *c, 1636 const DOM_SID*domain_sid,1688 const *domain_sid, 1637 1689 const char *domain_name, 1638 1690 struct cli_state *cli, … … 1642 1694 const char **argv) 1643 1695 { 1696 1644 1697 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; 1645 1698 WERROR result; … … 1649 1702 const char *printername, *sharename; 1650 1703 struct rpc_pipe_client *pipe_hnd_dst = NULL; 1704 1651 1705 struct policy_handle hnd_src, hnd_dst; 1652 1706 union spoolss_PrinterInfo *info_enum; … … 1661 1715 nt_status = connect_dst_pipe(c, &cli_dst, &pipe_hnd_dst, 1662 1716 &ndr_table_spoolss.syntax_id); 1663 if (!NT_STATUS_IS_OK(nt_status)) 1717 if (!NT_STATUS_IS_OK(nt_status)) 1664 1718 return nt_status; 1719 1720 1665 1721 1666 1722 /* enum src printers */ … … 1737 1793 /* FIXME: there might be something wrong with samba's 1738 1794 builtin-forms */ 1739 status = rpccli_spoolss_AddForm(pipe_hnd_dst, mem_ctx,1795 status = _dst, mem_ctx, 1740 1796 &hnd_dst, 1741 1797 1, 1742 1798 info, 1743 1799 &result); 1800 1801 1802 1803 1804 1744 1805 if (!W_ERROR_IS_OK(result)) { 1745 1806 d_printf(_("\tAddForm form %d: [%s] refused.\n"), … … 1755 1816 /* close printer handles here */ 1756 1817 if (is_valid_policy_hnd(&hnd_src)) { 1757 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);1818 ); 1758 1819 } 1759 1820 1760 1821 if (is_valid_policy_hnd(&hnd_dst)) { 1761 rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);1822 ); 1762 1823 } 1763 1824 } … … 1767 1828 done: 1768 1829 1769 if (is_valid_policy_hnd(&hnd_src)) 1770 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL); 1771 1772 if (is_valid_policy_hnd(&hnd_dst)) 1773 rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL); 1830 if (is_valid_policy_hnd(&hnd_src)) { 1831 dcerpc_spoolss_ClosePrinter(b_src, mem_ctx, &hnd_src, &result); 1832 } 1833 1834 if (is_valid_policy_hnd(&hnd_dst)) { 1835 dcerpc_spoolss_ClosePrinter(b_dst, mem_ctx, &hnd_dst, &result); 1836 } 1774 1837 1775 1838 if (cli_dst) { … … 1797 1860 1798 1861 NTSTATUS rpc_printer_migrate_drivers_internals(struct net_context *c, 1799 const DOM_SID*domain_sid,1862 const *domain_sid, 1800 1863 const char *domain_name, 1801 1864 struct cli_state *cli, … … 1805 1868 const char **argv) 1806 1869 { 1870 1807 1871 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; 1808 1872 uint32_t i, p; … … 1813 1877 bool got_dst_driver_share = false; 1814 1878 struct rpc_pipe_client *pipe_hnd_dst = NULL; 1879 1815 1880 struct policy_handle hnd_src, hnd_dst; 1816 1881 union spoolss_DriverInfo drv_info_src; … … 1821 1886 struct cli_state *cli_share_dst = NULL; 1822 1887 const char *drivername = NULL; 1888 1823 1889 1824 1890 DEBUG(3,("copying printer-drivers\n")); … … 1826 1892 nt_status = connect_dst_pipe(c, &cli_dst, &pipe_hnd_dst, 1827 1893 &ndr_table_spoolss.syntax_id); 1828 if (!NT_STATUS_IS_OK(nt_status)) 1894 if (!NT_STATUS_IS_OK(nt_status)) 1829 1895 return nt_status; 1896 1897 1830 1898 1831 1899 /* open print$-share on the src server */ … … 1956 2024 /* close dst */ 1957 2025 if (is_valid_policy_hnd(&hnd_dst)) { 1958 rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);2026 ); 1959 2027 } 1960 2028 1961 2029 /* close src */ 1962 2030 if (is_valid_policy_hnd(&hnd_src)) { 1963 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);2031 ); 1964 2032 } 1965 2033 } … … 1969 2037 done: 1970 2038 1971 if (is_valid_policy_hnd(&hnd_src)) 1972 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL); 1973 1974 if (is_valid_policy_hnd(&hnd_dst)) 1975 rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL); 2039 if (is_valid_policy_hnd(&hnd_dst)) { 2040 dcerpc_spoolss_ClosePrinter(b_dst, mem_ctx, &hnd_dst, &werr); 2041 } 2042 2043 /* close src */ 2044 if (is_valid_policy_hnd(&hnd_src)) { 2045 dcerpc_spoolss_ClosePrinter(b_src, mem_ctx, &hnd_src, &werr); 2046 } 1976 2047 1977 2048 if (cli_dst) { … … 2008 2079 2009 2080 NTSTATUS rpc_printer_migrate_printers_internals(struct net_context *c, 2010 const DOM_SID*domain_sid,2081 const *domain_sid, 2011 2082 const char *domain_name, 2012 2083 struct cli_state *cli, … … 2016 2087 const char **argv) 2017 2088 { 2089 2018 2090 WERROR result; 2019 2091 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; … … 2026 2098 const char *printername, *sharename; 2027 2099 struct rpc_pipe_client *pipe_hnd_dst = NULL; 2100 2028 2101 struct spoolss_SetPrinterInfoCtr info_ctr; 2029 2102 … … 2033 2106 nt_status = connect_dst_pipe(c, &cli_dst, &pipe_hnd_dst, 2034 2107 &ndr_table_spoolss.syntax_id); 2035 if (!NT_STATUS_IS_OK(nt_status)) 2108 if (!NT_STATUS_IS_OK(nt_status)) 2036 2109 return nt_status; 2110 2111 2037 2112 2038 2113 /* enum printers */ … … 2082 2157 /* close printer handle here - dst only, not got src yet. */ 2083 2158 if (is_valid_policy_hnd(&hnd_dst)) { 2084 rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);2159 ); 2085 2160 } 2086 2161 continue; … … 2125 2200 /* close printer handles here */ 2126 2201 if (is_valid_policy_hnd(&hnd_src)) { 2127 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);2202 ); 2128 2203 } 2129 2204 2130 2205 if (is_valid_policy_hnd(&hnd_dst)) { 2131 rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);2206 ); 2132 2207 } 2133 2208 } … … 2136 2211 2137 2212 done: 2138 if (is_valid_policy_hnd(&hnd_src)) 2139 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL); 2140 2141 if (is_valid_policy_hnd(&hnd_dst)) 2142 rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL); 2213 if (is_valid_policy_hnd(&hnd_src)) { 2214 dcerpc_spoolss_ClosePrinter(b_src, mem_ctx, &hnd_src, &result); 2215 } 2216 2217 if (is_valid_policy_hnd(&hnd_dst)) { 2218 dcerpc_spoolss_ClosePrinter(b_dst, mem_ctx, &hnd_dst, &result); 2219 } 2143 2220 2144 2221 if (cli_dst) { … … 2167 2244 2168 2245 NTSTATUS rpc_printer_migrate_settings_internals(struct net_context *c, 2169 const DOM_SID*domain_sid,2246 const *domain_sid, 2170 2247 const char *domain_name, 2171 2248 struct cli_state *cli, … … 2175 2252 const char **argv) 2176 2253 { 2254 2177 2255 2178 2256 /* FIXME: Here the nightmare begins */ … … 2180 2258 WERROR result; 2181 2259 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; 2182 uint32_t i = 0, p = 0,j = 0;2260 uint32_t i = 0, j = 0; 2183 2261 uint32_t num_printers; 2184 2262 uint32_t level = 2; 2185 2263 const char *printername, *sharename; 2186 2264 struct rpc_pipe_client *pipe_hnd_dst = NULL; 2265 2187 2266 struct policy_handle hnd_src, hnd_dst; 2188 2267 union spoolss_PrinterInfo *info_enum; … … 2202 2281 nt_status = connect_dst_pipe(c, &cli_dst, &pipe_hnd_dst, 2203 2282 &ndr_table_spoolss.syntax_id); 2204 if (!NT_STATUS_IS_OK(nt_status)) 2283 if (!NT_STATUS_IS_OK(nt_status)) 2205 2284 return nt_status; 2285 2286 2206 2287 2207 2288 /* enum src printers */ … … 2228 2309 for (i = 0; i < num_printers; i++) { 2229 2310 2230 uint32_t value_ offered = 0, value_needed;2231 uint32_t data_ offered = 0, data_needed;2311 uint32_t value_needed; 2312 uint32_t data_needed; 2232 2313 enum winreg_Type type; 2233 uint8_t *buffer = NULL; 2234 const char *value_name = NULL; 2314 struct spoolss_EnumPrinterData r; 2235 2315 2236 2316 /* do some initialization */ … … 2324 2404 */ 2325 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2326 2416 /* enumerate data on src handle */ 2327 nt_status = rpccli_spoolss_EnumPrinterData(pipe_hnd, mem_ctx, 2328 &hnd_src, 2329 p, 2330 value_name, 2331 value_offered, 2332 &value_needed, 2333 &type, 2334 buffer, 2335 data_offered, 2336 &data_needed, 2337 &result); 2338 2339 data_offered = data_needed; 2340 value_offered = value_needed; 2341 buffer = talloc_zero_array(mem_ctx, uint8_t, data_needed); 2342 value_name = talloc_zero_array(mem_ctx, char, value_needed); 2417 nt_status = dcerpc_spoolss_EnumPrinterData_r(b_src, mem_ctx, &r); 2418 2419 r.in.data_offered = *r.out.data_needed; 2420 r.in.value_offered = *r.out.value_needed; 2421 r.out.data = talloc_zero_array(mem_ctx, uint8_t, r.in.data_offered); 2422 r.out.value_name = talloc_zero_array(mem_ctx, char, r.in.value_offered); 2343 2423 2344 2424 /* loop for all printerdata of "PrinterDriverData" */ 2345 while (NT_STATUS_IS_OK(nt_status) && W_ERROR_IS_OK(result)) { 2346 2347 nt_status = rpccli_spoolss_EnumPrinterData(pipe_hnd, mem_ctx, 2348 &hnd_src, 2349 p++, 2350 value_name, 2351 value_offered, 2352 &value_needed, 2353 &type, 2354 buffer, 2355 data_offered, 2356 &data_needed, 2357 &result); 2425 while (NT_STATUS_IS_OK(nt_status) && W_ERROR_IS_OK(r.out.result)) { 2426 2427 r.in.enum_index++; 2428 2429 nt_status = dcerpc_spoolss_EnumPrinterData_r(b_src, mem_ctx, &r); 2430 2358 2431 /* loop for all reg_keys */ 2359 if (NT_STATUS_IS_OK(nt_status) && W_ERROR_IS_OK(result)) { 2360 2361 struct regval_blob v; 2432 if (NT_STATUS_IS_OK(nt_status) && W_ERROR_IS_OK(r.out.result)) { 2362 2433 2363 2434 /* display_value */ 2364 2435 if (c->opt_verbose) { 2365 fstrcpy(v.valuename, value_name); 2366 v.type = type; 2367 v.size = data_offered; 2368 v.data_p = buffer; 2436 struct regval_blob *v; 2437 2438 v = regval_compose(talloc_tos(), 2439 r.out.value_name, 2440 *r.out.type, 2441 r.out.data, 2442 r.in.data_offered); 2443 if (v == NULL) { 2444 nt_status = NT_STATUS_NO_MEMORY; 2445 goto done; 2446 } 2447 2369 2448 display_reg_value(SPOOL_PRINTERDATA_KEY, v); 2449 2370 2450 } 2371 2451 2372 2452 /* set_value */ 2373 2453 if (!net_spoolss_setprinterdata(pipe_hnd_dst, mem_ctx, 2374 &hnd_dst, value_name,2375 type, buffer,data_offered))2454 &hnd_dst, value_name, 2455 data_offered)) 2376 2456 goto done; 2377 2457 2378 2458 DEBUGADD(1,("\tSetPrinterData of [%s] succeeded\n", 2379 v.valuename));2459 name)); 2380 2460 } 2381 2461 } … … 2416 2496 for (j=0; j < count; j++) { 2417 2497 2418 struct regval_blob value;2498 struct regval_blob value; 2419 2499 DATA_BLOB blob; 2500 2501 2420 2502 2421 2503 /* although samba replies with sane data in most cases we … … 2432 2514 /* although windows uses a multi-sz, we use a sz */ 2433 2515 push_reg_sz(mem_ctx, &blob, SAMBA_PRINTER_PORT_NAME); 2434 fstrcpy(value.valuename, SPOOL_REG_PORTNAME);2435 2516 } 2436 2517 … … 2442 2523 } 2443 2524 push_reg_sz(mem_ctx, &blob, unc_name); 2444 fstrcpy(value.valuename, SPOOL_REG_UNCNAME);2445 2525 } 2446 2526 … … 2455 2535 goto done; 2456 2536 } 2457 push_reg_sz(mem_ctx, &blob, url);2537 push_reg_sz(mem_ctx, &blob, url); 2458 2538 fstrcpy(value.valuename, SPOOL_REG_URL); 2459 2539 #endif … … 2463 2543 2464 2544 push_reg_sz(mem_ctx, &blob, longname); 2465 fstrcpy(value.valuename, SPOOL_REG_SERVERNAME);2466 2545 } 2467 2546 … … 2469 2548 2470 2549 push_reg_sz(mem_ctx, &blob, global_myname()); 2471 fstrcpy(value.valuename, SPOOL_REG_SHORTSERVERNAME);2472 2550 } 2473 2551 2474 value.type = REG_SZ; 2475 value.size = blob.length; 2476 if (value.size) { 2477 value.data_p = blob.data; 2478 } else { 2479 value.data_p = NULL; 2552 value = regval_compose(talloc_tos(), 2553 info[j].value_name, 2554 REG_SZ, 2555 blob.length == 0 ? NULL : blob.data, 2556 blob.length); 2557 if (value == NULL) { 2558 nt_status = NT_STATUS_NO_MEMORY; 2559 goto done; 2480 2560 } 2481 2561 … … 2485 2565 /* here we have to set all subkeys on the dst server */ 2486 2566 if (!net_spoolss_setprinterdataex(pipe_hnd_dst, mem_ctx, &hnd_dst, 2487 subkey, &value)) 2567 subkey, value)) 2568 { 2569 talloc_free(value); 2488 2570 goto done; 2489 2571 } 2572 2573 talloc_free(value); 2490 2574 } else { 2491 2575 2492 struct regval_blob v; 2493 2494 fstrcpy(v.valuename, info[j].value_name); 2495 v.type = info[j].type; 2496 v.data_p = info[j].data->data; 2497 v.size = info[j].data->length; 2576 struct regval_blob *v; 2577 2578 v = regval_compose(talloc_tos(), 2579 info[j].value_name, 2580 info[j].type, 2581 info[j].data->data, 2582 info[j].data->length); 2583 if (v == NULL) { 2584 nt_status = NT_STATUS_NO_MEMORY; 2585 goto done; 2586 } 2498 2587 2499 2588 if (c->opt_verbose) { … … 2503 2592 /* here we have to set all subkeys on the dst server */ 2504 2593 if (!net_spoolss_setprinterdataex(pipe_hnd_dst, mem_ctx, &hnd_dst, 2505 subkey, &v)) {2594 subkey, v)) { 2506 2595 goto done; 2507 2596 } 2508 2597 2598 2509 2599 } 2510 2600 … … 2519 2609 /* close printer handles here */ 2520 2610 if (is_valid_policy_hnd(&hnd_src)) { 2521 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);2611 ); 2522 2612 } 2523 2613 2524 2614 if (is_valid_policy_hnd(&hnd_dst)) { 2525 rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL); 2526 } 2527 2615 dcerpc_spoolss_ClosePrinter(b_dst, mem_ctx, &hnd_dst, &result); 2616 } 2528 2617 } 2529 2618 … … 2535 2624 SAFE_FREE(unc_name); 2536 2625 2537 if (is_valid_policy_hnd(&hnd_src)) 2538 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL); 2539 2540 if (is_valid_policy_hnd(&hnd_dst)) 2541 rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL); 2626 if (is_valid_policy_hnd(&hnd_src)) { 2627 dcerpc_spoolss_ClosePrinter(b_src, mem_ctx, &hnd_src, &result); 2628 } 2629 2630 if (is_valid_policy_hnd(&hnd_dst)) { 2631 dcerpc_spoolss_ClosePrinter(b_dst, mem_ctx, &hnd_dst, &result); 2632 } 2542 2633 2543 2634 if (cli_dst) {
Note:
See TracChangeset
for help on using the changeset viewer.
