~ubuntu-branches/debian/sid/network-manager/sid

« back to all changes in this revision

Viewing changes to src/settings/plugins/keyfile/writer.c

  • Committer: Package Import Robot
  • Author(s): Michael Biebl
  • Date: 2011-11-03 21:32:50 UTC
  • mfrom: (1.4.6)
  • Revision ID: package-import@ubuntu.com-20111103213250-w49ucjmux3hbwnta
Tags: 0.9.1.95-1
* New upstream release (0.9.2 rc1).
  - Fix connection sharing with newer iptables versions. (Closes: #638995)
  - Fix handling of numeric SSIDs in the keyfile plugin. (Closes: #642912)
* debian/watch: Track .xz tarballs.
* debian/libnm-util2.symbols: Add new symbols for libnm-util.
* debian/patches/04-dont-update-routing-and-dns-for-unmanaged-devices.patch
  - Avoid blowing away existing routes and resolv.conf if NM never managed
    any devices. (Closes: #546893, #624159, #637005, #641904)
* debian/control: Add Build-Depends on libglib2.0-doc for proper
  cross-references in the gtk-doc API documentation.
* Enable default hardening options from dpkg-buildflags.
  - Use buildflags.mk snippet in debian/rules.
  - Add Build-Depends on dpkg-dev (>= 1.6.1).

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
#include <ctype.h>
45
45
 
46
46
#include "nm-dbus-glib-types.h"
 
47
#include "nm-glib-compat.h"
47
48
#include "writer.h"
48
49
#include "common.h"
49
50
 
483
484
        GByteArray *array;
484
485
        const char *setting_name = nm_setting_get_name (setting);
485
486
        gboolean new_format = TRUE;
 
487
        unsigned int semicolons = 0;
486
488
        int i, *tmp_array;
487
489
        char *ssid;
488
490
 
501
503
                        new_format = FALSE;
502
504
                        break;
503
505
                }
 
506
                if (c == ';')
 
507
                        semicolons++;
504
508
        }
505
509
 
506
510
        if (new_format) {
507
 
                ssid = g_malloc0 (array->len + 1);
508
 
                memcpy (ssid, array->data, array->len);
 
511
                ssid = g_malloc0 (array->len + semicolons + 1);
 
512
                if (semicolons == 0)
 
513
                        memcpy (ssid, array->data, array->len);
 
514
                else {
 
515
                        /* Escape semicolons with backslashes to make strings
 
516
                         * containing ';', such as '16;17;' unambiguous */
 
517
                        int j = 0;
 
518
                        for (i = 0; i < array->len; i++) {
 
519
                                if (array->data[i] == ';')
 
520
                                        ssid[j++] = '\\';
 
521
                                ssid[j++] = array->data[i];
 
522
                        }
 
523
                }
509
524
                g_key_file_set_string (file, setting_name, key, ssid);
510
525
                g_free (ssid);
511
526
        } else {
876
891
        } else if (type == G_TYPE_BOOLEAN) {
877
892
                g_key_file_set_boolean (info->keyfile, setting_name, key, g_value_get_boolean (value));
878
893
        } else if (type == G_TYPE_CHAR) {
879
 
                g_key_file_set_integer (info->keyfile, setting_name, key, (int) g_value_get_char (value));
 
894
                g_key_file_set_integer (info->keyfile, setting_name, key, (int) g_value_get_schar (value));
880
895
        } else if (type == DBUS_TYPE_G_UCHAR_ARRAY) {
881
896
                GByteArray *array;
882
897
 
993
1008
 
994
1009
                path = g_strdup_printf ("%s/%s-%s", keyfile_dir, filename, nm_connection_get_uuid (connection));
995
1010
                if (g_file_test (path, G_FILE_TEST_EXISTS)) {
996
 
                        /* Hmm, this is odd. Give up. */
997
 
                        g_set_error (error, KEYFILE_PLUGIN_ERROR, 0,
998
 
                                         "%s.%d: could not find suitable keyfile file name (%s already used)",
999
 
                                         __FILE__, __LINE__, path);
1000
 
                        g_free (path);
1001
 
                        goto out;
 
1011
                        if (existing_path == NULL || g_strcmp0 (path, existing_path) != 0) {
 
1012
                                /* This should not happen. But, it actually occurs when
 
1013
                                 * two connections have the same UUID, and one of the connections
 
1014
                                 * is edited to contain the same ID as the other one.
 
1015
                                 * Give up.
 
1016
                                 */
 
1017
                                g_set_error (error, KEYFILE_PLUGIN_ERROR, 0,
 
1018
                                                    "%s.%d: could not find suitable keyfile file name (%s already used)",
 
1019
                                                    __FILE__, __LINE__, path);
 
1020
                                g_free (path);
 
1021
                                goto out;
 
1022
                        }
1002
1023
                }
1003
1024
        }
1004
1025
 
 
1026
        /* In case of updating the connection and changing the file path,
 
1027
         * we need to remove the old one, not to end up with two connections.
 
1028
         */
 
1029
        if (existing_path != NULL && strcmp (path, existing_path) != 0)
 
1030
                unlink (existing_path);
 
1031
 
1005
1032
        g_file_set_contents (path, data, len, error);
1006
1033
        if (chown (path, owner_uid, owner_grp) < 0) {
1007
1034
                g_set_error (error, KEYFILE_PLUGIN_ERROR, 0,