+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.
#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;
* 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
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;
}
/*
* 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.
buf[strlen (buf) - 1] = '\0';
if (strcmp (buf, tty) == 0) {
(void) fclose (fp);
- return 1;
+ return true;
}
}
*/
(void) fclose (fp);
- return 0;
+ return false;
}
/*
* 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);
}
+