mirror of
https://github.com/samba-team/samba.git
synced 2025-09-12 13:44:19 +03:00
wbinfo: use wbcLogonUser for wbinfo -K.
Guenther
This commit is contained in:
@@ -1178,66 +1178,107 @@ static char *wbinfo_prompt_pass(const char *prefix,
|
|||||||
|
|
||||||
static bool wbinfo_auth_krb5(char *username, const char *cctype, uint32 flags)
|
static bool wbinfo_auth_krb5(char *username, const char *cctype, uint32 flags)
|
||||||
{
|
{
|
||||||
struct winbindd_request request;
|
wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
|
||||||
struct winbindd_response response;
|
char *s = NULL;
|
||||||
NSS_STATUS result;
|
char *p = NULL;
|
||||||
char *p;
|
char *password = NULL;
|
||||||
char *password;
|
char *name = NULL;
|
||||||
|
uid_t uid;
|
||||||
|
struct wbcLogonUserParams params;
|
||||||
|
struct wbcLogonUserInfo *info;
|
||||||
|
struct wbcAuthErrorInfo *error;
|
||||||
|
struct wbcUserPasswordPolicyInfo *policy;
|
||||||
|
|
||||||
/* Send off request */
|
if ((s = SMB_STRDUP(username)) == NULL) {
|
||||||
|
return false;
|
||||||
ZERO_STRUCT(request);
|
|
||||||
ZERO_STRUCT(response);
|
|
||||||
|
|
||||||
p = strchr(username, '%');
|
|
||||||
|
|
||||||
if (p) {
|
|
||||||
*p = 0;
|
|
||||||
fstrcpy(request.data.auth.user, username);
|
|
||||||
fstrcpy(request.data.auth.pass, p + 1);
|
|
||||||
*p = '%';
|
|
||||||
} else {
|
|
||||||
fstrcpy(request.data.auth.user, username);
|
|
||||||
password = wbinfo_prompt_pass(NULL, username);
|
|
||||||
fstrcpy(request.data.auth.pass, password);
|
|
||||||
SAFE_FREE(password);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
request.flags = flags;
|
if ((p = strchr(s, '%')) != NULL) {
|
||||||
|
*p = 0;
|
||||||
|
p++;
|
||||||
|
password = SMB_STRDUP(p);
|
||||||
|
} else {
|
||||||
|
password = wbinfo_prompt_pass(NULL, username);
|
||||||
|
}
|
||||||
|
|
||||||
fstrcpy(request.data.auth.krb5_cc_type, cctype);
|
name = s;
|
||||||
|
|
||||||
request.data.auth.uid = geteuid();
|
uid = geteuid();
|
||||||
|
|
||||||
result = winbindd_request_response(WINBINDD_PAM_AUTH, &request, &response);
|
params.username = name;
|
||||||
|
params.password = password;
|
||||||
|
params.num_blobs = 0;
|
||||||
|
params.blobs = NULL;
|
||||||
|
|
||||||
/* Display response */
|
wbc_status = wbcAddNamedBlob(¶ms.num_blobs,
|
||||||
|
¶ms.blobs,
|
||||||
|
"flags",
|
||||||
|
0,
|
||||||
|
(uint8_t *)&flags,
|
||||||
|
sizeof(flags));
|
||||||
|
if (!WBC_ERROR_IS_OK(wbc_status)) {
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
|
wbc_status = wbcAddNamedBlob(¶ms.num_blobs,
|
||||||
|
¶ms.blobs,
|
||||||
|
"user_uid",
|
||||||
|
0,
|
||||||
|
(uint8_t *)&uid,
|
||||||
|
sizeof(uid));
|
||||||
|
if (!WBC_ERROR_IS_OK(wbc_status)) {
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
|
wbc_status = wbcAddNamedBlob(¶ms.num_blobs,
|
||||||
|
¶ms.blobs,
|
||||||
|
"krb5_cc_type",
|
||||||
|
0,
|
||||||
|
(uint8_t *)cctype,
|
||||||
|
strlen(cctype)+1);
|
||||||
|
if (!WBC_ERROR_IS_OK(wbc_status)) {
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
|
wbc_status = wbcLogonUser(¶ms, &info, &error, &policy);
|
||||||
|
|
||||||
d_printf("plaintext kerberos password authentication for [%s] %s (requesting cctype: %s)\n",
|
d_printf("plaintext kerberos password authentication for [%s] %s (requesting cctype: %s)\n",
|
||||||
username, (result == NSS_STATUS_SUCCESS) ? "succeeded" : "failed", cctype);
|
username, WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed", cctype);
|
||||||
|
|
||||||
if (response.data.auth.nt_status)
|
if (error) {
|
||||||
d_fprintf(stderr, "error code was %s (0x%x)\nerror messsage was: %s\n",
|
d_fprintf(stderr, "error code was %s (0x%x)\nerror messsage was: %s\n",
|
||||||
response.data.auth.nt_status_string,
|
error->nt_string,
|
||||||
response.data.auth.nt_status,
|
error->nt_status,
|
||||||
response.data.auth.error_string);
|
error->display_string);
|
||||||
|
}
|
||||||
|
|
||||||
if (result == NSS_STATUS_SUCCESS) {
|
if (WBC_ERROR_IS_OK(wbc_status)) {
|
||||||
|
if (flags & WBFLAG_PAM_INFO3_TEXT) {
|
||||||
if (request.flags & WBFLAG_PAM_INFO3_TEXT) {
|
if (info && info->info && info->info->user_flags & NETLOGON_CACHED_ACCOUNT) {
|
||||||
if (response.data.auth.info3.user_flgs & NETLOGON_CACHED_ACCOUNT) {
|
|
||||||
d_printf("user_flgs: NETLOGON_CACHED_ACCOUNT\n");
|
d_printf("user_flgs: NETLOGON_CACHED_ACCOUNT\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response.data.auth.krb5ccname[0] != '\0') {
|
if (info) {
|
||||||
d_printf("credentials were put in: %s\n", response.data.auth.krb5ccname);
|
int i;
|
||||||
|
for (i=0; i < info->num_blobs; i++) {
|
||||||
|
if (strequal(info->blobs[i].name, "krb5ccname")) {
|
||||||
|
d_printf("credentials were put in: %s\n",
|
||||||
|
(const char *)info->blobs[i].blob.data);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
d_printf("no credentials cached\n");
|
d_printf("no credentials cached\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
done:
|
||||||
|
|
||||||
return result == NSS_STATUS_SUCCESS;
|
SAFE_FREE(s);
|
||||||
|
SAFE_FREE(password);
|
||||||
|
wbcFreeMemory(params.blobs);
|
||||||
|
|
||||||
|
return WBC_ERROR_IS_OK(wbc_status);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Authenticate a user with a plaintext password */
|
/* Authenticate a user with a plaintext password */
|
||||||
|
Reference in New Issue
Block a user