forked from Lainports/freebsd-ports
71 lines
1.9 KiB
Text
71 lines
1.9 KiB
Text
--- blimitd.c
|
|
+++ blimitd.c
|
|
@@ -15,7 +15,7 @@
|
|
#include <sysexits.h>
|
|
#include <syslog.h>
|
|
#include <unistd.h>
|
|
-#include <utmp.h>
|
|
+#include <utmpx.h>
|
|
|
|
#include "blimitd.h"
|
|
#include "config.h"
|
|
@@ -35,7 +35,7 @@
|
|
pid_t pid;
|
|
char *name;
|
|
FILE *utmp_fh;
|
|
- struct utmp utmp_record;
|
|
+ struct utmpx *utmp_record;
|
|
struct passwd *pw;
|
|
struct user_instance ui;
|
|
|
|
@@ -115,23 +115,19 @@
|
|
|
|
/* actually do stuff */
|
|
while (sig_no == 0) {
|
|
- /* get the logged in users */
|
|
- if ((utmp_fh = fopen(_PATH_UTMP, "r")) == NULL) {
|
|
- syslog(LOG_ERR, "failed to open %s for reading: %m", _PATH_UTMP);
|
|
- continue;
|
|
- }
|
|
/* prepare for pw access */
|
|
if (! setpassent(1)) {
|
|
syslog(LOG_ERR, "setpassent: %m");
|
|
}
|
|
/* for each entry */
|
|
- while (fread(&utmp_record, sizeof(utmp_record), 1, utmp_fh)) {
|
|
- if (utmp_record.ut_name[0] == '\0') {
|
|
+ setutxent();
|
|
+ while ((utmp_record = getutxent()) != NULL) {
|
|
+ if (utmp_record->ut_type != USER_PROCESS) {
|
|
/* this entry has been removed */
|
|
continue;
|
|
}
|
|
/* get their name in a char *\0 */
|
|
- if ((name = strndup(utmp_record.ut_name, UT_NAMESIZE)) == NULL) {
|
|
+ if ((name = strndup(utmp_record->ut_user, sizeof utmp_record->ut_user)) == NULL) {
|
|
syslog(LOG_ERR, "strndup failed: %m");
|
|
continue;
|
|
}
|
|
@@ -150,7 +146,7 @@
|
|
|
|
/* initialise ui for passing to enforcement functions */
|
|
ui.pw = pw;
|
|
- if ((ui.tty = find_tty(utmp_record.ut_line, UT_LINESIZE)) == NULL) {
|
|
+ if ((ui.tty = find_tty(utmp_record->ut_line, sizeof utmp_record->ut_line)) == NULL) {
|
|
syslog(LOG_ERR, "find_tty failed: %m");
|
|
continue;
|
|
}
|
|
@@ -163,12 +159,7 @@
|
|
free(ui.tty);
|
|
}
|
|
|
|
- if (ferror(utmp_fh)) {
|
|
- syslog(LOG_ERR, "error reading from %s: %m", _PATH_UTMP);
|
|
- }
|
|
- if (fclose(utmp_fh) != 0) {
|
|
- syslog(LOG_ERR, "error closing %s: %m", _PATH_UTMP);
|
|
- }
|
|
+ endutxent();
|
|
|
|
/* finished with the password database till next time */
|
|
endpwent();
|