Disabled in container environment
[platform/upstream/connman.git] / scripts / libppp-plugin.c
old mode 100644 (file)
new mode 100755 (executable)
index ba79db0..0dd8b47
@@ -2,7 +2,7 @@
  *
  *  Connection Manager
  *
- *  Copyright (C) 2011  Intel Corporation. All rights reserved.
+ *  Copyright (C) 2012-2013  Intel Corporation. All rights reserved.
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License version 2 as
@@ -45,6 +45,7 @@ static char *interface;
 static char *path;
 
 static DBusConnection *connection;
+static int prev_phase;
 
 char pppd_version[] = VERSION;
 
@@ -75,7 +76,7 @@ static void append(DBusMessageIter *dict, const char *key, const char *value)
 }
 
 
-static int ppp_have_secret()
+static int ppp_have_secret(void)
 {
        return 1;
 }
@@ -86,27 +87,27 @@ static int ppp_get_secret(char *username, char *password)
        const char *user, *pass;
        DBusError err;
 
-       if (username == NULL && password == NULL)
+       if (!username && !password)
                return -1;
 
-       if (password == NULL)
+       if (!password)
                return 1;
 
-       if (connection == NULL)
+       if (!connection)
                return -1;
 
        dbus_error_init(&err);
 
        msg = dbus_message_new_method_call(busname, path, interface, "getsec");
-       if (msg == NULL)
+       if (!msg)
                return -1;
 
        dbus_message_append_args(msg, DBUS_TYPE_INVALID, DBUS_TYPE_INVALID);
 
        reply = dbus_connection_send_with_reply_and_block(connection,
                                                                msg, -1, &err);
-       if (reply == NULL) {
-               if (dbus_error_is_set(&err) == TRUE)
+       if (!reply) {
+               if (dbus_error_is_set(&err))
                        dbus_error_free(&err);
 
                dbus_message_unref(msg);
@@ -117,17 +118,17 @@ static int ppp_get_secret(char *username, char *password)
 
        dbus_error_init(&err);
 
-       if (dbus_message_get_args(reply, &err, DBUS_TYPE_STRING, &user,
-                                               DBUS_TYPE_STRING, &pass,
-                                               DBUS_TYPE_INVALID) == FALSE) {
-               if (dbus_error_is_set(&err) == TRUE)
+       if (!dbus_message_get_args(reply, &err, DBUS_TYPE_STRING, &user,
+                                       DBUS_TYPE_STRING, &pass,
+                                       DBUS_TYPE_INVALID)) {
+               if (dbus_error_is_set(&err))
                        dbus_error_free(&err);
 
                dbus_message_unref(reply);
                return -1;
        }
 
-       if (username != NULL)
+       if (username)
                strcpy(username, user);
 
        strcpy(password, pass);
@@ -146,7 +147,7 @@ static void ppp_up(void *data, int arg)
        DBusMessageIter iter, dict;
        DBusMessage *msg;
 
-       if (connection == NULL)
+       if (!connection)
                return;
 
        if (ipcp_gotoptions[0].ouraddr == 0)
@@ -154,7 +155,7 @@ static void ppp_up(void *data, int arg)
 
        msg = dbus_message_new_method_call(busname, path,
                                                interface, "notify");
-       if (msg == NULL)
+       if (!msg)
                return;
 
        dbus_message_set_no_reply(msg, TRUE);
@@ -192,7 +193,7 @@ static void ppp_up(void *data, int arg)
                if (ipcp_gotoptions[0].dnsaddr[1]) {
                        inet_ntop(AF_INET, &ipcp_gotoptions[0].dnsaddr[1],
                                                        buf, INET_ADDRSTRLEN);
-                       if (add_blank == TRUE)
+                       if (add_blank)
                                strcat(dns, " ");
 
                        strcat(dns, buf);
@@ -213,22 +214,22 @@ static void ppp_up(void *data, int arg)
 
 static void ppp_exit(void *data, int arg)
 {
-       if (connection != NULL) {
+       if (connection) {
                dbus_connection_unref(connection);
                connection = NULL;
        }
 
-       if (busname != NULL) {
+       if (busname) {
                free(busname);
                busname = NULL;
        }
 
-       if (interface != NULL) {
+       if (interface) {
                free(interface);
                interface = NULL;
        }
 
-       if (path != NULL) {
+       if (path) {
                free(path);
                path = NULL;
        }
@@ -238,14 +239,21 @@ static void ppp_phase_change(void *data, int arg)
 {
        const char *reason = "disconnect";
        DBusMessage *msg;
+       int send_msg = 0;
 
-       if (connection == NULL)
+       if (!connection)
                return;
 
-       if (arg == PHASE_DEAD || arg == PHASE_DISCONNECT) {
+       if (prev_phase == PHASE_AUTHENTICATE &&
+                               arg == PHASE_TERMINATE) {
+               reason = "auth failed";
+               send_msg = 1;
+       }
+
+       if (send_msg > 0 || arg == PHASE_DEAD || arg == PHASE_DISCONNECT) {
                msg = dbus_message_new_method_call(busname, path,
                                                interface, "notify");
-               if (msg == NULL)
+               if (!msg)
                        return;
 
                dbus_message_set_no_reply(msg, TRUE);
@@ -259,6 +267,8 @@ static void ppp_phase_change(void *data, int arg)
 
                dbus_message_unref(msg);
        }
+
+       prev_phase = arg;
 }
 
 int plugin_init(void)
@@ -272,21 +282,21 @@ int plugin_init(void)
        inter = getenv("CONNMAN_INTERFACE");
        p = getenv("CONNMAN_PATH");
 
-       if (bus == NULL || inter == NULL || p == NULL)
+       if (!bus || !inter || !p)
                return -1;
 
        busname = strdup(bus);
        interface = strdup(inter);
        path = strdup(p);
 
-       if (busname == NULL || interface == NULL || path == NULL) {
+       if (!busname || !interface || !path) {
                ppp_exit(NULL, 0);
                return -1;
        }
 
        connection = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
-       if (connection == NULL) {
-               if (dbus_error_is_set(&error) == TRUE)
+       if (!connection) {
+               if (dbus_error_is_set(&error))
                        dbus_error_free(&error);
 
                ppp_exit(NULL, 0);