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
|
/*
* Unix SMB/Netbios implementation.
* Version 1.9.
* RPC Pipe client / server routines
* Copyright (C) Andrew Tridgell 1992-1997,
* Copyright (C) Luke Kenneth Casson Leighton 1996-1997,
* Copyright (C) Paul Ashton 1997.
* Copyright (C) Jeremy Allison 2001.
*
* 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 2 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, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* This is the implementation of the srvsvc pipe. */
#include "includes.h"
extern pstring global_myname;
/*******************************************************************
Fill in a share info level 1 structure.
********************************************************************/
static void init_srv_share_info_1(pipes_struct *p, SRV_SHARE_INFO_1 *sh1, int snum)
{
int len_net_name;
pstring net_name;
pstring remark;
uint32 type;
StrnCpy(net_name, lp_servicename(snum),
(get_remote_arch() == RA_WIN2K) ? 127 : 12);
pstrcpy(remark, lp_comment(snum));
standard_sub_conn(p->conn, remark, sizeof(remark));
len_net_name = strlen(net_name);
/* work out the share type */
type = STYPE_DISKTREE;
if (lp_print_ok(snum))
type = STYPE_PRINTQ;
if (strequal("IPC$", net_name) || strequal("ADMIN$", net_name))
type = STYPE_IPC;
if (net_name[len_net_name] == '$')
type |= STYPE_HIDDEN;
init_srv_share_info1(&sh1->info_1, net_name, type, remark);
init_srv_share_info1_str(&sh1->info_1_str, net_name, remark);
}
/*******************************************************************
Fill in a share info level 2 structure.
********************************************************************/
static void init_srv_share_info_2(pipes_struct *p, SRV_SHARE_INFO_2 *sh2, int snum)
{
int len_net_name;
pstring net_name;
pstring remark;
pstring path;
pstring passwd;
uint32 type;
pstrcpy(net_name, lp_servicename(snum));
pstrcpy(remark, lp_comment(snum));
standard_sub_conn(p->conn, remark, sizeof(remark));
pstrcpy(path, "C:");
pstrcat(path, lp_pathname(snum));
/*
* Change / to \\ so that win2k will see it as a valid path. This was added to
* enable use of browsing in win2k add share dialog.
*/
string_replace(path, '/', '\\');
pstrcpy(passwd, "");
len_net_name = strlen(net_name);
/* work out the share type */
type = STYPE_DISKTREE;
if (lp_print_ok(snum))
type = STYPE_PRINTQ;
if (strequal("IPC$", net_name) || strequal("ADMIN$", net_name))
type = STYPE_IPC;
if (net_name[len_net_name] == '$')
type |= STYPE_HIDDEN;
init_srv_share_info2(&sh2->info_2, net_name, type, remark, 0, 0xffffffff, 1, path, passwd);
init_srv_share_info2_str(&sh2->info_2_str, net_name, remark, path, passwd);
}
/*******************************************************************
What to do when smb.conf is updated.
********************************************************************/
static void smb_conf_updated(int msg_type, pid_t src, void *buf, size_t len)
{
DEBUG(10,("smb_conf_updated: Got message saying smb.conf was updated. Reloading.\n"));
reload_services(False);
}
/*******************************************************************
Create the share security tdb.
********************************************************************/
static TDB_CONTEXT *share_tdb; /* used for share security descriptors */
#define SHARE_DATABASE_VERSION_V1 1
#define SHARE_DATABASE_VERSION_V2 2 /* version id in little endian. */
BOOL share_info_db_init(void)
{
static pid_t local_pid;
const char *vstring = "INFO/version";
int32 vers_id;
if (share_tdb && local_pid == sys_getpid())
return True;
share_tdb = tdb_open_log(lock_path("share_info.tdb"), 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0600);
if (!share_tdb) {
DEBUG(0,("Failed to open share info database %s (%s)\n",
lock_path("share_info.tdb"), strerror(errno) ));
return False;
}
local_pid = sys_getpid();
/* handle a Samba upgrade */
tdb_lock_bystring(share_tdb, vstring,0);
/* Cope with byte-reversed older versions of the db. */
vers_id = tdb_fetch_int32(share_tdb, vstring);
if ((vers_id == SHARE_DATABASE_VERSION_V1) || (IREV(vers_id) == SHARE_DATABASE_VERSION_V1)) {
/* Written on a bigendian machine with old fetch_int code. Save as le. */
tdb_store_int32(share_tdb, vstring, SHARE_DATABASE_VERSION_V2);
vers_id = SHARE_DATABASE_VERSION_V2;
}
if (vers_id != SHARE_DATABASE_VERSION_V2) {
tdb_traverse(share_tdb, tdb_traverse_delete_fn, NULL);
tdb_store_int32(share_tdb, vstring, SHARE_DATABASE_VERSION_V2);
}
tdb_unlock_bystring(share_tdb, vstring);
message_register(MSG_SMB_CONF_UPDATED, smb_conf_updated);
return True;
}
/*******************************************************************
Fake up a Everyone, full access as a default.
********************************************************************/
static SEC_DESC *get_share_security_default( TALLOC_CTX *ctx, int snum, size_t *psize)
{
extern DOM_SID global_sid_World;
extern struct generic_mapping file_generic_mapping;
SEC_ACCESS sa;
SEC_ACE ace;
SEC_ACL *psa = NULL;
SEC_DESC *psd = NULL;
uint32 def_access = GENERIC_ALL_ACCESS;
se_map_generic(&def_access, &file_generic_mapping);
init_sec_access(&sa, GENERIC_ALL_ACCESS | def_access );
init_sec_ace(&ace, &global_sid_World, SEC_ACE_TYPE_ACCESS_ALLOWED, sa, 0);
if ((psa = make_sec_acl(ctx, NT4_ACL_REVISION, 1, &ace)) != NULL) {
psd = make_sec_desc(ctx, SEC_DESC_REVISION, NULL, NULL, NULL, psa, psize);
}
if (!psd) {
DEBUG(0,("get_share_security: Failed to make SEC_DESC.\n"));
return NULL;
}
return psd;
}
/*******************************************************************
Pull a security descriptor from the share tdb.
********************************************************************/
static SEC_DESC *get_share_security( TALLOC_CTX *ctx, int snum, size_t *psize)
{
prs_struct ps;
fstring key;
SEC_DESC *psd = NULL;
*psize = 0;
/* Fetch security descriptor from tdb */
slprintf(key, sizeof(key)-1, "SECDESC/%s", lp_servicename(snum));
if (tdb_prs_fetch(share_tdb, key, &ps, ctx)!=0 ||
!sec_io_desc("get_share_security", &psd, &ps, 1)) {
DEBUG(4,("get_share_security: using default secdesc for %s\n", lp_servicename(snum) ));
return get_share_security_default(ctx, snum, psize);
}
if (psd)
*psize = sec_desc_size(psd);
prs_mem_free(&ps);
return psd;
}
/*******************************************************************
Store a security descriptor in the share db.
********************************************************************/
static BOOL set_share_security(TALLOC_CTX *ctx, const char *share_name, SEC_DESC *psd)
{
prs_struct ps;
TALLOC_CTX *mem_ctx = NULL;
fstring key;
BOOL ret = False;
mem_ctx = talloc_init();
if (mem_ctx == NULL)
return False;
prs_init(&ps, (uint32)sec_desc_size(psd), mem_ctx, MARSHALL);
if (!sec_io_desc("share_security", &psd, &ps, 1))
goto out;
slprintf(key, sizeof(key)-1, "SECDESC/%s", share_name);
if (tdb_prs_store(share_tdb, key, &ps)==0) {
ret = True;
DEBUG(5,("set_share_security: stored secdesc for %s\n", share_name ));
} else {
DEBUG(1,("set_share_security: Failed to store secdesc for %s\n", share_name ));
}
/* Free malloc'ed memory */
out:
prs_mem_free(&ps);
if (mem_ctx)
talloc_destroy(mem_ctx);
return ret;
}
/*******************************************************************
Delete a security descriptor.
********************************************************************/
static BOOL delete_share_security(int snum)
{
TDB_KEY kbuf;
fstring key;
slprintf(key, sizeof(key)-1, "SECDESC/%s", lp_servicename(snum));
kbuf.dptr = key;
kbuf.dsize = strlen(key)+1;
if (tdb_delete(share_tdb, kbuf) != 0) {
DEBUG(0,("delete_share_security: Failed to delete entry for share %s\n",
lp_servicename(snum) ));
return False;
}
return True;
}
/*******************************************************************
Map any generic bits to file specific bits.
********************************************************************/
void map_generic_share_sd_bits(SEC_DESC *psd)
{
extern struct generic_mapping file_generic_mapping;
int i;
SEC_ACL *ps_dacl = NULL;
if (!psd)
return;
ps_dacl = psd->dacl;
if (!ps_dacl)
return;
for (i = 0; i < ps_dacl->num_aces; i++) {
SEC_ACE *psa = &ps_dacl->ace[i];
uint32 orig_mask = psa->info.mask;
se_map_generic(&psa->info.mask, &file_generic_mapping);
psa->info.mask |= orig_mask;
}
}
/*******************************************************************
Can this user access with share with the required permissions ?
********************************************************************/
BOOL share_access_check(connection_struct *conn, int snum, uint16 vuid, uint32 desired_access)
{
uint32 granted;
NTSTATUS status;
TALLOC_CTX *mem_ctx = NULL;
SEC_DESC *psd = NULL;
size_t sd_size;
NT_USER_TOKEN *token = NULL;
user_struct *vuser = get_valid_user_struct(vuid);
BOOL ret = True;
mem_ctx = talloc_init();
if (mem_ctx == NULL)
return False;
psd = get_share_security(mem_ctx, snum, &sd_size);
if (!psd)
goto out;
if (vuser)
token = vuser->nt_user_token;
else
token = conn->nt_user_token;
ret = se_access_check(psd, token, desired_access, &granted, &status);
out:
talloc_destroy(mem_ctx);
return ret;
}
/*******************************************************************
Fill in a share info level 501 structure.
********************************************************************/
static void init_srv_share_info_501(pipes_struct *p, SRV_SHARE_INFO_501 *sh501, int snum)
{
int len_net_name;
pstring net_name;
pstring remark;
uint32 type;
pstrcpy(net_name, lp_servicename(snum));
pstrcpy(remark, lp_comment(snum));
standard_sub_conn(p->conn, remark,sizeof(remark));
len_net_name = strlen(net_name);
/* work out the share type */
type = STYPE_DISKTREE;
if (lp_print_ok(snum))
type = STYPE_PRINTQ;
if (strequal("IPC$", net_name) || strequal("ADMIN$", net_name))
type = STYPE_IPC;
if (net_name[len_net_name] == '$')
type |= STYPE_HIDDEN;
init_srv_share_info501(&sh501->info_501, net_name, type, remark, (lp_csc_policy(snum) << 4));
init_srv_share_info501_str(&sh501->info_501_str, net_name, remark);
}
/*******************************************************************
Fill in a share info level 502 structure.
********************************************************************/
static void init_srv_share_info_502(pipes_struct *p, SRV_SHARE_INFO_502 *sh502, int snum)
{
int len_net_name;
pstring net_name;
pstring remark;
pstring path;
pstring passwd;
uint32 type;
SEC_DESC *sd;
size_t sd_size;
TALLOC_CTX *ctx = p->mem_ctx;
ZERO_STRUCTP(sh502);
pstrcpy(net_name, lp_servicename(snum));
pstrcpy(remark, lp_comment(snum));
standard_sub_conn(p->conn, remark,sizeof(remark));
pstrcpy(path, "C:");
pstrcat(path, lp_pathname(snum));
/*
* Change / to \\ so that win2k will see it as a valid path. This was added to
* enable use of browsing in win2k add share dialog.
*/
string_replace(path, '/', '\\');
pstrcpy(passwd, "");
len_net_name = strlen(net_name);
/* work out the share type */
type = STYPE_DISKTREE;
if (lp_print_ok(snum))
type = STYPE_PRINTQ;
if (strequal("IPC$", net_name))
type = STYPE_IPC;
if (net_name[len_net_name] == '$')
type |= STYPE_HIDDEN;
sd = get_share_security(ctx, snum, &sd_size);
init_srv_share_info502(&sh502->info_502, net_name, type, remark, 0, 0xffffffff, 1, path, passwd, sd, sd_size);
init_srv_share_info502_str(&sh502->info_502_str, &sh502->info_502, net_name, remark, path, passwd, sd, sd_size);
}
/***************************************************************************
Fill in a share info level 1005 structure.
***************************************************************************/
static void init_srv_share_info_1005(SRV_SHARE_INFO_1005* sh1005, int snum)
{
sh1005->misc_flags = 0;
#ifdef WITH_MSDFS
if(lp_host_msdfs() && lp_msdfs_root(snum))
sh1005->misc_flags = 3;
#endif
sh1005->misc_flags |= (lp_csc_policy(snum) << 4);
}
/*******************************************************************
True if it ends in '$'.
********************************************************************/
static BOOL is_admin_share(int snum)
{
pstring net_name;
pstrcpy(net_name, lp_servicename(snum));
return (net_name[strlen(net_name)] == '$') ? True : False;
}
/*******************************************************************
Fill in a share info structure.
********************************************************************/
static BOOL init_srv_share_info_ctr(pipes_struct *p, SRV_SHARE_INFO_CTR *ctr,
uint32 info_level, uint32 *resume_hnd, uint32 *total_entries, BOOL all_shares)
{
int num_entries = 0;
int num_services = lp_numservices();
int snum;
TALLOC_CTX *ctx = p->mem_ctx;
DEBUG(5,("init_srv_share_info_ctr\n"));
ZERO_STRUCTPN(ctr);
ctr->info_level = ctr->switch_value = info_level;
*resume_hnd = 0;
/* Count the number of entries. */
for (snum = 0; snum < num_services; snum++) {
if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_admin_share(snum)) )
num_entries++;
}
*total_entries = num_entries;
ctr->num_entries2 = ctr->num_entries = num_entries;
ctr->ptr_share_info = ctr->ptr_entries = 1;
if (!num_entries)
return True;
switch (info_level) {
case 1:
{
SRV_SHARE_INFO_1 *info1;
int i = 0;
info1 = talloc(ctx, num_entries * sizeof(SRV_SHARE_INFO_1));
for (snum = *resume_hnd; snum < num_services; snum++) {
if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_admin_share(snum)) ) {
init_srv_share_info_1(p, &info1[i++], snum);
}
}
ctr->share.info1 = info1;
break;
}
case 2:
{
SRV_SHARE_INFO_2 *info2;
int i = 0;
info2 = talloc(ctx, num_entries * sizeof(SRV_SHARE_INFO_2));
for (snum = *resume_hnd; snum < num_services; snum++) {
if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_admin_share(snum)) ) {
init_srv_share_info_2(p, &info2[i++], snum);
}
}
ctr->share.info2 = info2;
break;
}
case 501:
{
SRV_SHARE_INFO_501 *info501;
int i = 0;
info501 = talloc(ctx, num_entries * sizeof(SRV_SHARE_INFO_501));
for (snum = *resume_hnd; snum < num_services; snum++) {
if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_admin_share(snum)) ) {
init_srv_share_info_501(p, &info501[i++], snum);
}
}
ctr->share.info501 = info501;
break;
}
case 502:
{
SRV_SHARE_INFO_502 *info502;
int i = 0;
info502 = talloc(ctx, num_entries * sizeof(SRV_SHARE_INFO_502));
for (snum = *resume_hnd; snum < num_services; snum++) {
if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_admin_share(snum)) ) {
init_srv_share_info_502(p, &info502[i++], snum);
}
}
ctr->share.info502 = info502;
break;
}
default:
DEBUG(5,("init_srv_share_info_ctr: unsupported switch value %d\n", info_level));
return False;
}
return True;
}
/*******************************************************************
Inits a SRV_R_NET_SHARE_ENUM structure.
********************************************************************/
static void init_srv_r_net_share_enum(pipes_struct *p, SRV_R_NET_SHARE_ENUM *r_n,
uint32 info_level, uint32 resume_hnd, BOOL all)
{
DEBUG(5,("init_srv_r_net_share_enum: %d\n", __LINE__));
if (init_srv_share_info_ctr(p, &r_n->ctr, info_level,
&resume_hnd, &r_n->total_entries, all)) {
r_n->status = WERR_OK;
} else {
r_n->status = WERR_UNKNOWN_LEVEL;
}
init_enum_hnd(&r_n->enum_hnd, resume_hnd);
}
/*******************************************************************
Inits a SRV_R_NET_SHARE_GET_INFO structure.
********************************************************************/
static void init_srv_r_net_share_get_info(pipes_struct *p, SRV_R_NET_SHARE_GET_INFO *r_n,
char *share_name, uint32 info_level)
{
WERROR status = WERR_OK;
int snum;
DEBUG(5,("init_srv_r_net_share_get_info: %d\n", __LINE__));
r_n->info.switch_value = info_level;
snum = find_service(share_name);
if (snum >= 0) {
switch (info_level) {
case 1:
init_srv_share_info_1(p, &r_n->info.share.info1, snum);
break;
case 2:
init_srv_share_info_2(p, &r_n->info.share.info2, snum);
break;
case 501:
init_srv_share_info_501(p, &r_n->info.share.info501, snum);
break;
case 502:
init_srv_share_info_502(p, &r_n->info.share.info502, snum);
break;
case 1005:
init_srv_share_info_1005(&r_n->info.share.info1005, snum);
break;
default:
DEBUG(5,("init_srv_net_share_get_info: unsupported switch value %d\n", info_level));
status = WERR_UNKNOWN_LEVEL;
break;
}
} else {
status = WERR_INVALID_NAME;
}
r_n->info.ptr_share_ctr = W_ERROR_IS_OK(status) ? 1 : 0;
r_n->status = status;
}
/*******************************************************************
fill in a sess info level 1 structure.
********************************************************************/
static void init_srv_sess_0_info(SESS_INFO_0 *se0, SESS_INFO_0_STR *str0, const char *name)
{
init_srv_sess_info0(se0, name);
init_srv_sess_info0_str(str0, name);
}
/*******************************************************************
fill in a sess info level 0 structure.
********************************************************************/
static void init_srv_sess_info_0(SRV_SESS_INFO_0 *ss0, uint32 *snum, uint32 *stot)
{
uint32 num_entries = 0;
(*stot) = 1;
if (ss0 == NULL) {
(*snum) = 0;
return;
}
DEBUG(5,("init_srv_sess_0_ss0\n"));
if (snum) {
for (; (*snum) < (*stot) && num_entries < MAX_SESS_ENTRIES; (*snum)++) {
init_srv_sess_0_info(&ss0->info_0[num_entries],
&ss0->info_0_str[num_entries], "MACHINE");
/* move on to creating next session */
/* move on to creating next sess */
num_entries++;
}
ss0->num_entries_read = num_entries;
ss0->ptr_sess_info = num_entries > 0 ? 1 : 0;
ss0->num_entries_read2 = num_entries;
if ((*snum) >= (*stot)) {
(*snum) = 0;
}
} else {
ss0->num_entries_read = 0;
ss0->ptr_sess_info = 0;
ss0->num_entries_read2 = 0;
}
}
/*******************************************************************
fill in a sess info level 1 structure.
********************************************************************/
static void init_srv_sess_1_info(SESS_INFO_1 *se1, SESS_INFO_1_STR *str1,
const char *name, const char *user,
uint32 num_opens,
uint32 open_time, uint32 idle_time,
uint32 usr_flgs)
{
init_srv_sess_info1(se1 , name, user, num_opens, open_time, idle_time, usr_flgs);
init_srv_sess_info1_str(str1, name, user);
}
/*******************************************************************
fill in a sess info level 1 structure.
********************************************************************/
static void init_srv_sess_info_1(SRV_SESS_INFO_1 *ss1, uint32 *snum, uint32 *stot)
{
uint32 num_entries = 0;
(*stot) = 1;
if (ss1 == NULL) {
(*snum) = 0;
return;
}
DEBUG(5,("init_srv_sess_1_ss1\n"));
if (snum) {
for (; (*snum) < (*stot) && num_entries < MAX_SESS_ENTRIES; (*snum)++) {
init_srv_sess_1_info(&ss1->info_1[num_entries],
&ss1->info_1_str[num_entries],
"MACHINE", "dummy_user", 1, 10, 5, 0);
/* move on to creating next session */
/* move on to creating next sess */
num_entries++;
}
ss1->num_entries_read = num_entries;
ss1->ptr_sess_info = num_entries > 0 ? 1 : 0;
ss1->num_entries_read2 = num_entries;
if ((*snum) >= (*stot)) {
(*snum) = 0;
}
} else {
ss1->num_entries_read = 0;
ss1->ptr_sess_info = 0;
ss1->num_entries_read2 = 0;
(*stot) = 0;
}
}
/*******************************************************************
makes a SRV_R_NET_SESS_ENUM structure.
********************************************************************/
static WERROR init_srv_sess_info_ctr(SRV_SESS_INFO_CTR *ctr,
int switch_value, uint32 *resume_hnd, uint32 *total_entries)
{
WERROR status = WERR_OK;
DEBUG(5,("init_srv_sess_info_ctr: %d\n", __LINE__));
ctr->switch_value = switch_value;
switch (switch_value) {
case 0:
init_srv_sess_info_0(&(ctr->sess.info0), resume_hnd, total_entries);
ctr->ptr_sess_ctr = 1;
break;
case 1:
init_srv_sess_info_1(&(ctr->sess.info1), resume_hnd, total_entries);
ctr->ptr_sess_ctr = 1;
break;
default:
DEBUG(5,("init_srv_sess_info_ctr: unsupported switch value %d\n", switch_value));
(*resume_hnd) = 0;
(*total_entries) = 0;
ctr->ptr_sess_ctr = 0;
status = WERR_UNKNOWN_LEVEL;
break;
}
return status;
}
/*******************************************************************
makes a SRV_R_NET_SESS_ENUM structure.
********************************************************************/
static void init_srv_r_net_sess_enum(SRV_R_NET_SESS_ENUM *r_n,
uint32 resume_hnd, int sess_level, int switch_value)
{
DEBUG(5,("init_srv_r_net_sess_enum: %d\n", __LINE__));
r_n->sess_level = sess_level;
if (sess_level == -1)
r_n->status = WERR_UNKNOWN_LEVEL;
else
r_n->status = init_srv_sess_info_ctr(r_n->ctr, switch_value, &resume_hnd, &r_n->total_entries);
if (!W_ERROR_IS_OK(r_n->status))
resume_hnd = 0;
init_enum_hnd(&r_n->enum_hnd, resume_hnd);
}
/*******************************************************************
fill in a conn info level 0 structure.
********************************************************************/
static void init_srv_conn_info_0(SRV_CONN_INFO_0 *ss0, uint32 *snum, uint32 *stot)
{
uint32 num_entries = 0;
(*stot) = 1;
if (ss0 == NULL) {
(*snum) = 0;
return;
}
DEBUG(5,("init_srv_conn_0_ss0\n"));
if (snum) {
for (; (*snum) < (*stot) && num_entries < MAX_CONN_ENTRIES; (*snum)++) {
init_srv_conn_info0(&ss0->info_0[num_entries], (*stot));
/* move on to creating next connection */
/* move on to creating next conn */
num_entries++;
}
ss0->num_entries_read = num_entries;
ss0->ptr_conn_info = num_entries > 0 ? 1 : 0;
ss0->num_entries_read2 = num_entries;
if ((*snum) >= (*stot)) {
(*snum) = 0;
}
} else {
ss0->num_entries_read = 0;
ss0->ptr_conn_info = 0;
ss0->num_entries_read2 = 0;
(*stot) = 0;
}
}
/*******************************************************************
fill in a conn info level 1 structure.
********************************************************************/
static void init_srv_conn_1_info(CONN_INFO_1 *se1, CONN_INFO_1_STR *str1,
uint32 id, uint32 type,
uint32 num_opens, uint32 num_users, uint32 open_time,
const char *usr_name, const char *net_name)
{
init_srv_conn_info1(se1 , id, type, num_opens, num_users, open_time, usr_name, net_name);
init_srv_conn_info1_str(str1, usr_name, net_name);
}
/*******************************************************************
fill in a conn info level 1 structure.
********************************************************************/
static void init_srv_conn_info_1(SRV_CONN_INFO_1 *ss1, uint32 *snum, uint32 *stot)
{
uint32 num_entries = 0;
(*stot) = 1;
if (ss1 == NULL) {
(*snum) = 0;
return;
}
DEBUG(5,("init_srv_conn_1_ss1\n"));
if (snum) {
for (; (*snum) < (*stot) && num_entries < MAX_CONN_ENTRIES; (*snum)++) {
init_srv_conn_1_info(&ss1->info_1[num_entries],
&ss1->info_1_str[num_entries],
(*stot), 0x3, 1, 1, 3,"dummy_user", "IPC$");
/* move on to creating next connection */
/* move on to creating next conn */
num_entries++;
}
ss1->num_entries_read = num_entries;
ss1->ptr_conn_info = num_entries > 0 ? 1 : 0;
ss1->num_entries_read2 = num_entries;
if ((*snum) >= (*stot)) {
(*snum) = 0;
}
} else {
ss1->num_entries_read = 0;
ss1->ptr_conn_info = 0;
ss1->num_entries_read2 = 0;
(*stot) = 0;
}
}
/*******************************************************************
makes a SRV_R_NET_CONN_ENUM structure.
********************************************************************/
static WERROR init_srv_conn_info_ctr(SRV_CONN_INFO_CTR *ctr,
int switch_value, uint32 *resume_hnd, uint32 *total_entries)
{
WERROR status = WERR_OK;
DEBUG(5,("init_srv_conn_info_ctr: %d\n", __LINE__));
ctr->switch_value = switch_value;
switch (switch_value) {
case 0:
init_srv_conn_info_0(&ctr->conn.info0, resume_hnd, total_entries);
ctr->ptr_conn_ctr = 1;
break;
case 1:
init_srv_conn_info_1(&ctr->conn.info1, resume_hnd, total_entries);
ctr->ptr_conn_ctr = 1;
break;
default:
DEBUG(5,("init_srv_conn_info_ctr: unsupported switch value %d\n", switch_value));
(*resume_hnd = 0);
(*total_entries) = 0;
ctr->ptr_conn_ctr = 0;
status = WERR_UNKNOWN_LEVEL;
break;
}
return status;
}
/*******************************************************************
makes a SRV_R_NET_CONN_ENUM structure.
********************************************************************/
static void init_srv_r_net_conn_enum(SRV_R_NET_CONN_ENUM *r_n,
uint32 resume_hnd, int conn_level, int switch_value)
{
DEBUG(5,("init_srv_r_net_conn_enum: %d\n", __LINE__));
r_n->conn_level = conn_level;
if (conn_level == -1)
r_n->status = WERR_UNKNOWN_LEVEL;
else
r_n->status = init_srv_conn_info_ctr(r_n->ctr, switch_value, &resume_hnd, &r_n->total_entries);
if (!W_ERROR_IS_OK(r_n->status))
resume_hnd = 0;
init_enum_hnd(&r_n->enum_hnd, resume_hnd);
}
/*******************************************************************
fill in a file info level 3 structure.
********************************************************************/
static void init_srv_file_3_info(FILE_INFO_3 *fl3, FILE_INFO_3_STR *str3,
uint32 fnum, uint32 perms, uint32 num_locks,
const char *path_name, const char *user_name)
{
init_srv_file_info3(fl3 , fnum, perms, num_locks, path_name, user_name);
init_srv_file_info3_str(str3, path_name, user_name);
}
/*******************************************************************
fill in a file info level 3 structure.
********************************************************************/
static void init_srv_file_info_3(SRV_FILE_INFO_3 *fl3, uint32 *fnum, uint32 *ftot)
{
uint32 num_entries = 0;
(*ftot) = 1;
if (fl3 == NULL) {
(*fnum) = 0;
return;
}
DEBUG(5,("init_srv_file_3_fl3\n"));
for (; (*fnum) < (*ftot) && num_entries < MAX_FILE_ENTRIES; (*fnum)++) {
init_srv_file_3_info(&fl3->info_3[num_entries],
&fl3->info_3_str[num_entries],
(*fnum), 0x35, 0, "\\PIPE\\samr", "dummy user");
/* move on to creating next file */
num_entries++;
}
fl3->num_entries_read = num_entries;
fl3->ptr_file_info = num_entries > 0 ? 1 : 0;
fl3->num_entries_read2 = num_entries;
if ((*fnum) >= (*ftot)) {
(*fnum) = 0;
}
}
/*******************************************************************
makes a SRV_R_NET_FILE_ENUM structure.
********************************************************************/
static WERROR init_srv_file_info_ctr(SRV_FILE_INFO_CTR *ctr,
int switch_value, uint32 *resume_hnd, uint32 *total_entries)
{
WERROR status = WERR_OK;
DEBUG(5,("init_srv_file_info_ctr: %d\n", __LINE__));
ctr->switch_value = switch_value;
switch (switch_value) {
case 3:
init_srv_file_info_3(&ctr->file.info3, resume_hnd, total_entries);
ctr->ptr_file_ctr = 1;
break;
default:
DEBUG(5,("init_srv_file_info_ctr: unsupported switch value %d\n", switch_value));
(*resume_hnd = 0);
(*total_entries) = 0;
ctr->ptr_file_ctr = 0;
status = WERR_UNKNOWN_LEVEL;
break;
}
return status;
}
/*******************************************************************
makes a SRV_R_NET_FILE_ENUM structure.
********************************************************************/
static void init_srv_r_net_file_enum(SRV_R_NET_FILE_ENUM *r_n,
uint32 resume_hnd, int file_level, int switch_value)
{
DEBUG(5,("init_srv_r_net_file_enum: %d\n", __LINE__));
r_n->file_level = file_level;
if (file_level == 0)
r_n->status = WERR_UNKNOWN_LEVEL;
else
r_n->status = init_srv_file_info_ctr(r_n->ctr, switch_value, &resume_hnd, &r_n->total_entries);
if (!W_ERROR_IS_OK(r_n->status))
resume_hnd = 0;
init_enum_hnd(&r_n->enum_hnd, resume_hnd);
}
/*******************************************************************
net server get info
********************************************************************/
WERROR _srv_net_srv_get_info(pipes_struct *p, SRV_Q_NET_SRV_GET_INFO *q_u, SRV_R_NET_SRV_GET_INFO *r_u)
{
WERROR status = WERR_OK;
SRV_INFO_CTR *ctr = (SRV_INFO_CTR *)talloc(p->mem_ctx, sizeof(SRV_INFO_CTR));
if (!ctr)
return WERR_NOMEM;
ZERO_STRUCTP(ctr);
DEBUG(5,("srv_net_srv_get_info: %d\n", __LINE__));
switch (q_u->switch_value) {
case 102:
init_srv_info_102(&ctr->srv.sv102,
500, global_myname,
string_truncate(lp_serverstring(), MAX_SERVER_STRING_LENGTH),
lp_major_announce_version(), lp_minor_announce_version(),
lp_default_server_announce(),
0xffffffff, /* users */
0xf, /* disc */
0, /* hidden */
240, /* announce */
3000, /* announce delta */
100000, /* licenses */
"c:\\"); /* user path */
break;
case 101:
init_srv_info_101(&ctr->srv.sv101,
500, global_myname,
lp_major_announce_version(), lp_minor_announce_version(),
lp_default_server_announce(),
string_truncate(lp_serverstring(), MAX_SERVER_STRING_LENGTH));
break;
case 100:
init_srv_info_100(&ctr->srv.sv100, 500, global_myname);
break;
default:
status = WERR_UNKNOWN_LEVEL;
break;
}
/* set up the net server get info structure */
init_srv_r_net_srv_get_info(r_u, q_u->switch_value, ctr, status);
DEBUG(5,("srv_net_srv_get_info: %d\n", __LINE__));
return r_u->status;
}
/*******************************************************************
net server set info
********************************************************************/
WERROR _srv_net_srv_set_info(pipes_struct *p, SRV_Q_NET_SRV_SET_INFO *q_u, SRV_R_NET_SRV_SET_INFO *r_u)
{
WERROR status = WERR_OK;
DEBUG(5,("srv_net_srv_set_info: %d\n", __LINE__));
/* Set up the net server set info structure. */
init_srv_r_net_srv_set_info(r_u, 0x0, status);
DEBUG(5,("srv_net_srv_set_info: %d\n", __LINE__));
return r_u->status;
}
/*******************************************************************
net file enum
********************************************************************/
WERROR _srv_net_file_enum(pipes_struct *p, SRV_Q_NET_FILE_ENUM *q_u, SRV_R_NET_FILE_ENUM *r_u)
{
r_u->ctr = (SRV_FILE_INFO_CTR *)talloc(p->mem_ctx, sizeof(SRV_FILE_INFO_CTR));
if (!r_u->ctr)
return WERR_NOMEM;
ZERO_STRUCTP(r_u->ctr);
DEBUG(5,("srv_net_file_enum: %d\n", __LINE__));
/* set up the */
init_srv_r_net_file_enum(r_u,
get_enum_hnd(&q_u->enum_hnd),
q_u->file_level,
q_u->ctr->switch_value);
DEBUG(5,("srv_net_file_enum: %d\n", __LINE__));
return r_u->status;
}
/*******************************************************************
net conn enum
********************************************************************/
WERROR _srv_net_conn_enum(pipes_struct *p, SRV_Q_NET_CONN_ENUM *q_u, SRV_R_NET_CONN_ENUM *r_u)
{
DEBUG(5,("srv_net_conn_enum: %d\n", __LINE__));
r_u->ctr = (SRV_CONN_INFO_CTR *)talloc(p->mem_ctx, sizeof(SRV_CONN_INFO_CTR));
if (!r_u->ctr)
return WERR_NOMEM;
ZERO_STRUCTP(r_u->ctr);
/* set up the */
init_srv_r_net_conn_enum(r_u,
get_enum_hnd(&q_u->enum_hnd),
q_u->conn_level,
q_u->ctr->switch_value);
DEBUG(5,("srv_net_conn_enum: %d\n", __LINE__));
return r_u->status;
}
/*******************************************************************
net sess enum
********************************************************************/
WERROR _srv_net_sess_enum(pipes_struct *p, SRV_Q_NET_SESS_ENUM *q_u, SRV_R_NET_SESS_ENUM *r_u)
{
DEBUG(5,("_srv_net_sess_enum: %d\n", __LINE__));
r_u->ctr = (SRV_SESS_INFO_CTR *)talloc(p->mem_ctx, sizeof(SRV_SESS_INFO_CTR));
if (!r_u->ctr)
return WERR_NOMEM;
ZERO_STRUCTP(r_u->ctr);
/* set up the */
init_srv_r_net_sess_enum(r_u,
get_enum_hnd(&q_u->enum_hnd),
q_u->sess_level,
q_u->ctr->switch_value);
DEBUG(5,("_srv_net_sess_enum: %d\n", __LINE__));
return r_u->status;
}
/*******************************************************************
Net share enum all.
********************************************************************/
WERROR _srv_net_share_enum_all(pipes_struct *p, SRV_Q_NET_SHARE_ENUM *q_u, SRV_R_NET_SHARE_ENUM *r_u)
{
DEBUG(5,("_srv_net_share_enum: %d\n", __LINE__));
/* Create the list of shares for the response. */
init_srv_r_net_share_enum(p, r_u,
q_u->ctr.info_level,
get_enum_hnd(&q_u->enum_hnd), True);
DEBUG(5,("_srv_net_share_enum: %d\n", __LINE__));
return r_u->status;
}
/*******************************************************************
Net share enum.
********************************************************************/
WERROR _srv_net_share_enum(pipes_struct *p, SRV_Q_NET_SHARE_ENUM *q_u, SRV_R_NET_SHARE_ENUM *r_u)
{
DEBUG(5,("_srv_net_share_enum: %d\n", __LINE__));
/* Create the list of shares for the response. */
init_srv_r_net_share_enum(p, r_u,
q_u->ctr.info_level,
get_enum_hnd(&q_u->enum_hnd), False);
DEBUG(5,("_srv_net_share_enum: %d\n", __LINE__));
return r_u->status;
}
/*******************************************************************
Net share get info.
********************************************************************/
WERROR _srv_net_share_get_info(pipes_struct *p, SRV_Q_NET_SHARE_GET_INFO *q_u, SRV_R_NET_SHARE_GET_INFO *r_u)
{
fstring share_name;
DEBUG(5,("_srv_net_share_get_info: %d\n", __LINE__));
/* Create the list of shares for the response. */
unistr2_to_dos(share_name, &q_u->uni_share_name, sizeof(share_name));
init_srv_r_net_share_get_info(p, r_u, share_name, q_u->info_level);
DEBUG(5,("_srv_net_share_get_info: %d\n", __LINE__));
return r_u->status;
}
/*******************************************************************
Check a given DOS pathname is valid for a share.
********************************************************************/
static char *valid_share_pathname(char *dos_pathname)
{
pstring saved_pathname;
pstring unix_pathname;
char *ptr;
int ret;
/* Convert any '\' paths to '/' */
unix_format(dos_pathname);
unix_clean_name(dos_pathname);
/* NT is braindead - it wants a C: prefix to a pathname ! So strip it. */
ptr = dos_pathname;
if (strlen(dos_pathname) > 2 && ptr[1] == ':' && ptr[0] != '/')
ptr += 2;
/* Only abolute paths allowed. */
if (*ptr != '/')
return NULL;
/* Can we cd to it ? */
/* First save our current directory. */
if (getcwd(saved_pathname, sizeof(saved_pathname)) == NULL)
return False;
/* Convert to UNIX charset. */
dos_to_unix(unix_pathname, ptr);
ret = chdir(unix_pathname);
/* We *MUST* be able to chdir back. Abort if we can't. */
if (chdir(saved_pathname) == -1)
smb_panic("valid_share_pathname: Unable to restore current directory.\n");
return (ret != -1) ? ptr : NULL;
}
/*******************************************************************
Net share set info. Modify share details.
********************************************************************/
WERROR _srv_net_share_set_info(pipes_struct *p, SRV_Q_NET_SHARE_SET_INFO *q_u, SRV_R_NET_SHARE_SET_INFO *r_u)
{
struct current_user user;
pstring command;
fstring share_name;
pstring comment;
pstring pathname;
int type;
int snum;
int ret;
char *ptr;
SEC_DESC *psd = NULL;
pstring cvt_buf;
DEBUG(5,("_srv_net_share_set_info: %d\n", __LINE__));
unistr2_to_dos(share_name, &q_u->uni_share_name, sizeof(share_name));
r_u->switch_value = 0;
if (strequal(share_name,"IPC$") || strequal(share_name,"ADMIN$") || strequal(share_name,"global"))
return WERR_ACCESS_DENIED;
snum = find_service(share_name);
/* Does this share exist ? */
if (snum < 0)
return WERR_INVALID_NAME;
/* No change to printer shares. */
if (lp_print_ok(snum))
return WERR_ACCESS_DENIED;
get_current_user(&user,p);
if (user.uid != 0)
return WERR_ACCESS_DENIED;
switch (q_u->info_level) {
case 1:
/* Not enough info in a level 1 to do anything. */
return WERR_ACCESS_DENIED;
case 2:
unistr2_to_dos(comment, &q_u->info.share.info2.info_2_str.uni_remark, sizeof(share_name));
unistr2_to_dos(pathname, &q_u->info.share.info2.info_2_str.uni_path, sizeof(share_name));
type = q_u->info.share.info2.info_2.type;
psd = NULL;
break;
case 502:
unistr2_to_dos(comment, &q_u->info.share.info502.info_502_str.uni_remark, sizeof(share_name));
unistr2_to_dos(pathname, &q_u->info.share.info502.info_502_str.uni_path, sizeof(share_name));
type = q_u->info.share.info502.info_502.type;
psd = q_u->info.share.info502.info_502_str.sd;
map_generic_share_sd_bits(psd);
break;
case 1005:
return WERR_ACCESS_DENIED;
case 1501:
pstrcpy(pathname, lp_pathname(snum));
pstrcpy(comment, lp_comment(snum));
psd = q_u->info.share.info1501.sdb->sec;
map_generic_share_sd_bits(psd);
type = STYPE_DISKTREE;
break;
default:
DEBUG(5,("_srv_net_share_set_info: unsupported switch value %d\n", q_u->info_level));
return WERR_UNKNOWN_LEVEL;
}
/* We can only modify disk shares. */
if (type != STYPE_DISKTREE)
return WERR_ACCESS_DENIED;
/* Check if the pathname is valid. */
if (!(ptr = valid_share_pathname( pathname )))
return WERR_OBJECT_PATH_INVALID;
/* Ensure share name, pathname and comment don't contain '"' characters. */
string_replace(share_name, '"', ' ');
string_replace(ptr, '"', ' ');
string_replace(comment, '"', ' ');
DEBUG(10,("_srv_net_share_set_info: change share command = %s\n",
lp_change_share_cmd() ? lp_change_share_cmd() : "NULL" ));
/* Only call modify function if something changed. */
if (strcmp(ptr, lp_pathname(snum)) || strcmp(comment, lp_comment(snum)) ) {
if (!lp_change_share_cmd() || !*lp_change_share_cmd())
return WERR_ACCESS_DENIED;
dos_to_unix(cvt_buf, share_name);
pstrcpy(pathname, ptr);
dos_to_unix(pathname, pathname);
dos_to_unix(comment, comment);
slprintf(command, sizeof(command)-1, "%s '%s' '%s' '%s' '%s'",
lp_change_share_cmd(), CONFIGFILE, cvt_buf, pathname, comment);
DEBUG(10,("_srv_net_share_set_info: Running [%s]\n", command ));
if ((ret = smbrun(command, NULL)) != 0) {
DEBUG(0,("_srv_net_share_set_info: Running [%s] returned (%d)\n", command, ret ));
return WERR_ACCESS_DENIED;
}
/* Tell everyone we updated smb.conf. */
message_send_all(conn_tdb_ctx(), MSG_SMB_CONF_UPDATED, NULL, 0, False, NULL);
} else {
DEBUG(10,("_srv_net_share_set_info: No change to share name (%s)\n", share_name ));
}
/* Replace SD if changed. */
if (psd) {
SEC_DESC *old_sd;
size_t sd_size;
old_sd = get_share_security(p->mem_ctx, snum, &sd_size);
if (old_sd && !sec_desc_equal(old_sd, psd)) {
if (!set_share_security(p->mem_ctx, share_name, psd))
DEBUG(0,("_srv_net_share_set_info: Failed to change security info in share %s.\n",
share_name ));
}
}
DEBUG(5,("_srv_net_share_set_info: %d\n", __LINE__));
return WERR_OK;
}
/*******************************************************************
Net share add. Call 'add_share_command "sharename" "pathname" "comment" "read only = xxx"'
********************************************************************/
WERROR _srv_net_share_add(pipes_struct *p, SRV_Q_NET_SHARE_ADD *q_u, SRV_R_NET_SHARE_ADD *r_u)
{
struct current_user user;
pstring command;
fstring share_name;
pstring comment;
pstring pathname;
int type;
int snum;
int ret;
char *ptr;
SEC_DESC *psd = NULL;
pstring cvt_buf;
DEBUG(5,("_srv_net_share_add: %d\n", __LINE__));
r_u->switch_value = 0;
get_current_user(&user,p);
if (user.uid != 0) {
DEBUG(10,("_srv_net_share_add: uid != 0. Access denied.\n"));
return WERR_ACCESS_DENIED;
}
if (!lp_add_share_cmd() || !*lp_add_share_cmd()) {
DEBUG(10,("_srv_net_share_add: No add share command\n"));
return WERR_ACCESS_DENIED;
}
switch (q_u->info_level) {
case 1:
/* Not enough info in a level 1 to do anything. */
return WERR_ACCESS_DENIED;
case 2:
unistr2_to_dos(share_name, &q_u->info.share.info2.info_2_str.uni_netname, sizeof(share_name));
unistr2_to_dos(comment, &q_u->info.share.info2.info_2_str.uni_remark, sizeof(share_name));
unistr2_to_dos(pathname, &q_u->info.share.info2.info_2_str.uni_path, sizeof(share_name));
type = q_u->info.share.info2.info_2.type;
break;
case 502:
unistr2_to_dos(share_name, &q_u->info.share.info502.info_502_str.uni_netname, sizeof(share_name));
unistr2_to_dos(comment, &q_u->info.share.info502.info_502_str.uni_remark, sizeof(share_name));
unistr2_to_dos(pathname, &q_u->info.share.info502.info_502_str.uni_path, sizeof(share_name));
type = q_u->info.share.info502.info_502.type;
psd = q_u->info.share.info502.info_502_str.sd;
map_generic_share_sd_bits(psd);
break;
case 1005:
/* DFS only level. */
return WERR_ACCESS_DENIED;
default:
DEBUG(5,("_srv_net_share_add: unsupported switch value %d\n", q_u->info_level));
return WERR_UNKNOWN_LEVEL;
}
if (strequal(share_name,"IPC$") || strequal(share_name,"ADMIN$") || strequal(share_name,"global"))
return WERR_ACCESS_DENIED;
snum = find_service(share_name);
/* Share already exists. */
if (snum >= 0)
return WERR_ALREADY_EXISTS;
/* We can only add disk shares. */
if (type != STYPE_DISKTREE)
return WERR_ACCESS_DENIED;
/* Check if the pathname is valid. */
if (!(ptr = valid_share_pathname( pathname )))
return WERR_OBJECT_PATH_INVALID;
/* Ensure share name, pathname and comment don't contain '"' characters. */
string_replace(share_name, '"', ' ');
string_replace(ptr, '"', ' ');
string_replace(comment, '"', ' ');
dos_to_unix(cvt_buf, share_name);
pstrcpy(pathname, ptr);
dos_to_unix(pathname, pathname);
dos_to_unix(comment, comment);
slprintf(command, sizeof(command)-1, "%s '%s' '%s' '%s' '%s'",
lp_add_share_cmd(), CONFIGFILE, cvt_buf, pathname, comment);
DEBUG(10,("_srv_net_share_add: Running [%s]\n", command ));
if ((ret = smbrun(command, NULL)) != 0) {
DEBUG(0,("_srv_net_share_add: Running [%s] returned (%d)\n", command, ret ));
return WERR_ACCESS_DENIED;
}
if (psd) {
if (!set_share_security(p->mem_ctx, share_name, psd))
DEBUG(0,("_srv_net_share_add: Failed to add security info to share %s.\n",
share_name ));
}
/* Tell everyone we updated smb.conf. */
message_send_all(conn_tdb_ctx(), MSG_SMB_CONF_UPDATED, NULL, 0, False, NULL);
/*
* We don't call reload_services() here, the message will
* cause this to be done before the next packet is read
* from the client. JRA.
*/
DEBUG(5,("_srv_net_share_add: %d\n", __LINE__));
return WERR_OK;
}
/*******************************************************************
Net share delete. Call "delete share command" with the share name as
a parameter.
********************************************************************/
WERROR _srv_net_share_del(pipes_struct *p, SRV_Q_NET_SHARE_DEL *q_u, SRV_R_NET_SHARE_DEL *r_u)
{
struct current_user user;
pstring command;
fstring share_name;
int ret;
int snum;
pstring cvt_buf;
DEBUG(5,("_srv_net_share_del: %d\n", __LINE__));
unistr2_to_dos(share_name, &q_u->uni_share_name, sizeof(share_name));
if (strequal(share_name,"IPC$") || strequal(share_name,"ADMIN$") || strequal(share_name,"global"))
return WERR_ACCESS_DENIED;
snum = find_service(share_name);
if (snum < 0)
return WERR_NO_SUCH_SHARE;
/* No change to printer shares. */
if (lp_print_ok(snum))
return WERR_ACCESS_DENIED;
get_current_user(&user,p);
if (user.uid != 0)
return WERR_ACCESS_DENIED;
if (!lp_delete_share_cmd() || !*lp_delete_share_cmd())
return WERR_ACCESS_DENIED;
dos_to_unix(cvt_buf, lp_servicename(snum));
slprintf(command, sizeof(command)-1, "%s '%s' '%s'",
lp_delete_share_cmd(), CONFIGFILE, cvt_buf);
DEBUG(10,("_srv_net_share_del: Running [%s]\n", command ));
if ((ret = smbrun(command, NULL)) != 0) {
DEBUG(0,("_srv_net_share_del: Running [%s] returned (%d)\n", command, ret ));
return WERR_ACCESS_DENIED;
}
/* Delete the SD in the database. */
delete_share_security(snum);
/* Tell everyone we updated smb.conf. */
message_send_all(conn_tdb_ctx(), MSG_SMB_CONF_UPDATED, NULL, 0, False, NULL);
lp_killservice(snum);
return WERR_OK;
}
/*******************************************************************
time of day
********************************************************************/
WERROR _srv_net_remote_tod(pipes_struct *p, SRV_Q_NET_REMOTE_TOD *q_u, SRV_R_NET_REMOTE_TOD *r_u)
{
TIME_OF_DAY_INFO *tod;
struct tm *t;
time_t unixdate = time(NULL);
tod = (TIME_OF_DAY_INFO *)talloc(p->mem_ctx, sizeof(TIME_OF_DAY_INFO));
if (!tod)
return WERR_NOMEM;
ZERO_STRUCTP(tod);
r_u->tod = tod;
r_u->ptr_srv_tod = 0x1;
r_u->status = WERR_OK;
DEBUG(5,("_srv_net_remote_tod: %d\n", __LINE__));
t = gmtime(&unixdate);
/* set up the */
init_time_of_day_info(tod,
unixdate,
0,
t->tm_hour,
t->tm_min,
t->tm_sec,
0,
TimeDiff(unixdate)/60,
10000,
t->tm_mday,
t->tm_mon + 1,
1900+t->tm_year,
t->tm_wday);
DEBUG(5,("_srv_net_remote_tod: %d\n", __LINE__));
return r_u->status;
}
/***********************************************************************************
Win9x NT tools get security descriptor.
***********************************************************************************/
WERROR _srv_net_file_query_secdesc(pipes_struct *p, SRV_Q_NET_FILE_QUERY_SECDESC *q_u,
SRV_R_NET_FILE_QUERY_SECDESC *r_u)
{
SEC_DESC *psd = NULL;
size_t sd_size;
fstring null_pw;
fstring dev;
pstring filename;
pstring qualname;
files_struct *fsp = NULL;
SMB_STRUCT_STAT st;
BOOL bad_path;
int access_mode;
int action;
int ecode;
struct current_user user;
fstring user_name;
connection_struct *conn = NULL;
BOOL became_user = False;
ZERO_STRUCT(st);
r_u->status = WERR_OK;
unistr2_to_dos(qualname, &q_u->uni_qual_name, sizeof(qualname));
/* Null password is ok - we are already an authenticated user... */
*null_pw = '\0';
fstrcpy(dev, "A:");
get_current_user(&user, p);
fstrcpy(user_name, uidtoname(user.uid));
become_root();
conn = make_connection(qualname, user_name, null_pw, 0, dev, user.vuid, &ecode);
unbecome_root();
if (conn == NULL) {
DEBUG(3,("_srv_net_file_query_secdesc: Unable to connect to %s\n", qualname));
r_u->status = W_ERROR(ecode);
goto error_exit;
}
if (!become_user(conn, conn->vuid)) {
DEBUG(0,("_srv_net_file_query_secdesc: Can't become connected user!\n"));
r_u->status = WERR_ACCESS_DENIED;
goto error_exit;
}
became_user = True;
unistr2_to_dos(filename, &q_u->uni_file_name, sizeof(filename));
unix_convert(filename, conn, NULL, &bad_path, &st);
fsp = open_file_shared(conn, filename, &st, SET_OPEN_MODE(DOS_OPEN_RDONLY),
(FILE_FAIL_IF_NOT_EXIST|FILE_EXISTS_OPEN), 0, 0, &access_mode, &action);
if (!fsp) {
/* Perhaps it is a directory */
if (errno == EISDIR)
fsp = open_directory(conn, filename, &st,FILE_READ_ATTRIBUTES,0,
(FILE_FAIL_IF_NOT_EXIST|FILE_EXISTS_OPEN), 0, &action);
if (!fsp) {
DEBUG(3,("_srv_net_file_query_secdesc: Unable to open file %s\n", filename));
r_u->status = WERR_ACCESS_DENIED;
goto error_exit;
}
}
sd_size = conn->vfs_ops.get_nt_acl(fsp, fsp->fsp_name, &psd);
if (sd_size == 0) {
DEBUG(3,("_srv_net_file_query_secdesc: Unable to get NT ACL for file %s\n", filename));
r_u->status = WERR_ACCESS_DENIED;
goto error_exit;
}
r_u->ptr_response = 1;
r_u->size_response = sd_size;
r_u->ptr_secdesc = 1;
r_u->size_secdesc = sd_size;
r_u->sec_desc = psd;
psd->dacl->revision = (uint16) NT4_ACL_REVISION;
close_file(fsp, True);
unbecome_user();
close_cnum(conn, user.vuid);
return r_u->status;
error_exit:
if(fsp) {
close_file(fsp, True);
}
if (became_user)
unbecome_user();
if (conn)
close_cnum(conn, user.vuid);
return r_u->status;
}
/***********************************************************************************
Win9x NT tools set security descriptor.
***********************************************************************************/
WERROR _srv_net_file_set_secdesc(pipes_struct *p, SRV_Q_NET_FILE_SET_SECDESC *q_u,
SRV_R_NET_FILE_SET_SECDESC *r_u)
{
BOOL ret;
pstring filename;
pstring qualname;
fstring null_pw;
fstring dev;
files_struct *fsp = NULL;
SMB_STRUCT_STAT st;
BOOL bad_path;
int access_mode;
int action;
int ecode;
struct current_user user;
fstring user_name;
connection_struct *conn = NULL;
BOOL became_user = False;
ZERO_STRUCT(st);
r_u->status = WERR_OK;
unistr2_to_dos(qualname, &q_u->uni_qual_name, sizeof(qualname));
/* Null password is ok - we are already an authenticated user... */
*null_pw = '\0';
fstrcpy(dev, "A:");
get_current_user(&user, p);
fstrcpy(user_name, uidtoname(user.uid));
become_root();
conn = make_connection(qualname, user_name, null_pw, 0, dev, user.vuid, &ecode);
unbecome_root();
if (conn == NULL) {
DEBUG(3,("_srv_net_file_set_secdesc: Unable to connect to %s\n", qualname));
r_u->status = W_ERROR(ecode);
goto error_exit;
}
if (!become_user(conn, conn->vuid)) {
DEBUG(0,("_srv_net_file_set_secdesc: Can't become connected user!\n"));
r_u->status = WERR_ACCESS_DENIED;
goto error_exit;
}
became_user = True;
unistr2_to_dos(filename, &q_u->uni_file_name, sizeof(filename));
unix_convert(filename, conn, NULL, &bad_path, &st);
fsp = open_file_shared(conn, filename, &st, SET_OPEN_MODE(DOS_OPEN_RDWR),
(FILE_FAIL_IF_NOT_EXIST|FILE_EXISTS_OPEN), 0, 0, &access_mode, &action);
if (!fsp) {
/* Perhaps it is a directory */
if (errno == EISDIR)
fsp = open_directory(conn, filename, &st,FILE_READ_ATTRIBUTES,0,
(FILE_FAIL_IF_NOT_EXIST|FILE_EXISTS_OPEN), 0, &action);
if (!fsp) {
DEBUG(3,("_srv_net_file_set_secdesc: Unable to open file %s\n", filename));
r_u->status = WERR_ACCESS_DENIED;
goto error_exit;
}
}
ret = conn->vfs_ops.set_nt_acl(fsp, fsp->fsp_name, q_u->sec_info, q_u->sec_desc);
if (ret == False) {
DEBUG(3,("_srv_net_file_set_secdesc: Unable to set NT ACL on file %s\n", filename));
r_u->status = WERR_ACCESS_DENIED;
goto error_exit;
}
close_file(fsp, True);
unbecome_user();
close_cnum(conn, user.vuid);
return r_u->status;
error_exit:
if(fsp) {
close_file(fsp, True);
}
if (became_user)
unbecome_user();
if (conn)
close_cnum(conn, user.vuid);
return r_u->status;
}
/***********************************************************************************
It may be that we want to limit users to creating shares on certain areas of the UNIX file area.
We could define areas by mapping Windows style disks to points on the UNIX directory hierarchy.
These disks would the disks listed by this function.
Users could then create shares relative to these disks. Watch out for moving these disks around.
"Nigel Williams" <nigel@veritas.com>.
***********************************************************************************/
const char *server_disks[] = {"C:"};
static uint32 get_server_disk_count(void)
{
return sizeof(server_disks)/sizeof(server_disks[0]);
}
static uint32 init_server_disk_enum(uint32 *resume)
{
uint32 server_disk_count = get_server_disk_count();
/*resume can be an offset into the list for now*/
if(*resume & 0x80000000)
*resume = 0;
if(*resume > server_disk_count)
*resume = server_disk_count;
return server_disk_count - *resume;
}
static const char *next_server_disk_enum(uint32 *resume)
{
const char *disk;
if(init_server_disk_enum(resume) == 0)
return NULL;
disk = server_disks[*resume];
(*resume)++;
DEBUG(10, ("next_server_disk_enum: reporting disk %s. resume handle %d.\n", disk, *resume));
return disk;
}
WERROR _srv_net_disk_enum(pipes_struct *p, SRV_Q_NET_DISK_ENUM *q_u, SRV_R_NET_DISK_ENUM *r_u)
{
uint32 i;
const char *disk_name;
uint32 resume=get_enum_hnd(&q_u->enum_hnd);
r_u->status=WERR_OK;
r_u->total_entries = init_server_disk_enum(&resume);
r_u->disk_enum_ctr.unknown = 0;
r_u->disk_enum_ctr.disk_info_ptr = r_u->disk_enum_ctr.disk_info ? 1 : 0;
/*allow one DISK_INFO for null terminator*/
for(i = 0; i < MAX_SERVER_DISK_ENTRIES -1 && (disk_name = next_server_disk_enum(&resume)); i++) {
r_u->disk_enum_ctr.entries_read++;
/*copy disk name into a unicode string*/
init_unistr3(&r_u->disk_enum_ctr.disk_info[i].disk_name, disk_name);
}
/*add a terminating null string. Is this there if there is more data to come?*/
r_u->disk_enum_ctr.entries_read++;
init_unistr3(&r_u->disk_enum_ctr.disk_info[i].disk_name, "");
init_enum_hnd(&r_u->enum_hnd, resume);
return r_u->status;
}
WERROR _srv_net_name_validate(pipes_struct *p, SRV_Q_NET_NAME_VALIDATE *q_u, SRV_R_NET_NAME_VALIDATE *r_u)
{
int snum;
fstring share_name;
r_u->status=WERR_OK;
switch(q_u->type) {
case 0x9:
/*check if share name is ok*/
/*also check if we already have a share with this name*/
unistr2_to_dos(share_name, &q_u->uni_name, sizeof(share_name));
snum = find_service(share_name);
/* Share already exists. */
if (snum >= 0)
r_u->status = WERR_ALREADY_EXISTS;
break;
default:
/*unsupported type*/
r_u->status = WERR_UNKNOWN_LEVEL;
break;
}
return r_u->status;
}
|