summaryrefslogtreecommitdiff
path: root/source3/utils/net_rpc_printer.c
blob: 5c2c797b90147a0e8130b9236220ef6144c0d68c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
/*
   Samba Unix/Linux SMB client library
   Distributed SMB/CIFS Server Management Utility
   Copyright (C) 2004,2009 Guenther Deschner (gd@samba.org)

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
#include "includes.h"
#include "system/filesys.h"
#include "utils/net.h"
#include "rpc_client/rpc_client.h"
#include "../librpc/gen_ndr/ndr_spoolss_c.h"
#include "rpc_client/cli_spoolss.h"
#include "rpc_client/init_spoolss.h"
#include "nt_printing.h"
#include "registry.h"
#include "../libcli/security/security.h"
#include "../libcli/registry/util_reg.h"
#include "libsmb/libsmb.h"

/* support itanium as well */
static const struct print_architecture_table_node archi_table[]= {

	{"Windows 4.0",          "WIN40",	0 },
	{"Windows NT x86",       "W32X86",	2 },
	{"Windows NT x86",       "W32X86",	3 },
	{"Windows NT R4000",     "W32MIPS",	2 },
	{"Windows NT Alpha_AXP", "W32ALPHA",	2 },
	{"Windows NT PowerPC",   "W32PPC",	2 },
	{"Windows IA64",         "IA64",	3 },
	{"Windows x64",          "x64",		3 },
	{NULL,                   "",		-1 }
};


/**
 * This display-printdriver-functions was borrowed from rpcclient/cmd_spoolss.c.
 * It is here for debugging purpose and should be removed later on.
 **/

/****************************************************************************
 Printer info level 3 display function.
****************************************************************************/

static void display_print_driver3(struct spoolss_DriverInfo3 *r)
{
	int i;

	if (!r) {
		return;
	}

	printf(_("Printer Driver Info 3:\n"));
	printf(_("\tVersion: [%x]\n"), r->version);
	printf(_("\tDriver Name: [%s]\n"), r->driver_name);
	printf(_("\tArchitecture: [%s]\n"), r->architecture);
	printf(_("\tDriver Path: [%s]\n"), r->driver_path);
	printf(_("\tDatafile: [%s]\n"), r->data_file);
	printf(_("\tConfigfile: [%s]\n\n"), r->config_file);
	printf(_("\tHelpfile: [%s]\n\n"), r->help_file);

	for (i=0; r->dependent_files && r->dependent_files[i] != NULL; i++) {
		printf(_("\tDependentfiles: [%s]\n"), r->dependent_files[i]);
	}

	printf("\n");

	printf(_("\tMonitorname: [%s]\n"), r->monitor_name);
	printf(_("\tDefaultdatatype: [%s]\n\n"), r->default_datatype);
}

static void display_reg_value(const char *subkey, const char *name, struct registry_value *value)
{
	const char *text;

	switch(value->type) {
	case REG_DWORD:
		if (value->data.length == sizeof(uint32)) {
			d_printf(_("\t[%s:%s]: REG_DWORD: 0x%08x\n"), subkey,
				 name, IVAL(value->data.data,0));
		} else {
			d_printf(_("\t[%s:%s]: REG_DWORD: <invalid>\n"), subkey,
				 name);
		}
		break;

	case REG_SZ:
		pull_reg_sz(talloc_tos(), &value->data, &text);
		if (!text) {
			break;
		}
		d_printf(_("\t[%s:%s]: REG_SZ: %s\n"), subkey, name, text);
		break;

	case REG_BINARY:
		d_printf(_("\t[%s:%s]: REG_BINARY: unknown length value not "
			   "displayed\n"),
			 subkey, name);
		break;

	case REG_MULTI_SZ: {
		uint32_t i;
		const char **values;

		if (!pull_reg_multi_sz(NULL, &value->data, &values)) {
			d_printf("pull_reg_multi_sz failed\n");
			break;
		}

		printf("%s: REG_MULTI_SZ: \n", name);
		for (i=0; values[i] != NULL; i++) {
			d_printf("%s\n", values[i]);
		}
		TALLOC_FREE(values);
		break;
	}

	default:
		d_printf(_("\t%s: unknown type %d\n"), name, value->type);
	}

}

/**
 * Copies ACLs, DOS-attributes and timestamps from one
 * file or directory from one connected share to another connected share
 *
 * @param c			A net_context structure
 * @param mem_ctx		A talloc-context
 * @param cli_share_src		A connected cli_state
 * @param cli_share_dst		A connected cli_state
 * @param src_file		The source file-name
 * @param dst_file		The destination file-name
 * @param copy_acls		Whether to copy acls
 * @param copy_attrs		Whether to copy DOS attributes
 * @param copy_timestamps	Whether to preserve timestamps
 * @param is_file		Whether this file is a file or a dir
 *
 * @return Normal NTSTATUS return.
 **/

NTSTATUS net_copy_fileattr(struct net_context *c,
		  TALLOC_CTX *mem_ctx,
		  struct cli_state *cli_share_src,
		  struct cli_state *cli_share_dst,
		  const char *src_name, const char *dst_name,
		  bool copy_acls, bool copy_attrs,
		  bool copy_timestamps, bool is_file)
{
	NTSTATUS nt_status;
	uint16_t fnum_src = 0;
	uint16_t fnum_dst = 0;
	struct security_descriptor *sd = NULL;
	uint16_t attr;
	time_t f_atime, f_ctime, f_mtime;

	if (!copy_timestamps && !copy_acls && !copy_attrs)
		return NT_STATUS_OK;

	/* open file/dir on the originating server */

	DEBUGADD(3,("opening %s %s on originating server\n",
		is_file?"file":"dir", src_name));

	nt_status = cli_ntcreate(cli_share_src, src_name, 0,
				 READ_CONTROL_ACCESS, 0,
				 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN,
				 0x0, 0x0, &fnum_src);
	if (!NT_STATUS_IS_OK(nt_status)) {
		DEBUGADD(0,("cannot open %s %s on originating server %s\n",
			is_file?"file":"dir", src_name, nt_errstr(nt_status)));
		goto out;
	}

	if (copy_acls) {
		/* get the security descriptor */
		nt_status = cli_query_secdesc(cli_share_src, fnum_src,
					      mem_ctx, &sd);
		if (!NT_STATUS_IS_OK(nt_status)) {
			DEBUG(0,("failed to get security descriptor: %s\n",
				 nt_errstr(nt_status)));
			goto out;
		}

		if (c->opt_verbose && DEBUGLEVEL >= 3)
			display_sec_desc(sd);
	}

	if (copy_attrs || copy_timestamps) {

		/* get file attributes */
		nt_status = cli_getattrE(cli_share_src, fnum_src, &attr, NULL,
		                      &f_ctime, &f_atime, &f_mtime);
		if (!NT_STATUS_IS_OK(nt_status)) {
			DEBUG(0,("failed to get file-attrs: %s\n",
				nt_errstr(nt_status)));
			goto out;
		}
	}

	/* open the file/dir on the destination server */
	nt_status = cli_ntcreate(cli_share_dst, dst_name, 0,
				 WRITE_DAC_ACCESS | WRITE_OWNER_ACCESS, 0,
				 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN,
				 0x0, 0x0, &fnum_dst);
	if (!NT_STATUS_IS_OK(nt_status)) {
		DEBUG(0,("failed to open %s on the destination server: %s: %s\n",
			is_file?"file":"dir", dst_name, nt_errstr(nt_status)));
		goto out;
	}

	if (copy_timestamps) {
		/* set timestamps */
		nt_status = cli_setattrE(cli_share_dst, fnum_dst, f_ctime, f_atime, f_mtime);
		if (!NT_STATUS_IS_OK(nt_status)) {
			DEBUG(0,("failed to set file-attrs (timestamps): %s\n",
				nt_errstr(nt_status)));
			goto out;
		}
	}

	if (copy_acls) {
		/* set acls */
		nt_status = cli_set_secdesc(cli_share_dst, fnum_dst, sd);
		if (!NT_STATUS_IS_OK(nt_status)) {
			DEBUG(0, ("could not set secdesc on %s: %s\n",
				  dst_name, nt_errstr(nt_status)));
			goto out;
		}
	}

	if (copy_attrs) {
		/* set attrs */
		nt_status = cli_setatr(cli_share_dst, dst_name, attr, 0);
		if (!NT_STATUS_IS_OK(nt_status)) {
			DEBUG(0,("failed to set file-attrs: %s\n",
				nt_errstr(nt_status)));
			goto out;
		}
	}


	/* closing files */
	nt_status = cli_close(cli_share_src, fnum_src);
	if (!NT_STATUS_IS_OK(nt_status)) {
		d_fprintf(stderr,
			_("could not close %s on originating server: %s\n"),
			is_file?"file":"dir", nt_errstr(nt_status));
		goto out;
	}

	nt_status = cli_close(cli_share_dst, fnum_dst);
	if (!NT_STATUS_IS_OK(nt_status)) {
		d_fprintf(stderr,
			_("could not close %s on destination server: %s\n"),
			is_file?"file":"dir", nt_errstr(nt_status));
		goto out;
	}


	nt_status = NT_STATUS_OK;

out:

	/* cleaning up */
	if (fnum_src)
		cli_close(cli_share_src, fnum_src);

	if (fnum_dst)
		cli_close(cli_share_dst, fnum_dst);

	return nt_status;
}

