]> git.pld-linux.org Git - packages/libutempter.git/blob - libutempter-utmp-cleanup.patch
- rel 1; fixes from Adam Osuchowski
[packages/libutempter.git] / libutempter-utmp-cleanup.patch
1 --- libutempter-1.1.5/Makefile~ 2007-02-19 13:14:08.000000000 +0100
2 +++ libutempter-1.1.5/Makefile  2010-09-21 14:16:43.025917709 +0200
3 @@ -27,7 +27,7 @@
4  STATICLIB = lib$(PROJECT).a
5  MAP = lib$(PROJECT).map
6  
7 -TARGETS = $(PROJECT) $(SHAREDLIB) $(STATICLIB)
8 +TARGETS = $(PROJECT) $(SHAREDLIB) $(STATICLIB) utmp-cleanup
9  
10  INSTALL = install
11  libdir = /usr/lib
12 @@ -70,8 +70,9 @@
13         $(INSTALL) -p -m644 $(PROJECT).h $(DESTDIR)$(includedir)/
14         $(INSTALL) -p -m755 $(SHAREDLIB) $(DESTDIR)$(libdir)/$(SHAREDLIB).$(VERSION)
15         $(INSTALL) -p -m644 $(STATICLIB) $(DESTDIR)$(libdir)/
16 +       $(INSTALL) -p -m755 utmp-cleanup $(DESTDIR)$(libexecdir)/$(PROJECT)/
17         ln -s $(SHAREDLIB).$(VERSION) $(DESTDIR)$(libdir)/$(SONAME)
18         ln -s $(SONAME) $(DESTDIR)$(libdir)/$(SHAREDLIB)
19  
20  clean:
21 -       $(RM) $(TARGETS) iface.o iface.os core *~
22 +       $(RM) $(TARGETS) iface.o iface.os core *~ utmp-cleanup
23 diff -urN utempter-0.5.3.org/utmp-cleanup.c utempter-0.5.3/utmp-cleanup.c
24 --- utempter-0.5.3.org/utmp-cleanup.c   1970-01-01 01:00:00.000000000 +0100
25 +++ utempter-0.5.3/utmp-cleanup.c       2003-12-18 23:33:51.996966369 +0100
26 @@ -0,0 +1,69 @@
27 +#include <unistd.h>
28 +#include <fcntl.h>
29 +#include <stdio.h>
30 +#include <utmp.h>
31 +#include <sys/stat.h>
32 +#include <sys/types.h>
33 +#include <pwd.h>
34 +
35 +int check_entry(struct utmp * ut)
36 +{
37 +char buf[100];
38 +struct stat st;
39 +struct passwd * pwd;
40 +int s;
41 +
42 +pwd=getpwnam(ut->ut_user);
43 +       if(!pwd)return 1;
44 +                       
45 +snprintf(buf,100,"/proc/%d/",ut->ut_pid);
46 +s=stat(buf,&st);
47 +       if(s)return 2;
48 +
49 +       if(st.st_uid!=pwd->pw_uid && st.st_uid!=0)return 3;
50 +return 0;
51 +}
52 +
53 +char * msgs[]={"","Nonexistent user","Dead process","Owner mismatch"};
54 +
55 +int main(int ac, char ** av)
56 +{
57 +int clean=1;
58 +int justcheck=0;
59 +int fd;
60 +char * file="/var/run/utmpx";
61 +       if(ac>1)file=av[1];
62 +fd=open(file,O_RDWR,0);
63 +       if(fd<0){
64 +       fd=open(file,O_RDONLY,0);
65 +       justcheck=1;
66 +       printf("Warning: opening %s read-only\n",file);
67 +       }
68 +       
69 +       if(fd<0){
70 +       perror("open"); exit(1);
71 +       }
72 +
73 +       while(1){
74 +       struct utmp ut;
75 +       int r=read(fd,&ut,sizeof(ut));
76 +               if(r!=sizeof(ut))break;
77 +       
78 +               if(ut.ut_type==USER_PROCESS){
79 +               int i;  
80 +                       if((i=check_entry(&ut))){
81 +                       clean=0;
82 +                       printf("%s: %d (%s)\n",msgs[i],ut.ut_pid,ut.ut_name);
83 +                       if(justcheck)continue;
84 +                       lseek(fd,-sizeof(ut),SEEK_CUR);
85 +                       bzero(&ut,sizeof(ut));
86 +                       ut.ut_type=DEAD_PROCESS;
87 +                       write(fd,&ut,sizeof(ut));
88 +                       }
89 +               }
90 +               
91 +       }
92 +
93 +       if(clean)printf("%s is clean\n",file);
94 +return 0;
95 +}
This page took 0.049093 seconds and 3 git commands to generate.