2
Unix SMB/CIFS implementation.
4
Winbind daemon - cached credentials funcions
6
Copyright (C) Guenther Deschner 2005
8
This program is free software; you can redistribute it and/or modify
9
it under the terms of the GNU General Public License as published by
10
the Free Software Foundation; either version 2 of the License, or
11
(at your option) any later version.
13
This program is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
GNU General Public License for more details.
18
You should have received a copy of the GNU General Public License
19
along with this program; if not, write to the Free Software
20
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26
#define DBGC_CLASS DBGC_WINBIND
28
#define MAX_CACHED_LOGINS 10
30
NTSTATUS winbindd_get_creds(struct winbindd_domain *domain,
33
NET_USER_INFO_3 **info3,
34
const uint8 *cached_nt_pass[NT_HASH_LEN])
36
NET_USER_INFO_3 *info;
39
status = wcache_get_creds(domain, mem_ctx, sid, cached_nt_pass);
40
if (!NT_STATUS_IS_OK(status)) {
44
info = netsamlogon_cache_get(mem_ctx, sid);
46
return NT_STATUS_OBJECT_NAME_NOT_FOUND;
55
NTSTATUS winbindd_store_creds(struct winbindd_domain *domain,
59
NET_USER_INFO_3 *info3,
60
const DOM_SID *user_sid)
63
uchar nt_pass[NT_HASH_LEN];
69
sid_copy(&sid, &(info3->dom_sid.sid));
70
sid_append_rid(&sid, info3->user_rid);
71
sid_copy(&cred_sid, &sid);
72
info3->user_flgs |= LOGON_CACHED_ACCOUNT;
74
} else if (user_sid != NULL) {
76
sid_copy(&cred_sid, user_sid);
78
} else if (user != NULL) {
80
/* do lookup ourself */
82
enum SID_NAME_USE type;
84
if (!lookup_cached_name(mem_ctx,
89
return NT_STATUS_NO_SUCH_USER;
92
return NT_STATUS_INVALID_PARAMETER;
99
status = wcache_count_cached_creds(domain, &count);
100
if (!NT_STATUS_IS_OK(status)) {
104
DEBUG(11,("we have %d cached creds\n", count));
106
if (count + 1 > MAX_CACHED_LOGINS) {
108
DEBUG(10,("need to delete the oldest cached login\n"));
110
status = wcache_remove_oldest_cached_creds(domain, &cred_sid);
111
if (!NT_STATUS_IS_OK(status)) {
112
DEBUG(10,("failed to remove oldest cached cred: %s\n",
118
E_md4hash(pass, nt_pass);
121
dump_data(100, (const char *)nt_pass, NT_HASH_LEN);
124
status = wcache_save_creds(domain, mem_ctx, &cred_sid, nt_pass);
125
if (!NT_STATUS_IS_OK(status)) {
130
if (info3 != NULL && user != NULL) {
131
if (!netsamlogon_cache_store(user, info3)) {
132
return NT_STATUS_ACCESS_DENIED;
139
NTSTATUS winbindd_update_creds_by_info3(struct winbindd_domain *domain,
143
NET_USER_INFO_3 *info3)
145
return winbindd_store_creds(domain, mem_ctx, user, pass, info3, NULL);
148
NTSTATUS winbindd_update_creds_by_sid(struct winbindd_domain *domain,
153
return winbindd_store_creds(domain, mem_ctx, NULL, pass, NULL, sid);
156
NTSTATUS winbindd_update_creds_by_name(struct winbindd_domain *domain,
161
return winbindd_store_creds(domain, mem_ctx, user, pass, NULL, NULL);