/**
 * Copy a file or directory from a connected share to another connected share
 *
 * @param c			A net_context structure
 * @param mem_ctx		A talloc-context
 * @param cli_share_src		A connected cli_state
 * @param cli_share_dst		A connected cli_state
 * @param src_file		The source file-name
 * @param dst_file		The destination file-name
 * @param copy_acls		Whether to copy acls
 * @param copy_attrs		Whether to copy DOS attributes
 * @param copy_timestamps	Whether to preserve timestamps
 * @param is_file		Whether this file is a file or a dir
 *
 * @return Normal NTSTATUS return.
 **/

NTSTATUS net_copy_file(struct net_context *c,
		       TALLOC_CTX *mem_ctx,
		       struct cli_state *cli_share_src,
		       struct cli_state *cli_share_dst,
		       const char *src_name, const char *dst_name,
		       bool copy_acls, bool copy_attrs,
		       bool copy_timestamps, bool is_file)
{
	NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
	uint16_t fnum_src = 0;
	uint16_t fnum_dst = 0;
	static int io_bufsize = 64512;
	int read_size = io_bufsize;
	char *data = NULL;
	off_t nread = 0;


	if (!src_name || !dst_name)
		goto out;

	if (cli_share_src == NULL || cli_share_dst == NULL)
		goto out;

	/* open on the originating server */
	DEBUGADD(3,("opening %s %s on originating server\n",
		is_file ? "file":"dir", src_name));
	if (is_file)
		nt_status = cli_open(cli_share_src, src_name, O_RDONLY, DENY_NONE, &fnum_src);
	else
		nt_status = cli_ntcreate(cli_share_src, src_name, 0, READ_CONTROL_ACCESS, 0,
				FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0x0, 0x0, &fnum_src);

	if (!NT_STATUS_IS_OK(nt_status)) {
		DEBUGADD(0,("cannot open %s %s on originating server %s\n",
			is_file ? "file":"dir",
			src_name, nt_errstr(nt_status)));
		goto out;
	}


	if (is_file) {

		/* open file on the destination server */
		DEBUGADD(3,("opening file %s on destination server\n", dst_name));
		nt_status = cli_open(cli_share_dst, dst_name,
				O_RDWR|O_CREAT|O_TRUNC, DENY_NONE, &fnum_dst);

		if (!NT_STATUS_IS_OK(nt_status)) {
			DEBUGADD(1,("cannot create file %s on destination server: %s\n", 
				dst_name, nt_errstr(nt_status)));
			goto out;
		}

		/* allocate memory */
		if (!(data = (char *)SMB_MALLOC(read_size))) {
			d_fprintf(stderr, _("malloc fail for size %d\n"),
				  read_size);
			nt_status = NT_STATUS_NO_MEMORY;
			goto out;
		}

	}


	if (c->opt_verbose) {

		d_printf(_("copying [\\\\%s\\%s%s] => [\\\\%s\\%s%s] "
			   "%s ACLs and %s DOS Attributes %s\n"),
			cli_state_remote_name(cli_share_src),
			cli_share_src->share, src_name,
			cli_state_remote_name(cli_share_dst),
			cli_share_dst->share, dst_name,
			copy_acls ?  _("with") : _("without"),
			copy_attrs ? _("with") : _("without"),
			copy_timestamps ? _("(preserving timestamps)") : "" );
	}


	while (is_file) {

		/* copying file */
		size_t n;

		nt_status = cli_read(cli_share_src, fnum_src, data, nread,
				     read_size, &n);
		if (!NT_STATUS_IS_OK(nt_status)) {
			d_fprintf(stderr,
				  _("Error reading file [\\\\%s\\%s%s]: %s\n"),
				  cli_state_remote_name(cli_share_src),
				  cli_share_src->share,
				  src_name, nt_errstr(nt_status));
			goto out;
		}

		if (n == 0)
			break;

		nt_status = cli_writeall(cli_share_dst, fnum_dst, 0,
					 (uint8_t *)data, nread, n, NULL);

		if (!NT_STATUS_IS_OK(nt_status)) {
			d_fprintf(stderr,
				  _("Error writing file: [\\\\%s\\%s%s]: %s\n"),
				  cli_state_remote_name(cli_share_dst),
				  cli_share_dst->share,
				  dst_name, nt_errstr(nt_status));
			goto out;
		}

		nread += n;
	}


	if (!is_file && !NT_STATUS_IS_OK(cli_chkpath(cli_share_dst, dst_name))) {

		/* creating dir */
		DEBUGADD(3,("creating dir %s on the destination server\n",
			dst_name));

		nt_status = cli_mkdir(cli_share_dst, dst_name);
		if (!NT_STATUS_IS_OK(nt_status)) {
			DEBUG(0,("cannot create directory %s: %s\n",
				dst_name, nt_errstr(nt_status)));
			nt_status = NT_STATUS_NO_SUCH_FILE;
		}


		nt_status = cli_chkpath(cli_share_dst, dst_name);
		if (!NT_STATUS_IS_OK(nt_status)) {
			d_fprintf(stderr,
				_("cannot check for directory %s: %s\n"),
				dst_name, nt_errstr(nt_status));
			goto out;
		}
	}


	/* closing files */
	nt_status = cli_close(cli_share_src, fnum_src);
	if (!NT_STATUS_IS_OK(nt_status)) {
		d_fprintf(stderr,
			_("could not close file on originating server: %s\n"),
			nt_errstr(nt_status));
		goto out;
	}

	if (is_file) {
		nt_status = cli_close(cli_share_dst, fnum_dst);
		if (!NT_STATUS_IS_OK(nt_status)) {
			d_fprintf(stderr,
			_("could not close file on destination server: %s\n"),
			nt_errstr(nt_status));
			goto out;
		}
	}

	/* possibly we have to copy some file-attributes / acls / sd */
	nt_status = net_copy_fileattr(c, mem_ctx, cli_share_src, cli_share_dst,
				      src_name, dst_name, copy_acls,
				      copy_attrs, copy_timestamps, is_file);
	if (!NT_STATUS_IS_OK(nt_status))
		goto out;


	nt_status = NT_STATUS_OK;

out:

	/* cleaning up */
	if (fnum_src)
		cli_close(cli_share_src, fnum_src);

	if (fnum_dst)
		cli_close(cli_share_dst, fnum_dst);

	SAFE_FREE(data);

	return nt_status;
}

/**
 * Copy a driverfile from on connected share to another connected share
 * This silently assumes that a driver-file is picked up from
 *
 *	\\src_server\print$\{arch}\{version}\file
 *
 * and copied to
 *
 * 	\\dst_server\print$\{arch}\file
 *
 * to be added via setdriver-calls later.
 * @param c			A net_context structure
 * @param mem_ctx		A talloc-context
 * @param cli_share_src		A cli_state connected to source print$-share
 * @param cli_share_dst		A cli_state connected to destination print$-share
 * @param file			The file-name to be copied
 * @param short_archi		The name of the driver-architecture (short form)
 *
 * @return Normal NTSTATUS return.
 **/

