*/
#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
#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:
{
wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
struct wbcAuthErrorInfo *error = NULL;
+ char *dcname = NULL;
- wbc_status = wbcPingDc(NULL, &error);
+ wbc_status = wbcPingDc2(NULL, &error, &dcname);
- d_printf("checking the NETLOGON dc connection %s\n",
+ d_printf("checking the NETLOGON dc connection to \"%s\" %s\n",
+ dcname ? dcname : "",
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);
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;
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;
}
domains[names[i].domain_index].short_name,
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 */
{
wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
struct wbcLogonUserParams params;
- struct wbcAuthErrorInfo *error;
+ struct wbcAuthErrorInfo *error = NULL;
char *s = NULL;
char *p = NULL;
TALLOC_CTX *frame = talloc_tos();
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",
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;
/* 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)
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 },
break;
case 'P':
if (!wbinfo_ping_dc()) {
- d_fprintf(stderr, "Could not ping our DC\n");
goto done;
}
break;
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");