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