Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!iuvax!cica!tut.cis.ohio-state.edu!zaphod.mps.ohio-state.edu!usc!snorkelwacker!bloom-beacon!prg.oxford.ac.UK!Mark.Bush From: Mark.Bush@prg.oxford.ac.UK Newsgroups: comp.windows.x Subject: Re: How to get xdm to make wtmp and utmp file entries? Message-ID: <9006111454.AA13186@uk.ac.oxford.prg.boothp1> Date: 11 Jun 90 14:54:50 GMT Sender: root@athena.mit.edu (Wizard A. Root) Organization: The Internet Lines: 124 I've had a few requests for my xlogin/xlogout programs so I thought I'd include them here---I didn't think it was worth posting them to comp.sources.x. We have a network of Sun workstations here (no x-terminals or anything) so I no longer use xdm or these programs to run X sessions but get users to invoke startx. WARNING: These programs assume that the console entry in the utmp file is the second slot. I was only using these programs on my machine and I could guarantee that the first utmp slot was all NULLs and the second was the console slot. To make them more general, ttyslot() should be used. I think they will only run on Suns as they are (though they may well run on general BSD4.{2,3} boxes). DISCLAIMER: These programs are supplied `as is' and without warranty. I accept no responsibility for any problems/errors/faults that may occur due to their use. If you want to take these programs and change them and/or distribute them then feel free. I wrote these one afternoon as a hack so they are not exactly elegant and I don't claim that they will always work so, please, no flames. Share and enjoy, Mark ------------------------------------------------------------------------------- /* * xlogin.c * Mark Bush * Mark.Bush@uk.ac.oxford.prg */ #include #include #include main(argc, argv) int argc; char *argv[]; { char *p; FILE *ufp, *wfp; struct utmp ut; int i, length; if ((ufp = fopen("/etc/utmp", "r+")) == NULL || (wfp = fopen("/usr/adm/wtmp", "a")) == NULL) { perror("Can't log login."); exit(1); } length = strlen(argv[1]); length = (length>8 ? 8 : length); fseek(ufp, (long)36, 0); /* Go to second slot */ p = (char *)&ut; for (i=0; i<36; i++) *p++ = getc(ufp); fseek(ufp, (long)-36, 1); sprintf(ut.ut_name, "\0\0\0\0\0\0\0\0"); for (i=0; i #include #include main(argc, argv) int argc; char *argv[]; { char *p; FILE *ufp, *wfp; struct utmp ut; int i; if ((ufp = fopen("/etc/utmp", "r+")) == NULL || (wfp = fopen("/usr/adm/wtmp", "a")) == NULL) { perror("Can't log logout."); exit(1); } fseek(ufp, (long)36, 0); /* Go to second slot */ p = (char *)&ut; for (i=0; i<36; i++) *p++ = getc(ufp); fseek(ufp, (long)-36, 1); sprintf(ut.ut_name, "\0\0\0\0\0\0\0\0"); ut.ut_time = time(0); sprintf(ut.ut_host, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"); p = (char *)&ut; for (i=0; i<36; i++) { putc('\0', ufp); putc(*p++, wfp); } fclose(ufp); fclose(wfp); } -------------------------------------------------------------------------------