Lines 38-43
Link Here
|
38 |
* |
38 |
* |
39 |
* |
39 |
* |
40 |
* all str commands are 0x00 terminated string of chars. |
40 |
* all str commands are 0x00 terminated string of chars. |
|
|
41 |
* |
42 |
* Patched by Chris Jensen - 19 Aug 2004 |
43 |
* Clear passwords after first use |
44 |
* Overwrite passwords with 0x00 before freeing memory |
45 |
* Overwrite and free all passwords on server shutdown |
46 |
* Add --verbose option to prevent disconnection from terminal |
47 |
* and print debugging |
41 |
*/ |
48 |
*/ |
42 |
|
49 |
|
43 |
#include "version.h" |
50 |
#include "version.h" |
Lines 52-57
Link Here
|
52 |
char *value; |
59 |
char *value; |
53 |
} *root = 0; |
60 |
} *root = 0; |
54 |
|
61 |
|
|
|
62 |
/* clean_free_str |
63 |
Whipes a string to all 0 before freeing it |
64 |
Used to ensure passwords are not left in memory |
65 |
*/ |
66 |
void clean_free_str(char **ptr) |
67 |
{ |
68 |
if (*ptr) |
69 |
{ |
70 |
memset(*ptr, 0x00, strlen(*ptr)); |
71 |
free(*ptr); |
72 |
} |
73 |
|
74 |
*ptr = NULL; |
75 |
} |
76 |
|
55 |
int cache_store_entry(char *key, char *value) |
77 |
int cache_store_entry(char *key, char *value) |
56 |
{ |
78 |
{ |
57 |
// search from root to the end of the list... |
79 |
// search from root to the end of the list... |
Lines 63-69
Link Here
|
63 |
if(strcmp((*entry)->key, key) == 0) |
85 |
if(strcmp((*entry)->key, key) == 0) |
64 |
{ |
86 |
{ |
65 |
//printf("Already an entry for key %s\n", key); |
87 |
//printf("Already an entry for key %s\n", key); |
66 |
free((*entry)->value); |
88 |
clean_free_str(&((*entry)->value)); |
|
|
89 |
|
67 |
(*entry)->value = strdup(value); |
90 |
(*entry)->value = strdup(value); |
68 |
return 1; |
91 |
return 1; |
69 |
} |
92 |
} |
Lines 80-95
Link Here
|
80 |
return 0; |
103 |
return 0; |
81 |
} |
104 |
} |
82 |
|
105 |
|
|
|
106 |
/* scrub_memory |
107 |
Write 0x00 over all passwords stored in memory before shutting down |
108 |
*/ |
109 |
void scrub_memory(void) |
110 |
{ |
111 |
struct entry_t *entry = root; |
112 |
|
113 |
while (entry) |
114 |
{ |
115 |
clean_free_str(&(entry->key)); |
116 |
clean_free_str(&(entry->value)); |
117 |
|
118 |
entry = entry->next; |
119 |
} |
120 |
} |
121 |
|
83 |
char *cache_retrieve_entry(char *key) |
122 |
char *cache_retrieve_entry(char *key) |
84 |
{ |
123 |
{ |
85 |
struct entry_t *entry = root; |
124 |
struct entry_t *entry = root; |
|
|
125 |
char *password = NULL; |
86 |
|
126 |
|
87 |
while(entry) |
127 |
while(entry) |
88 |
{ |
128 |
{ |
89 |
//printf("%s, %s\n", entry->key, entry->value); |
129 |
//printf("%s, %s\n", entry->key, entry->value); |
90 |
if(strcmp(key, entry->key) == 0) |
130 |
if(strcmp(key, entry->key) == 0) |
91 |
{ |
131 |
{ |
92 |
return entry->value; |
132 |
if (entry->value) |
|
|
133 |
{ |
134 |
password = strdup(entry->value); |
135 |
|
136 |
clean_free_str(&(entry->value)); |
137 |
} |
138 |
return password; |
93 |
} |
139 |
} |
94 |
entry = entry->next; |
140 |
entry = entry->next; |
95 |
} |
141 |
} |
Lines 158-179
Link Here
|
158 |
return 1; |
204 |
return 1; |
159 |
} |
205 |
} |
160 |
|
206 |
|
161 |
// detach process... |
207 |
if ((argc > 1) && (((strcmp(argv[1], "--verbose") == 0) || |
162 |
cpid=fork(); |
208 |
(strcmp(argv[1], "-v") == 0)))) |
|
|
209 |
{ |
210 |
verbose = 1; |
211 |
} |
163 |
|
212 |
|
164 |
if(cpid != 0) |
213 |
if (!verbose) |
165 |
{ |
214 |
{ |
166 |
exit(0); |
215 |
// detach process... |
|
|
216 |
cpid=fork(); |
217 |
|
218 |
if(cpid != 0) |
219 |
{ |
220 |
exit(0); |
221 |
} |
222 |
setsid(); |
223 |
chdir("/"); |
167 |
} |
224 |
} |
168 |
setsid(); |
|
|
169 |
chdir("/"); |
170 |
|
225 |
|
171 |
fprintf(lock, "%d\n", getpid()); |
226 |
fprintf(lock, "%d\n", getpid()); |
|
|
227 |
|
172 |
fclose(lock); |
228 |
fclose(lock); |
173 |
close(0); |
|
|
174 |
close(1); |
175 |
close(2); |
176 |
|
229 |
|
|
|
230 |
if (!verbose) |
231 |
{ |
232 |
close(0); |
233 |
close(1); |
234 |
close(2); |
235 |
} |
177 |
|
236 |
|
178 |
log(LOG_INFO, "smbpwman daemon version %s ready\n", VERSION); |
237 |
log(LOG_INFO, "smbpwman daemon version %s ready\n", VERSION); |
179 |
while(1) |
238 |
while(1) |
Lines 241-246
Link Here
|
241 |
result = 0x00; |
300 |
result = 0x00; |
242 |
write(cs, &result, sizeof(result)); |
301 |
write(cs, &result, sizeof(result)); |
243 |
write(cs, password, strlen(password) + 1); |
302 |
write(cs, password, strlen(password) + 1); |
|
|
303 |
clean_free_str(&password); |
244 |
} |
304 |
} |
245 |
else |
305 |
else |
246 |
{ |
306 |
{ |
Lines 255-260
Link Here
|
255 |
printf("SHUTDOWN\n"); |
315 |
printf("SHUTDOWN\n"); |
256 |
} |
316 |
} |
257 |
log(LOG_INFO, "shutdown request. daemon terminating\n"); |
317 |
log(LOG_INFO, "shutdown request. daemon terminating\n"); |
|
|
318 |
scrub_memory(); |
258 |
return 0; |
319 |
return 0; |
259 |
break; |
320 |
break; |
260 |
|
321 |
|