]> git.samba.org - nivanova/samba-autobuild/.git/blobdiff - nsswitch/wbinfo.c
nss_aix: Hack away WINBINDD_UID_TO_SID
[nivanova/samba-autobuild/.git] / nsswitch / wbinfo.c
index 9efd40b56a0842a8976b9ce908e86c1c8a54be6e..f7b5ace3f94d77e640bf48a00c1c34b09a3d3065 100644 (file)
 */
 
 #include "includes.h"
-#include "popt_common.h"
 #include "winbind_client.h"
 #include "libwbclient/wbclient.h"
-#include "lib/popt/popt.h"
 #include "../libcli/auth/libcli_auth.h"
-#if (_SAMBA_BUILD_) >= 4
 #include "lib/cmdline/popt_common.h"
-#endif
+#include "lib/afs/afs_settoken.h"
 
 #ifdef DBGC_CLASS
 #undef DBGC_CLASS
@@ -120,7 +117,8 @@ static bool parse_wbinfo_domain_user(const char *domuser, fstring domain,
 
        if (!p) {
                /* Maybe it was a UPN? */
-               if ((p = strchr(domuser, '@')) != NULL) {
+               p = strchr(domuser, '@');
+               if (p != NULL) {
                        fstrcpy(domain, "");
                        fstrcpy(user, domuser);
                        return true;
@@ -134,7 +132,6 @@ static bool parse_wbinfo_domain_user(const char *domuser, fstring domain,
        fstrcpy(user, p+1);
        fstrcpy(domain, domuser);
        domain[PTR_DIFF(p, domuser)] = 0;
-       strupper_m(domain);
 
        return true;
 }
@@ -187,6 +184,8 @@ static bool wbinfo_get_userinfo(char *user)
                 pwd->pw_dir,
                 pwd->pw_shell);
 
+       wbcFreeMemory(pwd);
+
        return true;
 }
 
@@ -212,6 +211,8 @@ static bool wbinfo_get_uidinfo(int uid)
                 pwd->pw_dir,
                 pwd->pw_shell);
 
+       wbcFreeMemory(pwd);
+
        return true;
 }
 
@@ -238,6 +239,8 @@ static bool wbinfo_get_user_sidinfo(const char *sid_str)
                 pwd->pw_dir,
                 pwd->pw_shell);
 
+       wbcFreeMemory(pwd);
+
        return true;
 }
 
@@ -515,7 +518,7 @@ static bool wbinfo_list_domains(bool list_all_domains, bool verbose)
        }
 
        if (print_all) {
-               d_printf("%-16s%-24s%-12s%-12s%-5s%-5s\n",
+               d_printf("%-16s%-65s%-12s%-12s%-5s%-5s\n",
                         "Domain Name", "DNS Domain", "Trust Type",
                         "Transitive", "In", "Out");
        }
@@ -529,7 +532,7 @@ static bool wbinfo_list_domains(bool list_all_domains, bool verbose)
                        continue;
                }
 
