remove @EAP_LDFLAGS@, no longer exists
[mech_eap.orig] / libeap / wpa_supplicant / config_file.c
1 /*
2  * WPA Supplicant / Configuration backend: text file
3  * Copyright (c) 2003-2008, Jouni Malinen <j@w1.fi>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation.
8  *
9  * Alternatively, this software may be distributed under the terms of BSD
10  * license.
11  *
12  * See README and COPYING for more details.
13  *
14  * This file implements a configuration backend for text files. All the
15  * configuration information is stored in a text file that uses a format
16  * described in the sample configuration file, wpa_supplicant.conf.
17  */
18
19 #include "includes.h"
20
21 #include "common.h"
22 #include "config.h"
23 #include "base64.h"
24 #include "uuid.h"
25
26
27 /**
28  * wpa_config_get_line - Read the next configuration file line
29  * @s: Buffer for the line
30  * @size: The buffer length
31  * @stream: File stream to read from
32  * @line: Pointer to a variable storing the file line number
33  * @_pos: Buffer for the pointer to the beginning of data on the text line or
34  * %NULL if not needed (returned value used instead)
35  * Returns: Pointer to the beginning of data on the text line or %NULL if no
36  * more text lines are available.
37  *
38  * This function reads the next non-empty line from the configuration file and
39  * removes comments. The returned string is guaranteed to be null-terminated.
40  */
41 static char * wpa_config_get_line(char *s, int size, FILE *stream, int *line,
42                                   char **_pos)
43 {
44         char *pos, *end, *sstart;
45
46         while (fgets(s, size, stream)) {
47                 (*line)++;
48                 s[size - 1] = '\0';
49                 pos = s;
50
51                 /* Skip white space from the beginning of line. */
52                 while (*pos == ' ' || *pos == '\t' || *pos == '\r')
53                         pos++;
54
55                 /* Skip comment lines and empty lines */
56                 if (*pos == '#' || *pos == '\n' || *pos == '\0')
57                         continue;
58
59                 /*
60                  * Remove # comments unless they are within a double quoted
61                  * string.
62                  */
63                 sstart = os_strchr(pos, '"');
64                 if (sstart)
65                         sstart = os_strrchr(sstart + 1, '"');
66                 if (!sstart)
67                         sstart = pos;
68                 end = os_strchr(sstart, '#');
69                 if (end)
70                         *end-- = '\0';
71                 else
72                         end = pos + os_strlen(pos) - 1;
73
74                 /* Remove trailing white space. */
75                 while (end > pos &&
76                        (*end == '\n' || *end == ' ' || *end == '\t' ||
77                         *end == '\r'))
78                         *end-- = '\0';
79
80                 if (*pos == '\0')
81                         continue;
82
83                 if (_pos)
84                         *_pos = pos;
85                 return pos;
86         }
87
88         if (_pos)
89                 *_pos = NULL;
90         return NULL;
91 }
92
93
94 static int wpa_config_validate_network(struct wpa_ssid *ssid, int line)
95 {
96         int errors = 0;
97
98         if (ssid->passphrase) {
99                 if (ssid->psk_set) {
100                         wpa_printf(MSG_ERROR, "Line %d: both PSK and "
101                                    "passphrase configured.", line);
102                         errors++;
103                 }
104                 wpa_config_update_psk(ssid);
105         }
106
107         if ((ssid->key_mgmt & (WPA_KEY_MGMT_PSK | WPA_KEY_MGMT_FT_PSK |
108                                WPA_KEY_MGMT_PSK_SHA256)) &&
109             !ssid->psk_set) {
110                 wpa_printf(MSG_ERROR, "Line %d: WPA-PSK accepted for key "
111                            "management, but no PSK configured.", line);
112                 errors++;
113         }
114
115         if ((ssid->group_cipher & WPA_CIPHER_CCMP) &&
116             !(ssid->pairwise_cipher & WPA_CIPHER_CCMP) &&
117             !(ssid->pairwise_cipher & WPA_CIPHER_NONE)) {
118                 /* Group cipher cannot be stronger than the pairwise cipher. */
119                 wpa_printf(MSG_DEBUG, "Line %d: removed CCMP from group cipher"
120                            " list since it was not allowed for pairwise "
121                            "cipher", line);
122                 ssid->group_cipher &= ~WPA_CIPHER_CCMP;
123         }
124
125         return errors;
126 }
127
128
129 static struct wpa_ssid * wpa_config_read_network(FILE *f, int *line, int id)
130 {
131         struct wpa_ssid *ssid;
132         int errors = 0, end = 0;
133         char buf[256], *pos, *pos2;
134
135         wpa_printf(MSG_MSGDUMP, "Line: %d - start of a new network block",
136                    *line);
137         ssid = os_zalloc(sizeof(*ssid));
138         if (ssid == NULL)
139                 return NULL;
140         ssid->id = id;
141
142         wpa_config_set_network_defaults(ssid);
143
144         while (wpa_config_get_line(buf, sizeof(buf), f, line, &pos)) {
145                 if (os_strcmp(pos, "}") == 0) {
146                         end = 1;
147                         break;
148                 }
149
150                 pos2 = os_strchr(pos, '=');
151                 if (pos2 == NULL) {
152                         wpa_printf(MSG_ERROR, "Line %d: Invalid SSID line "
153                                    "'%s'.", *line, pos);
154                         errors++;
155                         continue;
156                 }
157
158                 *pos2++ = '\0';
159                 if (*pos2 == '"') {
160                         if (os_strchr(pos2 + 1, '"') == NULL) {
161                                 wpa_printf(MSG_ERROR, "Line %d: invalid "
162                                            "quotation '%s'.", *line, pos2);
163                                 errors++;
164                                 continue;
165                         }
166                 }
167
168                 if (wpa_config_set(ssid, pos, pos2, *line) < 0)
169                         errors++;
170         }
171
172         if (!end) {
173                 wpa_printf(MSG_ERROR, "Line %d: network block was not "
174                            "terminated properly.", *line);
175                 errors++;
176         }
177
178         errors += wpa_config_validate_network(ssid, *line);
179
180         if (errors) {
181                 wpa_config_free_ssid(ssid);
182                 ssid = NULL;
183         }
184
185         return ssid;
186 }
187
188
189 #ifndef CONFIG_NO_CONFIG_BLOBS
190 static struct wpa_config_blob * wpa_config_read_blob(FILE *f, int *line,
191                                                      const char *name)
192 {
193         struct wpa_config_blob *blob;
194         char buf[256], *pos;
195         unsigned char *encoded = NULL, *nencoded;
196         int end = 0;
197         size_t encoded_len = 0, len;
198
199         wpa_printf(MSG_MSGDUMP, "Line: %d - start of a new named blob '%s'",
200                    *line, name);
201
202         while (wpa_config_get_line(buf, sizeof(buf), f, line, &pos)) {
203                 if (os_strcmp(pos, "}") == 0) {
204                         end = 1;
205                         break;
206                 }
207
208                 len = os_strlen(pos);
209                 nencoded = os_realloc(encoded, encoded_len + len);
210                 if (nencoded == NULL) {
211                         wpa_printf(MSG_ERROR, "Line %d: not enough memory for "
212                                    "blob", *line);
213                         os_free(encoded);
214                         return NULL;
215                 }
216                 encoded = nencoded;
217                 os_memcpy(encoded + encoded_len, pos, len);
218                 encoded_len += len;
219         }
220
221         if (!end) {
222                 wpa_printf(MSG_ERROR, "Line %d: blob was not terminated "
223                            "properly", *line);
224                 os_free(encoded);
225                 return NULL;
226         }
227
228         blob = os_zalloc(sizeof(*blob));
229         if (blob == NULL) {
230                 os_free(encoded);
231                 return NULL;
232         }
233         blob->name = os_strdup(name);
234         blob->data = base64_decode(encoded, encoded_len, &blob->len);
235         os_free(encoded);
236
237         if (blob->name == NULL || blob->data == NULL) {
238                 wpa_config_free_blob(blob);
239                 return NULL;
240         }
241
242         return blob;
243 }
244
245
246 static int wpa_config_process_blob(struct wpa_config *config, FILE *f,
247                                    int *line, char *bname)
248 {
249         char *name_end;
250         struct wpa_config_blob *blob;
251
252         name_end = os_strchr(bname, '=');
253         if (name_end == NULL) {
254                 wpa_printf(MSG_ERROR, "Line %d: no blob name terminator",
255                            *line);
256                 return -1;
257         }
258         *name_end = '\0';
259
260         blob = wpa_config_read_blob(f, line, bname);
261         if (blob == NULL) {
262                 wpa_printf(MSG_ERROR, "Line %d: failed to read blob %s",
263                            *line, bname);
264                 return -1;
265         }
266         wpa_config_set_blob(config, blob);
267         return 0;
268 }
269 #endif /* CONFIG_NO_CONFIG_BLOBS */
270
271
272 struct wpa_config * wpa_config_read(const char *name)
273 {
274         FILE *f;
275         char buf[256], *pos;
276         int errors = 0, line = 0;
277         struct wpa_ssid *ssid, *tail = NULL, *head = NULL;
278         struct wpa_config *config;
279         int id = 0;
280
281         config = wpa_config_alloc_empty(NULL, NULL);
282         if (config == NULL)
283                 return NULL;
284         wpa_printf(MSG_DEBUG, "Reading configuration file '%s'", name);
285         f = fopen(name, "r");
286         if (f == NULL) {
287                 os_free(config);
288                 return NULL;
289         }
290
291         while (wpa_config_get_line(buf, sizeof(buf), f, &line, &pos)) {
292                 if (os_strcmp(pos, "network={") == 0) {
293                         ssid = wpa_config_read_network(f, &line, id++);
294                         if (ssid == NULL) {
295                                 wpa_printf(MSG_ERROR, "Line %d: failed to "
296                                            "parse network block.", line);
297                                 errors++;
298                                 continue;
299                         }
300                         if (head == NULL) {
301                                 head = tail = ssid;
302                         } else {
303                                 tail->next = ssid;
304                                 tail = ssid;
305                         }
306                         if (wpa_config_add_prio_network(config, ssid)) {
307                                 wpa_printf(MSG_ERROR, "Line %d: failed to add "
308                                            "network block to priority list.",
309                                            line);
310                                 errors++;
311                                 continue;
312                         }
313 #ifndef CONFIG_NO_CONFIG_BLOBS
314                 } else if (os_strncmp(pos, "blob-base64-", 12) == 0) {
315                         if (wpa_config_process_blob(config, f, &line, pos + 12)
316                             < 0) {
317                                 errors++;
318                                 continue;
319                         }
320 #endif /* CONFIG_NO_CONFIG_BLOBS */
321                 } else if (wpa_config_process_global(config, pos, line) < 0) {
322                         wpa_printf(MSG_ERROR, "Line %d: Invalid configuration "
323                                    "line '%s'.", line, pos);
324                         errors++;
325                         continue;
326                 }
327         }
328
329         fclose(f);
330
331         config->ssid = head;
332         wpa_config_debug_dump_networks(config);
333
334         if (errors) {
335                 wpa_config_free(config);
336                 config = NULL;
337                 head = NULL;
338         }
339
340         return config;
341 }
342
343
344 #ifndef CONFIG_NO_CONFIG_WRITE
345
346 static void write_str(FILE *f, const char *field, struct wpa_ssid *ssid)
347 {
348         char *value = wpa_config_get(ssid, field);
349         if (value == NULL)
350                 return;
351         fprintf(f, "\t%s=%s\n", field, value);
352         os_free(value);
353 }
354
355
356 static void write_int(FILE *f, const char *field, int value, int def)
357 {
358         if (value == def)
359                 return;
360         fprintf(f, "\t%s=%d\n", field, value);
361 }
362
363
364 static void write_bssid(FILE *f, struct wpa_ssid *ssid)
365 {
366         char *value = wpa_config_get(ssid, "bssid");
367         if (value == NULL)
368                 return;
369         fprintf(f, "\tbssid=%s\n", value);
370         os_free(value);
371 }
372
373
374 static void write_psk(FILE *f, struct wpa_ssid *ssid)
375 {
376         char *value = wpa_config_get(ssid, "psk");
377         if (value == NULL)
378                 return;
379         fprintf(f, "\tpsk=%s\n", value);
380         os_free(value);
381 }
382
383
384 static void write_proto(FILE *f, struct wpa_ssid *ssid)
385 {
386         char *value;
387
388         if (ssid->proto == DEFAULT_PROTO)
389                 return;
390
391         value = wpa_config_get(ssid, "proto");
392         if (value == NULL)
393                 return;
394         if (value[0])
395                 fprintf(f, "\tproto=%s\n", value);
396         os_free(value);
397 }
398
399
400 static void write_key_mgmt(FILE *f, struct wpa_ssid *ssid)
401 {
402         char *value;
403
404         if (ssid->key_mgmt == DEFAULT_KEY_MGMT)
405                 return;
406
407         value = wpa_config_get(ssid, "key_mgmt");
408         if (value == NULL)
409                 return;
410         if (value[0])
411                 fprintf(f, "\tkey_mgmt=%s\n", value);
412         os_free(value);
413 }
414
415
416 static void write_pairwise(FILE *f, struct wpa_ssid *ssid)
417 {
418         char *value;
419
420         if (ssid->pairwise_cipher == DEFAULT_PAIRWISE)
421                 return;
422
423         value = wpa_config_get(ssid, "pairwise");
424         if (value == NULL)
425                 return;
426         if (value[0])
427                 fprintf(f, "\tpairwise=%s\n", value);
428         os_free(value);
429 }
430
431
432 static void write_group(FILE *f, struct wpa_ssid *ssid)
433 {
434         char *value;
435
436         if (ssid->group_cipher == DEFAULT_GROUP)
437                 return;
438
439         value = wpa_config_get(ssid, "group");
440         if (value == NULL)
441                 return;
442         if (value[0])
443                 fprintf(f, "\tgroup=%s\n", value);
444         os_free(value);
445 }
446
447
448 static void write_auth_alg(FILE *f, struct wpa_ssid *ssid)
449 {
450         char *value;
451
452         if (ssid->auth_alg == 0)
453                 return;
454
455         value = wpa_config_get(ssid, "auth_alg");
456         if (value == NULL)
457                 return;
458         if (value[0])
459                 fprintf(f, "\tauth_alg=%s\n", value);
460         os_free(value);
461 }
462
463
464 #ifdef IEEE8021X_EAPOL
465 static void write_eap(FILE *f, struct wpa_ssid *ssid)
466 {
467         char *value;
468
469         value = wpa_config_get(ssid, "eap");
470         if (value == NULL)
471                 return;
472
473         if (value[0])
474                 fprintf(f, "\teap=%s\n", value);
475         os_free(value);
476 }
477 #endif /* IEEE8021X_EAPOL */
478
479
480 static void write_wep_key(FILE *f, int idx, struct wpa_ssid *ssid)
481 {
482         char field[20], *value;
483         int res;
484
485         res = os_snprintf(field, sizeof(field), "wep_key%d", idx);
486         if (res < 0 || (size_t) res >= sizeof(field))
487                 return;
488         value = wpa_config_get(ssid, field);
489         if (value) {
490                 fprintf(f, "\t%s=%s\n", field, value);
491                 os_free(value);
492         }
493 }
494
495
496 static void wpa_config_write_network(FILE *f, struct wpa_ssid *ssid)
497 {
498         int i;
499
500 #define STR(t) write_str(f, #t, ssid)
501 #define INT(t) write_int(f, #t, ssid->t, 0)
502 #define INTe(t) write_int(f, #t, ssid->eap.t, 0)
503 #define INT_DEF(t, def) write_int(f, #t, ssid->t, def)
504 #define INT_DEFe(t, def) write_int(f, #t, ssid->eap.t, def)
505
506         STR(ssid);
507         INT(scan_ssid);
508         write_bssid(f, ssid);
509         write_psk(f, ssid);
510         write_proto(f, ssid);
511         write_key_mgmt(f, ssid);
512         write_pairwise(f, ssid);
513         write_group(f, ssid);
514         write_auth_alg(f, ssid);
515 #ifdef IEEE8021X_EAPOL
516         write_eap(f, ssid);
517         STR(identity);
518         STR(anonymous_identity);
519         STR(password);
520         STR(ca_cert);
521         STR(ca_path);
522         STR(client_cert);
523         STR(private_key);
524         STR(private_key_passwd);
525         STR(dh_file);
526         STR(subject_match);
527         STR(altsubject_match);
528         STR(ca_cert2);
529         STR(ca_path2);
530         STR(client_cert2);
531         STR(private_key2);
532         STR(private_key2_passwd);
533         STR(dh_file2);
534         STR(subject_match2);
535         STR(altsubject_match2);
536         STR(phase1);
537         STR(phase2);
538         STR(pcsc);
539         STR(pin);
540         STR(engine_id);
541         STR(key_id);
542         STR(cert_id);
543         STR(ca_cert_id);
544         STR(key2_id);
545         STR(pin2);
546         STR(engine2_id);
547         STR(cert2_id);
548         STR(ca_cert2_id);
549         INTe(engine);
550         INTe(engine2);
551         INT_DEF(eapol_flags, DEFAULT_EAPOL_FLAGS);
552 #endif /* IEEE8021X_EAPOL */
553         for (i = 0; i < 4; i++)
554                 write_wep_key(f, i, ssid);
555         INT(wep_tx_keyidx);
556         INT(priority);
557 #ifdef IEEE8021X_EAPOL
558         INT_DEF(eap_workaround, DEFAULT_EAP_WORKAROUND);
559         STR(pac_file);
560         INT_DEFe(fragment_size, DEFAULT_FRAGMENT_SIZE);
561 #endif /* IEEE8021X_EAPOL */
562         INT(mode);
563         INT(proactive_key_caching);
564         INT(disabled);
565         INT(peerkey);
566 #ifdef CONFIG_IEEE80211W
567         INT(ieee80211w);
568 #endif /* CONFIG_IEEE80211W */
569         STR(id_str);
570
571 #undef STR
572 #undef INT
573 #undef INT_DEF
574 }
575
576
577 #ifndef CONFIG_NO_CONFIG_BLOBS
578 static int wpa_config_write_blob(FILE *f, struct wpa_config_blob *blob)
579 {
580         unsigned char *encoded;
581
582         encoded = base64_encode(blob->data, blob->len, NULL);
583         if (encoded == NULL)
584                 return -1;
585
586         fprintf(f, "\nblob-base64-%s={\n%s}\n", blob->name, encoded);
587         os_free(encoded);
588         return 0;
589 }
590 #endif /* CONFIG_NO_CONFIG_BLOBS */
591
592
593 static void wpa_config_write_global(FILE *f, struct wpa_config *config)
594 {
595 #ifdef CONFIG_CTRL_IFACE
596         if (config->ctrl_interface)
597                 fprintf(f, "ctrl_interface=%s\n", config->ctrl_interface);
598         if (config->ctrl_interface_group)
599                 fprintf(f, "ctrl_interface_group=%s\n",
600                         config->ctrl_interface_group);
601 #endif /* CONFIG_CTRL_IFACE */
602         if (config->eapol_version != DEFAULT_EAPOL_VERSION)
603                 fprintf(f, "eapol_version=%d\n", config->eapol_version);
604         if (config->ap_scan != DEFAULT_AP_SCAN)
605                 fprintf(f, "ap_scan=%d\n", config->ap_scan);
606         if (config->fast_reauth != DEFAULT_FAST_REAUTH)
607                 fprintf(f, "fast_reauth=%d\n", config->fast_reauth);
608         if (config->opensc_engine_path)
609                 fprintf(f, "opensc_engine_path=%s\n",
610                         config->opensc_engine_path);
611         if (config->pkcs11_engine_path)
612                 fprintf(f, "pkcs11_engine_path=%s\n",
613                         config->pkcs11_engine_path);
614         if (config->pkcs11_module_path)
615                 fprintf(f, "pkcs11_module_path=%s\n",
616                         config->pkcs11_module_path);
617         if (config->driver_param)
618                 fprintf(f, "driver_param=%s\n", config->driver_param);
619         if (config->dot11RSNAConfigPMKLifetime)
620                 fprintf(f, "dot11RSNAConfigPMKLifetime=%d\n",
621                         config->dot11RSNAConfigPMKLifetime);
622         if (config->dot11RSNAConfigPMKReauthThreshold)
623                 fprintf(f, "dot11RSNAConfigPMKReauthThreshold=%d\n",
624                         config->dot11RSNAConfigPMKReauthThreshold);
625         if (config->dot11RSNAConfigSATimeout)
626                 fprintf(f, "dot11RSNAConfigSATimeout=%d\n",
627                         config->dot11RSNAConfigSATimeout);
628         if (config->update_config)
629                 fprintf(f, "update_config=%d\n", config->update_config);
630 #ifdef CONFIG_WPS
631         if (!is_nil_uuid(config->uuid)) {
632                 char buf[40];
633                 uuid_bin2str(config->uuid, buf, sizeof(buf));
634                 fprintf(f, "uuid=%s\n", buf);
635         }
636         if (config->device_name)
637                 fprintf(f, "device_name=%s\n", config->device_name);
638         if (config->manufacturer)
639                 fprintf(f, "manufacturer=%s\n", config->manufacturer);
640         if (config->model_name)
641                 fprintf(f, "model_name=%s\n", config->model_name);
642         if (config->model_number)
643                 fprintf(f, "model_number=%s\n", config->model_number);
644         if (config->serial_number)
645                 fprintf(f, "serial_number=%s\n", config->serial_number);
646         if (config->device_type)
647                 fprintf(f, "device_type=%s\n", config->device_type);
648         if (WPA_GET_BE32(config->os_version))
649                 fprintf(f, "os_version=%08x\n",
650                         WPA_GET_BE32(config->os_version));
651         if (config->config_methods)
652                 fprintf(f, "config_methods=%s\n", config->config_methods);
653         if (config->wps_cred_processing)
654                 fprintf(f, "wps_cred_processing=%d\n",
655                         config->wps_cred_processing);
656 #endif /* CONFIG_WPS */
657 #ifdef CONFIG_P2P
658         if (config->p2p_listen_reg_class)
659                 fprintf(f, "p2p_listen_reg_class=%u\n",
660                         config->p2p_listen_reg_class);
661         if (config->p2p_listen_channel)
662                 fprintf(f, "p2p_listen_channel=%u\n",
663                         config->p2p_listen_channel);
664         if (config->p2p_oper_reg_class)
665                 fprintf(f, "p2p_oper_reg_class=%u\n",
666                         config->p2p_oper_reg_class);
667         if (config->p2p_oper_channel)
668                 fprintf(f, "p2p_oper_channel=%u\n", config->p2p_oper_channel);
669         if (config->p2p_go_intent != DEFAULT_P2P_GO_INTENT)
670                 fprintf(f, "p2p_go_intent=%u\n", config->p2p_go_intent);
671         if (config->p2p_ssid_postfix)
672                 fprintf(f, "p2p_ssid_postfix=%s\n", config->p2p_ssid_postfix);
673         if (config->persistent_reconnect)
674                 fprintf(f, "persistent_reconnect=%u\n",
675                         config->persistent_reconnect);
676         if (config->p2p_intra_bss != DEFAULT_P2P_INTRA_BSS)
677                 fprintf(f, "p2p_intra_bss=%u\n", config->p2p_intra_bss);
678
679 #endif /* CONFIG_P2P */
680         if (config->country[0] && config->country[1]) {
681                 fprintf(f, "country=%c%c\n",
682                         config->country[0], config->country[1]);
683         }
684         if (config->bss_max_count != DEFAULT_BSS_MAX_COUNT)
685                 fprintf(f, "bss_max_count=%u\n", config->bss_max_count);
686         if (config->filter_ssids)
687                 fprintf(f, "filter_ssids=%d\n", config->filter_ssids);
688 }
689
690 #endif /* CONFIG_NO_CONFIG_WRITE */
691
692
693 int wpa_config_write(const char *name, struct wpa_config *config)
694 {
695 #ifndef CONFIG_NO_CONFIG_WRITE
696         FILE *f;
697         struct wpa_ssid *ssid;
698 #ifndef CONFIG_NO_CONFIG_BLOBS
699         struct wpa_config_blob *blob;
700 #endif /* CONFIG_NO_CONFIG_BLOBS */
701         int ret = 0;
702
703         wpa_printf(MSG_DEBUG, "Writing configuration file '%s'", name);
704
705         f = fopen(name, "w");
706         if (f == NULL) {
707                 wpa_printf(MSG_DEBUG, "Failed to open '%s' for writing", name);
708                 return -1;
709         }
710
711         wpa_config_write_global(f, config);
712
713         for (ssid = config->ssid; ssid; ssid = ssid->next) {
714                 if (ssid->key_mgmt == WPA_KEY_MGMT_WPS || ssid->temporary)
715                         continue; /* do not save temporary networks */
716                 fprintf(f, "\nnetwork={\n");
717                 wpa_config_write_network(f, ssid);
718                 fprintf(f, "}\n");
719         }
720
721 #ifndef CONFIG_NO_CONFIG_BLOBS
722         for (blob = config->blobs; blob; blob = blob->next) {
723                 ret = wpa_config_write_blob(f, blob);
724                 if (ret)
725                         break;
726         }
727 #endif /* CONFIG_NO_CONFIG_BLOBS */
728
729         fclose(f);
730
731         wpa_printf(MSG_DEBUG, "Configuration file '%s' written %ssuccessfully",
732                    name, ret ? "un" : "");
733         return ret;
734 #else /* CONFIG_NO_CONFIG_WRITE */
735         return -1;
736 #endif /* CONFIG_NO_CONFIG_WRITE */
737 }