Source-Changes-HG archive

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

[src/trunk]: src/sys/net Don't throw away the name and the secret lengths. Th...



details:   https://anonhg.NetBSD.org/src/rev/cc957d1082df
branches:  trunk
changeset: 534507:cc957d1082df
user:      christos <christos%NetBSD.org@localhost>
date:      Sun Jul 28 19:54:47 2002 +0000

description:
Don't throw away the name and the secret lengths. This eliminates all the
strlen() calls, and there was a whole bunch of them.

diffstat:

 sys/net/if_spppsubr.c |  37 ++++++++++++++++++++-----------------
 sys/net/if_spppvar.h  |   4 +++-
 2 files changed, 23 insertions(+), 18 deletions(-)

diffs (175 lines):

diff -r c8c40f7369bc -r cc957d1082df sys/net/if_spppsubr.c
--- a/sys/net/if_spppsubr.c     Sun Jul 28 18:42:41 2002 +0000
+++ b/sys/net/if_spppsubr.c     Sun Jul 28 19:54:47 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_spppsubr.c,v 1.53 2002/07/28 15:12:29 christos Exp $         */
+/*     $NetBSD: if_spppsubr.c,v 1.54 2002/07/28 19:54:47 christos Exp $         */
 
 /*
  * Synchronous PPP/Cisco link level subroutines.
@@ -28,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.53 2002/07/28 15:12:29 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.54 2002/07/28 19:54:47 christos Exp $");
 
 #include "opt_inet.h"
 #include "opt_ipx.h"
@@ -3814,7 +3814,7 @@
                /* Compute reply value. */
                MD5Init(&ctx);
                MD5Update(&ctx, &h->ident, 1);
-               MD5Update(&ctx, sp->myauth.secret, strlen(sp->myauth.secret));
+               MD5Update(&ctx, sp->myauth.secret, sp->myauth.secret_len);
                MD5Update(&ctx, value, value_len);
                MD5Final(digest, &ctx);
                dsize = sizeof digest;
@@ -3822,7 +3822,7 @@
                sppp_auth_send(&chap, sp, CHAP_RESPONSE, h->ident,
                               sizeof dsize, (const char *)&dsize,
                               sizeof digest, digest,
-                              strlen(sp->myauth.name),
+                              sp->myauth.name_len,
                               sp->myauth.name,
                               0);
                break;
@@ -3909,14 +3909,14 @@
                        break;
                }
                if (sp->hisauth.name != NULL && 
-                   (name_len != strlen(sp->hisauth.name)
+                   (name_len != sp->hisauth.name_len
                    || memcmp(name, sp->hisauth.name, name_len) != 0)) {
                        log(LOG_INFO, SPP_FMT "chap response, his name ",
                            SPP_ARGS(ifp));
                        sppp_print_string(name, name_len);
                        addlog(" != expected ");
                        sppp_print_string(sp->hisauth.name,
-                                         strlen(sp->hisauth.name));
+                                         sp->hisauth.name_len);
                        addlog("\n");
                    goto chap_failure;
                }
@@ -3944,8 +3944,7 @@
 
                MD5Init(&ctx);
                MD5Update(&ctx, &h->ident, 1);
-               MD5Update(&ctx, sp->hisauth.secret,
-                         strlen(sp->hisauth.secret));
+               MD5Update(&ctx, sp->hisauth.secret, sp->hisauth.secret_len);
                MD5Update(&ctx, sp->myauth.challenge, sizeof(sp->myauth.challenge));
                MD5Final(digest, &ctx);
 
@@ -4167,7 +4166,7 @@
        sppp_auth_send(&chap, sp, CHAP_CHALLENGE, sp->confid[IDX_CHAP],
                       sizeof clen, (const char *)&clen,
                       sizeof(sp->myauth.challenge), sp->myauth.challenge,
-                      strlen(sp->myauth.name),
+                      sp->myauth.name_len,
                       sp->myauth.name,
                       0);
 }
@@ -4247,9 +4246,9 @@
                        sppp_print_string((char*)secret, secret_len);
                        addlog(">\n");
                }
