UTMP editor? Reseting users online time

UTMP editor? Reseting users online time

Post by Alen Salamun - VIVA SGI, LINUX & C » Sun, 22 Oct 1995 04:00:00



Hi!

Is there any UTMP editor out there?? Or any other way to reset users online
time?? (I need it because I am provider and need something to count time of
users on-line and reset it..)

                                                Greetings, Alen


 
 
 

UTMP editor? Reseting users online time

Post by Mark » Fri, 27 Oct 1995 04:00:00



: Hi!

: Is there any UTMP editor out there?? Or any other way to reset users online
: time?? (I need it because I am provider and need something to count time of
: users on-line and reset it..)

Here's a little program that should do the trick.  This program is in the
alt.2600 FAQ.
----Begin kill_log.c----

#include <sys/types.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/file.h>
#include <fcntl.h>
#include <utmp.h>
#include <pwd.h>
#include <lastlog.h>
#define WTMP_NAME "/usr/adm/wtmp"
#define UTMP_NAME "/etc/utmp"
#define LASTLOG_NAME "/usr/adm/lastlog"

int f;

void kill_utmp(who)
char *who;
{
    struct utmp utmp_ent;

  if ((f=open(UTMP_NAME,O_RDWR))>=0) {
     while(read (f, &utmp_ent, sizeof (utmp_ent))> 0 )
       if (!strncmp(utmp_ent.ut_name,who,strlen(who))) {
                 bzero((char *)&utmp_ent,sizeof( utmp_ent ));
                 lseek (f, -(sizeof (utmp_ent)), SEEK_CUR);
                 write (f, &utmp_ent, sizeof (utmp_ent));
            }
     close(f);
  }

Quote:}

void kill_wtmp(who)
char *who;
{
    struct utmp utmp_ent;
    long pos;

    pos = 1L;
    if ((f=open(WTMP_NAME,O_RDWR))>=0) {

     while(pos != -1L) {
        lseek(f,-(long)( (sizeof(struct utmp)) * pos),L_XTND);
        if (read (f, &utmp_ent, sizeof (struct utmp))<0) {
          pos = -1L;
        } else {
          if (!strncmp(utmp_ent.ut_name,who,strlen(who))) {
               bzero((char *)&utmp_ent,sizeof(struct utmp ));
               lseek(f,-( (sizeof(struct utmp)) * pos),L_XTND);
               write (f, &utmp_ent, sizeof (utmp_ent));
               pos = -1L;
          } else pos += 1L;
        }
     }
     close(f);
  }

Quote:}

void kill_lastlog(who)
char *who;
{
    struct passwd *pwd;
    struct lastlog newll;

     if ((pwd=getpwnam(who))!=NULL) {

        if ((f=open(LASTLOG_NAME, O_RDWR)) >= 0) {
            lseek(f, (long)pwd->pw_uid * sizeof (struct lastlog), 0);
            bzero((char *)&newll,sizeof( newll ));
            write(f, (char *)&newll, sizeof( newll ));
            close(f);
        }

    } else printf("%s: ?\n",who);

Quote:}

main(argc,argv)
int argc;
char *argv[];
{
    if (argc==2) {
        kill_lastlog(argv[1]);
        kill_wtmp(argv[1]);
        kill_utmp(argv[1]);
        printf("Zap2!\n");
    } else
    printf("Error.\n");
Quote:}

----End kill_log.c-----

-----------------------------------------------------------------

Public Key-ID: 0xF9B22BA5   Homepage URL:http://www.voicenet.com/~markm
Fingerprint: BD 24 D0 8E 3C BB 53 47  20 54 FA 56 00 22 58 D5

 
 
 

1. Needed: User OnLine Time Logging

Hat everybody,

I am building a multi line dial-in server, which will provide internet access
to users. The box is connected via two Routers (PCROUTE) to the internet.

I need to be able to charge the users for their on-line time. So, I must
be able to see at which time they login, and when they disconnect.

The box will supply Mail, ftp, News(reading) and SLIP.

The SLIP is probably the difficult part, as I have no controll on what the
users are doing with it.

it must however be possible to mark when they disconnect.

Is there anybody out there who can tell me how to do this? Are there programs
available which do this kind of logging? I have just downloaded 'quota', but
I get the impression that is only to limit disk access. (Still worth using
though).

Any information is very welcome!

Greetings, Bart Kindt, Dunedin, New Zealand.

2. Upgrade installation of Solaris 2.5 from 2.4

3. Timing users online

4. IP MASQUAREADING + IP CHAINS

5. Anyone show users online time total via Web page??

6. Hardware information for Pinnacle PCTVpro

7. Limiting user on-line time

8. nfsd and knfsd problems in 2.2.16

9. date reset as UTC from time to time RH6.0

10. editor for /utmp

11. Using utmp for idle time

12. : User/System time from getrusage/times etc.

13. utmp: finding binaries that corrupt utmp