mirror of
https://git.FreeBSD.org/ports.git
synced 2024-11-27 00:57:50 +00:00
Let blimitd use utmpx on OSVERSION 900007 and higher.
Approved by: miwi (portmgr, implicit)
This commit is contained in:
parent
eb24cef1f9
commit
f9d9f937a8
Notes:
svn2git
2021-03-31 03:12:20 +00:00
svn path=/head/; revision=248228
@ -26,4 +26,10 @@ post-install:
|
||||
${INSTALL_SCRIPT} -m 751 ${FILESDIR}/blimitd.sh ${PREFIX}/etc/rc.d/blimitd.sh; \
|
||||
fi
|
||||
|
||||
.include <bsd.port.mk>
|
||||
.include <bsd.port.pre.mk>
|
||||
|
||||
.if ${OSVERSION} >= 900007
|
||||
EXTRA_PATCHES+= ${FILESDIR}/extra-patch-utmpx
|
||||
.endif
|
||||
|
||||
.include <bsd.port.post.mk>
|
||||
|
71
sysutils/blimitd/files/extra-patch-utmpx
Normal file
71
sysutils/blimitd/files/extra-patch-utmpx
Normal file
@ -0,0 +1,71 @@
|
||||
--- 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();
|
Loading…
Reference in New Issue
Block a user