Winbind status program.
Copyright (C) Tim Potter 2000-2003
- Copyright (C) Andrew Bartlett 2002
+ Copyright (C) Andrew Bartlett 2002-2007
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
#include "includes.h"
#include "winbind_client.h"
#include "libwbclient/wbclient.h"
+#include "lib/popt/popt.h"
#include "../libcli/auth/libcli_auth.h"
+#if !(_SAMBA_VERSION_) < 4
+#include "lib/cmdline/popt_common.h"
+#endif
+#ifdef DBGC_CLASS
#undef DBGC_CLASS
#define DBGC_CLASS DBGC_WINBIND
+#endif
static struct wbcInterfaceDetails *init_interface_details(void)
{
return details->netbios_domain;
}
+static const char *get_winbind_netbios_name(void)
+{
+ static struct wbcInterfaceDetails *details;
+
+ details = init_interface_details();
+
+ if (!details) {
+ d_fprintf(stderr, "could not obtain winbind netbios name!\n");
+ return 0;
+ }
+
+ return details->netbios_name;
+}
+
/* Copy of parse_domain_user from winbindd_util.c. Parse a string of the
form DOMAIN/user into a domain and a user */
/* Check trust account password */
-static bool wbinfo_check_secret(void)
+static bool wbinfo_check_secret(const char *domain)
{
wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
struct wbcAuthErrorInfo *error = NULL;
+ const char *domain_name;
+
+ if (domain) {
+ domain_name = domain;
+ } else {
+ domain_name = get_winbind_domain();
+ }
- wbc_status = wbcCheckTrustCredentials(NULL, &error);
+ wbc_status = wbcCheckTrustCredentials(domain_name, &error);
- d_printf("checking the trust secret via RPC calls %s\n",
- WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
+ d_printf("checking the trust secret for domain %s via RPC calls %s\n",
+ domain_name,
+ 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);
+ }
+ if (!WBC_ERROR_IS_OK(wbc_status)) {
+ return false;
+ }
+
+ return true;
+}
+
+/* Change trust account password */
+
+static bool wbinfo_change_secret(const char *domain)
+{
+ wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
+ struct wbcAuthErrorInfo *error = NULL;
+ const char *domain_name;
+
+ if (domain) {
+ domain_name = domain;
+ } else {
+ domain_name = get_winbind_domain();
+ }
+
+ wbc_status = wbcChangeTrustCredentials(domain_name, &error);
+
+ d_printf("changing the trust secret for domain %s via RPC calls %s\n",
+ domain_name,
+ 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",
for (i=0; i<num_rids; i++) {
d_printf("%8d: %s (%s)\n", rids[i], names[i],
- sid_type_lookup(types[i]));
+ wbcSidTypeString(types[i]));
}
ret = true;
/* Display response */
- d_printf("%s %s (%d)\n", sid_str, sid_type_lookup(type), type);
+ d_printf("%s %s (%d)\n", sid_str, wbcSidTypeString(type), type);
wbcFreeMemory(sid_str);
return true;
}
-static char *wbinfo_prompt_pass(const char *prefix,
+static char *wbinfo_prompt_pass(TALLOC_CTX *mem_ctx,
+ const char *prefix,
const char *username)
{
char *prompt;
const char *ret = NULL;
- prompt = talloc_asprintf(talloc_tos(), "Enter %s's ", username);
+ prompt = talloc_asprintf(mem_ctx, "Enter %s's ", username);
if (!prompt) {
return NULL;
}
ret = getpass(prompt);
TALLOC_FREE(prompt);
- return SMB_STRDUP(ret);
+ return talloc_strdup(mem_ctx, ret);
}
/* Authenticate a user with a plaintext password */
char *p = NULL;
char *password = NULL;
char *name = NULL;
+ char *local_cctype = NULL;
uid_t uid;
struct wbcLogonUserParams params;
struct wbcLogonUserInfo *info;
struct wbcAuthErrorInfo *error;
struct wbcUserPasswordPolicyInfo *policy;
+ TALLOC_CTX *frame = talloc_tos();
- if ((s = SMB_STRDUP(username)) == NULL) {
+ if ((s = talloc_strdup(frame, username)) == NULL) {
return false;
}
if ((p = strchr(s, '%')) != NULL) {
*p = 0;
p++;
- password = SMB_STRDUP(p);
+ password = talloc_strdup(frame, p);
} else {
- password = wbinfo_prompt_pass(NULL, username);
+ password = wbinfo_prompt_pass(frame, NULL, username);
}
+ local_cctype = talloc_strdup(frame, cctype);
+
name = s;
uid = geteuid();
¶ms.blobs,
"krb5_cc_type",
0,
- (uint8_t *)cctype,
+ (uint8_t *)local_cctype,
strlen(cctype)+1);
if (!WBC_ERROR_IS_OK(wbc_status)) {
goto done;
}
done:
- SAFE_FREE(s);
- SAFE_FREE(password);
wbcFreeMemory(params.blobs);
return WBC_ERROR_IS_OK(wbc_status);
char *p = NULL;
char *password = NULL;
char *name = NULL;
+ TALLOC_CTX *frame = talloc_tos();
- if ((s = SMB_STRDUP(username)) == NULL) {
+ if ((s = talloc_strdup(frame, username)) == NULL) {
return false;
}
if ((p = strchr(s, '%')) != NULL) {
*p = 0;
p++;
- password = SMB_STRDUP(p);
+ password = talloc_strdup(frame, p);
} else {
- password = wbinfo_prompt_pass(NULL, username);
+ password = wbinfo_prompt_pass(frame, NULL, username);
}
name = s;
response.data.auth.error_string);
#endif
- SAFE_FREE(s);
- SAFE_FREE(password);
-
return WBC_ERROR_IS_OK(wbc_status);
}
fstring name_domain;
char *pass;
char *p;
+ TALLOC_CTX *frame = talloc_tos();
p = strchr(username, '%');
if (p) {
*p = 0;
- pass = SMB_STRDUP(p + 1);
+ pass = talloc_strdup(frame, p + 1);
} else {
- pass = wbinfo_prompt_pass(NULL, username);
+ pass = wbinfo_prompt_pass(frame, NULL, username);
}
parse_wbinfo_domain_user(username, name_domain, name_user);
server_chal = data_blob(params.password.response.challenge, 8);
/* Pretend this is a login to 'us', for blob purposes */
- names_blob = NTLMv2_generate_names_blob(NULL, global_myname(),
- get_winbind_domain());
+ names_blob = NTLMv2_generate_names_blob(NULL,
+ get_winbind_netbios_name(),
+ get_winbind_domain());
if (!SMBNTLMv2encrypt(NULL, name_user, name_domain, pass,
&server_chal,
&lm, &nt, NULL, NULL)) {
data_blob_free(&names_blob);
data_blob_free(&server_chal);
- SAFE_FREE(pass);
+ TALLOC_FREE(pass);
return false;
}
data_blob_free(&names_blob);
data_blob_free(&nt);
data_blob_free(&lm);
- SAFE_FREE(pass);
return WBC_ERROR_IS_OK(wbc_status);
}
+#ifdef WITH_FAKE_KASERVER
/* Authenticate a user with a plaintext password and set a token */
static bool wbinfo_klog(char *username)
d_printf("Successfully created AFS token\n");
return true;
}
+#else
+static bool wbinfo_klog(char *username)
+{
+ d_fprintf(stderr, "No AFS support compiled in.\n");
+ return false;
+}
+#endif
/* Print domain users */
wbcErr wbc_status;
char *old_password = NULL;
char *new_password = NULL;
+ TALLOC_CTX *frame = talloc_tos();
- old_password = wbinfo_prompt_pass("old", username);
- new_password = wbinfo_prompt_pass("new", username);
+ old_password = wbinfo_prompt_pass(frame, "old", username);
+ new_password = wbinfo_prompt_pass(frame, "new", username);
wbc_status = wbcChangeUserPassword(username, old_password,new_password);
d_printf("Password change for user %s %s\n", username,
WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
- SAFE_FREE(old_password);
- SAFE_FREE(new_password);
-
return WBC_ERROR_IS_OK(wbc_status);
}
{ "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" },
{ "check-secret", 't', POPT_ARG_NONE, 0, 't', "Check shared secret" },
+ { "change-secret", 'c', POPT_ARG_NONE, 0, 'c', "Change shared secret" },
{ "trusted-domains", 'm', POPT_ARG_NONE, 0, 'm', "List trusted domains" },
{ "all-domains", 0, POPT_ARG_NONE, 0, OPT_LIST_ALL_DOMAINS, "List all domains (trusted and own domain)" },
{ "own-domain", 0, POPT_ARG_NONE, 0, OPT_LIST_OWN_DOMAIN, "List own domain" },
{ "change-user-password", 0, POPT_ARG_STRING, &string_arg, OPT_CHANGE_USER_PASSWORD, "Change the password for a user", NULL },
{ "ntlmv2", 0, POPT_ARG_NONE, 0, OPT_NTLMV2, "Use NTLMv2 cryptography for user authentication", NULL},
{ "lanman", 0, POPT_ARG_NONE, 0, OPT_LANMAN, "Use lanman cryptography for user authentication", NULL},
- POPT_COMMON_CONFIGFILE
POPT_COMMON_VERSION
POPT_TABLEEND
};
/* get the generic configuration parameters like --domain */
switch (opt) {
case OPT_VERBOSE:
- verbose = True;
+ verbose = true;
break;
case OPT_NTLMV2:
use_ntlmv2 = true;
poptFreeContext(pc);
- if (!init_names())
- return 1;
-
- load_interfaces();
-
pc = poptGetContext(NULL, argc, (const char **)argv, long_options,
POPT_CONTEXT_KEEP_FIRST);
}
break;
case 't':
- if (!wbinfo_check_secret()) {
+ if (!wbinfo_check_secret(opt_domain_name)) {
d_fprintf(stderr, "Could not check secret\n");
goto done;
}
break;
+ case 'c':
+ if (!wbinfo_change_secret(opt_domain_name)) {
+ d_fprintf(stderr, "Could not change secret\n");
+ goto done;
+ }
+ break;
case 'm':
if (!wbinfo_list_domains(false, verbose)) {
d_fprintf(stderr,
/* Exit code */
done:
- talloc_destroy(frame);
+ talloc_free(frame);
poptFreeContext(pc);
return result;