src/logoutd.c: Use STRNDUPA() instead of its pattern
STRNDUPA() is equivalent to automatic storage allocation (alloca(3))
+ ZUSTR2STP().
The benefits of this refactor are:
- The allocation size is always correct, and needs no comments, since
it's now automatically calculated by the macro.
- STRNDUPA() is probably more familiar, since
- strndupa(3) is a libc function,
- STRNDUPA() is the obvious wrapper that
calculates the size based on the input array.
- We can remove ZUSTR2STP().
Signed-off-by: Alejandro Colomar <alx@kernel.org>
This commit is contained in:
committed by
Serge Hallyn
parent
ac591763fe
commit
cb3e2fbdcf
+9
-16
@@ -16,11 +16,12 @@
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <utmpx.h>
|
#include <utmpx.h>
|
||||||
|
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "prototypes.h"
|
#include "prototypes.h"
|
||||||
#include "shadowlog.h"
|
#include "shadowlog.h"
|
||||||
#include "sizeof.h"
|
#include "sizeof.h"
|
||||||
#include "string/strcpy/zustr2stp.h"
|
#include "string/strdup/strndupa.h"
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -48,22 +49,16 @@ static void send_mesg_to_tty (int tty_fd);
|
|||||||
static int
|
static int
|
||||||
check_login(const struct utmpx *ut)
|
check_login(const struct utmpx *ut)
|
||||||
{
|
{
|
||||||
char user[sizeof(ut->ut_user) + 1];
|
char *user;
|
||||||
char line[sizeof(ut->ut_line) + 1];
|
char *line;
|
||||||
time_t now;
|
time_t now;
|
||||||
|
|
||||||
ZUSTR2STP(user, ut->ut_user);
|
user = STRNDUPA(ut->ut_user);
|
||||||
ZUSTR2STP(line, ut->ut_line);
|
line = STRNDUPA(ut->ut_line);
|
||||||
|
|
||||||
now = time(NULL);
|
now = time(NULL);
|
||||||
|
|
||||||
/*
|
return isttytime(user, line, now);
|
||||||
* Check if they are allowed to be logged in right now.
|
|
||||||
*/
|
|
||||||
if (!isttytime(user, line, now)) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -177,7 +172,6 @@ main(int argc, char **argv)
|
|||||||
*/
|
*/
|
||||||
while ((ut = getutxent()) != NULL) {
|
while ((ut = getutxent()) != NULL) {
|
||||||
int tty_fd;
|
int tty_fd;
|
||||||
char user[sizeof(ut->ut_user) + 1]; // NUL
|
|
||||||
char tty_name[sizeof(ut->ut_line) + 6]; // /dev/ + NUL
|
char tty_name[sizeof(ut->ut_line) + 6]; // /dev/ + NUL
|
||||||
|
|
||||||
if (ut->ut_type != USER_PROCESS) {
|
if (ut->ut_type != USER_PROCESS) {
|
||||||
@@ -229,10 +223,9 @@ main(int argc, char **argv)
|
|||||||
kill (-ut->ut_pid, SIGKILL);
|
kill (-ut->ut_pid, SIGKILL);
|
||||||
}
|
}
|
||||||
|
|
||||||
ZUSTR2STP(user, ut->ut_user);
|
|
||||||
|
|
||||||
SYSLOG ((LOG_NOTICE,
|
SYSLOG ((LOG_NOTICE,
|
||||||
"logged off user '%s' on '%s'", user,
|
"logged off user '%s' on '%s'",
|
||||||
|
STRNDUPA(ut->ut_user),
|
||||||
tty_name));
|
tty_name));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in New Issue
Block a user