Ignore:
Timestamp:
Nov 24, 2016, 1:14:11 PM (9 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: update vendor to version 4.4.3

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vendor/current/nsswitch/wbinfo.c

    r860 r988  
    2323
    2424#include "includes.h"
    25 #include "popt_common.h"
    2625#include "winbind_client.h"
    2726#include "libwbclient/wbclient.h"
    28 #include "lib/popt/popt.h"
    2927#include "../libcli/auth/libcli_auth.h"
    30 #if (_SAMBA_BUILD_) >= 4
    3128#include "lib/cmdline/popt_common.h"
    32 #endif
     29#include "lib/afs/afs_settoken.h"
    3330
    3431#ifdef DBGC_CLASS
     
    121118        if (!p) {
    122119                /* Maybe it was a UPN? */
    123                 if ((p = strchr(domuser, '@')) != NULL) {
     120                p = strchr(domuser, '@');
     121                if (p != NULL) {
    124122                        fstrcpy(domain, "");
    125123                        fstrcpy(user, domuser);
     
    135133        fstrcpy(domain, domuser);
    136134        domain[PTR_DIFF(p, domuser)] = 0;
    137         strupper_m(domain);
    138135
    139136        return true;
     
    243240                 pwd->pw_shell);
    244241
     242        wbcFreeMemory(pwd);
     243
    245244        return true;
    246245}
     
    520519
    521520        if (print_all) {
    522                 d_printf("%-16s%-24s%-12s%-12s%-5s%-5s\n",
     521                d_printf("%-16s%-65s%-12s%-12s%-5s%-5s\n",
    523522                         "Domain Name", "DNS Domain", "Trust Type",
    524523                         "Transitive", "In", "Out");
     
    534533                }
    535534
    536                 d_printf("%-24s", domain_list[i].dns_name);
     535                d_printf("%-65s", domain_list[i].dns_name);
    537536
    538537                switch(domain_list[i].trust_type) {
     
    690689        /* Send request */
    691690
    692         if (winbindd_request_response(WINBINDD_GETDCNAME, &request,
     691        if (winbindd_request_response(NULL, WINBINDD_GETDCNAME, &request,
    693692                                      &response) != NSS_STATUS_SUCCESS) {
    694693                d_fprintf(stderr, "Could not get dc name for %s\n",domain_name);
     
    754753
    755754        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);
    758757                wbcFreeMemory(error);
    759758        }
     
    813812
    814813        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);
    817816                wbcFreeMemory(error);
    818817        }
     
    828827/* Check DC connection */
    829828
    830 static bool wbinfo_ping_dc(void)
     829static bool wbinfo_ping_dc(const char *domain)
    831830{
    832831        wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
    833832        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 : "",
    838848                 WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
    839849
     850        wbcFreeMemory(dcname);
    840851        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);
    843854                wbcFreeMemory(error);
     855                return false;
    844856        }
    845857        if (!WBC_ERROR_IS_OK(wbc_status)) {
     
    10201032                        d_printf("%s -> gid %d\n", sidstr, unix_ids[i].id.gid);
    10211033                        break;
     1034                case WBC_ID_TYPE_BOTH:
     1035                        d_printf("%s -> uid/gid %d\n", sidstr, unix_ids[i].id.uid);
     1036                        break;
    10221037                default:
    10231038                        d_printf("%s -> unmapped\n", sidstr);
     
    12181233        /* Display response */
    12191234
    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);
    12221244
    12231245        return true;
     
    12541276        d_printf("%s%c%s %d\n",
    12551277                 domain, winbind_separator(), name, type);
     1278
     1279        wbcFreeMemory(domain);
     1280        wbcFreeMemory(name);
    12561281
    12571282        return true;
     
    13141339
    13151340        wbc_status = wbcLookupRids(&dinfo->sid, num_rids, rids,
    1316                                    (const char **)&domain_name, &names, &types);
     1341                                   &p, &names, &types);
    13171342        if (!WBC_ERROR_IS_OK(wbc_status)) {
    13181343                d_printf("winbind_lookup_rids failed: %s\n",
     
    13211346        }
    13221347
     1348        domain_name = discard_const_p(char, p);
    13231349        d_printf("Domain: %s\n", domain_name);
    13241350
     
    13951421                if (names[i].type == WBC_SID_NAME_DOMAIN) {
    13961422                        d_printf("%s -> %s %d\n", sidstr,
    1397                                 domain,
    1398                                 names[i].type);
     1423                                 domain,
     1424                                 names[i].type);
    13991425                } else {
    14001426                        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);
    14061434        return true;
    14071435}
     
    14451473{
    14461474        char *prompt;
    1447         const char *ret = NULL;
     1475        char buf[1024] = {0};
     1476        int rc;
    14481477
    14491478        prompt = talloc_asprintf(mem_ctx, "Enter %s's ", username);
     
    14621491        }
    14631492
    1464         ret = getpass(prompt);
     1493        rc = samba_getpass(prompt, buf, sizeof(buf), false, false);
    14651494        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);
    14681500}
    14691501
     
    15531585        if (error) {
    15541586                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,
    15571590                         error->nt_status,
    15581591                         error->display_string);
     
    17251758        if (wbc_status == WBC_ERR_AUTH_ERROR) {
    17261759                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,
    17281765                         err->nt_string,
    17291766                         err->nt_status,
     
    17421779/* Authenticate a user with a plaintext password */
    17431780
    1744 static bool wbinfo_pam_logon(char *username)
     1781static bool wbinfo_pam_logon(char *username, bool verbose)
    17451782{
    17461783        wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
    17471784        struct wbcLogonUserParams params;
     1785        struct wbcLogonUserInfo *info = NULL;
    17481786        struct wbcAuthErrorInfo *error = NULL;
    17491787        char *s = NULL;
     
    17901828        }
    17911829
    1792         wbc_status = wbcLogonUser(&params, NULL, &error, NULL);
     1830        wbc_status = wbcLogonUser(&params, &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        }
    17931879
    17941880        wbcFreeMemory(params.blobs);
     
    17991885        if (!WBC_ERROR_IS_OK(wbc_status) && (error != NULL)) {
    18001886                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,
    18021890                          error->nt_string,
    18031891                          (int)error->nt_status,
     
    18691957        } else {
    18701958                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);
    18721963        }
    18731964
    18741965        request.flags |= WBFLAG_PAM_AFS_TOKEN;
    18751966
    1876         result = winbindd_request_response(WINBINDD_PAM_AUTH, &request,
     1967        result = winbindd_request_response(NULL, WINBINDD_PAM_AUTH, &request,
    18771968                                           &response);
    18781969
     
    19242015        /* Send request to winbind daemon */
    19252016
    1926         /* '.' is the special sign for our own domain */
    1927         if (domain && strcmp(domain, ".") == 0) {
     2017        if (domain == NULL) {
    19282018                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                }
    19292027        }
    19302028
     
    19542052        /* Send request to winbind daemon */
    19552053
    1956         /* '.' is the special sign for our own domain */
    1957         if (domain && strcmp(domain, ".") == 0) {
     2054        if (domain == NULL) {
    19582055                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                }
    19592064        }
    19602065
     
    20622167        OPT_LOGOFF_USER,
    20632168        OPT_LOGOFF_UID,
    2064         OPT_LANMAN
     2169        OPT_LANMAN,
     2170        OPT_KRB5CCNAME
    20652171};
    20662172
    2067 int main(int argc, char **argv, char **envp)
     2173int main(int argc, const char **argv, char **envp)
    20682174{
    20692175        int opt;
     
    20812187        char *logoff_user = getenv("USER");
    20822188        int logoff_uid = geteuid();
     2189        const char *opt_krb5ccname = "FILE";
    20832190
    20842191        struct poptOption long_options[] = {
     
    21622269                        /* destroys wbinfo --help output */
    21632270                        /* "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" },
    21642272#endif
    21652273                { "separator", 0, POPT_ARG_NONE, 0, OPT_SEPARATOR, "Get the active winbind separator", NULL },
     
    21732281
    21742282        /* Samba client initialisation */
    2175         load_case_tables();
     2283        smb_init_locale();
    21762284
    21772285
    21782286        /* Parse options */
    21792287
    2180         pc = poptGetContext("wbinfo", argc, (const char **)argv,
     2288        pc = poptGetContext("wbinfo", argc, argv,
    21812289                            long_options, 0);
    21822290
     
    23822490                        break;
    23832491                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)) {
    23862493                                goto done;
    23872494                        }
     
    25092616                        }
    25102617                case OPT_PAM_LOGON:
    2511                         if (!wbinfo_pam_logon(string_arg)) {
     2618                        if (!wbinfo_pam_logon(string_arg, verbose)) {
    25122619                                d_fprintf(stderr, "pam_logon failed for %s\n",
    25132620                                          string_arg);
     
    25322639                                                 WBFLAG_PAM_CONTACT_TRUSTDOM;
    25332640
    2534                                 if (!wbinfo_auth_krb5(string_arg, "FILE",
     2641                                if (!wbinfo_auth_krb5(string_arg, opt_krb5ccname,
    25352642                                                      flags)) {
    25362643                                        d_fprintf(stderr,
     
    25382645                                                "[%s] with Kerberos "
    25392646                                                "(ccache: %s)\n", string_arg,
    2540                                                 "FILE");
     2647                                                opt_krb5ccname);
    25412648                                        goto done;
    25422649                                }
     
    26182725                case OPT_LOGOFF_USER:
    26192726                case OPT_LOGOFF_UID:
     2727                case OPT_KRB5CCNAME:
    26202728                        break;
    26212729                default:
Note: See TracChangeset for help on using the changeset viewer.