config: Check SSID length before comparing protected SSIDs
[platform/upstream/connman.git] / src / config.c
1 /*
2  *
3  *  Connection Manager
4  *
5  *  Copyright (C) 2007-2010  Intel Corporation. All rights reserved.
6  *
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License version 2 as
9  *  published by the Free Software Foundation.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20  */
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <stdio.h>
27 #include <unistd.h>
28 #include <string.h>
29 #include <sys/vfs.h>
30 #include <sys/inotify.h>
31 #include <glib.h>
32
33 #include "connman.h"
34
35 struct connman_config_service {
36         char *ident;
37         char *name;
38         char *type;
39         void *ssid;
40         unsigned int ssid_len;
41         char *eap;
42         char *identity;
43         char *ca_cert_file;
44         char *client_cert_file;
45         char *private_key_file;
46         char *private_key_passphrase;
47         char *private_key_passphrase_type;
48         char *phase2;
49         char *passphrase;
50         connman_bool_t from_fs;
51 };
52
53 struct connman_config {
54         char *ident;
55         char *name;
56         char *description;
57         connman_bool_t protected;
58         GHashTable *service_table;
59 };
60
61 static GHashTable *config_table = NULL;
62 static GSList *protected_services = NULL;
63
64 static int inotify_wd = -1;
65
66 static GIOChannel *inotify_channel = NULL;
67 static uint inotify_watch = 0;
68
69 #define NONFS_CONFIG_NAME                "internal"
70 #define INTERNAL_CONFIG_PREFIX           "__internal"
71
72 /* Definition of possible strings in the .config files */
73 #define CONFIG_KEY_NAME                "Name"
74 #define CONFIG_KEY_DESC                "Description"
75 #define CONFIG_KEY_PROT                "Protected"
76
77 #define SERVICE_KEY_TYPE               "Type"
78 #define SERVICE_KEY_NAME               "Name"
79 #define SERVICE_KEY_SSID               "SSID"
80 #define SERVICE_KEY_EAP                "EAP"
81 #define SERVICE_KEY_CA_CERT            "CACertFile"
82 #define SERVICE_KEY_CL_CERT            "ClientCertFile"
83 #define SERVICE_KEY_PRV_KEY            "PrivateKeyFile"
84 #define SERVICE_KEY_PRV_KEY_PASS       "PrivateKeyPassphrase"
85 #define SERVICE_KEY_PRV_KEY_PASS_TYPE  "PrivateKeyPassphraseType"
86 #define SERVICE_KEY_IDENTITY           "Identity"
87 #define SERVICE_KEY_PHASE2             "Phase2"
88 #define SERVICE_KEY_PASSPHRASE         "Passphrase"
89
90 static const char *config_possible_keys[] = {
91         CONFIG_KEY_NAME,
92         CONFIG_KEY_DESC,
93         CONFIG_KEY_PROT,
94         NULL,
95 };
96
97 static const char *service_possible_keys[] = {
98         SERVICE_KEY_TYPE,
99         SERVICE_KEY_NAME,
100         SERVICE_KEY_SSID,
101         SERVICE_KEY_EAP,
102         SERVICE_KEY_CA_CERT,
103         SERVICE_KEY_CL_CERT,
104         SERVICE_KEY_PRV_KEY,
105         SERVICE_KEY_PRV_KEY_PASS,
106         SERVICE_KEY_PRV_KEY_PASS_TYPE,
107         SERVICE_KEY_IDENTITY,
108         SERVICE_KEY_PHASE2,
109         SERVICE_KEY_PASSPHRASE,
110         NULL,
111 };
112
113 static void unregister_config(gpointer data)
114 {
115         struct connman_config *config = data;
116
117         connman_info("Removing configuration %s", config->ident);
118
119         g_hash_table_destroy(config->service_table);
120
121         g_free(config->description);
122         g_free(config->name);
123         g_free(config->ident);
124         g_free(config);
125 }
126
127 static void unregister_service(gpointer data)
128 {
129         struct connman_config_service *service = data;
130
131         connman_info("Removing service configuration %s", service->ident);
132
133         protected_services = g_slist_remove(protected_services, service);
134
135         g_free(service->ident);
136         g_free(service->type);
137         g_free(service->name);
138         g_free(service->ssid);
139         g_free(service->eap);
140         g_free(service->identity);
141         g_free(service->ca_cert_file);
142         g_free(service->client_cert_file);
143         g_free(service->private_key_file);
144         g_free(service->private_key_passphrase);
145         g_free(service->private_key_passphrase_type);
146         g_free(service->phase2);
147         g_free(service->passphrase);
148         g_free(service);
149 }
150
151 static void check_keys(GKeyFile *keyfile, const char *group,
152                         const char **possible_keys)
153 {
154         char **avail_keys;
155         gsize nb_avail_keys, i, j;
156
157         avail_keys = g_key_file_get_keys(keyfile, group, &nb_avail_keys, NULL);
158         if (avail_keys == NULL)
159                 return;
160
161         /*
162          * For each key in the configuration file,
163          * verify it is understood by connman
164          */
165         for (i = 0 ; i < nb_avail_keys; i++) {
166                 for (j = 0; possible_keys[j] ; j++)
167                         if (g_strcmp0(avail_keys[i], possible_keys[j]) == 0)
168                                 break;
169
170                 if (possible_keys[j] == NULL)
171                         connman_warn("Unknown configuration key %s in [%s]",
172                                         avail_keys[i], group);
173         }
174
175         g_strfreev(avail_keys);
176 }
177
178 static connman_bool_t
179 is_protected_service(struct connman_config_service *service)
180 {
181         GSList *list;
182
183         DBG("ident %s", service->ident);
184
185         for (list = protected_services; list; list = list->next) {
186                 struct connman_config_service *s = list->data;
187
188                 if (g_strcmp0(s->type, service->type) != 0)
189                         continue;
190
191                 if (s->ssid == NULL || service->ssid == NULL)
192                         continue;
193
194                 if (s->ssid_len != service->ssid_len)
195                         continue;
196
197                 if (g_strcmp0(service->type, "wifi") == 0 &&
198                         strncmp(s->ssid, service->ssid, s->ssid_len) == 0) {
199                         return TRUE;
200                 }
201         }
202
203         return FALSE;
204 }
205
206 static int load_service(GKeyFile *keyfile, const char *group,
207                                                 struct connman_config *config)
208 {
209         struct connman_config_service *service;
210         const char *ident;
211         char *str, *hex_ssid;
212         gboolean service_created = FALSE;
213         int err;
214
215         /* Strip off "service_" prefix */
216         ident = group + 8;
217
218         if (strlen(ident) < 1)
219                 return -EINVAL;
220
221         /* Verify that provided keys are good */
222         check_keys(keyfile, group, service_possible_keys);
223
224         service = g_hash_table_lookup(config->service_table, ident);
225         if (service == NULL) {
226                 service = g_try_new0(struct connman_config_service, 1);
227                 if (service == NULL)
228                         return -ENOMEM;
229
230                 service->ident = g_strdup(ident);
231
232                 service_created = TRUE;
233         }
234
235         str = g_key_file_get_string(keyfile, group, SERVICE_KEY_TYPE, NULL);
236         if (str != NULL) {
237                 g_free(service->type);
238                 service->type = str;
239         }
240
241         str = g_key_file_get_string(keyfile, group, SERVICE_KEY_NAME, NULL);
242         if (str != NULL) {
243                 g_free(service->name);
244                 service->name = str;
245         }
246
247         hex_ssid = g_key_file_get_string(keyfile, group, SERVICE_KEY_SSID,
248                                          NULL);
249         if (hex_ssid != NULL) {
250                 char *ssid;
251                 unsigned int i, j = 0, hex;
252                 size_t hex_ssid_len = strlen(hex_ssid);
253
254                 ssid = g_try_malloc0(hex_ssid_len / 2);
255                 if (ssid == NULL) {
256                         err = -ENOMEM;
257                         g_free(hex_ssid);
258                         goto err;
259                 }
260
261                 for (i = 0; i < hex_ssid_len; i += 2) {
262                         sscanf(hex_ssid + i, "%02x", &hex);
263                         ssid[j++] = hex;
264                 }
265
266                 g_free(hex_ssid);
267
268                 g_free(service->ssid);
269                 service->ssid = ssid;
270                 service->ssid_len = hex_ssid_len / 2;
271         } else if (service->name != NULL) {
272                 char *ssid;
273                 unsigned int ssid_len;
274
275                 ssid_len = strlen(service->name);
276                 ssid = g_try_malloc0(ssid_len);
277                 if (ssid == NULL) {
278                         err = -ENOMEM;
279                         goto err;
280                 }
281
282                 memcpy(ssid, service->name, ssid_len);
283                 g_free(service->ssid);
284                 service->ssid = ssid;
285                 service->ssid_len = ssid_len;
286         }
287
288         if (is_protected_service(service) == TRUE) {
289                 connman_error("Trying to provision a protected service");
290                 err = -EACCES;
291                 goto err;
292         }
293
294         str = g_key_file_get_string(keyfile, group, SERVICE_KEY_EAP, NULL);
295         if (str != NULL) {
296                 g_free(service->eap);
297                 service->eap = str;
298         }
299
300         str = g_key_file_get_string(keyfile, group, SERVICE_KEY_CA_CERT, NULL);
301         if (str != NULL) {
302                 g_free(service->ca_cert_file);
303                 service->ca_cert_file = str;
304         }
305
306         str = g_key_file_get_string(keyfile, group, SERVICE_KEY_CL_CERT, NULL);
307         if (str != NULL) {
308                 g_free(service->client_cert_file);
309                 service->client_cert_file = str;
310         }
311
312         str = g_key_file_get_string(keyfile, group, SERVICE_KEY_PRV_KEY, NULL);
313         if (str != NULL) {
314                 g_free(service->private_key_file);
315                 service->private_key_file = str;
316         }
317
318         str = g_key_file_get_string(keyfile, group,
319                                                 SERVICE_KEY_PRV_KEY_PASS, NULL);
320         if (str != NULL) {
321                 g_free(service->private_key_passphrase);
322                 service->private_key_passphrase = str;
323         }
324
325         str = g_key_file_get_string(keyfile, group,
326                                         SERVICE_KEY_PRV_KEY_PASS_TYPE, NULL);
327         if (str != NULL) {
328                 g_free(service->private_key_passphrase_type);
329                 service->private_key_passphrase_type = str;
330         }
331
332         str = g_key_file_get_string(keyfile, group, SERVICE_KEY_IDENTITY, NULL);
333         if (str != NULL) {
334                 g_free(service->identity);
335                 service->identity = str;
336         }
337
338         str = g_key_file_get_string(keyfile, group, SERVICE_KEY_PHASE2, NULL);
339         if (str != NULL) {
340                 g_free(service->phase2);
341                 service->phase2 = str;
342         }
343
344         str = g_key_file_get_string(keyfile, group, SERVICE_KEY_PASSPHRASE,
345                                         NULL);
346         if (str != NULL) {
347                 g_free(service->passphrase);
348                 service->passphrase = str;
349         }
350
351         if (g_strcmp0(config->ident, NONFS_CONFIG_NAME) != 0)
352                 service->from_fs = TRUE;
353         else
354                 service->from_fs = FALSE;
355
356         if (service_created)
357                 g_hash_table_insert(config->service_table, service->ident,
358                                         service);
359
360         if (config->protected == TRUE)
361                 protected_services =
362                         g_slist_append(protected_services, service);
363
364         connman_info("Adding service configuration %s", service->ident);
365
366         return 0;
367
368 err:
369         if (service_created == TRUE) {
370                 g_free(service->ident);
371                 g_free(service->type);
372                 g_free(service->name);
373                 g_free(service->ssid);
374                 g_free(service);
375         }
376
377         return err;
378 }
379
380 static int load_config(struct connman_config *config)
381 {
382         GKeyFile *keyfile;
383         gsize length;
384         char **groups;
385         char *str;
386         gboolean protected;
387         int i;
388
389         DBG("config %p", config);
390
391         keyfile = __connman_storage_open_config(config->ident);
392         if (keyfile == NULL)
393                 return -EIO;
394
395         /* Verify keys validity of the global section */
396         check_keys(keyfile, "global", config_possible_keys);
397
398         str = g_key_file_get_string(keyfile, "global", CONFIG_KEY_NAME, NULL);
399         if (str != NULL) {
400                 g_free(config->name);
401                 config->name = str;
402         }
403
404         str = g_key_file_get_string(keyfile, "global", CONFIG_KEY_DESC, NULL);
405         if (str != NULL) {
406                 g_free(config->description);
407                 config->description = str;
408         }
409
410         protected = g_key_file_get_boolean(keyfile, "global",
411                                         CONFIG_KEY_PROT, NULL);
412         config->protected = protected;
413
414         groups = g_key_file_get_groups(keyfile, &length);
415
416         for (i = 0; groups[i] != NULL; i++) {
417                 if (g_str_has_prefix(groups[i], "service_") == TRUE)
418                         load_service(keyfile, groups[i], config);
419         }
420
421         g_strfreev(groups);
422
423         __connman_storage_close_config(config->ident, keyfile, FALSE);
424
425         return 0;
426 }
427
428 static struct connman_config *create_config(const char *ident)
429 {
430         struct connman_config *config;
431
432         DBG("ident %s", ident);
433
434         if (g_hash_table_lookup(config_table, ident) != NULL)
435                 return NULL;
436
437         config = g_try_new0(struct connman_config, 1);
438         if (config == NULL)
439                 return NULL;
440
441         config->ident = g_strdup(ident);
442
443         config->service_table = g_hash_table_new_full(g_str_hash, g_str_equal,
444                                                 NULL, unregister_service);
445
446         g_hash_table_insert(config_table, config->ident, config);
447
448         connman_info("Adding configuration %s", config->ident);
449
450         return config;
451 }
452
453 int __connman_config_load_service(GKeyFile *keyfile, const char *group,
454                                         connman_bool_t persistent)
455 {
456         struct connman_config *config;
457         const char *service_name;
458         char *ident, *filename = NULL, *content = NULL;
459         gsize content_length;
460         int err;
461
462         service_name = group + strlen("service_");
463         ident = g_strdup_printf("%s_%s", INTERNAL_CONFIG_PREFIX, service_name);
464         if (ident == NULL)
465                 return -ENOMEM;
466
467         DBG("ident %s", ident);
468
469         config = g_hash_table_lookup(config_table, ident);
470         if (config == NULL) {
471                 config = create_config(ident);
472                 if (config == NULL) {
473                         err = -ENOMEM;
474                         goto out;
475                 }
476
477                 config->protected = FALSE;
478         }
479
480         err = load_service(keyfile, group, config);
481         if (persistent == FALSE || err < 0)
482                 goto out;
483
484         g_key_file_set_string(keyfile, "global", CONFIG_KEY_NAME,
485                                                         service_name);
486         g_key_file_set_string(keyfile, "global", CONFIG_KEY_DESC,
487                                                 "Internal Config File");
488
489         content = g_key_file_to_data(keyfile, &content_length, NULL);
490         if (content == NULL) {
491                 err = -EIO;
492                 goto out;
493         }
494
495         filename = g_strdup_printf("%s/%s.config", STORAGEDIR, ident);
496         if (filename == NULL) {
497                 err = -ENOMEM;
498                 goto out;
499         }
500
501         DBG("Saving %d bytes to %s", content_length, filename);
502
503         if (g_file_set_contents(filename, content,
504                                 content_length, NULL) == FALSE) {
505                 err = -EIO;
506                 goto out;
507         }
508
509         return 0;
510
511 out:
512         g_free(ident);
513         g_free(content);
514         g_free(filename);
515
516         return err;
517 }
518
519 static int read_configs(void)
520 {
521         GDir *dir;
522
523         DBG("");
524
525         dir = g_dir_open(STORAGEDIR, 0, NULL);
526         if (dir != NULL) {
527                 const gchar *file;
528
529                 while ((file = g_dir_read_name(dir)) != NULL) {
530                         GString *str;
531                         gchar *ident;
532
533                         if (g_str_has_suffix(file, ".config") == FALSE)
534                                 continue;
535
536                         ident = g_strrstr(file, ".config");
537                         if (ident == NULL)
538                                 continue;
539
540                         if (g_str_equal(ident, NONFS_CONFIG_NAME) == TRUE)
541                                 continue;
542
543                         str = g_string_new_len(file, ident - file);
544                         if (str == NULL)
545                                 continue;
546
547                         ident = g_string_free(str, FALSE);
548
549                         if (connman_dbus_validate_ident(ident) == TRUE) {
550                                 struct connman_config *config;
551
552                                 config = create_config(ident);
553                                 if (config != NULL)
554                                         load_config(config);
555                         }
556                         g_free(ident);
557                 }
558
559                 g_dir_close(dir);
560         }
561
562         return 0;
563 }
564
565 static gboolean inotify_data(GIOChannel *channel, GIOCondition cond,
566                                                         gpointer user_data)
567 {
568         char buffer[256];
569         char *next_event;
570         gsize bytes_read;
571         GIOStatus status;
572
573         if (cond & (G_IO_NVAL | G_IO_ERR | G_IO_HUP)) {
574                 inotify_watch = 0;
575                 return FALSE;
576         }
577
578         status = g_io_channel_read_chars(channel, buffer,
579                                         sizeof(buffer) -1, &bytes_read, NULL);
580
581         switch (status) {
582         case G_IO_STATUS_NORMAL:
583                 break;
584         case G_IO_STATUS_AGAIN:
585                 return TRUE;
586         default:
587                 connman_error("Reading from inotify channel failed");
588                 inotify_watch = 0;
589                 return FALSE;
590         }
591
592         next_event = buffer;
593
594         while (bytes_read > 0) {
595                 struct inotify_event *event;
596                 gchar *ext;
597                 gchar *ident;
598                 gsize len;
599
600                 event = (struct inotify_event *) next_event;
601                 if (event->len)
602                         ident = next_event + sizeof(struct inotify_event);
603                 else
604                         ident = NULL;
605
606                 len = sizeof(struct inotify_event) + event->len;
607
608                 /* check if inotify_event block fit */
609                 if (len > bytes_read)
610                         break;
611
612                 next_event += len;
613                 bytes_read -= len;
614
615                 if (ident == NULL)
616                         continue;
617
618                 if (g_str_has_suffix(ident, ".config") == FALSE)
619                         continue;
620
621                 ext = g_strrstr(ident, ".config");
622                 if (ext == NULL)
623                         continue;
624
625                 *ext = '\0';
626
627                 if (g_str_equal(ident, NONFS_CONFIG_NAME) == TRUE)
628                         continue;
629
630                 if (connman_dbus_validate_ident(ident) == FALSE)
631                         continue;
632
633                 if (event->mask & IN_CREATE)
634                         create_config(ident);
635
636                 if (event->mask & IN_MODIFY) {
637                         struct connman_config *config;
638
639                         config = g_hash_table_lookup(config_table, ident);
640                         if (config != NULL) {
641                                 g_hash_table_remove_all(config->service_table);
642                                 load_config(config);
643                         }
644                 }
645
646                 if (event->mask & IN_DELETE)
647                         g_hash_table_remove(config_table, ident);
648         }
649
650         return TRUE;
651 }
652
653 static int create_watch(void)
654 {
655         int fd;
656
657         fd = inotify_init();
658         if (fd < 0)
659                 return -EIO;
660
661         inotify_wd = inotify_add_watch(fd, STORAGEDIR,
662                                         IN_MODIFY | IN_CREATE | IN_DELETE);
663         if (inotify_wd < 0) {
664                 connman_error("Creation of STORAGEDIR  watch failed");
665                 close(fd);
666                 return -EIO;
667         }
668
669         inotify_channel = g_io_channel_unix_new(fd);
670         if (inotify_channel == NULL) {
671                 connman_error("Creation of inotify channel failed");
672                 inotify_rm_watch(fd, inotify_wd);
673                 inotify_wd = 0;
674
675                 close(fd);
676                 return -EIO;
677         }
678
679         g_io_channel_set_close_on_unref(inotify_channel, TRUE);
680         g_io_channel_set_encoding(inotify_channel, NULL, NULL);
681         g_io_channel_set_buffered(inotify_channel, FALSE);
682
683         inotify_watch = g_io_add_watch(inotify_channel,
684                                 G_IO_IN | G_IO_HUP | G_IO_NVAL | G_IO_ERR,
685                                 inotify_data, NULL);
686
687         return 0;
688 }
689
690 static void remove_watch(void)
691 {
692         int fd;
693
694         if (inotify_channel == NULL)
695                 return;
696
697         if (inotify_watch > 0) {
698                 g_source_remove(inotify_watch);
699                 inotify_watch = 0;
700         }
701
702         fd = g_io_channel_unix_get_fd(inotify_channel);
703
704         if (inotify_wd >= 0) {
705                 inotify_rm_watch(fd, inotify_wd);
706                 inotify_wd = 0;
707         }
708
709         g_io_channel_unref(inotify_channel);
710 }
711
712 int __connman_config_init(void)
713 {
714         DBG("");
715
716         config_table = g_hash_table_new_full(g_str_hash, g_str_equal,
717                                                 NULL, unregister_config);
718
719         create_watch();
720
721         return read_configs();
722 }
723
724 void __connman_config_cleanup(void)
725 {
726         DBG("");
727
728         remove_watch();
729
730         g_hash_table_destroy(config_table);
731         config_table = NULL;
732 }
733
734 static char *config_pem_fsid(const char *pem_file)
735 {
736         struct statfs buf;
737         unsigned *fsid = (unsigned *) &buf.f_fsid;
738         unsigned long long fsid64;
739
740         if (pem_file == NULL)
741                 return NULL;
742
743         if (statfs(pem_file, &buf) < 0) {
744                 connman_error("statfs error %s for %s",
745                                                 strerror(errno), pem_file);
746                 return NULL;
747         }
748
749         fsid64 = ((unsigned long long) fsid[0] << 32) | fsid[1];
750
751         return g_strdup_printf("%llx", fsid64);
752 }
753
754 static void provision_service(gpointer key, gpointer value, gpointer user_data)
755 {
756         struct connman_service *service = user_data;
757         struct connman_config_service *config = value;
758         struct connman_network *network;
759         const void *ssid;
760         unsigned int ssid_len;
761
762         /* For now only WiFi service entries are supported */
763         if (g_strcmp0(config->type, "wifi") != 0)
764                 return;
765
766         network = __connman_service_get_network(service);
767         if (network == NULL) {
768                 connman_error("Service has no network set");
769                 return;
770         }
771
772         ssid = connman_network_get_blob(network, "WiFi.SSID", &ssid_len);
773         if (ssid == NULL) {
774                 connman_error("Network SSID not set");
775                 return;
776         }
777
778         if (config->ssid == NULL || ssid_len != config->ssid_len)
779                 return;
780
781         if (memcmp(config->ssid, ssid, ssid_len) != 0)
782                 return;
783
784         /* do not provision immutable services with non-fs originated configs */
785         if (config->from_fs == FALSE &&
786                         __connman_service_get_immutable(service) == TRUE)
787                 return;
788
789         /* only lock services with a config originated from the filesystem */
790         if (config->from_fs == TRUE)
791                 __connman_service_set_immutable(service, TRUE);
792
793         __connman_service_set_favorite(service, TRUE);
794
795         if (config->eap != NULL)
796                 __connman_service_set_string(service, "EAP", config->eap);
797
798         if (config->identity != NULL)
799                 __connman_service_set_string(service, "Identity",
800                                                         config->identity);
801
802         if (config->ca_cert_file != NULL)
803                 __connman_service_set_string(service, "CACertFile",
804                                                         config->ca_cert_file);
805
806         if (config->client_cert_file != NULL)
807                 __connman_service_set_string(service, "ClientCertFile",
808                                                 config->client_cert_file);
809
810         if (config->private_key_file != NULL)
811                 __connman_service_set_string(service, "PrivateKeyFile",
812                                                 config->private_key_file);
813
814         if (g_strcmp0(config->private_key_passphrase_type, "fsid") == 0 &&
815                                         config->private_key_file != NULL) {
816                 char *fsid;
817
818                 fsid = config_pem_fsid(config->private_key_file);
819                 if (fsid == NULL)
820                         return;
821
822                 g_free(config->private_key_passphrase);
823                 config->private_key_passphrase = fsid;
824         }
825
826         if (config->private_key_passphrase != NULL) {
827                 __connman_service_set_string(service, "PrivateKeyPassphrase",
828                                                 config->private_key_passphrase);
829                 /*
830                  * TODO: Support for PEAP with both identity and key passwd.
831                  * In that case, we should check if both of them are found
832                  * from the config file. If not, we should not set the
833                  * service passphrase in order for the UI to request for an
834                  * additional passphrase.
835                  */
836         }
837
838         if (config->phase2 != NULL)
839                 __connman_service_set_string(service, "Phase2", config->phase2);
840
841         if (config->passphrase != NULL)
842                 __connman_service_set_string(service, "Passphrase", config->passphrase);
843 }
844
845 int __connman_config_provision_service(struct connman_service *service)
846 {
847         enum connman_service_type type;
848         GHashTableIter iter;
849         gpointer value, key;
850
851         DBG("service %p", service);
852
853         /* For now only WiFi services are supported */
854         type = connman_service_get_type(service);
855         if (type != CONNMAN_SERVICE_TYPE_WIFI)
856                 return -ENOSYS;
857
858         g_hash_table_iter_init(&iter, config_table);
859
860         while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
861                 struct connman_config *config = value;
862
863                 g_hash_table_foreach(config->service_table,
864                                                 provision_service, service);
865         }
866
867         return 0;
868 }