dbus: Remove perror() calls

The perror() calls do not make much sense with libdbus functions and
wpa_printf() would really be used for all error printing anyway. In
addition, many of the error messages on out-of-memory cases are not
really of much use, so they were removed. This is also cleaning up
some of the error path handling to avoid duplicated code.
This commit is contained in:
Jouni Malinen 2010-01-01 20:50:12 +02:00
parent c49cf2d68f
commit c2b8c674cb
8 changed files with 144 additions and 379 deletions

View file

@ -291,8 +291,7 @@ static int integrate_with_eloop(struct wpas_dbus_priv *priv)
if (!dbus_connection_set_watch_functions(priv->con, add_watch,
remove_watch, watch_toggled,
priv, NULL)) {
perror("dbus_connection_set_watch_functions[dbus]");
wpa_printf(MSG_ERROR, "Not enough memory to set up dbus.");
wpa_printf(MSG_ERROR, "dbus: Not enough memory to set up");
return -1;
}
@ -300,14 +299,13 @@ static int integrate_with_eloop(struct wpas_dbus_priv *priv)
remove_timeout,
timeout_toggled, priv,
NULL)) {
perror("dbus_connection_set_timeout_functions[dbus]");
wpa_printf(MSG_ERROR, "Not enough memory to set up dbus.");
wpa_printf(MSG_ERROR, "dbus: Not enough memory to set up");
return -1;
}
if (connection_setup_wakeup_main(priv) < 0) {
perror("connection_setup_wakeup_main[dbus]");
wpa_printf(MSG_ERROR, "Could not setup main wakeup function.");
wpa_printf(MSG_ERROR, "dbus: Could not setup main wakeup "
"function");
return -1;
}

View file

