Changeset 988 for vendor/current/nsswitch/wbinfo.c
- Timestamp:
- Nov 24, 2016, 1:14:11 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/current/nsswitch/wbinfo.c
r860 r988 23 23 24 24 #include "includes.h" 25 #include "popt_common.h"26 25 #include "winbind_client.h" 27 26 #include "libwbclient/wbclient.h" 28 #include "lib/popt/popt.h"29 27 #include "../libcli/auth/libcli_auth.h" 30 #if (_SAMBA_BUILD_) >= 431 28 #include "lib/cmdline/popt_common.h" 32 # endif29 #include "lib/afs/afs_settoken.h" 33 30 34 31 #ifdef DBGC_CLASS … … 121 118 if (!p) { 122 119 /* Maybe it was a UPN? */ 123 if ((p = strchr(domuser, '@')) != NULL) { 120 p = strchr(domuser, '@'); 121 if (p != NULL) { 124 122 fstrcpy(domain, ""); 125 123 fstrcpy(user, domuser); … … 135 133 fstrcpy(domain, domuser); 136 134 domain[PTR_DIFF(p, domuser)] = 0; 137 strupper_m(domain);138 135 139 136 return true; … … 243 240 pwd->pw_shell); 244 241 242 wbcFreeMemory(pwd); 243 245 244 return true; 246 245 } … … 520 519 521 520 if (print_all) { 522 d_printf("%-16s%- 24s%-12s%-12s%-5s%-5s\n",521 d_printf("%-16s%-65s%-12s%-12s%-5s%-5s\n", 523 522 "Domain Name", "DNS Domain", "Trust Type", 524 523 "Transitive", "In", "Out"); … … 534 533 } 535 534 536 d_printf("%- 24s", domain_list[i].dns_name);535 d_printf("%-65s", domain_list[i].dns_name); 537 536 538 537 switch(domain_list[i].trust_type) { … … 690 689 /* Send request */ 691 690 692 if (winbindd_request_response( WINBINDD_GETDCNAME, &request,691 if (winbindd_request_response(NULL, WINBINDD_GETDCNAME, &request, 693 692 &response) != NSS_STATUS_SUCCESS) { 694 693 d_fprintf(stderr, "Could not get dc name for %s\n",domain_name); … … 754 753 755 754 if (wbc_status == WBC_ERR_AUTH_ERROR) { 756 d_fprintf(stderr, " error code was %s (0x%x)\n",757 error->nt_string, error->nt_status);755 d_fprintf(stderr, "wbcCheckTrustCredentials(%s): error code was %s (0x%x)\n", 756 domain_name, error->nt_string, error->nt_status); 758 757 wbcFreeMemory(error); 759 758 } … … 813 812 814 813 if (wbc_status == WBC_ERR_AUTH_ERROR) { 815 d_fprintf(stderr, " error code was %s (0x%x)\n",816 error->nt_string, error->nt_status);814 d_fprintf(stderr, "wbcChangeTrustCredentials(%s): error code was %s (0x%x)\n", 815 domain_name, error->nt_string, error->nt_status); 817 816 wbcFreeMemory(error); 818 817 } … … 828 827 /* Check DC connection */ 829 828 830 static bool wbinfo_ping_dc( void)829 static bool wbinfo_ping_dc(const char *domain) 831 830 { 832 831 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; 833 832 struct wbcAuthErrorInfo *error = NULL; 834 835 wbc_status = wbcPingDc(NULL, &error); 836 837 d_printf("checking the NETLOGON dc connection %s\n", 833 char *dcname = NULL; 834 835 const char *domain_name; 836 837 if (domain) { 838 domain_name = domain; 839 } else { 840 domain_name = get_winbind_domain(); 841 } 842 843 wbc_status = wbcPingDc2(domain_name, &error, &dcname); 844 845 d_printf("checking the NETLOGON for domain[%s] dc connection to \"%s\" %s\n", 846 domain_name ? domain_name : "", 847 dcname ? dcname : "", 838 848 WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed"); 839 849 850 wbcFreeMemory(dcname); 840 851 if (wbc_status == WBC_ERR_AUTH_ERROR) { 841 d_fprintf(stderr, " error code was %s (0x%x)\n",842 error->nt_string, error->nt_status);852 d_fprintf(stderr, "wbcPingDc2(%s): error code was %s (0x%x)\n", 853 domain_name, error->nt_string, error->nt_status); 843 854 wbcFreeMemory(error); 855 return false; 844 856 } 845 857 if (!WBC_ERROR_IS_OK(wbc_status)) { … … 1020 1032 d_printf("%s -> gid %d\n", sidstr, unix_ids[i].id.gid); 1021 1033 break; 1034 case WBC_ID_TYPE_BOTH: 1035 d_printf("%s -> uid/gid %d\n", sidstr, unix_ids[i].id.uid); 1036 break; 1022 1037 default: 1023 1038 d_printf("%s -> unmapped\n", sidstr); … … 1218 1233 /* Display response */ 1219 1234 1220 d_printf("%s%c%s %d\n", 1221 domain, winbind_separator(), name, type); 1235 if (type == WBC_SID_NAME_DOMAIN) { 1236 d_printf("%s %d\n", domain, type); 1237 } else { 1238 d_printf("%s%c%s %d\n", 1239 domain, winbind_separator(), name, type); 1240 } 1241 1242 wbcFreeMemory(domain); 1243 wbcFreeMemory(name); 1222 1244 1223 1245 return true; … … 1254 1276 d_printf("%s%c%s %d\n", 1255 1277 domain, winbind_separator(), name, type); 1278 1279 wbcFreeMemory(domain); 1280 wbcFreeMemory(name); 1256 1281 1257 1282 return true; … … 1314 1339 1315 1340 wbc_status = wbcLookupRids(&dinfo->sid, num_rids, rids, 1316 (const char **)&domain_name, &names, &types);1341 &p, &names, &types); 1317 1342 if (!WBC_ERROR_IS_OK(wbc_status)) { 1318 1343 d_printf("winbind_lookup_rids failed: %s\n", … … 1321 1346 } 1322 1347 1348 domain_name = discard_const_p(char, p); 1323 1349 d_printf("Domain: %s\n", domain_name); 1324 1350 … … 1395 1421 if (names[i].type == WBC_SID_NAME_DOMAIN) { 1396 1422 d_printf("%s -> %s %d\n", sidstr, 1397 domain,1398 names[i].type);1423 domain, 1424 names[i].type); 1399 1425 } else { 1400 1426 d_printf("%s -> %s%c%s %d\n", sidstr, 1401 domain, 1402 winbind_separator(), 1403 names[i].name, names[i].type); 1404 } 1405 } 1427 domain, 1428 winbind_separator(), 1429 names[i].name, names[i].type); 1430 } 1431 } 1432 wbcFreeMemory(names); 1433 wbcFreeMemory(domains); 1406 1434 return true; 1407 1435 } … … 1445 1473 { 1446 1474 char *prompt; 1447 const char *ret = NULL; 1475 char buf[1024] = {0}; 1476 int rc; 1448 1477 1449 1478 prompt = talloc_asprintf(mem_ctx, "Enter %s's ", username); … … 1462 1491 } 1463 1492 1464 r et = getpass(prompt);1493 rc = samba_getpass(prompt, buf, sizeof(buf), false, false); 1465 1494 TALLOC_FREE(prompt); 1466 1467 return talloc_strdup(mem_ctx, ret); 1495 if (rc < 0) { 1496 return NULL; 1497 } 1498 1499 return talloc_strdup(mem_ctx, buf); 1468 1500 } 1469 1501 … … 1553 1585 if (error) { 1554 1586 d_fprintf(stderr, 1555 "error code was %s (0x%x)\nerror message was: %s\n", 1556 error->nt_string, 1587 "wbcLogonUser(%s): error code was %s (0x%x)\n" 1588 "error message was: %s\n", 1589 params.username, error->nt_string, 1557 1590 error->nt_status, 1558 1591 error->display_string); … … 1725 1758 if (wbc_status == WBC_ERR_AUTH_ERROR) { 1726 1759 d_fprintf(stderr, 1727 "error code was %s (0x%x)\nerror message was: %s\n", 1760 "wbcAuthenticateUserEx(%s%c%s): error code was %s (0x%x)\n" 1761 "error message was: %s\n", 1762 name_domain, 1763 winbind_separator(), 1764 name_user, 1728 1765 err->nt_string, 1729 1766 err->nt_status, … … 1742 1779 /* Authenticate a user with a plaintext password */ 1743 1780 1744 static bool wbinfo_pam_logon(char *username )1781 static bool wbinfo_pam_logon(char *username, bool verbose) 1745 1782 { 1746 1783 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; 1747 1784 struct wbcLogonUserParams params; 1785 struct wbcLogonUserInfo *info = NULL; 1748 1786 struct wbcAuthErrorInfo *error = NULL; 1749 1787 char *s = NULL; … … 1790 1828 } 1791 1829 1792 wbc_status = wbcLogonUser(¶ms, NULL, &error, NULL); 1830 wbc_status = wbcLogonUser(¶ms, &info, &error, NULL); 1831 1832 if (verbose && (info != NULL)) { 1833 struct wbcAuthUserInfo *i = info->info; 1834 uint32_t j; 1835 1836 if (i->account_name != NULL) { 1837 d_printf("account_name: %s\n", i->account_name); 1838 } 1839 if (i->user_principal != NULL) { 1840 d_printf("user_principal: %s\n", i->user_principal); 1841 } 1842 if (i->full_name != NULL) { 1843 d_printf("full_name: %s\n", i->full_name); 1844 } 1845 if (i->domain_name != NULL) { 1846 d_printf("domain_name: %s\n", i->domain_name); 1847 } 1848 if (i->dns_domain_name != NULL) { 1849 d_printf("dns_domain_name: %s\n", i->dns_domain_name); 1850 } 1851 if (i->logon_server != NULL) { 1852 d_printf("logon_server: %s\n", i->logon_server); 1853 } 1854 if (i->logon_script != NULL) { 1855 d_printf("logon_script: %s\n", i->logon_script); 1856 } 1857 if (i->profile_path != NULL) { 1858 d_printf("profile_path: %s\n", i->profile_path); 1859 } 1860 if (i->home_directory != NULL) { 1861 d_printf("home_directory: %s\n", i->home_directory); 1862 } 1863 if (i->home_drive != NULL) { 1864 d_printf("home_drive: %s\n", i->home_drive); 1865 } 1866 1867 d_printf("sids:"); 1868 1869 for (j=0; j<i->num_sids; j++) { 1870 char buf[WBC_SID_STRING_BUFLEN]; 1871 wbcSidToStringBuf(&i->sids[j].sid, buf, sizeof(buf)); 1872 d_printf(" %s", buf); 1873 } 1874 d_printf("\n"); 1875 1876 wbcFreeMemory(info); 1877 info = NULL; 1878 } 1793 1879 1794 1880 wbcFreeMemory(params.blobs); … … 1799 1885 if (!WBC_ERROR_IS_OK(wbc_status) && (error != NULL)) { 1800 1886 d_fprintf(stderr, 1801 "error code was %s (0x%x)\nerror message was: %s\n", 1887 "wbcLogonUser(%s): error code was %s (0x%x)\n" 1888 "error message was: %s\n", 1889 params.username, 1802 1890 error->nt_string, 1803 1891 (int)error->nt_status, … … 1869 1957 } else { 1870 1958 fstrcpy(request.data.auth.user, username); 1871 fstrcpy(request.data.auth.pass, getpass("Password: ")); 1959 (void) samba_getpass("Password: ", 1960 request.data.auth.pass, 1961 sizeof(request.data.auth.pass), 1962 false, false); 1872 1963 } 1873 1964 1874 1965 request.flags |= WBFLAG_PAM_AFS_TOKEN; 1875 1966 1876 result = winbindd_request_response( WINBINDD_PAM_AUTH, &request,1967 result = winbindd_request_response(NULL, WINBINDD_PAM_AUTH, &request, 1877 1968 &response); 1878 1969 … … 1924 2015 /* Send request to winbind daemon */ 1925 2016 1926 /* '.' is the special sign for our own domain */ 1927 if (domain && strcmp(domain, ".") == 0) { 2017 if (domain == NULL) { 1928 2018 domain = get_winbind_domain(); 2019 } else { 2020 /* '.' is the special sign for our own domain */ 2021 if ((domain[0] == '\0') || strcmp(domain, ".") == 0) { 2022 domain = get_winbind_domain(); 2023 /* '*' is the special sign for all domains */ 2024 } else if (strcmp(domain, "*") == 0) { 2025 domain = NULL; 2026 } 1929 2027 } 1930 2028 … … 1954 2052 /* Send request to winbind daemon */ 1955 2053 1956 /* '.' is the special sign for our own domain */ 1957 if (domain && strcmp(domain, ".") == 0) { 2054 if (domain == NULL) { 1958 2055 domain = get_winbind_domain(); 2056 } else { 2057 /* '.' is the special sign for our own domain */ 2058 if ((domain[0] == '\0') || strcmp(domain, ".") == 0) { 2059 domain = get_winbind_domain(); 2060 /* '*' is the special sign for all domains */ 2061 } else if (strcmp(domain, "*") == 0) { 2062 domain = NULL; 2063 } 1959 2064 } 1960 2065 … … 2062 2167 OPT_LOGOFF_USER, 2063 2168 OPT_LOGOFF_UID, 2064 OPT_LANMAN 2169 OPT_LANMAN, 2170 OPT_KRB5CCNAME 2065 2171 }; 2066 2172 2067 int main(int argc, c har **argv, char **envp)2173 int main(int argc, const char **argv, char **envp) 2068 2174 { 2069 2175 int opt; … … 2081 2187 char *logoff_user = getenv("USER"); 2082 2188 int logoff_uid = geteuid(); 2189 const char *opt_krb5ccname = "FILE"; 2083 2190 2084 2191 struct poptOption long_options[] = { … … 2162 2269 /* destroys wbinfo --help output */ 2163 2270 /* "user%password,DOM\\user%password,user@EXAMPLE.COM,EXAMPLE.COM\\user%password" }, */ 2271 { "krb5ccname", 0, POPT_ARG_STRING, &opt_krb5ccname, OPT_KRB5CCNAME, "authenticate user using Kerberos and specific credential cache type", "krb5ccname" }, 2164 2272 #endif 2165 2273 { "separator", 0, POPT_ARG_NONE, 0, OPT_SEPARATOR, "Get the active winbind separator", NULL }, … … 2173 2281 2174 2282 /* Samba client initialisation */ 2175 load_case_tables();2283 smb_init_locale(); 2176 2284 2177 2285 2178 2286 /* Parse options */ 2179 2287 2180 pc = poptGetContext("wbinfo", argc, (const char **)argv,2288 pc = poptGetContext("wbinfo", argc, argv, 2181 2289 long_options, 0); 2182 2290 … … 2382 2490 break; 2383 2491 case 'P': 2384 if (!wbinfo_ping_dc()) { 2385 d_fprintf(stderr, "Could not ping our DC\n"); 2492 if (!wbinfo_ping_dc(opt_domain_name)) { 2386 2493 goto done; 2387 2494 } … … 2509 2616 } 2510 2617 case OPT_PAM_LOGON: 2511 if (!wbinfo_pam_logon(string_arg )) {2618 if (!wbinfo_pam_logon(string_arg, verbose)) { 2512 2619 d_fprintf(stderr, "pam_logon failed for %s\n", 2513 2620 string_arg); … … 2532 2639 WBFLAG_PAM_CONTACT_TRUSTDOM; 2533 2640 2534 if (!wbinfo_auth_krb5(string_arg, "FILE",2641 if (!wbinfo_auth_krb5(string_arg, opt_krb5ccname, 2535 2642 flags)) { 2536 2643 d_fprintf(stderr, … … 2538 2645 "[%s] with Kerberos " 2539 2646 "(ccache: %s)\n", string_arg, 2540 "FILE");2647 opt_krb5ccname); 2541 2648 goto done; 2542 2649 } … … 2618 2725 case OPT_LOGOFF_USER: 2619 2726 case OPT_LOGOFF_UID: 2727 case OPT_KRB5CCNAME: 2620 2728 break; 2621 2729 default:
Note:
See TracChangeset
for help on using the changeset viewer.