s3:libsmb: add tstream_cli_np_use_trans() and the needed logic
[Samba/gebeck_regimport.git] / source3 / auth / user_info.c
blob3d4ee08b9f6a0b15782af0315de910508d985ac6
1 /*
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/>.
20 #include "includes.h"
21 #include "librpc/gen_ndr/samr.h"
23 #undef DBGC_CLASS
24 #define DBGC_CLASS DBGC_AUTH
26 static int clear_samr_Password(struct samr_Password *password)
28 memset(password->hash, '\0', sizeof(password->hash));
29 return 0;
32 static int clear_string(char *password)
34 memset(password, '\0', strlen(password));
35 return 0;
38 /****************************************************************************
39 Create an auth_usersupplied_data structure
40 ****************************************************************************/
42 NTSTATUS make_user_info(struct auth_usersupplied_info **ret_user_info,
43 const char *smb_name,
44 const char *internal_username,
45 const char *client_domain,
46 const char *domain,
47 const char *workstation_name,
48 const DATA_BLOB *lm_pwd,
49 const DATA_BLOB *nt_pwd,
50 const struct samr_Password *lm_interactive_pwd,
51 const struct samr_Password *nt_interactive_pwd,
52 const char *plaintext_password,
53 enum auth_password_state password_state)
55 struct auth_usersupplied_info *user_info;
56 *ret_user_info = NULL;
58 DEBUG(5,("attempting to make a user_info for %s (%s)\n", internal_username, smb_name));
60 /* FIXME: Have the caller provide a talloc context of the
61 * correct lifetime (possibly talloc_tos(), but it depends on
62 * the caller) */
63 user_info = talloc_zero(NULL, struct auth_usersupplied_info);
64 if (user_info == NULL) {
65 DEBUG(0,("talloc failed for user_info\n"));
66 return NT_STATUS_NO_MEMORY;
69 DEBUG(5,("making strings for %s's user_info struct\n", internal_username));
71 user_info->client.account_name = talloc_strdup(user_info, smb_name);
72 NT_STATUS_HAVE_NO_MEMORY_AND_FREE(user_info->client.account_name, user_info);
74 user_info->mapped.account_name = talloc_strdup(user_info, internal_username);
75 NT_STATUS_HAVE_NO_MEMORY_AND_FREE(user_info->mapped.account_name, user_info);
77 user_info->mapped.domain_name = talloc_strdup(user_info, domain);
78 NT_STATUS_HAVE_NO_MEMORY_AND_FREE(user_info->mapped.domain_name, user_info);
80 user_info->client.domain_name = talloc_strdup(user_info, client_domain);
81 NT_STATUS_HAVE_NO_MEMORY_AND_FREE(user_info->client.domain_name, user_info);
83 user_info->workstation_name = talloc_strdup(user_info, workstation_name);
84 NT_STATUS_HAVE_NO_MEMORY_AND_FREE(user_info->workstation_name, user_info);
86 DEBUG(5,("making blobs for %s's user_info struct\n", internal_username));
88 if (lm_pwd && lm_pwd->data) {
89 user_info->password.response.lanman = data_blob_talloc(user_info, lm_pwd->data, lm_pwd->length);
90 NT_STATUS_HAVE_NO_MEMORY_AND_FREE(user_info->password.response.lanman.data, user_info);
92 if (nt_pwd && nt_pwd->data) {
93 user_info->password.response.nt = data_blob_talloc(user_info, nt_pwd->data, nt_pwd->length);
94 NT_STATUS_HAVE_NO_MEMORY_AND_FREE(user_info->password.response.nt.data, user_info);
96 if (lm_interactive_pwd) {
97 user_info->password.hash.lanman = talloc(user_info, struct samr_Password);
98 NT_STATUS_HAVE_NO_MEMORY_AND_FREE(user_info->password.hash.lanman, user_info);
99 memcpy(user_info->password.hash.lanman->hash, lm_interactive_pwd->hash,
100 sizeof(user_info->password.hash.lanman->hash));
101 talloc_set_destructor(user_info->password.hash.lanman, clear_samr_Password);
104 if (nt_interactive_pwd) {
105 user_info->password.hash.nt = talloc(user_info, struct samr_Password);
106 NT_STATUS_HAVE_NO_MEMORY_AND_FREE(user_info->password.hash.nt, user_info);
107 memcpy(user_info->password.hash.nt->hash, nt_interactive_pwd->hash,
108 sizeof(user_info->password.hash.nt->hash));
109 talloc_set_destructor(user_info->password.hash.nt, clear_samr_Password);
112 if (plaintext_password) {
113 user_info->password.plaintext = talloc_strdup(user_info, plaintext_password);
114 NT_STATUS_HAVE_NO_MEMORY_AND_FREE(user_info->password.plaintext, user_info);
115 talloc_set_destructor(user_info->password.plaintext, clear_string);
118 user_info->password_state = password_state;
120 user_info->logon_parameters = 0;
122 DEBUG(10,("made a user_info for %s (%s)\n", internal_username, smb_name));
123 *ret_user_info = user_info;
124 return NT_STATUS_OK;
127 /***************************************************************************
128 Free a user_info struct
129 ***************************************************************************/
131 void free_user_info(struct auth_usersupplied_info **user_info)
133 TALLOC_FREE(*user_info);