-               if (name_len != strlen(sp->hisauth.name) ||
+               if (name_len != sp->hisauth.name_len ||
+                   secret_len != sp->hisauth.secret_len ||
                    memcmp(name, sp->hisauth.name, name_len) != 0 ||
-                   secret_len != strlen(sp->hisauth.secret) ||
                    memcmp(secret, sp->hisauth.secret, secret_len) != 0) {
                        /* action scn, tld */
                        sp->pp_auth_failures++;
@@ -4490,8 +4489,8 @@
        }
        
        sp->confid[IDX_PAP] = ++sp->pp_seq[IDX_PAP];
-       pwdlen = strlen(sp->myauth.secret);
-       idlen = strlen(sp->myauth.name);
+       pwdlen = sp->myauth.secret_len;
+       idlen = sp->myauth.name_len;
 
        sppp_auth_send(&pap, sp, PAP_REQ, sp->confid[IDX_PAP],
                       sizeof idlen, (const char *)&idlen,
@@ -4973,12 +4972,12 @@
                    cfg->myauth = (sp->myauth.proto == PPP_PAP) ? SPPP_AUTHPROTO_PAP : SPPP_AUTHPROTO_CHAP;
                if (cfg->myname_length == 0) {
                    if (sp->myauth.name != NULL)
-                       cfg->myname_length = strlen(sp->myauth.name)+1;
+                       cfg->myname_length = sp->myauth.name_len + 1;
                } else {
                    if (sp->myauth.name == NULL) {
                        cfg->myname_length = 0;
                    } else {
-                       len = strlen(sp->myauth.name)+1;
+                       len = sp->myauth.name_len + 1;
                        if (cfg->myname_length < len)
                            return (ENAMETOOLONG);
                        error = copyout(sp->myauth.name, cfg->myname, len);
@@ -4987,12 +4986,12 @@
                }
                if (cfg->hisname_length == 0) {
                    if(sp->hisauth.name != NULL)
-                       cfg->hisname_length = strlen(sp->hisauth.name)+1;
+                       cfg->hisname_length = sp->hisauth.name_len + 1;
                } else {
                    if (sp->hisauth.name == NULL) {
                        cfg->hisname_length = 0;
                    } else {
-                       len = strlen(sp->hisauth.name)+1;
+                       len = sp->hisauth.name_len + 1;
                        if (cfg->hisname_length < len)
                            return (ENAMETOOLONG);
                        error = copyout(sp->hisauth.name, cfg->hisname, len);
@@ -5034,6 +5033,7 @@
                        return error;
                    }
                    sp->hisauth.name[cfg->hisname_length-1] = 0;
+                   sp->hisauth.name_len = cfg->hisname_length;
                }
                if (cfg->hissecret != NULL && cfg->hissecret_length > 0) {
                    if (cfg->hissecret_length >= MCLBYTES)
@@ -5046,6 +5046,7 @@
                        return error;
                    }
                    sp->hisauth.secret[cfg->hissecret_length-1] = 0;
+                   sp->hisauth.secret_len = cfg->hissecret_length;
                }
                if (cfg->myname != NULL && cfg->myname_length > 0) {
                    if (cfg->myname_length >= MCLBYTES)
@@ -5058,6 +5059,7 @@
                        return error;
                    }
                    sp->myauth.name[cfg->myname_length-1] = 0;
+                   sp->myauth.name_len = cfg->myname_length;
                }
                if (cfg->mysecret != NULL && cfg->mysecret_length > 0) {
                    if (cfg->mysecret_length >= MCLBYTES)
@@ -5070,6 +5072,7 @@
                        return error;
                    }
                    sp->myauth.secret[cfg->mysecret_length-1] = 0;
+                   sp->myauth.secret_len = cfg->mysecret_length;
                }
                sp->myauth.flags = cfg->myauthflags;
                if (cfg->myauth)
diff -r c8c40f7369bc -r cc957d1082df sys/net/if_spppvar.h
--- a/sys/net/if_spppvar.h      Sun Jul 28 18:42:41 2002 +0000
+++ b/sys/net/if_spppvar.h      Sun Jul 28 19:54:47 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_spppvar.h,v 1.4 2002/03/02 16:23:42 martin Exp $    */
+/*     $NetBSD: if_spppvar.h,v 1.5 2002/07/28 19:54:47 christos Exp $  */
 
 /*
  * Defines for synchronous PPP/Cisco link level subroutines.
@@ -63,6 +63,8 @@
        u_short flags;
        char    *name;                  /* system identification name */
        char    *secret;                /* secret password */
+       u_char  name_len;               /* no need to have a bigger size */
+       u_char  secret_len;             /* because proto gives size in a byte */
        char    challenge[16];          /* random challenge [don't change size! it's realy hardcoded!] */
 };
 



Home | Main Index | Thread Index | Old Index