blob: d326ad5dfe1b2ba02cfcde18b911bd2979468a4a [file] [log] [blame]
San Mehat94447ca2009-05-13 11:54:16 -07001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#include <errno.h>
San Mehat5d6d4172009-05-14 15:00:06 -070017#include <netinet/in.h>
18#include <arpa/inet.h>
San Mehat94447ca2009-05-13 11:54:16 -070019
20#define LOG_TAG "OpenVpnController"
21#include <cutils/log.h>
22#include <cutils/properties.h>
23
San Mehat5d6d4172009-05-14 15:00:06 -070024#include <sysutils/ServiceManager.h>
25
San Mehat94447ca2009-05-13 11:54:16 -070026#include "OpenVpnController.h"
27
28#define DAEMON_PROP_NAME "vpn.openvpn.status"
San Mehat5d6d4172009-05-14 15:00:06 -070029#define DAEMON_CONFIG_FILE "/data/misc/openvpn/openvpn.conf"
San Mehat94447ca2009-05-13 11:54:16 -070030
31OpenVpnController::OpenVpnController() :
32 VpnController() {
San Mehat5d6d4172009-05-14 15:00:06 -070033 mServiceManager = new ServiceManager();
34}
35
36OpenVpnController::~OpenVpnController() {
37 delete mServiceManager;
San Mehat94447ca2009-05-13 11:54:16 -070038}
39
40int OpenVpnController::start() {
41 return 0;
42}
43
44int OpenVpnController::stop() {
45 return 0;
46}
47
48int OpenVpnController::enable() {
49
San Mehat5d6d4172009-05-14 15:00:06 -070050 if (validateConfig()) {
51 LOGE("Error validating configuration file");
San Mehat94447ca2009-05-13 11:54:16 -070052 return -1;
53 }
54
San Mehat5d6d4172009-05-14 15:00:06 -070055 if (mServiceManager->start("openvpn"))
56 return -1;
57
San Mehat94447ca2009-05-13 11:54:16 -070058 return 0;
59}
60
61int OpenVpnController::disable() {
San Mehat5d6d4172009-05-14 15:00:06 -070062
63 if (mServiceManager->stop("openvpn"))
64 return -1;
65 return 0;
66}
67
68int OpenVpnController::validateConfig() {
69 unlink(DAEMON_CONFIG_FILE);
70
71 FILE *fp = fopen(DAEMON_CONFIG_FILE, "w");
72 if (!fp)
73 return -1;
74
75 fprintf(fp, "remote %s 1194\n", inet_ntoa(getVpnGateway()));
76 fclose(fp);
77 return 0;
San Mehat94447ca2009-05-13 11:54:16 -070078}