Lines 45-50
Link Here
|
45 |
* Overwrite and free all passwords on server shutdown |
45 |
* Overwrite and free all passwords on server shutdown |
46 |
* Add --verbose option to prevent disconnection from terminal |
46 |
* Add --verbose option to prevent disconnection from terminal |
47 |
* and print debugging |
47 |
* and print debugging |
|
|
48 |
* Patched by Chris Jensen - 20 Aug 2004 |
49 |
* Fix race condition in clearing passwords after 1 use |
50 |
* Add dump for server debugging |
51 |
* Free records completely when the password is cleared |
48 |
*/ |
52 |
*/ |
49 |
|
53 |
|
50 |
#include "version.h" |
54 |
#include "version.h" |
Lines 52-62
Link Here
|
52 |
#include <stdarg.h> |
56 |
#include <stdarg.h> |
53 |
#include <syslog.h> |
57 |
#include <syslog.h> |
54 |
|
58 |
|
|
|
59 |
/* Reference counter is necissary otherwise |
60 |
* the sequence store, store, retrieve, retrieve |
61 |
* results in the password being cleared from the |
62 |
* cache before the last retrieve command |
63 |
*/ |
55 |
struct entry_t |
64 |
struct entry_t |
56 |
{ |
65 |
{ |
57 |
struct entry_t *next; |
66 |
struct entry_t *next; |
58 |
char *key; |
67 |
char *key; |
59 |
char *value; |
68 |
char *value; |
|
|
69 |
int ref; /* reference counter */ |
60 |
} *root = 0; |
70 |
} *root = 0; |
61 |
|
71 |
|
62 |
/* clean_free_str |
72 |
/* clean_free_str |
Lines 84-89
Link Here
|
84 |
{ |
94 |
{ |
85 |
if(strcmp((*entry)->key, key) == 0) |
95 |
if(strcmp((*entry)->key, key) == 0) |
86 |
{ |
96 |
{ |
|
|
97 |
(*entry)->ref++; |
87 |
//printf("Already an entry for key %s\n", key); |
98 |
//printf("Already an entry for key %s\n", key); |
88 |
clean_free_str(&((*entry)->value)); |
99 |
clean_free_str(&((*entry)->value)); |
89 |
|
100 |
|
Lines 96-101
Link Here
|
96 |
// not already exist |
107 |
// not already exist |
97 |
new = malloc(sizeof(struct entry_t)); |
108 |
new = malloc(sizeof(struct entry_t)); |
98 |
new->next = 0; |
109 |
new->next = 0; |
|
|
110 |
new->ref=1; |
99 |
new->key = strdup(key); |
111 |
new->key = strdup(key); |
100 |
new->value = strdup(value); |
112 |
new->value = strdup(value); |
101 |
*entry = new; |
113 |
*entry = new; |
Lines 119-128
Link Here
|
119 |
} |
131 |
} |
120 |
} |
132 |
} |
121 |
|
133 |
|
|
|
134 |
#ifdef DEBUG |
135 |
/* cache_dump |
136 |
* Dump all cached users and passwords to |
137 |
* the console. |
138 |
* For obvious security reasons, this is only enabled if DEBUG is defined. |
139 |
*/ |
140 |
void cache_dump(void) |
141 |
{ |
142 |
struct entry_t *entry = root; |
143 |
int count = 0; |
144 |
|
145 |
while (entry) |
146 |
{ |
147 |
count++; |
148 |
printf("%i, User: %s, Password: %s, Ref: %i\n", |
149 |
count, entry->key, entry->value, |
150 |
entry->ref); |
151 |
|
152 |
entry = entry->next; |
153 |
} |
154 |
|
155 |
printf("Total: %i\n", count); |
156 |
} |
157 |
#endif |
158 |
|
122 |
char *cache_retrieve_entry(char *key) |
159 |
char *cache_retrieve_entry(char *key) |
123 |
{ |
160 |
{ |
124 |
struct entry_t *entry = root; |
161 |
struct entry_t *entry = root; |
125 |
char *password = NULL; |
162 |
char *password = NULL; |
|
|
163 |
struct entry_t **prev = &root; |
126 |
|
164 |
|
127 |
while(entry) |
165 |
while(entry) |
128 |
{ |
166 |
{ |
Lines 133-142
Link Here
|
133 |
{ |
171 |
{ |
134 |
password = strdup(entry->value); |
172 |
password = strdup(entry->value); |
135 |
|
173 |
|
136 |
clean_free_str(&(entry->value)); |
174 |
if ((--(entry->ref)) < 1) |
|
|
175 |
{ |
176 |
clean_free_str(&(entry->value)); |
177 |
|
178 |
*prev=entry->next; |
179 |
free(entry); |
180 |
} |
137 |
} |
181 |
} |
138 |
return password; |
182 |
return password; |
139 |
} |
183 |
} |
|
|
184 |
prev = &entry->next; |
140 |
entry = entry->next; |
185 |
entry = entry->next; |
141 |
} |
186 |
} |
142 |
return 0; |
187 |
return 0; |
Lines 318-323
Link Here
|
318 |
scrub_memory(); |
363 |
scrub_memory(); |
319 |
return 0; |
364 |
return 0; |
320 |
break; |
365 |
break; |
|
|
366 |
#ifdef DEBUG |
367 |
case 0x03: |
368 |
if(verbose) |
369 |
{ |
370 |
printf("DUMP\n"); |
371 |
log(LOG_WARNING, "smbpwman: performing dump of all users and passwords to terminal."); |
372 |
cache_dump(); |
373 |
} |
374 |
break; |
375 |
#endif /* DEBUG */ |
321 |
|
376 |
|
322 |
default: |
377 |
default: |
323 |
break; |
378 |
break; |