@ -636,17 +636,14 @@ static dbus_bool_t _wpa_dbus_dict_entry_get_byte_array(
{
dbus_uint32_t count = 0;
dbus_bool_t success = FALSE;
char *buffer;
char *buffer, *nbuffer;;
entry->bytearray_value = NULL;
entry->array_type = DBUS_TYPE_BYTE;
buffer = os_zalloc(BYTE_ARRAY_ITEM_SIZE * BYTE_ARRAY_CHUNK_SIZE);
if (!buffer) {
perror("_wpa_dbus_dict_entry_get_byte_array[dbus]: out of "
"memory");
goto done;
}
if (!buffer)
return FALSE;
entry->bytearray_value = buffer;
entry->array_len = 0;
@ -654,14 +651,17 @@ static dbus_bool_t _wpa_dbus_dict_entry_get_byte_array(
char byte;
if ((count % BYTE_ARRAY_CHUNK_SIZE) == 0 && count != 0) {
buffer = os_realloc(buffer, BYTE_ARRAY_ITEM_SIZE *
nbuffer = os_realloc(buffer, BYTE_ARRAY_ITEM_SIZE *
(count + BYTE_ARRAY_CHUNK_SIZE));
if (buffer == NULL) {
perror("_wpa_dbus_dict_entry_get_byte_array["
"dbus] out of memory trying to "
"retrieve the string array");
if (nbuffer == NULL) {
os_free(buffer);
wpa_printf(MSG_ERROR, "dbus: _wpa_dbus_dict_"
"entry_get_byte_array out of "
"memory trying to retrieve the "
"string array");
goto done;
}
buffer = nbuffer;
}
entry->bytearray_value = buffer;
@ -693,17 +693,14 @@ static dbus_bool_t _wpa_dbus_dict_entry_get_string_array(
{
dbus_uint32_t count = 0;
dbus_bool_t success = FALSE;
char **buffer;
char **buffer, **nbuffer;
entry->strarray_value = NULL;
entry->array_type = DBUS_TYPE_STRING;
buffer = os_zalloc(STR_ARRAY_ITEM_SIZE * STR_ARRAY_CHUNK_SIZE);
if (buffer == NULL) {
perror("_wpa_dbus_dict_entry_get_string_array[dbus] out of "
"memory trying to retrieve a string array");
goto done;
}
if (buffer == NULL)
return FALSE;
entry->strarray_value = buffer;
entry->array_len = 0;
@ -712,23 +709,26 @@ static dbus_bool_t _wpa_dbus_dict_entry_get_string_array(
char *str;
if ((count % STR_ARRAY_CHUNK_SIZE) == 0 && count != 0) {
buffer = os_realloc(buffer, STR_ARRAY_ITEM_SIZE *
nbuffer = os_realloc(buffer, STR_ARRAY_ITEM_SIZE *
(count + STR_ARRAY_CHUNK_SIZE));
if (buffer == NULL) {
perror("_wpa_dbus_dict_entry_get_string_array["
"dbus] out of memory trying to "
"retrieve the string array");
if (nbuffer == NULL) {
os_free(buffer);
wpa_printf(MSG_ERROR, "dbus: _wpa_dbus_dict_"
"entry_get_string_array out of "
"memory trying to retrieve the "
"string array");
goto done;
}
buffer = nbuffer;
}
entry->strarray_value = buffer;
dbus_message_iter_get_basic(iter, &value);
str = os_strdup(value);
if (str == NULL) {
perror("_wpa_dbus_dict_entry_get_string_array[dbus] "
"out of memory trying to duplicate the string "
"array");
wpa_printf(MSG_ERROR, "dbus: _wpa_dbus_dict_entry_get_"
"string_array out of memory trying to "
"duplicate the string array");
goto done;
}
entry->strarray_value[count] = str;
@ -933,10 +933,8 @@ error:
*/
dbus_bool_t wpa_dbus_dict_has_dict_entry(DBusMessageIter *iter_dict)
{
if (!iter_dict) {
perror("wpa_dbus_dict_has_dict_entry[dbus]: out of memory");
if (!iter_dict)
return FALSE;
}
return dbus_message_iter_get_arg_type(iter_dict) ==
DBUS_TYPE_DICT_ENTRY;
}

View file

@ -458,26 +458,13 @@ void wpas_dbus_signal_state_changed(struct wpa_supplicant *wpa_s,
_signal = dbus_message_new_signal(wpa_s->dbus_new_path,
WPAS_DBUS_NEW_IFACE_INTERFACE,
"StateChanged");
if (_signal == NULL) {
perror("wpas_dbus_signal_state_changed[dbus]: "
"couldn't create dbus signal; likely out of memory");
wpa_printf(MSG_ERROR,
"wpas_dbus_signal_state_changed[dbus]: "
"couldn't create dbus signal; likely out of "
"memory.");
if (_signal == NULL)
return;
}
new_state_str = os_strdup(wpa_supplicant_state_txt(new_state));
old_state_str = os_strdup(wpa_supplicant_state_txt(old_state));
if (new_state_str == NULL || old_state_str == NULL) {
perror("wpas_dbus_signal_state_changed[dbus]: "
"couldn't convert state strings");
wpa_printf(MSG_ERROR,
"wpas_dbus_signal_state_changed[dbus]: "
"couldn't convert state strings.");
if (new_state_str == NULL || old_state_str == NULL)
goto out;
}
/* make state string lowercase to fit new DBus API convention */
tmp = new_state_str;
@ -495,12 +482,10 @@ void wpas_dbus_signal_state_changed(struct wpa_supplicant *wpa_s,
DBUS_TYPE_STRING, &new_state_str,
DBUS_TYPE_STRING, &old_state_str,
DBUS_TYPE_INVALID)) {
perror("wpas_dbus_signal_state_changed[dbus]: "
"not enough memory to construct state change signal.");
wpa_printf(MSG_ERROR,
"wpas_dbus_signal_state_changed[dbus]: "
"dbus: wpas_dbus_signal_state_changed: "
"not enough memory to construct state change "
"signal.");
"signal");
goto out;
}
@ -730,19 +715,13 @@ void wpas_dbus_signal_wps_cred(struct wpa_supplicant *wpa_s,
_signal = dbus_message_new_signal(wpa_s->dbus_new_path,
WPAS_DBUS_NEW_IFACE_WPS,
"Credentials");
if (!_signal) {
wpa_printf(MSG_ERROR, "wpas_dbus_signal_wps_cred[dbus]: "
"out of memory when creating a signal");
if (!_signal)
return;
}
dbus_message_iter_init_append(_signal, &iter);
if (!wpa_dbus_dict_open_write(&iter, &dict_iter)) {
perror("wpas_dbus_signal_wps_cred[dbus]: out of memory "
"when opening a dictionary");
if (!wpa_dbus_dict_open_write(&iter, &dict_iter))
goto nomem;
}
if (cred->auth_type & WPS_AUTH_OPEN)
auth_type[at_num++] = "open";
@ -771,12 +750,9 @@ void wpas_dbus_signal_wps_cred(struct wpa_supplicant *wpa_s,
if (!wpa_dbus_dict_append_byte_array(
&dict_iter, "BSSID",
(const char *) wpa_s->current_ssid->bssid,
ETH_ALEN)) {
perror("wpas_dbus_signal_wps_cred[dbus]: out of "
"memory when appending bssid to dictionary");
ETH_ALEN))
goto nomem;
}
}
if (!(wpa_dbus_dict_append_byte_array(&dict_iter, "SSID",
(const char *) cred->ssid,
@ -791,17 +767,11 @@ void wpas_dbus_signal_wps_cred(struct wpa_supplicant *wpa_s,
(const char *) cred->key,
cred->key_len) &&
wpa_dbus_dict_append_uint32(&dict_iter, "KeyIndex",
cred->key_idx))) {
perror("wpas_dbus_signal_wps_cred[dbus]: out of memory "
"when appending to dictionary");
cred->key_idx)))
goto nomem;
}
if (!wpa_dbus_dict_close_write(&iter, &dict_iter)) {
perror("wpas_dbus_signal_wps_cred[dbus]: out of memory "
"when closing a dictionary");
if (!wpa_dbus_dict_close_write(&iter, &dict_iter))
goto nomem;
}
dbus_connection_send(iface->con, _signal, NULL);

View file

@ -709,16 +709,11 @@ DBusMessage * wpas_dbus_handler_get_interface(DBusMessage *message,
path = wpa_s->dbus_new_path;
reply = dbus_message_new_method_return(message);
if (reply == NULL) {
perror("wpas_dbus_handler_get_interface[dbus]: out of memory "
"when creating reply");
if (reply == NULL)
return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
NULL);
}
if (!dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &path,
DBUS_TYPE_INVALID)) {
perror("wpas_dbus_handler_get_interface[dbus]: out of memory "
"when appending argument to reply");
dbus_message_unref(reply);
return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
NULL);
@ -1338,8 +1333,6 @@ DBusMessage * wpas_dbus_handler_add_network(DBusMessage *message,
path = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
if (path == NULL) {
perror("wpas_dbus_handler_add_network[dbus]: out of "
"memory.");
reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
NULL);
goto err;
@ -1376,16 +1369,12 @@ DBusMessage * wpas_dbus_handler_add_network(DBusMessage *message,
reply = dbus_message_new_method_return(message);
if (reply == NULL) {
perror("wpas_dbus_handler_add_network[dbus]: out of memory "
"when creating reply");
reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
NULL);
goto err;
}
if (!dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &path,
DBUS_TYPE_INVALID)) {
perror("wpas_dbus_handler_add_network[dbus]: out of memory "
"when appending argument to reply");
dbus_message_unref(reply);
reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
NULL);
@ -1552,8 +1541,6 @@ DBusMessage * wpas_dbus_handler_add_blob(DBusMessage *message,
blob = os_zalloc(sizeof(*blob));
if (!blob) {
perror("wpas_dbus_handler_add_blob[dbus] out of memory when "
"trying to allocate blob struct");
reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
NULL);
goto err;
@ -1561,8 +1548,6 @@ DBusMessage * wpas_dbus_handler_add_blob(DBusMessage *message,
blob->data = os_malloc(blob_len);
if (!blob->data) {
perror("wpas_dbus_handler_add_blob[dbus] out of memory when "
"trying to allocate blob data");
reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
NULL);
goto err;
@ -1572,8 +1557,6 @@ DBusMessage * wpas_dbus_handler_add_blob(DBusMessage *message,
blob->len = blob_len;
blob->name = os_strdup(blob_name);
if (!blob->name) {
perror("wpas_dbus_handler_add_blob[dbus] out of memory when "
"trying to copy blob name");
reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
NULL);
goto err;
@ -1623,8 +1606,6 @@ DBusMessage * wpas_dbus_handler_get_blob(DBusMessage *message,
reply = dbus_message_new_method_return(message);
if (!reply) {
perror("wpas_dbus_handler_get_blob[dbus] out of memory when "
"trying to allocate return message");
reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
NULL);
goto out;
@ -1636,8 +1617,6 @@ DBusMessage * wpas_dbus_handler_get_blob(DBusMessage *message,
DBUS_TYPE_BYTE_AS_STRING,
&array_iter)) {
dbus_message_unref(reply);
perror("wpas_dbus_handler_get_blob[dbus] out of memory when "
"trying to open array");
reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
NULL);
goto out;
@ -1646,8 +1625,6 @@ DBusMessage * wpas_dbus_handler_get_blob(DBusMessage *message,
if (!dbus_message_iter_append_fixed_array(&array_iter, DBUS_TYPE_BYTE,
&(blob->data), blob->len)) {
dbus_message_unref(reply);
perror("wpas_dbus_handler_get_blob[dbus] out of memory when "
"trying to append data to array");
reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
NULL);
goto out;
@ -1655,8 +1632,6 @@ DBusMessage * wpas_dbus_handler_get_blob(DBusMessage *message,
if (!dbus_message_iter_close_container(&iter, &array_iter)) {
dbus_message_unref(reply);
perror("wpas_dbus_handler_get_blob[dbus] out of memory when "
"trying to close array");
reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
NULL);
goto out;
@ -2142,12 +2117,9 @@ DBusMessage * wpas_dbus_getter_current_bss(DBusMessage *message,
char *bss_obj_path = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
struct wpa_bss *bss = NULL;
if (bss_obj_path == NULL) {
perror("wpas_dbus_getter_current_bss[dbus]: out of "
"memory to allocate result argument.");
if (bss_obj_path == NULL)
return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
NULL);
}
/* TODO: store current BSS or BSS id in wpa_s */
if (!is_zero_ether_addr(wpa_s->bssid))
@ -2184,12 +2156,9 @@ DBusMessage * wpas_dbus_getter_current_network(DBusMessage *message,
DBusMessage *reply = NULL;
char *net_obj_path = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
if (net_obj_path == NULL) {
perror("wpas_dbus_getter_current_network[dbus]: out of "
"memory to allocate result argument.");
if (net_obj_path == NULL)
return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
NULL);
}
if (wpa_s->current_ssid)
os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
@ -2260,8 +2229,6 @@ DBusMessage * wpas_dbus_getter_bsss(DBusMessage *message,
dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) {
paths[i] = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
if (paths[i] == NULL) {
perror("wpas_dbus_getter_bsss[dbus]: out of "
"memory.");
reply = dbus_message_new_error(message,
DBUS_ERROR_NO_MEMORY,
NULL);
@ -2319,11 +2286,8 @@ DBusMessage * wpas_dbus_getter_networks(DBusMessage *message,
/* Loop through configured networks and append object path of each */
for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
paths[i] = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
if (paths[i] == NULL) {
perror("wpas_dbus_getter_networks[dbus]: out of "
"memory.");
reply = dbus_message_new_error(message,
DBUS_ERROR_NO_MEMORY,
NULL);
@ -2367,132 +2331,57 @@ DBusMessage * wpas_dbus_getter_blobs(DBusMessage *message,
reply = dbus_message_new(DBUS_MESSAGE_TYPE_SIGNAL);
else
reply = dbus_message_new_method_return(message);
if (!reply) {
perror("wpas_dbus_getter_blobs[dbus] out of memory when "
"trying to initialize return message");
reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
if (!reply)
return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
NULL);
goto out;
}
dbus_message_iter_init_append(reply, &iter);
if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT,
"a{say}", &variant_iter)) {
dbus_message_unref(reply);
perror("wpas_dbus_getter_blobs[dbus] out of memory when "
"trying to open variant");
reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
NULL);
goto out;
}
if (!dbus_message_iter_open_container(&variant_iter, DBUS_TYPE_ARRAY,
"a{say}", &variant_iter) ||
!dbus_message_iter_open_container(&variant_iter, DBUS_TYPE_ARRAY,
"{say}", &dict_iter)) {
dbus_message_unref(reply);
perror("wpas_dbus_getter_blobs[dbus] out of memory when "
"trying to open dictionary");
reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
NULL);
goto out;
}
blob = wpa_s->conf->blobs;
while (blob) {
if (!dbus_message_iter_open_container(&dict_iter,
DBUS_TYPE_DICT_ENTRY,
NULL, &entry_iter)) {
dbus_message_unref(reply);
perror("wpas_dbus_getter_blobs[dbus] out of memory "
"when trying to open entry");
reply = dbus_message_new_error(message,
DBUS_ERROR_NO_MEMORY,
NULL);
goto out;
}
if (!dbus_message_iter_append_basic(&entry_iter,
NULL, &entry_iter) ||
!dbus_message_iter_append_basic(&entry_iter,
DBUS_TYPE_STRING,
&(blob->name))) {
dbus_message_unref(reply);
perror("wpas_dbus_getter_blobs[dbus] out of memory "
"when trying to append blob name");
reply = dbus_message_new_error(message,
DBUS_ERROR_NO_MEMORY,
NULL);
goto out;
}
if (!dbus_message_iter_open_container(&entry_iter,
&(blob->name)) ||
!dbus_message_iter_open_container(&entry_iter,
DBUS_TYPE_ARRAY,
DBUS_TYPE_BYTE_AS_STRING,
&array_iter)) {
dbus_message_unref(reply);
perror("wpas_dbus_getter_blobs[dbus] out of memory "
"when trying to open array");
reply = dbus_message_new_error(message,
DBUS_ERROR_NO_MEMORY,
NULL);
goto out;
}
if (!dbus_message_iter_append_fixed_array(&array_iter,
&array_iter) ||
!dbus_message_iter_append_fixed_array(&array_iter,
DBUS_TYPE_BYTE,
&(blob->data),
blob->len)) {
dbus_message_unref(reply);
perror("wpas_dbus_getter_blobs[dbus] out of memory "
"when trying to append blob data");
reply = dbus_message_new_error(message,
DBUS_ERROR_NO_MEMORY,
NULL);
goto out;
}
if (!dbus_message_iter_close_container(&entry_iter,
&array_iter)) {
dbus_message_unref(reply);
perror("wpas_dbus_getter_blobs[dbus] out of memory "
"when trying to close array");
reply = dbus_message_new_error(message,
DBUS_ERROR_NO_MEMORY,
NULL);
goto out;
}
if (!dbus_message_iter_close_container(&dict_iter,
blob->len) ||
!dbus_message_iter_close_container(&entry_iter,
&array_iter) ||
!dbus_message_iter_close_container(&dict_iter,
&entry_iter)) {
dbus_message_unref(reply);
perror("wpas_dbus_getter_blobs[dbus] out of memory "
"when trying to close entry");
reply = dbus_message_new_error(message,
return dbus_message_new_error(message,
DBUS_ERROR_NO_MEMORY,
NULL);
goto out;
}
blob = blob->next;
}
if (!dbus_message_iter_close_container(&variant_iter, &dict_iter)) {
if (!dbus_message_iter_close_container(&variant_iter, &dict_iter) ||
!dbus_message_iter_close_container(&iter, &variant_iter)) {
dbus_message_unref(reply);
perror("wpas_dbus_getter_blobs[dbus] out of memory when "
"trying to close dictionary");
reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
NULL);
goto out;
}
if (!dbus_message_iter_close_container(&iter, &variant_iter)) {
dbus_message_unref(reply);
perror("wpas_dbus_getter_blobs[dbus] out of memory when "
"trying to close variant");
reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
NULL);
goto out;
}
out:
return reply;
}
@ -2835,20 +2724,15 @@ DBusMessage * wpas_dbus_getter_network_properties(
DBusMessageIter iter, variant_iter, dict_iter;
char **iterator;
char **props = wpa_config_get_all(net->ssid, 0);
if (!props) {
perror("wpas_dbus_getter_network_properties[dbus] couldn't "
"read network properties. out of memory.");
if (!props)
return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
NULL);
}
if (message == NULL)
reply = dbus_message_new(DBUS_MESSAGE_TYPE_SIGNAL);
else
reply = dbus_message_new_method_return(message);
if (!reply) {
perror("wpas_dbus_getter_network_properties[dbus] out of "
"memory when trying to initialize return message");
reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
NULL);
goto out;
@ -2857,18 +2741,8 @@ DBusMessage * wpas_dbus_getter_network_properties(
dbus_message_iter_init_append(reply, &iter);
if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT,
"a{sv}", &variant_iter)) {
perror("wpas_dbus_getter_network_properties[dbus] out of "
"memory when trying to open variant container");
dbus_message_unref(reply);
reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
NULL);
goto out;
}
if (!wpa_dbus_dict_open_write(&variant_iter, &dict_iter)) {
perror("wpas_dbus_getter_network_properties[dbus] out of "
"memory when trying to open dict");
"a{sv}", &variant_iter) ||
!wpa_dbus_dict_open_write(&variant_iter, &dict_iter)) {
dbus_message_unref(reply);
reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
NULL);
@ -2879,8 +2753,6 @@ DBusMessage * wpas_dbus_getter_network_properties(
while (*iterator) {
if (!wpa_dbus_dict_append_string(&dict_iter, *iterator,
*(iterator + 1))) {
perror("wpas_dbus_getter_network_properties[dbus] out "
"of memory when trying to add entry");
dbus_message_unref(reply);
reply = dbus_message_new_error(message,
DBUS_ERROR_NO_MEMORY,
@ -2891,18 +2763,8 @@ DBusMessage * wpas_dbus_getter_network_properties(
}
if (!wpa_dbus_dict_close_write(&variant_iter, &dict_iter)) {
perror("wpas_dbus_getter_network_properties[dbus] out of "
"memory when trying to close dictionary");
dbus_message_unref(reply);
reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
NULL);
goto out;
}
if (!dbus_message_iter_close_container(&iter, &variant_iter)) {
perror("wpas_dbus_getter_network_properties[dbus] out of "
"memory when trying to close variant container");
if (!wpa_dbus_dict_close_write(&variant_iter, &dict_iter) ||
!dbus_message_iter_close_container(&iter, &variant_iter)) {
dbus_message_unref(reply);
reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
NULL);

View file

@ -67,9 +67,8 @@ DBusMessage * wpas_dbus_handler_wps_start(DBusMessage *message,
"wpas_dbus_handler_wps_start"
"[dbus]: "
"wrong Role type. string required");
reply = wpas_dbus_error_invald_args(
return wpas_dbus_error_invald_args(
message, "Role must be a string");
goto out;
}
dbus_message_iter_get_basic(&variant_iter, &val);
if (os_strcmp(val, "enrollee") == 0)
@ -80,8 +79,8 @@ DBusMessage * wpas_dbus_handler_wps_start(DBusMessage *message,
wpa_printf(MSG_DEBUG,
"wpas_dbus_handler_wps_start[dbus]: "
"unknown role %s", val);
reply = wpas_dbus_error_invald_args(message, val);
goto out;
return wpas_dbus_error_invald_args(message,
val);
}
} else if (strcmp(key, "Type") == 0) {
dbus_message_iter_recurse(&entry_iter, &variant_iter);
@ -90,9 +89,8 @@ DBusMessage * wpas_dbus_handler_wps_start(DBusMessage *message,
wpa_printf(MSG_DEBUG,
"wpas_dbus_handler_wps_start[dbus]: "
"wrong Type type. string required");
reply = wpas_dbus_error_invald_args(
return wpas_dbus_error_invald_args(
message, "Type must be a string");
goto out;
}
dbus_message_iter_get_basic(&variant_iter, &val);
if (os_strcmp(val, "pin") == 0)
@ -103,9 +101,8 @@ DBusMessage * wpas_dbus_handler_wps_start(DBusMessage *message,
wpa_printf(MSG_DEBUG,
"wpas_dbus_handler_wps_start[dbus]: "
"unknown type %s", val);
reply = wpas_dbus_error_invald_args(message,
return wpas_dbus_error_invald_args(message,
val);
goto out;
}
} else if (strcmp(key, "Bssid") == 0) {
dbus_message_iter_recurse(&entry_iter, &variant_iter);
@ -116,9 +113,8 @@ DBusMessage * wpas_dbus_handler_wps_start(DBusMessage *message,
wpa_printf(MSG_DEBUG,
"wpas_dbus_handler_wps_start[dbus]: "
"wrong Bssid type. byte array required");
reply = wpas_dbus_error_invald_args(
return wpas_dbus_error_invald_args(
message, "Bssid must be a byte array");
goto out;
}
dbus_message_iter_recurse(&variant_iter, &array_iter);
dbus_message_iter_get_fixed_array(&array_iter, &bssid,
@ -127,9 +123,8 @@ DBusMessage * wpas_dbus_handler_wps_start(DBusMessage *message,
wpa_printf(MSG_DEBUG,
"wpas_dbus_handler_wps_start[dbus]: "
"wrong Bssid length %d", len);
reply = wpas_dbus_error_invald_args(
return wpas_dbus_error_invald_args(
message, "Bssid is wrong length");
goto out;
}
}
else if (os_strcmp(key, "Pin") == 0) {
@ -139,17 +134,15 @@ DBusMessage * wpas_dbus_handler_wps_start(DBusMessage *message,
wpa_printf(MSG_DEBUG,
"wpas_dbus_handler_wps_start[dbus]: "
"wrong Pin type. string required");
reply = wpas_dbus_error_invald_args(
return wpas_dbus_error_invald_args(
message, "Pin must be a string");
goto out;
}
dbus_message_iter_get_basic(&variant_iter, &pin);
} else {
wpa_printf(MSG_DEBUG,
"wpas_dbus_handler_wps_start[dbus]: "
"unknown key %s", key);
reply = wpas_dbus_error_invald_args(message, key);
goto out;
return wpas_dbus_error_invald_args(message, key);
}
dbus_message_iter_next(&dict_iter);
@ -158,23 +151,20 @@ DBusMessage * wpas_dbus_handler_wps_start(DBusMessage *message,
if (role == 0) {
wpa_printf(MSG_DEBUG, "wpas_dbus_handler_wps_start[dbus]: "
"Role not specified");
reply = wpas_dbus_error_invald_args(message,
return wpas_dbus_error_invald_args(message,
"Role not specified");
goto out;
}
else if (role == 1 && type == 0) {
wpa_printf(MSG_DEBUG, "wpas_dbus_handler_wps_start[dbus]: "
"Type not specified");
reply = wpas_dbus_error_invald_args(message,
return wpas_dbus_error_invald_args(message,
"Type not specified");
goto out;
}
else if (role == 2 && pin == NULL) {
wpa_printf(MSG_DEBUG, "wpas_dbus_handler_wps_start[dbus]: "
"Pin required for registrar role.");
reply = wpas_dbus_error_invald_args(
return wpas_dbus_error_invald_args(
message, "Pin required for registrar role.");
goto out;
}
if (role == 2)
@ -191,52 +181,38 @@ DBusMessage * wpas_dbus_handler_wps_start(DBusMessage *message,
"wpas_wps_failed in role %s and key %s.",
(role == 1 ? "enrollee" : "registrar"),
(type == 0 ? "" : (type == 1 ? "pin" : "pbc")));
reply = wpas_dbus_error_unknown_error(message,
return wpas_dbus_error_unknown_error(message,
"wps start failed");
goto out;
}
reply = dbus_message_new_method_return(message);
if (!reply) {
perror("wpas_dbus_handler_wps_start[dbus]: out of memory "
"when creating reply");
reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
NULL);
goto out;
}
dbus_message_iter_init_append(reply, &iter);
if (!wpa_dbus_dict_open_write(&iter, &dict_iter)) {
perror("wpas_dbus_handler_wps_start[dbus]: out of memory "
"when opening dictionary");
dbus_message_unref(reply);
reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
NULL);
goto out;
}
if (os_strlen(npin) > 0) {
if (!wpa_dbus_dict_append_string(&dict_iter, "Pin", npin)) {
perror("wpas_dbus_handler_wps_start[dbus]: "
"out of memory when appending pin");
dbus_message_unref(reply);
reply = dbus_message_new_error(message,
return dbus_message_new_error(message,
DBUS_ERROR_NO_MEMORY,
NULL);
goto out;
}
}
if (!wpa_dbus_dict_close_write(&iter, &dict_iter)) {
perror("wpas_dbus_handler_wps_start[dbus]: out of memory "
"when closing dictionary");
dbus_message_unref(reply);
reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
NULL);
goto out;
}
out:
return reply;
}

View file

@ -550,9 +550,8 @@ int wpa_dbus_ctrl_iface_init(struct wpas_dbus_priv *iface,
if (!dbus_connection_register_object_path(iface->con,
dbus_path, &wpa_vtable,
obj_desc)) {
perror("dbus_connection_register_object_path[dbus]");
wpa_printf(MSG_ERROR, "Could not set up DBus message "
"handler.");
wpa_printf(MSG_ERROR, "dbus: Could not set up message "
"handler");
return -1;
}
@ -566,14 +565,12 @@ int wpa_dbus_ctrl_iface_init(struct wpas_dbus_priv *iface,
case DBUS_REQUEST_NAME_REPLY_EXISTS:
case DBUS_REQUEST_NAME_REPLY_IN_QUEUE:
case DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER:
perror("dbus_bus_request_name[dbus]");
wpa_printf(MSG_ERROR, "Could not request DBus service name: "
"already registered.");
wpa_printf(MSG_ERROR, "dbus: Could not request service name: "
"already registered");
break;
default:
perror("dbus_bus_request_name[dbus]");
wpa_printf(MSG_ERROR, "Could not request DBus service name: "
"%s %s.", error.name, error.message);
wpa_printf(MSG_ERROR, "dbus: Could not request service name: "
"%s %s", error.name, error.message);
break;
}
dbus_error_free(&error);
@ -619,10 +616,8 @@ int wpa_dbus_register_object_per_iface(
/* Register the message handler for the interface functions */
if (!dbus_connection_register_object_path(con, path, &vtable,
obj_desc)) {
perror("wpa_dbus_register_iface [dbus]");
wpa_printf(MSG_ERROR, "Could not set up DBus message "
"handler for interface %s\n"
"and object %s.", ifname, path);
wpa_printf(MSG_ERROR, "dbus: Could not set up message "
"handler for interface %s object %s", ifname, path);
return -1;
}

View file

@ -406,10 +406,8 @@ void wpa_supplicant_dbus_notify_scan_results(struct wpa_supplicant *wpa_s)
WPAS_DBUS_IFACE_INTERFACE,
"ScanResultsAvailable");
if (_signal == NULL) {
perror("wpa_supplicant_dbus_notify_scan_results[dbus]: "
"couldn't create dbus signal; likely out of memory");
wpa_printf(MSG_ERROR, "dbus control interface: not enough "
"memory to send scan results signal.");
wpa_printf(MSG_ERROR, "dbus: Not enough memory to send scan "
"results signal");
return;
}
dbus_connection_send(iface->con, _signal, NULL);
@ -449,23 +447,19 @@ void wpa_supplicant_dbus_notify_state_change(struct wpa_supplicant *wpa_s,
WPAS_DBUS_IFACE_INTERFACE,
"StateChange");
if (_signal == NULL) {
perror("wpa_supplicant_dbus_notify_state_change[dbus]: "
"couldn't create dbus signal; likely out of memory");
wpa_printf(MSG_ERROR,
"wpa_supplicant_dbus_notify_state_change[dbus]: "
"couldn't create dbus signal; likely out of "
"memory.");
"dbus: wpa_supplicant_dbus_notify_state_change: "
"could not create dbus signal; likely out of "
"memory");
return;
}
new_state_str = wpa_supplicant_state_txt(new_state);
old_state_str = wpa_supplicant_state_txt(old_state);
if (new_state_str == NULL || old_state_str == NULL) {
perror("wpa_supplicant_dbus_notify_state_change[dbus]: "
"couldn't convert state strings");
wpa_printf(MSG_ERROR,
"wpa_supplicant_dbus_notify_state_change[dbus]: "
"couldn't convert state strings.");
"dbus: wpa_supplicant_dbus_notify_state_change: "
"Could not convert state strings");
goto out;
}
@ -473,12 +467,10 @@ void wpa_supplicant_dbus_notify_state_change(struct wpa_supplicant *wpa_s,
DBUS_TYPE_STRING, &new_state_str,
DBUS_TYPE_STRING, &old_state_str,
DBUS_TYPE_INVALID)) {
perror("wpa_supplicant_dbus_notify_state_change[dbus]: "
"not enough memory to construct state change signal.");
wpa_printf(MSG_ERROR,
"wpa_supplicant_dbus_notify_state_change[dbus]: "
"not enough memory to construct state change "
"signal.");
"dbus: wpa_supplicant_dbus_notify_state_change: "
"Not enough memory to construct state change "
"signal");
goto out;
}
@ -510,11 +502,8 @@ void wpa_supplicant_dbus_notify_scanning(struct wpa_supplicant *wpa_s)
WPAS_DBUS_IFACE_INTERFACE,
"Scanning");
if (_signal == NULL) {
perror("wpa_supplicant_dbus_notify_scanning[dbus]: couldn't "
"create dbus signal; likely out of memory");
wpa_printf(MSG_ERROR, "%s[dbus]: dbus control interface: not "
"enough memory to send scan results signal.",
__FUNCTION__);
wpa_printf(MSG_ERROR, "dbus: Not enough memory to send scan "
"results signal");
return;
}
@ -523,10 +512,8 @@ void wpa_supplicant_dbus_notify_scanning(struct wpa_supplicant *wpa_s)
DBUS_TYPE_INVALID)) {
dbus_connection_send(iface->con, _signal, NULL);
} else {
perror("wpa_supplicant_dbus_notify_scanning[dbus]: not enough "
"memory to construct signal.");
wpa_printf(MSG_ERROR, "%s[dbus]: not enough memory to "
"construct signal.", __FUNCTION__);
wpa_printf(MSG_ERROR, "dbus: Not enough memory to construct "
"signal");
}
dbus_message_unref(_signal);
}
@ -550,12 +537,10 @@ void wpa_supplicant_dbus_notify_wps_cred(struct wpa_supplicant *wpa_s,
WPAS_DBUS_IFACE_INTERFACE,
"WpsCred");
if (_signal == NULL) {
perror("wpa_supplicant_dbus_notify_wps_cred[dbus]: "
"couldn't create dbus signal; likely out of memory");
wpa_printf(MSG_ERROR,
"wpa_supplicant_dbus_notify_wps_cred[dbus]: "
"couldn't create dbus signal; likely out of "
"memory.");
"dbus: wpa_supplicant_dbus_notify_wps_cred: "
"Could not create dbus signal; likely out of "
"memory");
return;
}
@ -563,11 +548,9 @@ void wpa_supplicant_dbus_notify_wps_cred(struct wpa_supplicant *wpa_s,
DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE,
&cred->cred_attr, cred->cred_attr_len,
DBUS_TYPE_INVALID)) {
perror("wpa_supplicant_dbus_notify_wps_cred[dbus]: "
"not enough memory to construct signal.");
wpa_printf(MSG_ERROR,
"wpa_supplicant_dbus_notify_wps_cred[dbus]: "
"not enough memory to construct signal.");
"dbus: wpa_supplicant_dbus_notify_wps_cred: "
"Not enough memory to construct signal");
goto out;
}
@ -604,9 +587,8 @@ int wpa_supplicant_dbus_ctrl_iface_init(struct wpas_dbus_priv *iface)
if (!dbus_connection_register_object_path(iface->con,
WPAS_DBUS_PATH, &wpas_vtable,
iface)) {
perror("dbus_connection_register_object_path[dbus]");
wpa_printf(MSG_ERROR, "Could not set up DBus message "
"handler.");
wpa_printf(MSG_ERROR, "dbus: Could not set up message "
"handler");
return -1;
}
@ -620,14 +602,12 @@ int wpa_supplicant_dbus_ctrl_iface_init(struct wpas_dbus_priv *iface)
case DBUS_REQUEST_NAME_REPLY_EXISTS:
case DBUS_REQUEST_NAME_REPLY_IN_QUEUE:
case DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER:
perror("dbus_bus_request_name[dbus]");
wpa_printf(MSG_ERROR, "Could not request DBus service name: "
"already registered.");
wpa_printf(MSG_ERROR, "dbus: Could not request service name: "
"already registered");
break;
default:
perror("dbus_bus_request_name[dbus]");
wpa_printf(MSG_ERROR, "Could not request DBus service name: "
"%s %s.", error.name, error.message);
wpa_printf(MSG_ERROR, "dbus: Could not request service name: "
"%s %s", error.name, error.message);
break;
}
dbus_error_free(&error);
@ -657,7 +637,6 @@ int wpas_dbus_register_iface(struct wpa_supplicant *wpa_s)
DBusObjectPathVTable vtable = {
NULL, &wpas_iface_message_handler, NULL, NULL, NULL, NULL
};
int ret = -1;
/* Do nothing if the control interface is not turned on */
if (ctrl_iface == NULL)
@ -677,15 +656,12 @@ int wpas_dbus_register_iface(struct wpa_supplicant *wpa_s)
/* Register the message handler for the interface functions */
if (!dbus_connection_register_fallback(con, wpa_s->dbus_path, &vtable,
wpa_s)) {
perror("wpas_dbus_register_iface [dbus]");
wpa_printf(MSG_ERROR, "Could not set up DBus message "
"handler for interface %s.", wpa_s->ifname);
goto out;
wpa_printf(MSG_ERROR, "dbus: Could not set up message "
"handler for interface %s", wpa_s->ifname);
return -1;
}
ret = 0;
out:
return ret;
return 0;
}

View file

@ -362,10 +362,9 @@ DBusMessage * wpas_dbus_iface_scan_results(DBusMessage *message,
/* Ensure we've actually got scan results to return */
if (wpa_s->scan_res == NULL &&
wpa_supplicant_get_scan_results(wpa_s) < 0) {
reply = dbus_message_new_error(message, WPAS_ERROR_SCAN_ERROR,
return dbus_message_new_error(message, WPAS_ERROR_SCAN_ERROR,
"An error ocurred getting scan "
"results.");
goto out;
}
/* Create and initialize the return message */
@ -382,11 +381,8 @@ DBusMessage * wpas_dbus_iface_scan_results(DBusMessage *message,
path = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
if (path == NULL) {
perror("wpas_dbus_iface_scan_results[dbus]: out of "
"memory.");
wpa_printf(MSG_ERROR, "dbus control interface: not "
"enough memory to send scan results "
"signal.");
wpa_printf(MSG_ERROR, "dbus: Not enough memory to "
"send scan results signal");
break;
}
/* Construct the object path for this network. Note that ':'
@ -403,7 +399,6 @@ DBusMessage * wpas_dbus_iface_scan_results(DBusMessage *message,
dbus_message_iter_close_container(&iter, &sub_iter);
out:
return reply;
}
@ -810,11 +805,8 @@ DBusMessage * wpas_dbus_iface_add_network(DBusMessage *message,
path = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
if (path == NULL) {
perror("wpas_dbus_iface_scan_results[dbus]: out of "
"memory.");
wpa_printf(MSG_ERROR, "dbus control interface: not "
"enough memory to send scan results "
"signal.");
wpa_printf(MSG_ERROR, "dbus: Not enough memory to send scan "
"results signal");
goto out;
}
@ -1324,10 +1316,8 @@ DBusMessage * wpas_dbus_iface_get_scanning(DBusMessage *message,
dbus_message_append_args(reply, DBUS_TYPE_BOOLEAN, &scanning,
DBUS_TYPE_INVALID);
} else {
perror("wpas_dbus_iface_get_scanning[dbus]: out of "
"memory.");
wpa_printf(MSG_ERROR, "dbus control interface: not enough "
"memory to return scanning state.");
wpa_printf(MSG_ERROR, "dbus: Not enough memory to return "
"scanning state");
}
return reply;