shishi-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Cleanups.


From: shishi-commit
Subject: Cleanups.
Date: Thu, 18 Dec 2003 09:12:38 +0100

Commit from jas 2003-12-18 09:12 CET
Cleanups.
Module File name Revision
shishi src/shishid.c 1.77 >>> 1.78

shishi/src/shishid.c   1.77 >>> 1.78
Line 186
    size_t bufpos;
  #ifdef USE_STARTTLS
    gnutls_session session;
+   int usetls;
  #endif
    struct listenspec *next;
  };
Line 290
  }
        else if (!arg.quiet_flag)
  printf ("done\n");
+
+     }
+
+   if (ls->usetls)
+     {
+       gnutls_bye (ls->session, GNUTLS_SHUT_WR);
+       gnutls_deinit (ls->session);
      }
 
    if (ls->str)
Line 315
    listenspec = kdc_close (ls);
  }
 
- static void
- kdc_handle2 (struct listenspec *ls)
+ static int
+ kdc_extension (struct listenspec *ls)
  {
    ssize_t sent_bytes, read_bytes;
    struct sockaddr addr;
    int rc;
 
  #ifdef USE_STARTTLS
-   if (ls->type == SOCK_STREAM &&
+   if (!ls->usetls &&
+       ls->type == SOCK_STREAM &&
        ls->bufpos == 4 &&
        memcmp (ls->buf, "\x70\x00\x00\x01", 4) == 0)
      {
Line 355
 
        rc = gnutls_handshake (ls->session);
        if (rc < 0)
- printf ("Handshake has failed %d: %s\n",
- rc, gnutls_strerror (rc));
-       else
  {
-   if (!arg.quiet_flag)
-     printf ("TLS successful\n");
+   printf ("Handshake has failed %d: %s\n",
+   rc, gnutls_strerror (rc));
+   return -1;
+ }
 
-   rc = gnutls_record_recv (ls->session, ls->buf,
-    sizeof (ls->buf) - 1);
+       if (!arg.quiet_flag)
+ printf ("TLS successful\n");
 
-   if (rc == 0)
-     {
-       printf ("Peer has closed the GNUTLS connection\n");
-     }
-   else if (rc < 0)
-     {
-       printf ("Corrupted data(%d).\n", rc);
-     }
-   else if (rc > 0)
-     {
-       char *p;
-       size_t plen;
+       ls->bufpos = 0;
+       ls->usetls = 1;
+     }
+ #endif
+
+   return 0;
+ }
+
+ static void
+ kdc_handle2 (struct listenspec *ls)
+ {
+   ssize_t sent_bytes, read_bytes;
+   struct sockaddr addr;
+   int rc;
 
-       process (ls->buf, rc, &p, &plen);
+ #ifdef USE_STARTTLS
+   if (ls->usetls)
+     {
+       char *p;
+       size_t plen;
 
-       printf ("TLS process %d sending %d\n", rc, plen);
+       process (ls->buf, ls->bufpos, &p, &plen);
 
-       gnutls_record_send (ls->session, p, plen);
+       printf ("TLS process %d sending %d\n", ls->bufpos, plen);
 
-       if (p != fatal_krberror)
- free (p);
-     }
-   ls->bufpos = 0;
- }
-       gnutls_bye (ls->session, GNUTLS_SHUT_WR);
-       gnutls_deinit (ls->session);
+       gnutls_record_send (ls->session, p, plen);
+
+       if (p != fatal_krberror)
+ free (p);
+
+       ls->bufpos = 0;
      }
    else
  #endif
Line 441
  }
 
  static int
+ kdc_ready (struct listenspec *ls)
+ {
+   ssize_t sent_bytes, read_bytes;
+   struct sockaddr addr;
+   int rc;
+
+ #ifdef USE_STARTTLS
+   if (ls->usetls && ls->bufpos > 0)
+     return 1;
+   else
+ #endif
+     if (ls->type == SOCK_DGRAM)
+       return 1;
+     else if (ls->bufpos > 4 && ntohl (*(int *) ls->buf) + 4 == ls->bufpos)
+       return 1;
+
+   return 0;
+ }
+
+ static int
  kdc_read (struct listenspec *ls)
  {
    ssize_t read_bytes;
 
-   read_bytes = recvfrom (ls->sockfd, ls->buf + ls->bufpos,
-  sizeof(ls->buf) - ls->bufpos, 0,
-  &ls->addr, &ls->addrlen);
-
+   if (ls->usetls)
+     read_bytes = gnutls_record_recv (ls->session, ls->buf,
+      sizeof (ls->buf));
+   else
+     read_bytes = recvfrom (ls->sockfd, ls->buf + ls->bufpos,
+    sizeof(ls->buf) - ls->bufpos, 0,
+    &ls->addr, &ls->addrlen);
    if (read_bytes < 0)
      {
-       error (0, errno, "Error from recvfrom (%d)", read_bytes);
+       if (ls->usetls)
+ error (0, 0, "Corrupted TLS data (%d): %s\n", read_bytes,
+        gnutls_strerror (read_bytes));
+       else
+ error (0, errno, "Error from recvfrom (%d)", read_bytes);
        return -1;
      }
 
Line 463
      }
 
    ls->bufpos += read_bytes;
-   ls->buf[ls->bufpos] = '\0';
 
    if (!arg.quiet_flag)
      printf ("Has %d bytes from %s on socket %d\n",
Line 544
      kdc_accept (ls);
    else if (kdc_read (ls) < 0)
      ls = kdc_close (ls);
-   else
+   else if (kdc_extension (ls) < 0)
+     ls = kdc_close (ls);
+   else if (kdc_ready (ls))
      kdc_handle2 (ls);
      }
  }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]