* libmisc/console.c: Change is_listed() prototype to return a bool.

The default parameter should also be a bool.
	* libmisc/console.c: Add brackets and parenthesis.
	* libmisc/console.c: Avoid assignments in comparisons.
	* libmisc/console.c: Change console() prototype to return a bool.
This commit is contained in:
nekral-guest 2008-06-09 18:11:20 +00:00
parent 9e31065b5e
commit 747664ad4f
2 changed files with 25 additions and 11 deletions

View File

@ -1,3 +1,11 @@
2008-06-09 Nicolas François <nicolas.francois@centraliens.net>
* libmisc/console.c: Change is_listed() prototype to return a bool.
The default parameter should also be a bool.
* libmisc/console.c: Add brackets and parenthesis.
* libmisc/console.c: Avoid assignments in comparisons.
* libmisc/console.c: Change console() prototype to return a bool.
2008-05-26 Nicolas François <nicolas.francois@centraliens.net>
* lib/sgetspent.c: Add brackets and parenthesis.

View File

@ -40,14 +40,14 @@
#ident "$Id$"
/* local function prototypes */
static int is_listed (const char *cfgin, const char *tty, int def);
static bool is_listed (const char *cfgin, const char *tty, bool def);
/*
* This is now rather generic function which decides if "tty" is listed
* under "cfgin" in config (directly or indirectly). Fallback to default if
* something is bad.
*/
static int is_listed (const char *cfgin, const char *tty, int def)
static bool is_listed (const char *cfgin, const char *tty, bool def)
{
FILE *fp;
char buf[200], *cons, *s;
@ -57,8 +57,10 @@ static int is_listed (const char *cfgin, const char *tty, int def)
* fallback to default.
*/
if ((cons = getdef_str (cfgin)) == NULL)
cons = getdef_str (cfgin);
if (NULL == cons) {
return def;
}
/*
* If this isn't a filename, then it is a ":" delimited list of
@ -68,12 +70,13 @@ static int is_listed (const char *cfgin, const char *tty, int def)
if (*cons != '/') {
cons = strcpy (buf, cons);
while ((s = strtok (cons, ":")) != NULL) {
if (strcmp (s, tty) == 0)
return 1;
if (strcmp (s, tty) == 0) {
return true;
}
cons = NULL;
}
return 0;
return false;
}
/*
@ -81,8 +84,10 @@ static int is_listed (const char *cfgin, const char *tty, int def)
* console - otherwise root will never be allowed to login.
*/
if ((fp = fopen (cons, "r")) == NULL)
fp = fopen (cons, "r");
if (NULL == fp) {
return def;
}
/*
* See if this tty is listed in the console file.
@ -92,7 +97,7 @@ static int is_listed (const char *cfgin, const char *tty, int def)
buf[strlen (buf) - 1] = '\0';
if (strcmp (buf, tty) == 0) {
(void) fclose (fp);
return 1;
return true;
}
}
@ -101,7 +106,7 @@ static int is_listed (const char *cfgin, const char *tty, int def)
*/
(void) fclose (fp);
return 0;
return false;
}
/*
@ -114,7 +119,8 @@ static int is_listed (const char *cfgin, const char *tty, int def)
* that would allow an unauthorized root login.
*/
int console (const char *tty)
bool console (const char *tty)
{
return is_listed ("CONSOLE", tty, 1);
return is_listed ("CONSOLE", tty, true);
}