config: Save D-Bus provisioned files
[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 (g_strcmp0(service->type, "wifi") == 0 &&
195                         strncmp(s->ssid, service->ssid, s->ssid_len) == 0) {
196                         return TRUE;
197                 }
198         }
199
200         return FALSE;
201 }
202
203 static int load_service(GKeyFile *keyfile, const char *group,
204                                                 struct connman_config *config)
205 {
206         struct connman_config_service *service;
207         const char *ident;
208         char *str, *hex_ssid;
209         gboolean service_created = FALSE;
210         int err;
211
212         /* Strip off "service_" prefix */
213         ident = group + 8;
214
215         if (strlen(ident) < 1)
216                 return -EINVAL;
217
218         /* Verify that provided keys are good */
219         check_keys(keyfile, group, service_possible_keys);
220
221         service = g_hash_table_lookup(config->service_table, ident);
222         if (service == NULL) {
223                 service = g_try_new0(struct connman_config_service, 1);
224                 if (service == NULL)
225                         return -ENOMEM;
226
227                 service->ident = g_strdup(ident);
228
229                 service_created = TRUE;
230         }
231
232         str = g_key_file_get_string(keyfile, group, SERVICE_KEY_TYPE, NULL);
233         if (str != NULL) {
234                 g_free(service->type);
235                 service->type = str;
236         }
237
238         str = g_key_file_get_string(keyfile, group, SERVICE_KEY_NAME, NULL);
239         if (str != NULL) {
240                 g_free(service->name);
241                 service->name = str;
242         }
243
244         hex_ssid = g_key_file_get_string(keyfile, group, SERVICE_KEY_SSID,
245                                          NULL);
246         if (hex_ssid != NULL) {
247                 char *ssid;
248                 unsigned int i, j = 0, hex;
249                 size_t hex_ssid_len = strlen(hex_ssid);
250
251                 ssid = g_try_malloc0(hex_ssid_len / 2);
252                 if (ssid == NULL) {
253                         err = -ENOMEM;
254                         g_free(hex_ssid);
255                         goto err;
256                 }
257
258                 for (i = 0; i < hex_ssid_len; i += 2) {
259                         sscanf(hex_ssid + i, "%02x", &hex);
260                         ssid[j++] = hex;
261                 }
262
263                 g_free(hex_ssid);
264
265                 g_free(service->ssid);
266                 service->ssid = ssid;
267                 service->ssid_len = hex_ssid_len / 2;
268         } else if (service->name != NULL) {
269                 char *ssid;
270                 unsigned int ssid_len;
271
272                 ssid_len = strlen(service->name);
273                 ssid = g_try_malloc0(ssid_len);
274                 if (ssid == NULL) {
275                         err = -ENOMEM;
276                         goto err;
277                 }
278
279                 memcpy(ssid, service->name, ssid_len);
280                 g_free(service->ssid);
281                 service->ssid = ssid;
282                 service->ssid_len = ssid_len;
283         }
284
285         if (is_protected_service(service) == TRUE) {
286                 connman_error("Trying to provision a protected service");
287                 err = -EACCES;
288                 goto err;
289         }
290
291         str = g_key_file_get_string(keyfile, group, SERVICE_KEY_EAP, NULL);
292         if (str != NULL) {
293                 g_free(service->eap);
294                 service->eap = str;
295         }
296
297         str = g_key_file_get_string(keyfile, group, SERVICE_KEY_CA_CERT, NULL);
298         if (str != NULL) {
299                 g_free(service->ca_cert_file);
300                 service->ca_cert_file = str;
301         }
302
303         str = g_key_file_get_string(keyfile, group, SERVICE_KEY_CL_CERT, NULL);
304         if (str != NULL) {
305                 g_free(service->client_cert_file);
306                 service->client_cert_file = str;
307         }
308
309         str = g_key_file_get_string(keyfile, group, SERVICE_KEY_PRV_KEY, NULL);
310         if (str != NULL) {
311                 g_free(service->private_key_file);
312                 service->private_key_file = str;
313         }
314
315         str = g_key_file_get_string(keyfile, group,
316                                                 SERVICE_KEY_PRV_KEY_PASS, NULL);
317         if (str != NULL) {
318                 g_free(service->private_key_passphrase);
319                 service->private_key_passphrase = str;
320         }
321
322         str = g_key_file_get_string(keyfile, group,
323                                         SERVICE_KEY_PRV_KEY_PASS_TYPE, NULL);
324         if (str != NULL) {
325                 g_free(service->private_key_passphrase_type);
326                 service->private_key_passphrase_type = str;
327         }
328
329         str = g_key_file_get_string(keyfile, group, SERVICE_KEY_IDENTITY, NULL);
330         if (str != NULL) {
331                 g_free(service->identity);
332                 service->identity = str;
333         }
334
335         str = g_key_file_get_string(keyfile, group, SERVICE_KEY_PHASE2, NULL);
336         if (str != NULL) {
337                 g_free(service->phase2);
338                 service->phase2 = str;
339         }
340
341         str = g_key_file_get_string(keyfile, group, SERVICE_KEY_PASSPHRASE,
342                                         NULL);
343         if (str != NULL) {
344                 g_free(service->passphrase);
345                 service->passphrase = str;
346         }
347
348         if (g_strcmp0(config->ident, NONFS_CONFIG_NAME) != 0)
349                 service->from_fs = TRUE;
350         else
351                 service->from_fs = FALSE;
352
353         if (service_created)
354                 g_hash_table_insert(config->service_table, service->ident,
355                                         service);
356
357         if (config->protected == TRUE)
358                 protected_services =
359                         g_slist_append(protected_services, service);
360
361         connman_info("Adding service configuration %s", service->ident);
362
363         return 0;
364
365 err:
366         if (service_created == TRUE) {
367                 g_free(service->ident);
368                 g_free(service->type);
369                 g_free(service->name);
370                 g_free(service->ssid);
371                 g_free(service);
372         }
373
374         return err;
375 }
376
377 static int load_config(struct connman_config *config)
378 {
379         GKeyFile *keyfile;
380         gsize length;
381         char **groups;
382         char *str;
383         gboolean protected;
384         int i;
385
386         DBG("config %p", config);
387
388         keyfile = __connman_storage_open_config(config->ident);
389         if (keyfile == NULL)
390                 return -EIO;
391
392         /* Verify keys validity of the global section */
393         check_keys(keyfile, "global", config_possible_keys);
394
395         str = g_key_file_get_string(keyfile, "global", CONFIG_KEY_NAME, NULL);
396         if (str != NULL) {
397                 g_free(config->name);
398                 config->name = str;
399         }
400
401         str = g_key_file_get_string(keyfile, "global", CONFIG_KEY_DESC, NULL);
402         if (str != NULL) {
403                 g_free(config->description);
404                 config->description = str;
405         }
406
407         protected = g_key_file_get_boolean(keyfile, "global",
408                                         CONFIG_KEY_PROT, NULL);
409         config->protected = protected;
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
486         content = g_key_file_to_data(keyfile, &content_length, NULL);
487         if (content == NULL) {
488                 err = -EIO;
489                 goto out;
490         }
491
492         filename = g_strdup_printf("%s/%s.config", STORAGEDIR, ident);
493         if (filename == NULL) {
494                 err = -ENOMEM;
495                 goto out;
496         }
497
498         DBG("Saving %d bytes to %s", content_length, filename);
499
500         if (g_file_set_contents(filename, content,
501                                 content_length, NULL) == FALSE) {
502                 err = -EIO;
503                 goto out;
504         }
505
506         return 0;
507
508 out:
509         g_free(ident);
510         g_free(content);
511         g_free(filename);
512
513         return err;
514 }
515
516 static int read_configs(void)
517 {
518         GDir *dir;
519
520         DBG("");
521
522         dir = g_dir_open(STORAGEDIR, 0, NULL);
523         if (dir != NULL) {
524                 const gchar *file;
525
526                 while ((file = g_dir_read_name(dir)) != NULL) {
527                         GString *str;
528                         gchar *ident;
529
530                         if (g_str_has_suffix(file, ".config") == FALSE)
531                                 continue;
532
533                         ident = g_strrstr(file, ".config");
534                         if (ident == NULL)
535                                 continue;
536
537                         if (g_str_equal(ident, NONFS_CONFIG_NAME) == TRUE)
538                                 continue;
539
540                         str = g_string_new_len(file, ident - file);
541                         if (str == NULL)
542                                 continue;
543
544                         ident = g_string_free(str, FALSE);
545
546                         if (connman_dbus_validate_ident(ident) == TRUE) {
547                                 struct connman_config *config;
548
549                                 config = create_config(ident);
550                                 if (config != NULL)
551                                         load_config(config);
552                         }
553                         g_free(ident);
554                 }
555
556                 g_dir_close(dir);
557         }
558
559         return 0;
560 }
561
562 static gboolean inotify_data(GIOChannel *channel, GIOCondition cond,
563                                                         gpointer user_data)
564 {
565         char buffer[256];
566         char *next_event;
567         gsize bytes_read;
568         GIOStatus status;
569
570         if (cond & (G_IO_NVAL | G_IO_ERR | G_IO_HUP)) {
571                 inotify_watch = 0;
572                 return FALSE;
573         }
574
575         status = g_io_channel_read_chars(channel, buffer,
576                                         sizeof(buffer) -1, &bytes_read, NULL);
577
578         switch (status) {
579         case G_IO_STATUS_NORMAL:
580                 break;
581         case G_IO_STATUS_AGAIN:
582                 return TRUE;
583         default:
584                 connman_error("Reading from inotify channel failed");
585                 inotify_watch = 0;
586                 return FALSE;
587         }
588
589         next_event = buffer;
590
591         while (bytes_read > 0) {
592                 struct inotify_event *event;
593                 gchar *ext;
594                 gchar *ident;
595                 gsize len;
596
597                 event = (struct inotify_event *) next_event;
598                 if (event->len)
599                         ident = next_event + sizeof(struct inotify_event);
600                 else
601                         ident = NULL;
602
603                 len = sizeof(struct inotify_event) + event->len;
604
605                 /* check if inotify_event block fit */
606                 if (len > bytes_read)
607                         break;
608
609                 next_event += len;
610                 bytes_read -= len;
611
612                 if (ident == NULL)
613                         continue;
614
615                 if (g_str_has_suffix(ident, ".config") == FALSE)
616                         continue;
617
618                 ext = g_strrstr(ident, ".config");
619                 if (ext == NULL)
620                         continue;
621
622                 *ext = '\0';
623
624                 if (g_str_equal(ident, NONFS_CONFIG_NAME) == TRUE)
625                         continue;
626
627                 if (connman_dbus_validate_ident(ident) == FALSE)
628                         continue;
629
630                 if (event->mask & IN_CREATE)
631                         create_config(ident);
632
633                 if (event->mask & IN_MODIFY) {
634                         struct connman_config *config;
635
636                         config = g_hash_table_lookup(config_table, ident);
637                         if (config != NULL) {
638                                 g_hash_table_remove_all(config->service_table);
639                                 load_config(config);
640                         }
641                 }
642
643                 if (event->mask & IN_DELETE)
644                         g_hash_table_remove(config_table, ident);
645         }
646
647         return TRUE;
648 }
649
650 static int create_watch(void)
651 {
652         int fd;
653
654         fd = inotify_init();
655         if (fd < 0)
656                 return -EIO;
657
658         inotify_wd = inotify_add_watch(fd, STORAGEDIR,
659                                         IN_MODIFY | IN_CREATE | IN_DELETE);
660         if (inotify_wd < 0) {
661                 connman_error("Creation of STORAGEDIR  watch failed");
662                 close(fd);
663                 return -EIO;
664         }
665
666         inotify_channel = g_io_channel_unix_new(fd);
667         if (inotify_channel == NULL) {
668                 connman_error("Creation of inotify channel failed");
669                 inotify_rm_watch(fd, inotify_wd);
670                 inotify_wd = 0;
671
672                 close(fd);
673                 return -EIO;
674         }
675
676         g_io_channel_set_close_on_unref(inotify_channel, TRUE);
677         g_io_channel_set_encoding(inotify_channel, NULL, NULL);
678         g_io_channel_set_buffered(inotify_channel, FALSE);
679
680         inotify_watch = g_io_add_watch(inotify_channel,
681                                 G_IO_IN | G_IO_HUP | G_IO_NVAL | G_IO_ERR,
682                                 inotify_data, NULL);
683
684         return 0;
685 }
686
687 static void remove_watch(void)
688 {
689         int fd;
690
691         if (inotify_channel == NULL)
692                 return;
693
694         if (inotify_watch > 0) {
695                 g_source_remove(inotify_watch);
696                 inotify_watch = 0;
697         }
698
699         fd = g_io_channel_unix_get_fd(inotify_channel);
700
701         if (inotify_wd >= 0) {
702                 inotify_rm_watch(fd, inotify_wd);
703                 inotify_wd = 0;
704         }
705
706         g_io_channel_unref(inotify_channel);
707 }
708
709 int __connman_config_init(void)
710 {
711         DBG("");
712
713         config_table = g_hash_table_new_full(g_str_hash, g_str_equal,
714                                                 NULL, unregister_config);
715
716         create_watch();
717
718         return read_configs();
719 }
720
721 void __connman_config_cleanup(void)
722 {
723         DBG("");
724
725         remove_watch();
726
727         g_hash_table_destroy(config_table);
728         config_table = NULL;
729 }
730
731 static char *config_pem_fsid(const char *pem_file)
732 {
733         struct statfs buf;
734         unsigned *fsid = (unsigned *) &buf.f_fsid;
735         unsigned long long fsid64;
736
737         if (pem_file == NULL)
738                 return NULL;
739
740         if (statfs(pem_file, &buf) < 0) {
741                 connman_error("statfs error %s for %s",
742                                                 strerror(errno), pem_file);
743                 return NULL;
744         }
745
746         fsid64 = ((unsigned long long) fsid[0] << 32) | fsid[1];
747
748         return g_strdup_printf("%llx", fsid64);
749 }
750
751 static void provision_service(gpointer key, gpointer value, gpointer user_data)
752 {
753         struct connman_service *service = user_data;
754         struct connman_config_service *config = value;
755         struct connman_network *network;
756         const void *ssid;
757         unsigned int ssid_len;
758
759         /* For now only WiFi service entries are supported */
760         if (g_strcmp0(config->type, "wifi") != 0)
761                 return;
762
763         network = __connman_service_get_network(service);
764         if (network == NULL) {
765                 connman_error("Service has no network set");
766                 return;
767         }
768
769         ssid = connman_network_get_blob(network, "WiFi.SSID", &ssid_len);
770         if (ssid == NULL) {
771                 connman_error("Network SSID not set");
772                 return;
773         }
774
775         if (config->ssid == NULL || ssid_len != config->ssid_len)
776                 return;
777
778         if (memcmp(config->ssid, ssid, ssid_len) != 0)
779                 return;
780
781         /* do not provision immutable services with non-fs originated configs */
782         if (config->from_fs == FALSE &&
783                         __connman_service_get_immutable(service) == TRUE)
784                 return;
785
786         /* only lock services with a config originated from the filesystem */
787         if (config->from_fs == TRUE)
788                 __connman_service_set_immutable(service, TRUE);
789
790         __connman_service_set_favorite(service, TRUE);
791
792         if (config->eap != NULL)
793                 __connman_service_set_string(service, "EAP", config->eap);
794
795         if (config->identity != NULL)
796                 __connman_service_set_string(service, "Identity",
797                                                         config->identity);
798
799         if (config->ca_cert_file != NULL)
800                 __connman_service_set_string(service, "CACertFile",
801                                                         config->ca_cert_file);
802
803         if (config->client_cert_file != NULL)
804                 __connman_service_set_string(service, "ClientCertFile",
805                                                 config->client_cert_file);
806
807         if (config->private_key_file != NULL)
808                 __connman_service_set_string(service, "PrivateKeyFile",
809                                                 config->private_key_file);
810
811         if (g_strcmp0(config->private_key_passphrase_type, "fsid") == 0 &&
812                                         config->private_key_file != NULL) {
813                 char *fsid;
814
815                 fsid = config_pem_fsid(config->private_key_file);
816                 if (fsid == NULL)
817                         return;
818
819                 g_free(config->private_key_passphrase);
820                 config->private_key_passphrase = fsid;
821         }
822
823         if (config->private_key_passphrase != NULL) {
824                 __connman_service_set_string(service, "PrivateKeyPassphrase",
825                                                 config->private_key_passphrase);
826                 /*
827                  * TODO: Support for PEAP with both identity and key passwd.
828                  * In that case, we should check if both of them are found
829                  * from the config file. If not, we should not set the
830                  * service passphrase in order for the UI to request for an
831                  * additional passphrase.
832                  */
833         }
834
835         if (config->phase2 != NULL)
836                 __connman_service_set_string(service, "Phase2", config->phase2);
837
838         if (config->passphrase != NULL)
839                 __connman_service_set_string(service, "Passphrase", config->passphrase);
840 }
841
842 int __connman_config_provision_service(struct connman_service *service)
843 {
844         enum connman_service_type type;
845         GHashTableIter iter;
846         gpointer value, key;
847
848         DBG("service %p", service);
849
850         /* For now only WiFi services are supported */
851         type = connman_service_get_type(service);
852         if (type != CONNMAN_SERVICE_TYPE_WIFI)
853                 return -ENOSYS;
854
855         g_hash_table_iter_init(&iter, config_table);
856
857         while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
858                 struct connman_config *config = value;
859
860                 g_hash_table_foreach(config->service_table,
861                                                 provision_service, service);
862         }
863
864         return 0;
865 }