1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627
|
/*
* Copyright (C) 2000-2002, 2004, 2005, 2008 Red Hat, Inc.
*
* This is free software; you can redistribute it and/or modify it under
* the terms of the GNU Library 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 Library General Public
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <config.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>
#include <limits.h>
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <glib.h>
#include <ldap.h>
#include <sasl/sasl.h>
#include "../lib/user_private.h"
#undef DEBUG
#define LOCKCHAR '!'
#define LOCKSTRING "!"
#define USERBRANCH "ou=People"
#define GROUPBRANCH "ou=Group"
#define OBJECTCLASS "objectClass"
#define ACCOUNT "account"
#define POSIXACCOUNT "posixAccount"
#define POSIXGROUP "posixGroup"
#define SHADOWACCOUNT "shadowAccount"
#define INETORGPERSON "inetOrgPerson"
#define DISTINGUISHED_NAME "dn"
LU_MODULE_INIT(libuser_ldap_init)
enum lock_op { LO_LOCK, LO_UNLOCK, LO_UNLOCK_NONEMPTY };
enum interact_indices {
LU_LDAP_SERVER,
LU_LDAP_BASEDN,
LU_LDAP_BINDDN,
LU_LDAP_PASSWORD,
LU_LDAP_AUTHUSER,
LU_LDAP_AUTHZUSER,
LU_LDAP_MAX,
};
static const struct {
const char *lu_attribute;
const char *ldap_attribute;
const char *objectclass;
enum lu_entity_type type;
} ldap_attribute_map[] = {
{LU_USERNAME, "uid", POSIXACCOUNT, lu_user},
{LU_USERPASSWORD, "userPassword", POSIXACCOUNT, lu_user},
{LU_UIDNUMBER, "uidNumber", POSIXACCOUNT, lu_user},
{LU_GIDNUMBER, "gidNumber", POSIXACCOUNT, lu_user},
{LU_GECOS, "gecos", POSIXACCOUNT, lu_user},
{LU_HOMEDIRECTORY, "homeDirectory", POSIXACCOUNT, lu_user},
{LU_LOGINSHELL, "loginShell", POSIXACCOUNT, lu_user},
{LU_COMMONNAME, "cn", POSIXACCOUNT, lu_user},
{LU_GROUPNAME, "cn", POSIXGROUP, lu_group},
{LU_GROUPPASSWORD, "userPassword", POSIXGROUP, lu_group},
{LU_GIDNUMBER, "gidNumber", POSIXGROUP, lu_group},
{LU_MEMBERNAME, "memberUid", POSIXGROUP, lu_group},
{LU_SHADOWLASTCHANGE, "shadowLastChange", SHADOWACCOUNT, lu_user},
{LU_SHADOWMIN, "shadowMin", SHADOWACCOUNT, lu_user},
{LU_SHADOWMAX, "shadowMax", SHADOWACCOUNT, lu_user},
{LU_SHADOWWARNING, "shadowWarning", SHADOWACCOUNT, lu_user},
{LU_SHADOWINACTIVE, "shadowInactive", SHADOWACCOUNT, lu_user},
{LU_SHADOWEXPIRE, "shadowExpire", SHADOWACCOUNT, lu_user},
{LU_SHADOWFLAG, "shadowFlag", SHADOWACCOUNT, lu_user},
{LU_GIVENNAME, "givenName", INETORGPERSON, lu_user},
{LU_SN, "sn", INETORGPERSON, lu_user},
{LU_ROOMNUMBER, "roomNumber", INETORGPERSON, lu_user},
{LU_TELEPHONENUMBER, "telephoneNumber", INETORGPERSON, lu_user},
{LU_HOMEPHONE, "homePhone", INETORGPERSON, lu_user},
};
static const char *const lu_ldap_user_attributes[] = {
LU_USERNAME,
LU_USERPASSWORD,
LU_UIDNUMBER,
LU_GIDNUMBER,
LU_GECOS,
LU_HOMEDIRECTORY,
LU_LOGINSHELL,
/* Not LU_SHADOWPASSWORD: We can't allow modification of
* LU_USERPASSWORD and LU_SHADOWPASSWORD at the same time; LDAP simply
* doesn't implement LU_SHADOWPASSWORD. */
LU_SHADOWLASTCHANGE,
LU_SHADOWMIN,
LU_SHADOWMAX,
LU_SHADOWWARNING,
LU_SHADOWINACTIVE,
LU_SHADOWEXPIRE,
LU_SHADOWFLAG,
LU_COMMONNAME,
LU_GIVENNAME,
LU_SN,
LU_ROOMNUMBER,
LU_TELEPHONENUMBER,
LU_HOMEPHONE,
NULL
};
static const char *const lu_ldap_group_attributes[] = {
LU_GROUPNAME,
LU_GROUPPASSWORD,
LU_GIDNUMBER,
LU_MEMBERNAME,
LU_ADMINISTRATORNAME,
NULL
};
struct lu_ldap_context {
struct lu_context *global_context; /* The library context. */
struct lu_module *module; /* The module's structure. */
struct lu_prompt prompts[LU_LDAP_MAX]; /* Questions and answers. */
gboolean bind_simple, bind_sasl; /* What kind of bind to use. */
char *sasl_mechanism; /* What sasl mechanism to use. */
const char *user_branch, *group_branch; /* Cached config values */
char **mapped_user_attributes, **mapped_group_attributes;
LDAP *ldap; /* The connection. */
};
static void
close_server(LDAP *ldap)
{
ldap_unbind_ext(ldap, NULL, NULL);
}
/* Get the name of the user running the calling application. */
static char *
getuser(void)
{
char buf[LINE_MAX * 4];
struct passwd pwd, *err;
int i;
i = getpwuid_r(getuid(), &pwd, buf, sizeof(buf), &err);
return ((i == 0) && (err == &pwd)) ? g_strdup(pwd.pw_name) : NULL;
}
static gboolean
nonempty(const char *string)
{
return (string != NULL) && (strlen(string) > 0);
}
/* Connect to the server. */
static LDAP *
connect_server(struct lu_ldap_context *context, struct lu_error **error)
{
LDAP *ldap = NULL;
int version, ret, start_tls;
g_assert(context != NULL);
LU_ERROR_CHECK(error);
/* Create the LDAP context. */
ret = ldap_initialize(&ldap, context->prompts[LU_LDAP_SERVER].value);
if (ret == LDAP_SUCCESS)
start_tls = FALSE;
else {
if (ldap_create(&ldap) != LDAP_SUCCESS)
ldap = NULL;
else if (ldap_set_option(ldap, LDAP_OPT_HOST_NAME,
context->prompts[LU_LDAP_SERVER]
.value) != LDAP_SUCCESS) {
close_server(ldap);
ldap = NULL;
}
start_tls = TRUE;
}
if (ldap == NULL) {
lu_error_new(error, lu_error_init,
_("error initializing ldap library"));
return NULL;
}
/* Switch to LDAPv3, which gives us some more features we need. */
version = LDAP_VERSION3;
ret = ldap_set_option(ldap,
LDAP_OPT_PROTOCOL_VERSION,
&version);
if (ret != LDAP_OPT_SUCCESS) {
lu_error_new(error, lu_error_init,
_("could not set LDAP protocol to version %d"),
version);
close_server(ldap);
return NULL;
}
/* Try to start TLS. */
ret = ldap_start_tls_s(ldap, NULL, NULL);
/* Note that TLS is not required for ldap:// URLs (unlike simple server
names). */
if (ret != LDAP_SUCCESS && start_tls) {
lu_error_new(error, lu_error_init,
_("could not negotiate TLS with LDAP server"));
close_server(ldap);
return NULL;
}
return ldap;
}
/* Authentication callback. */
static int
interact(LDAP *ld, unsigned flags, void *defs, void *xres)
{
sasl_interact_t *res;
struct lu_ldap_context *ctx = (struct lu_ldap_context*) defs;
int i, retval = LDAP_SUCCESS;
(void)ld;
(void)flags;
res = xres;
for(i = 0; res && res[i].id != SASL_CB_LIST_END; i++) {
res[i].result = NULL;
switch(res[i].id) {
case SASL_CB_USER:
res[i].result = ctx->prompts[LU_LDAP_AUTHUSER].value;
if (res[i].result == NULL)
res[i].result = "";
#ifdef DEBUG
g_print("Sending SASL user `%s'.\n",
(const char *)res[i].result);
#endif
break;
case SASL_CB_AUTHNAME:
res[i].result = ctx->prompts[LU_LDAP_AUTHZUSER].value;
#ifdef DEBUG
g_print("Sending SASL auth user `%s'.\n",
(const char *)res[i].result);
#endif
break;
case SASL_CB_GETREALM:
/* Always tell sasl to find it on its own. */
res[i].result = "";
break;
default:
#ifdef DEBUG
g_print("Unhandled SASL Intreractive option `%d'.\n",
res[i].id);
#endif
retval = LDAP_OTHER;
}
if (res[i].result != NULL)
res[i].len = strlen(res[i].result);
else
res[i].len = 0;
}
return retval;
}
/* Authenticate to the server. */
static LDAP *
bind_server(struct lu_ldap_context *context, struct lu_error **error)
{
LDAP *ldap;
int ret, first_failure;
const char *generated_binddn, *first_binddn;
char *binddn, *tmp;
char *user;
char *password;
struct lu_string_cache *scache = NULL;
g_assert(context != NULL);
LU_ERROR_CHECK(error);
/* Create the connection. */
ldap = connect_server(context, error);
if (ldap == NULL) {
return NULL;
}
/* Generate the DN we might want to bind to. */
scache = context->global_context->scache;
user = getuser();
if (user) {
tmp = scache->cache(scache, user);
free(user);
user = tmp;
}
if (nonempty(context->prompts[LU_LDAP_AUTHUSER].value)) {
user = context->prompts[LU_LDAP_AUTHUSER].value;
}
tmp = g_strdup_printf("uid=%s,%s,%s", user, context->user_branch,
context->prompts[LU_LDAP_BASEDN].value);
generated_binddn = scache->cache(scache, tmp);
g_free(tmp);
/* Try to bind to the server using SASL. */
binddn = context->prompts[LU_LDAP_BINDDN].value;
if (nonempty(context->prompts[LU_LDAP_AUTHUSER].value)) {
ldap_set_option(ldap, LDAP_OPT_X_SASL_AUTHCID,
context->prompts[LU_LDAP_AUTHUSER].value);
}
if (nonempty(context->prompts[LU_LDAP_AUTHZUSER].value)) {
ldap_set_option(ldap, LDAP_OPT_X_SASL_AUTHZID,
context->prompts[LU_LDAP_AUTHZUSER].value);
}
if (context->prompts[LU_LDAP_PASSWORD].value != NULL) {
password = context->prompts[LU_LDAP_PASSWORD].value;
} else {
password = NULL;
}
ret = LDAP_SUCCESS + 1; /* Not LDAP_SUCCESS */
first_failure = LDAP_SUCCESS; /* No failure known yet */
first_binddn = NULL;
if ((binddn != NULL) && (strlen(binddn) == 0)) {
binddn = NULL;
}
if (context->bind_sasl) {
/* Try to bind using SASL, and if that fails... */
if (binddn != NULL) {
#ifdef DEBUG
g_print("Attempting SASL bind to `%s'.\n", binddn);
#endif
ret = ldap_sasl_interactive_bind_s(ldap, binddn,
context->sasl_mechanism,
NULL, NULL,
LDAP_SASL_AUTOMATIC,
interact,
context);
if (ret != LDAP_SUCCESS) {
first_failure = ret;
first_binddn = binddn;
}
}
if (ret != LDAP_SUCCESS) {
#ifdef DEBUG
g_print("Attempting SASL bind to `%s'.\n",
generated_binddn);
#endif
ret = ldap_sasl_interactive_bind_s(ldap,
generated_binddn,
context->sasl_mechanism,
NULL, NULL,
LDAP_SASL_AUTOMATIC,
interact, context);
if (ret != LDAP_SUCCESS
&& first_failure == LDAP_SUCCESS) {
first_failure = ret;
first_binddn = generated_binddn;
}
}
}
if (ret != LDAP_SUCCESS && context->bind_simple) {
/* try to bind using a password, and if that fails... */
if ((password != NULL) && (strlen(password) > 0)) {
BerValue cred;
cred.bv_val = password;
cred.bv_len = strlen(password);
if (binddn != NULL) {
#ifdef DEBUG
g_print("Attempting simple bind to `%s'.\n",
binddn);
#endif
ret = ldap_sasl_bind_s(ldap, binddn,
LDAP_SASL_SIMPLE, &cred,
NULL, NULL, NULL);
if (ret != LDAP_SUCCESS
&& first_failure == LDAP_SUCCESS) {
first_failure = ret;
first_binddn = binddn;
}
}
if (ret != LDAP_SUCCESS) {
#ifdef DEBUG
g_print("Attempting simple bind to `%s'.\n",
generated_binddn);
#endif
ret = ldap_sasl_bind_s(ldap, generated_binddn,
LDAP_SASL_SIMPLE, &cred,
NULL, NULL, NULL);
if (ret != LDAP_SUCCESS
&& first_failure == LDAP_SUCCESS) {
first_failure = ret;
first_binddn = generated_binddn;
}
}
}
}
if (ret != LDAP_SUCCESS) {
/* give up. */
if (first_failure == LDAP_SUCCESS)
lu_error_new(error, lu_error_init,
_("could not bind to LDAP server"));
else
lu_error_new(error, lu_error_init,
_("could not bind to LDAP server, first "
"attempt as `%s': %s"), first_binddn,
ldap_err2string(first_failure));
close_server(ldap);
return NULL;
}
return ldap;
}
/* Map an attribute name from an internal name to an LDAP atribute name. */
static const char *
map_to_ldap(struct lu_string_cache *cache, const char *libuser_attribute)
{
size_t i;
/* Luckily the only duplicate is LU_GIDNUMBER, which maps to the
same value in both cases. */
for (i = 0; i < G_N_ELEMENTS(ldap_attribute_map); i++) {
if (g_ascii_strcasecmp(ldap_attribute_map[i].lu_attribute,
libuser_attribute) == 0) {
return ldap_attribute_map[i].ldap_attribute;
}
}
return cache->cache(cache, libuser_attribute);
}
/* Generate the distinguished name which corresponds to the container where
* the lu_ent structure's entry would be found. */
static const char *
lu_ldap_base(struct lu_module *module, const char *branch)
{
struct lu_ldap_context *context;
char *tmp, *ret;
g_assert(module != NULL);
context = module->module_context;
/* Generate the branch DN. */
if (strlen(branch) != 0)
tmp = g_strconcat(branch, ",",
context->prompts[LU_LDAP_BASEDN].value,
(const gchar *)NULL);
else
tmp = g_strdup(context->prompts[LU_LDAP_BASEDN].value);
ret = module->scache->cache(module->scache, tmp);
g_free(tmp);
return ret;
}
/* Discover the distinguished name which corresponds to an account. */
static const char *
lu_ldap_ent_to_dn(struct lu_module *module, const char *namingAttr,
const char *name, const char *branch)
{
static char *noattrs[] = { NULL };
const char *base, *mapped_naming_attr;
char *tmp, *ret = NULL, *filter;
struct lu_ldap_context *ctx;
LDAPMessage *messages = NULL;
g_assert(module != NULL);
g_assert(namingAttr != NULL);
g_assert(strlen(namingAttr) > 0);
g_assert(name != NULL);
g_assert(strlen(name) > 0);
/* Search for the right object using the entity's current name. */
base = lu_ldap_base(module, branch);
ctx = module->module_context;
mapped_naming_attr = map_to_ldap(module->scache, namingAttr);
filter = g_strdup_printf("(%s=%s)", mapped_naming_attr, name);
if (ldap_search_ext_s(ctx->ldap, base, LDAP_SCOPE_SUBTREE, filter,
noattrs, FALSE, NULL, NULL, NULL, LDAP_NO_LIMIT,
&messages) == LDAP_SUCCESS) {
LDAPMessage *entry;
entry = ldap_first_entry(ctx->ldap, messages);
if (entry != NULL) {
tmp = ldap_get_dn(ctx->ldap, entry);
ret = module->scache->cache(module->scache, tmp);
if (tmp)
ldap_memfree(tmp);
}
ldap_msgfree(messages);
}
g_free(filter);
if (ret == NULL) {
/* Guess at the DN using the branch and the base. */
tmp = g_strdup_printf("%s=%s,%s", mapped_naming_attr, name,
base);
ret = module->scache->cache(module->scache, tmp);
g_free(tmp);
}
return ret;
}
/* This is the lookup workhorse. */
static gboolean
lu_ldap_lookup(struct lu_module *module,
const char *namingAttr, const char *name,
struct lu_ent *ent, GPtrArray *ent_array, const char *branch,
const char *filter, const char *const *attributes,
enum lu_entity_type type, struct lu_error **error)
{
LDAPMessage *messages = NULL, *entry = NULL;
char *filt, **mapped_attributes;
const char *dn = NULL;
const char *base;
gboolean ret = FALSE;
struct lu_ldap_context *ctx;
g_assert(module != NULL);
g_assert(namingAttr != NULL);
g_assert(strlen(namingAttr) > 0);
name = name ?: "*";
g_assert((ent != NULL) || (ent_array != NULL));
if (ent != NULL) {
g_assert(ent->magic == LU_ENT_MAGIC);
}
g_assert(attributes != NULL);
g_assert(attributes[0] != NULL);
LU_ERROR_CHECK(error);
ctx = module->module_context;
if (ent != NULL) {
GValueArray *array;
/* Try to use the dn the object already knows about. */
array = lu_ent_get(ent, DISTINGUISHED_NAME);
if (array != NULL) {
GValue *val;
val = g_value_array_get_nth(array, 0);
if (G_VALUE_HOLDS_STRING(val))
dn = g_value_get_string(val);
}
if (dn == NULL)
/* Map the user or group name to an LDAP object name. */
dn = lu_ldap_ent_to_dn(module, namingAttr, name,
branch);
}
/* Get the entry in the directory under which we'll search for this
* entity. */
base = lu_ldap_base(module, branch);
/* Generate an LDAP filter, optionally including a filter supplied
* by the caller. */
if (filter && (strlen(filter) > 0)) {
filt = g_strdup_printf("(&%s(%s=%s))", filter,
namingAttr, name);
} else {
filt = g_strdup_printf("(%s=%s)", namingAttr, name);
}
#ifdef DEBUG
g_print("Looking up `%s' with filter `%s'.\n", dn, filt);
#endif
if (attributes == lu_ldap_user_attributes)
mapped_attributes = ctx->mapped_user_attributes;
else if (attributes == lu_ldap_group_attributes)
mapped_attributes = ctx->mapped_group_attributes;
else {
g_assert_not_reached();
mapped_attributes = NULL;
}
if (ent != NULL) {
/* Perform the search and read the first (hopefully only)
* entry. */
if (ldap_search_ext_s(ctx->ldap, dn, LDAP_SCOPE_BASE, filt,
mapped_attributes, FALSE, NULL, NULL,
NULL, LDAP_NO_LIMIT, &messages)
== LDAP_SUCCESS) {
entry = ldap_first_entry(ctx->ldap, messages);
}
}
/* If there isn't an entry with this exact name, search for something
* which matches. */
if (entry == NULL) {
#ifdef DEBUG
g_print("Looking under `%s' with filter `%s'.\n", base,
filt);
#endif
if (messages != NULL) {
ldap_msgfree(messages);
messages = NULL;
}
if (ldap_search_ext_s(ctx->ldap, base, LDAP_SCOPE_SUBTREE,
filt, mapped_attributes, FALSE, NULL,
NULL, NULL, LDAP_NO_LIMIT, &messages)
== LDAP_SUCCESS) {
entry = ldap_first_entry(ctx->ldap, messages);
}
}
/* We don't need the generated filter any more, so free it. */
g_free(filt);
/* If we got an entry, read its contents into an entity structure. */
while (entry != NULL) {
GValue value;
size_t i;
char *p;
/* Mark that the search succeeded. */
ret = TRUE;
/* If we need to add the data to the array, then create a new
* data item to hold the data. */
if (ent_array != NULL)
ent = lu_ent_new_typed(type);
/* Set the distinguished name. */
memset(&value, 0, sizeof(value));
g_value_init(&value, G_TYPE_STRING);
p = ldap_get_dn(ctx->ldap, entry);
g_value_set_string(&value, p);
ldap_memfree(p);
lu_ent_clear_current(ent, DISTINGUISHED_NAME);
lu_ent_add_current(ent, DISTINGUISHED_NAME, &value);
g_value_unset(&value);
/* Read each of the attributes we asked for. */
for (i = 0; attributes[i]; i++) {
BerValue **values;
const char *attr;
/* Get the values which correspond to this attribute. */
attr = attributes[i];
values = ldap_get_values_len(ctx->ldap, entry,
mapped_attributes[i]);
/* If we got answers, add them. */
if (values) {
size_t j;
lu_ent_clear_current(ent, attr);
for (j = 0; values[j]; j++) {
char *val;
gboolean ok;
struct lu_error *error;
val = g_strndup(values[j]->bv_val,
values[j]->bv_len);
#ifdef DEBUG
g_print("Got `%s' = `%s'.\n", attr,
val);
#endif
error = NULL;
ok = lu_value_init_set_attr_from_string
(&value, attr, val, &error);
if (ok == FALSE) {
g_assert(error != NULL);
g_warning(lu_strerror(error));
lu_error_free(&error);
} else {
lu_ent_add_current(ent, attr,
&value);
g_value_unset(&value);
}
g_free(val);
}
ldap_value_free_len(values);
}
}
/* Stash the data in the array if we need to. */
if (ent_array != NULL) {
g_ptr_array_add(ent_array, ent);
ent = NULL;
/* Go to the next entry. */
entry = ldap_next_entry(ctx->ldap, entry);
} else {
/* Stop here. */
entry = NULL;
}
}
/* Free all of the responses. */
if (messages) {
ldap_msgfree(messages);
}
return ret;
}
/* Look up a user by name. */
static gboolean
lu_ldap_user_lookup_name(struct lu_module *module, const char *name,
struct lu_ent *ent, struct lu_error **error)
{
struct lu_ldap_context *ctx;
LU_ERROR_CHECK(error);
ctx = module->module_context;
return lu_ldap_lookup(module, "uid", name, ent, NULL, ctx->user_branch,
"("OBJECTCLASS"="POSIXACCOUNT")",
lu_ldap_user_attributes, lu_user, error);
}
/* Look up a user by ID. */
static gboolean
lu_ldap_user_lookup_id(struct lu_module *module, uid_t uid,
struct lu_ent *ent, struct lu_error **error)
{
struct lu_ldap_context *ctx;
char uid_string[sizeof (uid) * CHAR_BIT + 1];
LU_ERROR_CHECK(error);
ctx = module->module_context;
sprintf(uid_string, "%jd", (intmax_t)uid);
return lu_ldap_lookup(module, "uidNumber", uid_string, ent, NULL,
ctx->user_branch,
"("OBJECTCLASS"="POSIXACCOUNT")",
lu_ldap_user_attributes, lu_user, error);
}
/* Look up a group by name. */
static gboolean
lu_ldap_group_lookup_name(struct lu_module *module, const char *name,
struct lu_ent *ent, struct lu_error **error)
{
struct lu_ldap_context *ctx;
LU_ERROR_CHECK(error);
ctx = module->module_context;
return lu_ldap_lookup(module, "cn", name, ent, NULL, ctx->group_branch,
"("OBJECTCLASS"="POSIXGROUP")",
lu_ldap_group_attributes, lu_group, error);
}
/* Look up a group by ID. */
static gboolean
lu_ldap_group_lookup_id(struct lu_module *module, gid_t gid,
struct lu_ent *ent, struct lu_error **error)
{
struct lu_ldap_context *ctx;
char gid_string[sizeof (gid) * CHAR_BIT + 1];
LU_ERROR_CHECK(error);
ctx = module->module_context;
sprintf(gid_string, "%jd", (intmax_t)gid);
return lu_ldap_lookup(module, "gidNumber", gid_string, ent, NULL,
ctx->group_branch,
"("OBJECTCLASS"="POSIXGROUP")",
lu_ldap_group_attributes, lu_group, error);
}
/* Compare the contents of two GValueArrays, and return TRUE if they contain
* the same set of values, though not necessarily in the same order. */
static gboolean
arrays_equal(GValueArray *a, GValueArray *b)
{
GValue *aval, *bval;
size_t i, j;
if ((a != NULL) && (b == NULL)) {
return FALSE;
}
if ((a == NULL) && (b != NULL)) {
return FALSE;
}
for (i = 0; i < a->n_values; i++) {
aval = g_value_array_get_nth(a, i);
for (j = 0; j < b->n_values; j++) {
bval = g_value_array_get_nth(b, j);
if (G_VALUE_TYPE(aval) == G_VALUE_TYPE(bval)
&& lu_values_equal(aval, bval))
break;
}
if (j >= b->n_values) {
return FALSE;
}
}
for (j = 0; j < b->n_values; j++) {
bval = g_value_array_get_nth(b, j);
for (i = 0; i < a->n_values; i++) {
aval = g_value_array_get_nth(a, i);
if (G_VALUE_TYPE(aval) == G_VALUE_TYPE(bval)
&& lu_values_equal(aval, bval))
break;
}
if (i >= a->n_values) {
return FALSE;
}
}
return TRUE;
}
/* Check whether class is among old_values or new_values */
static int
objectclass_present(const char *dn, const char *class,
BerValue *const *old_values, size_t old_count,
BerValue *const *new_values, size_t new_count)
{
size_t i, len;
(void)dn;
len = strlen(class);
for (i = 0; i < old_count; i++) {
const BerValue *val;
val = old_values[i];
if (val->bv_len == len
&& memcmp(class, val->bv_val, len) == 0) {
#ifdef DEBUG
g_print("Entity `%s' is already a `%.*s'.\n", dn,
(int)val->bv_len, val->bv_val);
#endif
return 1;
}
}
for (i = 0; i < new_count; i++) {
const BerValue *val;
val = new_values[i];
if (val->bv_len == len
&& memcmp(class, val->bv_val, len) == 0) {
#ifdef DEBUG
g_print("Entity `%s' was already determined to be a "
"`%.*s'.\n", dn, (int)val->bv_len,
val->bv_val);
#endif
return 1;
}
}
return 0;
}
/* Create a list of new object classes needed for representing all attributes,
* assuming old_values (may be NULL).
*
* Returns NULL if no new object classes are needed. */
static BerValue **
lu_ldap_needed_objectclasses(const char *dn, struct lu_ent *ent,
BerValue **old_values)
{
BerValue **new_values;
size_t old_count, new_count;
GList *attributes, *a;
if (old_values)
old_count = ldap_count_values_len(old_values);
else
old_count = 0;
new_values = g_malloc(sizeof(*new_values) *
(G_N_ELEMENTS(ldap_attribute_map) + 1 + 1));
new_count = 0;
/* Iterate over all of the attributes the object possesses. */
attributes = lu_ent_get_attributes(ent);
for (a = attributes; a != NULL; a = a->next) {
size_t i;
const char *attr;
BerValue *bv;
attr = a->data;
#ifdef DEBUG
g_print("Entity `%s' has attribute `%s'.\n", dn, attr);
#endif
/* Get the name of the next object class the object needs
* to be a member of. */
for (i = 0; i < G_N_ELEMENTS(ldap_attribute_map); i++) {
if (ldap_attribute_map[i].type == ent->type
&& strcasecmp(ldap_attribute_map[i].lu_attribute,
attr) == 0) {
#ifdef DEBUG
g_print("Entity `%s' needs to be a `%s'.\n",
dn, ldap_attribute_map[i].objectclass);
#endif
break;
}
}
/* If the attribute doesn't map to a class, skip it. */
if (i >= G_N_ELEMENTS(ldap_attribute_map))
continue;
/* Check if the object class the object needs to be in is
* already one of which it is a part or is already being
* added. */
if (objectclass_present(dn, ldap_attribute_map[i].objectclass,
old_values, old_count, new_values,
new_count))
continue;
/* Add it to the class. */
bv = g_malloc(sizeof (*bv));
bv->bv_val = (char *)ldap_attribute_map[i].objectclass;
bv->bv_len = strlen(bv->bv_val);
new_values[new_count] = bv;
#ifdef DEBUG
g_print("Adding entity `%s' to class `%s'.\n", dn,
new_values[new_count]);
#endif
new_count++;
}
g_list_free(attributes);
/* Ugly, but implied by the fact that the basic account schemas are not
* structural. We can't use INETORGPERSON unless LU_SN is present,
* which would already force usage of INETORGPERSON; so if
* INETORGPERSON is not used, we add ACCOUNT. */
if (ent->type == lu_user
&& !objectclass_present(dn, INETORGPERSON, old_values, old_count,
new_values, new_count)
&& !objectclass_present(dn, ACCOUNT, old_values, old_count,
new_values, new_count)) {
BerValue *bv;
bv = g_malloc(sizeof (*bv));
bv->bv_val = ACCOUNT;
bv->bv_len = strlen(ACCOUNT);
new_values[new_count++] = bv;
}
if (new_count != 0)
new_values[new_count] = NULL;
else {
g_free(new_values);
new_values = NULL;
}
return new_values;
}
/* Free the (non-NULL) result of ldap_needed_objectclasses */
static void
free_needed_objectclasses(BerValue **values)
{
size_t i;
for (i = 0; values[i] != NULL; i++)
g_free(values[i]);
g_free(values);
}
/* Build a list of LDAPMod structures for adding the entity object. */
static LDAPMod **
get_ent_adds(const char *dn, struct lu_ent *ent)
{
LDAPMod **mods;
GList *attrs;
g_assert(ent != NULL);
g_assert(ent->magic == LU_ENT_MAGIC);
mods = NULL;
/* If there are no attributes, then this is EASY. */
attrs = lu_ent_get_attributes(ent);
if (attrs) {
BerValue **classes;
size_t mod_count, i;
LDAPMod *mod;
GValueArray *vals;
GValue *value;
const GList *a;
mods = g_malloc0(sizeof(*mods)
* (g_list_length(attrs) + 2 + 1));
mod_count = 0;
for (a = attrs; a != NULL; a = a->next) {
const char *attribute;
attribute = a->data;
if (strcasecmp(attribute, DISTINGUISHED_NAME) == 0)
continue;
/* We don't have shadow passwords. Period. */
if (strcasecmp(attribute, LU_SHADOWPASSWORD) == 0)
continue;
vals = lu_ent_get(ent, attribute);
if (vals == NULL)
continue;
attribute = map_to_ldap(ent->cache, attribute);
mod = g_malloc0(sizeof(*mod));
mod->mod_op = LDAP_MOD_ADD;
mod->mod_type = (char *)attribute;
mod->mod_values
= g_malloc0((vals->n_values + 1)
* sizeof(*mod->mod_values));
for (i = 0; i < vals->n_values; i++) {
value = g_value_array_get_nth(vals, i);
mod->mod_values[i] = lu_value_strdup(value);
}
mods[mod_count++] = mod;
}
/* We don't need the list of attributes any more. */
g_list_free(attrs);
classes = lu_ldap_needed_objectclasses(dn, ent, NULL);
if (classes != NULL) {
mod = g_malloc0(sizeof(*mod));
mod->mod_op = LDAP_MOD_ADD;
mod->mod_type = OBJECTCLASS;
mod->mod_values
= g_malloc0((ldap_count_values_len(classes)
+ 1) * sizeof(*mod->mod_values));
for (i = 0; classes[i] != NULL; i++)
mod->mod_values[i]
= g_strdup(classes[i]->bv_val);
free_needed_objectclasses(classes);
mods[mod_count++] = mod;
}
/* Ugly hack:
*
* Make sure there is 'cn', posixAccount requires it. */
if (ent->type == lu_user
&& lu_ent_get(ent, LU_COMMONNAME) == NULL) {
char *cn;
vals = lu_ent_get(ent, LU_GECOS);
if (vals != NULL) {
char *p;
value = g_value_array_get_nth(vals, 0);
cn = lu_value_strdup(value);
p = strchr(cn, ',');
if (p != NULL)
*p = 0;
} else {
vals = lu_ent_get(ent, LU_USERNAME);
/* Guaranteed by lu_ldap_set() */
g_assert (vals != NULL);
value = g_value_array_get_nth(vals, 0);
cn = lu_value_strdup(value);
}
mod = g_malloc0(sizeof(*mod));
mod->mod_op = LDAP_MOD_ADD;
mod->mod_type = (char *)"cn";
mod->mod_values
= g_malloc0(2 * sizeof (*mod->mod_values));
mod->mod_values[0] = cn;
mods[mod_count++] = mod;
}
}
return mods;
}
/* Build a list of LDAPMod structures based on the differences between the
* pending and current values in the entity object. */
static LDAPMod **
get_ent_mods(struct lu_ent *ent, const char *namingAttr)
{
LDAPMod **mods = NULL;
GList *attrs;
g_assert(ent != NULL);
g_assert(ent->magic == LU_ENT_MAGIC);
g_assert(namingAttr != NULL);
g_assert(namingAttr[0] != 0);
/* If there are no attributes, then this is EASY. */
attrs = lu_ent_get_attributes(ent);
if (attrs) {
GValueArray *empty;
size_t mod_count;
LDAPMod *mod;
const GList *a;
empty = g_value_array_new(0);
/* Allocate an array big enough to hold two LDAPMod structures
* for each attribute, in case all of them need changing. */
mods = g_malloc0(sizeof(*mods) *
((2 * g_list_length(attrs)) + 1));
mod_count = 0;
for (a = attrs; a != NULL; a = a->next) {
GValueArray *current, *pending, *additions, *deletions;
GValue *value, *pvalue, *cvalue;
char *attribute;
size_t j, k;
/* Get the name of the attribute, and its current and
* pending values. */
attribute = a->data;
if (strcasecmp(attribute, DISTINGUISHED_NAME) == 0
|| strcasecmp(attribute, namingAttr) == 0)
continue;
current = lu_ent_get_current(ent, attribute) ?: empty;
pending = lu_ent_get(ent, attribute) ?: empty;
additions = g_value_array_new(0);
deletions = g_value_array_new(0);
attribute = (char *)map_to_ldap(ent->cache, attribute);
/* Create a pair of modification request structures,
* using the LDAP name for the attribute, using
* elements from the first array which aren't in the
* second for the remove list, and elements which are
* in the second but not the first for the add list. */
for (j = 0; j < current->n_values; j++) {
cvalue = g_value_array_get_nth(current, j);
/* Search for this value in the other array. */
for (k = 0; k < pending->n_values; k++) {
pvalue = g_value_array_get_nth(pending,
k);
if (G_VALUE_TYPE(cvalue)
== G_VALUE_TYPE(pvalue)
&& lu_values_equal(cvalue, pvalue))
break;
}
/* If not found, it's a mod. */
if (k >= pending->n_values)
/* Delete this value. */
g_value_array_append(deletions, cvalue);
}
/* If we have deletions, create an LDAPMod structure
* containing them. */
if (deletions->n_values != 0) {
mod = g_malloc0(sizeof(*mod));
mod->mod_op = LDAP_MOD_DELETE;
mod->mod_type = attribute;
mod->mod_values
= g_malloc0((deletions->n_values + 1)
* sizeof(*mod->mod_values));
for (j = 0; j < deletions->n_values; j++) {
value = g_value_array_get_nth(deletions, j);
mod->mod_values[j]
= lu_value_strdup(value);
}
mods[mod_count++] = mod;
}
/* Now extract additions. */
for (j = 0; j < pending->n_values; j++) {
pvalue = g_value_array_get_nth(pending, j);
/* Search for this value in the other array. */
for (k = 0; k < current->n_values; k++) {
cvalue = g_value_array_get_nth(current,
k);
if (G_VALUE_TYPE(cvalue)
== G_VALUE_TYPE(pvalue)
&& lu_values_equal(cvalue, pvalue))
break;
}
/* If not found, it's a mod. */
if (k >= current->n_values)
/* Add this value. */
g_value_array_append(additions, pvalue);
}
/* If we have additions, create an LDAPMod structure
* containing them. */
if (additions->n_values != 0) {
mod = g_malloc0(sizeof(*mod));
mod->mod_op = LDAP_MOD_ADD;
mod->mod_type = attribute;
mod->mod_values
= g_malloc0((additions->n_values + 1)
* sizeof(*mod->mod_values));
for (j = 0; j < additions->n_values; j++) {
value = g_value_array_get_nth(additions, j);
mod->mod_values[j]
= lu_value_strdup(value);
}
mods[mod_count++] = mod;
}
g_value_array_free(additions);
g_value_array_free(deletions);
}
g_value_array_free(empty);
/* We don't need the list of attributes any more. */
g_list_free(attrs);
}
return mods;
}
/* Free a set of modification structures generated by get_ent_mods(). */
static void
free_ent_mods(LDAPMod ** mods)
{
size_t i;
g_assert(mods != NULL);
for (i = 0; mods && mods[i]; i++) {
if (mods[i]->mod_values) {
size_t j;
for (j = 0; mods[i]->mod_values[j] != NULL; j++) {
g_free(mods[i]->mod_values[j]);
}
g_free(mods[i]->mod_values);
}
g_free(mods[i]);
}
g_free(mods);
}
#ifdef DEBUG
/* Dump out the modifications structure. For debugging only. */
static void
dump_mods(LDAPMod ** mods)
{
size_t i;
if (mods == NULL) {
g_print("NULL modifications");
return;
}
for (i = 0; mods[i]; i++) {
g_print("%s (%d)\n", mods[i]->mod_type, mods[i]->mod_op);
if (mods[i]->mod_values) {
size_t j;
for (j = 0; mods[i]->mod_values[j]; j++) {
g_print(" = `%s'\n",
mods[i]->mod_values[j]);
}
}
}
}
#endif /* DEBUG */
/* Add an entity's LDAP object to the proper object classes to allow the
* user to possess the attributes she needs to. */
static void
lu_ldap_fudge_objectclasses(struct lu_ldap_context *ctx,
const char *dn,
struct lu_ent *ent)
{
static char *attrs[] = {
OBJECTCLASS,
NULL,
};
BerValue **old_values, **new_values;
LDAPMessage *res = NULL;
LDAPMessage *entry;
/* Pull up this object's entry. */
if (ldap_search_ext_s(ctx->ldap, dn, LDAP_SCOPE_BASE, NULL, attrs,
FALSE, NULL, NULL, NULL, LDAP_NO_LIMIT, &res)
!= LDAP_SUCCESS) {
return;
}
entry = ldap_first_entry(ctx->ldap, res);
if (entry == NULL) {
ldap_msgfree(res);
return;
}
/* Get the list of object classes the object is in now. */
old_values = ldap_get_values_len(ctx->ldap, entry, OBJECTCLASS);
new_values = lu_ldap_needed_objectclasses(dn, ent, old_values);
if (new_values != NULL) {
int err;
LDAPMod mod;
LDAPMod *mods[] = { &mod, NULL };
#ifdef DEBUG
g_print("Adding user `%s' to new classes.\n", dn);
#endif
/* Set up the modify request. */
memset(&mod, 0, sizeof(mod));
mod.mod_op = LDAP_MOD_ADD | LDAP_MOD_BVALUES;
mod.mod_type = OBJECTCLASS;
mod.mod_bvalues = new_values;
/* Give it the old try. */
#ifdef DEBUG
dump_mods(mods);
#endif
err = ldap_modify_ext_s(ctx->ldap, dn, mods, NULL, NULL);
#ifdef DEBUG
g_message("Fudged: `%s'.\n", ldap_err2string(err));
#endif
free_needed_objectclasses(new_values);
}
ldap_value_free_len(old_values);
ldap_msgfree(res);
}
/* Apply the changes to a given entity structure, or add a new entitty. */
static gboolean
lu_ldap_set(struct lu_module *module, enum lu_entity_type type, int add,
struct lu_ent *ent, const char *branch, struct lu_error **error)
{
LDAPMod **mods;
GValueArray *name, *old_name;
GValue *value;
char *name_string;
const char *dn, *namingAttr;
int err;
gboolean ret;
struct lu_ldap_context *ctx;
g_assert(module != NULL);
g_assert((type == lu_user) || (type == lu_group));
g_assert(ent != NULL);
g_assert(ent->magic == LU_ENT_MAGIC);
LU_ERROR_CHECK(error);
ctx = module->module_context;
/* Get the user/group's pending name, which may be different from the
* current name. If so, we want to change it seperately, because it
* requires a renaming of the object in the directory. */
if (type == lu_user)
namingAttr = LU_USERNAME;
else
namingAttr = LU_GROUPNAME;
name = lu_ent_get(ent, namingAttr);
if (name == NULL) {
lu_error_new(error, lu_error_generic,
_("user object had no %s attribute"),
namingAttr);
return FALSE;
}
/* Get the object's old (current) name. */
old_name = lu_ent_get_current(ent, namingAttr);
if (old_name == NULL) {
lu_error_new(error, lu_error_generic,
_("user object was created with no `%s'"),
namingAttr);
return FALSE;
}
/* Get the object's current object name. */
value = g_value_array_get_nth(add ? name : old_name, 0);
name_string = lu_value_strdup(value);
dn = lu_ldap_ent_to_dn(module, namingAttr, name_string, branch);
g_free(name_string);
if (add) {
mods = get_ent_adds(dn, ent);
#ifdef DEBUG
dump_mods(mods);
g_message("Adding `%s'.\n", dn);
#endif
err = ldap_add_ext_s(ctx->ldap, dn, mods, NULL, NULL);
if (err != LDAP_SUCCESS) {
lu_error_new(error, lu_error_write,
_("error creating a LDAP directory "
"entry: %s"), ldap_err2string(err));
ret = FALSE;
goto err_mods;
}
} else {
mods = get_ent_mods(ent, namingAttr);
#ifdef DEBUG
dump_mods(mods);
g_message("Modifying `%s'.\n", dn);
#endif
/* Attempt the modify operation. The Fedora Directory server
rejects modify operations with no modifications. */
if (mods != NULL && mods[0] != NULL) {
err = ldap_modify_ext_s(ctx->ldap, dn, mods, NULL,
NULL);
if (err == LDAP_OBJECT_CLASS_VIOLATION) {
/* AAAARGH! The application decided it wanted
* to add some new attributes! Damage
* control.... */
lu_ldap_fudge_objectclasses(ctx, dn, ent);
err = ldap_modify_ext_s(ctx->ldap, dn, mods,
NULL, NULL);
}
if (err != LDAP_SUCCESS) {
lu_error_new(error, lu_error_write,
_("error modifying LDAP "
"directory entry: %s"),
ldap_err2string(err));
ret = FALSE;
goto err_mods;
}
}
/* If the name has changed, process a rename (modrdn). */
if (arrays_equal(name, old_name) == FALSE) {
char *tmp1, *tmp2;
/* Format the name to rename it to. */
value = g_value_array_get_nth(name, 0);
tmp1 = lu_value_strdup(value);
tmp2 = g_strconcat(map_to_ldap(module->scache,
namingAttr), "=",
tmp1, NULL);
g_free (tmp1);
/* Attempt the rename. */
err = ldap_rename_s(ctx->ldap, dn, tmp2, NULL, TRUE,
NULL, NULL);
g_free(tmp2);
if (err != LDAP_SUCCESS) {
lu_error_new(error, lu_error_write,
_("error renaming LDAP directory "
"entry: %s"),
ldap_err2string(err));
ret = FALSE;
goto err_mods;
}
}
}
ret = TRUE;
err_mods:
free_ent_mods(mods);
return ret;
}
/* Remove an entry from the directory. */
static gboolean
lu_ldap_del(struct lu_module *module, enum lu_entity_type type,
struct lu_ent *ent, const char *branch, struct lu_error **error)
{
GValueArray *name;
GValue *value;
char *name_string;
const char *dn, *namingAttr;
int err;
gboolean ret = FALSE;
struct lu_ldap_context *ctx;
g_assert(module != NULL);
g_assert((type == lu_user) || (type == lu_group));
g_assert(ent != NULL);
g_assert(ent->magic == LU_ENT_MAGIC);
LU_ERROR_CHECK(error);
ctx = module->module_context;
/* Get the user or group's name. */
if (type == lu_user) {
namingAttr = LU_USERNAME;
} else {
namingAttr = LU_GROUPNAME;
}
name = lu_ent_get(ent, namingAttr);
if (name == NULL) {
lu_error_new(error, lu_error_generic,
_("object had no %s attribute"), namingAttr);
return FALSE;
}
/* Convert the name to a distinguished name. */
value = g_value_array_get_nth(name, 0);
name_string = lu_value_strdup(value);
dn = lu_ldap_ent_to_dn(module, namingAttr, name_string, branch);
g_free(name_string);
/* Process the removal. */
#ifdef DEBUG
g_message("Removing `%s'.\n", dn);
#endif
err = ldap_delete_ext_s(ctx->ldap, dn, NULL, NULL);
if (err == LDAP_SUCCESS) {
ret = TRUE;
} else {
lu_error_new(error, lu_error_write,
_("error removing LDAP directory entry: %s"),
ldap_err2string(err));
return FALSE;
}
return ret;
}
/* Lock an account of some kind. */
static gboolean
lu_ldap_handle_lock(struct lu_module *module, struct lu_ent *ent,
const char *namingAttr, enum lock_op op,
const char *branch, struct lu_error **error)
{
const char *dn;
gboolean ret = FALSE;
LDAPMod mod[2], *mods[3];
GValueArray *name, *password;
GValue *value;
char *result, *name_string, *oldpassword, *values[2][2];
const char *tmp, *attribute;
struct lu_ldap_context *ctx;
int err;
g_assert(module != NULL);
g_assert(ent != NULL);
g_assert(namingAttr != NULL);
g_assert(strlen(namingAttr) > 0);
LU_ERROR_CHECK(error);
ctx = module->module_context;
/* Get the entry's name. */
name = lu_ent_get(ent, namingAttr);
if (name == NULL) {
lu_error_new(error, lu_error_generic,
_("object has no %s attribute"), namingAttr);
return FALSE;
}
/* Convert the name to a distinguished name. */
value = g_value_array_get_nth(name, 0);
name_string = lu_value_strdup(value);
dn = lu_ldap_ent_to_dn(module, namingAttr, name_string, branch);
g_free(name_string);
attribute = ent->type == lu_user ? LU_USERPASSWORD : LU_GROUPPASSWORD;
/* Get the values for the entry's password. */
password = lu_ent_get_current(ent, attribute);
if (password == NULL) {
lu_error_new(error, lu_error_generic,
_("object has no %s attribute"),
LU_USERPASSWORD);
return FALSE;
}
value = g_value_array_get_nth(password, 0);
oldpassword = lu_value_strdup(value);
/* We only know how to lock crypted passwords, so crypt it if it
* isn't already. */
if (!g_str_has_prefix(oldpassword, LU_CRYPTED)) {
char *salt;
salt = lu_util_default_salt_specifier(module->lu_context);
tmp = lu_make_crypted(oldpassword, salt);
g_free(salt);
if (tmp == NULL) {
lu_error_new(error, lu_error_generic,
_("error encrypting password"));
g_free(oldpassword);
return FALSE;
}
} else
tmp = ent->cache->cache(ent->cache,
oldpassword + strlen(LU_CRYPTED));
result = ent->cache->cache(ent->cache, tmp);
/* Generate a new string with the modification applied. */
switch (op) {
case LO_LOCK:
if (result[0] != LOCKCHAR)
result = g_strdup_printf("%s%c%s", LU_CRYPTED,
LOCKCHAR, result);
else
result = g_strconcat(LU_CRYPTED, result,
(const gchar *)NULL);
break;
case LO_UNLOCK_NONEMPTY:
if (result[0] == LOCKCHAR && result[1] == '\0') {
lu_error_new(error, lu_error_unlock_empty, NULL);
g_free(oldpassword);
return FALSE;
}
/* Fall through */
case LO_UNLOCK:
if (result[0] == LOCKCHAR)
result = g_strconcat(LU_CRYPTED, result + 1,
(const gchar *)NULL);
else
result = g_strconcat(LU_CRYPTED, result,
(const gchar *)NULL);
break;
default:
g_assert_not_reached();
}
/* Set up the LDAP modify operation. */
mod[0].mod_op = LDAP_MOD_DELETE;
mod[0].mod_type = (char *)map_to_ldap(ent->cache, attribute);
values[0][0] = ent->cache->cache(ent->cache, oldpassword);
values[0][1] = NULL;
mod[0].mod_values = values[0];
mod[1].mod_op = LDAP_MOD_ADD;
mod[1].mod_type = mod[0].mod_type;
values[1][0] = ent->cache->cache(ent->cache, result);
values[1][1] = NULL;
mod[1].mod_values = values[1];
g_free(result);
/* Set up the array to pass to the modification routines. */
mods[0] = &mod[0];
mods[1] = &mod[1];
mods[2] = NULL;
err = ldap_modify_ext_s(ctx->ldap, dn, mods, NULL, NULL);
if (err == LDAP_SUCCESS) {
ret = TRUE;
} else {
lu_error_new(error, lu_error_write,
_("error modifying LDAP directory entry: %s"),
ldap_err2string(err));
ret = FALSE;
}
g_free(oldpassword);
return ret;
}
/* Check if an account is locked. */
static gboolean
lu_ldap_is_locked(struct lu_module *module, struct lu_ent *ent,
const char *namingAttr, const char *branch,
struct lu_error **error)
{
static const char mapped_password[] = "userPassword";
const char *dn;
GValueArray *name;
GValue *value;
char *name_string;
struct lu_ldap_context *ctx = module->module_context;
char *attributes[] = { NULL, NULL };
BerValue **values;
LDAPMessage *entry = NULL, *messages = NULL;
int i;
gboolean locked;
/* Get the name of the user or group. */
name = lu_ent_get(ent, namingAttr);
if (name == NULL) {
lu_error_new(error, lu_error_generic,
_("object has no %s attribute"), namingAttr);
return FALSE;
}
/* Convert the name to a distinguished name. */
value = g_value_array_get_nth(name, 0);
name_string = lu_value_strdup(value);
dn = lu_ldap_ent_to_dn(module, namingAttr, name_string, branch);
g_free(name_string);
#ifdef DEBUG
g_print("Looking up `%s'.\n", dn);
#endif
/* Read the entry data. */
attributes[0] = (char *)mapped_password;
if (ldap_search_ext_s(ctx->ldap, dn, LDAP_SCOPE_BASE,
ent->type == lu_user
? "("OBJECTCLASS"="POSIXACCOUNT")"
: "("OBJECTCLASS"="POSIXGROUP")", attributes,
FALSE, NULL, NULL, NULL, LDAP_NO_LIMIT,
&messages) == LDAP_SUCCESS) {
entry = ldap_first_entry(ctx->ldap, messages);
}
if (entry == NULL) {
lu_error_new(error, lu_error_generic,
_("no such object in LDAP directory"));
return FALSE;
}
/* Read the values for the attribute we want to change. */
values = ldap_get_values_len(ctx->ldap, entry, mapped_password);
if (values == NULL) {
ldap_msgfree(messages);
#ifdef DEBUG
g_print("No `%s' attribute found for entry.", mapped_password);
#endif
lu_error_new(error, lu_error_generic,
_("no `%s' attribute found"), mapped_password);
return FALSE;
}
/* Check any of the possibly-multiple passwords. */
locked = FALSE;
for (i = 0; values[i] != NULL; i++) {
const BerValue *val;
size_t prefix_len;
val = values[i];
prefix_len = strlen(LU_CRYPTED);
#ifdef DEBUG
g_print("Got `%s' = `.*%s'.\n", mapped_password,
(int)val->bv_len, val->bv_val);
#endif
if (val->bv_len >= prefix_len
&& memcmp(val->bv_val, LU_CRYPTED, prefix_len) == 0) {
locked = (val->bv_len > prefix_len
&& val->bv_val[prefix_len] == LOCKCHAR);
break;
}
}
/* Clean up and return. */
ldap_value_free_len(values);
if (messages != NULL) {
ldap_msgfree(messages);
}
return locked;
}
/* Set the password for an account. */
static gboolean
lu_ldap_setpass(struct lu_module *module, const char *namingAttr,
struct lu_ent *ent, const char *branch,
const char *password, struct lu_error **error)
{
static const char mapped_password[] = "userPassword";
const char *dn;
GValueArray *name;
GValue *value;
char *name_string;
struct lu_ldap_context *ctx = module->module_context;
char *attributes[] = { NULL, NULL };
char *addvalues[] = { NULL, NULL }, *rmvalues[] = { NULL, NULL };
BerValue **values;
char *previous;
int i;
size_t j;
LDAPMessage *messages = NULL;
LDAPMod addmod, rmmod;
LDAPMod *mods[3];
char filter[LINE_MAX];
/* Get the user or group's name. */
#ifdef DEBUG
g_print("Setting password to `%s'.\n", password);
#endif
name = lu_ent_get(ent, namingAttr);
if (name == NULL) {
lu_error_new(error, lu_error_generic,
_("object has no %s attribute"), namingAttr);
return FALSE;
}
/* Convert the name to a distinguished name. */
value = g_value_array_get_nth(name, 0);
name_string = lu_value_strdup(value);
dn = lu_ldap_ent_to_dn(module, namingAttr, name_string, branch);
#ifdef DEBUG
g_print("Setting password for `%s'.\n", dn);
#endif
snprintf(filter, sizeof(filter), "(%s=%s)",
map_to_ldap(module->scache, namingAttr), name_string);
g_free(name_string);
previous = NULL;
values = NULL;
attributes[0] = (char *)mapped_password;
i = ldap_search_ext_s(ctx->ldap, dn, LDAP_SCOPE_BASE, filter,
attributes, FALSE, NULL, NULL, NULL,
LDAP_NO_LIMIT, &messages);
if (i == LDAP_SUCCESS) {
LDAPMessage *entry;
entry = ldap_first_entry(ctx->ldap, messages);
if (entry != NULL) {
values = ldap_get_values_len(ctx->ldap, entry,
mapped_password);
if (values) {
for (j = 0; values[j] != NULL; j++) {
char *val;
val = g_strndup(values[j]->bv_val,
values[j]->bv_len);
#ifdef DEBUG
g_print("Got `%s' = `%s'.\n",
mapped_password, val);
#endif
if (g_str_has_prefix(val,
LU_CRYPTED)) {
#ifdef DEBUG
g_print
("Previous entry was `%s'.\n",
val);
#endif
previous = val;
break;
}
g_free(val);
}
ldap_value_free_len(values);
}
}
} else {
#ifdef DEBUG
g_print("Error searching LDAP directory for `%s': %s.\n",
dn, ldap_err2string(i));
#endif
}
if (messages != NULL) {
ldap_msgfree(messages);
}
if (g_str_has_prefix(password, LU_CRYPTED))
addvalues[0] = (char *)password;
else {
const char *crypted;
char *salt, *tmp;
if (previous != NULL)
salt = previous + strlen(LU_CRYPTED);
else
salt = lu_util_default_salt_specifier(module
->lu_context);
crypted = lu_make_crypted(password, salt);
if (previous == NULL)
g_free(salt);
if (crypted == NULL) {
lu_error_new(error, lu_error_generic,
_("error encrypting password"));
g_free(previous);
return FALSE;
}
tmp = g_strconcat(LU_CRYPTED, crypted, NULL);
addvalues[0] = module->scache->cache(module->scache, tmp);
g_free(tmp);
}
j = 0;
if (values != NULL) {
if (previous)
rmvalues[0] = previous;
/* else deletes all values */
rmmod.mod_op = LDAP_MOD_DELETE;
rmmod.mod_type = (char *)mapped_password;
rmmod.mod_values = rmvalues;
mods[j++] = &rmmod;
}
addmod.mod_op = LDAP_MOD_ADD;
addmod.mod_type = (char *)mapped_password;
addmod.mod_values = addvalues;
mods[j++] = &addmod;
mods[j] = NULL;
i = ldap_modify_ext_s(ctx->ldap, dn, mods, NULL, NULL);
g_free(previous);
if (i != LDAP_SUCCESS) {
lu_error_new(error, lu_error_generic,
_
("error setting password in LDAP directory for %s: %s"),
dn, ldap_err2string(i));
return FALSE;
}
return TRUE;
}
static gboolean
lu_ldap_user_removepass(struct lu_module *module, struct lu_ent *ent,
struct lu_error **error)
{
struct lu_ldap_context *ctx;
LU_ERROR_CHECK(error);
ctx = module->module_context;
return lu_ldap_setpass(module, LU_USERNAME, ent, ctx->user_branch,
LU_CRYPTED, error);
}
static gboolean
lu_ldap_group_removepass(struct lu_module *module, struct lu_ent *ent,
struct lu_error **error)
{
struct lu_ldap_context *ctx;
LU_ERROR_CHECK(error);
ctx = module->module_context;
return lu_ldap_setpass(module, LU_GROUPNAME, ent, ctx->group_branch,
LU_CRYPTED, error);
}
static GValueArray *
lu_ldap_enumerate(struct lu_module *module,
const char *searchAttr, const char *pattern,
const char *returnAttr, const char *branch,
struct lu_error **error)
{
LDAPMessage *messages = NULL;
char *base, *filt;
GValue value;
GValueArray *ret;
struct lu_ldap_context *ctx;
char *attributes[] = { (char *) returnAttr, NULL };
g_assert(module != NULL);
g_assert(searchAttr != NULL);
g_assert(strlen(searchAttr) > 0);
g_assert(returnAttr != NULL);
g_assert(strlen(returnAttr) > 0);
LU_ERROR_CHECK(error);
ctx = module->module_context;
/* Generate the base DN to search under. */
/* FIXME: this is inconsistent with lu_ldap_base() usage elsewhere */
base = g_strdup_printf("%s,%s", branch,
ctx->prompts[LU_LDAP_BASEDN].value &&
strlen(ctx->prompts[LU_LDAP_BASEDN].value) ?
ctx->prompts[LU_LDAP_BASEDN].value : "*");
/* Generate the filter to search with. */
filt = g_strdup_printf("(%s=%s)", searchAttr, pattern ?: "*");
#ifdef DEBUG
g_print("Looking under `%s' with filter `%s'.\n", base, filt);
#endif
/* Perform the search. */
ret = g_value_array_new(0);
memset(&value, 0, sizeof(value));
g_value_init(&value, G_TYPE_STRING);
if (ldap_search_ext_s(ctx->ldap, base, LDAP_SCOPE_SUBTREE, filt,
attributes, FALSE, NULL, NULL, NULL,
LDAP_NO_LIMIT, &messages) == LDAP_SUCCESS) {
LDAPMessage *entry;
entry = ldap_first_entry(ctx->ldap, messages);
if (entry != NULL) {
while (entry != NULL) {
BerValue **values;
size_t i;
values = ldap_get_values_len(ctx->ldap, entry,
returnAttr);
for (i = 0;
(values != NULL) && (values[i] != NULL);
i++) {
char *val;
val = g_strndup(values[i]->bv_val,
values[i]->bv_len);
#ifdef DEBUG
g_print("Got `%s' = `%s'.\n",
returnAttr, val);
#endif
g_value_take_string(&value, val);
g_value_array_append(ret, &value);
}
ldap_value_free_len(values);
entry = ldap_next_entry(ctx->ldap, entry);
}
#ifdef DEBUG
} else {
g_print("No such entry found in LDAP, continuing.\n");
#endif
}
}
if (messages != NULL) {
ldap_msgfree(messages);
}
g_value_unset(&value);
g_free(base);
g_free(filt);
return ret;
}
/* Add a user to the directory. */
static gboolean
lu_ldap_user_add_prep(struct lu_module *module, struct lu_ent *ent,
struct lu_error **error)
{
(void)module;
(void)ent;
(void)error;
return TRUE;
}
static gboolean
lu_ldap_user_add(struct lu_module *module, struct lu_ent *ent,
struct lu_error **error)
{
struct lu_ldap_context *ctx;
LU_ERROR_CHECK(error);
ctx = module->module_context;
return lu_ldap_set(module, lu_user, 1, ent, ctx->user_branch, error);
}
/* Modify a user record in the directory. */
static gboolean
lu_ldap_user_mod(struct lu_module *module, struct lu_ent *ent,
struct lu_error **error)
{
struct lu_ldap_context *ctx;
LU_ERROR_CHECK(error);
ctx = module->module_context;
return lu_ldap_set(module, lu_user, 0, ent, ctx->user_branch, error);
}
/* Remove a user from the directory. */
static gboolean
lu_ldap_user_del(struct lu_module *module, struct lu_ent *ent,
struct lu_error **error)
{
struct lu_ldap_context *ctx;
LU_ERROR_CHECK(error);
ctx = module->module_context;
return lu_ldap_del(module, lu_user, ent, ctx->user_branch, error);
}
/* Lock a user account in the directory. */
static gboolean
lu_ldap_user_lock(struct lu_module *module, struct lu_ent *ent,
struct lu_error **error)
{
struct lu_ldap_context *ctx;
LU_ERROR_CHECK(error);
ctx = module->module_context;
return lu_ldap_handle_lock(module, ent, LU_USERNAME, LO_LOCK,
ctx->user_branch, error);
}
/* Unlock a user account in the directory. */
static gboolean
lu_ldap_user_unlock(struct lu_module *module, struct lu_ent *ent,
struct lu_error **error)
{
struct lu_ldap_context *ctx;
LU_ERROR_CHECK(error);
ctx = module->module_context;
return lu_ldap_handle_lock(module, ent, LU_USERNAME, LO_UNLOCK,
ctx->user_branch, error);
}
static gboolean
lu_ldap_user_unlock_nonempty(struct lu_module *module, struct lu_ent *ent,
struct lu_error **error)
{
struct lu_ldap_context *ctx;
LU_ERROR_CHECK(error);
ctx = module->module_context;
return lu_ldap_handle_lock(module, ent, LU_USERNAME,
LO_UNLOCK_NONEMPTY, ctx->user_branch,
error);
}
/* Check if a user account in the directory is locked. */
static gboolean
lu_ldap_user_is_locked(struct lu_module *module, struct lu_ent *ent,
struct lu_error **error)
{
struct lu_ldap_context *ctx;
LU_ERROR_CHECK(error);
ctx = module->module_context;
return lu_ldap_is_locked(module, ent, LU_USERNAME, ctx->user_branch,
error);
}
/* Set a user's password in the directory. */
static gboolean
lu_ldap_user_setpass(struct lu_module *module, struct lu_ent *ent,
const char *password, struct lu_error **error)
{
struct lu_ldap_context *ctx;
LU_ERROR_CHECK(error);
ctx = module->module_context;
return lu_ldap_setpass(module, LU_USERNAME, ent, ctx->user_branch,
password, error);
}
/* Add a group entry to the directory. */
static gboolean
lu_ldap_group_add_prep(struct lu_module *module, struct lu_ent *ent,
struct lu_error **error)
{
(void)module;
(void)ent;
(void)error;
return TRUE;
}
static gboolean
lu_ldap_group_add(struct lu_module *module, struct lu_ent *ent,
struct lu_error **error)
{
struct lu_ldap_context *ctx;
LU_ERROR_CHECK(error);
ctx = module->module_context;
return lu_ldap_set(module, lu_group, 1, ent, ctx->group_branch, error);
}
/* Modify a group entry in the directory. */
static gboolean
lu_ldap_group_mod(struct lu_module *module, struct lu_ent *ent,
struct lu_error **error)
{
struct lu_ldap_context *ctx;
LU_ERROR_CHECK(error);
ctx = module->module_context;
return lu_ldap_set(module, lu_group, 0, ent, ctx->group_branch, error);
}
/* Remove a group entry from the directory. */
static gboolean
lu_ldap_group_del(struct lu_module *module, struct lu_ent *ent,
struct lu_error **error)
{
struct lu_ldap_context *ctx;
LU_ERROR_CHECK(error);
ctx = module->module_context;
return lu_ldap_del(module, lu_group, ent, ctx->group_branch, error);
}
/* Lock a group account in the directory. */
static gboolean
lu_ldap_group_lock(struct lu_module *module, struct lu_ent *ent,
struct lu_error **error)
{
struct lu_ldap_context *ctx;
LU_ERROR_CHECK(error);
ctx = module->module_context;
return lu_ldap_handle_lock(module, ent, LU_GROUPNAME, LO_LOCK,
ctx->group_branch, error);
}
/* Unlock a group account in the directory. */
static gboolean
lu_ldap_group_unlock(struct lu_module *module, struct lu_ent *ent,
struct lu_error **error)
{
struct lu_ldap_context *ctx;
LU_ERROR_CHECK(error);
ctx = module->module_context;
return lu_ldap_handle_lock(module, ent, LU_GROUPNAME, LO_UNLOCK,
ctx->group_branch, error);
}
static gboolean
lu_ldap_group_unlock_nonempty(struct lu_module *module, struct lu_ent *ent,
struct lu_error **error)
{
struct lu_ldap_context *ctx;
LU_ERROR_CHECK(error);
ctx = module->module_context;
return lu_ldap_handle_lock(module, ent, LU_GROUPNAME,
LO_UNLOCK_NONEMPTY, ctx->group_branch,
error);
}
/* Check if a group account in the directory is locked. */
static gboolean
lu_ldap_group_is_locked(struct lu_module *module, struct lu_ent *ent,
struct lu_error **error)
{
struct lu_ldap_context *ctx;
LU_ERROR_CHECK(error);
ctx = module->module_context;
return lu_ldap_is_locked(module, ent, LU_GROUPNAME, ctx->group_branch,
error);
}
/* Set a group's password in the directory. */
static gboolean
lu_ldap_group_setpass(struct lu_module *module, struct lu_ent *ent,
const char *password, struct lu_error **error)
{
struct lu_ldap_context *ctx;
LU_ERROR_CHECK(error);
ctx = module->module_context;
return lu_ldap_setpass(module, LU_GROUPNAME, ent, ctx->group_branch,
password, error);
}
/* Populate user or group structures with the proper defaults. */
static gboolean
lu_ldap_user_default(struct lu_module *module,
const char *user, gboolean is_system,
struct lu_ent *ent, struct lu_error **error)
{
return lu_common_user_default(module, user, is_system, ent, error) &&
lu_common_suser_default(module, user, is_system, ent, error);
}
static gboolean
lu_ldap_group_default(struct lu_module *module,
const char *group, gboolean is_system,
struct lu_ent *ent, struct lu_error **error)
{
return lu_common_group_default(module, group, is_system, ent, error) &&
lu_common_sgroup_default(module, group, is_system, ent, error);
}
/* Get a listing of all user names. */
static GValueArray *
lu_ldap_users_enumerate(struct lu_module *module, const char *pattern,
struct lu_error **error)
{
struct lu_ldap_context *ctx;
LU_ERROR_CHECK(error);
ctx = module->module_context;
return lu_ldap_enumerate(module, "uid", pattern, "uid",
ctx->user_branch, error);
}
static GPtrArray *
lu_ldap_users_enumerate_full(struct lu_module *module, const char *pattern,
struct lu_error **error)
{
struct lu_ldap_context *ctx;
GPtrArray *array = g_ptr_array_new();
LU_ERROR_CHECK(error);
ctx = module->module_context;
lu_ldap_lookup(module, "uid", pattern, NULL, array, ctx->user_branch,
"("OBJECTCLASS"="POSIXACCOUNT")",
lu_ldap_user_attributes, lu_user, error);
return array;
}
/* Get a listing of all group names. */
static GValueArray *
lu_ldap_groups_enumerate(struct lu_module *module, const char *pattern,
struct lu_error **error)
{
struct lu_ldap_context *ctx;
LU_ERROR_CHECK(error);
ctx = module->module_context;
return lu_ldap_enumerate(module, "cn", pattern, "cn",
ctx->group_branch, error);
}
static GPtrArray *
lu_ldap_groups_enumerate_full(struct lu_module *module, const char *pattern,
struct lu_error **error)
{
struct lu_ldap_context *ctx;
GPtrArray *array = g_ptr_array_new();
LU_ERROR_CHECK(error);
ctx = module->module_context;
lu_ldap_lookup(module, "cn", pattern, NULL, array, ctx->group_branch,
"("OBJECTCLASS"="POSIXGROUP")",
lu_ldap_group_attributes, lu_group, error);
return array;
}
/* Get a list of all users in a group, either via their primary or supplemental
* group memberships. */
static GValueArray *
lu_ldap_users_enumerate_by_group(struct lu_module *module,
const char *group, gid_t gid,
struct lu_error **error)
{
struct lu_ldap_context *ctx;
GValueArray *primaries;
GValue *value;
char grp[sizeof (gid) * CHAR_BIT + 1];
size_t i;
LU_ERROR_CHECK(error);
ctx = module->module_context;
sprintf(grp, "%jd", (intmax_t)gid);
primaries = lu_ldap_enumerate(module, "gidNumber", grp, "uid",
ctx->user_branch, error);
if ((error == NULL) || (*error == NULL)) {
GValueArray *secondaries;
secondaries = lu_ldap_enumerate(module, "cn", group,
"memberUid", ctx->group_branch,
error);
for (i = 0; i < secondaries->n_values; i++) {
value = g_value_array_get_nth(secondaries, i);
g_value_array_append(primaries, value);
}
g_value_array_free(secondaries);
}
#ifdef DEBUG
for (i = 0; i < primaries->n_values; i++) {
value = g_value_array_get_nth(primaries, i);
g_print("`%s' contains `%s'\n", group,
g_value_get_string(value));
}
#endif
return primaries;
}
static GPtrArray *
lu_ldap_users_enumerate_by_group_full(struct lu_module *module,
const char *group, gid_t gid,
struct lu_error **error)
{
(void)module;
(void)group;
(void)gid;
(void)error;
return NULL;
}
/* Get a list of all groups to which the user belongs, via either primary or
* supplemental group memberships. */
static GValueArray *
lu_ldap_groups_enumerate_by_user(struct lu_module *module,
const char *user,
uid_t uid,
struct lu_error **error)
{
struct lu_ldap_context *ctx;
GValueArray *primaries, *gids;
GValue *value;
size_t i;
(void)uid;
LU_ERROR_CHECK(error);
ctx = module->module_context;
/* Create an array to hold the values returned. */
primaries = g_value_array_new(0);
/* Get the user's primary GID(s). */
gids = lu_ldap_enumerate(module, "uid", user, "gidNumber",
ctx->user_branch, error);
/* For each GID, look up the group. Which has this GID. */
for (i = 0; (gids != NULL) && (i < gids->n_values); i++) {
gid_t gid;
struct lu_ent *ent;
value = g_value_array_get_nth(gids, i);
gid = lu_value_get_id(value);
g_assert (gid != LU_VALUE_INVALID_ID);
ent = lu_ent_new();
if (lu_group_lookup_id(module->lu_context, gid,
ent, error)) {
GValueArray *values;
size_t j;
/* Get the group's names and add them to the list
* of values to return. */
values = lu_ent_get(ent, LU_GROUPNAME);
for (j = 0; j < values->n_values; j++) {
value = g_value_array_get_nth(values, j);
g_value_array_append(primaries, value);
}
}
lu_ent_free(ent);
}
g_value_array_free(gids);
/* Search for the supplemental groups which list this user as
* a member. */
if ((error == NULL) || (*error == NULL)) {
GValueArray *secondaries;
secondaries = lu_ldap_enumerate(module, "memberUid", user,
"cn", ctx->group_branch,
error);
for (i = 0; i < secondaries->n_values; i++) {
value = g_value_array_get_nth(secondaries, i);
g_value_array_append(primaries, value);
}
g_value_array_free(secondaries);
}
#ifdef DEBUG
for (i = 0; i < primaries->n_values; i++) {
value = g_value_array_get_nth(primaries, i);
g_print("`%s' is in `%s'\n", user,
g_value_get_string(value));
}
#endif
return primaries;
}
static GPtrArray *
lu_ldap_groups_enumerate_by_user_full(struct lu_module *module,
const char *user, uid_t uid,
struct lu_error **error)
{
(void)module;
(void)user;
(void)uid;
(void)error;
return NULL;
}
static gboolean
lu_ldap_close_module(struct lu_module *module)
{
struct lu_ldap_context *ctx;
size_t i;
g_assert(module != NULL);
ctx = module->module_context;
close_server(ctx->ldap);
module->scache->free(module->scache);
for (i = 0; i < sizeof(ctx->prompts) / sizeof(ctx->prompts[0]);
i++) {
if (ctx->prompts[i].value && ctx->prompts[i].free_value) {
ctx->prompts[i].free_value(ctx->prompts[i].value);
}
}
g_free(ctx->sasl_mechanism);
g_free(ctx->mapped_user_attributes);
g_free(ctx->mapped_group_attributes);
g_free(ctx);
memset(module, 0, sizeof(struct lu_module));
g_free(module);
return TRUE;
}
static gboolean
lu_ldap_uses_elevated_privileges(struct lu_module *module)
{
(void)module;
/* FIXME: do some checking, don't know what we need, though */
return FALSE;
}
struct lu_module *
libuser_ldap_init(struct lu_context *context, struct lu_error **error)
{
struct lu_module *ret;
struct lu_ldap_context *ctx;
struct lu_prompt prompts[G_N_ELEMENTS(ctx->prompts)];
const char *bind_type;
char **bind_types;
size_t i;
LDAP *ldap;
g_assert(context != NULL);
g_assert(context->prompter != NULL);
LU_ERROR_CHECK(error);
ctx = g_malloc0(sizeof(struct lu_ldap_context));
ctx->global_context = context;
/* Initialize the prompts structure. */
ctx->prompts[LU_LDAP_SERVER].key = "ldap/server";
ctx->prompts[LU_LDAP_SERVER].prompt = N_("LDAP Server Name");
ctx->prompts[LU_LDAP_SERVER].default_value =
lu_cfg_read_single(context, "ldap/server", "ldap");
ctx->prompts[LU_LDAP_SERVER].visible = TRUE;
ctx->prompts[LU_LDAP_BASEDN].key = "ldap/basedn";
ctx->prompts[LU_LDAP_BASEDN].prompt = N_("LDAP Search Base DN");
ctx->prompts[LU_LDAP_BASEDN].default_value =
lu_cfg_read_single(context, "ldap/basedn", "dc=example,dc=com");
ctx->prompts[LU_LDAP_BASEDN].visible = TRUE;
ctx->prompts[LU_LDAP_BINDDN].key = "ldap/binddn";
ctx->prompts[LU_LDAP_BINDDN].prompt = N_("LDAP Bind DN");
ctx->prompts[LU_LDAP_BINDDN].visible = TRUE;
ctx->prompts[LU_LDAP_BINDDN].default_value =
lu_cfg_read_single(context, "ldap/binddn",
"cn=manager,dc=example,dc=com");
ctx->prompts[LU_LDAP_PASSWORD].key = "ldap/password";
ctx->prompts[LU_LDAP_PASSWORD].prompt = N_("LDAP Bind Password");
ctx->prompts[LU_LDAP_PASSWORD].visible = FALSE;
ctx->prompts[LU_LDAP_AUTHUSER].key = "ldap/user";
ctx->prompts[LU_LDAP_AUTHUSER].prompt = N_("LDAP SASL User");
ctx->prompts[LU_LDAP_AUTHUSER].visible = TRUE;
ctx->prompts[LU_LDAP_AUTHUSER].default_value =
lu_cfg_read_single(context, "ldap/user", "");
ctx->prompts[LU_LDAP_AUTHZUSER].key = "ldap/authuser";
ctx->prompts[LU_LDAP_AUTHZUSER].prompt =
N_("LDAP SASL Authorization User");
ctx->prompts[LU_LDAP_AUTHZUSER].visible = TRUE;
ctx->prompts[LU_LDAP_AUTHZUSER].default_value =
lu_cfg_read_single(context, "ldap/authuser", "");
/* Try to be somewhat smart and allow the user to specify which bind
* type to use, which should prevent us from asking for information
* we can be certain we don't have a use for. */
bind_type = lu_cfg_read_single(context, "ldap/bindtype", "simple,sasl");
bind_types = g_strsplit(bind_type, ",", 0);
for (i = 0; (bind_types != NULL) && (bind_types[i] != NULL); i++) {
if (g_ascii_strcasecmp(bind_types[i], "simple") == 0) {
ctx->bind_simple = TRUE;
} else
if (g_ascii_strcasecmp(bind_types[i], "sasl") == 0) {
ctx->bind_sasl = TRUE;
ctx->sasl_mechanism = NULL;
}
if (g_ascii_strncasecmp(bind_types[i], "sasl/", 5) == 0) {
ctx->bind_sasl = TRUE;
ctx->sasl_mechanism = g_strdup(bind_types[i] + 5);
}
}
g_strfreev(bind_types);
/* Get the information we're sure we'll need. */
i = 0;
prompts[i++] = ctx->prompts[LU_LDAP_SERVER];
prompts[i++] = ctx->prompts[LU_LDAP_BASEDN];
if (ctx->bind_simple) {
prompts[i++] = ctx->prompts[LU_LDAP_BINDDN];
prompts[i++] = ctx->prompts[LU_LDAP_PASSWORD];
}
if (ctx->bind_sasl) {
prompts[i++] = ctx->prompts[LU_LDAP_AUTHUSER];
prompts[i++] = ctx->prompts[LU_LDAP_AUTHZUSER];
}
if (context->prompter(prompts, i,
context->prompter_data, error) == FALSE) {
g_free(ctx);
return NULL;
}
i = 0;
ctx->prompts[LU_LDAP_SERVER] = prompts[i++];
ctx->prompts[LU_LDAP_BASEDN] = prompts[i++];
if (ctx->bind_simple) {
ctx->prompts[LU_LDAP_BINDDN] = prompts[i++];
ctx->prompts[LU_LDAP_PASSWORD] = prompts[i++];
}
if (ctx->bind_sasl) {
ctx->prompts[LU_LDAP_AUTHUSER] = prompts[i++];
ctx->prompts[LU_LDAP_AUTHZUSER] = prompts[i++];
}
/* Allocate the method structure. */
ret = g_malloc0(sizeof(struct lu_module));
ret->version = LU_MODULE_VERSION;
ret->module_context = ctx;
ret->scache = lu_string_cache_new(TRUE);
ret->name = ret->scache->cache(ret->scache, "ldap");
ctx->module = ret;
ctx->user_branch = lu_cfg_read_single(context, "ldap/userBranch",
USERBRANCH);
ctx->group_branch = lu_cfg_read_single(context, "ldap/groupBranch",
GROUPBRANCH);
/* Try to bind to the server to verify that we can. */
ldap = bind_server(ctx, error);
if (ldap == NULL) {
ret->scache->free(ret->scache);
g_free(ret);
g_free(ctx);
return NULL;
}
ctx->ldap = ldap;
ctx->mapped_user_attributes
= g_malloc0(sizeof(*ctx->mapped_user_attributes)
* G_N_ELEMENTS(lu_ldap_user_attributes));
for (i = 0; i < G_N_ELEMENTS(lu_ldap_user_attributes); i++) {
if (lu_ldap_user_attributes[i] != NULL)
ctx->mapped_user_attributes[i] = (char *)
map_to_ldap(ret->scache,
lu_ldap_user_attributes[i]);
else
ctx->mapped_user_attributes[i] = NULL;
}
ctx->mapped_group_attributes
= g_malloc0(sizeof(*ctx->mapped_group_attributes)
* G_N_ELEMENTS(lu_ldap_group_attributes));
for (i = 0; i < G_N_ELEMENTS(lu_ldap_group_attributes); i++) {
if (lu_ldap_group_attributes[i] != NULL)
ctx->mapped_group_attributes[i] = (char *)
map_to_ldap(ret->scache,
lu_ldap_group_attributes[i]);
else
ctx->mapped_group_attributes[i] = NULL;
}
/* Set the method pointers. */
ret->uses_elevated_privileges = lu_ldap_uses_elevated_privileges;
ret->user_lookup_name = lu_ldap_user_lookup_name;
ret->user_lookup_id = lu_ldap_user_lookup_id;
ret->user_default = lu_ldap_user_default;
ret->user_add_prep = lu_ldap_user_add_prep;
ret->user_add = lu_ldap_user_add;
ret->user_mod = lu_ldap_user_mod;
ret->user_del = lu_ldap_user_del;
ret->user_lock = lu_ldap_user_lock;
ret->user_unlock = lu_ldap_user_unlock;
ret->user_unlock_nonempty = lu_ldap_user_unlock_nonempty;
ret->user_is_locked = lu_ldap_user_is_locked;
ret->user_setpass = lu_ldap_user_setpass;
ret->user_removepass = lu_ldap_user_removepass;
ret->users_enumerate = lu_ldap_users_enumerate;
ret->users_enumerate_by_group = lu_ldap_users_enumerate_by_group;
ret->users_enumerate_full = lu_ldap_users_enumerate_full;
ret->users_enumerate_by_group_full = lu_ldap_users_enumerate_by_group_full;
ret->group_lookup_name = lu_ldap_group_lookup_name;
ret->group_lookup_id = lu_ldap_group_lookup_id;
ret->group_default = lu_ldap_group_default;
ret->group_add_prep = lu_ldap_group_add_prep;
ret->group_add = lu_ldap_group_add;
ret->group_mod = lu_ldap_group_mod;
ret->group_del = lu_ldap_group_del;
ret->group_lock = lu_ldap_group_lock;
ret->group_unlock = lu_ldap_group_unlock;
ret->group_unlock_nonempty = lu_ldap_group_unlock_nonempty;
ret->group_is_locked = lu_ldap_group_is_locked;
ret->group_setpass = lu_ldap_group_setpass;
ret->group_removepass = lu_ldap_group_removepass;
ret->groups_enumerate = lu_ldap_groups_enumerate;
ret->groups_enumerate_by_user = lu_ldap_groups_enumerate_by_user;
ret->groups_enumerate_full = lu_ldap_groups_enumerate_full;
ret->groups_enumerate_by_user_full = lu_ldap_groups_enumerate_by_user_full;
ret->close = lu_ldap_close_module;
/* Done. */
return ret;
}
|