static NTSTATUS net_copy_driverfile(struct net_context *c,
				    TALLOC_CTX *mem_ctx,
				    struct cli_state *cli_share_src,
				    struct cli_state *cli_share_dst,
				    const char *file, const char *short_archi) {

	const char *p;
	char *src_name;
	char *dst_name;
	char *version = NULL;
	char *filename = NULL;
	char *tok;

	if (!file) {
		return NT_STATUS_OK;
	}

	/* scroll through the file until we have the part
	   beyond archi_table.short_archi */
	p = file;
	while (next_token_talloc(mem_ctx, &p, &tok, "\\")) {
		if (strequal(tok, short_archi)) {
			next_token_talloc(mem_ctx, &p, &version, "\\");
			next_token_talloc(mem_ctx, &p, &filename, "\\");
		}
	}

	if (version == NULL || filename == NULL) {
		return NT_STATUS_UNSUCCESSFUL;
	}

	/* build source file name */
	src_name = talloc_asprintf(mem_ctx, "\\%s\\%s\\%s",
				   short_archi, version, filename);
	if (src_name == NULL) {
		return NT_STATUS_NO_MEMORY;
	}

	/* create destination file name */
	dst_name = talloc_asprintf(mem_ctx, "\\%s\\%s", short_archi, filename);
	if (dst_name == NULL) {
		return NT_STATUS_NO_MEMORY;
	}


	/* finally copy the file */
	return net_copy_file(c, mem_ctx, cli_share_src, cli_share_dst,
			     src_name, dst_name, false, false, false, true);
}

/**
 * Check for existing Architecture directory on a given server
 *
 * @param cli_share		A cli_state connected to a print$-share
 * @param short_archi		The Architecture for the print-driver
 *
 * @return Normal NTSTATUS return.
 **/

static NTSTATUS check_arch_dir(struct cli_state *cli_share, const char *short_archi)
{

	NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
	char *dir;

	if (asprintf(&dir, "\\%s", short_archi) < 0) {
		return NT_STATUS_NO_MEMORY;
	}

	DEBUG(10,("creating print-driver dir for architecture: %s\n",
		short_archi));

	nt_status = cli_mkdir(cli_share, dir);
	if (!NT_STATUS_IS_OK(nt_status)) {
                DEBUG(1,("cannot create directory %s: %s\n",
                         dir, nt_errstr(nt_status)));
        }

	nt_status = cli_chkpath(cli_share, dir);
	if (!NT_STATUS_IS_OK(nt_status)) {
		d_fprintf(stderr, _("cannot check %s: %s\n"),
			dir, nt_errstr(nt_status));
		goto out;
	}

	nt_status = NT_STATUS_OK;

out:
	SAFE_FREE(dir);
	return nt_status;
}

/**
 * Copy a print-driver (level 3) from one connected print$-share to another
 * connected print$-share
 *
 * @param c			A net_context structure
 * @param mem_ctx		A talloc-context
 * @param cli_share_src		A cli_state connected to a print$-share
 * @param cli_share_dst		A cli_state connected to a print$-share
 * @param short_archi		The Architecture for the print-driver
 * @param i1			The DRIVER_INFO_3-struct
 *
 * @return Normal NTSTATUS return.
 **/

static NTSTATUS copy_print_driver_3(struct net_context *c,
		    TALLOC_CTX *mem_ctx,
		    struct cli_state *cli_share_src,
		    struct cli_state *cli_share_dst,
		    const char *short_archi,
		    struct spoolss_DriverInfo3 *r)
{
	NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
	int i;

	if (r == NULL) {
		return nt_status;
	}

	if (c->opt_verbose)
		d_printf(_("copying driver: [%s], for architecture: [%s], "
			   "version: [%d]\n"),
			  r->driver_name, short_archi, r->version);

	nt_status = net_copy_driverfile(c, mem_ctx, cli_share_src, cli_share_dst,
		r->driver_path, short_archi);
	if (!NT_STATUS_IS_OK(nt_status))
		return nt_status;

	nt_status = net_copy_driverfile(c, mem_ctx, cli_share_src, cli_share_dst,
		r->data_file, short_archi);
	if (!NT_STATUS_IS_OK(nt_status))
		return nt_status;

	nt_status = net_copy_driverfile(c, mem_ctx, cli_share_src, cli_share_dst,
		r->config_file, short_archi);
	if (!NT_STATUS_IS_OK(nt_status))
		return nt_status;

	nt_status = net_copy_driverfile(c, mem_ctx, cli_share_src, cli_share_dst,
		r->help_file, short_archi);
	if (!NT_STATUS_IS_OK(nt_status))
		return nt_status;

	for (i=0; r->dependent_files[i] != NULL; i++) {

		nt_status = net_copy_driverfile(c, mem_ctx,
				cli_share_src, cli_share_dst,
				r->dependent_files[i], short_archi);
		if (!NT_STATUS_IS_OK(nt_status)) {
			return nt_status;
		}
	}

	return NT_STATUS_OK;
}

/**
 * net_spoolss-functions
 * =====================
 *
 * the net_spoolss-functions aim to simplify spoolss-client-functions
 * required during the migration-process wrt buffer-sizes, returned
 * error-codes, etc.
 *
 * this greatly reduces the complexitiy of the migrate-functions.
 *
 **/

static bool net_spoolss_enum_printers(struct rpc_pipe_client *pipe_hnd,
					TALLOC_CTX *mem_ctx,
					char *name,
					uint32_t flags,
					uint32_t level,
					uint32_t *num_printers,
					union spoolss_PrinterInfo **info)
{
	WERROR result;

	/* enum printers */

	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;
	}

	return true;
}

static bool net_spoolss_open_printer_ex(struct rpc_pipe_client *pipe_hnd,
					TALLOC_CTX *mem_ctx,
					const char *printername,
					uint32_t access_required,
					const char *username,
					struct policy_handle *hnd)
{
	WERROR result;
	fstring printername2;

	fstrcpy(printername2, pipe_hnd->srv_name_slash);
	fstrcat(printername2, "\\");
	fstrcat(printername2, printername);

	DEBUG(10,("connecting to: %s as %s for %s and access: %x\n",
		pipe_hnd->srv_name_slash, username, printername2, access_required));

	/* open printer */
	result = rpccli_spoolss_openprinter_ex(pipe_hnd, mem_ctx,
					       printername2,
					       access_required,
					       hnd);

	/* be more verbose */
	if (W_ERROR_V(result) == W_ERROR_V(WERR_ACCESS_DENIED)) {
		d_fprintf(stderr,
			_("no access to printer [%s] on [%s] for user [%s] "
			  "granted\n"),
			printername2, pipe_hnd->srv_name_slash, username);
		return false;
	}

	if (!W_ERROR_IS_OK(result)) {
		d_fprintf(stderr,_("cannot open printer %s on server %s: %s\n"),
			printername2, pipe_hnd->srv_name_slash, win_errstr(result));
		return false;
	}

	DEBUG(2,("got printer handle for printer: %s, server: %s\n",
		printername2, pipe_hnd->srv_name_slash));

	return true;
}

static bool net_spoolss_getprinter(struct rpc_pipe_client *pipe_hnd,
				TALLOC_CTX *mem_ctx,
				struct policy_handle *hnd,
				uint32_t level,
				union spoolss_PrinterInfo *info)
{
	WERROR result;

	/* getprinter call */
	result = rpccli_spoolss_getprinter(pipe_hnd, mem_ctx,
					   hnd,
					   level,
					   0, /* offered */
					   info);
	if (!W_ERROR_IS_OK(result)) {
		printf(_("cannot get printer-info: %s\n"), win_errstr(result));
		return false;
	}

	return true;
}

static bool net_spoolss_setprinter(struct rpc_pipe_client *pipe_hnd,
				TALLOC_CTX *mem_ctx,
				struct policy_handle *hnd,
				uint32_t level,
				union spoolss_PrinterInfo *info)
{
	struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
	WERROR result;
	NTSTATUS status;
	struct spoolss_SetPrinterInfoCtr info_ctr;
	struct spoolss_SetPrinterInfo2 info2;
	struct spoolss_DevmodeContainer devmode_ctr;
	struct sec_desc_buf secdesc_ctr;

	ZERO_STRUCT(devmode_ctr);
	ZERO_STRUCT(secdesc_ctr);

	/* setprinter call */

