Enable devices when policy is set to manual
[connman] / plugins / resolvconf.c
1 /*
2  *
3  *  Connection Manager
4  *
5  *  Copyright (C) 2007-2008  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 <unistd.h>
28 #include <stdlib.h>
29
30 #include <connman/plugin.h>
31 #include <connman/resolver.h>
32 #include <connman/log.h>
33
34 #include <glib.h>
35
36 static int resolvconf_append(const char *interface, const char *domain,
37                                                         const char *server)
38 {
39         char *cmd;
40         int err;
41
42         DBG("interface %s server %s", interface, server);
43
44         if (access(RESOLVCONF, X_OK) < 0)
45                 return -errno;
46
47         cmd = g_strdup_printf("echo \"nameserver %s\" | %s -a %s",
48                                                 server, RESOLVCONF, interface);
49
50         DBG("%s", cmd);
51
52         err = system(cmd);
53
54         g_free(cmd);
55
56         return err;
57 }
58
59 static int resolvconf_remove(const char *interface, const char *domain,
60                                                         const char *server)
61 {
62         char *cmd;
63         int err;
64
65         DBG("interface %s server %s", interface, server);
66
67         cmd = g_strdup_printf("%s -d %s", RESOLVCONF, interface);
68
69         DBG("%s", cmd);
70
71         err = system(cmd);
72
73         g_free(cmd);
74
75         return err;
76 }
77
78 static struct connman_resolver resolvconf_resolver = {
79         .name           = "resolvconf",
80         .priority       = CONNMAN_RESOLVER_PRIORITY_DEFAULT,
81         .append         = resolvconf_append,
82         .remove         = resolvconf_remove,
83 };
84
85 static int resolvconf_init(void)
86 {
87         return connman_resolver_register(&resolvconf_resolver);
88 }
89
90 static void resolvconf_exit(void)
91 {
92         connman_resolver_unregister(&resolvconf_resolver);
93 }
94
95 CONNMAN_PLUGIN_DEFINE(resolvconf, "Name resolver plugin", VERSION,
96                                         resolvconf_init, resolvconf_exit)