*/
#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
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;
pwd->pw_dir,
pwd->pw_shell);
+ wbcFreeMemory(pwd);
+
return true;
}
}
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");
}
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:
/* 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;
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)) {
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)) {
/* 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;
+
+ if (domain) {
+ domain_name = domain;
+ } else {
+ domain_name = get_winbind_domain();
+ }
- wbc_status = wbcPingDc(NULL, &error);
+ wbc_status = wbcPingDc2(domain_name, &error, &dcname);
- d_printf("checking the NETLOGON dc connection %s\n",
+ 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",
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;
/* 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;
}
d_printf("%s%c%s %d\n",
domain, winbind_separator(), name, type);
+ wbcFreeMemory(domain);
+ wbcFreeMemory(name);
+
return true;
}
}
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++) {
}
for (i=0; i<num_sids; i++) {
+ const char *domain = NULL;
+
wbcSidToStringBuf(&sids[i], sidstr, sizeof(sidstr));
- d_printf("%s -> %s\\%s %d\n", sidstr,
- domains[names[i].domain_index].short_name,
- names[i].name, names[i].type);
+ 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;
}
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) {
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 */
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);
}
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);
/* 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();
return false;
}
- wbc_status = wbcLogonUser(¶ms, NULL, &error, NULL);
+ wbc_status = wbcLogonUser(¶ms, &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 */
*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 */
/* 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);
/* 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);
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();
bool use_lanman = false;
char *logoff_user = getenv("USER");
int logoff_uid = geteuid();
+ const char *opt_krb5ccname = "FILE";
struct poptOption long_options[] = {
POPT_AUTOHELP
{ "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 },
};
/* 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 */
}
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;
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;
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;
case OPT_LANMAN:
case OPT_LOGOFF_USER:
case OPT_LOGOFF_UID:
+ case OPT_KRB5CCNAME:
break;
default:
d_fprintf(stderr, "Invalid option\n");