config: Remove the from_fs config field
[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 };
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         gsize length;
377         char **groups;
378         char *str;
379         gboolean protected;
380         int i;
381
382         DBG("config %p", config);
383
384         keyfile = __connman_storage_open_config(config->ident);
385         if (keyfile == NULL)
386                 return -EIO;
387
388         /* Verify keys validity of the global section */
389         check_keys(keyfile, "global", config_possible_keys);
390
391         str = g_key_file_get_string(keyfile, "global", CONFIG_KEY_NAME, NULL);
392         if (str != NULL) {
393                 g_free(config->name);
394                 config->name = str;
395         }
396
397         str = g_key_file_get_string(keyfile, "global", CONFIG_KEY_DESC, NULL);
398         if (str != NULL) {
399                 g_free(config->description);
400                 config->description = str;
401         }
402
403         protected = g_key_file_get_boolean(keyfile, "global",
404                                         CONFIG_KEY_PROT, NULL);
405         config->protected = protected;
406
407         groups = g_key_file_get_groups(keyfile, &length);
408
409         for (i = 0; groups[i] != NULL; i++) {
410                 if (g_str_has_prefix(groups[i], "service_") == TRUE)
411                         load_service(keyfile, groups[i], config);
412         }
413
414         g_strfreev(groups);
415
416         __connman_storage_close_config(config->ident, keyfile, FALSE);
417
418         return 0;
419 }
420
421 static struct connman_config *create_config(const char *ident)
422 {
423         struct connman_config *config;
424
425         DBG("ident %s", ident);
426
427         if (g_hash_table_lookup(config_table, ident) != NULL)
428                 return NULL;
429
430         config = g_try_new0(struct connman_config, 1);
431         if (config == NULL)
432                 return NULL;
433
434         config->ident = g_strdup(ident);
435
436         config->service_table = g_hash_table_new_full(g_str_hash, g_str_equal,
437                                                 NULL, unregister_service);
438
439         g_hash_table_insert(config_table, config->ident, config);
440
441         connman_info("Adding configuration %s", config->ident);
442
443         return config;
444 }
445
446 int __connman_config_load_service(GKeyFile *keyfile, const char *group,
447                                         connman_bool_t persistent)
448 {
449         struct connman_config *config;
450         const char *service_name;
451         char *ident, *filename = NULL, *content = NULL;
452         gsize content_length;
453         int err;
454
455         service_name = group + strlen("service_");
456         ident = g_strdup_printf("%s_%s", INTERNAL_CONFIG_PREFIX, service_name);
457         if (ident == NULL)
458                 return -ENOMEM;
459
460         DBG("ident %s", ident);
461
462         config = g_hash_table_lookup(config_table, ident);
463         if (config == NULL) {
464                 config = create_config(ident);
465                 if (config == NULL) {
466                         err = -ENOMEM;
467                         goto out;
468                 }
469
470                 config->protected = FALSE;
471         }
472
473         err = load_service(keyfile, group, config);
474         if (persistent == FALSE || err < 0)
475                 goto out;
476
477         g_key_file_set_string(keyfile, "global", CONFIG_KEY_NAME,
478                                                         service_name);
479         g_key_file_set_string(keyfile, "global", CONFIG_KEY_DESC,
480                                                 "Internal Config File");
481
482         content = g_key_file_to_data(keyfile, &content_length, NULL);
483         if (content == NULL) {
484                 err = -EIO;
485                 goto out;
486         }
487
488         filename = g_strdup_printf("%s/%s.config", STORAGEDIR, ident);
489         if (filename == NULL) {
490                 err = -ENOMEM;
491                 goto out;
492         }
493
494         DBG("Saving %d bytes to %s", content_length, filename);
495
496         if (g_file_set_contents(filename, content,
497                                 content_length, NULL) == FALSE) {
498                 err = -EIO;
499                 goto out;
500         }
501
502         return 0;
503
504 out:
505         g_free(ident);
506         g_free(content);
507         g_free(filename);
508
509         return err;
510 }
511
512 static int read_configs(void)
513 {
514         GDir *dir;
515
516         DBG("");
517
518         dir = g_dir_open(STORAGEDIR, 0, NULL);
519         if (dir != NULL) {
520                 const gchar *file;
521
522                 while ((file = g_dir_read_name(dir)) != NULL) {
523                         GString *str;
524                         gchar *ident;
525
526                         if (g_str_has_suffix(file, ".config") == FALSE)
527                                 continue;
528
529                         ident = g_strrstr(file, ".config");
530                         if (ident == NULL)
531                                 continue;
532
533                         str = g_string_new_len(file, ident - file);
534                         if (str == NULL)
535                                 continue;
536
537                         ident = g_string_free(str, FALSE);
538
539                         if (connman_dbus_validate_ident(ident) == TRUE) {
540                                 struct connman_config *config;
541
542                                 config = create_config(ident);
543                                 if (config != NULL)
544                                         load_config(config);
545                         }
546                         g_free(ident);
547                 }
548
549                 g_dir_close(dir);
550         }
551
552         return 0;
553 }
554
555 static gboolean inotify_data(GIOChannel *channel, GIOCondition cond,
556                                                         gpointer user_data)
557 {
558         char buffer[256];
559         char *next_event;
560         gsize bytes_read;
561         GIOStatus status;
562
563         if (cond & (G_IO_NVAL | G_IO_ERR | G_IO_HUP)) {
564                 inotify_watch = 0;
565                 return FALSE;
566         }
567
568         status = g_io_channel_read_chars(channel, buffer,
569                                         sizeof(buffer) -1, &bytes_read, NULL);
570
571         switch (status) {
572         case G_IO_STATUS_NORMAL:
573                 break;
574         case G_IO_STATUS_AGAIN:
575                 return TRUE;
576         default:
577                 connman_error("Reading from inotify channel failed");
578                 inotify_watch = 0;
579                 return FALSE;
580         }
581
582         next_event = buffer;
583
584         while (bytes_read > 0) {
585                 struct inotify_event *event;
586                 gchar *ext;
587                 gchar *ident;
588                 gsize len;
589
590                 event = (struct inotify_event *) next_event;
591                 if (event->len)
592                         ident = next_event + sizeof(struct inotify_event);
593                 else
594                         ident = NULL;
595
596                 len = sizeof(struct inotify_event) + event->len;
597
598                 /* check if inotify_event block fit */
599                 if (len > bytes_read)
600                         break;
601
602                 next_event += len;
603                 bytes_read -= len;
604
605                 if (ident == NULL)
606                         continue;
607
608                 if (g_str_has_suffix(ident, ".config") == FALSE)
609                         continue;
610
611                 ext = g_strrstr(ident, ".config");
612                 if (ext == NULL)
613                         continue;
614
615                 *ext = '\0';
616
617                 if (connman_dbus_validate_ident(ident) == FALSE)
618                         continue;
619
620                 if (event->mask & IN_CREATE)
621                         create_config(ident);
622
623                 if (event->mask & IN_MODIFY) {
624                         struct connman_config *config;
625
626                         config = g_hash_table_lookup(config_table, ident);
627                         if (config != NULL) {
628                                 g_hash_table_remove_all(config->service_table);
629                                 load_config(config);
630                         }
631                 }
632
633                 if (event->mask & IN_DELETE)
634                         g_hash_table_remove(config_table, ident);
635         }
636
637         return TRUE;
638 }
639
640 static int create_watch(void)
641 {
642         int fd;
643
644         fd = inotify_init();
645         if (fd < 0)
646                 return -EIO;
647
648         inotify_wd = inotify_add_watch(fd, STORAGEDIR,
649                                         IN_MODIFY | IN_CREATE | IN_DELETE);
650         if (inotify_wd < 0) {
651                 connman_error("Creation of STORAGEDIR  watch failed");
652                 close(fd);
653                 return -EIO;
654         }
655
656         inotify_channel = g_io_channel_unix_new(fd);
657         if (inotify_channel == NULL) {
658                 connman_error("Creation of inotify channel failed");
659                 inotify_rm_watch(fd, inotify_wd);
660                 inotify_wd = 0;
661
662                 close(fd);
663                 return -EIO;
664         }
665
666         g_io_channel_set_close_on_unref(inotify_channel, TRUE);
667         g_io_channel_set_encoding(inotify_channel, NULL, NULL);
668         g_io_channel_set_buffered(inotify_channel, FALSE);
669
670         inotify_watch = g_io_add_watch(inotify_channel,
671                                 G_IO_IN | G_IO_HUP | G_IO_NVAL | G_IO_ERR,
672                                 inotify_data, NULL);
673
674         return 0;
675 }
676
677 static void remove_watch(void)
678 {
679         int fd;
680
681         if (inotify_channel == NULL)
682                 return;
683
684         if (inotify_watch > 0) {
685                 g_source_remove(inotify_watch);
686                 inotify_watch = 0;
687         }
688
689         fd = g_io_channel_unix_get_fd(inotify_channel);
690
691         if (inotify_wd >= 0) {
692                 inotify_rm_watch(fd, inotify_wd);
693                 inotify_wd = 0;
694         }
695
696         g_io_channel_unref(inotify_channel);
697 }
698
699 int __connman_config_init(void)
700 {
701         DBG("");
702
703         config_table = g_hash_table_new_full(g_str_hash, g_str_equal,
704                                                 NULL, unregister_config);
705
706         create_watch();
707
708         return read_configs();
709 }
710
711 void __connman_config_cleanup(void)
712 {
713         DBG("");
714
715         remove_watch();
716
717         g_hash_table_destroy(config_table);
718         config_table = NULL;
719 }
720
721 static char *config_pem_fsid(const char *pem_file)
722 {
723         struct statfs buf;
724         unsigned *fsid = (unsigned *) &buf.f_fsid;
725         unsigned long long fsid64;
726
727         if (pem_file == NULL)
728                 return NULL;
729
730         if (statfs(pem_file, &buf) < 0) {
731                 connman_error("statfs error %s for %s",
732                                                 strerror(errno), pem_file);
733                 return NULL;
734         }
735
736         fsid64 = ((unsigned long long) fsid[0] << 32) | fsid[1];
737
738         return g_strdup_printf("%llx", fsid64);
739 }
740
741 static void provision_service(gpointer key, gpointer value, gpointer user_data)
742 {
743         struct connman_service *service = user_data;
744         struct connman_config_service *config = value;
745         struct connman_network *network;
746         const void *ssid;
747         unsigned int ssid_len;
748
749         /* For now only WiFi service entries are supported */
750         if (g_strcmp0(config->type, "wifi") != 0)
751                 return;
752
753         network = __connman_service_get_network(service);
754         if (network == NULL) {
755                 connman_error("Service has no network set");
756                 return;
757         }
758
759         ssid = connman_network_get_blob(network, "WiFi.SSID", &ssid_len);
760         if (ssid == NULL) {
761                 connman_error("Network SSID not set");
762                 return;
763         }
764
765         if (config->ssid == NULL || ssid_len != config->ssid_len)
766                 return;
767
768         if (memcmp(config->ssid, ssid, ssid_len) != 0)
769                 return;
770
771         __connman_service_set_immutable(service, TRUE);
772
773         __connman_service_set_favorite(service, TRUE);
774
775         if (config->eap != NULL)
776                 __connman_service_set_string(service, "EAP", config->eap);
777
778         if (config->identity != NULL)
779                 __connman_service_set_string(service, "Identity",
780                                                         config->identity);
781
782         if (config->ca_cert_file != NULL)
783                 __connman_service_set_string(service, "CACertFile",
784                                                         config->ca_cert_file);
785
786         if (config->client_cert_file != NULL)
787                 __connman_service_set_string(service, "ClientCertFile",
788                                                 config->client_cert_file);
789
790         if (config->private_key_file != NULL)
791                 __connman_service_set_string(service, "PrivateKeyFile",
792                                                 config->private_key_file);
793
794         if (g_strcmp0(config->private_key_passphrase_type, "fsid") == 0 &&
795                                         config->private_key_file != NULL) {
796                 char *fsid;
797
798                 fsid = config_pem_fsid(config->private_key_file);
799                 if (fsid == NULL)
800                         return;
801
802                 g_free(config->private_key_passphrase);
803                 config->private_key_passphrase = fsid;
804         }
805
806         if (config->private_key_passphrase != NULL) {
807                 __connman_service_set_string(service, "PrivateKeyPassphrase",
808                                                 config->private_key_passphrase);
809                 /*
810                  * TODO: Support for PEAP with both identity and key passwd.
811                  * In that case, we should check if both of them are found
812                  * from the config file. If not, we should not set the
813                  * service passphrase in order for the UI to request for an
814                  * additional passphrase.
815                  */
816         }
817
818         if (config->phase2 != NULL)
819                 __connman_service_set_string(service, "Phase2", config->phase2);
820
821         if (config->passphrase != NULL)
822                 __connman_service_set_string(service, "Passphrase", config->passphrase);
823 }
824
825 int __connman_config_provision_service(struct connman_service *service)
826 {
827         enum connman_service_type type;
828         GHashTableIter iter;
829         gpointer value, key;
830
831         DBG("service %p", service);
832
833         /* For now only WiFi services are supported */
834         type = connman_service_get_type(service);
835         if (type != CONNMAN_SERVICE_TYPE_WIFI)
836                 return -ENOSYS;
837
838         g_hash_table_iter_init(&iter, config_table);
839
840         while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
841                 struct connman_config *config = value;
842
843                 g_hash_table_foreach(config->service_table,
844                                                 provision_service, service);
845         }
846
847         return 0;
848 }