~ubuntu-branches/ubuntu/lucid/wpasupplicant/lucid-updates

« back to all changes in this revision

Viewing changes to ctrl_iface_unix.c

  • Committer: Bazaar Package Importer
  • Author(s): Kel Modderman
  • Date: 2006-10-05 08:04:01 UTC
  • mfrom: (1.1.5 upstream) (3 etch)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20061005080401-r8lqlix4390yos7b
Tags: 0.5.5-2
* Update madwifi headers to latest SVN. (Closes: #388316)
* Remove failed attempt at action locking. [debian/functions.sh,
  debian/wpa_action.sh]
* Add hysteresis checking functions, to avoid "event loops" while
  using wpa-roam. [debian/functions.sh, debian/wpa_action.sh]
* Change of co-maintainer email address.
* Add ishex() function to functions.sh to determine wpa-psk value type in
  plaintext or hex. This effectively eliminates the need for the bogus and
  somewhat confusing wpa-passphrase contruct specific to our scripts and
  allows wpa-psk to work with either a 8 to 63 character long plaintext
  string or 64 character long hex string.
* Adjust README.modes to not refer to the redundant wpa-passphrase stuff.
* Add big fat NOTE about acceptable wpa-psk's to top of example gallery.
* Strip surrounding quotes from wpa-ssid if present, instead of just whining
  about them.
* Update email address in copyright blurb of functions.sh, ifupdown.sh and
  wpa_action.sh.  

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
#include "includes.h"
16
16
#include <sys/un.h>
17
17
#include <sys/stat.h>
 
18
#include <grp.h>
18
19
 
19
20
#include "common.h"
20
21
#include "eloop.h"
188
189
{
189
190
        char *buf;
190
191
        size_t len;
 
192
        char *pbuf, *dir = NULL, *gid_str = NULL;
191
193
 
192
194
        if (wpa_s->conf->ctrl_interface == NULL)
193
195
                return NULL;
194
196
 
195
 
        len = strlen(wpa_s->conf->ctrl_interface) + strlen(wpa_s->ifname) + 2;
 
197
        pbuf = strdup(wpa_s->conf->ctrl_interface);
 
198
        if (pbuf == NULL)
 
199
                return NULL;
 
200
        if (strncmp(pbuf, "DIR=", 4) == 0) {
 
201
                dir = pbuf + 4;
 
202
                gid_str = strstr(dir, " GROUP=");
 
203
                if (gid_str) {
 
204
                        *gid_str = '\0';
 
205
                        gid_str += 7;
 
206
                }
 
207
        } else
 
208
                dir = pbuf;
 
209
 
 
210
        len = strlen(dir) + strlen(wpa_s->ifname) + 2;
196
211
        buf = malloc(len);
197
 
        if (buf == NULL)
 
212
        if (buf == NULL) {
 
213
                free(pbuf);
198
214
                return NULL;
 
215
        }
199
216
 
200
 
        snprintf(buf, len, "%s/%s",
201
 
                 wpa_s->conf->ctrl_interface, wpa_s->ifname);
 
217
        snprintf(buf, len, "%s/%s", dir, wpa_s->ifname);
202
218
#ifdef __CYGWIN__
203
219
        {
204
220
                /* Windows/WinPcap uses interface names that are not suitable
211
227
                }
212
228
        }
213
229
#endif /* __CYGWIN__ */
 
230
        free(pbuf);
214
231
        return buf;
215
232
}
216
233
 
221
238
        struct ctrl_iface_priv *priv;
222
239
        struct sockaddr_un addr;
223
240
        char *fname = NULL;
 
241
        gid_t gid = 0;
 
242
        int gid_set = 0;
 
243
        char *buf, *dir = NULL, *gid_str = NULL;
 
244
        struct group *grp;
 
245
        char *endp;
224
246
 
225
247
        priv = wpa_zalloc(sizeof(*priv));
226
248
        if (priv == NULL)
231
253
        if (wpa_s->conf->ctrl_interface == NULL)
232
254
                return priv;
233
255
 
234
 
        if (mkdir(wpa_s->conf->ctrl_interface, S_IRWXU | S_IRWXG) < 0) {
 
256
        buf = strdup(wpa_s->conf->ctrl_interface);
 
257
        if (buf == NULL)
 
258
                goto fail;
 
259
        if (strncmp(buf, "DIR=", 4) == 0) {
 
260
                dir = buf + 4;
 
261
                gid_str = strstr(dir, " GROUP=");
 
262
                if (gid_str) {
 
263
                        *gid_str = '\0';
 
264
                        gid_str += 7;
 
265
                }
 
266
        } else {
 
267
                dir = buf;
 
268
                gid_str = wpa_s->conf->ctrl_interface_group;
 
269
        }
 
270
 
 
271
        if (mkdir(dir, S_IRWXU | S_IRWXG) < 0) {
235
272
                if (errno == EEXIST) {
236
273
                        wpa_printf(MSG_DEBUG, "Using existing control "
237
274
                                   "interface directory.");
241
278
                }
242
279
        }
243
280
 
244
 
        if (wpa_s->conf->ctrl_interface_gid_set &&
245
 
            chown(wpa_s->conf->ctrl_interface, 0,
246
 
                  wpa_s->conf->ctrl_interface_gid) < 0) {
 
281
        if (gid_str) {
 
282
                grp = getgrnam(gid_str);
 
283
                if (grp) {
 
284
                        gid = grp->gr_gid;
 
285
                        gid_set = 1;
 
286
                        wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d"
 
287
                                   " (from group name '%s')",
 
288
                                   (int) gid, gid_str);
 
289
                } else {
 
290
                        /* Group name not found - try to parse this as gid */
 
291
                        gid = strtol(gid_str, &endp, 10);
 
292
                        if (*gid_str == '\0' || *endp != '\0') {
 
293
                                wpa_printf(MSG_DEBUG, "CTRL: Invalid group "
 
294
                                           "'%s'", gid_str);
 
295
                                goto fail;
 
296
                        }
 
297
                        gid_set = 1;
 
298
                        wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d",
 
299
                                   (int) gid);
 
300
                }
 
301
        }
 
302
 
 
303
        if (gid_set && chown(dir, -1, gid) < 0) {
247
304
                perror("chown[ctrl_interface]");
248
305
                goto fail;
249
306
        }
250
307
 
251
 
        if (strlen(wpa_s->conf->ctrl_interface) + 1 + strlen(wpa_s->ifname) >=
252
 
            sizeof(addr.sun_path))
 
308
        if (strlen(dir) + 1 + strlen(wpa_s->ifname) >= sizeof(addr.sun_path))
253
309
                goto fail;
254
310
 
255
311
        priv->sock = socket(PF_UNIX, SOCK_DGRAM, 0);
296
352
                }
297
353
        }