	info_ctr.level = level;
	switch (level) {
	case 0:
		info_ctr.info.info0 = (struct spoolss_SetPrinterInfo0 *)
			(void *)&info->info0;
		break;
	case 1:
		info_ctr.info.info1 = (struct spoolss_SetPrinterInfo1 *)
			(void *)&info->info1;
		break;
	case 2:
		spoolss_printerinfo2_to_setprinterinfo2(&info->info2, &info2);
		info_ctr.info.info2 = &info2;
		break;
	case 3:
		info_ctr.info.info3 = (struct spoolss_SetPrinterInfo3 *)
			(void *)&info->info3;
		break;
	case 4:
		info_ctr.info.info4 = (struct spoolss_SetPrinterInfo4 *)
			(void *)&info->info4;
		break;
	case 5:
		info_ctr.info.info5 = (struct spoolss_SetPrinterInfo5 *)
			(void *)&info->info5;
		break;
	case 6:
		info_ctr.info.info6 = (struct spoolss_SetPrinterInfo6 *)
			(void *)&info->info6;
		break;
	case 7:
		info_ctr.info.info7 = (struct spoolss_SetPrinterInfo7 *)
			(void *)&info->info7;
		break;
#if 0 /* FIXME GD */
	case 8:
		info_ctr.info.info8 = (struct spoolss_SetPrinterInfo8 *)
			(void *)&info->info8;
		break;
	case 9:
		info_ctr.info.info9 = (struct spoolss_SetPrinterInfo9 *)
			(void *)&info->info9;
		break;
#endif
	default:
		break; /* FIXME */
	}

	status = dcerpc_spoolss_SetPrinter(b, mem_ctx,
					   hnd,
					   &info_ctr,
					   &devmode_ctr,
					   &secdesc_ctr,
					   0, /* command */
					   &result);
	if (!NT_STATUS_IS_OK(status)) {
		printf(_("cannot set printer-info: %s\n"), nt_errstr(status));
		return false;
	}
	if (!W_ERROR_IS_OK(result)) {
		printf(_("cannot set printer-info: %s\n"), win_errstr(result));
		return false;
	}

	return true;
}


static bool net_spoolss_setprinterdata(struct rpc_pipe_client *pipe_hnd,
				       TALLOC_CTX *mem_ctx,
				       struct policy_handle *hnd,
				       const char *value_name,
				       enum winreg_Type type,
				       uint8_t *data,
				       uint32_t offered)
{
	struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
	WERROR result;
	NTSTATUS status;

	/* setprinterdata call */
	status = dcerpc_spoolss_SetPrinterData(b, mem_ctx,
					       hnd,
					       value_name,
					       type,
					       data,
					       offered,
					       &result);
	if (!NT_STATUS_IS_OK(status)) {
		printf (_("unable to set printerdata: %s\n"),
			nt_errstr(status));
		return false;
	}
	if (!W_ERROR_IS_OK(result)) {
		printf (_("unable to set printerdata: %s\n"),
			win_errstr(result));
		return false;
	}

	return true;
}


static bool net_spoolss_enumprinterkey(struct rpc_pipe_client *pipe_hnd,
					TALLOC_CTX *mem_ctx,
					struct policy_handle *hnd,
					const char *keyname,
					const char ***keylist)
{
	WERROR result;

	/* enumprinterkey call */
	result = rpccli_spoolss_enumprinterkey(pipe_hnd, mem_ctx, hnd, keyname, keylist, 0);

	if (!W_ERROR_IS_OK(result)) {
		printf(_("enumprinterkey failed: %s\n"), win_errstr(result));
		return false;
	}

	return true;
}

static bool net_spoolss_enumprinterdataex(struct rpc_pipe_client *pipe_hnd,
					TALLOC_CTX *mem_ctx,
					uint32_t offered,
					struct policy_handle *hnd,
					const char *keyname,
					uint32_t *count,
					struct spoolss_PrinterEnumValues **info)
{
	WERROR result;

	/* enumprinterdataex call */
	result = rpccli_spoolss_enumprinterdataex(pipe_hnd, mem_ctx,
						  hnd,
						  keyname,
						  0, /* offered */
						  count,
						  info);

	if (!W_ERROR_IS_OK(result)) {
		printf(_("enumprinterdataex failed: %s\n"), win_errstr(result));
		return false;
	}

	return true;
}


static bool net_spoolss_setprinterdataex(struct rpc_pipe_client *pipe_hnd,
					 TALLOC_CTX *mem_ctx,
					 struct policy_handle *hnd,
					 const char *keyname,
					 const char *name,
					 struct registry_value *value)
{
	struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
	WERROR result;
	NTSTATUS status;

	/* setprinterdataex call */
	status = dcerpc_spoolss_SetPrinterDataEx(b, mem_ctx,
						 hnd,
						 keyname,
						 name,
						 value->type,
						 value->data.data,
						 value->data.length,
						 &result);
	if (!NT_STATUS_IS_OK(status)) {
		printf(_("could not set printerdataex: %s\n"),
		       nt_errstr(status));
		return false;
	}
	if (!W_ERROR_IS_OK(result)) {
		printf(_("could not set printerdataex: %s\n"),
		       win_errstr(result));
		return false;
	}

	return true;
}

static bool net_spoolss_enumforms(struct rpc_pipe_client *pipe_hnd,
				TALLOC_CTX *mem_ctx,
				struct policy_handle *hnd,
				int level,
				uint32_t *num_forms,
				union spoolss_FormInfo **forms)
{
	WERROR result;

	/* enumforms call */
	result = rpccli_spoolss_enumforms(pipe_hnd, mem_ctx,
					  hnd,
					  level,
					  0,
					  num_forms,
					  forms);
	if (!W_ERROR_IS_OK(result)) {
		printf(_("could not enum forms: %s\n"), win_errstr(result));
		return false;
	}

	return true;
}

static bool net_spoolss_enumprinterdrivers (struct rpc_pipe_client *pipe_hnd,
					TALLOC_CTX *mem_ctx,
					uint32_t level, const char *env,
					uint32_t *count,
					union spoolss_DriverInfo **info)
{
	WERROR result;

	/* enumprinterdrivers call */
	result = rpccli_spoolss_enumprinterdrivers(pipe_hnd, mem_ctx,
						   pipe_hnd->srv_name_slash,
						   env,
						   level,
						   0,
						   count,
						   info);
	if (!W_ERROR_IS_OK(result)) {
		if (W_ERROR_V(result) != W_ERROR_V(WERR_INVALID_ENVIRONMENT)) {
			printf(_("cannot enum drivers for environment %s: %s\n"), env,
				win_errstr(result));
			return false;
		} else {
			printf(_("Server does not support environment [%s]\n"),
				env);
		}
	}

	return true;
}

static bool net_spoolss_getprinterdriver(struct rpc_pipe_client *pipe_hnd,
			     TALLOC_CTX *mem_ctx,
			     struct policy_handle *hnd, uint32_t level,
			     const char *env, int version,
			     union spoolss_DriverInfo *info)
{
	WERROR result;
	uint32_t server_major_version;
	uint32_t server_minor_version;

	/* getprinterdriver call */
	result = rpccli_spoolss_getprinterdriver2(pipe_hnd, mem_ctx,
						  hnd,
						  env,
						  level,
						  0,
						  version,
						  2,
						  info,
						  &server_major_version,
						  &server_minor_version);
	if (!W_ERROR_IS_OK(result)) {
		DEBUG(1,("cannot get driver (for architecture: %s): %s\n",
			env, win_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"),
			       win_errstr(result));
		}
		return false;
	}

	return true;
}


static bool net_spoolss_addprinterdriver(struct rpc_pipe_client *pipe_hnd,
			     TALLOC_CTX *mem_ctx, uint32_t level,
			     union spoolss_DriverInfo *info)
{
	struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
	WERROR result;
	NTSTATUS status;
	struct spoolss_AddDriverInfoCtr info_ctr;

	info_ctr.level = level;

	switch (level) {
	case 2:
		info_ctr.info.info2 = (struct spoolss_AddDriverInfo2 *)
			(void *)&info->info2;
		break;
	case 3:
		info_ctr.info.info3 = (struct spoolss_AddDriverInfo3 *)
			(void *)&info->info3;
		break;
	default:
		printf(_("unsupported info level: %d\n"), level);
		return false;
	}