-               d_printf("%-24s", domain_list[i].dns_name);
+               d_printf("%-65s", domain_list[i].dns_name);
 
                switch(domain_list[i].trust_type) {
                case WBC_DOMINFO_TRUSTTYPE_NONE:
@@ -685,7 +688,7 @@ static bool wbinfo_getdcname(const char *domain_name)
 
        /* Send request */
 
-       if (winbindd_request_response(WINBINDD_GETDCNAME, &request,
+       if (winbindd_request_response(NULL, WINBINDD_GETDCNAME, &request,
                                      &response) != NSS_STATUS_SUCCESS) {
                d_fprintf(stderr, "Could not get dc name for %s\n",domain_name);
                return false;
@@ -749,8 +752,8 @@ static bool wbinfo_check_secret(const char *domain)
                WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
 
        if (wbc_status == WBC_ERR_AUTH_ERROR) {
-               d_fprintf(stderr, "error code was %s (0x%x)\n",
-                         error->nt_string, error->nt_status);
+               d_fprintf(stderr, "wbcCheckTrustCredentials(%s): error code was %s (0x%x)\n",
+                         domain_name, error->nt_string, error->nt_status);
                wbcFreeMemory(error);
        }
        if (!WBC_ERROR_IS_OK(wbc_status)) {
@@ -808,8 +811,8 @@ static bool wbinfo_change_secret(const char *domain)
                WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
 
        if (wbc_status == WBC_ERR_AUTH_ERROR) {
-               d_fprintf(stderr, "error code was %s (0x%x)\n",
-                         error->nt_string, error->nt_status);
+               d_fprintf(stderr, "wbcChangeTrustCredentials(%s): error code was %s (0x%x)\n",
+                         domain_name, error->nt_string, error->nt_status);
                wbcFreeMemory(error);
        }
        if (!WBC_ERROR_IS_OK(wbc_status)) {
@@ -823,20 +826,33 @@ static bool wbinfo_change_secret(const char *domain)
 
 /* Check DC connection */
 
-static bool wbinfo_ping_dc(void)
+static bool wbinfo_ping_dc(const char *domain)
 {
        wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
        struct wbcAuthErrorInfo *error = NULL;
+       char *dcname = NULL;
+
+       const char *domain_name;
 
-       wbc_status = wbcPingDc(NULL, &error);
+       if (domain) {
+               domain_name = domain;
+       } else {
+               domain_name = get_winbind_domain();
+       }
 
-       d_printf("checking the NETLOGON dc connection %s\n",
+       wbc_status = wbcPingDc2(domain_name, &error, &dcname);
+
+       d_printf("checking the NETLOGON for domain[%s] dc connection to \"%s\" %s\n",
+                domain_name ? domain_name : "",
+                dcname ? dcname : "",
                 WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
 
+       wbcFreeMemory(dcname);
        if (wbc_status == WBC_ERR_AUTH_ERROR) {
-               d_fprintf(stderr, "error code was %s (0x%x)\n",
-                         error->nt_string, error->nt_status);
+               d_fprintf(stderr, "wbcPingDc2(%s): error code was %s (0x%x)\n",
+                         domain_name, error->nt_string, error->nt_status);
                wbcFreeMemory(error);
+               return false;
        }
        if (!WBC_ERROR_IS_OK(wbc_status)) {
                d_fprintf(stderr, "failed to call wbcPingDc: %s\n",
@@ -959,6 +975,143 @@ static bool wbinfo_sid_to_gid(const char *sid_str)
        return true;
 }
 
+static bool wbinfo_sids_to_unix_ids(const char *arg)
+{
+       char sidstr[WBC_SID_STRING_BUFLEN];
+       struct wbcDomainSid *sids;
+       struct wbcUnixId *unix_ids;
+       int i, num_sids;
+       const char *p;
+       wbcErr wbc_status;
+
+
+       num_sids = 0;
+       sids = NULL;
+       p = arg;
+
+       while (next_token(&p, sidstr, LIST_SEP, sizeof(sidstr))) {
+               sids = talloc_realloc(talloc_tos(), sids, struct wbcDomainSid,
+                                     num_sids+1);
+               if (sids == NULL) {
+                       d_fprintf(stderr, "talloc failed\n");
+                       return false;
+               }
+               wbc_status = wbcStringToSid(sidstr, &sids[num_sids]);
+               if (!WBC_ERROR_IS_OK(wbc_status)) {
+                       d_fprintf(stderr, "wbcSidToString(%s) failed: %s\n",
+                                 sidstr, wbcErrorString(wbc_status));
+                       TALLOC_FREE(sids);
+                       return false;
+               }
+               num_sids += 1;
+       }
+
+       unix_ids = talloc_array(talloc_tos(), struct wbcUnixId, num_sids);
+       if (unix_ids == NULL) {
+               TALLOC_FREE(sids);
+               return false;
+       }
+
+       wbc_status = wbcSidsToUnixIds(sids, num_sids, unix_ids);
+       if (!WBC_ERROR_IS_OK(wbc_status)) {
+               d_fprintf(stderr, "wbcSidsToUnixIds failed: %s\n",
+                         wbcErrorString(wbc_status));
+               TALLOC_FREE(sids);
+               return false;
+       }
+
+       for (i=0; i<num_sids; i++) {
+
+               wbcSidToStringBuf(&sids[i], sidstr, sizeof(sidstr));
+
+               switch(unix_ids[i].type) {
+               case WBC_ID_TYPE_UID:
+                       d_printf("%s -> uid %d\n", sidstr, unix_ids[i].id.uid);
+                       break;
+               case WBC_ID_TYPE_GID:
+                       d_printf("%s -> gid %d\n", sidstr, unix_ids[i].id.gid);
+                       break;
+               case WBC_ID_TYPE_BOTH:
+                       d_printf("%s -> uid/gid %d\n", sidstr, unix_ids[i].id.uid);
+                       break;
+               default:
+                       d_printf("%s -> unmapped\n", sidstr);
+                       break;
+               }
+       }
+
+       TALLOC_FREE(sids);
+       TALLOC_FREE(unix_ids);
+
+       return true;
+}
+
+static bool wbinfo_xids_to_sids(const char *arg)
+{
+       fstring idstr;
+       struct wbcUnixId *xids = NULL;
+       struct wbcDomainSid *sids;
+       wbcErr wbc_status;
+       int num_xids = 0;
+       const char *p;
+       int i;
+
+       p = arg;
+
+       while (next_token(&p, idstr, LIST_SEP, sizeof(idstr))) {
+               xids = talloc_realloc(talloc_tos(), xids, struct wbcUnixId,
+                                     num_xids+1);
+               if (xids == NULL) {
+                       d_fprintf(stderr, "talloc failed\n");
+                       return false;
+               }
+
+               switch (idstr[0]) {
+               case 'u':
+                       xids[num_xids] = (struct wbcUnixId) {
+                               .type = WBC_ID_TYPE_UID,
+                               .id.uid = atoi(&idstr[1])
+                       };
+                       break;
+               case 'g':
+                       xids[num_xids] = (struct wbcUnixId) {
+                               .type = WBC_ID_TYPE_GID,
+                               .id.gid = atoi(&idstr[1])
+                       };
+                       break;
+               default:
+                       d_fprintf(stderr, "%s is an invalid id\n", idstr);
+                       TALLOC_FREE(xids);
+                       return false;
+               }
+               num_xids += 1;
+       }
+
+       sids = talloc_array(talloc_tos(), struct wbcDomainSid, num_xids);
+       if (sids == NULL) {
+               d_fprintf(stderr, "talloc failed\n");
+               TALLOC_FREE(xids);
+               return false;
+       }
+
+       wbc_status = wbcUnixIdsToSids(xids, num_xids, sids);
+       if (!WBC_ERROR_IS_OK(wbc_status)) {
+               d_fprintf(stderr, "wbcUnixIdsToSids failed: %s\n",
+                         wbcErrorString(wbc_status));
+               TALLOC_FREE(sids);
+               TALLOC_FREE(xids);
+               return false;
+       }
+
+       for (i=0; i<num_xids; i++) {
+               char str[WBC_SID_STRING_BUFLEN];
+               wbcSidToStringBuf(&sids[i], str, sizeof(str));
+               d_printf("%s\n", str);
+       }
+
+       return true;
+}
+
 static bool wbinfo_allocate_uid(void)
 {
        wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
@@ -1145,8 +1298,15 @@ static bool wbinfo_lookupsid(const char *sid_str)
 
        /* Display response */
 
-       d_printf("%s%c%s %d\n",
-                domain, winbind_separator(), name, type);
+       if (type == WBC_SID_NAME_DOMAIN) {
+               d_printf("%s %d\n", domain, type);
+       } else {
+               d_printf("%s%c%s %d\n",
+                        domain, winbind_separator(), name, type);
+       }
+
+       wbcFreeMemory(domain);
+       wbcFreeMemory(name);
 
        return true;
 }
@@ -1182,6 +1342,9 @@ static bool wbinfo_lookupsid_fullname(const char *sid_str)
        d_printf("%s%c%s %d\n",
                 domain, winbind_separator(), name, type);
 
+       wbcFreeMemory(domain);
+       wbcFreeMemory(name);
+
        return true;
 }
 
@@ -1241,13 +1404,14 @@ static bool wbinfo_lookuprids(const char *domain, const char *arg)
        }
 
        wbc_status = wbcLookupRids(&dinfo->sid, num_rids, rids,
-                                  (const char **)&domain_name, &names, &types);
+                                  &p, &names, &types);
        if (!WBC_ERROR_IS_OK(wbc_status)) {
                d_printf("winbind_lookup_rids failed: %s\n",
                         wbcErrorString(wbc_status));
                goto done;
        }
 
+       domain_name = discard_const_p(char, p);
        d_printf("Domain: %s\n", domain_name);
 
        for (i=0; i<num_rids; i++) {
@@ -1265,6 +1429,77 @@ done:
        return ret;
 }
 
+static bool wbinfo_lookup_sids(const char *arg)
+{
+       char sidstr[WBC_SID_STRING_BUFLEN];
+       struct wbcDomainSid *sids;
+       struct wbcDomainInfo *domains;
+       struct wbcTranslatedName *names;
+       int num_domains;
+       int i, num_sids;
+       const char *p;
+       wbcErr wbc_status;
+
+
+       num_sids = 0;
+       sids = NULL;
+       p = arg;
+
+       while (next_token(&p, sidstr, LIST_SEP, sizeof(sidstr))) {
+               sids = talloc_realloc(talloc_tos(), sids, struct wbcDomainSid,
+                                     num_sids+1);
+               if (sids == NULL) {
+                       d_fprintf(stderr, "talloc failed\n");
+                       return false;
+               }
+               wbc_status = wbcStringToSid(sidstr, &sids[num_sids]);
+               if (!WBC_ERROR_IS_OK(wbc_status)) {
+                       d_fprintf(stderr, "wbcSidToString(%s) failed: %s\n",
+                                 sidstr, wbcErrorString(wbc_status));
+                       TALLOC_FREE(sids);
+                       return false;
+               }
+               num_sids += 1;
+       }
+
+       wbc_status = wbcLookupSids(sids, num_sids, &domains, &num_domains,
+                                  &names);
+       if (!WBC_ERROR_IS_OK(wbc_status)) {
+               d_fprintf(stderr, "wbcLookupSids failed: %s\n",
+                         wbcErrorString(wbc_status));
+               TALLOC_FREE(sids);
+               return false;
+       }
+
+       for (i=0; i<num_sids; i++) {
+               const char *domain = NULL;
+
+               wbcSidToStringBuf(&sids[i], sidstr, sizeof(sidstr));
+
+               if (names[i].domain_index >= num_domains) {
+                       domain = "<none>";
+               } else if (names[i].domain_index < 0) {
+                       domain = "<none>";
+               } else {
+                       domain = domains[names[i].domain_index].short_name;
+               }
+
+               if (names[i].type == WBC_SID_NAME_DOMAIN) {
+                       d_printf("%s -> %s %d\n", sidstr,
+                                domain,
+                                names[i].type);
+               } else {
+                       d_printf("%s -> %s%c%s %d\n", sidstr,
+                                domain,
+                                winbind_separator(),
+                                names[i].name, names[i].type);
+               }
+       }
+       wbcFreeMemory(names);
+       wbcFreeMemory(domains);
+       return true;
+}
+
 /* Convert string to sid */
 
 static bool wbinfo_lookupname(const char *full_name)
@@ -1303,7 +1538,8 @@ static char *wbinfo_prompt_pass(TALLOC_CTX *mem_ctx,
                                const char *username)
 {
        char *prompt;
-       const char *ret = NULL;
+       char buf[1024] = {0};
+       int rc;
 
        prompt = talloc_asprintf(mem_ctx, "Enter %s's ", username);
        if (!prompt) {
@@ -1320,10 +1556,13 @@ static char *wbinfo_prompt_pass(TALLOC_CTX *mem_ctx,
                return NULL;
        }
 
-       ret = getpass(prompt);
+       rc = samba_getpass(prompt, buf, sizeof(buf), false, false);
        TALLOC_FREE(prompt);
+       if (rc < 0) {
+               return NULL;
+       }
 
-       return talloc_strdup(mem_ctx, ret);
+       return talloc_strdup(mem_ctx, buf);
 }
 
 /* Authenticate a user with a plaintext password */
@@ -1411,8 +1650,9 @@ static bool wbinfo_auth_krb5(char *username, const char *cctype, uint32_t flags)
 
        if (error) {
                d_fprintf(stderr,
-                        "error code was %s (0x%x)\nerror message was: %s\n",
-                        error->nt_string,
+                        "wbcLogonUser(%s): error code was %s (0x%x)\n"
+                        "error message was: %s\n",
+                        params.username, error->nt_string,
                         error->nt_status,
                         error->display_string);
        }
@@ -1583,7 +1823,11 @@ static bool wbinfo_auth_crap(char *username, bool use_ntlmv2, bool use_lanman)
 
        if (wbc_status == WBC_ERR_AUTH_ERROR) {
                d_fprintf(stderr,
-                        "error code was %s (0x%x)\nerror message was: %s\n",
+                        "wbcAuthenticateUserEx(%s%c%s): error code was %s (0x%x)\n"
+                        "error message was: %s\n",
+                        name_domain,
+                        winbind_separator(),
+                        name_user,
                         err->nt_string,
                         err->nt_status,
                         err->display_string);
@@ -1600,11 +1844,12 @@ static bool wbinfo_auth_crap(char *username, bool use_ntlmv2, bool use_lanman)
 
 /* Authenticate a user with a plaintext password */
 
-static bool wbinfo_pam_logon(char *username)
+static bool wbinfo_pam_logon(char *username, bool verbose)
 {
        wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
        struct wbcLogonUserParams params;
-       struct wbcAuthErrorInfo *error;
+       struct wbcLogonUserInfo *info = NULL;
+       struct wbcAuthErrorInfo *error = NULL;
        char *s = NULL;
        char *p = NULL;
        TALLOC_CTX *frame = talloc_tos();
@@ -1648,23 +1893,72 @@ static bool wbinfo_pam_logon(char *username)
                return false;
        }
 
-       wbc_status = wbcLogonUser(&params, NULL, &error, NULL);
+       wbc_status = wbcLogonUser(&params, &info, &error, NULL);
+
+       if (verbose && (info != NULL)) {
+               struct wbcAuthUserInfo *i = info->info;
+               uint32_t j;
+
+               if (i->account_name != NULL) {
+                       d_printf("account_name: %s\n", i->account_name);
+               }
+               if (i->user_principal != NULL) {
+                       d_printf("user_principal: %s\n", i->user_principal);
+               }
+               if (i->full_name != NULL) {
+                       d_printf("full_name: %s\n", i->full_name);
+               }
+               if (i->domain_name != NULL) {
+                       d_printf("domain_name: %s\n", i->domain_name);
+               }
+               if (i->dns_domain_name != NULL) {
+                       d_printf("dns_domain_name: %s\n", i->dns_domain_name);
+               }
+               if (i->logon_server != NULL) {
+                       d_printf("logon_server: %s\n", i->logon_server);
+               }
+               if (i->logon_script != NULL) {
+                       d_printf("logon_script: %s\n", i->logon_script);
+               }
+               if (i->profile_path != NULL) {
+                       d_printf("profile_path: %s\n", i->profile_path);
+               }
+               if (i->home_directory != NULL) {
+                       d_printf("home_directory: %s\n", i->home_directory);
+               }
+               if (i->home_drive != NULL) {
+                       d_printf("home_drive: %s\n", i->home_drive);
+               }
+
+               d_printf("sids:");
+
+               for (j=0; j<i->num_sids; j++) {
+                       char buf[WBC_SID_STRING_BUFLEN];
+                       wbcSidToStringBuf(&i->sids[j].sid, buf, sizeof(buf));
+                       d_printf(" %s", buf);
+               }
+               d_printf("\n");
+
+               wbcFreeMemory(info);
+               info = NULL;
+       }
 
        wbcFreeMemory(params.blobs);
 
        d_printf("plaintext password authentication %s\n",
                 WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
 
-       if (!WBC_ERROR_IS_OK(wbc_status)) {
+       if (!WBC_ERROR_IS_OK(wbc_status) && (error != NULL)) {
                d_fprintf(stderr,
-                         "error code was %s (0x%x)\nerror message was: %s\n",
+                         "wbcLogonUser(%s): error code was %s (0x%x)\n"
+                         "error message was: %s\n",
+                         params.username,
                          error->nt_string,
                          (int)error->nt_status,
                          error->display_string);
                wbcFreeMemory(error);
-               return false;
        }
-       return true;
+       return WBC_ERROR_IS_OK(wbc_status);
 }
 
 /* Save creds with winbind */
@@ -1728,12 +2022,15 @@ static bool wbinfo_klog(char *username)
                *p = '%';
        } else {
                fstrcpy(request.data.auth.user, username);
-               fstrcpy(request.data.auth.pass, getpass("Password: "));
+               (void) samba_getpass("Password: ",
+                                    request.data.auth.pass,
+                                    sizeof(request.data.auth.pass),
+                                    false, false);
        }
 
        request.flags |= WBFLAG_PAM_AFS_TOKEN;
 
-       result = winbindd_request_response(WINBINDD_PAM_AUTH, &request,
+       result = winbindd_request_response(NULL, WINBINDD_PAM_AUTH, &request,
                                           &response);
 
        /* Display response */
@@ -1783,9 +2080,16 @@ static bool print_domain_users(const char *domain)
 
        /* Send request to winbind daemon */
 
-       /* '.' is the special sign for our own domain */
-       if (domain && strcmp(domain, ".") == 0) {
+       if (domain == NULL) {
                domain = get_winbind_domain();
+       } else {
+               /* '.' is the special sign for our own domain */
+               if ((domain[0] == '\0') || strcmp(domain, ".") == 0) {
+                       domain = get_winbind_domain();
+               /* '*' is the special sign for all domains */
+               } else if (strcmp(domain, "*") == 0) {
+                       domain = NULL;
+               }
        }
 
        wbc_status = wbcListUsers(domain, &num_users, &users);
@@ -1813,9 +2117,16 @@ static bool print_domain_groups(const char *domain)
 
        /* Send request to winbind daemon */
 
-       /* '.' is the special sign for our own domain */
-       if (domain && strcmp(domain, ".") == 0) {
+       if (domain == NULL) {
                domain = get_winbind_domain();
+       } else {
+               /* '.' is the special sign for our own domain */
+               if ((domain[0] == '\0') || strcmp(domain, ".") == 0) {
+                       domain = get_winbind_domain();
+               /* '*' is the special sign for all domains */
+               } else if (strcmp(domain, "*") == 0) {
+                       domain = NULL;
+               }
        }
 
        wbc_status = wbcListGroups(domain, &num_groups, &groups);
@@ -1896,12 +2207,15 @@ enum {
        OPT_USERDOMGROUPS,
        OPT_SIDALIASES,
        OPT_USERSIDS,
+       OPT_LOOKUP_SIDS,
        OPT_ALLOCATE_UID,
        OPT_ALLOCATE_GID,
        OPT_SET_UID_MAPPING,
        OPT_SET_GID_MAPPING,
        OPT_REMOVE_UID_MAPPING,
        OPT_REMOVE_GID_MAPPING,
+       OPT_SIDS_TO_XIDS,
+       OPT_XIDS_TO_SIDS,
        OPT_SEPARATOR,
        OPT_LIST_ALL_DOMAINS,
        OPT_LIST_OWN_DOMAIN,
@@ -1919,10 +2233,11 @@ enum {
        OPT_LOGOFF,
        OPT_LOGOFF_USER,
        OPT_LOGOFF_UID,
-       OPT_LANMAN
+       OPT_LANMAN,
+       OPT_KRB5CCNAME
 };
 
-int main(int argc, char **argv, char **envp)
+int main(int argc, const char **argv, char **envp)
 {
        int opt;
        TALLOC_CTX *frame = talloc_stackframe();
@@ -1938,6 +2253,7 @@ int main(int argc, char **argv, char **envp)
        bool use_lanman = false;
        char *logoff_user = getenv("USER");
        int logoff_uid = geteuid();
+       const char *opt_krb5ccname = "FILE";
 
        struct poptOption long_options[] = {
                POPT_AUTOHELP
@@ -1954,6 +2270,9 @@ int main(int argc, char **argv, char **envp)
                { "sid-to-fullname", 0, POPT_ARG_STRING, &string_arg,
                  OPT_SID_TO_FULLNAME, "Converts sid to fullname", "SID" },
                { "lookup-rids", 'R', POPT_ARG_STRING, &string_arg, 'R', "Converts RIDs to names", "RIDs" },
+               { "lookup-sids", 0, POPT_ARG_STRING, &string_arg,
+                 OPT_LOOKUP_SIDS, "Converts SIDs to types and names",
+                 "Sid-List"},
                { "uid-to-sid", 'U', POPT_ARG_INT, &int_arg, 'U', "Converts uid to sid" , "UID" },
                { "gid-to-sid", 'G', POPT_ARG_INT, &int_arg, 'G', "Converts gid to sid", "GID" },
                { "sid-to-uid", 'S', POPT_ARG_STRING, &string_arg, 'S', "Converts sid to uid", "SID" },
@@ -1966,6 +2285,11 @@ int main(int argc, char **argv, char **envp)
                { "set-gid-mapping", 0, POPT_ARG_STRING, &string_arg, OPT_SET_GID_MAPPING, "Create or modify gid to sid mapping in idmap", "GID,SID" },
                { "remove-uid-mapping", 0, POPT_ARG_STRING, &string_arg, OPT_REMOVE_UID_MAPPING, "Remove uid to sid mapping in idmap", "UID,SID" },
                { "remove-gid-mapping", 0, POPT_ARG_STRING, &string_arg, OPT_REMOVE_GID_MAPPING, "Remove gid to sid mapping in idmap", "GID,SID" },
+               { "sids-to-unix-ids", 0, POPT_ARG_STRING, &string_arg,
+                 OPT_SIDS_TO_XIDS, "Translate SIDs to Unix IDs", "Sid-List" },
+               { "unix-ids-to-sids", 0, POPT_ARG_STRING, &string_arg,
+                 OPT_XIDS_TO_SIDS, "Translate Unix IDs to SIDs",
+                 "ID-List (u<num> g<num>)" },
                { "check-secret", 't', POPT_ARG_NONE, 0, 't', "Check shared secret" },
                { "change-secret", 'c', POPT_ARG_NONE, 0, 'c', "Change shared secret" },
                { "ping-dc", 'P', POPT_ARG_NONE, 0, 'P',
@@ -2014,6 +2338,7 @@ int main(int argc, char **argv, char **envp)
                { "krb5auth", 'K', POPT_ARG_STRING, &string_arg, 'K', "authenticate user using Kerberos", "user%password" },
                        /* destroys wbinfo --help output */
                        /* "user%password,DOM\\user%password,user@EXAMPLE.COM,EXAMPLE.COM\\user%password" }, */
+               { "krb5ccname", 0, POPT_ARG_STRING, &opt_krb5ccname, OPT_KRB5CCNAME, "authenticate user using Kerberos and specific credential cache type", "krb5ccname" },
 #endif
                { "separator", 0, POPT_ARG_NONE, 0, OPT_SEPARATOR, "Get the active winbind separator", NULL },
                { "verbose", 0, POPT_ARG_NONE, 0, OPT_VERBOSE, "Print additional information per command", NULL },
@@ -2025,12 +2350,12 @@ int main(int argc, char **argv, char **envp)
        };
 
        /* Samba client initialisation */
-       load_case_tables();
+       smb_init_locale();
 
 
        /* Parse options */
 
-       pc = poptGetContext("wbinfo", argc, (const char **)argv,
+       pc = poptGetContext("wbinfo", argc, argv,
                            long_options, 0);
 
        /* Parse command line options */
@@ -2098,6 +2423,13 @@ int main(int argc, char **argv, char **envp)
                                goto done;
                        }
                        break;
+               case OPT_LOOKUP_SIDS:
+                       if (!wbinfo_lookup_sids(string_arg)) {
+                               d_fprintf(stderr, "Could not lookup SIDs %s\n",
+                                         string_arg);
+                               goto done;
+                       }
+                       break;
                case 'n':
                        if (!wbinfo_lookupname(string_arg)) {
                                d_fprintf(stderr, "Could not lookup name %s\n",
@@ -2207,6 +2539,20 @@ int main(int argc, char **argv, char **envp)
                                goto done;
                        }
                        break;
+               case OPT_SIDS_TO_XIDS:
+                       if (!wbinfo_sids_to_unix_ids(string_arg)) {
+                               d_fprintf(stderr, "wbinfo_sids_to_unix_ids "
+                                         "failed\n");
+                               goto done;
+                       }
+                       break;
+               case OPT_XIDS_TO_SIDS:
+                       if (!wbinfo_xids_to_sids(string_arg)) {
+                               d_fprintf(stderr, "wbinfo_xids_to_sids "
+                                         "failed\n");
+                               goto done;
+                       }
+                       break;
                case 't':
                        if (!wbinfo_check_secret(opt_domain_name)) {
                                d_fprintf(stderr, "Could not check secret\n");
@@ -2220,8 +2566,7 @@ int main(int argc, char **argv, char **envp)
                        }
                        break;
                case 'P':
-                       if (!wbinfo_ping_dc()) {
-                               d_fprintf(stderr, "Could not ping our DC\n");
+                       if (!wbinfo_ping_dc(opt_domain_name)) {
                                goto done;
                        }
                        break;
@@ -2347,7 +2692,7 @@ int main(int argc, char **argv, char **envp)
                                break;
                        }
                case OPT_PAM_LOGON:
-                       if (!wbinfo_pam_logon(string_arg)) {
+                       if (!wbinfo_pam_logon(string_arg, verbose)) {
                                d_fprintf(stderr, "pam_logon failed for %s\n",
                                          string_arg);
                                goto done;
@@ -2370,13 +2715,13 @@ int main(int argc, char **argv, char **envp)
                                                 WBFLAG_PAM_INFO3_TEXT |
                                                 WBFLAG_PAM_CONTACT_TRUSTDOM;
 
-                               if (!wbinfo_auth_krb5(string_arg, "FILE",
+                               if (!wbinfo_auth_krb5(string_arg, opt_krb5ccname,
                                                      flags)) {
                                        d_fprintf(stderr,
                                                "Could not authenticate user "
                                                "[%s] with Kerberos "
                                                "(ccache: %s)\n", string_arg,
-                                               "FILE");
+                                               opt_krb5ccname);
                                        goto done;
                                }
                                break;
@@ -2456,6 +2801,7 @@ int main(int argc, char **argv, char **envp)
                case OPT_LANMAN:
                case OPT_LOGOFF_USER:
                case OPT_LOGOFF_UID:
+               case OPT_KRB5CCNAME:
                        break;
                default:
                        d_fprintf(stderr, "Invalid option\n");