~ubuntu-branches/ubuntu/maverick/irssi-plugin-xmpp/maverick

« back to all changes in this revision

Viewing changes to src/core/xmpp-servers.c

  • Committer: Bazaar Package Importer
  • Author(s): David Ammouial
  • Date: 2010-07-06 15:14:51 UTC
  • mfrom: (2.2.4 sid)
  • Revision ID: james.westby@ubuntu.com-20100706151451-tyil9o1evi8ydutr
Tags: 0.51+cvs20100627-1
* New upstream release + CVS snapshot (Closes: #588163).
  - Prompt for a password if none was provided in the configuration
    (Closes: #580659).
  - Don't segfault upon reception of a ping without "from" field.
    (Closes: #521227).
  - Various bugfixes and improvements.
* Provide a package with debugging symbols (Closes: #580658).
* Bump Standards-Version to 3.8.4 (no changes needed).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * $Id: xmpp-servers.c,v 1.59 2010/01/22 18:41:14 cdidier Exp $
 
2
 * $Id: xmpp-servers.c,v 1.62 2010/06/10 08:09:36 cdidier Exp $
3
3
 *
4
4
 * Copyright (C) 2007 Colin DIDIER
5
5
 *
19
19
 
20
20
#include <sys/types.h>
21
21
#include <sys/socket.h>
 
22
#include <string.h>
 
23
#include <termios.h>
22
24
 
23
25
#include "module.h"
24
26
#include "network.h"
239
241
            "Authenticated successfully.");
240
242
}
241
243
 
 
244
/*
 
245
 * Displays input prompt on command line and takes input data from user
 
246
 * From irssi-silc (silc-client/lib/silcutil/silcutil.c)
 
247
 */
 
248
static char *
 
249
get_password()
 
250
{
 
251
        char input[2048], *ret = NULL;
 
252
        int fd;
 
253
 
 
254
#ifndef DISABLE_TERMIOS
 
255
        struct termios to;
 
256
        struct termios to_old;
 
257
 
 
258
        if ((fd = open("/dev/tty", O_RDONLY)) < 0) {
 
259
                g_warning("Cannot open /dev/tty: %s\n",
 
260
                    strerror(errno));
 
261
                return NULL;
 
262
        }
 
263
        signal(SIGINT, SIG_IGN);
 
264
 
 
265
        /* Get terminal info */
 
266
        tcgetattr(fd, &to);
 
267
        to_old = to;
 
268
        /* Echo OFF, and assure we can prompt and get input */
 
269
        to.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL);
 
270
        to.c_lflag |= ICANON;
 
271
        to.c_cc[VMIN] = 255;
 
272
        tcsetattr(fd, TCSANOW, &to);
 
273
 
 
274
        printf("\tXMPP Password: ");
 
275
        fflush(stdout);
 
276
 
 
277
        memset(input, 0, sizeof(input));
 
278
        if ((read(fd, input, sizeof(input))) < 0) {
 
279
                g_warning("Cannot read from /dev/tty: %s\n",
 
280
                    strerror(errno));
 
281
                tcsetattr(fd, TCSANOW, &to_old);
 
282
                return NULL;
 
283
        }
 
284
        if (strlen(input) <= 1) {
 
285
                tcsetattr(fd, TCSANOW, &to_old);
 
286
                return NULL;
 
287
        }
 
288
        if ((ret = strchr(input, '\n')) != NULL)
 
289
                *ret = '\0';
 
290
 
 
291
        /* Restore old terminfo */
 
292
        tcsetattr(fd, TCSANOW, &to_old);
 
293
        signal(SIGINT, SIG_DFL);
 
294
 
 
295
        ret = g_strdup(input);
 
296
        memset(input, 0, sizeof(input));
 
297
#endif /* DISABLE_TERMIOS */
 
298
        return ret;
 
299
}
 
300
 
242
301
static void
243
302
lm_open_cb(LmConnection *connection, gboolean success,
244
303
    gpointer user_data)
265
324
                signal_emit("xmpp server status", 2, server,
266
325
                    "Using STARTTLS encryption.");
267
326
        recoded_user = xmpp_recode_out(server->user);
 
327
 
 
328
        if (server->connrec->password == NULL
 
329
            || *(server->connrec->password) == '\0'
 
330
            || *(server->connrec->password) == '\r') {
 
331
                if (server->connrec->password != NULL)
 
332
                        g_free(server->connrec->password);
 
333
                server->connrec->password = get_password();
 
334
                if (server->connrec->password == NULL)
 
335
                        server->connrec->password = g_strdup(" ");
 
336
        }
268
337
        recoded_password = xmpp_recode_out(server->connrec->password);
269
338
        recoded_resource = xmpp_recode_out(server->resource);
270
339
        lm_connection_authenticate(connection, recoded_user,