diff options
author | Ulrich Drepper <drepper@redhat.com> | 2004-12-22 20:10:10 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 2004-12-22 20:10:10 +0000 |
commit | a334319f6530564d22e775935d9c91663623a1b4 (patch) | |
tree | b5877475619e4c938e98757d518bb1e9cbead751 /nis/nss_nis/nis-publickey.c | |
parent | 0ecb606cb6cf65de1d9fc8a919bceb4be476c602 (diff) | |
download | glibc-a334319f6530564d22e775935d9c91663623a1b4.tar.gz glibc-a334319f6530564d22e775935d9c91663623a1b4.tar.xz glibc-a334319f6530564d22e775935d9c91663623a1b4.zip |
(CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4.
Diffstat (limited to 'nis/nss_nis/nis-publickey.c')
-rw-r--r-- | nis/nss_nis/nis-publickey.c | 106 |
1 files changed, 55 insertions, 51 deletions
diff --git a/nis/nss_nis/nis-publickey.c b/nis/nss_nis/nis-publickey.c index f58eb154ad..6e92112d11 100644 --- a/nis/nss_nis/nis-publickey.c +++ b/nis/nss_nis/nis-publickey.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1996-1999,2001,2002,2005,2006 Free Software Foundation, Inc. +/* Copyright (C) 1996,1997,1998,1999,2001,2002 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Thorsten Kukuk <kukuk@suse.de>, 1996. @@ -36,6 +36,10 @@ extern int xdecrypt (char *, char *); enum nss_status _nss_nis_getpublickey (const char *netname, char *pkey, int *errnop) { + enum nss_status retval; + char *domain, *result; + int len; + pkey[0] = 0; if (netname == NULL) @@ -44,23 +48,19 @@ _nss_nis_getpublickey (const char *netname, char *pkey, int *errnop) return NSS_STATUS_UNAVAIL; } - char *domain = strchr (netname, '@'); - if (domain == NULL) + domain = strchr (netname, '@'); + if (!domain) { *errnop = EINVAL; return NSS_STATUS_UNAVAIL; } ++domain; - char *result; - int len; - int yperr = yp_match (domain, "publickey.byname", netname, strlen (netname), - &result, &len); + retval = yperr2nss (yp_match (domain, "publickey.byname", netname, + strlen (netname), &result, &len)); - if (__builtin_expect (yperr != YPERR_SUCCESS, 0)) + if (retval != NSS_STATUS_SUCCESS) { - enum nss_status retval = yperr2nss (yperr); - if (retval == NSS_STATUS_TRYAGAIN) *errnop = errno; return retval; @@ -73,7 +73,6 @@ _nss_nis_getpublickey (const char *netname, char *pkey, int *errnop) *p = 0; strncpy (pkey, result, HEXKEYBYTES + 1); pkey[HEXKEYBYTES] = '\0'; - free (result); } return NSS_STATUS_SUCCESS; } @@ -82,6 +81,11 @@ enum nss_status _nss_nis_getsecretkey (const char *netname, char *skey, char *passwd, int *errnop) { + enum nss_status retval; + char buf[2 * (HEXKEYBYTES + 1)]; + char *domain, *result; + int len; + skey[0] = 0; if (netname == NULL || passwd == NULL) @@ -90,23 +94,19 @@ _nss_nis_getsecretkey (const char *netname, char *skey, char *passwd, return NSS_STATUS_UNAVAIL; } - char *domain = strchr (netname, '@'); - if (domain == NULL) + domain = strchr (netname, '@'); + if (!domain) { *errnop = EINVAL; return NSS_STATUS_UNAVAIL; } ++domain; - char *result; - int len; - int yperr = yp_match (domain, "publickey.byname", netname, strlen (netname), - &result, &len); + retval = yperr2nss (yp_match (domain, "publickey.byname", netname, + strlen (netname), &result, &len)); - if (__builtin_expect (yperr != YPERR_SUCCESS, 0)) + if (retval != NSS_STATUS_SUCCESS) { - enum nss_status retval = yperr2nss (yperr); - if (retval == NSS_STATUS_TRYAGAIN) *errnop = errno; return retval; @@ -115,22 +115,20 @@ _nss_nis_getsecretkey (const char *netname, char *skey, char *passwd, if (result != NULL) { char *p = strchr (result, ':'); - if (p != NULL) - { - char buf[2 * (HEXKEYBYTES + 1)]; - - ++p; - strncpy (buf, p, 2 * (HEXKEYBYTES + 1)); - buf[2 * HEXKEYBYTES + 1] = '\0'; - if (xdecrypt (buf, passwd) - && memcmp (buf, &(buf[HEXKEYBYTES]), KEYCHECKSUMSIZE) == 0) - { - buf[HEXKEYBYTES] = '\0'; - strcpy (skey, buf); - } - } - - free (result); + if (p == NULL) + return NSS_STATUS_SUCCESS; + + ++p; + strncpy (buf, p, 2 * (HEXKEYBYTES + 1)); + buf[2 * (HEXKEYBYTES + 1)] = '\0'; + if (!xdecrypt (buf, passwd)) + return NSS_STATUS_SUCCESS; + + if (memcmp (buf, &(buf[HEXKEYBYTES]), KEYCHECKSUMSIZE) != 0) + return NSS_STATUS_SUCCESS; + + buf[HEXKEYBYTES] = '\0'; + strcpy (skey, buf); } return NSS_STATUS_SUCCESS; } @@ -196,8 +194,13 @@ enum nss_status _nss_nis_netname2user (char netname[MAXNETNAMELEN + 1], uid_t *uidp, gid_t *gidp, int *gidlenp, gid_t *gidlist, int *errnop) { - char *domain = strchr (netname, '@'); - if (domain == NULL) + char *domain; + int yperr; + char *lookup; + int len; + + domain = strchr (netname, '@'); + if (!domain) { *errnop = EINVAL; return NSS_STATUS_UNAVAIL; @@ -205,10 +208,9 @@ _nss_nis_netname2user (char netname[MAXNETNAMELEN + 1], uid_t *uidp, /* Point past the '@' character */ ++domain; - char *lookup = NULL; - int len; - int yperr = yp_match (domain, "netid.byname", netname, strlen (netname), - &lookup, &len); + lookup = NULL; + yperr = yp_match (domain, "netid.byname", netname, strlen (netname), + &lookup, &len); switch (yperr) { case YPERR_SUCCESS: @@ -221,15 +223,17 @@ _nss_nis_netname2user (char netname[MAXNETNAMELEN + 1], uid_t *uidp, return NSS_STATUS_UNAVAIL; } - if (lookup == NULL) - return NSS_STATUS_NOTFOUND; - - - lookup[len] = '\0'; - - enum nss_status err = parse_netid_str (lookup, uidp, gidp, gidlenp, gidlist); + if (lookup) + { + enum nss_status err; - free (lookup); + lookup[len] = '\0'; + err = parse_netid_str (lookup, uidp, gidp, gidlenp, gidlist); + free (lookup); + return err; + } + else + return NSS_STATUS_NOTFOUND; - return err; + return NSS_STATUS_SUCCESS; } |