2
Unix SMB/CIFS implementation.
3
Authentication utility functions
4
Copyright (C) Volker Lendecke 2010
6
This program is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 3 of the License, or
9
(at your option) any later version.
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU General Public License for more details.
16
You should have received a copy of the GNU General Public License
17
along with this program. If not, see <http://www.gnu.org/licenses/>.
22
#include "librpc/gen_ndr/samr.h"
25
#define DBGC_CLASS DBGC_AUTH
27
static int clear_samr_Password(struct samr_Password *password)
29
memset(password->hash, '\0', sizeof(password->hash));
33
static int clear_string(char *password)
35
memset(password, '\0', strlen(password));
39
/****************************************************************************
40
Create an auth_usersupplied_data structure
41
****************************************************************************/
43
NTSTATUS make_user_info(struct auth_usersupplied_info **ret_user_info,
45
const char *internal_username,
46
const char *client_domain,
48
const char *workstation_name,
49
const DATA_BLOB *lm_pwd,
50
const DATA_BLOB *nt_pwd,
51
const struct samr_Password *lm_interactive_pwd,
52
const struct samr_Password *nt_interactive_pwd,
53
const char *plaintext_password,
54
enum auth_password_state password_state)
56
struct auth_usersupplied_info *user_info;
57
*ret_user_info = NULL;
59
DEBUG(5,("attempting to make a user_info for %s (%s)\n", internal_username, smb_name));
61
/* FIXME: Have the caller provide a talloc context of the
62
* correct lifetime (possibly talloc_tos(), but it depends on
64
user_info = talloc_zero(NULL, struct auth_usersupplied_info);
65
if (user_info == NULL) {
66
DEBUG(0,("talloc failed for user_info\n"));
67
return NT_STATUS_NO_MEMORY;
70
DEBUG(5,("making strings for %s's user_info struct\n", internal_username));
72
user_info->client.account_name = talloc_strdup(user_info, smb_name);
73
NT_STATUS_HAVE_NO_MEMORY_AND_FREE(user_info->client.account_name, user_info);
75
user_info->mapped.account_name = talloc_strdup(user_info, internal_username);
76
NT_STATUS_HAVE_NO_MEMORY_AND_FREE(user_info->mapped.account_name, user_info);
78
user_info->mapped.domain_name = talloc_strdup(user_info, domain);
79
NT_STATUS_HAVE_NO_MEMORY_AND_FREE(user_info->mapped.domain_name, user_info);
81
user_info->client.domain_name = talloc_strdup(user_info, client_domain);
82
NT_STATUS_HAVE_NO_MEMORY_AND_FREE(user_info->client.domain_name, user_info);
84
user_info->workstation_name = talloc_strdup(user_info, workstation_name);
85
NT_STATUS_HAVE_NO_MEMORY_AND_FREE(user_info->workstation_name, user_info);
87
DEBUG(5,("making blobs for %s's user_info struct\n", internal_username));
89
if (lm_pwd && lm_pwd->data) {
90
user_info->password.response.lanman = data_blob_talloc(user_info, lm_pwd->data, lm_pwd->length);
91
NT_STATUS_HAVE_NO_MEMORY_AND_FREE(user_info->password.response.lanman.data, user_info);
93
if (nt_pwd && nt_pwd->data) {
94
user_info->password.response.nt = data_blob_talloc(user_info, nt_pwd->data, nt_pwd->length);
95
NT_STATUS_HAVE_NO_MEMORY_AND_FREE(user_info->password.response.nt.data, user_info);
97
if (lm_interactive_pwd) {
98
user_info->password.hash.lanman = talloc(user_info, struct samr_Password);
99
NT_STATUS_HAVE_NO_MEMORY_AND_FREE(user_info->password.hash.lanman, user_info);
100
memcpy(user_info->password.hash.lanman->hash, lm_interactive_pwd->hash,
101
sizeof(user_info->password.hash.lanman->hash));
102
talloc_set_destructor(user_info->password.hash.lanman, clear_samr_Password);
105
if (nt_interactive_pwd) {
106
user_info->password.hash.nt = talloc(user_info, struct samr_Password);
107
NT_STATUS_HAVE_NO_MEMORY_AND_FREE(user_info->password.hash.nt, user_info);
108
memcpy(user_info->password.hash.nt->hash, nt_interactive_pwd->hash,
109
sizeof(user_info->password.hash.nt->hash));
110
talloc_set_destructor(user_info->password.hash.nt, clear_samr_Password);
113
if (plaintext_password) {
114
user_info->password.plaintext = talloc_strdup(user_info, plaintext_password);
115
NT_STATUS_HAVE_NO_MEMORY_AND_FREE(user_info->password.plaintext, user_info);
116
talloc_set_destructor(user_info->password.plaintext, clear_string);
119
user_info->password_state = password_state;
121
user_info->logon_parameters = 0;
123
DEBUG(10,("made a user_info for %s (%s)\n", internal_username, smb_name));
124
*ret_user_info = user_info;
128
/***************************************************************************
129
Free a user_info struct
130
***************************************************************************/
132
void free_user_info(struct auth_usersupplied_info **user_info)
134
TALLOC_FREE(*user_info);