From 747664ad4f0f576efa5ce93082c3205f4a650590 Mon Sep 17 00:00:00 2001 From: nekral-guest Date: Mon, 9 Jun 2008 18:11:20 +0000 Subject: [PATCH] * 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. --- ChangeLog | 8 ++++++++ libmisc/console.c | 28 +++++++++++++++++----------- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index a9136cd0..3333dc57 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2008-06-09 Nicolas François + + * 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 * lib/sgetspent.c: Add brackets and parenthesis. diff --git a/libmisc/console.c b/libmisc/console.c index 7c800297..ec482406 100644 --- a/libmisc/console.c +++ b/libmisc/console.c @@ -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); } +