Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 67060 | Differences between
and this patch

Collapse All | Expand All

(-)smbpwman-0.5.orig/smbpw.h (+3 lines)
Lines 46-50 Link Here
46
int store(char *username, char *password);
46
int store(char *username, char *password);
47
char *retrieve(char *username);
47
char *retrieve(char *username);
48
int shutdown_server(void);
48
int shutdown_server(void);
49
#ifdef DEBUG
50
void dump(void);
51
#endif /* DEBUG */
49
52
50
#endif
53
#endif
(-)smbpwman-0.5.orig/smbpwcommon.c (+13 lines)
Lines 249-254 Link Here
249
	return 0;
249
	return 0;
250
}
250
}
251
251
252
#ifdef DEBUG
253
void dump(void)
254
{
255
	int cs;
256
	char command = 0x03;
257
258
	cs = unix_connect(SOCKET_NAME);
259
260
	write(cs, &command, sizeof(command));
261
	close(cs);
262
}
263
#endif /* DEBUG */
264
252
char *retrieve(char *username)
265
char *retrieve(char *username)
253
{
266
{
254
	int cs;
267
	int cs;
(-)smbpwman-0.5.orig/smbpwman.c (-1 / +56 lines)
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;
(-)smbpwman-0.5.orig/smbpwtest.c (+17 lines)
Lines 35-45 Link Here
35
		}
35
		}
36
	
36
	
37
	}
37
	}
38
#ifdef DEBUG
39
	else if(argc == 2 && strcmp(argv[1], "--dump") == 0)
40
	{
41
		printf("Requesting dump.\n");
42
		dump();
43
	}
44
#endif /* DEBUG */
38
	else if(argc == 3 && strcmp(argv[1], "--store") == 0)
45
	else if(argc == 3 && strcmp(argv[1], "--store") == 0)
39
	{
46
	{
40
		password = getpass("Password: ");
47
		password = getpass("Password: ");
41
		store(argv[2], password);
48
		store(argv[2], password);
42
	}
49
	}
50
	else
51
	{
52
		printf("Usage:\n");
53
		printf("%s --store <username>\n", argv[0]);
54
		printf("%s --retrieve <username>\n", argv[0]);
55
		printf("%s --shutdown\n", argv[0]);
56
#ifdef DEBUG
57
		printf("%s --dump\n", argv[0]);
58
#endif /* DEBUG */
59
	}
43
60
44
	return 0;
61
	return 0;
45
62

Return to bug 67060