release 0.92.3
[cntlm.git] / auth.c
blob8714510879f60a3f8b140da2d7328ab3b5020903
1 /*
2 * Credentials related structures and routines for the main module of CNTLM
4 * CNTLM is free software; you can redistribute it and/or modify it under the
5 * terms of the GNU General Public License as published by the Free Software
6 * Foundation; either version 2 of the License, or (at your option) any later
7 * version.
9 * CNTLM is distributed in the hope that it will be useful, but WITHOUT ANY
10 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12 * details.
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
16 * St, Fifth Floor, Boston, MA 02110-1301, USA.
18 * Copyright (c) 2007 David Kubicek
22 #include <stdlib.h>
23 #include <stdio.h>
24 #include <string.h>
26 #include "utils.h"
27 #include "auth.h"
29 struct auth_s *new_auth(void) {
30 struct auth_s *tmp;
32 tmp = (struct auth_s *)malloc(sizeof(struct auth_s));
33 if (tmp == NULL)
34 return NULL;
36 memset(tmp->user, 0, MINIBUF_SIZE);
37 memset(tmp->domain, 0, MINIBUF_SIZE);
38 memset(tmp->workstation, 0, MINIBUF_SIZE);
39 memset(tmp->passntlm2, 0, MINIBUF_SIZE);
40 memset(tmp->passnt, 0, MINIBUF_SIZE);
41 memset(tmp->passlm, 0, MINIBUF_SIZE);
42 tmp->hashntlm2 = 1;
43 tmp->hashnt = 0;
44 tmp->hashlm = 0;
45 tmp->flags = 0;
47 return tmp;
50 struct auth_s *copy_auth(struct auth_s *dst, struct auth_s *src, int fullcopy) {
51 dst->hashntlm2 = src->hashntlm2;
52 dst->hashnt = src->hashnt;
53 dst->hashlm = src->hashlm;
54 dst->flags = src->flags;
56 strlcpy(dst->domain, src->domain, MINIBUF_SIZE);
57 strlcpy(dst->workstation, src->workstation, MINIBUF_SIZE);
59 if (fullcopy) {
60 strlcpy(dst->user, src->user, MINIBUF_SIZE);
61 if (src->passntlm2)
62 memcpy(dst->passntlm2, src->passntlm2, MINIBUF_SIZE);
63 if (src->passnt)
64 memcpy(dst->passnt, src->passnt, MINIBUF_SIZE);
65 if (src->passlm)
66 memcpy(dst->passlm, src->passlm, MINIBUF_SIZE);
67 } else {
68 memset(dst->user, 0, MINIBUF_SIZE);
69 memset(dst->passntlm2, 0, MINIBUF_SIZE);
70 memset(dst->passnt, 0, MINIBUF_SIZE);
71 memset(dst->passlm, 0, MINIBUF_SIZE);
74 return dst;
77 struct auth_s *dup_auth(struct auth_s *creds, int fullcopy) {
78 struct auth_s *tmp;
80 tmp = new_auth();
81 if (tmp == NULL)
82 return NULL;
84 return copy_auth(tmp, creds, fullcopy);
87 void dump_auth(struct auth_s *creds) {
88 char *tmp;
90 printf("Credentials structure dump:\n");
91 if (creds == NULL) {
92 printf("Struct is not allocated!\n");
93 return;
96 printf("User: %s\n", creds->user);
97 printf("Domain: %s\n", creds->domain);
98 printf("Wks: %s\n", creds->workstation);
99 printf("HashNTLMv2: %d\n", creds->hashntlm2);
100 printf("HashNT: %d\n", creds->hashnt);
101 printf("HashLM: %d\n", creds->hashlm);
102 printf("Flags: %X\n", creds->flags);
103 if (creds->passntlm2) {
104 tmp = printmem(creds->passntlm2, 16, 8);
105 printf("PassNTLMv2: %s\n", tmp);
106 free(tmp);
109 if (creds->passnt) {
110 tmp = printmem(creds->passnt, 16, 8);
111 printf("PassNT: %s\n", tmp);
112 free(tmp);
115 if (creds->passlm) {
116 tmp = printmem(creds->passlm, 16, 8);
117 printf("PassLM: %s\n\n", tmp);
118 free(tmp);