	/* addprinterdriver call */
	status = dcerpc_spoolss_AddPrinterDriver(b, mem_ctx,
						 pipe_hnd->srv_name_slash,
						 &info_ctr,
						 &result);
	if (!NT_STATUS_IS_OK(status)) {
		printf(_("cannot add driver: %s\n"), nt_errstr(status));
		return false;
	}
	/* 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"), win_errstr(result));
		return false;
	}

	return true;
}

/**
 * abstraction function to get uint32_t 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_t *num_printers,
			union spoolss_PrinterInfo **info_p)
{
	struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
	struct policy_handle hnd;
	WERROR werr;

	/* 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, info_p))
			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->auth->user_name,
					 &hnd))
		return false;

	*info_p = talloc_zero(mem_ctx, union spoolss_PrinterInfo);
	if (*info_p == NULL) {
		return false;
	}

	if (!net_spoolss_getprinter(pipe_hnd, mem_ctx, &hnd, level, *info_p)) {
		dcerpc_spoolss_ClosePrinter(b, mem_ctx, &hnd, &werr);
		return false;
	}

	dcerpc_spoolss_ClosePrinter(b, mem_ctx, &hnd, &werr);

	*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 c	A net_context structure
 * @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(struct net_context *c,
					const struct 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_t i, num_printers;
	uint32_t level = 2;
	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, &info))
		return nt_status;

	for (i = 0; i < num_printers; i++) {

		/* do some initialization */
		printername = info[i].info2.printername;
		sharename = info[i].info2.sharename;

		if (printername && sharename) {
			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 c	A net_context structure
 * @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(struct net_context *c,
						const struct 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_t i;
	uint32_t level = 3;
	union spoolss_DriverInfo *info;
	int d;

	printf(_("listing printer-drivers\n"));

        for (i=0; archi_table[i].long_archi!=NULL; i++) {

		uint32_t num_drivers;

		/* enum remote drivers */
		if (!net_spoolss_enumprinterdrivers(pipe_hnd, mem_ctx, level,
				archi_table[i].long_archi,
				&num_drivers, &info)) {
			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_driver3(&info[d].info3);
		}
	}

	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_t action)
{
	struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
	NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
	uint32_t i, num_printers;
	uint32_t level = 7;
	const char *printername, *sharename;
	union spoolss_PrinterInfo *info_enum;
	union spoolss_PrinterInfo info;
	struct spoolss_SetPrinterInfoCtr info_ctr;
	struct spoolss_DevmodeContainer devmode_ctr;
	struct sec_desc_buf secdesc_ctr;
	struct policy_handle hnd = { 0, };
	WERROR result;
	const char *action_str;

	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 */
		printername = info_enum[i].info2.printername;
		sharename = info_enum[i].info2.sharename;
		if (!printername || !sharename) {
			goto done;
		}

		/* open printer handle */
		if (!net_spoolss_open_printer_ex(pipe_hnd, mem_ctx, sharename,
			PRINTER_ALL_ACCESS, pipe_hnd->auth->user_name, &hnd))
			goto done;

		/* check for existing dst printer */
		if (!net_spoolss_getprinter(pipe_hnd, mem_ctx, &hnd, level, &info))
			goto done;

		/* check action and set string */
		switch (action) {
		case DSPRINT_PUBLISH:
			action_str = N_("published");
			break;
		case DSPRINT_UPDATE:
			action_str = N_("updated");
			break;
		case DSPRINT_UNPUBLISH:
			action_str = N_("unpublished");
			break;
		default:
			action_str = N_("unknown action");
			printf(_("unknown action: %d\n"), action);
			break;
		}

		info.info7.action = action;
		info_ctr.level = 7;
		info_ctr.info.info7 = (struct spoolss_SetPrinterInfo7 *)
			(void *)&info.info7;

		ZERO_STRUCT(devmode_ctr);
		ZERO_STRUCT(secdesc_ctr);

		nt_status = dcerpc_spoolss_SetPrinter(b, mem_ctx,
						      &hnd,
						      &info_ctr,
						      &devmode_ctr,
						      &secdesc_ctr,
						      0, /* command */
						      &result);
		if (!NT_STATUS_IS_OK(nt_status)) {
			printf(_("cannot set printer-info: %s\n"),
			       nt_errstr(nt_status));
			goto done;
		}
		if (!W_ERROR_IS_OK(result) && !W_ERROR_EQUAL(result, WERR_IO_PENDING)) {
			if ((action == DSPRINT_UPDATE) && W_ERROR_EQUAL(result, W_ERROR(0x80070002))) {
				printf(_("printer not published yet\n"));
			} else {
				printf(_("cannot set printer-info: %s\n"),
				       win_errstr(result));
			}
			nt_status = werror_to_ntstatus(result);
			goto done;
		}

		printf(_("successfully %s printer %s in Active Directory\n"),
		       action_str, sharename);
	}

	nt_status = NT_STATUS_OK;

done:
	if (is_valid_policy_hnd(&hnd)) {
		dcerpc_spoolss_ClosePrinter(b, mem_ctx, &hnd, &result);
	}

	return nt_status;
}

NTSTATUS rpc_printer_publish_publish_internals(struct net_context *c,
						const struct 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, DSPRINT_PUBLISH);
}

NTSTATUS rpc_printer_publish_unpublish_internals(struct net_context *c,
						const struct 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, DSPRINT_UNPUBLISH);
}

