~ubuntu-branches/ubuntu/intrepid/pidgin/intrepid-security

« back to all changes in this revision

Viewing changes to libpurple/proxy.c

  • Committer: Bazaar Package Importer
  • Author(s): Pedro Fragoso
  • Date: 2008-04-04 02:18:00 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20080404021800-qaa00wom38gd7xus
Tags: 1:2.4.1-1ubuntu1
* Sync with Debian, remaining Ubuntu changes; (LP: #211769)
  - debian/control:
    + Set Maintainer to Ubuntu Core Developers.
    + Add build-deps on liblaunchpad-integration-dev, intltool,
      libnm-glib-dev (for --enable-nm)
    + Drop build-deps on libsilc-1.1-2-dev | libsilc-dev (>= 1.1.1) as
      this library is in universe.
    + Drop the libpurple0 recommends on libpurple-bin.
    + Add a gaim transitionnal package for upgrades.
    + Moved finch's libx11-6 dependency to Suggests
  - Ship compatibility symlinks via debian/gaim.links
  - debian/rules:
    + Pass --enable-nm to configure to enable NetworkManager support
    + Pass --disable-silc to configure to disable silc support even if
      it's installed in the build environment.
    + Add X-Ubuntu-Gettext-Domain to the desktop file and update the
      translation templates in common-install-impl::.
    + Added necessary arguments to dh_shlibdeps for finch
  - Update debian/prefs.xml to set the notify plugin prefs
    /plugins/gtk/X11/notify/* and set /pidgin/plugins/loaded to load
    the notify plugin
  - debian/patches:
    + 02_lpi for LP integration
    + 04_let_crasher_for_apport to stop catching the SIGSEGV signal
      and let apport handle it
    + 05_default_to_irc_ubuntu_com to set the default IRC
      server to irc.ubuntu.com.
    + 70_autoconf patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
211
211
purple_gnome_proxy_get_info(void)
212
212
{
213
213
        static PurpleProxyInfo info = {0, NULL, 0, NULL, NULL};
214
 
        gchar *path;
215
 
        if ((path = g_find_program_in_path("gconftool-2"))) {
216
 
                gchar *tmp;
217
 
 
218
 
                g_free(path);
219
 
 
220
 
                /* See whether to use a proxy. */
221
 
                if (!g_spawn_command_line_sync("gconftool-2 -g /system/proxy/mode", &tmp,
222
 
                                               NULL, NULL, NULL))
223
 
                        return purple_global_proxy_get_info();
224
 
                if (!strcmp(tmp, "none\n")) {
225
 
                        info.type = PURPLE_PROXY_NONE;
226
 
                        g_free(tmp);
227
 
                        return &info;
228
 
                } else if (strcmp(tmp, "manual\n")) {
229
 
                        g_free(tmp);
230
 
                        return purple_global_proxy_get_info();
231
 
                }
232
 
 
233
 
                g_free(tmp);
234
 
                info.type = PURPLE_PROXY_HTTP;
235
 
 
236
 
                /* Free the old fields */
237
 
                if (info.host) {
238
 
                        g_free(info.host);
239
 
                        info.host = NULL;
240
 
                }
241
 
                if (info.username) {
242
 
                        g_free(info.username);
243
 
                        info.username = NULL;
244
 
                }
245
 
                if (info.password) {
246
 
                        g_free(info.password);
247
 
                        info.password = NULL;
248
 
                }
249
 
 
250
 
                /* Get the new ones */
251
 
                if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/host", &info.host,
252
 
                                               NULL, NULL, NULL))
253
 
                        return purple_global_proxy_get_info();
254
 
                g_strchomp(info.host);
255
 
 
256
 
                if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/authentication_user", &info.username,
257
 
                                               NULL, NULL, NULL))
258
 
                        return purple_global_proxy_get_info();
259
 
                g_strchomp(info.username);
260
 
 
261
 
                if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/authentication_password", &info.password,
262
 
                                               NULL, NULL, NULL))
263
 
                        return purple_global_proxy_get_info();
264
 
                g_strchomp(info.password);
265
 
 
266
 
                if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/port", &tmp,
267
 
                                               NULL, NULL, NULL))
268
 
                        return purple_global_proxy_get_info();
269
 
                info.port = atoi(tmp);
270
 
                g_free(tmp);
271
 
 
 
214
        gchar *tmp;
 
215
 
 
216
        tmp = g_find_program_in_path("gconftool-2");
 
217
        if (tmp == NULL)
 
218
                return purple_global_proxy_get_info();
 
219
 
 
220
        g_free(tmp);
 
221
 
 
222
        /* Check whether to use a proxy. */
 