298
354
 
299
 
        if (wpa_s->conf->ctrl_interface_gid_set &&
300
 
            chown(fname, 0, wpa_s->conf->ctrl_interface_gid) < 0) {
 
355
        if (gid_set && chown(fname, -1, gid) < 0) {
301
356
                perror("chown[ctrl_interface/ifname]");
302
357
                goto fail;
303
358
        }
311
366
        eloop_register_read_sock(priv->sock, wpa_supplicant_ctrl_iface_receive,
312
367
                                 wpa_s, priv);
313
368
 
 
369
        free(buf);
314
370
        return priv;
315
371
 
316
372
fail:
321
377
                unlink(fname);
322
378
                free(fname);
323
379
        }
 
380
        free(buf);
324
381
        return NULL;
325
382
}
326
383
 
331
388
 
332
389
        if (priv->sock > -1) {
333
390
                char *fname;
 
391
                char *buf, *dir = NULL, *gid_str = NULL;
334
392
                eloop_unregister_read_sock(priv->sock);
335
393
                if (priv->ctrl_dst) {
336
394
                        /*
349
407
                        unlink(fname);
350
408
                free(fname);
351
409
 
352
 
                if (rmdir(priv->wpa_s->conf->ctrl_interface) < 0) {
 
410
                buf = strdup(priv->wpa_s->conf->ctrl_interface);
 
411
                if (buf == NULL)
 
412
                        goto free_dst;
 
413
                if (strncmp(buf, "DIR=", 4) == 0) {
 
414
                        dir = buf + 4;
 
415
                        gid_str = strstr(dir, " GROUP=");
 
416
                        if (gid_str) {
 
417
                                *gid_str = '\0';
 
418
                                gid_str += 7;
 
419
                        }
 
420
                } else
 
421
                        dir = buf;
 
422
 
 
423
                if (rmdir(dir) < 0) {
353
424
                        if (errno == ENOTEMPTY) {
354
425
                                wpa_printf(MSG_DEBUG, "Control interface "
355
426
                                           "directory not empty - leaving it "
358
429
                                perror("rmdir[ctrl_interface]");
359
430
                        }
360
431
                }
 
432
                free(buf);
361
433
        }
362
434
 
 
435
free_dst:
363
436
        dst = priv->ctrl_dst;
364
437
        while (dst) {
365
438
                prev = dst;