NTSTATUS rpc_printer_publish_update_internals(struct net_context *c,
						const struct 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, DSPRINT_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 c	A net_context structure
 * @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(struct net_context *c,
						const struct 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)
{
	struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
	NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
	uint32_t i, num_printers;
	uint32_t level = 7;
	const char *printername, *sharename;
	union spoolss_PrinterInfo *info_enum;
	union spoolss_PrinterInfo info;
	struct policy_handle hnd = { 0, };
	int state;
	WERROR werr;

	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 */
		printername = info_enum[i].info2.printername;
		sharename = info_enum[i].info2.sharename;

		if (!printername || !sharename) {
			goto done;
		}

		/* open printer handle */
		if (!net_spoolss_open_printer_ex(pipe_hnd, mem_ctx, sharename,
			PRINTER_ALL_ACCESS, cli->user_name, &hnd))
			goto done;

		/* check for existing dst printer */
		if (!net_spoolss_getprinter(pipe_hnd, mem_ctx, &hnd, level, &info))
			goto done;

		if (!info.info7.guid) {
			goto done;
		}
		state = info.info7.action;
		switch (state) {
			case DSPRINT_PUBLISH:
				printf(_("printer [%s] is published"),
				       sharename);
				if (c->opt_verbose)
					printf(_(", guid: %s"),info.info7.guid);
				printf("\n");
				break;
			case DSPRINT_UNPUBLISH:
				printf(_("printer [%s] is unpublished\n"),
				       sharename);
				break;
			case DSPRINT_UPDATE:
				printf(_("printer [%s] is currently updating\n"),
				       sharename);
				break;
			default:
				printf(_("unknown state: %d\n"), state);
				break;
		}
	}

	nt_status = NT_STATUS_OK;

done:
	if (is_valid_policy_hnd(&hnd)) {
		dcerpc_spoolss_ClosePrinter(b, mem_ctx, &hnd, &werr);
	}

	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 c	A net_context structure
 * @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(struct net_context *c,
						const struct 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)
{
	struct dcerpc_binding_handle *b_src = pipe_hnd->binding_handle;
	/* 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_t i = 0;
	uint32_t num_printers;
	uint32_t level = 2;
	const char *printername, *sharename;
	struct rpc_pipe_client *pipe_hnd_dst = NULL;
	struct dcerpc_binding_handle *b_dst = NULL;
	struct policy_handle hnd_src = { 0, };
	struct policy_handle hnd_dst = { 0, };
	union spoolss_PrinterInfo *info_enum;
	struct cli_state *cli_dst = NULL;
	union spoolss_PrinterInfo info_src, info_dst;
	WERROR werr;

	DEBUG(3,("copying printer ACLs\n"));

	/* connect destination PI_SPOOLSS */
	nt_status = connect_dst_pipe(c, &cli_dst, &pipe_hnd_dst,
				     &ndr_table_spoolss.syntax_id);
	if (!NT_STATUS_IS_OK(nt_status)) {
		return nt_status;
	}
	b_dst = pipe_hnd_dst->binding_handle;

	/* enum source printers */
	if (!get_printer_info(pipe_hnd, mem_ctx, level, argc, argv, &num_printers, &info_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 */
		printername = info_enum[i].info2.printername;
		sharename = info_enum[i].info2.sharename;

		if (!printername || !sharename) {
			nt_status = NT_STATUS_UNSUCCESSFUL;
			goto done;
		}

		/* 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;

		/* 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;

		/* check for existing dst printer */
		if (!net_spoolss_getprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, level, &info_dst))
			goto done;

		/* check for existing src printer */
		if (!net_spoolss_getprinter(pipe_hnd, mem_ctx, &hnd_src, 3, &info_src))
			goto done;

		/* Copy Security Descriptor */

		/* copy secdesc (info level 2) */
		info_dst.info2.devmode = NULL;
		info_dst.info2.secdesc = dup_sec_desc(mem_ctx, info_src.info3.secdesc);

		if (c->opt_verbose)
			display_sec_desc(info_dst.info2.secdesc);

		if (!net_spoolss_setprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, 2, &info_dst))
			goto done;

		DEBUGADD(1,("\tSetPrinter of SECDESC succeeded\n"));


		/* close printer handles here */
		if (is_valid_policy_hnd(&hnd_src)) {
			dcerpc_spoolss_ClosePrinter(b_src, mem_ctx, &hnd_src, &werr);
		}

		if (is_valid_policy_hnd(&hnd_dst)) {
			dcerpc_spoolss_ClosePrinter(b_dst, mem_ctx, &hnd_dst, &werr);
		}

	}

	nt_status = NT_STATUS_OK;

done:

	if (is_valid_policy_hnd(&hnd_src)) {
		dcerpc_spoolss_ClosePrinter(b_src, mem_ctx, &hnd_src, &werr);
	}

	if (is_valid_policy_hnd(&hnd_dst)) {
		dcerpc_spoolss_ClosePrinter(b_dst, mem_ctx, &hnd_dst, &werr);
	}

	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 c	A net_context structure
 * @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(struct net_context *c,
						const struct 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)
{
	struct dcerpc_binding_handle *b_src = pipe_hnd->binding_handle;
	NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
	WERROR result;
	uint32_t i, f;
	uint32_t num_printers;
	uint32_t level = 1;
	const char *printername, *sharename;
	struct rpc_pipe_client *pipe_hnd_dst = NULL;
	struct dcerpc_binding_handle *b_dst = NULL;
	struct policy_handle hnd_src = { 0, };
	struct policy_handle hnd_dst = { 0, };
	union spoolss_PrinterInfo *info_enum;
	union spoolss_PrinterInfo info_dst;
	uint32_t num_forms;
	union spoolss_FormInfo *forms;
	struct cli_state *cli_dst = NULL;

	DEBUG(3,("copying forms\n"));

	/* connect destination PI_SPOOLSS */
	nt_status = connect_dst_pipe(c, &cli_dst, &pipe_hnd_dst,
				     &ndr_table_spoolss.syntax_id);
	if (!NT_STATUS_IS_OK(nt_status)) {
		return nt_status;
	}
	b_dst = pipe_hnd_dst->binding_handle;

	/* enum src printers */
	if (!get_printer_info(pipe_hnd, mem_ctx, 2, argc, argv, &num_printers, &info_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 */
		printername = info_enum[i].info2.printername;
		sharename = info_enum[i].info2.sharename;

		if (!printername || !sharename) {
			nt_status = NT_STATUS_UNSUCCESSFUL;
			goto done;
		}
		/* 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;

		/* 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;

		/* check for existing dst printer */
		if (!net_spoolss_getprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, level, &info_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++) {

			union spoolss_AddFormInfo info;
			NTSTATUS status;

			/* only migrate FORM_PRINTER types, according to jerry
			   FORM_BUILTIN-types are hard-coded in samba */
			if (forms[f].info1.flags != SPOOLSS_FORM_PRINTER)
				continue;

			if (c->opt_verbose)
				d_printf(_("\tmigrating form # %d [%s] of type "
					   "[%d]\n"),
					f, forms[f].info1.form_name,
					forms[f].info1.flags);

			info.info1 = (struct spoolss_AddFormInfo1 *)
				(void *)&forms[f].info1;

			/* FIXME: there might be something wrong with samba's
			   builtin-forms */
			status = dcerpc_spoolss_AddForm(b_dst, mem_ctx,
							&hnd_dst,
							1,
							info,
							&result);
			if (!NT_STATUS_IS_OK(status)) {
				d_printf(_("\tdcerpc_spoolss_AddForm form %d: [%s] - %s\n"),
					f, forms[f].info1.form_name, nt_errstr(status));
				continue;
			}
			if (!W_ERROR_IS_OK(result)) {
				d_printf(_("\tAddForm form %d: [%s] refused.\n"),
					f, forms[f].info1.form_name);
				continue;
			}

			DEBUGADD(1,("\tAddForm of [%s] succeeded\n",
				forms[f].info1.form_name));
		}


		/* close printer handles here */
		if (is_valid_policy_hnd(&hnd_src)) {
			dcerpc_spoolss_ClosePrinter(b_src, mem_ctx, &hnd_src, &result);
		}

		if (is_valid_policy_hnd(&hnd_dst)) {
			dcerpc_spoolss_ClosePrinter(b_dst, mem_ctx, &hnd_dst, &result);
		}
	}

	nt_status = NT_STATUS_OK;

done:

	if (is_valid_policy_hnd(&hnd_src)) {
		dcerpc_spoolss_ClosePrinter(b_src, mem_ctx, &hnd_src, &result);
	}

	if (is_valid_policy_hnd(&hnd_dst)) {
		dcerpc_spoolss_ClosePrinter(b_dst, mem_ctx, &hnd_dst, &result);
	}

	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 c	A net_context structure
 * @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(struct net_context *c,
						const struct 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)
{
	struct dcerpc_binding_handle *b_src = pipe_hnd->binding_handle;
	NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
	uint32_t i, p;
	uint32_t num_printers;
	uint32_t level = 3;
	const char *printername, *sharename;
	bool got_src_driver_share = false;
	bool got_dst_driver_share = false;
	struct rpc_pipe_client *pipe_hnd_dst = NULL;
	struct dcerpc_binding_handle *b_dst = NULL;
	struct policy_handle hnd_src = { 0, };
	struct policy_handle hnd_dst = { 0, };
	union spoolss_DriverInfo drv_info_src;
	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;
	WERROR werr;

	DEBUG(3,("copying printer-drivers\n"));

	nt_status = connect_dst_pipe(c, &cli_dst, &pipe_hnd_dst,
				     &ndr_table_spoolss.syntax_id);
	if (!NT_STATUS_IS_OK(nt_status)) {
		return nt_status;
	}
	b_dst = pipe_hnd_dst->binding_handle;

	/* open print$-share on the src server */
	nt_status = connect_to_service(c, &cli_share_src,
				       cli_state_remote_sockaddr(cli),
				       cli_state_remote_name(cli),
				       "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(c, &cli_share_dst,
				       cli_state_remote_sockaddr(cli_dst),
				       cli_state_remote_name(cli_dst),
				       "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_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 */
		printername = info_enum[p].info2.printername;
		sharename = info_enum[p].info2.sharename;

		if (!printername || !sharename) {
			nt_status = NT_STATUS_UNSUCCESSFUL;
			goto done;
		}

		/* 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;

		/* check for existing dst printer */
		if (!net_spoolss_getprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, 2, &info_dst))
			goto done;


		/* open src printer handle */
		if (!net_spoolss_open_printer_ex(pipe_hnd, mem_ctx, sharename,
						 MAXIMUM_ALLOWED_ACCESS,
						 pipe_hnd->auth->user_name,
						 &hnd_src))
			goto done;

		/* 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_info_src))
				continue;

			drivername = drv_info_src.info3.driver_name;

			if (c->opt_verbose)
				display_print_driver3(&drv_info_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(c, mem_ctx, cli_share_src, cli_share_dst,
							archi_table[i].short_archi,
							&drv_info_src.info3);
			if (!NT_STATUS_IS_OK(nt_status))
				goto done;


			/* adddriver dst */
			if (!net_spoolss_addprinterdriver(pipe_hnd_dst, mem_ctx, level, &drv_info_src)) {
				nt_status = NT_STATUS_UNSUCCESSFUL;
				goto done;
			}

			DEBUGADD(1,("Sucessfully added driver [%s] for printer [%s]\n",
				drivername, printername));

		}

		if (!drivername || strlen(drivername) == 0) {
			DEBUGADD(1,("Did not get driver for printer %s\n",
				    printername));
			goto done;
		}

		/* setdriver dst */
		info_dst.info2.drivername = drivername;

		if (!net_spoolss_setprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, 2, &info_dst)) {
			nt_status = NT_STATUS_UNSUCCESSFUL;
			goto done;
		}

		DEBUGADD(1,("Sucessfully set driver %s for printer %s\n",
			drivername, printername));

		/* close dst */
		if (is_valid_policy_hnd(&hnd_dst)) {
			dcerpc_spoolss_ClosePrinter(b_dst, mem_ctx, &hnd_dst, &werr);
		}

		/* close src */
		if (is_valid_policy_hnd(&hnd_src)) {
			dcerpc_spoolss_ClosePrinter(b_src, mem_ctx, &hnd_src, &werr);
		}
	}

	nt_status = NT_STATUS_OK;

done:

	if (is_valid_policy_hnd(&hnd_dst)) {
		dcerpc_spoolss_ClosePrinter(b_dst, mem_ctx, &hnd_dst, &werr);
	}

	/* close src */
	if (is_valid_policy_hnd(&hnd_src)) {
		dcerpc_spoolss_ClosePrinter(b_src, mem_ctx, &hnd_src, &werr);
	}

	if (cli_dst) {
		cli_shutdown(cli_dst);
	}

	if (got_src_driver_share)
		cli_shutdown(cli_share_src);

	if (got_dst_driver_share)
		cli_shutdown(cli_share_dst);

	return nt_status;

}

