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
|
/*
* "$Id: adminutil.c 5970 2006-09-19 20:11:08Z mike $"
*
* Administration utility API definitions for the Common UNIX Printing
* System (CUPS).
*
* MANY OF THE FUNCTIONS IN THIS HEADER ARE PRIVATE AND SUBJECT TO
* CHANGE AT ANY TIME. USE AT YOUR OWN RISK.
*
* Copyright 2001-2006 by Easy Software Products.
*
* These coded instructions, statements, and computer programs are the
* property of Easy Software Products and are protected by Federal
* copyright law. Distribution and use rights are outlined in the file
* "LICENSE.txt" which should have been included with this file. If this
* file is missing or damaged please contact Easy Software Products
* at:
*
* Attn: CUPS Licensing Information
* Easy Software Products
* 44141 Airport View Drive, Suite 204
* Hollywood, Maryland 20636 USA
*
* Voice: (301) 373-9600
* EMail: cups-info@cups.org
* WWW: http://www.cups.org
*
* This file is subject to the Apple OS-Developed Software exception.
*
* Contents:
*
* cupsAdminCreateWindowsPPD() - Create the Windows PPD file for a printer.
* cupsAdminExportSamba() - Export a printer to Samba.
* _cupsAdminGetServerSettings() - Get settings from the server.
* _cupsAdminSetServerSettings() - Set settings on the server.
* do_samba_command() - Do a SAMBA command.
* get_cupsd_conf() - Get the current cupsd.conf file.
* invalidate_cupsd_cache() - Invalidate the cached cupsd.conf settings.
* write_option() - Write a CUPS option to a PPD file.
*/
/*
* Include necessary headers...
*/
#include "adminutil.h"
#include "globals.h"
#include "debug.h"
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/wait.h>
/*
* Local functions...
*/
static int do_samba_command(const char *command,
const char *address,
const char *subcommand,
const char *authfile,
FILE *logfile);
static http_status_t get_cupsd_conf(http_t *http, _cups_globals_t *cg,
time_t last_update, char *name,
int namelen, int *remote);
static void invalidate_cupsd_cache(_cups_globals_t *cg);
static void write_option(cups_file_t *dstfp, int order,
const char *name, const char *text,
const char *attrname,
ipp_attribute_t *suppattr,
ipp_attribute_t *defattr, int defval,
int valcount);
/*
* 'cupsAdminCreateWindowsPPD()' - Create the Windows PPD file for a printer.
*/
char * /* O - PPD file or NULL */
cupsAdminCreateWindowsPPD(
http_t *http, /* I - Connection to server */
const char *dest, /* I - Printer or class */
char *buffer, /* I - Filename buffer */
int bufsize) /* I - Size of filename buffer */
{
const char *src; /* Source PPD filename */
cups_file_t *srcfp, /* Source PPD file */
*dstfp; /* Destination PPD file */
ipp_t *request, /* IPP request */
*response; /* IPP response */
ipp_attribute_t *suppattr, /* IPP -supported attribute */
*defattr; /* IPP -default attribute */
cups_lang_t *language; /* Current language */
char line[256], /* Line from PPD file */
junk[256], /* Extra junk to throw away */
*ptr, /* Pointer into line */
uri[1024], /* Printer URI */
option[41], /* Option */
choice[41]; /* Choice */
int jcloption, /* In a JCL option? */
linenum; /* Current line number */
time_t curtime; /* Current time */
struct tm *curdate; /* Current date */
static const char * const pattrs[] = /* Printer attributes we want */
{
"job-hold-until-supported",
"job-hold-until-default",
"job-sheets-supported",
"job-sheets-default",
"job-priority-supported",
"job-priority-default"
};
/*
* Range check the input...
*/
if (buffer)
*buffer = '\0';
if (!http || !dest || !buffer || bufsize < 2)
return (NULL);
/*
* Get the PPD file...
*/
if ((src = cupsGetPPD2(http, dest)) == NULL)
return (NULL);
/*
* Get the supported banner pages, etc. for the printer...
*/
request = ippNewRequest(IPP_GET_PRINTER_ATTRIBUTES);
httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL,
"localhost", 0, "/printers/%s", dest);
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
"printer-uri", NULL, uri);
ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
"requested-attributes", sizeof(pattrs) / sizeof(pattrs[0]),
NULL, pattrs);
/*
* Do the request and get back a response...
*/
response = cupsDoRequest(http, request, "/");
if (!response || cupsLastError() > IPP_OK_CONFLICT)
{
unlink(src);
return (NULL);
}
/*
* Open the original PPD file...
*/
if ((srcfp = cupsFileOpen(src, "rb")) == NULL)
return (NULL);
/*
* Create a temporary output file using the destination buffer...
*/
if ((dstfp = cupsTempFile2(buffer, bufsize)) == NULL)
{
cupsFileClose(srcfp);
unlink(src);
return (NULL);
}
/*
* Write a new header explaining that this isn't the original PPD...
*/
cupsFilePuts(dstfp, "*PPD-Adobe: \"4.3\"\n");
curtime = time(NULL);
curdate = gmtime(&curtime);
cupsFilePrintf(dstfp, "*%% Modified on %04d%02d%02d%02d%02d%02d+0000 "
"for CUPS Windows Driver\n",
curdate->tm_year + 1900, curdate->tm_mon + 1, curdate->tm_mday,
curdate->tm_hour, curdate->tm_min, curdate->tm_sec);
/*
* Read the existing PPD file, converting all PJL commands to CUPS
* job ticket comments...
*/
jcloption = 0;
linenum = 0;
language = cupsLangDefault();
while (cupsFileGets(srcfp, line, sizeof(line)))
{
linenum ++;
if (!strncmp(line, "*PPD-Adobe:", 11))
{
/*
* Already wrote the PPD header...
*/
continue;
}
else if (!strncmp(line, "*JCLBegin:", 10) ||
!strncmp(line, "*JCLToPSInterpreter:", 20) ||
!strncmp(line, "*JCLEnd:", 8) ||
!strncmp(line, "*Protocols:", 11))
{
/*
* Don't use existing JCL keywords; we'll create our own, below...
*/
cupsFilePrintf(dstfp, "*%% Commented out for CUPS Windows Driver...\n"
"*%%%s\n", line + 1);
continue;
}
else if (!strncmp(line, "*JCLOpenUI", 10))
{
jcloption = 1;
cupsFilePrintf(dstfp, "%s\n", line);
}
else if (!strncmp(line, "*JCLCloseUI", 11))
{
jcloption = 0;
cupsFilePrintf(dstfp, "%s\n", line);
}
else if (jcloption &&
strncmp(line, "*End", 4) &&
strncmp(line, "*Default", 8) &&
strncmp(line, "*OrderDependency", 16))
{
if ((ptr = strchr(line, ':')) == NULL)
{
snprintf(line, sizeof(line),
_cupsLangString(language, _("Missing value on line %d!\n")),
linenum);
_cupsSetError(IPP_DOCUMENT_FORMAT_ERROR, line);
cupsFileClose(srcfp);
cupsFileClose(dstfp);
unlink(src);
unlink(buffer);
*buffer = '\0';
return (NULL);
}
if ((ptr = strchr(ptr, '\"')) == NULL)
{
snprintf(line, sizeof(line),
_cupsLangString(language,
_("Missing double quote on line %d!\n")),
linenum);
_cupsSetError(IPP_DOCUMENT_FORMAT_ERROR, line);
cupsFileClose(srcfp);
cupsFileClose(dstfp);
unlink(src);
unlink(buffer);
*buffer = '\0';
return (NULL);
}
if (sscanf(line, "*%40s%*[ \t]%40[^/]", option, choice) != 2)
{
snprintf(line, sizeof(line),
_cupsLangString(language,
_("Bad option + choice on line %d!\n")),
linenum);
_cupsSetError(IPP_DOCUMENT_FORMAT_ERROR, line);
cupsFileClose(srcfp);
cupsFileClose(dstfp);
unlink(src);
unlink(buffer);
*buffer = '\0';
return (NULL);
}
if (strchr(ptr + 1, '\"') == NULL)
{
/*
* Skip remaining...
*/
while (cupsFileGets(srcfp, junk, sizeof(junk)) != NULL)
{
linenum ++;
if (!strncmp(junk, "*End", 4))
break;
}
}
snprintf(ptr + 1, sizeof(line) - (ptr - line + 1),
"%%cupsJobTicket: %s=%s\n\"\n*End", option, choice);
cupsFilePrintf(dstfp, "*%% Changed for CUPS Windows Driver...\n%s\n",
line);
}
else
cupsFilePrintf(dstfp, "%s\n", line);
}
cupsFileClose(srcfp);
unlink(src);
/*
* Now add the CUPS-specific attributes and options...
*/
cupsFilePuts(dstfp, "\n*% CUPS Job Ticket support and options...\n");
cupsFilePuts(dstfp, "*Protocols: PJL\n");
cupsFilePuts(dstfp, "*JCLBegin: \"%!PS-Adobe-3.0<0A>\"\n");
cupsFilePuts(dstfp, "*JCLToPSInterpreter: \"\"\n");
cupsFilePuts(dstfp, "*JCLEnd: \"\"\n");
cupsFilePuts(dstfp, "\n*OpenGroup: CUPS/CUPS Options\n\n");
if ((defattr = ippFindAttribute(response, "job-hold-until-default",
IPP_TAG_ZERO)) != NULL &&
(suppattr = ippFindAttribute(response, "job-hold-until-supported",
IPP_TAG_ZERO)) != NULL)
write_option(dstfp, 10, "cupsJobHoldUntil", "Hold Until", "job-hold-until",
suppattr, defattr, 0, 1);
if ((defattr = ippFindAttribute(response, "job-priority-default",
IPP_TAG_INTEGER)) != NULL &&
(suppattr = ippFindAttribute(response, "job-priority-supported",
IPP_TAG_RANGE)) != NULL)
write_option(dstfp, 11, "cupsJobPriority", "Priority", "job-priority",
suppattr, defattr, 0, 1);
if ((defattr = ippFindAttribute(response, "job-sheets-default",
IPP_TAG_ZERO)) != NULL &&
(suppattr = ippFindAttribute(response, "job-sheets-supported",
IPP_TAG_ZERO)) != NULL)
{
write_option(dstfp, 20, "cupsJobSheetsStart", "Start Banner",
"job-sheets", suppattr, defattr, 0, 2);
write_option(dstfp, 21, "cupsJobSheetsEnd", "End Banner",
"job-sheets", suppattr, defattr, 1, 2);
}
cupsFilePuts(dstfp, "*CloseGroup: CUPS\n");
cupsFileClose(dstfp);
ippDelete(response);
return (buffer);
}
/*
* 'cupsAdminExportSamba()' - Export a printer to Samba.
*/
int /* O - 1 on success, 0 on failure */
cupsAdminExportSamba(
const char *dest, /* I - Destination to export */
const char *ppd, /* I - PPD file */
const char *samba_server, /* I - Samba server */
const char *samba_user, /* I - Samba username */
const char *samba_password, /* I - Samba password */
FILE *logfile) /* I - Log file, if any */
{
int status; /* Status of Samba commands */
int have_drivers; /* Have drivers? */
char file[1024], /* File to test for */
authfile[1024], /* Temporary authentication file */
address[1024], /* Address for command */
subcmd[1024], /* Sub-command */
message[1024]; /* Error message */
cups_file_t *fp; /* Authentication file */
cups_lang_t *language; /* Current language */
_cups_globals_t *cg = _cupsGlobals();
/* Global data */
/*
* Range check input...
*/
if (!dest || !ppd || !samba_server || !samba_user || !samba_password)
{
_cupsSetError(IPP_INTERNAL_ERROR, NULL);
return (0);
}
/*
* Create a temporary authentication file for Samba...
*/
if ((fp = cupsTempFile2(authfile, sizeof(authfile))) == NULL)
{
_cupsSetError(IPP_INTERNAL_ERROR, strerror(errno));
return (0);
}
cupsFilePrintf(fp, "username = %s\n", samba_user);
cupsFilePrintf(fp, "password = %s\n", samba_password);
cupsFileClose(fp);
/*
* See which drivers are available; the new CUPS v6 and Adobe drivers
* depend on the Windows 2k PS driver, so copy that driver first:
*
* Files:
*
* ps5ui.dll
* pscript.hlp
* pscript.ntf
* pscript5.dll
*/
have_drivers = 0;
language = cupsLangDefault();
snprintf(file, sizeof(file), "%s/drivers/pscript5.dll", cg->cups_datadir);
if (!access(file, 0))
{
have_drivers |= 1;
/*
* Windows 2k driver is installed; do the smbclient commands needed
* to copy the Win2k drivers over...
*/
snprintf(address, sizeof(address), "//%s/print$", samba_server);
snprintf(subcmd, sizeof(subcmd),
"mkdir W32X86;"
"put %s W32X86/%s.ppd;"
"put %s/drivers/ps5ui.dll W32X86/ps5ui.dll;"
"put %s/drivers/pscript.hlp W32X86/pscript.hlp;"
"put %s/drivers/pscript.ntf W32X86/pscript.ntf;"
"put %s/drivers/pscript5.dll W32X86/pscript5.dll",
ppd, dest, cg->cups_datadir, cg->cups_datadir,
cg->cups_datadir, cg->cups_datadir);
if ((status = do_samba_command("smbclient", address, subcmd,
authfile, logfile)) != 0)
{
snprintf(message, sizeof(message),
_cupsLangString(language,
_("Unable to copy Windows 2000 printer "
"driver files (%d)!")), status);
_cupsSetError(IPP_INTERNAL_ERROR, message);
if (logfile)
_cupsLangPrintf(logfile, "%s\n", message);
unlink(authfile);
return (0);
}
/*
* See if we also have the CUPS driver files; if so, use them!
*/
snprintf(file, sizeof(file), "%s/drivers/cupsps6.dll", cg->cups_datadir);
if (!access(file, 0))
{
/*
* Copy the CUPS driver files over...
*/
snprintf(subcmd, sizeof(subcmd),
"put %s/drivers/cups6.ini W32X86/cups6.ini;"
"put %s/drivers/cupsps6.dll W32X86/cupsps6.dll;"
"put %s/drivers/cupsui6.dll W32X86/cupsui6.dll",
cg->cups_datadir, cg->cups_datadir, cg->cups_datadir);
if ((status = do_samba_command("smbclient", address, subcmd,
authfile, logfile)) != 0)
{
snprintf(message, sizeof(message),
_cupsLangString(language,
_("Unable to copy CUPS printer driver "
"files (%d)!")), status);
_cupsSetError(IPP_INTERNAL_ERROR, message);
if (logfile)
_cupsLangPrintf(logfile, "%s\n", message);
unlink(authfile);
return (0);
}
/*
* Do the rpcclient command needed for the CUPS drivers...
*/
snprintf(subcmd, sizeof(subcmd),
"adddriver \"Windows NT x86\" \"%s:"
"pscript5.dll:%s.ppd:ps5ui.dll:pscript.hlp:NULL:RAW:"
"pscript5.dll,%s.ppd,ps5ui.dll,pscript.hlp,pscript.ntf,"
"cups6.ini,cupsps6.dll,cupsui6.dll\"",
dest, dest, dest);
}
else
{
/*
* Don't have the CUPS drivers, so just use the standard Windows
* drivers...
*/
snprintf(subcmd, sizeof(subcmd),
"adddriver \"Windows NT x86\" \"%s:"
"pscript5.dll:%s.ppd:ps5ui.dll:pscript.hlp:NULL:RAW:"
"pscript5.dll,%s.ppd,ps5ui.dll,pscript.hlp,pscript.ntf\"",
dest, dest, dest);
}
if ((status = do_samba_command("rpcclient", samba_server, subcmd,
authfile, logfile)) != 0)
{
snprintf(message, sizeof(message),
_cupsLangString(language,
_("Unable to install Windows 2000 printer "
"driver files (%d)!")), status);
_cupsSetError(IPP_INTERNAL_ERROR, message);
if (logfile)
_cupsLangPrintf(logfile, "%s\n", message);
unlink(authfile);
return (0);
}
}
snprintf(file, sizeof(file), "%s/drivers/ADOBEPS4.DRV", cg->cups_datadir);
if (!access(file, 0))
{
have_drivers |= 2;
/*
* Do the smbclient commands needed for the Adobe Win9x drivers...
*/
snprintf(address, sizeof(address), "//%s/print$", samba_server);
snprintf(subcmd, sizeof(subcmd),
"mkdir WIN40;"
"put %s WIN40/%s.PPD;"
"put %s/drivers/ADFONTS.MFM WIN40/ADFONTS.MFM;"
"put %s/drivers/ADOBEPS4.DRV WIN40/ADOBEPS4.DRV;"
"put %s/drivers/ADOBEPS4.HLP WIN40/ADOBEPS4.HLP;"
"put %s/drivers/ICONLIB.DLL WIN40/ICONLIB.DLL;"
"put %s/drivers/PSMON.DLL WIN40/PSMON.DLL;",
ppd, dest, cg->cups_datadir, cg->cups_datadir,
cg->cups_datadir, cg->cups_datadir, cg->cups_datadir);
if ((status = do_samba_command("smbclient", address, subcmd,
authfile, logfile)) != 0)
{
snprintf(message, sizeof(message),
_cupsLangString(language,
_("Unable to copy Windows 9x printer "
"driver files (%d)!")), status);
_cupsSetError(IPP_INTERNAL_ERROR, message);
if (logfile)
_cupsLangPrintf(logfile, "%s\n", message);
unlink(authfile);
return (0);
}
/*
* Do the rpcclient commands needed for the Adobe Win9x drivers...
*/
snprintf(subcmd, sizeof(subcmd),
"adddriver \"Windows 4.0\" \"%s:ADOBEPS4.DRV:%s.PPD:NULL:"
"ADOBEPS4.HLP:PSMON.DLL:RAW:"
"ADOBEPS4.DRV,%s.PPD,ADOBEPS4.HLP,PSMON.DLL,ADFONTS.MFM,"
"ICONLIB.DLL\"",
dest, dest, dest);
if ((status = do_samba_command("rpcclient", samba_server, subcmd,
authfile, logfile)) != 0)
{
snprintf(message, sizeof(message),
_cupsLangString(language,
_("Unable to install Windows 9x printer "
"driver files (%d)!")), status);
_cupsSetError(IPP_INTERNAL_ERROR, message);
if (logfile)
_cupsLangPrintf(logfile, "%s\n", message);
unlink(authfile);
return (0);
}
}
if (logfile && !(have_drivers & 1))
{
if (!have_drivers)
strlcpy(message,
_cupsLangString(language,
_("No Windows printer drivers are installed!")),
sizeof(message));
else
strlcpy(message,
_cupsLangString(language,
_("Warning, no Windows 2000 printer drivers "
"are installed!")),
sizeof(message));
_cupsSetError(IPP_INTERNAL_ERROR, message);
_cupsLangPrintf(logfile, "%s\n", message);
}
if (have_drivers == 0)
return (0);
/*
* Finally, associate the drivers we just added with the queue...
*/
snprintf(subcmd, sizeof(subcmd), "setdriver %s %s", dest, dest);
if ((status = do_samba_command("rpcclient", samba_server, subcmd,
authfile, logfile)) != 0)
{
snprintf(message, sizeof(message),
_cupsLangString(language,
_("Unable to set Windows printer driver (%d)!\n")),
status);
_cupsSetError(IPP_INTERNAL_ERROR, message);
if (logfile)
_cupsLangPrintf(logfile, "%s\n", message);
unlink(authfile);
return (0);
}
unlink(authfile);
return (1);
}
/*
* '_cupsAdminGetServerSettings()' - Get settings from the server.
*
* The returned settings should be freed with cupsFreeOptions() when
* you are done with them.
*
* @since CUPS 1.2@
*/
int /* O - 1 on success, 0 on failure */
_cupsAdminGetServerSettings(
http_t *http, /* I - Connection to server */
int *num_settings, /* O - Number of settings */
cups_option_t **settings) /* O - Settings */
{
int i; /* Looping var */
cups_file_t *cupsd; /* cupsd.conf file */
char cupsdconf[1024]; /* cupsd.conf filename */
int remote; /* Remote cupsd.conf file? */
http_status_t status; /* Status of getting cupsd.conf */
char line[1024], /* Line from cupsd.conf file */
*value; /* Value on line */
cups_option_t *setting; /* Current setting */
_cups_globals_t *cg = _cupsGlobals(); /* Global data */
/*
* Range check input...
*/
if (!http || !num_settings || !settings)
{
_cupsSetError(IPP_INTERNAL_ERROR, NULL);
if (num_settings)
*num_settings = 0;
if (settings)
*settings = NULL;
return (0);
}
*num_settings = 0;
*settings = NULL;
/*
* Get the cupsd.conf file...
*/
if ((status = get_cupsd_conf(http, cg, cg->cupsd_update, cupsdconf,
sizeof(cupsdconf), &remote)) == HTTP_OK)
{
if ((cupsd = cupsFileOpen(cupsdconf, "r")) == NULL)
{
char message[1024]; /* Message string */
snprintf(message, sizeof(message),
_cupsLangString(cupsLangDefault(), _("open of %s failed: %s")),
cupsdconf, strerror(errno));
_cupsSetError(IPP_INTERNAL_ERROR, message);
}
}
else
cupsd = NULL;
if (cupsd)
{
/*
* Read the file, keeping track of what settings are enabled...
*/
int remote_access = 0, /* Remote access allowed? */
remote_admin = 0, /* Remote administration allowed? */
browsing = 1, /* Browsing enabled? */
browse_allow = 1, /* Browse address set? */
browse_address = 0, /* Browse address set? */
cancel_policy = 1, /* Cancel-job policy set? */
debug_logging = 0; /* LogLevel debug set? */
int linenum = 0, /* Line number in file */
in_location = 0, /* In a location section? */
in_policy = 0, /* In a policy section? */
in_cancel_job = 0, /* In a cancel-job section? */
in_admin_location = 0; /* In the /admin location? */
invalidate_cupsd_cache(cg);
cg->cupsd_update = time(NULL);
httpGetHostname(http, cg->cupsd_hostname, sizeof(cg->cupsd_hostname));
while (cupsFileGetConf(cupsd, line, sizeof(line), &value, &linenum))
{
if (!value)
continue;
if (!strcasecmp(line, "Port") || !strcasecmp(line, "Listen"))
{
char *port; /* Pointer to port number, if any */
if ((port = strrchr(value, ':')) != NULL)
*port = '\0';
else if (isdigit(*value & 255))
{
/*
* Listen on a port number implies remote access...
*/
remote_access = 1;
continue;
}
if (strcasecmp(value, "localhost") && strcmp(value, "127.0.0.1")
#ifdef AF_LOCAL
&& *value != '/'
#endif /* AF_LOCAL */
#ifdef AF_INET6
&& strcmp(value, "::1")
#endif /* AF_INET6 */
)
remote_access = 1;
}
else if (!strcasecmp(line, "Browsing"))
{
browsing = !strcasecmp(value, "yes") || !strcasecmp(value, "on") ||
!strcasecmp(value, "true");
}
else if (!strcasecmp(line, "BrowseAddress"))
{
browse_address = 1;
}
else if (!strcasecmp(line, "BrowseAllow"))
{
browse_allow = 1;
}
else if (!strcasecmp(line, "BrowseOrder"))
{
browse_allow = !strncasecmp(value, "deny,", 5);
}
else if (!strcasecmp(line, "LogLevel"))
{
debug_logging = !strncasecmp(value, "debug", 5);
}
else if (!strcasecmp(line, "<Policy") && !strcasecmp(value, "default"))
{
in_policy = 1;
}
else if (!strcasecmp(line, "</Policy>"))
{
in_policy = 0;
}
else if (!strcasecmp(line, "<Limit") && in_policy)
{
/*
* See if the policy limit is for the Cancel-Job operation...
*/
char *valptr; /* Pointer into value */
while (*value)
{
for (valptr = value; !isspace(*valptr & 255) && *valptr; valptr ++);
if (*valptr)
*valptr++ = '\0';
if (!strcasecmp(value, "cancel-job") || !strcasecmp(value, "all"))
{
in_cancel_job = 1;
break;
}
for (value = valptr; isspace(*value & 255); value ++);
}
}
else if (!strcasecmp(line, "</Limit>"))
{
in_cancel_job = 0;
}
else if (!strcasecmp(line, "Require") && in_cancel_job)
{
cancel_policy = 0;
}
else if (!strcasecmp(line, "<Location"))
{
in_admin_location = !strcasecmp(value, "/admin");
in_location = 1;
}
else if (!strcasecmp(line, "</Location>"))
{
in_admin_location = 0;
in_location = 0;
}
else if (!strcasecmp(line, "Allow") && in_admin_location &&
strcasecmp(value, "localhost") && strcasecmp(value, "127.0.0.1")
#ifdef AF_LOCAL
&& *value != '/'
#endif /* AF_LOCAL */
#ifdef AF_INET6
&& strcmp(value, "::1")
#endif /* AF_INET6 */
)
{
remote_admin = 1;
}
else if (line[0] != '<' && !in_location && !in_policy)
cg->cupsd_num_settings = cupsAddOption(line, value,
cg->cupsd_num_settings,
&(cg->cupsd_settings));
}
cupsFileClose(cupsd);
cg->cupsd_num_settings = cupsAddOption(CUPS_SERVER_DEBUG_LOGGING,
debug_logging ? "1" : "0",
cg->cupsd_num_settings,
&(cg->cupsd_settings));
cg->cupsd_num_settings = cupsAddOption(CUPS_SERVER_REMOTE_ADMIN,
(remote_access && remote_admin) ?
"1" : "0",
cg->cupsd_num_settings,
&(cg->cupsd_settings));
cg->cupsd_num_settings = cupsAddOption(CUPS_SERVER_REMOTE_PRINTERS,
(browsing && browse_allow) ?
"1" : "0",
cg->cupsd_num_settings,
&(cg->cupsd_settings));
cg->cupsd_num_settings = cupsAddOption(CUPS_SERVER_SHARE_PRINTERS,
(remote_access && browsing &&
browse_address) ? "1" : "0",
cg->cupsd_num_settings,
&(cg->cupsd_settings));
cg->cupsd_num_settings = cupsAddOption(CUPS_SERVER_USER_CANCEL_ANY,
cancel_policy ? "1" : "0",
cg->cupsd_num_settings,
&(cg->cupsd_settings));
}
else if (status != HTTP_NOT_MODIFIED)
invalidate_cupsd_cache(cg);
/*
* Remove any temporary files and copy the settings array...
*/
if (remote)
unlink(cupsdconf);
for (i = cg->cupsd_num_settings, setting = cg->cupsd_settings;
i > 0;
i --, setting ++)
*num_settings = cupsAddOption(setting->name, setting->value,
*num_settings, settings);
return (cg->cupsd_num_settings > 0);
}
/*
* '_cupsAdminSetServerSettings()' - Set settings on the server.
*
* @since CUPS 1.2@
*/
int /* O - 1 on success, 0 on failure */
_cupsAdminSetServerSettings(
http_t *http, /* I - Connection to server */
int num_settings, /* I - Number of settings */
cups_option_t *settings) /* I - Settings */
{
int i; /* Looping var */
http_status_t status; /* GET/PUT status */
const char *server_port_env; /* SERVER_PORT env var */
int server_port; /* IPP port for server */
cups_file_t *cupsd; /* cupsd.conf file */
char cupsdconf[1024]; /* cupsd.conf filename */
int remote; /* Remote cupsd.conf file? */
char tempfile[1024]; /* Temporary new cupsd.conf */
cups_file_t *temp; /* Temporary file */
char line[1024], /* Line from cupsd.conf file */
*value; /* Value on line */
int linenum, /* Line number in file */
in_location, /* In a location section? */
in_policy, /* In a policy section? */
in_default_policy, /* In the default policy section? */
in_cancel_job, /* In a cancel-job section? */
in_admin_location, /* In the /admin location? */
in_conf_location, /* In the /admin/conf location? */
in_root_location; /* In the / location? */
const char *val; /* Setting value */
int remote_printers, /* Show remote printers */
share_printers, /* Share local printers */
remote_admin, /* Remote administration allowed? */
user_cancel_any, /* Cancel-job policy set? */
debug_logging; /* LogLevel debug set? */
int wrote_port_listen, /* Wrote the port/listen lines? */
wrote_browsing, /* Wrote the browsing lines? */
wrote_policy, /* Wrote the policy? */
wrote_loglevel, /* Wrote the LogLevel line? */
wrote_admin_location, /* Wrote the /admin location? */
wrote_conf_location, /* Wrote the /admin/conf location? */
wrote_root_location; /* Wrote the / location? */
int indent; /* Indentation */
int cupsd_num_settings; /* New number of settings */
cups_option_t *cupsd_settings, /* New settings */
*setting; /* Current setting */
_cups_globals_t *cg = _cupsGlobals(); /* Global data */
/*
* Range check input...
*/
if (!http || !num_settings || !settings)
{
_cupsSetError(IPP_INTERNAL_ERROR, NULL);
return (0);
}
/*
* Get the cupsd.conf file...
*/
if ((status = get_cupsd_conf(http, cg, 0, cupsdconf, sizeof(cupsdconf),
&remote)) == HTTP_OK)
{
if ((cupsd = cupsFileOpen(cupsdconf, "r")) == NULL)
{
_cupsSetError(IPP_INTERNAL_ERROR, strerror(errno));
return (0);
}
}
else
return (0);
/*
* Get basic settings...
*/
if ((val = cupsGetOption(CUPS_SERVER_DEBUG_LOGGING, num_settings,
settings)) != NULL)
debug_logging = atoi(val);
else
debug_logging = 0;
if ((val = cupsGetOption(CUPS_SERVER_REMOTE_ADMIN, num_settings,
settings)) != NULL)
remote_admin = atoi(val);
else
remote_admin = 0;
if ((val = cupsGetOption(CUPS_SERVER_REMOTE_PRINTERS, num_settings,
settings)) != NULL)
remote_printers = atoi(val);
else
remote_printers = 1;
if ((val = cupsGetOption(CUPS_SERVER_SHARE_PRINTERS, num_settings,
settings)) != NULL)
share_printers = atoi(val);
else
share_printers = 0;
if ((val = cupsGetOption(CUPS_SERVER_USER_CANCEL_ANY, num_settings,
settings)) != NULL)
user_cancel_any = atoi(val);
else
user_cancel_any = 0;
/*
* Create a temporary file for the new cupsd.conf file...
*/
if ((temp = cupsTempFile2(tempfile, sizeof(tempfile))) == NULL)
{
cupsFileClose(cupsd);
if (remote)
unlink(cupsdconf);
_cupsSetError(IPP_INTERNAL_ERROR, strerror(errno));
return (0);
}
/*
* Copy the old file to the new, making changes along the way...
*/
cupsd_num_settings = 0;
in_admin_location = 0;
in_cancel_job = 0;
in_conf_location = 0;
in_default_policy = 0;
in_location = 0;
in_policy = 0;
in_root_location = 0;
linenum = 0;
wrote_admin_location = 0;
wrote_browsing = 0;
wrote_conf_location = 0;
wrote_loglevel = 0;
wrote_policy = 0;
wrote_port_listen = 0;
wrote_root_location = 0;
indent = 0;
if ((server_port_env = getenv("SERVER_PORT")) != NULL)
{
if ((server_port = atoi(server_port_env)) <= 0)
server_port = ippPort();
}
else
server_port = ippPort();
if (server_port <= 0)
server_port = IPP_PORT;
while (cupsFileGetConf(cupsd, line, sizeof(line), &value, &linenum))
{
if (!strcasecmp(line, "Port") || !strcasecmp(line, "Listen"))
{
if (!wrote_port_listen)
{
wrote_port_listen = 1;
if (share_printers || remote_admin)
{
cupsFilePuts(temp, "# Allow remote access\n");
cupsFilePrintf(temp, "Port %d\n", server_port);
}
else
{
cupsFilePuts(temp, "# Only listen for connections from the local "
"machine.\n");
cupsFilePrintf(temp, "Listen localhost:%d\n", server_port);
}
#ifdef CUPS_DEFAULT_DOMAINSOCKET
if ((!value || strcmp(CUPS_DEFAULT_DOMAINSOCKET, value)) &&
!access(CUPS_DEFAULT_DOMAINSOCKET, 0))
cupsFilePuts(temp, "Listen " CUPS_DEFAULT_DOMAINSOCKET "\n");
#endif /* CUPS_DEFAULT_DOMAINSOCKET */
}
else if (value && value[0] == '/' &&
strcmp(CUPS_DEFAULT_DOMAINSOCKET, value))
cupsFilePrintf(temp, "Listen %s\n", value);
}
else if (!strcasecmp(line, "Browsing") ||
!strcasecmp(line, "BrowseAddress") ||
!strcasecmp(line, "BrowseAllow") ||
!strcasecmp(line, "BrowseDeny") ||
!strcasecmp(line, "BrowseOrder"))
{
if (!wrote_browsing)
{
wrote_browsing = 1;
if (remote_printers || share_printers)
{
if (remote_printers && share_printers)
cupsFilePuts(temp,
"# Enable printer sharing and shared printers.\n");
else if (remote_printers)
cupsFilePuts(temp,
"# Show shared printers on the local network.\n");
else
cupsFilePuts(temp,
"# Share local printers on the local network.\n");
cupsFilePuts(temp, "Browsing On\n");
cupsFilePuts(temp, "BrowseOrder allow,deny\n");
if (remote_printers)
cupsFilePuts(temp, "BrowseAllow @LOCAL\n");
if (share_printers)
cupsFilePuts(temp, "BrowseAddress @LOCAL\n");
}
else
{
cupsFilePuts(temp,
"# Disable printer sharing and shared printers.\n");
cupsFilePuts(temp, "Browsing Off\n");
}
}
}
else if (!strcasecmp(line, "LogLevel"))
{
wrote_loglevel = 1;
if (debug_logging)
{
cupsFilePuts(temp,
"# Show troubleshooting information in error_log.\n");
cupsFilePuts(temp, "LogLevel debug\n");
}
else
{
cupsFilePuts(temp, "# Show general information in error_log.\n");
cupsFilePuts(temp, "LogLevel info\n");
}
}
else if (!strcasecmp(line, "<Policy"))
{
in_default_policy = !strcasecmp(value, "default");
in_policy = 1;
cupsFilePrintf(temp, "%s %s>\n", line, value);
indent += 2;
}
else if (!strcasecmp(line, "</Policy>"))
{
indent -= 2;
if (!wrote_policy && in_default_policy)
{
wrote_policy = 1;
if (!user_cancel_any)
cupsFilePuts(temp, " # Only the owner or an administrator can "
"cancel a job...\n"
" <Limit Cancel-Job>\n"
" Order deny,allow\n"
" Allow @SYSTEM\n"
" Allow @OWNER\n"
" </Limit>\n");
}
in_policy = 0;
in_default_policy = 0;
cupsFilePuts(temp, "</Policy>\n");
}
else if (!strcasecmp(line, "<Location"))
{
in_location = 1;
indent += 2;
if (!strcmp(value, "/admin"))
in_admin_location = 1;
if (!strcmp(value, "/admin/conf"))
in_conf_location = 1;
else if (!strcmp(value, "/"))
in_root_location = 1;
cupsFilePrintf(temp, "%s %s>\n", line, value);
}
else if (!strcasecmp(line, "</Location>"))
{
in_location = 0;
indent -= 2;
if (in_admin_location)
{
wrote_admin_location = 1;
if (remote_admin)
cupsFilePuts(temp, " # Allow remote administration...\n");
else
cupsFilePuts(temp, " # Restrict access to the admin pages...\n");
cupsFilePuts(temp, " Order allow,deny\n");
if (remote_admin)
cupsFilePuts(temp, " Allow @LOCAL\n");
else
cupsFilePuts(temp, " Allow localhost\n");
}
else if (in_conf_location)
{
wrote_conf_location = 1;
if (remote_admin)
cupsFilePuts(temp, " # Allow remote access to the configuration "
"files...\n");
else
cupsFilePuts(temp, " # Restrict access to the configuration "
"files...\n");
cupsFilePuts(temp, " Order allow,deny\n");
if (remote_admin)
cupsFilePuts(temp, " Allow @LOCAL\n");
else
cupsFilePuts(temp, " Allow localhost\n");
}
else if (in_root_location)
{
wrote_root_location = 1;
if (remote_admin && share_printers)
cupsFilePuts(temp, " # Allow shared printing and remote "
"administration...\n");
else if (remote_admin)
cupsFilePuts(temp, " # Allow remote administration...\n");
else if (share_printers)
cupsFilePuts(temp, " # Allow shared printing...\n");
else
cupsFilePuts(temp, " # Restrict access to the server...\n");
cupsFilePuts(temp, " Order allow,deny\n");
if (remote_admin || share_printers)
cupsFilePuts(temp, " Allow @LOCAL\n");
else
cupsFilePuts(temp, " Allow localhost\n");
}
in_admin_location = 0;
in_conf_location = 0;
in_root_location = 0;
cupsFilePuts(temp, "</Location>\n");
}
else if (!strcasecmp(line, "<Limit") && in_default_policy)
{
/*
* See if the policy limit is for the Cancel-Job operation...
*/
char *valptr; /* Pointer into value */
indent += 2;
if (!strcasecmp(value, "cancel-job"))
{
/*
* Don't write anything for this limit section...
*/
in_cancel_job = 2;
}
else
{
cupsFilePrintf(temp, " %s", line);
while (*value)
{
for (valptr = value; !isspace(*valptr & 255) && *valptr; valptr ++);
if (*valptr)
*valptr++ = '\0';
if (!strcasecmp(value, "cancel-job"))
{
/*
* Write everything except for this definition...
*/
in_cancel_job = 1;
}
else
cupsFilePrintf(temp, " %s", value);
for (value = valptr; isspace(*value & 255); value ++);
}
cupsFilePuts(temp, ">\n");
}
}
else if (!strcasecmp(line, "</Limit>") && in_cancel_job)
{
indent -= 2;
if (in_cancel_job == 1)
cupsFilePuts(temp, " </Limit>\n");
wrote_policy = 1;
if (!user_cancel_any)
cupsFilePuts(temp, " # Only the owner or an administrator can cancel "
"a job...\n"
" <Limit Cancel-Job>\n"
" Order deny,allow\n"
" Require user @OWNER @SYSTEM\n"
" </Limit>\n");
in_cancel_job = 0;
}
else if ((in_admin_location || in_conf_location || in_root_location) &&
(!strcasecmp(line, "Allow") || !strcasecmp(line, "Deny") ||
!strcasecmp(line, "Order")))
continue;
else if (in_cancel_job == 2)
continue;
else if (!strcasecmp(line, "<Limit") && value)
cupsFilePrintf(temp, " %s %s>\n", line, value);
else if (line[0] == '<')
{
if (value)
{
cupsFilePrintf(temp, "%*s%s %s>\n", indent, "", line, value);
indent += 2;
}
else
{
if (line[1] == '/')
indent -= 2;
cupsFilePrintf(temp, "%*s%s\n", indent, "", line);
}
}
else if (!in_policy && !in_location &&
(val = cupsGetOption(line, num_settings, settings)) != NULL &&
!cupsGetOption(line, cupsd_num_settings, cupsd_settings))
{
/*
* Add this directive to the list of directives we have written...
*/
cupsd_num_settings = cupsAddOption(line, value, cupsd_num_settings,
&cupsd_settings);
/*
* Write the new value in its place, without indentation since we
* only support setting root directives, not in sections...
*/
cupsFilePrintf(temp, "%s %s\n", line, value);
}
else if (value)
{
if (!in_policy && !in_location)
{
/*
* Record the non-policy, non-location directives that we find
* in the server settings, since we cache this info and record it
* in _cupsAdminGetServerSettings()...
*/
cupsd_num_settings = cupsAddOption(line, value, cupsd_num_settings,
&cupsd_settings);
}
cupsFilePrintf(temp, "%*s%s %s\n", indent, "", line, value);
}
else
cupsFilePrintf(temp, "%*s%s\n", indent, "", line);
}
/*
* Write any missing info...
*/
if (!wrote_browsing)
{
if (remote_printers || share_printers)
{
if (remote_printers && share_printers)
cupsFilePuts(temp, "# Enable printer sharing and shared printers.\n");
else if (remote_printers)
cupsFilePuts(temp, "# Show shared printers on the local network.\n");
else
cupsFilePuts(temp, "# Share local printers on the local network.\n");
cupsFilePuts(temp, "Browsing On\n");
cupsFilePuts(temp, "BrowseOrder allow,deny\n");
if (remote_printers)
cupsFilePuts(temp, "BrowseAllow @LOCAL\n");
if (share_printers)
cupsFilePuts(temp, "BrowseAddress @LOCAL\n");
}
else
{
cupsFilePuts(temp, "# Disable printer sharing and shared printers.\n");
cupsFilePuts(temp, "Browsing Off\n");
}
}
if (!wrote_loglevel)
{
if (debug_logging)
{
cupsFilePuts(temp, "# Show troubleshooting information in error_log.\n");
cupsFilePuts(temp, "LogLevel debug\n");
}
else
{
cupsFilePuts(temp, "# Show general information in error_log.\n");
cupsFilePuts(temp, "LogLevel info\n");
}
}
if (!wrote_port_listen)
{
if (share_printers || remote_admin)
{
cupsFilePuts(temp, "# Allow remote access\n");
cupsFilePrintf(temp, "Port %d\n", ippPort());
}
else
{
cupsFilePuts(temp,
"# Only listen for connections from the local machine.\n");
cupsFilePrintf(temp, "Listen localhost:%d\n", ippPort());
}
#ifdef CUPS_DEFAULT_DOMAINSOCKET
if (!access(CUPS_DEFAULT_DOMAINSOCKET, 0))
cupsFilePuts(temp, "Listen " CUPS_DEFAULT_DOMAINSOCKET "\n");
#endif /* CUPS_DEFAULT_DOMAINSOCKET */
}
if (!wrote_root_location)
{
if (remote_admin && share_printers)
cupsFilePuts(temp,
"# Allow shared printing and remote administration...\n");
else if (remote_admin)
cupsFilePuts(temp, "# Allow remote administration...\n");
else if (share_printers)
cupsFilePuts(temp, "# Allow shared printing...\n");
else
cupsFilePuts(temp, "# Restrict access to the server...\n");
cupsFilePuts(temp, "<Location />\n"
" Order allow,deny\n");
if (remote_admin || share_printers)
cupsFilePuts(temp, " Allow @LOCAL\n");
else
cupsFilePuts(temp, " Allow localhost\n");
cupsFilePuts(temp, "</Location>\n");
}
if (!wrote_admin_location)
{
if (remote_admin)
cupsFilePuts(temp, "# Allow remote administration...\n");
else
cupsFilePuts(temp, "# Restrict access to the admin pages...\n");
cupsFilePuts(temp, "<Location /admin>\n"
" Order allow,deny\n");
if (remote_admin)
cupsFilePuts(temp, " Allow @LOCAL\n");
else
cupsFilePuts(temp, " Allow localhost\n");
cupsFilePuts(temp, "</Location>\n");
}
if (!wrote_conf_location)
{
if (remote_admin)
cupsFilePuts(temp,
"# Allow remote access to the configuration files...\n");
else
cupsFilePuts(temp, "# Restrict access to the configuration files...\n");
cupsFilePuts(temp, "<Location /admin/conf>\n"
" AuthType Basic\n"
" Require user @SYSTEM\n"
" Order allow,deny\n");
if (remote_admin)
cupsFilePuts(temp, " Allow @LOCAL\n");
else
cupsFilePuts(temp, " Allow localhost\n");
cupsFilePuts(temp, "</Location>\n");
}
if (!wrote_policy)
{
cupsFilePuts(temp, "<Policy default>\n"
" # Job-related operations must be done by the owner "
"or an adminstrator...\n"
" <Limit Send-Document Send-URI Hold-Job Release-Job "
"Restart-Job Purge-Jobs Set-Job-Attributes "
"Create-Job-Subscription Renew-Subscription "
"Cancel-Subscription Get-Notifications Reprocess-Job "
"Cancel-Current-Job Suspend-Current-Job Resume-Job "
"CUPS-Move-Job>\n"
" Require user @OWNER @SYSTEM\n"
" Order deny,allow\n"
" </Limit>\n"
" # All administration operations require an "
"adminstrator to authenticate...\n"
" <Limit Pause-Printer Resume-Printer "
"Set-Printer-Attributes Enable-Printer "
"Disable-Printer Pause-Printer-After-Current-Job "
"Hold-New-Jobs Release-Held-New-Jobs Deactivate-Printer "
"Activate-Printer Restart-Printer Shutdown-Printer "
"Startup-Printer Promote-Job Schedule-Job-After "
"CUPS-Add-Printer CUPS-Delete-Printer "
"CUPS-Add-Class CUPS-Delete-Class "
"CUPS-Accept-Jobs CUPS-Reject-Jobs "
"CUPS-Set-Default CUPS-Add-Device CUPS-Delete-Device>\n"
" AuthType Basic\n"
" Require user @SYSTEM\n"
" Order deny,allow\n"
"</Limit>\n");
if (!user_cancel_any)
cupsFilePuts(temp, " # Only the owner or an administrator can cancel "
"a job...\n"
" <Limit Cancel-Job>\n"
" Require user @OWNER @SYSTEM\n"
" Order deny,allow\n"
" </Limit>\n");
cupsFilePuts(temp, " <Limit All>\n"
" Order deny,allow\n"
" </Limit>\n"
"</Policy>\n");
}
for (i = num_settings, setting = settings; i > 0; i --, setting ++)
if (setting->name[0] != '_' &&
!cupsGetOption(setting->name, cupsd_num_settings, cupsd_settings))
{
/*
* Add this directive to the list of directives we have written...
*/
cupsd_num_settings = cupsAddOption(setting->name, setting->value,
cupsd_num_settings, &cupsd_settings);
/*
* Write the new value in its place, without indentation since we
* only support setting root directives, not in sections...
*/
cupsFilePrintf(temp, "%s %s\n", setting->name, setting->value);
}
cupsFileClose(cupsd);
cupsFileClose(temp);
/*
* Upload the configuration file to the server...
*/
status = cupsPutFile(http, "/admin/conf/cupsd.conf", tempfile);
if (status == HTTP_CREATED)
{
/*
* Updated OK, add the basic settings...
*/
cupsd_num_settings = cupsAddOption(CUPS_SERVER_DEBUG_LOGGING,
debug_logging ? "1" : "0",
cupsd_num_settings, &cupsd_settings);
cupsd_num_settings = cupsAddOption(CUPS_SERVER_REMOTE_ADMIN,
remote_admin ? "1" : "0",
cupsd_num_settings, &cupsd_settings);
cupsd_num_settings = cupsAddOption(CUPS_SERVER_REMOTE_PRINTERS,
remote_printers ? "1" : "0",
cupsd_num_settings, &cupsd_settings);
cupsd_num_settings = cupsAddOption(CUPS_SERVER_SHARE_PRINTERS,
share_printers ? "1" : "0",
cupsd_num_settings, &cupsd_settings);
cupsd_num_settings = cupsAddOption(CUPS_SERVER_USER_CANCEL_ANY,
user_cancel_any ? "1" : "0",
cupsd_num_settings, &cupsd_settings);
/*
* Save the new values...
*/
invalidate_cupsd_cache(cg);
cg->cupsd_num_settings = cupsd_num_settings;
cg->cupsd_settings = cupsd_settings;
cg->cupsd_update = time(NULL);
httpGetHostname(http, cg->cupsd_hostname, sizeof(cg->cupsd_hostname));
}
else
cupsFreeOptions(cupsd_num_settings, cupsd_settings);
/*
* Remote our temp files and return...
*/
if (remote)
unlink(cupsdconf);
unlink(tempfile);
return (status == HTTP_CREATED);
}
/*
* 'do_samba_command()' - Do a SAMBA command.
*/
static int /* O - Status of command */
do_samba_command(const char *command, /* I - Command to run */
const char *address, /* I - Address for command */
const char *subcmd, /* I - Sub-command */
const char *authfile, /* I - Samba authentication file */
FILE *logfile) /* I - Optional log file */
{
int status; /* Status of command */
int pid; /* Process ID of child */
if (logfile)
_cupsLangPrintf(logfile,
_("Running command: %s %s -N -A %s -c \'%s\'\n"),
command, address, authfile, subcmd);
if ((pid = fork()) == 0)
{
/*
* Child goes here, redirect stdin/out/err and execute the command...
*/
close(0);
open("/dev/null", O_RDONLY);
close(1);
if (logfile)
dup(fileno(logfile));
else
open("/dev/null", O_WRONLY);
close(2);
dup(1);
execlp(command, command, address, "-N", "-A", authfile, "-c", subcmd,
(char *)0);
exit(errno);
}
else if (pid < 0)
{
status = -1;
if (logfile)
_cupsLangPrintf(logfile, _("Unable to run \"%s\": %s\n"),
command, strerror(errno));
}
else
{
/*
* Wait for the process to complete...
*/
while (wait(&status) != pid);
}
if (logfile)
_cupsLangPuts(logfile, "\n");
DEBUG_printf(("status=%d\n", status));
if (WIFEXITED(status))
return (WEXITSTATUS(status));
else
return (-WTERMSIG(status));
}
/*
* 'get_cupsd_conf()' - Get the current cupsd.conf file.
*/
static http_status_t /* O - Status of request */
get_cupsd_conf(
http_t *http, /* I - Connection to server */
_cups_globals_t *cg, /* I - Global data */
time_t last_update, /* I - Last update time for file */
char *name, /* I - Filename buffer */
int namesize, /* I - Size of filename buffer */
int *remote) /* O - Remote file? */
{
int fd; /* Temporary file descriptor */
struct stat info; /* cupsd.conf file information */
http_status_t status; /* Status of getting cupsd.conf */
char host[HTTP_MAX_HOST]; /* Hostname for connection */
/*
* See if we already have the data we need...
*/
httpGetHostname(http, host, sizeof(host));
if (strcasecmp(cg->cupsd_hostname, host))
invalidate_cupsd_cache(cg);
snprintf(name, namesize, "%s/cupsd.conf", cg->cups_serverroot);
*remote = 0;
if (!strcasecmp(host, "localhost") && !access(name, R_OK))
{
/*
* Read the local file rather than using HTTP...
*/
if (stat(name, &info))
{
char message[1024]; /* Message string */
snprintf(message, sizeof(message),
_cupsLangString(cupsLangDefault(), _("stat of %s failed: %s")),
name, strerror(errno));
_cupsSetError(IPP_INTERNAL_ERROR, message);
*name = '\0';
return (HTTP_SERVER_ERROR);
}
else if (last_update && info.st_mtime <= last_update)
status = HTTP_NOT_MODIFIED;
else
status = HTTP_OK;
}
else
{
/*
* Read cupsd.conf via a HTTP GET request...
*/
if ((fd = cupsTempFd(name, namesize)) < 0)
{
*name = '\0';
_cupsSetError(IPP_INTERNAL_ERROR, strerror(errno));
invalidate_cupsd_cache(cg);
return (HTTP_SERVER_ERROR);
}
*remote = 1;
httpClearFields(http);
if (last_update)
httpSetField(http, HTTP_FIELD_IF_MODIFIED_SINCE,
httpGetDateString(last_update));
status = cupsGetFd(http, "/admin/conf/cupsd.conf", fd);
close(fd);
if (status != HTTP_OK)
{
unlink(name);
*name = '\0';
}
}
return (status);
}
/*
* 'invalidate_cupsd_cache()' - Invalidate the cached cupsd.conf settings.
*/
static void
invalidate_cupsd_cache(
_cups_globals_t *cg) /* I - Global data */
{
cupsFreeOptions(cg->cupsd_num_settings, cg->cupsd_settings);
cg->cupsd_hostname[0] = '\0';
cg->cupsd_update = 0;
cg->cupsd_num_settings = 0;
cg->cupsd_settings = NULL;
}
/*
* 'write_option()' - Write a CUPS option to a PPD file.
*/
static void
write_option(cups_file_t *dstfp, /* I - PPD file */
int order, /* I - Order dependency */
const char *name, /* I - Option name */
const char *text, /* I - Option text */
const char *attrname, /* I - Attribute name */
ipp_attribute_t *suppattr, /* I - IPP -supported attribute */
ipp_attribute_t *defattr, /* I - IPP -default attribute */
int defval, /* I - Default value number */
int valcount) /* I - Number of values */
{
int i; /* Looping var */
cupsFilePrintf(dstfp, "*JCLOpenUI *%s/%s: PickOne\n"
"*OrderDependency: %d JCLSetup *%s\n",
name, text, order, name);
if (defattr->value_tag == IPP_TAG_INTEGER)
{
/*
* Do numeric options with a range or list...
*/
cupsFilePrintf(dstfp, "*Default%s: %d\n", name,
defattr->values[defval].integer);
if (suppattr->value_tag == IPP_TAG_RANGE)
{
/*
* List each number in the range...
*/
for (i = suppattr->values[0].range.lower;
i <= suppattr->values[0].range.upper;
i ++)
{
cupsFilePrintf(dstfp, "*%s %d: \"", name, i);
if (valcount == 1)
cupsFilePrintf(dstfp, "%%cupsJobTicket: %s=%d\n\"\n*End\n",
attrname, i);
else if (defval == 0)
cupsFilePrintf(dstfp, "%%cupsJobTicket: %s=%d\"\n", attrname, i);
else if (defval < (valcount - 1))
cupsFilePrintf(dstfp, ",%d\"\n", i);
else
cupsFilePrintf(dstfp, ",%d\n\"\n*End\n", i);
}
}
else
{
/*
* List explicit numbers...
*/
for (i = 0; i < suppattr->num_values; i ++)
{
cupsFilePrintf(dstfp, "*%s %d: \"", name, suppattr->values[i].integer);
if (valcount == 1)
cupsFilePrintf(dstfp, "%%cupsJobTicket: %s=%d\n\"\n*End\n", attrname,
suppattr->values[i].integer);
else if (defval == 0)
cupsFilePrintf(dstfp, "%%cupsJobTicket: %s=%d\"\n", attrname,
suppattr->values[i].integer);
else if (defval < (valcount - 1))
cupsFilePrintf(dstfp, ",%d\"\n", suppattr->values[i].integer);
else
cupsFilePrintf(dstfp, ",%d\n\"\n*End\n", suppattr->values[i].integer);
}
}
}
else
{
/*
* Do text options with a list...
*/
cupsFilePrintf(dstfp, "*Default%s: %s\n", name,
defattr->values[defval].string.text);
for (i = 0; i < suppattr->num_values; i ++)
{
cupsFilePrintf(dstfp, "*%s %s: \"", name,
suppattr->values[i].string.text);
if (valcount == 1)
cupsFilePrintf(dstfp, "%%cupsJobTicket: %s=%s\n\"\n*End\n", attrname,
suppattr->values[i].string.text);
else if (defval == 0)
cupsFilePrintf(dstfp, "%%cupsJobTicket: %s=%s\"\n", attrname,
suppattr->values[i].string.text);
else if (defval < (valcount - 1))
cupsFilePrintf(dstfp, ",%s\"\n", suppattr->values[i].string.text);
else
cupsFilePrintf(dstfp, ",%s\n\"\n*End\n",
suppattr->values[i].string.text);
}
}
cupsFilePrintf(dstfp, "*JCLCloseUI: *%s\n\n", name);
}
/*
* End of "$Id: adminutil.c 5970 2006-09-19 20:11:08Z mike $".
*/
|