summaryrefslogtreecommitdiffstats
path: root/lib/gshadow.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--lib/gshadow.c231
1 files changed, 19 insertions, 212 deletions
diff --git a/lib/gshadow.c b/lib/gshadow.c
index 2e12923..3c71bea 100644
--- a/lib/gshadow.c
+++ b/lib/gshadow.c
@@ -15,8 +15,12 @@
#ident "$Id$"
#include <stdio.h>
+#include <string.h>
+
+#include "alloc.h"
#include "prototypes.h"
#include "defines.h"
+
static /*@null@*/FILE *shadow;
static /*@null@*//*@only@*/char **members = NULL;
static size_t nmembers = 0;
@@ -26,34 +30,6 @@ static struct sgrp sgroup;
#define FIELDS 4
-#ifdef USE_NIS
-static bool nis_used;
-static bool nis_ignore;
-static enum { native, start, middle, native2 } nis_state;
-static bool nis_bound;
-static char *nis_domain;
-static char *nis_key;
-static int nis_keylen;
-static char *nis_val;
-static int nis_vallen;
-
-#define IS_NISCHAR(c) ((c)=='+')
-#endif
-
-#ifdef USE_NIS
-/*
- * bind_nis - bind to NIS server
- */
-
-static int bind_nis (void)
-{
- if (yp_get_default_domain (&nis_domain))
- return -1;
-
- nis_bound = true;
- return 0;
-}
-#endif
static /*@null@*/char **build_list (char *s, char **list[], size_t * nlist)
{
@@ -62,21 +38,16 @@ static /*@null@*/char **build_list (char *s, char **list[], size_t * nlist)
while (s != NULL && *s != '\0') {
size = (nelem + 1) * sizeof (ptr);
- ptr = realloc (*list, size);
+ ptr = REALLOC(*list, size, char *);
if (NULL != ptr) {
- ptr[nelem] = s;
+ ptr[nelem] = strsep(&s, ",");
nelem++;
*list = ptr;
*nlist = nelem;
- s = strchr (s, ',');
- if (NULL != s) {
- *s = '\0';
- s++;
- }
}
}
size = (nelem + 1) * sizeof (ptr);
- ptr = realloc (*list, size);
+ ptr = REALLOC(*list, size, char *);
if (NULL != ptr) {
ptr[nelem] = NULL;
*list = ptr;
@@ -86,9 +57,6 @@ static /*@null@*/char **build_list (char *s, char **list[], size_t * nlist)
void setsgent (void)
{
-#ifdef USE_NIS
- nis_state = native;
-#endif
if (NULL != shadow) {
rewind (shadow);
} else {
@@ -102,7 +70,7 @@ void endsgent (void)
(void) fclose (shadow);
}
- shadow = (FILE *) 0;
+ shadow = NULL;
}
/*@observer@*//*@null@*/struct sgrp *sgetsgent (const char *string)
@@ -116,7 +84,7 @@ void endsgent (void)
size_t len = strlen (string) + 1;
if (len > sgrbuflen) {
- char *buf = (char *) realloc (sgrbuf, sizeof (char) * len);
+ char *buf = REALLOC(sgrbuf, len, char);
if (NULL == buf) {
return NULL;
}
@@ -124,8 +92,7 @@ void endsgent (void)
sgrbuflen = len;
}
- strncpy (sgrbuf, string, len);
- sgrbuf[len-1] = '\0';
+ strcpy (sgrbuf, string);
cp = strrchr (sgrbuf, '\n');
if (NULL != cp) {
@@ -137,30 +104,16 @@ void endsgent (void)
* all 4 of them and save the starting addresses in fields[].
*/
- for (cp = sgrbuf, i = 0; (i < FIELDS) && (NULL != cp); i++) {
- fields[i] = cp;
- cp = strchr (cp, ':');
- if (NULL != cp) {
- *cp++ = '\0';
- }
- }
+ for (cp = sgrbuf, i = 0; (i < FIELDS) && (NULL != cp); i++)
+ fields[i] = strsep(&cp, ":");
/*
* If there was an extra field somehow, or perhaps not enough,
* the line is invalid.
*/
- if ((NULL != cp) || (i != FIELDS)) {
-#ifdef USE_NIS
- if (!IS_NISCHAR (fields[0][0])) {
- return 0;
- } else {
- nis_used = true;
- }
-#else
+ if (NULL != cp || i != FIELDS)
return 0;
-#endif
- }
sgroup.sg_name = fields[0];
sgroup.sg_passwd = fields[1];
@@ -195,7 +148,7 @@ void endsgent (void)
char *cp;
if (0 == buflen) {
- buf = (char *) malloc (BUFSIZ);
+ buf = MALLOC(BUFSIZ, char);
if (NULL == buf) {
return NULL;
}
@@ -206,17 +159,12 @@ void endsgent (void)
return NULL;
}
-#ifdef USE_NIS
- while (fgetsx (buf, (int) buflen, fp) == buf)
-#else
- if (fgetsx (buf, (int) buflen, fp) == buf)
-#endif
- {
+ if (fgetsx(buf, buflen, fp) == buf) {
while ( ((cp = strrchr (buf, '\n')) == NULL)
&& (feof (fp) == 0)) {
size_t len;
- cp = (char *) realloc (buf, buflen*2);
+ cp = REALLOC(buf, buflen * 2, char);
if (NULL == cp) {
return NULL;
}
@@ -234,11 +182,6 @@ void endsgent (void)
if (NULL != cp) {
*cp = '\0';
}
-#ifdef USE_NIS
- if (nis_ignore && IS_NISCHAR (buf[0])) {
- continue;
- }
-#endif
return (sgetsgent (buf));
}
return NULL;
@@ -250,96 +193,10 @@ void endsgent (void)
/*@observer@*//*@null@*/struct sgrp *getsgent (void)
{
-#ifdef USE_NIS
- bool nis_1_group = false;
- struct sgrp *val;
-#endif
if (NULL == shadow) {
setsgent ();
}
-
-#ifdef USE_NIS
- again:
- /*
- * See if we are reading from the local file.
- */
-
- if (nis_state == native || nis_state == native2) {
-
- /*
- * Get the next entry from the shadow group file. Return
- * NULL right away if there is none.
- */
-
- val = fgetsgent (shadow);
- if (NULL == val) {
- return 0;
- }
-
- /*
- * If this entry began with a NIS escape character, we have
- * to see if this is just a single group, or if the entire
- * map is being asked for.
- */
-
- if (IS_NISCHAR (val->sg_name[0])) {
- if ('\0' != val->sg_name[1]) {
- nis_1_group = true;
- } else {
- nis_state = start;
- }
- }
-
- /*
- * If this isn't a NIS group and this isn't an escape to go
- * use a NIS map, it must be a regular local group.
- */
-
- if (!nis_1_group && (nis_state != start)) {
- return val;
- }
-
- /*
- * If this is an escape to use an NIS map, switch over to
- * that bunch of code.
- */
-
- if (nis_state == start) {
- goto again;
- }
-
- /*
- * NEEDSWORK. Here we substitute pieces-parts of this entry.
- */
-
- return 0;
- } else {
- if (!nis_bound) {
- if (bind_nis ()) {
- nis_state = native2;
- goto again;
- }
- }
- if (nis_state == start) {
- if (yp_first (nis_domain, "gshadow.byname", &nis_key,
- &nis_keylen, &nis_val, &nis_vallen)) {
- nis_state = native2;
- goto again;
- }
- nis_state = middle;
- } else if (nis_state == middle) {
- if (yp_next (nis_domain, "gshadow.byname", nis_key,
- nis_keylen, &nis_key, &nis_keylen,
- &nis_val, &nis_vallen)) {
- nis_state = native2;
- goto again;
- }
- }
- return sgetsgent (nis_val);
- }
-#else
return (fgetsgent (shadow));
-#endif
}
/*
@@ -350,63 +207,13 @@ void endsgent (void)
{
struct sgrp *sgrp;
-#ifdef USE_NIS
- static char save_name[16];
- int nis_disabled = 0;
-#endif
-
setsgent ();
-#ifdef USE_NIS
- if (nis_used) {
- again:
-
- /*
- * Search the gshadow.byname map for this group.
- */
-
- if (!nis_bound) {
- bind_nis ();
- }
-
- if (nis_bound) {
- char *cp;
-
- if (yp_match (nis_domain, "gshadow.byname", name,
- strlen (name), &nis_val,
- &nis_vallen) == 0) {
- cp = strchr (nis_val, '\n');
- if (NULL != cp) {
- *cp = '\0';
- }
-
- nis_state = middle;
- sgrp = sgetsgent (nis_val);
- if (NULL != sgrp) {
- strcpy (save_name, sgrp->sg_name);
- nis_key = save_name;
- nis_keylen = strlen (save_name);
- }
- return sgrp;
- }
- }
- nis_state = native2;
- }
-#endif
-#ifdef USE_NIS
- if (nis_used) {
- nis_ignore = true;
- nis_disabled = true;
- }
-#endif
- while ((sgrp = getsgent ()) != (struct sgrp *) 0) {
+ while ((sgrp = getsgent ()) != NULL) {
if (strcmp (name, sgrp->sg_name) == 0) {
break;
}
}
-#ifdef USE_NIS
- nis_ignore = false;
-#endif
return sgrp;
}
@@ -437,7 +244,7 @@ int putsgent (const struct sgrp *sgrp, FILE * fp)
size += strlen (sgrp->sg_mem[i]) + 1;
}
- buf = malloc (size);
+ buf = MALLOC(size, char);
if (NULL == buf) {
return -1;
}
@@ -502,5 +309,5 @@ int putsgent (const struct sgrp *sgrp, FILE * fp)
return 0;
}
#else
-extern int errno; /* warning: ANSI C forbids an empty source file */
+extern int ISO_C_forbids_an_empty_translation_unit;
#endif /*} SHADOWGRP */