~ubuntu-branches/ubuntu/hardy/open-iscsi/hardy-updates

« back to all changes in this revision

Viewing changes to usr/chap.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Zobel-Helas
  • Date: 2006-12-03 16:54:21 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20061203165421-xhttz5j4l9sowg8u
Tags: 2.0.730-0.2
upload to unstable, as no new bugs arised.

Show diffs side-by-side

added added

removed removed

Lines of Context:
323
323
        char *value, *p;
324
324
        char text[CHAP_CHALLENGE_MAX * 2 + 8];
325
325
        static int chap_id;
326
 
        int i;
 
326
        int i, tmpsize;
 
327
        int fd;
327
328
 
328
329
        value = text_key_find(conn, "CHAP_A");
329
330
        if (!value)
353
354
         * wise, or should we rather always use the max. allowed length of
354
355
         * 1024 for the (unencoded) challenge?
355
356
         */
356
 
        conn->auth.chap.challenge_size = (rand() % (CHAP_CHALLENGE_MAX / 2)) + CHAP_CHALLENGE_MAX / 2;
 
357
        fd = open("/dev/urandom", O_RDONLY);
 
358
        if (fd)
 
359
                read(fd, &tmpsize, sizeof(int));
 
360
        else
 
361
                tmpsize = rand();
 
362
 
 
363
        conn->auth.chap.challenge_size = (tmpsize % CHAP_CHALLENGE_MAX / 2) +
 
364
                CHAP_CHALLENGE_MAX / 2;
357
365
 
358
366
        conn->auth.chap.challenge = xmalloc(conn->auth.chap.challenge_size);
359
367
        if (!conn->auth.chap.challenge)
362
370
        p = text;
363
371
        strcpy(p, "0x");
364
372
        p += 2;
 
373
 
 
374
        if (fd) {
 
375
                read(fd, conn->auth.chap.challenge, 
 
376
                     sizeof(int) * conn->auth.chap.challenge_size);
 
377
        }
 
378
 
365
379
        for (i = 0; i < conn->auth.chap.challenge_size; i++) {
366
 
                conn->auth.chap.challenge[i] = rand();
 
380
                if (!fd) {
 
381
                        conn->auth.chap.challenge[i] = rand();
 
382
                }
367
383
                sprintf(p, "%.2hhx", conn->auth.chap.challenge[i]);
368
384
                p += 2;
369
385
        }
 
386
        if (fd) close(fd);
370
387
        text_key_add(conn, "CHAP_C",  text);
371
388
 
372
389
        return 0;