aboutsummaryrefslogtreecommitdiff
path: root/nis/nss_nis/nis-publickey.c
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2007-07-12 18:26:36 +0000
committerJakub Jelinek <jakub@redhat.com>2007-07-12 18:26:36 +0000
commit0ecb606cb6cf65de1d9fc8a919bceb4be476c602 (patch)
tree2ea1f8305970753e4a657acb2ccc15ca3eec8e2c /nis/nss_nis/nis-publickey.c
parent7d58530341304d403a6626d7f7a1913165fe2f32 (diff)
downloadglibc-0ecb606cb6cf65de1d9fc8a919bceb4be476c602.zip
glibc-0ecb606cb6cf65de1d9fc8a919bceb4be476c602.tar.gz
glibc-0ecb606cb6cf65de1d9fc8a919bceb4be476c602.tar.bz2
2.5-18.1
Diffstat (limited to 'nis/nss_nis/nis-publickey.c')
-rw-r--r--nis/nss_nis/nis-publickey.c106
1 files changed, 51 insertions, 55 deletions
diff --git a/nis/nss_nis/nis-publickey.c b/nis/nss_nis/nis-publickey.c
index 6e92112..f58eb15 100644
--- a/nis/nss_nis/nis-publickey.c
+++ b/nis/nss_nis/nis-publickey.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996,1997,1998,1999,2001,2002 Free Software Foundation, Inc.
+/* Copyright (C) 1996-1999,2001,2002,2005,2006 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@suse.de>, 1996.
@@ -36,10 +36,6 @@ 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)
@@ -48,19 +44,23 @@ _nss_nis_getpublickey (const char *netname, char *pkey, int *errnop)
return NSS_STATUS_UNAVAIL;
}
- domain = strchr (netname, '@');
- if (!domain)
+ char *domain = strchr (netname, '@');
+ if (domain == NULL)
{
*errnop = EINVAL;
return NSS_STATUS_UNAVAIL;
}
++domain;
- retval = yperr2nss (yp_match (domain, "publickey.byname", netname,
- strlen (netname), &result, &len));
+ char *result;
+ int len;
+ int yperr = yp_match (domain, "publickey.byname", netname, strlen (netname),
+ &result, &len);
- if (retval != NSS_STATUS_SUCCESS)
+ if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
{
+ enum nss_status retval = yperr2nss (yperr);
+
if (retval == NSS_STATUS_TRYAGAIN)
*errnop = errno;
return retval;
@@ -73,6 +73,7 @@ _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;
}
@@ -81,11 +82,6 @@ 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)
@@ -94,19 +90,23 @@ _nss_nis_getsecretkey (const char *netname, char *skey, char *passwd,
return NSS_STATUS_UNAVAIL;
}
- domain = strchr (netname, '@');
- if (!domain)
+ char *domain = strchr (netname, '@');
+ if (domain == NULL)
{
*errnop = EINVAL;
return NSS_STATUS_UNAVAIL;
}
++domain;
- retval = yperr2nss (yp_match (domain, "publickey.byname", netname,
- strlen (netname), &result, &len));
+ char *result;
+ int len;
+ int yperr = yp_match (domain, "publickey.byname", netname, strlen (netname),
+ &result, &len);
- if (retval != NSS_STATUS_SUCCESS)
+ if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
{
+ enum nss_status retval = yperr2nss (yperr);
+
if (retval == NSS_STATUS_TRYAGAIN)
*errnop = errno;
return retval;
@@ -115,20 +115,22 @@ _nss_nis_getsecretkey (const char *netname, char *skey, char *passwd,
if (result != NULL)
{
char *p = strchr (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);
+ 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);
}
return NSS_STATUS_SUCCESS;
}
@@ -194,13 +196,8 @@ 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;
- int yperr;
- char *lookup;
- int len;
-
- domain = strchr (netname, '@');
- if (!domain)
+ char *domain = strchr (netname, '@');
+ if (domain == NULL)
{
*errnop = EINVAL;
return NSS_STATUS_UNAVAIL;
@@ -208,9 +205,10 @@ _nss_nis_netname2user (char netname[MAXNETNAMELEN + 1], uid_t *uidp,
/* Point past the '@' character */
++domain;
- lookup = NULL;
- yperr = yp_match (domain, "netid.byname", netname, strlen (netname),
- &lookup, &len);
+ char *lookup = NULL;
+ int len;
+ int yperr = yp_match (domain, "netid.byname", netname, strlen (netname),
+ &lookup, &len);
switch (yperr)
{
case YPERR_SUCCESS:
@@ -223,17 +221,15 @@ _nss_nis_netname2user (char netname[MAXNETNAMELEN + 1], uid_t *uidp,
return NSS_STATUS_UNAVAIL;
}
- if (lookup)
- {
- enum nss_status err;
-
- lookup[len] = '\0';
- err = parse_netid_str (lookup, uidp, gidp, gidlenp, gidlist);
- free (lookup);
- return err;
- }
- else
+ if (lookup == NULL)
return NSS_STATUS_NOTFOUND;
- return NSS_STATUS_SUCCESS;
+
+ lookup[len] = '\0';
+
+ enum nss_status err = parse_netid_str (lookup, uidp, gidp, gidlenp, gidlist);
+
+ free (lookup);
+
+ return err;
}