aboutsummaryrefslogtreecommitdiff
path: root/nis/nis_defaults.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2004-12-22 20:10:10 +0000
committerUlrich Drepper <drepper@redhat.com>2004-12-22 20:10:10 +0000
commita334319f6530564d22e775935d9c91663623a1b4 (patch)
treeb5877475619e4c938e98757d518bb1e9cbead751 /nis/nis_defaults.c
parent0ecb606cb6cf65de1d9fc8a919bceb4be476c602 (diff)
downloadglibc-a334319f6530564d22e775935d9c91663623a1b4.tar
glibc-a334319f6530564d22e775935d9c91663623a1b4.tar.gz
glibc-a334319f6530564d22e775935d9c91663623a1b4.tar.bz2
glibc-a334319f6530564d22e775935d9c91663623a1b4.zip
(CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4.
Diffstat (limited to 'nis/nis_defaults.c')
-rw-r--r--nis/nis_defaults.c127
1 files changed, 80 insertions, 47 deletions
diff --git a/nis/nis_defaults.c b/nis/nis_defaults.c
index ed79b59ec6..f13578635a 100644
--- a/nis/nis_defaults.c
+++ b/nis/nis_defaults.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 1997, 1998, 2004, 2006 Free Software Foundation, Inc.
+/* Copyright (c) 1997, 1998, 2004 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997.
@@ -17,7 +17,6 @@
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
-#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -31,35 +30,44 @@
** Some functions for parsing the -D param and NIS_DEFAULTS Environ
*/
static nis_name
-searchXYX (char *str, const char *what)
+searchgroup (char *str)
{
- assert (strlen (what) == 6);
- assert (strncmp (str, what, 6) == 0);
- str += 6; /* Points to the begin of the parameters. */
-
- int i = 0;
- while (str[i] != '\0' && str[i] != ':')
- ++i;
- if (i == 0) /* only "<WHAT>=" ? */
- return strdup ("");
+ char *cptr;
+ int i;
- return strndup (str, i);
-}
+ cptr = strstr (str, "group=");
+ if (cptr == NULL)
+ return NULL;
+ cptr += 6; /* points to the begin of the group string */
+ i = 0;
+ while (cptr[i] != '\0' && cptr[i] != ':')
+ i++;
+ if (i == 0) /* only "group=" ? */
+ return (nis_name) "";
-static nis_name
-searchgroup (char *str)
-{
- return searchXYX (str, "group=");
+ return strndup (cptr, i);
}
-
static nis_name
searchowner (char *str)
{
- return searchXYX (str, "owner=");
-}
+ char *cptr;
+ int i;
+ cptr = strstr (str, "owner=");
+ if (cptr == NULL)
+ return NULL;
+
+ cptr += 6; /* points to the begin of the owner string */
+ i = 0;
+ while (cptr[i] != '\0' && cptr[i] != ':')
+ i++;
+ if (i == 0) /* only "owner=" ? */
+ return strdup ("");
+
+ return strndup (cptr, i);
+}
static uint32_t
searchttl (char *str)
@@ -350,61 +358,86 @@ searchaccess (char *str, unsigned int access)
return result;
}
-
nis_name
__nis_default_owner (char *defaults)
{
- char *default_owner = NULL;
+ char default_owner[NIS_MAXNAMELEN + 1];
+ char *cptr, *dptr;
- char *cptr = defaults;
- if (cptr == NULL)
- cptr = getenv ("NIS_DEFAULTS");
+ strcpy (default_owner, nis_local_principal ());
- if (cptr != NULL)
+ if (defaults != NULL)
{
- char *dptr = strstr (cptr, "owner=");
+ dptr = strstr (defaults, "owner=");
if (dptr != NULL)
{
- char *p = searchowner (dptr);
- if (p == NULL)
- return NULL;
- default_owner = strdupa (p);
+ char *p = searchowner (defaults);
+ if (strlen (p) <= NIS_MAXNAMELEN)
+ strcpy (default_owner, p);
free (p);
}
}
+ else
+ {
+ cptr = getenv ("NIS_DEFAULTS");
+ if (cptr != NULL)
+ {
+ dptr = strstr (cptr, "owner=");
+ if (dptr != NULL)
+ {
+ char *p = searchowner (cptr);
+ if (strlen (p) <= NIS_MAXNAMELEN)
+ strcpy (default_owner, p);
+ free (p);
+ }
+ }
+ }
- return strdup (default_owner ?: nis_local_principal ());
+ return strdup (default_owner);
}
libnsl_hidden_def (__nis_default_owner)
-
nis_name
__nis_default_group (char *defaults)
{
- char *default_group = NULL;
+ char default_group[NIS_MAXNAMELEN + 1];
+ char *cptr, *dptr;
- char *cptr = defaults;
- if (cptr == NULL)
- cptr = getenv ("NIS_DEFAULTS");
+ strcpy (default_group, nis_local_group ());
- if (cptr != NULL)
+ if (defaults != NULL)
{
- char *dptr = strstr (cptr, "group=");
+ dptr = strstr (defaults, "group=");
if (dptr != NULL)
{
- char *p = searchgroup (dptr);
- if (p == NULL)
- return NULL;
- default_group = strdupa (p);
+ char *p = searchgroup (defaults);
+
+ if (strlen (p) <= NIS_MAXNAMELEN)
+ strcpy (default_group, p);
free (p);
}
}
+ else
+ {
+ cptr = getenv ("NIS_DEFAULTS");
+ if (cptr != NULL)
+ {
+ dptr = strstr (cptr, "group=");
+ if (dptr != NULL)
+ {
+ char *p = searchgroup (cptr);
+
+ if (strlen (p) <= NIS_MAXNAMELEN)
+ strcpy (default_group, p);
+ free (p);
+ }
+ }
+ }
- return strdup (default_group ?: nis_local_group ());
+ return strdup (default_group);
}
libnsl_hidden_def (__nis_default_group)
-
uint32_t
__nis_default_ttl (char *defaults)
{
@@ -447,7 +480,7 @@ __nis_default_access (char *param, unsigned int defaults)
{
cptr = getenv ("NIS_DEFAULTS");
if (cptr != NULL && strstr (cptr, "access=") != NULL)
- result = searchaccess (cptr, result);
+ result = searchaccess (getenv ("NIS_DEFAULTS"), result);
}
return result;