]> git.pld-linux.org Git - packages/SysVinit.git/blob - sysvinit-selinux.patch
- new patches
[packages/SysVinit.git] / sysvinit-selinux.patch
1 --- sysvinit-2.85/src/Makefile.selinux  2003-12-18 10:59:15.000000000 -0500
2 +++ sysvinit-2.85/src/Makefile  2003-12-18 10:59:15.000000000 -0500
3 @@ -32,7 +32,7 @@
4  all:           $(PROGS)
5  
6  init:          init.o init_utmp.o
7 -               $(CC) $(LDFLAGS) $(STATIC) -o $@ init.o init_utmp.o
8 +               $(CC) $(LDFLAGS) $(STATIC) -o $@ init.o init_utmp.o -lselinux
9  
10  halt:          halt.o ifdown.o hddown.o utmp.o reboot.h
11                 $(CC) $(LDFLAGS) -o $@ halt.o ifdown.o hddown.o utmp.o
12 @@ -62,7 +62,7 @@
13                 $(CC) $(LDFLAGS) -o $@ bootlogd.o
14  
15  init.o:                init.c init.h set.h reboot.h
16 -               $(CC) -c $(CFLAGS) init.c
17 +               $(CC) -c $(CFLAGS) -DWITH_SELINUX init.c
18  
19  utmp.o:                utmp.c init.h
20                 $(CC) -c $(CFLAGS) utmp.c
21 --- sysvinit-2.85/src/init.c.selinux    2003-12-18 10:59:15.000000000 -0500
22 +++ sysvinit-2.85/src/init.c    2003-12-18 11:01:06.000000000 -0500
23 @@ -78,6 +78,81 @@
24                         sigemptyset(&sa.sa_mask); \
25                         sigaction(sig, &sa, NULL); \
26                 } while(0)
27 +#ifdef WITH_SELINUX
28 +#include <sys/mman.h>
29 +#include <selinux/selinux.h>
30 +#include <sys/mount.h>
31 +
32 +static int load_policy(int *enforce) 
33 +{
34 +  int fd=-1,ret=-1;
35 +  int rc=0;
36 +  struct stat sb;
37 +  void *map;
38 +  char policy_file[PATH_MAX];
39 +  int policy_version=0;
40 +  extern char *selinux_mnt;
41 +
42 +  log(L_VB, "Loading security policy\n");
43 +  if (mount("none", SELINUXMNT, "selinuxfs", 0, 0) < 0) {
44 +    if (errno == ENODEV) {
45 +      log(L_VB, "SELinux not supported by kernel: %s\n",SELINUXMNT,strerror(errno));
46 +    } 
47 +    else {
48 +      log(L_VB, "Failed to mount %s: %s\n",SELINUXMNT,strerror(errno));
49 +      return ret;
50 +    }
51 +    return ret; /* Never gets here */
52 +  }
53 +
54 +  selinux_mnt = SELINUXMNT; /* set manually since we mounted it */
55 +
56 +  policy_version=security_policyvers();
57 +  if (policy_version < 0) {
58 +    log(L_VB,  "Can't get policy version: %s\n", strerror(errno));
59 +    goto UMOUNT;
60 +  }
61 +  
62 +  rc=security_getenforce();
63 +  if (rc < 0) {
64 +    log(L_VB,  "Can't get SELinux enforcement flag: %s\n", strerror(errno));
65 +    goto UMOUNT;
66 +  } 
67 +  *enforce=rc;
68 +
69 +  snprintf(policy_file,sizeof(policy_file),"%s.%d",SELINUXPOLICY,policy_version);
70 +  fd = open(policy_file, O_RDONLY);
71 +  if (fd < 0) {
72 +    log(L_VB,  "Can't open '%s':  %s\n",
73 +           policy_file, strerror(errno));
74 +    goto UMOUNT;
75 +  }
76 +  
77 +  if (fstat(fd, &sb) < 0) {
78 +    log(L_VB, "Can't stat '%s':  %s\n",
79 +           policy_file, strerror(errno));
80 +    goto UMOUNT;
81 +  }
82 +  
83 +  map = mmap(NULL, sb.st_size, PROT_READ, MAP_SHARED, fd, 0);
84 +  if (map == MAP_FAILED) {
85 +    log(L_VB,  "Can't map '%s':  %s\n",
86 +           policy_file, strerror(errno));
87 +    goto UMOUNT;
88 +  }
89 +  ret=security_load_policy(map, sb.st_size);
90 +  if (ret < 0) {
91 +    log(L_VB, "security_load_policy failed\n");
92 +  }
93 +
94 + UMOUNT:
95 +  /*umount(SELINUXMNT); */
96 +  if ( fd >= 0) {
97 +    close(fd);
98 +  }
99 +  return(ret);
100 +}
101 +#endif
102  
103  /* Version information */
104  char *Version = "@(#) init " VERSION "  " DATE "  miquels@cistron.nl";
105 @@ -2576,6 +2651,20 @@
106                 maxproclen += strlen(argv[f]) + 1;
107         }
108  
109 +#ifdef WITH_SELINUX
110 +       if (getenv("SELINUX_INIT") == NULL) {
111 +         putenv("SELINUX_INIT=YES");
112 +         int enforce=0;
113 +         if (load_policy(&enforce) == 0 ) {
114 +           execv(myname, argv);
115 +         } else {
116 +           if (enforce) 
117 +             /* SELinux in enforcing mode but load_policy failed */
118 +             exit(1);
119 +         }
120 +       }
121 +#endif
122 +  
123         /* Start booting. */
124         argv0 = argv[0];
125         argv[1] = NULL;
126 --- sysvinit-2.85/src/killall5.c.selinux        2003-12-18 10:59:15.000000000 -0500
127 +++ sysvinit-2.85/src/killall5.c        2003-12-22 17:25:56.959018239 -0500
128 @@ -144,8 +144,11 @@
129  
130  /*
131   *     Read the proc filesystem.
132 + *      since pidOf does not use process sid added a needSid flag to eliminate
133 + *     the need of this privs for SELinux
134 + *
135   */
136 -int readproc()
137 +int readproc(int needSid)
138  {
139         DIR *dir;
140         struct dirent *d;
141 @@ -221,12 +224,16 @@
142                         free(p);
143                         continue;
144                 }
145 -               p->sid = getsid(pid);
146 -               if (p->sid < 0) {
147 -                       p->sid = 0;
148 -                       nsyslog(LOG_ERR, "can't read sid for pid %d\n", pid);
149 -                       free(p);
150 -                       continue;
151 +               if (needSid) {
152 +                 p->sid = getsid(pid);
153 +                 if (p->sid < 0) {
154 +                   p->sid = 0;
155 +                   nsyslog(LOG_ERR, "can't read sid for pid %d\n", pid);
156 +                   free(p);
157 +                   continue;
158 +                 }
159 +               } else {
160 +                   p->sid = 0;
161                 }
162  
163                 /* Now read argv[0] */
164 @@ -463,7 +470,7 @@
165         argv += optind;
166  
167         /* Print out process-ID's one by one. */
168 -       readproc();
169 +       readproc(0);
170         for(f = 0; f < argc; f++) {
171                 if ((q = pidof(argv[f])) != NULL) {
172                         spid = 0;
173 @@ -544,7 +551,7 @@
174         stopped = 1;
175  
176         /* Find out our own 'sid'. */
177 -       if (readproc() < 0) {
178 +       if (readproc(1) < 0) {
179                 kill(-1, SIGCONT);
180                 exit(1);
181         }
This page took 0.081728 seconds and 3 git commands to generate.