-
Notifications
You must be signed in to change notification settings - Fork 40
/
auth.c
127 lines (108 loc) · 3.4 KB
/
auth.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
* Credentials related structures and routines for the main module of CNTLM
*
* CNTLM 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 2 of the License, or (at your option) any later
* version.
*
* CNTLM 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, write to the Free Software Foundation, Inc., 51 Franklin
* St, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2007 David Kubicek
*
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "utils.h"
#include "auth.h"
struct auth_s *new_auth(void) {
struct auth_s *tmp;
tmp = (struct auth_s *)malloc(sizeof(struct auth_s));
if (tmp == NULL)
return NULL;
memset(tmp->user, 0, MINIBUF_SIZE);
memset(tmp->domain, 0, MINIBUF_SIZE);
memset(tmp->workstation, 0, MINIBUF_SIZE);
memset(tmp->passntlm2, 0, MINIBUF_SIZE);
memset(tmp->passnt, 0, MINIBUF_SIZE);
memset(tmp->passlm, 0, MINIBUF_SIZE);
#ifdef __CYGWIN__
memset(&tmp->sspi, 0, sizeof(struct sspi_handle));
#endif
tmp->hashntlm2 = 1;
tmp->hashnt = 0;
tmp->hashlm = 0;
tmp->flags = 0;
#if config_gss == 1
tmp->haskrb = 0;
#endif
return tmp;
}
struct auth_s *copy_auth(struct auth_s *dst, const struct auth_s *src, int fullcopy) {
dst->hashntlm2 = src->hashntlm2;
dst->hashnt = src->hashnt;
dst->hashlm = src->hashlm;
dst->flags = src->flags;
#if config_gss == 1
dst->haskrb = src->haskrb;
#endif
strlcpy(dst->domain, src->domain, MINIBUF_SIZE);
strlcpy(dst->workstation, src->workstation, MINIBUF_SIZE);
if (fullcopy) {
strlcpy(dst->user, src->user, MINIBUF_SIZE);
memcpy(dst->passntlm2, src->passntlm2, MINIBUF_SIZE);
memcpy(dst->passnt, src->passnt, MINIBUF_SIZE);
memcpy(dst->passlm, src->passlm, MINIBUF_SIZE);
} else {
memset(dst->user, 0, MINIBUF_SIZE);
memset(dst->passntlm2, 0, MINIBUF_SIZE);
memset(dst->passnt, 0, MINIBUF_SIZE);
memset(dst->passlm, 0, MINIBUF_SIZE);
}
return dst;
}
struct auth_s *dup_auth(const struct auth_s *creds, int fullcopy) {
struct auth_s *tmp;
tmp = new_auth();
if (tmp == NULL)
return NULL;
return copy_auth(tmp, creds, fullcopy);
}
void dump_auth(const struct auth_s *creds) {
char *tmp;
printf("Credentials structure dump:\n");
if (creds == NULL) {
printf("Struct is not allocated!\n");
return;
}
printf("User: %s\n", creds->user);
printf("Domain: %s\n", creds->domain);
printf("Wks: %s\n", creds->workstation);
printf("HashNTLMv2: %d\n", creds->hashntlm2);
printf("HashNT: %d\n", creds->hashnt);
printf("HashLM: %d\n", creds->hashlm);
printf("Flags: %X\n", creds->flags);
if (!is_memory_all_zero(creds->passntlm2, ARRAY_SIZE(creds->passntlm2))) {
tmp = printmem(creds->passntlm2, 16, 8);
printf("PassNTLMv2: %s\n", tmp);
free(tmp);
}
if (!is_memory_all_zero(creds->passnt, ARRAY_SIZE(creds->passnt))) {
tmp = printmem(creds->passnt, 16, 8);
printf("PassNT: %s\n", tmp);
free(tmp);
}
if (!is_memory_all_zero(creds->passlm, ARRAY_SIZE(creds->passlm))) {
tmp = printmem(creds->passlm, 16, 8);
printf("PassLM: %s\n\n", tmp);
free(tmp);
}
}