* lib/gshadow.c: Use a bool when possible instead of int integers.

* lib/gshadow.c: Remove __setsgNIS() -never used).
	* lib/gshadow.c: Avoid multi-statements lines.
	* lib/gshadow.c: Avoid assignments in comparisons.
	* lib/gshadow.c: ptr[nelem] is a string. Initialize it to NULL
	instead of '\0'.
	* lib/gshadow.c: Add brackets and parenthesis.
	* lib/gshadow.c: The size argument of strncpy is a size_t and the
	size argument of fgets is an int.
This commit is contained in:
nekral-guest 2008-06-13 21:45:47 +00:00
parent 4589ba350f
commit 838f39d0fd
2 changed files with 39 additions and 32 deletions

View File

@ -1,3 +1,15 @@
2008-06-13 Nicolas François <nicolas.francois@centraliens.net>
* lib/gshadow.c: Use a bool when possible instead of int integers.
* lib/gshadow.c: Remove __setsgNIS() -never used).
* lib/gshadow.c: Avoid multi-statements lines.
* lib/gshadow.c: Avoid assignments in comparisons.
* lib/gshadow.c: ptr[nelem] is a string. Initialize it to NULL
instead of '\0'.
* lib/gshadow.c: Add brackets and parenthesis.
* lib/gshadow.c: The size argument of strncpy is a size_t and the
size argument of fgets is an int.
2008-06-13 Nicolas François <nicolas.francois@centraliens.net> 2008-06-13 Nicolas François <nicolas.francois@centraliens.net>
* lib/groupio.c: Add brackets. * lib/groupio.c: Add brackets.

View File