223
        if (!g_spawn_command_line_sync("gconftool-2 -g /system/proxy/mode",
 
224
                        &tmp, NULL, NULL, NULL))
 
225
                return purple_global_proxy_get_info();
 
226
 
 
227
        if (!strcmp(tmp, "none\n")) {
 
228
                info.type = PURPLE_PROXY_NONE;
 
229
                g_free(tmp);
272
230
                return &info;
273
231
        }
274
 
        return purple_global_proxy_get_info();
 
232
 
 
233
        if (strcmp(tmp, "manual\n")) {
 
234
                /* Unknown setting.  Fallback to using our global proxy settings. */
 
235
                g_free(tmp);
 
236
                return purple_global_proxy_get_info();
 
237
        }
 
238
 
 
239
        g_free(tmp);
 
240
 
 
241
        /* If we get this far then we know we're using an HTTP proxy */
 
242
        info.type = PURPLE_PROXY_HTTP;
 
243
 
 
244
        /* Free the old fields */
 
245
        if (info.host) {
 
246
                g_free(info.host);
 
247
                info.host = NULL;
 
248
        }
 
249
        if (info.username) {
 
250
                g_free(info.username);
 
251
                info.username = NULL;
 
252
        }
 
253
        if (info.password) {
 
254
                g_free(info.password);
 
255
                info.password = NULL;
 
256
        }
 
257
 
 
258
        if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/host",
 
259
                        &info.host, NULL, NULL, NULL))
 
260
                return purple_global_proxy_get_info();
 
261
        g_strchomp(info.host);
 
262
        if (*info.host == '\0')
 
263
        {
 
264
                purple_debug_info("proxy", "Gnome proxy settings are set to "
 
265
                                "'manual' but no proxy server is specified.  Using "
 
266
                                "Pidgin's proxy settings instead.\n");
 
267
                g_free(info.host);
 
268
                return purple_global_proxy_get_info();
 
269
        }
 
270
 
 
271
        if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/authentication_user",
 
272
                        &info.username, NULL, NULL, NULL))
 
273
        {
 
274
                g_free(info.host);
 
275
                return purple_global_proxy_get_info();
 
276
        }
 
277
        g_strchomp(info.username);
 
278
 
 
279
        if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/authentication_password",
 
280
                        &info.password, NULL, NULL, NULL))
 
281
        {
 
282
                g_free(info.host);
 
283
                g_free(info.username);
 
284
                return purple_global_proxy_get_info();
 
285
        }
 
286
        g_strchomp(info.password);
 
287
 
 
288
        if (!g_spawn_command_line_sync("gconftool-2 -g /system/http_proxy/port",
 
289
                        &tmp, NULL, NULL, NULL))
 
290
        {
 
291
                g_free(info.host);
 
292
                g_free(info.username);
 
293
                g_free(info.password);
 
294
                return purple_global_proxy_get_info();
 
295
        }
 
296
        info.port = atoi(tmp);
 
297
        g_free(tmp);
 
298
 
 
299
        return &info;
275
300
}
276
301
/**************************************************************************
277
302
 * Proxy API
1101
1126
        if(connect_data->read_len < len) {
1102
1127
                if(connect_data->read_buf_len < len) {
1103
1128
                        /* it's not just that we haven't read enough, it's that we haven't tried to read enough yet */
1104
 
                        purple_debug_info("s5", "reallocing from %d to %d\n", connect_data->read_buf_len, len);
 
1129
                        purple_debug_info("s5", "reallocing from %" G_GSIZE_FORMAT
 
1130
                                        " to %d\n", connect_data->read_buf_len, len);
1105
1131
                        connect_data->read_buf_len = len;
1106
1132
                        connect_data->read_buffer = g_realloc(connect_data->read_buffer, connect_data->read_buf_len);
1107
1133
                }
1330
1356
        purple_debug(PURPLE_DEBUG_INFO, "socks5 proxy", "Got CHAP response.\n");
1331
1357
 
1332
1358
        if (connect_data->read_buffer == NULL) {
1333
 
                connect_data->read_buf_len = 20;
 
1359
                /* A big enough butfer to read the message header (2 bytes) and at least one complete attribute and value (1 + 1 + 255). */
 
1360
                connect_data->read_buf_len = 259;
1334
1361
                connect_data->read_buffer = g_malloc(connect_data->read_buf_len);
1335
1362
                connect_data->read_len = 0;
1336
1363
        }
1337
1364
 
 
1365
        if (connect_data->read_buf_len - connect_data->read_len == 0) {
 
1366
                /*If the stuff below is right, this shouldn't be possible. */
 
1367
                purple_debug_error("socks5 proxy", "This is about to suck because the read buffer is full (shouldn't happen).\n");
 
1368
        }
 
