diff -urN utempter-0.5.3.org/Makefile utempter-0.5.3/Makefile --- utempter-0.5.3.org/Makefile 2003-12-18 23:33:32.081092612 +0100 +++ utempter-0.5.3/Makefile 2003-12-18 23:34:17.941588864 +0100 @@ -11,12 +11,12 @@ CFLAGS = -Wall $(RPM_OPT_FLAGS) -TARGETS = $(NAME) utmp $(SHAREDLIB) +TARGETS = $(NAME) utmp $(SHAREDLIB) utmp-cleanup all: $(TARGETS) clean: - rm -f *.so utempter utmp *.os + rm -f *.so utempter utmp *.os utmp-cleanup %.os : %.c $(CC) -c $(CFLAGS) -fPIC $< -o $@ @@ -26,6 +26,7 @@ mkdir -p $(RPM_BUILD_ROOT)/$(LIBDIR) mkdir -p $(RPM_BUILD_ROOT)/usr/include install -m 4755 utempter $(RPM_BUILD_ROOT)/usr/sbin + install -m 755 utmp-cleanup $(RPM_BUILD_ROOT)/usr/sbin install -m 644 utempter.h $(RPM_BUILD_ROOT)/usr/include install -m 644 $(SHAREDLIB) $(RPM_BUILD_ROOT)/$(LIBDIR)/$(SHAREDLIB).$(VERSION) ln -sf $(SHAREDLIB).$(VERSION) $(RPM_BUILD_ROOT)/$(LIBDIR)/$(SHAREDLIB) diff -urN utempter-0.5.3.org/utmp-cleanup.c utempter-0.5.3/utmp-cleanup.c --- utempter-0.5.3.org/utmp-cleanup.c 1970-01-01 01:00:00.000000000 +0100 +++ utempter-0.5.3/utmp-cleanup.c 2003-12-18 23:33:51.996966369 +0100 @@ -0,0 +1,69 @@ +#include +#include +#include +#include +#include +#include +#include + +int check_entry(struct utmp * ut) +{ +char buf[100]; +struct stat st; +struct passwd * pwd; +int s; + +pwd=getpwnam(ut->ut_user); + if(!pwd)return 1; + +snprintf(buf,100,"/proc/%d/",ut->ut_pid); +s=stat(buf,&st); + if(s)return 2; + + if(st.st_uid!=pwd->pw_uid && st.st_uid!=0)return 3; +return 0; +} + +char * msgs[]={"","Nonexistent user","Dead process","Owner mismatch"}; + +int main(int ac, char ** av) +{ +int clean=1; +int justcheck=0; +int fd; +char * file="/var/run/utmpx"; + if(ac>1)file=av[1]; +fd=open(file,O_RDWR,0); + if(fd<0){ + fd=open(file,O_RDONLY,0); + justcheck=1; + printf("Warning: opening %s read-only\n",file); + } + + if(fd<0){ + perror("open"); exit(1); + } + + while(1){ + struct utmp ut; + int r=read(fd,&ut,sizeof(ut)); + if(r!=sizeof(ut))break; + + if(ut.ut_type==USER_PROCESS){ + int i; + if((i=check_entry(&ut))){ + clean=0; + printf("%s: %d (%s)\n",msgs[i],ut.ut_pid,ut.ut_name); + if(justcheck)continue; + lseek(fd,-sizeof(ut),SEEK_CUR); + bzero(&ut,sizeof(ut)); + ut.ut_type=DEAD_PROCESS; + write(fd,&ut,sizeof(ut)); + } + } + + } + + if(clean)printf("%s is clean\n",file); +return 0; +}