Bug 2798 - utmp support for *BSD systems
Summary: utmp support for *BSD systems
Status: RESOLVED FIXED
Alias: None
Product: Samba 3.0
Classification: Unclassified
Component: File Services (show other bugs)
Version: 3.0.9
Hardware: All OpenBSD
: P3 enhancement
Target Milestone: none
Assignee: Samba Bugzilla Account
QA Contact: Samba QA Contact
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-06-14 10:42 UTC by mickey (dead mail address)
Modified: 2020-12-20 17:48 UTC (History)
0 users

See Also:


Attachments
support for utmp on bsd systems (1.57 KB, patch)
2005-06-14 10:49 UTC, mickey (dead mail address)
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description mickey (dead mail address) 2005-06-14 10:42:19 UTC
currently there is no implementation for utmp support
for any of the BSD systems as they do not have any of
the bloated APIs from other OSs:
static void pututline_my(pstring uname, struct utmp *u, BOOL claim)
{
       DEBUG(1,("pututline_my: not yet implemented\n"));
       /* BSD implementor: may want to consider (or not) adjusting "lastlog" */
}


here is the patch that implements it (the bsd-way) ripped
of the openbsd's ftpd:

--- utmp.c      Thu Aug 12 14:24:20 2004
+++ /home/mickey/utmp.c Wed Mar 30 15:51:40 2005
@@ -261,6 +261,7 @@
 }
 
 #ifndef HAVE_PUTUTLINE
+#include <ttyent.h>
 
 /****************************************************************************
  Update utmp file directly.  No subroutine interface: probably a BSD system.
@@ -268,8 +269,50 @@
 
 static void pututline_my(pstring uname, struct utmp *u, BOOL claim)
 {
-       DEBUG(1,("pututline_my: not yet implemented\n"));
-       /* BSD implementor: may want to consider (or not) adjusting "lastlog" */
+       int fd, topslot;
+       struct utmp ubuf;
+
+       if ((fd = open(uname, O_RDWR, 0)) < 0)
+               return;
+
+       if (!setttyent())
+               return;
+
+       for (topslot = 0; getttyent() != (struct ttyent *)NULL; )
+               topslot++;
+
+       if (!endttyent())
+               return;
+
+       (void) lseek(fd, (off_t)(topslot * sizeof(struct utmp)), SEEK_SET);
+
+       DEBUG(1,("pututline(%s, %s, %d); topslot=%d\n",
+           u->ut_line, u->ut_name, claim, topslot));
+
+       while (1) {
+               if (read(fd, &ubuf, sizeof(ubuf)) == sizeof(ubuf)) {
+                       if ((claim && !ubuf.ut_name[0]) ||
+                           (!claim && ubuf.ut_name[0] &&
+                            !strncmp(ubuf.ut_line, u->ut_line, UT_LINESIZE))) {
+                               (void) lseek(fd, -(off_t)sizeof(struct utmp),
+                                   SEEK_CUR);
+                               break;
+                       }
+                       topslot++;
+               } else {
+                       (void) lseek(fd, (off_t)(topslot *
+                           sizeof(struct utmp)), SEEK_SET);
+                       break;
+               }
+       }
+
+       if (! claim) {
+               memset((char *)&u->ut_name, '\0', sizeof(u->ut_name));
+               memset((char *)&u->ut_host, '\0', sizeof(u->ut_host));
+       }
+       (void) write(fd, u, sizeof(struct utmp));
+
+       (void) close(fd);
 }
 #endif /* HAVE_PUTUTLINE */
Comment 1 mickey (dead mail address) 2005-06-14 10:49:53 UTC
Created attachment 1273 [details]
support for utmp on bsd systems
Comment 2 Björn Jacke 2020-12-20 17:48:22 UTC
freebsd has utmpx.h these days, which we support