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