s3-rpc_client: move protos to cli_lsarpc.h
[Samba/ekacnet.git] / source3 / auth / user_info.c
blobeb84a369f5ff3f1a184aa8b8b30a6ce8e5fde247
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"
22 #undef DBGC_CLASS
23 #define DBGC_CLASS DBGC_AUTH
25 /****************************************************************************
26 Create an auth_usersupplied_data structure
27 ****************************************************************************/
29 NTSTATUS make_user_info(struct auth_usersupplied_info **user_info,
30 const char *smb_name,
31 const char *internal_username,
32 const char *client_domain,
33 const char *domain,
34 const char *wksta_name,
35 const DATA_BLOB *lm_pwd,
36 const DATA_BLOB *nt_pwd,
37 const DATA_BLOB *lm_interactive_pwd,
38 const DATA_BLOB *nt_interactive_pwd,
39 const DATA_BLOB *plaintext,
40 bool encrypted)
43 DEBUG(5,("attempting to make a user_info for %s (%s)\n", internal_username, smb_name));
45 *user_info = SMB_MALLOC_P(struct auth_usersupplied_info);
46 if (*user_info == NULL) {
47 DEBUG(0,("malloc failed for user_info (size %lu)\n", (unsigned long)sizeof(*user_info)));
48 return NT_STATUS_NO_MEMORY;
51 ZERO_STRUCTP(*user_info);
53 DEBUG(5,("making strings for %s's user_info struct\n", internal_username));
55 (*user_info)->smb_name = SMB_STRDUP(smb_name);
56 if ((*user_info)->smb_name == NULL) {
57 free_user_info(user_info);
58 return NT_STATUS_NO_MEMORY;
61 (*user_info)->internal_username = SMB_STRDUP(internal_username);
62 if ((*user_info)->internal_username == NULL) {
63 free_user_info(user_info);
64 return NT_STATUS_NO_MEMORY;
67 (*user_info)->domain = SMB_STRDUP(domain);
68 if ((*user_info)->domain == NULL) {
69 free_user_info(user_info);
70 return NT_STATUS_NO_MEMORY;
73 (*user_info)->client_domain = SMB_STRDUP(client_domain);
74 if ((*user_info)->client_domain == NULL) {
75 free_user_info(user_info);
76 return NT_STATUS_NO_MEMORY;
79 (*user_info)->wksta_name = SMB_STRDUP(wksta_name);
80 if ((*user_info)->wksta_name == NULL) {
81 free_user_info(user_info);
82 return NT_STATUS_NO_MEMORY;
85 DEBUG(5,("making blobs for %s's user_info struct\n", internal_username));
87 if (lm_pwd)
88 (*user_info)->lm_resp = data_blob(lm_pwd->data, lm_pwd->length);
89 if (nt_pwd)
90 (*user_info)->nt_resp = data_blob(nt_pwd->data, nt_pwd->length);
91 if (lm_interactive_pwd)
92 (*user_info)->lm_interactive_pwd = data_blob(lm_interactive_pwd->data, lm_interactive_pwd->length);
93 if (nt_interactive_pwd)
94 (*user_info)->nt_interactive_pwd = data_blob(nt_interactive_pwd->data, nt_interactive_pwd->length);
96 if (plaintext)
97 (*user_info)->plaintext_password = data_blob(plaintext->data, plaintext->length);
99 (*user_info)->encrypted = encrypted;
101 (*user_info)->logon_parameters = 0;
103 DEBUG(10,("made an %sencrypted user_info for %s (%s)\n", encrypted ? "":"un" , internal_username, smb_name));
105 return NT_STATUS_OK;
108 /***************************************************************************
109 Free a user_info struct
110 ***************************************************************************/
112 void free_user_info(struct auth_usersupplied_info **user_info)
114 DEBUG(5,("attempting to free (and zero) a user_info structure\n"));
115 if (*user_info != NULL) {
116 if ((*user_info)->smb_name) {
117 DEBUG(10,("structure was created for %s\n",
118 (*user_info)->smb_name));
120 SAFE_FREE((*user_info)->smb_name);
121 SAFE_FREE((*user_info)->internal_username);
122 SAFE_FREE((*user_info)->client_domain);
123 SAFE_FREE((*user_info)->domain);
124 SAFE_FREE((*user_info)->wksta_name);
125 data_blob_free(&(*user_info)->lm_resp);
126 data_blob_free(&(*user_info)->nt_resp);
127 data_blob_clear_free(&(*user_info)->lm_interactive_pwd);
128 data_blob_clear_free(&(*user_info)->nt_interactive_pwd);
129 data_blob_clear_free(&(*user_info)->plaintext_password);
130 ZERO_STRUCT(**user_info);
132 SAFE_FREE(*user_info);