1369
 
1338
1370
        len = read(connect_data->fd, connect_data->read_buffer + connect_data->read_len,
1339
1371
                connect_data->read_buf_len - connect_data->read_len);
1340
1372
 
1374
1406
        cmdbuf++;
1375
1407
 
1376
1408
        for (currentav = 0; currentav < navas; currentav++) {
1377
 
                if (connect_data->read_len - (cmdbuf - connect_data->read_buffer) < 2)
1378
 
                        return;
1379
 
                if (connect_data->read_len - (cmdbuf - connect_data->read_buffer) < cmdbuf[1])
1380
 
                        return;
 
1409
 
 
1410
                len = connect_data->read_len - (cmdbuf - connect_data->read_buffer);
 
1411
                /* We don't have enough data to even know how long the next attribute is,
 
1412
                 * or we don't have the full length of the next attribute. */
 
1413
                if (len < 2 || len < (cmdbuf[1] + 2)) {
 
1414
                        /* Clear out the attributes that have been read - decrease the attribute count */
 
1415
                        connect_data->read_buffer[1] = navas - currentav;
 
1416
                        /* Move the unprocessed data into the first attribute position */
 
1417
                        memmove((connect_data->read_buffer + 2), cmdbuf, len);
 
1418
                        /* Decrease the read count accordingly */
 
1419
                        connect_data->read_len = len + 2;
 
1420
                        return;
 
1421
                }
 
1422
 
1381
1423
                buf = cmdbuf + 2;
 
1424
 
 
1425
                if (cmdbuf[1] == 0) {
 
1426
                        purple_debug_error("socks5 proxy", "Attribute %x Value length of 0; ignoring.\n", cmdbuf[0]);
 
1427
                        cmdbuf = buf;
 
1428
                        continue;
 
1429
                }
 
1430
 
1382
1431
                switch (cmdbuf[0]) {
1383
1432
                        case 0x00:
 
1433
                                purple_debug_info("socks5 proxy", "Received STATUS of %x\n", buf[0]);
1384
1434
                                /* Did auth work? */
1385
1435
                                if (buf[0] == 0x00) {
1386
1436
                                        purple_input_remove(connect_data->inpa);
1389
1439
                                        connect_data->read_buffer = NULL;
1390
1440
                                        /* Success */
1391
1441
                                        s5_sendconnect(connect_data, connect_data->fd);
1392
 
                                        return;
1393
1442
                                } else {
1394
1443
                                        /* Failure */
1395
1444
                                        purple_debug_warning("proxy",
1397
1446
                                                "failed.  Disconnecting...");
1398
1447
                                        purple_proxy_connect_data_disconnect(connect_data,
1399
1448
                                                        _("Authentication failed"));
1400
 
                                        return;
1401
1449
                                }
1402
 
                                break;
 
1450
                                return;
1403
1451
                        case 0x03:
 
1452
                                purple_debug_info("socks5 proxy", "Received CHALLENGE\n");
1404
1453
                                /* Server wants our credentials */
1405
1454
 
1406
1455
                                connect_data->write_buf_len = 16 + 4;
1425
1474
                                        PURPLE_INPUT_WRITE, proxy_do_write, connect_data);
1426
1475
 
1427
1476
                                proxy_do_write(connect_data, connect_data->fd, PURPLE_INPUT_WRITE);
1428
 
                                break;
 
1477
                                return;
1429
1478
                        case 0x11:
 
1479
                                purple_debug_info("socks5 proxy", "Received ALGORIGTHMS of %x\n", buf[0]);
1430
1480
                                /* Server wants to select an algorithm */
1431
1481
                                if (buf[0] != 0x85) {
1432
1482
                                        /* Only currently support HMAC-MD5 */
1441
1491
                                        return;
1442
1492
                                }
1443
1493
                                break;
 
1494
                        default:
 
1495
                                purple_debug_info("socks5 proxy", "Received unused command %x, length=%d\n", cmdbuf[0], cmdbuf[1]);
1444
1496
                }
1445
1497
                cmdbuf = buf + cmdbuf[1];
1446
1498
        }
 
1499
 
1447
1500
        /* Fell through.  We ran out of CHAP events to process, but haven't
1448
1501
         * succeeded or failed authentication - there may be more to come.
1449
1502
         * If this is the case, come straight back here. */
 
1503
 
 
1504
        /* We've processed all the available attributes, so get ready for a whole new message */
 
1505
        g_free(connect_data->read_buffer);
 
1506
        connect_data->read_buffer = NULL;
1450
1507
}
1451
1508
 
1452
1509
static void