/**
 * Migrate printer-queues from a src to the dst server
 * (requires a working "addprinter command" to be installed for the local smbd)
 *
 * All parameters are provided by the run_rpc_command function, except for
 * argc, argv which are passed through.
 *
 * @param c	A net_context structure
 * @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_printers_internals(struct net_context *c,
						const struct 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)
{
	struct dcerpc_binding_handle *b_src = pipe_hnd->binding_handle;
	WERROR result;
	NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
	uint32_t i = 0, num_printers;
	uint32_t level = 2;
	union spoolss_PrinterInfo info_dst, info_src;
	union spoolss_PrinterInfo *info_enum;
	struct cli_state *cli_dst = NULL;
	struct policy_handle hnd_src = { 0, };
	struct policy_handle hnd_dst = { 0, };
	const char *printername, *sharename;
	struct rpc_pipe_client *pipe_hnd_dst = NULL;
	struct dcerpc_binding_handle *b_dst = NULL;
	struct spoolss_SetPrinterInfoCtr info_ctr;

	DEBUG(3,("copying printers\n"));

	/* connect destination PI_SPOOLSS */
	nt_status = connect_dst_pipe(c, &cli_dst, &pipe_hnd_dst,
				     &ndr_table_spoolss.syntax_id);
	if (!NT_STATUS_IS_OK(nt_status)) {
		return nt_status;
	}
	b_dst = pipe_hnd_dst->binding_handle;

	/* enum printers */
	if (!get_printer_info(pipe_hnd, mem_ctx, level, argc, argv, &num_printers, &info_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++) {

		struct spoolss_SetPrinterInfo2 info2;

		/* do some initialization */
		printername = info_enum[i].info2.printername;
		sharename = info_enum[i].info2.sharename;

		if (!printername || !sharename) {
			nt_status = NT_STATUS_UNSUCCESSFUL;
			goto done;
		}
		/* 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 queue 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)) {

			DEBUG(1,("could not open printer: %s\n", sharename));
		}

		/* check for existing dst printer */
		if (!net_spoolss_getprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, level, &info_dst)) {
			printf (_("could not get printer, creating printer.\n"));
		} else {
			DEBUG(1,("printer already exists: %s\n", sharename));
			/* close printer handle here - dst only, not got src yet. */
			if (is_valid_policy_hnd(&hnd_dst)) {
				dcerpc_spoolss_ClosePrinter(b_dst, mem_ctx, &hnd_dst, &result);
			}
			continue;
		}

		/* now get again src printer ctr via getprinter,
		   we first need a handle for that */

		/* 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;

		/* getprinter on the src server */
		if (!net_spoolss_getprinter(pipe_hnd, mem_ctx, &hnd_src, level, &info_src))
			goto done;

		/* copy each src printer to a dst printer 1:1,
		   maybe some values have to be changed though */
		d_printf(_("creating printer: %s\n"), printername);

		info_ctr.level = level;
		spoolss_printerinfo2_to_setprinterinfo2(&info_src.info2, &info2);
		info_ctr.info.info2 = &info2;

		result = rpccli_spoolss_addprinterex(pipe_hnd_dst,
						     mem_ctx,
						     &info_ctr);

		if (W_ERROR_IS_OK(result))
			d_printf (_("printer [%s] successfully added.\n"),
				  printername);
		else if (W_ERROR_V(result) == W_ERROR_V(WERR_PRINTER_ALREADY_EXISTS))
			d_fprintf (stderr, _("printer [%s] already exists.\n"),
				   printername);
		else {
			d_fprintf (stderr, _("could not create printer [%s]\n"),
				   printername);
			goto done;
		}

		/* close printer handles here */
		if (is_valid_policy_hnd(&hnd_src)) {
			dcerpc_spoolss_ClosePrinter(b_src, mem_ctx, &hnd_src, &result);
		}

		if (is_valid_policy_hnd(&hnd_dst)) {
			dcerpc_spoolss_ClosePrinter(b_dst, mem_ctx, &hnd_dst, &result);
		}
	}

	nt_status = NT_STATUS_OK;

done:
	if (is_valid_policy_hnd(&hnd_src)) {
		dcerpc_spoolss_ClosePrinter(b_src, mem_ctx, &hnd_src, &result);
	}

	if (is_valid_policy_hnd(&hnd_dst)) {
		dcerpc_spoolss_ClosePrinter(b_dst, mem_ctx, &hnd_dst, &result);
	}

	if (cli_dst) {
		cli_shutdown(cli_dst);
	}
	return nt_status;
}

