summaryrefslogtreecommitdiff
path: root/client/agent.c
diff options
context:
space:
mode:
Diffstat (limited to 'client/agent.c')
-rw-r--r--client/agent.c79
1 files changed, 43 insertions, 36 deletions
diff --git a/client/agent.c b/client/agent.c
index 12b0a98..baa0a87 100644
--- a/client/agent.c
+++ b/client/agent.c
@@ -95,6 +95,11 @@ static struct agent_data agent_request = {
static struct agent_input_data vpnagent_input_handler[] = {
{ "OpenConnect.Cookie", false, "OpenConnect Cookie? ",
request_input_string_return },
+ { "OpenConnect.ServerCert", false,
+ "OpenConnect server certificate hash? ",
+ request_input_string_return },
+ { "OpenConnect.VPNHost", false, "OpenConnect VPN server? ",
+ request_input_string_return },
{ "Username", false, "VPN username? ", request_input_string_return },
{ "Password", false, "VPN password? ", request_input_string_return },
{ },
@@ -109,7 +114,7 @@ static int confirm_input(char *input)
{
int i;
- if (input == NULL)
+ if (!input)
return -1;
for (i = 0; input[i] != '\0'; i++)
@@ -130,7 +135,7 @@ static int confirm_input(char *input)
static char *strip_path(char *path)
{
char *name = strrchr(path, '/');
- if (name != NULL)
+ if (name)
name++;
else
name = path;
@@ -142,7 +147,7 @@ static char *agent_path(void)
{
static char *path = NULL;
- if (path == NULL)
+ if (!path)
path = g_strdup_printf("/net/connman/connmanctl%d", getpid());
return path;
@@ -150,12 +155,12 @@ static char *agent_path(void)
static void pending_message_remove(struct agent_data *request)
{
- if (request->message != NULL) {
+ if (request->message) {
dbus_message_unref(request->message);
request->message = NULL;
}
- if (request->reply != NULL) {
+ if (request->reply) {
dbus_message_unref(request->reply);
request->reply = NULL;
}
@@ -178,12 +183,12 @@ static void pending_command_complete(char *message)
else
__connmanctl_agent_mode("", NULL, NULL);
- if (agent_request.message != NULL)
+ if (agent_request.message)
next_request = &agent_request;
- else if (vpn_agent_request.message != NULL)
+ else if (vpn_agent_request.message)
next_request = &vpn_agent_request;
- if (next_request == NULL)
+ if (!next_request)
return;
pending_message = next_request->message;
@@ -199,8 +204,8 @@ static void pending_command_complete(char *message)
static bool handle_message(DBusMessage *message, struct agent_data *request,
GDBusMethodFunction function)
{
- if (agent_request.pending_function == NULL &&
- vpn_agent_request.pending_function == NULL)
+ if (!agent_request.pending_function &&
+ !vpn_agent_request.pending_function)
return true;
request->message = dbus_message_ref(message);
@@ -367,9 +372,9 @@ static void request_input_next(struct agent_data *request)
{
int i;
- for (i = 0; request->input[i].attribute != NULL; i++) {
+ for (i = 0; request->input[i].attribute; i++) {
if (request->input[i].requested == true) {
- if(request->input[i].func != NULL)
+ if (request->input[i].func)
__connmanctl_agent_mode(request->input[i].prompt,
request->input[i].func,
request);
@@ -403,7 +408,7 @@ static void request_input_ssid_return(char *input,
struct agent_data *request = user_data;
int len = 0;
- if (input != NULL)
+ if (input)
len = strlen(input);
if (len > 0 && len <= 32) {
@@ -422,7 +427,7 @@ static void request_input_passphrase_return(char *input, void *user_data)
/* TBD passphrase length checking */
- if (input != NULL)
+ if (input)
len = strlen(input);
if (len == 0 && request->input[WPS].requested == false)
@@ -445,7 +450,7 @@ static void request_input_string_return(char *input, void *user_data)
struct agent_data *request = user_data;
int i;
- for (i = 0; request->input[i].attribute != NULL; i++) {
+ for (i = 0; request->input[i].attribute; i++) {
if (request->input[i].requested == true) {
request_input_append(request,
request->input[i].attribute, input);
@@ -464,7 +469,7 @@ static DBusMessage *agent_request_input(DBusConnection *connection,
DBusMessageIter iter, dict, entry, variant;
char *service, *str, *field;
DBusMessageIter dict_entry, field_entry, field_value;
- char *argument, *value, *attr_type;
+ char *argument, *value, *attr_type = NULL;
int i;
@@ -519,7 +524,7 @@ static DBusMessage *agent_request_input(DBusConnection *connection,
dbus_message_iter_next(&dict_entry);
}
- for (i = 0; request->input[i].attribute != NULL; i++) {
+ for (i = 0; request->input[i].attribute; i++) {
if (strcmp(field, request->input[i].attribute) == 0) {
request->input[i].requested = true;
break;
@@ -570,7 +575,7 @@ static int agent_register_return(DBusMessageIter *iter, const char *error,
{
DBusConnection *connection = user_data;
- if (error != NULL) {
+ if (error) {
g_dbus_unregister_interface(connection, agent_path(),
AGENT_INTERFACE);
fprintf(stderr, "Error registering Agent: %s\n", error);
@@ -583,6 +588,13 @@ static int agent_register_return(DBusMessageIter *iter, const char *error,
return -EINPROGRESS;
}
+static void append_path(DBusMessageIter *iter, void *user_data)
+{
+ const char *path = user_data;
+
+ dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH, &path);
+}
+
int __connmanctl_agent_register(DBusConnection *connection)
{
char *path = agent_path();
@@ -595,18 +607,16 @@ int __connmanctl_agent_register(DBusConnection *connection)
agent_connection = connection;
- if (g_dbus_register_interface(connection, path,
+ if (!g_dbus_register_interface(connection, path,
AGENT_INTERFACE, agent_methods,
- NULL, NULL, &agent_request,
- NULL) == FALSE) {
+ NULL, NULL, &agent_request, NULL)) {
fprintf(stderr, "Error: Failed to register Agent callbacks\n");
return 0;
}
result = __connmanctl_dbus_method_call(connection, CONNMAN_SERVICE,
CONNMAN_PATH, "net.connman.Manager", "RegisterAgent",
- agent_register_return, connection,
- DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID);
+ agent_register_return, connection, append_path, path);
if (result != -EINPROGRESS) {
g_dbus_unregister_interface(connection, agent_path(),
@@ -621,7 +631,7 @@ int __connmanctl_agent_register(DBusConnection *connection)
static int agent_unregister_return(DBusMessageIter *iter, const char *error,
void *user_data)
{
- if (error != NULL) {
+ if (error) {
fprintf(stderr, "Error unregistering Agent: %s\n", error);
return 0;
}
@@ -646,8 +656,7 @@ int __connmanctl_agent_unregister(DBusConnection *connection)
result = __connmanctl_dbus_method_call(connection, CONNMAN_SERVICE,
CONNMAN_PATH, "net.connman.Manager", "UnregisterAgent",
- agent_unregister_return, NULL,
- DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID);
+ agent_unregister_return, NULL, append_path, path);
if (result != -EINPROGRESS)
fprintf(stderr, "Error: Failed to unregister Agent\n");
@@ -675,7 +684,7 @@ static int vpn_agent_register_return(DBusMessageIter *iter, const char *error,
{
DBusConnection *connection = user_data;
- if (error != NULL) {
+ if (error) {
g_dbus_unregister_interface(connection, agent_path(),
VPN_AGENT_INTERFACE);
fprintf(stderr, "Error registering VPN Agent: %s\n", error);
@@ -700,10 +709,9 @@ int __connmanctl_vpn_agent_register(DBusConnection *connection)
agent_connection = connection;
- if (g_dbus_register_interface(connection, path,
- VPN_AGENT_INTERFACE, vpn_agent_methods,
- NULL, NULL, &vpn_agent_request,
- NULL) == FALSE) {
+ if (!g_dbus_register_interface(connection, path,
+ VPN_AGENT_INTERFACE, vpn_agent_methods,
+ NULL, NULL, &vpn_agent_request, NULL)) {
fprintf(stderr, "Error: Failed to register VPN Agent "
"callbacks\n");
return 0;
@@ -711,8 +719,8 @@ int __connmanctl_vpn_agent_register(DBusConnection *connection)
result = __connmanctl_dbus_method_call(connection, VPN_SERVICE,
VPN_PATH, "net.connman.vpn.Manager", "RegisterAgent",
- vpn_agent_register_return, connection,
- DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID);
+ vpn_agent_register_return, connection, append_path,
+ path);
if (result != -EINPROGRESS) {
g_dbus_unregister_interface(connection, agent_path(),
@@ -727,7 +735,7 @@ int __connmanctl_vpn_agent_register(DBusConnection *connection)
static int vpn_agent_unregister_return(DBusMessageIter *iter,
const char *error, void *user_data)
{
- if (error != NULL) {
+ if (error) {
fprintf(stderr, "Error unregistering VPN Agent: %s\n", error);
return 0;
}
@@ -753,8 +761,7 @@ int __connmanctl_vpn_agent_unregister(DBusConnection *connection)
result = __connmanctl_dbus_method_call(connection, VPN_SERVICE,
VPN_PATH, "net.connman.vpn.Manager", "UnregisterAgent",
- vpn_agent_unregister_return, NULL,
- DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID);
+ vpn_agent_unregister_return, NULL, append_path, path);
if (result != -EINPROGRESS)
fprintf(stderr, "Error: Failed to unregister VPN Agent\n");