|
| 1 | +/* vim: set et sw=4 ts=4 sts=4 : */ |
1 | 2 | /********************************************************************\
|
2 | 3 | * This program is free software; you can redistribute it and/or *
|
3 | 4 | * modify it under the terms of the GNU General Public License as *
|
@@ -121,64 +122,64 @@ logout_client(t_client *client)
|
121 | 122 | void
|
122 | 123 | authenticate_client(request *r)
|
123 | 124 | {
|
124 |
| - t_client *client; |
| 125 | + t_client *client, *tmp; |
125 | 126 | t_authresponse auth_response;
|
126 |
| - char *mac, |
127 |
| - *token; |
| 127 | + char *token; |
128 | 128 | httpVar *var;
|
129 | 129 | char *urlFragment = NULL;
|
130 | 130 | s_config *config = NULL;
|
131 | 131 | t_auth_serv *auth_server = NULL;
|
132 | 132 |
|
133 | 133 | LOCK_CLIENT_LIST();
|
134 | 134 |
|
135 |
| - client = client_list_find_by_ip(r->clientAddr); |
| 135 | + client = client_dup(client_list_find_by_ip(r->clientAddr)); |
| 136 | + |
| 137 | + UNLOCK_CLIENT_LIST(); |
136 | 138 |
|
137 | 139 | if (client == NULL) {
|
138 | 140 | debug(LOG_ERR, "authenticate_client(): Could not find client for %s", r->clientAddr);
|
139 |
| - UNLOCK_CLIENT_LIST(); |
140 | 141 | return;
|
141 | 142 | }
|
142 | 143 |
|
143 |
| - mac = safe_strdup(client->mac); |
144 |
| - |
145 | 144 | /* Users could try to log in(so there is a valid token in
|
146 | 145 | * request) even after they have logged in, try to deal with
|
147 | 146 | * this */
|
148 | 147 | if ((var = httpdGetVariableByName(r, "token")) != NULL) {
|
149 |
| - if (client->token) |
150 |
| - free(client->token); |
151 |
| - |
152 |
| - client->token = safe_strdup(var->value); |
153 | 148 | token = safe_strdup(var->value);
|
154 | 149 | } else {
|
155 | 150 | token = safe_strdup(client->token);
|
156 | 151 | }
|
157 |
| - |
158 |
| - UNLOCK_CLIENT_LIST(); |
159 | 152 |
|
160 | 153 | /*
|
161 | 154 | * At this point we've released the lock while we do an HTTP request since it could
|
162 | 155 | * take multiple seconds to do and the gateway would effectively be frozen if we
|
163 | 156 | * kept the lock.
|
164 | 157 | */
|
165 |
| - auth_server_request(&auth_response, REQUEST_TYPE_LOGIN, r->clientAddr, mac, token, 0, 0); |
| 158 | + auth_server_request(&auth_response, REQUEST_TYPE_LOGIN, client->ip, client->mac, token, 0, 0); |
166 | 159 |
|
167 | 160 | LOCK_CLIENT_LIST();
|
168 | 161 |
|
169 | 162 | /* can't trust the client to still exist after n seconds have passed */
|
170 |
| - client = client_list_find(r->clientAddr, mac); |
| 163 | + tmp = client_list_find_by_client(client); |
171 | 164 |
|
172 |
| - if (client == NULL) { |
173 |
| - debug(LOG_ERR, "authenticate_client(): Could not find client node for %s (%s)", r->clientAddr, mac); |
| 165 | + if (NULL == tmp) { |
| 166 | + debug(LOG_ERR, "authenticate_client(): Could not find client node for %s (%s)", client->ip, client->mac); |
174 | 167 | UNLOCK_CLIENT_LIST();
|
| 168 | + client_list_destroy(client); /* Free the cloned client */ |
175 | 169 | free(token);
|
176 |
| - free(mac); |
177 | 170 | return;
|
178 | 171 | }
|
| 172 | + |
| 173 | + client_list_destroy(client); /* Free the cloned client */ |
| 174 | + client = tmp; |
179 | 175 |
|
180 |
| - free(token); |
181 |
| - free(mac); |
| 176 | + if (strcmp(token, client->token) != 0) { |
| 177 | + /* If token changed, save it. */ |
| 178 | + free(client->token); |
| 179 | + client->token = token; |
| 180 | + } else { |
| 181 | + free(token); |
| 182 | + } |
182 | 183 |
|
183 | 184 | /* Prepare some variables we'll need below */
|
184 | 185 | config = config_get_config();
|
|
0 commit comments