]> git.pld-linux.org Git - packages/libutempter.git/blob - utempter-utmp-cleanup.patch
- use modern chown syntax, cosmetics
[packages/libutempter.git] / utempter-utmp-cleanup.patch
1 diff -urN utempter-0.5.3.org/Makefile utempter-0.5.3/Makefile
2 --- utempter-0.5.3.org/Makefile 2003-12-18 23:33:32.081092612 +0100
3 +++ utempter-0.5.3/Makefile     2003-12-18 23:34:17.941588864 +0100
4 @@ -11,12 +11,12 @@
5  
6  CFLAGS = -Wall $(RPM_OPT_FLAGS)
7  
8 -TARGETS = $(NAME) utmp $(SHAREDLIB)
9 +TARGETS = $(NAME) utmp $(SHAREDLIB) utmp-cleanup
10  
11  all:   $(TARGETS)
12  
13  clean:
14 -       rm -f *.so utempter utmp *.os
15 +       rm -f *.so utempter utmp *.os utmp-cleanup
16  
17  %.os : %.c
18         $(CC) -c $(CFLAGS) -fPIC $< -o $@
19 @@ -26,6 +26,7 @@
20         mkdir -p $(RPM_BUILD_ROOT)/$(LIBDIR)
21         mkdir -p $(RPM_BUILD_ROOT)/usr/include
22         install -m 4755 utempter $(RPM_BUILD_ROOT)/usr/sbin
23 +       install -m 755 utmp-cleanup $(RPM_BUILD_ROOT)/usr/sbin
24         install -m 644 utempter.h $(RPM_BUILD_ROOT)/usr/include
25         install -m 644 $(SHAREDLIB) $(RPM_BUILD_ROOT)/$(LIBDIR)/$(SHAREDLIB).$(VERSION)
26         ln -sf $(SHAREDLIB).$(VERSION) $(RPM_BUILD_ROOT)/$(LIBDIR)/$(SHAREDLIB)
27 diff -urN utempter-0.5.3.org/utmp-cleanup.c utempter-0.5.3/utmp-cleanup.c
28 --- utempter-0.5.3.org/utmp-cleanup.c   1970-01-01 01:00:00.000000000 +0100
29 +++ utempter-0.5.3/utmp-cleanup.c       2003-12-18 23:33:51.996966369 +0100
30 @@ -0,0 +1,69 @@
31 +#include <unistd.h>
32 +#include <fcntl.h>
33 +#include <stdio.h>
34 +#include <utmp.h>
35 +#include <sys/stat.h>
36 +#include <sys/types.h>
37 +#include <pwd.h>
38 +
39 +int check_entry(struct utmp * ut)
40 +{
41 +char buf[100];
42 +struct stat st;
43 +struct passwd * pwd;
44 +int s;
45 +
46 +pwd=getpwnam(ut->ut_user);
47 +       if(!pwd)return 1;
48 +                       
49 +snprintf(buf,100,"/proc/%d/",ut->ut_pid);
50 +s=stat(buf,&st);
51 +       if(s)return 2;
52 +
53 +       if(st.st_uid!=pwd->pw_uid && st.st_uid!=0)return 3;
54 +return 0;
55 +}
56 +
57 +char * msgs[]={"","Nonexistent user","Dead process","Owner mismatch"};
58 +
59 +int main(int ac, char ** av)
60 +{
61 +int clean=1;
62 +int justcheck=0;
63 +int fd;
64 +char * file="/var/run/utmpx";
65 +       if(ac>1)file=av[1];
66 +fd=open(file,O_RDWR,0);
67 +       if(fd<0){
68 +       fd=open(file,O_RDONLY,0);
69 +       justcheck=1;
70 +       printf("Warning: opening %s read-only\n",file);
71 +       }
72 +       
73 +       if(fd<0){
74 +       perror("open"); exit(1);
75 +       }
76 +
77 +       while(1){
78 +       struct utmp ut;
79 +       int r=read(fd,&ut,sizeof(ut));
80 +               if(r!=sizeof(ut))break;
81 +       
82 +               if(ut.ut_type==USER_PROCESS){
83 +               int i;  
84 +                       if((i=check_entry(&ut))){
85 +                       clean=0;
86 +                       printf("%s: %d (%s)\n",msgs[i],ut.ut_pid,ut.ut_name);
87 +                       if(justcheck)continue;
88 +                       lseek(fd,-sizeof(ut),SEEK_CUR);
89 +                       bzero(&ut,sizeof(ut));
90 +                       ut.ut_type=DEAD_PROCESS;
91 +                       write(fd,&ut,sizeof(ut));
92 +                       }
93 +               }
94 +               
95 +       }
96 +
97 +       if(clean)printf("%s is clean\n",file);
98 +return 0;
99 +}
This page took 0.05509 seconds and 3 git commands to generate.