@ -52,7 +52,7 @@ static struct sgrp sgroup;
#ifdef USE_NIS #ifdef USE_NIS
static bool nis_used; static bool nis_used;
static int nis_ignore; static bool nis_ignore;
static enum { native, start, middle, native2 } nis_state; static enum { native, start, middle, native2 } nis_state;
static bool nis_bound; static bool nis_bound;
static char *nis_domain; static char *nis_domain;
@ -65,20 +65,6 @@ static int nis_vallen;
#endif #endif
#ifdef USE_NIS #ifdef USE_NIS
/*
* __setsgNIS - turn on or off NIS searches
*/
void __setsgNIS (int flag)
{
nis_ignore = !flag;
if (nis_ignore) {
nis_used = false;
}
}
/* /*
* bind_nis - bind to NIS server * bind_nis - bind to NIS server
*/ */
@ -101,16 +87,21 @@ static char **build_list (char *s, char **list[], size_t * nlist)
while (s != NULL && *s != '\0') { while (s != NULL && *s != '\0') {
size = (nelem + 1) * sizeof (ptr); size = (nelem + 1) * sizeof (ptr);
if ((ptr = realloc (*list, size)) != NULL) { if ((ptr = realloc (*list, size)) != NULL) {
ptr[nelem++] = s; ptr[nelem] = s;
nelem++;
*list = ptr; *list = ptr;
*nlist = nelem; *nlist = nelem;
if ((s = strchr (s, ','))) s = strchr (s, ',');
*s++ = '\0'; if (NULL != s) {
*s = '\0';
s++;
}
} }
} }
size = (nelem + 1) * sizeof (ptr); size = (nelem + 1) * sizeof (ptr);
if ((ptr = realloc (*list, size)) != NULL) { ptr = realloc (*list, size);
ptr[nelem] = '\0'; if (NULL != ptr) {
ptr[nelem] = NULL;
*list = ptr; *list = ptr;
} }
return ptr; return ptr;
@ -143,7 +134,7 @@ struct sgrp *sgetsgent (const char *string)
char *cp; char *cp;
int i; int i;
strncpy (sgrbuf, string, (int) sizeof sgrbuf - 1); strncpy (sgrbuf, string, sizeof sgrbuf - 1);
sgrbuf[sizeof sgrbuf - 1] = '\0'; sgrbuf[sizeof sgrbuf - 1] = '\0';
cp = strrchr (sgrbuf, '\n'); cp = strrchr (sgrbuf, '\n');
@ -215,9 +206,9 @@ struct sgrp *fgetsgent (FILE * fp)
} }
#ifdef USE_NIS #ifdef USE_NIS
while (fgetsx (buf, sizeof buf, fp) != (char *) 0) while (fgetsx (buf, (int) sizeof buf, fp) != (char *) 0)
#else #else
if (fgetsx (buf, sizeof buf, fp) != (char *) 0) if (fgetsx (buf, (int) sizeof buf, fp) != (char *) 0)
#endif #endif
{ {
cp = strchr (buf, '\n'); cp = strchr (buf, '\n');
@ -225,7 +216,7 @@ struct sgrp *fgetsgent (FILE * fp)
*cp = '\0'; *cp = '\0';
} }
#ifdef USE_NIS #ifdef USE_NIS
if ((0 != nis_ignore) && IS_NISCHAR (buf[0])) { if (nis_ignore && IS_NISCHAR (buf[0])) {
continue; continue;
} }
#endif #endif
@ -241,7 +232,7 @@ struct sgrp *fgetsgent (FILE * fp)
struct sgrp *getsgent (void) struct sgrp *getsgent (void)
{ {
#ifdef USE_NIS #ifdef USE_NIS
int nis_1_group = 0; bool nis_1_group = false;
struct sgrp *val; struct sgrp *val;
char buf[BUFSIZ]; char buf[BUFSIZ];
#endif #endif
@ -275,7 +266,7 @@ struct sgrp *getsgent (void)
if (IS_NISCHAR (val->sg_name[0])) { if (IS_NISCHAR (val->sg_name[0])) {
if ('\0' != val->sg_name[1]) { if ('\0' != val->sg_name[1]) {
nis_1_group = 1; nis_1_group = true;
} else { } else {
nis_state = start; nis_state = start;
} }
@ -286,16 +277,18 @@ struct sgrp *getsgent (void)
* use a NIS map, it must be a regular local group. * use a NIS map, it must be a regular local group.
*/ */
if (nis_1_group == 0 && nis_state != start) if (!nis_1_group && (nis_state != start)) {
return val; return val;
}
/* /*
* If this is an escape to use an NIS map, switch over to * If this is an escape to use an NIS map, switch over to
* that bunch of code. * that bunch of code.
*/ */
if (nis_state == start) if (nis_state == start) {
goto again; goto again;
}
/* /*
* NEEDSWORK. Here we substitute pieces-parts of this entry. * NEEDSWORK. Here we substitute pieces-parts of this entry.
@ -385,7 +378,7 @@ struct sgrp *getsgnam (const char *name)
#endif #endif
#ifdef USE_NIS #ifdef USE_NIS
if (nis_used) { if (nis_used) {
nis_ignore++; nis_ignore = true;
nis_disabled = true; nis_disabled = true;
} }
#endif #endif
@ -395,7 +388,7 @@ struct sgrp *getsgnam (const char *name)
} }
} }
#ifdef USE_NIS #ifdef USE_NIS
nis_ignore--; nis_ignore = false;
#endif #endif
return sgrp; return sgrp;
} }
@ -466,13 +459,15 @@ int putsgent (const struct sgrp *sgrp, FILE * fp)
for (i = 0; NULL != sgrp->sg_mem[i]; i++) { for (i = 0; NULL != sgrp->sg_mem[i]; i++) {
if (i > 0) { if (i > 0) {
*cp++ = ','; *cp = ',';
cp++;
} }
strcpy (cp, sgrp->sg_mem[i]); strcpy (cp, sgrp->sg_mem[i]);
cp += strlen (cp); cp += strlen (cp);
} }
*cp++ = '\n'; *cp = '\n';
cp++;
*cp = '\0'; *cp = '\0';
/* /*