1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-23 17:34:34 +03:00
samba-mirror/source3/winbindd/winbindd_creds.c
Günther Deschner 17ae9974f3 Fix gcc11 compiler issue "-Werror=stringop-overflow="
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14699

[3548/3991] Compiling source3/winbindd/winbindd_pam.c
../../source3/winbindd/winbindd_pam.c: In function ‘winbindd_dual_pam_auth_cached’:
../../source3/winbindd/winbindd_pam.c:1069:18: error: ‘winbindd_get_creds’ accessing 128 bytes in a region of size 8 [-Werror=stringop-overflow=]
 1069 |         result = winbindd_get_creds(domain,
      |                  ^~~~~~~~~~~~~~~~~~~~~~~~~~
 1070 |                                     state->mem_ctx,
      |                                     ~~~~~~~~~~~~~~~
 1071 |                                     &sid,
      |                                     ~~~~~
 1072 |                                     &my_info3,
      |                                     ~~~~~~~~~~
 1073 |                                     &cached_nt_pass,
      |                                     ~~~~~~~~~~~~~~~~
 1074 |                                     &cached_salt);
      |                                     ~~~~~~~~~~~~~
../../source3/winbindd/winbindd_pam.c:1069:18: note: referencing argument 5 of type ‘const uint8_t **’ {aka ‘const unsigned char **’}
../../source3/winbindd/winbindd_pam.c:1069:18: error: ‘winbindd_get_creds’ accessing 128 bytes in a region of size 8 [-Werror=stringop-overflow=]
../../source3/winbindd/winbindd_pam.c:1069:18: note: referencing argument 6 of type ‘const uint8_t **’ {aka ‘const unsigned char **’}
In file included from ../../source3/winbindd/winbindd.h:359,
                 from ../../source3/winbindd/winbindd_pam.c:26:
../../source3/winbindd/winbindd_proto.h:251:10: note: in a call to function ‘winbindd_get_creds’
  251 | NTSTATUS winbindd_get_creds(struct winbindd_domain *domain,
      |          ^~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors

Guenther

Signed-off-by: Guenther Deschner <gd@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
2021-05-07 06:23:32 +00:00

148 lines
3.5 KiB
C

/*
Unix SMB/CIFS implementation.
Winbind daemon - cached credentials funcions
Copyright (C) Guenther Deschner 2005
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "includes.h"
#include "winbindd.h"
#include "../libcli/auth/libcli_auth.h"
#include "../libcli/security/security.h"
#include "libsmb/samlogon_cache.h"
#undef DBGC_CLASS
#define DBGC_CLASS DBGC_WINBIND
#define MAX_CACHED_LOGINS 10
NTSTATUS winbindd_get_creds(struct winbindd_domain *domain,
TALLOC_CTX *mem_ctx,
const struct dom_sid *sid,
struct netr_SamInfo3 **info3,
const uint8_t **cached_nt_pass,
const uint8_t **cred_salt)
{
struct netr_SamInfo3 *info;
NTSTATUS status;
status = wcache_get_creds(domain, mem_ctx, sid, cached_nt_pass, cred_salt);
if (!NT_STATUS_IS_OK(status)) {
return status;
}
info = netsamlogon_cache_get(mem_ctx, sid);
if (info == NULL) {
return NT_STATUS_OBJECT_NAME_NOT_FOUND;
}
*info3 = info;
return NT_STATUS_OK;
}
NTSTATUS winbindd_store_creds(struct winbindd_domain *domain,
const char *user,
const char *pass,
struct netr_SamInfo3 *info3)
{
NTSTATUS status;
uchar nt_pass[NT_HASH_LEN];
struct dom_sid cred_sid;
if (info3 != NULL) {
sid_compose(&cred_sid, info3->base.domain_sid,
info3->base.rid);
info3->base.user_flags |= NETLOGON_CACHED_ACCOUNT;
} else if (user != NULL) {
/* do lookup ourself */
enum lsa_SidType type;
if (!lookup_cached_name(domain->name, /* namespace */
domain->name,
user,
&cred_sid,
&type)) {
return NT_STATUS_NO_SUCH_USER;
}
} else {
return NT_STATUS_INVALID_PARAMETER;
}
if (pass) {
int count = 0;
status = wcache_count_cached_creds(domain, &count);
if (!NT_STATUS_IS_OK(status)) {
return status;
}
DEBUG(11,("we have %d cached creds\n", count));
if (count + 1 > MAX_CACHED_LOGINS) {
DEBUG(10,("need to delete the oldest cached login\n"));
status = wcache_remove_oldest_cached_creds(domain, &cred_sid);
if (!NT_STATUS_IS_OK(status)) {
DEBUG(10,("failed to remove oldest cached cred: %s\n",
nt_errstr(status)));
return status;
}
}
E_md4hash(pass, nt_pass);
dump_data_pw("nt_pass", nt_pass, NT_HASH_LEN);
status = wcache_save_creds(domain, &cred_sid, nt_pass);
if (!NT_STATUS_IS_OK(status)) {
return status;
}
}
if (info3 != NULL && user != NULL) {
if (!netsamlogon_cache_store(user, info3)) {
return NT_STATUS_ACCESS_DENIED;
}
}
return NT_STATUS_OK;
}
NTSTATUS winbindd_update_creds_by_info3(struct winbindd_domain *domain,
const char *user,
const char *pass,
struct netr_SamInfo3 *info3)
{
return winbindd_store_creds(domain, user, pass, info3);
}
NTSTATUS winbindd_update_creds_by_name(struct winbindd_domain *domain,
const char *user,
const char *pass)
{
return winbindd_store_creds(domain, user, pass, NULL);
}