* hushed returns a bool instead of int.
* Avoid assignments in comparisons. * (hushed) Change type of found to bool. * Add brackets. * Always check if the user or the shell is in the file. Do not check the first character of the line first. This is simpler and match better with the HUSHLOGIN_FILE documentation.
This commit is contained in:
parent
712ed48a62
commit
bc0657d13c
12
ChangeLog
12
ChangeLog
@ -1,10 +1,20 @@
|
|||||||
|
2008-05-25 Nicolas François <nicolas.francois@centraliens.net>
|
||||||
|
|
||||||
|
* libmisc/hushed.c: hushed returns a bool instead of int.
|
||||||
|
* libmisc/hushed.c: Avoid assignments in comparisons.
|
||||||
|
* libmisc/hushed.c (hushed): Change type of found to bool.
|
||||||
|
* libmisc/hushed.c: Add brackets.
|
||||||
|
* libmisc/hushed.c: Always check if the user or the shell is in
|
||||||
|
the file. Do not check the first character of the line first. This
|
||||||
|
is simpler and match better with the HUSHLOGIN_FILE documentation.
|
||||||
|
|
||||||
2008-05-25 Nicolas François <nicolas.francois@centraliens.net>
|
2008-05-25 Nicolas François <nicolas.francois@centraliens.net>
|
||||||
|
|
||||||
* lib/getdef.h, lib/getdef.c: getdef_bool returns a bool instead
|
* lib/getdef.h, lib/getdef.c: getdef_bool returns a bool instead
|
||||||
of int.
|
of int.
|
||||||
* lib/getdef.c: Change typo of def_loaded to bool.
|
* lib/getdef.c: Change typo of def_loaded to bool.
|
||||||
* lib/getdef.c: Add brackets.
|
* lib/getdef.c: Add brackets.
|
||||||
* lib/getdef.c: Avoid assignment in comparisons.
|
* lib/getdef.c: Avoid assignments in comparisons.
|
||||||
|
|
||||||
2008-05-25 Nicolas François <nicolas.francois@centraliens.net>
|
2008-05-25 Nicolas François <nicolas.francois@centraliens.net>
|
||||||
|
|
||||||
|
@ -36,21 +36,21 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <pwd.h>
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "prototypes.h"
|
#include "prototypes.h"
|
||||||
#include "getdef.h"
|
#include "getdef.h"
|
||||||
#include <pwd.h>
|
|
||||||
/*
|
/*
|
||||||
* hushed - determine if a user receives login messages
|
* hushed - determine if a user receives login messages
|
||||||
*
|
*
|
||||||
* Look in the hushed-logins file (or user's home directory) to see
|
* Look in the hushed-logins file (or user's home directory) to see
|
||||||
* if the user is to receive the login-time messages.
|
* if the user is to receive the login-time messages.
|
||||||
*/
|
*/
|
||||||
int hushed (const struct passwd *pw)
|
bool hushed (const struct passwd *pw)
|
||||||
{
|
{
|
||||||
char *hushfile;
|
char *hushfile;
|
||||||
char buf[BUFSIZ];
|
char buf[BUFSIZ];
|
||||||
int found;
|
bool found;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -58,8 +58,10 @@ int hushed (const struct passwd *pw)
|
|||||||
* defined, default to a noisy login.
|
* defined, default to a noisy login.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ((hushfile = getdef_str ("HUSHLOGIN_FILE")) == NULL)
|
hushfile = getdef_str ("HUSHLOGIN_FILE");
|
||||||
return 0;
|
if (NULL == hushfile) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If this is not a fully rooted path then see if the
|
* If this is not a fully rooted path then see if the
|
||||||
@ -73,17 +75,19 @@ int hushed (const struct passwd *pw)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* If this is a fully rooted path then go through the file
|
* If this is a fully rooted path then go through the file
|
||||||
* and see if this user is in there.
|
* and see if this user, or its shell is in there.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ((fp = fopen (hushfile, "r")) == NULL)
|
fp = fopen (hushfile, "r");
|
||||||
return 0;
|
if (NULL == fp) {
|
||||||
|
return false;
|
||||||
for (found = 0; !found && fgets (buf, sizeof buf, fp);) {
|
}
|
||||||
|
for (found = false; !found && (fgets (buf, sizeof buf, fp) != NULL);) {
|
||||||
buf[strlen (buf) - 1] = '\0';
|
buf[strlen (buf) - 1] = '\0';
|
||||||
found = !strcmp (buf,
|
found = (strcmp (buf, pw->pw_shell) == 0) ||
|
||||||
buf[0] == '/' ? pw->pw_shell : pw->pw_name);
|
(strcmp (buf, pw->pw_name) == 0);
|
||||||
}
|
}
|
||||||
(void) fclose (fp);
|
(void) fclose (fp);
|
||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user