aboutsummaryrefslogtreecommitdiff
path: root/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/utmp_do.c
diff options
context:
space:
mode:
Diffstat (limited to 'riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/utmp_do.c')
-rw-r--r--riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/utmp_do.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/utmp_do.c b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/utmp_do.c
new file mode 100644
index 0000000..c820b42
--- /dev/null
+++ b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/utmp_do.c
@@ -0,0 +1,53 @@
+#include <unistd.h>
+#include <fcntl.h>
+#include <time.h>
+#include <sys/stat.h>
+#include "utmp_defs.h"
+#include "str_defs.h"
+
+#define SD(A,B) !str_diffn(A, B, sizeof(A))
+#define SC(A,B) str_copynz(A, B, sizeof(A))
+
+void utmp_do(char *username, char *line, int pid) /*EXTRACT_INCL*/{
+ off_t pos=0;
+ struct utmp u;
+ char *p;
+ int fd=open(_PATH_UTMP,O_RDWR);
+
+ while (utmp_io(fd, &u,F_RDLCK)) {
+ if (u.ut_pid == pid || SD(u.ut_line, line)) goto foundone;
+ pos += UTMP_SIZE;
+ }
+
+ byte_zero(&u,sizeof(u));
+ pos = lseek(fd,0,SEEK_END);
+ if (pos<0) pos =0;
+ pos = pos - (pos % (UTMP_SIZE));
+
+ foundone:
+ if (u.ut_id[0]==0) {
+ p=line;
+ while (str_len(p) > sizeof u.ut_id) p++;
+ SC(u.ut_id, p);
+ }
+ SC(u.ut_line, line);
+
+ SC(u.ut_user,username);
+ u.ut_type=USER_PROCESS;
+ u.ut_pid=pid;
+
+ byte_zero(u.ut_host,sizeof u.ut_host);
+ u.ut_tv.tv_sec = time(0);
+
+ if (fd>=0) {
+ if (lseek(fd,pos,SEEK_SET) == pos)
+ utmp_io(fd,&u,F_WRLCK);
+ close(fd);
+ }
+
+ fd=open(_PATH_WTMP, O_WRONLY|O_APPEND);
+ if (fd>=0) {
+ write(fd, &u, UTMP_SIZE);
+ close(fd);
+ }
+}