/**
 * Migrate Printer-Settings from a src server to the dst server
 * (for this to work, printers and drivers already have to be migrated earlier)
 *
 * All parameters are provided by the run_rpc_command function, except for
 * argc, argv which are passed through.
 *
 * @param c	A net_context structure
 * @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_settings_internals(struct net_context *c,
						const struct 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)
{
	struct dcerpc_binding_handle *b_src = pipe_hnd->binding_handle;

	/* FIXME: Here the nightmare begins */

	WERROR result;
	NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
	uint32_t i = 0, j = 0;
	uint32_t num_printers;
	uint32_t level = 2;
	const char *printername, *sharename;
	struct rpc_pipe_client *pipe_hnd_dst = NULL;
	struct dcerpc_binding_handle *b_dst = NULL;
	struct policy_handle hnd_src = { 0, };
	struct policy_handle hnd_dst = { 0, };
	union spoolss_PrinterInfo *info_enum;
	union spoolss_PrinterInfo info_dst_publish;
	union spoolss_PrinterInfo info_dst;
	struct cli_state *cli_dst = NULL;
	const char *longname;
	const char **keylist = NULL;

	/* FIXME GD */
	ZERO_STRUCT(info_dst_publish);

	DEBUG(3,("copying printer settings\n"));

	/* connect destination PI_SPOOLSS */
	nt_status = connect_dst_pipe(c, &cli_dst, &pipe_hnd_dst,
				     &ndr_table_spoolss.syntax_id);
	if (!NT_STATUS_IS_OK(nt_status)) {
		return nt_status;
	}
	b_dst = pipe_hnd_dst->binding_handle;

	/* enum src printers */
	if (!get_printer_info(pipe_hnd, mem_ctx, level, argc, argv, &num_printers, &info_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;
	}


	/* needed for dns-strings in regkeys */
	longname = get_mydnsfullname();
	if (!longname) {
		nt_status = NT_STATUS_UNSUCCESSFUL;
		goto done;
	}

	/* do something for all printers */
	for (i = 0; i < num_printers; i++) {

		uint32_t value_needed;
		uint32_t data_needed;
		enum winreg_Type type;
		struct spoolss_EnumPrinterData r;

		/* do some initialization */
		printername = info_enum[i].info2.printername;
		sharename = info_enum[i].info2.sharename;

		if (!printername || !sharename) {
			nt_status = NT_STATUS_UNSUCCESSFUL;
			goto done;
		}
		/* 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 settings 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;

		/* 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;

		/* check for existing dst printer */
		if (!net_spoolss_getprinter(pipe_hnd_dst, mem_ctx, &hnd_dst,
				level, &info_dst))
			goto done;


		/* STEP 1: COPY DEVICE-MODE and other
			   PRINTER_INFO_2-attributes
		*/

		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 (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))
				goto done;

			info_dst_publish.info7.action = DSPRINT_PUBLISH;

			/* ignore false from setprinter due to WERR_IO_PENDING */
			net_spoolss_setprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, 7, &info_dst_publish);

			DEBUG(3,("republished printer\n"));
		}

		if (info_enum[i].info2.devmode != NULL) {

			/* copy devmode (info level 2) */
			info_dst.info2.devmode = info_enum[i].info2.devmode;

			/* do not copy security descriptor (we have another
			 * command for that) */
			info_dst.info2.secdesc = NULL;

#if 0
			info_dst.info2.devmode.devicename =
				talloc_asprintf(mem_ctx, "\\\\%s\\%s",
						longname, printername);
			if (!info_dst.info2.devmode.devicename) {
				nt_status = NT_STATUS_NO_MEMORY;
				goto done;
			}
#endif
			if (!net_spoolss_setprinter(pipe_hnd_dst, mem_ctx, &hnd_dst,
						    level, &info_dst))
				goto done;

			DEBUGADD(1,("\tSetPrinter of DEVICEMODE succeeded\n"));
		}

		/* STEP 2: COPY REGISTRY VALUES */

		/* please keep in mind that samba parse_spools gives horribly
		   crippled results when used to rpccli_spoolss_enumprinterdataex
		   a win2k3-server.  (Bugzilla #1851)
		   FIXME: IIRC I've seen it too on a win2k-server
		*/

		r.in.handle = &hnd_src;
		r.in.enum_index = 0;
		r.in.value_offered = 0;
		r.in.data_offered = 0;
		r.out.value_name = NULL;
		r.out.value_needed = &value_needed;
		r.out.type = &type;
		r.out.data = NULL;
		r.out.data_needed = &data_needed;

		/* enumerate data on src handle */
		nt_status = dcerpc_spoolss_EnumPrinterData_r(b_src, mem_ctx, &r);

		r.in.data_offered	= *r.out.data_needed;
		r.in.value_offered	= *r.out.value_needed;
		r.out.data		= talloc_zero_array(mem_ctx, uint8_t, r.in.data_offered);
		r.out.value_name	= talloc_zero_array(mem_ctx, char, r.in.value_offered);

		/* loop for all printerdata of "PrinterDriverData" */
		while (NT_STATUS_IS_OK(nt_status) && W_ERROR_IS_OK(r.out.result)) {

			r.in.enum_index++;

			nt_status = dcerpc_spoolss_EnumPrinterData_r(b_src, mem_ctx, &r);

			/* loop for all reg_keys */
			if (NT_STATUS_IS_OK(nt_status) && W_ERROR_IS_OK(r.out.result)) {

				/* display_value */
				if (c->opt_verbose) {
					struct registry_value v;
					v.type = *r.out.type;
					v.data = data_blob_const(
						r.out.data, r.in.data_offered);

					display_reg_value(SPOOL_PRINTERDATA_KEY,
							  r.out.value_name, &v);
				}

				/* set_value */
				if (!net_spoolss_setprinterdata(pipe_hnd_dst, mem_ctx,
								&hnd_dst, r.out.value_name,
								*r.out.type, r.out.data, r.in.data_offered))
					goto done;

				DEBUGADD(1,("\tSetPrinterData of [%s] succeeded\n",
					    r.out.value_name));
			}
		}

		/* STEP 3: COPY SUBKEY VALUES */

		/* here we need to enum all printer_keys and then work
		   on the result with enum_printer_key_ex. nt4 does not
		   respond to enumprinterkey, win2k does, so continue
		   in case of an error */

		if (!net_spoolss_enumprinterkey(pipe_hnd, mem_ctx, &hnd_src, "", &keylist)) {
			printf(_("got no key-data\n"));
			continue;
		}


		/* work on a list of printer keys
		   each key has to be enumerated to get all required
		   information.  information is then set via setprinterdataex-calls */

		if (keylist == NULL)
			continue;

		for (i=0; keylist && keylist[i] != NULL; i++) {

			const char *subkey = keylist[i];
			uint32_t count;
			struct spoolss_PrinterEnumValues *info;

			/* enumerate all src subkeys */
			if (!net_spoolss_enumprinterdataex(pipe_hnd, mem_ctx, 0,
							   &hnd_src, subkey,
							   &count, &info)) {
				goto done;
			}

			for (j=0; j < count; j++) {

				struct registry_value value;
				const char *value_name = info[j].value_name;
				value.type = REG_SZ;

				/* although samba replies with sane data in most cases we
				   should try to avoid writing wrong registry data */

				if (strequal(value_name, SPOOL_REG_PORTNAME)) {
					/* although windows uses a multi-sz, we use a sz */
					push_reg_sz(mem_ctx, &value.data, SAMBA_PRINTER_PORT_NAME);
				}
				else if (strequal(value_name, SPOOL_REG_UNCNAME)) {
					char *unc_name;
					if (asprintf(&unc_name, "\\\\%s\\%s", longname, sharename) < 0) {
						nt_status = NT_STATUS_NO_MEMORY;
						goto done;
					}
					push_reg_sz(mem_ctx, &value.data, unc_name);
					free(unc_name);
				}
				else if (strequal(value_name, SPOOL_REG_URL)) {
					continue;
#if 0
					/* FIXME: should we really do that ??? */
					if (asprintf(&url, "http://%s:631/printers/%s", longname, sharename) < 0) {
						nt_status = NT_STATUS_NO_MEMORY;
						goto done;
					}
					push_reg_sz(mem_ctx, NULL, &value.data, url);
					free(url);
#endif
				}
				else if (strequal(value_name, SPOOL_REG_SERVERNAME)) {
					push_reg_sz(mem_ctx, &value.data, longname);
				}
				else if (strequal(value_name, SPOOL_REG_SHORTSERVERNAME)) {
					push_reg_sz(mem_ctx, &value.data, lp_netbios_name());
				}
				else {
					value.type = info[j].type;
					value.data = *info[j].data;
				}

				if (c->opt_verbose) {
					display_reg_value(subkey, value_name, &value);
				}

				/* here we have to set all subkeys on the dst server */
				if (!net_spoolss_setprinterdataex(pipe_hnd_dst, mem_ctx, &hnd_dst,
								  subkey, value_name, &value))
				{
					goto done;
				}

				DEBUGADD(1,("\tSetPrinterDataEx of key [%s\\%s] succeeded\n",
						subkey, info[j].value_name));

			}
		}

		TALLOC_FREE(keylist);

		/* close printer handles here */
		if (is_valid_policy_hnd(&hnd_src)) {
			dcerpc_spoolss_ClosePrinter(b_src, mem_ctx, &hnd_src, &result);
		}

		if (is_valid_policy_hnd(&hnd_dst)) {
			dcerpc_spoolss_ClosePrinter(b_dst, mem_ctx, &hnd_dst, &result);
		}
	}

	nt_status = NT_STATUS_OK;

done:
	if (is_valid_policy_hnd(&hnd_src)) {
		dcerpc_spoolss_ClosePrinter(b_src, mem_ctx, &hnd_src, &result);
	}

	if (is_valid_policy_hnd(&hnd_dst)) {
		dcerpc_spoolss_ClosePrinter(b_dst, mem_ctx, &hnd_dst, &result);
	}

	if (cli_dst) {
		cli_shutdown(cli_dst);
	}
	return nt_status;
}