/[pkgs]/rpms/openssh/devel/openssh-5.2p1-selinux.patch
ViewVC logotype

Contents of /rpms/openssh/devel/openssh-5.2p1-selinux.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (show annotations) (download) (as text)
Mon Aug 31 12:38:20 2009 UTC (2 months, 3 weeks ago) by jfch2222
Branch: MAIN
CVS Tags: openssh-5_2p1-28_fc12, F-12-split, openssh-5_2p1-24_fc12, openssh-5_2p1-27_fc12, openssh-5_2p1-26_fc12, openssh-5_2p1-23_fc12, openssh-5_2p1-22_fc12, openssh-5_3p1-2_fc13, openssh-5_3p1-8_fc13, openssh-5_2p1-21_fc12, openssh-5_3p1-10_fc13, openssh-5_2p1-25_fc12, openssh-5_3p1-9_fc13, openssh-5_3p1-7_fc13, openssh-5_3p1-1_fc13, openssh-5_3p1-3_fc13, openssh-5_3p1-4_fc13, openssh-5_3p1-5_fc13, openssh-5_3p1-6_fc13, openssh-5_2p1-29_fc13, HEAD
Changes since 1.3: +261 -228 lines
File MIME type: text/x-patch
Upstream convergence
1 diff -up openssh-5.2p1/auth1.c.selinux openssh-5.2p1/auth1.c
2 --- openssh-5.2p1/auth1.c.selinux 2008-07-09 12:54:05.000000000 +0200
3 +++ openssh-5.2p1/auth1.c 2009-08-11 22:43:07.918183730 +0200
4 @@ -392,6 +392,9 @@ do_authentication(Authctxt *authctxt)
5 {
6 u_int ulen;
7 char *user, *style = NULL;
8 +#ifdef WITH_SELINUX
9 + char *role=NULL;
10 +#endif
11
12 /* Get the name of the user that we wish to log in as. */
13 packet_read_expect(SSH_CMSG_USER);
14 @@ -400,11 +403,25 @@ do_authentication(Authctxt *authctxt)
15 user = packet_get_string(&ulen);
16 packet_check_eom();
17
18 +#ifdef WITH_SELINUX
19 + if ((role = strchr(user, '/')) != NULL)
20 + *role++ = '\0';
21 +#endif
22 +
23 if ((style = strchr(user, ':')) != NULL)
24 *style++ = '\0';
25 +#ifdef WITH_SELINUX
26 + else
27 + if (role && (style = strchr(role, ':')) != NULL)
28 + *style++ = '\0';
29 +#endif
30 +
31
32 authctxt->user = user;
33 authctxt->style = style;
34 +#ifdef WITH_SELINUX
35 + authctxt->role = role;
36 +#endif
37
38 /* Verify that the user is a valid user. */
39 if ((authctxt->pw = PRIVSEP(getpwnamallow(user))) != NULL)
40 diff -up openssh-5.2p1/auth2.c.selinux openssh-5.2p1/auth2.c
41 --- openssh-5.2p1/auth2.c.selinux 2008-11-05 06:20:46.000000000 +0100
42 +++ openssh-5.2p1/auth2.c 2009-08-11 22:43:07.919756192 +0200
43 @@ -216,6 +216,9 @@ input_userauth_request(int type, u_int32
44 Authctxt *authctxt = ctxt;
45 Authmethod *m = NULL;
46 char *user, *service, *method, *style = NULL;
47 +#ifdef WITH_SELINUX
48 + char *role = NULL;
49 +#endif
50 int authenticated = 0;
51
52 if (authctxt == NULL)
53 @@ -227,6 +230,11 @@ input_userauth_request(int type, u_int32
54 debug("userauth-request for user %s service %s method %s", user, service, method);
55 debug("attempt %d failures %d", authctxt->attempt, authctxt->failures);
56
57 +#ifdef WITH_SELINUX
58 + if ((role = strchr(user, '/')) != NULL)
59 + *role++ = 0;
60 +#endif
61 +
62 if ((style = strchr(user, ':')) != NULL)
63 *style++ = 0;
64
65 @@ -252,8 +260,15 @@ input_userauth_request(int type, u_int32
66 use_privsep ? " [net]" : "");
67 authctxt->service = xstrdup(service);
68 authctxt->style = style ? xstrdup(style) : NULL;
69 - if (use_privsep)
70 +#ifdef WITH_SELINUX
71 + authctxt->role = role ? xstrdup(role) : NULL;
72 +#endif
73 + if (use_privsep) {
74 mm_inform_authserv(service, style);
75 +#ifdef WITH_SELINUX
76 + mm_inform_authrole(role);
77 +#endif
78 + }
79 userauth_banner();
80 } else if (strcmp(user, authctxt->user) != 0 ||
81 strcmp(service, authctxt->service) != 0) {
82 diff -up openssh-5.2p1/auth2-gss.c.selinux openssh-5.2p1/auth2-gss.c
83 --- openssh-5.2p1/auth2-gss.c.selinux 2007-12-02 12:59:45.000000000 +0100
84 +++ openssh-5.2p1/auth2-gss.c 2009-08-11 22:43:07.921723295 +0200
85 @@ -258,6 +258,7 @@ input_gssapi_mic(int type, u_int32_t ple
86 Authctxt *authctxt = ctxt;
87 Gssctxt *gssctxt;
88 int authenticated = 0;
89 + char *micuser;
90 Buffer b;
91 gss_buffer_desc mic, gssbuf;
92 u_int len;
93 @@ -270,7 +271,13 @@ input_gssapi_mic(int type, u_int32_t ple
94 mic.value = packet_get_string(&len);
95 mic.length = len;
96
97 - ssh_gssapi_buildmic(&b, authctxt->user, authctxt->service,
98 +#ifdef WITH_SELINUX
99 + if (authctxt->role && (strlen(authctxt->role) > 0))
100 + xasprintf(&micuser, "%s/%s", authctxt->user, authctxt->role);
101 + else
102 +#endif
103 + micuser = authctxt->user;
104 + ssh_gssapi_buildmic(&b, micuser, authctxt->service,
105 "gssapi-with-mic");
106
107 gssbuf.value = buffer_ptr(&b);
108 @@ -282,6 +289,8 @@ input_gssapi_mic(int type, u_int32_t ple
109 logit("GSSAPI MIC check failed");
110
111 buffer_free(&b);
112 + if (micuser != authctxt->user)
113 + xfree(micuser);
114 xfree(mic.value);
115
116 authctxt->postponed = 0;
117 diff -up openssh-5.2p1/auth2-hostbased.c.selinux openssh-5.2p1/auth2-hostbased.c
118 --- openssh-5.2p1/auth2-hostbased.c.selinux 2008-07-17 10:57:19.000000000 +0200
119 +++ openssh-5.2p1/auth2-hostbased.c 2009-08-11 22:43:07.923721059 +0200
120 @@ -106,7 +106,15 @@ userauth_hostbased(Authctxt *authctxt)
121 buffer_put_string(&b, session_id2, session_id2_len);
122 /* reconstruct packet */
123 buffer_put_char(&b, SSH2_MSG_USERAUTH_REQUEST);
124 - buffer_put_cstring(&b, authctxt->user);
125 +#ifdef WITH_SELINUX
126 + if (authctxt->role) {
127 + buffer_put_int(&b, strlen(authctxt->user)+strlen(authctxt->role)+1);
128 + buffer_append(&b, authctxt->user, strlen(authctxt->user));
129 + buffer_put_char(&b, '/');
130 + buffer_append(&b, authctxt->role, strlen(authctxt->role));
131 + } else
132 +#endif
133 + buffer_put_cstring(&b, authctxt->user);
134 buffer_put_cstring(&b, service);
135 buffer_put_cstring(&b, "hostbased");
136 buffer_put_string(&b, pkalg, alen);
137 diff -up openssh-5.2p1/auth2-pubkey.c.selinux openssh-5.2p1/auth2-pubkey.c
138 --- openssh-5.2p1/auth2-pubkey.c.selinux 2008-07-04 04:54:25.000000000 +0200
139 +++ openssh-5.2p1/auth2-pubkey.c 2009-08-11 22:43:07.925704588 +0200
140 @@ -117,7 +117,15 @@ userauth_pubkey(Authctxt *authctxt)
141 }
142 /* reconstruct packet */
143 buffer_put_char(&b, SSH2_MSG_USERAUTH_REQUEST);
144 - buffer_put_cstring(&b, authctxt->user);
145 +#ifdef WITH_SELINUX
146 + if (authctxt->role) {
147 + buffer_put_int(&b, strlen(authctxt->user)+strlen(authctxt->role)+1);
148 + buffer_append(&b, authctxt->user, strlen(authctxt->user));
149 + buffer_put_char(&b, '/');
150 + buffer_append(&b, authctxt->role, strlen(authctxt->role));
151 + } else
152 +#endif
153 + buffer_put_cstring(&b, authctxt->user);
154 buffer_put_cstring(&b,
155 datafellows & SSH_BUG_PKSERVICE ?
156 "ssh-userauth" :
157 diff -up openssh-5.2p1/auth.h.selinux openssh-5.2p1/auth.h
158 --- openssh-5.2p1/auth.h.selinux 2008-11-05 06:20:46.000000000 +0100
159 +++ openssh-5.2p1/auth.h 2009-08-11 22:43:07.927199901 +0200
160 @@ -58,6 +58,9 @@ struct Authctxt {
161 char *service;
162 struct passwd *pw; /* set if 'valid' */
163 char *style;
164 +#ifdef WITH_SELINUX
165 + char *role;
166 +#endif
167 void *kbdintctxt;
168 void *jpake_ctx;
169 #ifdef BSD_AUTH
170 diff -up openssh-5.2p1/configure.ac.selinux openssh-5.2p1/configure.ac
171 --- openssh-5.2p1/configure.ac.selinux 2009-02-16 05:37:03.000000000 +0100
172 +++ openssh-5.2p1/configure.ac 2009-08-11 22:43:07.930259052 +0200
173 @@ -3335,6 +3335,7 @@ AC_ARG_WITH(selinux,
174 AC_CHECK_LIB(selinux, setexeccon, [ LIBSELINUX="-lselinux" ],
175 AC_MSG_ERROR(SELinux support requires libselinux library))
176 SSHDLIBS="$SSHDLIBS $LIBSELINUX"
177 + LIBS="$LIBS $LIBSELINUX"
178 AC_CHECK_FUNCS(getseuserbyname get_default_context_with_level)
179 LIBS="$save_LIBS"
180 fi ]
181 diff -up openssh-5.2p1/monitor.c.selinux openssh-5.2p1/monitor.c
182 --- openssh-5.2p1/monitor.c.selinux 2009-02-14 06:33:31.000000000 +0100
183 +++ openssh-5.2p1/monitor.c 2009-08-11 22:43:07.933623092 +0200
184 @@ -135,6 +135,9 @@ int mm_answer_sign(int, Buffer *);
185 int mm_answer_pwnamallow(int, Buffer *);
186 int mm_answer_auth2_read_banner(int, Buffer *);
187 int mm_answer_authserv(int, Buffer *);
188 +#ifdef WITH_SELINUX
189 +int mm_answer_authrole(int, Buffer *);
190 +#endif
191 int mm_answer_authpassword(int, Buffer *);
192 int mm_answer_bsdauthquery(int, Buffer *);
193 int mm_answer_bsdauthrespond(int, Buffer *);
194 @@ -211,6 +214,9 @@ struct mon_table mon_dispatch_proto20[]
195 {MONITOR_REQ_SIGN, MON_ONCE, mm_answer_sign},
196 {MONITOR_REQ_PWNAM, MON_ONCE, mm_answer_pwnamallow},
197 {MONITOR_REQ_AUTHSERV, MON_ONCE, mm_answer_authserv},
198 +#ifdef WITH_SELINUX
199 + {MONITOR_REQ_AUTHROLE, MON_ONCE, mm_answer_authrole},
200 +#endif
201 {MONITOR_REQ_AUTH2_READ_BANNER, MON_ONCE, mm_answer_auth2_read_banner},
202 {MONITOR_REQ_AUTHPASSWORD, MON_AUTH, mm_answer_authpassword},
203 #ifdef USE_PAM
204 @@ -680,6 +686,9 @@ mm_answer_pwnamallow(int sock, Buffer *m
205 else {
206 /* Allow service/style information on the auth context */
207 monitor_permit(mon_dispatch, MONITOR_REQ_AUTHSERV, 1);
208 +#ifdef WITH_SELINUX
209 + monitor_permit(mon_dispatch, MONITOR_REQ_AUTHROLE, 1);
210 +#endif
211 monitor_permit(mon_dispatch, MONITOR_REQ_AUTH2_READ_BANNER, 1);
212 }
213
214 @@ -724,6 +733,25 @@ mm_answer_authserv(int sock, Buffer *m)
215 return (0);
216 }
217
218 +#ifdef WITH_SELINUX
219 +int
220 +mm_answer_authrole(int sock, Buffer *m)
221 +{
222 + monitor_permit_authentications(1);
223 +
224 + authctxt->role = buffer_get_string(m, NULL);
225 + debug3("%s: role=%s",
226 + __func__, authctxt->role);
227 +
228 + if (strlen(authctxt->role) == 0) {
229 + xfree(authctxt->role);
230 + authctxt->role = NULL;
231 + }
232 +
233 + return (0);
234 +}
235 +#endif
236 +
237 int
238 mm_answer_authpassword(int sock, Buffer *m)
239 {
240 @@ -1102,7 +1130,7 @@ static int
241 monitor_valid_userblob(u_char *data, u_int datalen)
242 {
243 Buffer b;
244 - char *p;
245 + char *p, *r;
246 u_int len;
247 int fail = 0;
248
249 @@ -1128,6 +1156,8 @@ monitor_valid_userblob(u_char *data, u_i
250 if (buffer_get_char(&b) != SSH2_MSG_USERAUTH_REQUEST)
251 fail++;
252 p = buffer_get_string(&b, NULL);
253 + if ((r = strchr(p, '/')) != NULL)
254 + *r = '\0';
255 if (strcmp(authctxt->user, p) != 0) {
256 logit("wrong user name passed to monitor: expected %s != %.100s",
257 authctxt->user, p);
258 @@ -1159,7 +1189,7 @@ monitor_valid_hostbasedblob(u_char *data
259 char *chost)
260 {
261 Buffer b;
262 - char *p;
263 + char *p, *r;
264 u_int len;
265 int fail = 0;
266
267 @@ -1176,6 +1206,8 @@ monitor_valid_hostbasedblob(u_char *data
268 if (buffer_get_char(&b) != SSH2_MSG_USERAUTH_REQUEST)
269 fail++;
270 p = buffer_get_string(&b, NULL);
271 + if ((r = strchr(p, '/')) != NULL)
272 + *r = '\0';
273 if (strcmp(authctxt->user, p) != 0) {
274 logit("wrong user name passed to monitor: expected %s != %.100s",
275 authctxt->user, p);
276 diff -up openssh-5.2p1/monitor.h.selinux openssh-5.2p1/monitor.h
277 --- openssh-5.2p1/monitor.h.selinux 2008-11-05 06:20:46.000000000 +0100
278 +++ openssh-5.2p1/monitor.h 2009-08-11 22:43:07.935612930 +0200
279 @@ -31,6 +31,9 @@
280 enum monitor_reqtype {
281 MONITOR_REQ_MODULI, MONITOR_ANS_MODULI,
282 MONITOR_REQ_FREE, MONITOR_REQ_AUTHSERV,
283 +#ifdef WITH_SELINUX
284 + MONITOR_REQ_AUTHROLE,
285 +#endif
286 MONITOR_REQ_SIGN, MONITOR_ANS_SIGN,
287 MONITOR_REQ_PWNAM, MONITOR_ANS_PWNAM,
288 MONITOR_REQ_AUTH2_READ_BANNER, MONITOR_ANS_AUTH2_READ_BANNER,
289 diff -up openssh-5.2p1/monitor_wrap.c.selinux openssh-5.2p1/monitor_wrap.c
290 --- openssh-5.2p1/monitor_wrap.c.selinux 2008-11-05 06:20:47.000000000 +0100
291 +++ openssh-5.2p1/monitor_wrap.c 2009-08-11 22:43:07.937212340 +0200
292 @@ -297,6 +297,25 @@ mm_inform_authserv(char *service, char *
293 buffer_free(&m);
294 }
295
296 +/* Inform the privileged process about role */
297 +
298 +#ifdef WITH_SELINUX
299 +void
300 +mm_inform_authrole(char *role)
301 +{
302 + Buffer m;
303 +
304 + debug3("%s entering", __func__);
305 +
306 + buffer_init(&m);
307 + buffer_put_cstring(&m, role ? role : "");
308 +
309 + mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUTHROLE, &m);
310 +
311 + buffer_free(&m);
312 +}
313 +#endif
314 +
315 /* Do the password authentication */
316 int
317 mm_auth_password(Authctxt *authctxt, char *password)
318 diff -up openssh-5.2p1/monitor_wrap.h.selinux openssh-5.2p1/monitor_wrap.h
319 --- openssh-5.2p1/monitor_wrap.h.selinux 2008-11-05 06:20:47.000000000 +0100
320 +++ openssh-5.2p1/monitor_wrap.h 2009-08-11 22:43:07.938268752 +0200
321 @@ -41,6 +41,9 @@ int mm_is_monitor(void);
322 DH *mm_choose_dh(int, int, int);
323 int mm_key_sign(Key *, u_char **, u_int *, u_char *, u_int);
324 void mm_inform_authserv(char *, char *);
325 +#ifdef WITH_SELINUX
326 +void mm_inform_authrole(char *);
327 +#endif
328 struct passwd *mm_getpwnamallow(const char *);
329 char *mm_auth2_read_banner(void);
330 int mm_auth_password(struct Authctxt *, char *);
331 diff -up openssh-5.2p1/openbsd-compat/port-linux.c.selinux openssh-5.2p1/openbsd-compat/port-linux.c
332 --- openssh-5.2p1/openbsd-compat/port-linux.c.selinux 2008-03-26 21:27:21.000000000 +0100
333 +++ openssh-5.2p1/openbsd-compat/port-linux.c 2009-08-11 22:44:14.529196220 +0200
334 @@ -30,11 +30,16 @@
335 #ifdef WITH_SELINUX
336 #include "log.h"
337 #include "port-linux.h"
338 +#include "key.h"
339 +#include "hostfile.h"
340 +#include "auth.h"
341
342 #include <selinux/selinux.h>
343 #include <selinux/flask.h>
344 #include <selinux/get_context_list.h>
345
346 +extern Authctxt *the_authctxt;
347 +
348 /* Wrapper around is_selinux_enabled() to log its return value once only */
349 int
350 ssh_selinux_enabled(void)
351 @@ -53,23 +58,36 @@ ssh_selinux_enabled(void)
352 static security_context_t
353 ssh_selinux_getctxbyname(char *pwname)
354 {
355 - security_context_t sc;
356 - char *sename = NULL, *lvl = NULL;
357 - int r;
358 + security_context_t sc = NULL;
359 + char *sename, *lvl;
360 + char *role = NULL;
361 + int r = 0;
362
363 + if (the_authctxt)
364 + role=the_authctxt->role;
365 #ifdef HAVE_GETSEUSERBYNAME
366 - if (getseuserbyname(pwname, &sename, &lvl) != 0)
367 - return NULL;
368 + if ((r=getseuserbyname(pwname, &sename, &lvl)) != 0) {
369 + sename = NULL;
370 + lvl = NULL;
371 + }
372 #else
373 sename = pwname;
374 lvl = NULL;
375 #endif
376
377 + if (r == 0) {
378 #ifdef HAVE_GET_DEFAULT_CONTEXT_WITH_LEVEL
379 - r = get_default_context_with_level(sename, lvl, NULL, &sc);
380 + if (role != NULL && role[0])
381 + r = get_default_context_with_rolelevel(sename, role, lvl, NULL, &sc);
382 + else
383 + r = get_default_context_with_level(sename, lvl, NULL, &sc);
384 #else
385 - r = get_default_context(sename, NULL, &sc);
386 + if (role != NULL && role[0])
387 + r = get_default_context_with_role(sename, role, NULL, &sc);
388 + else
389 + r = get_default_context(sename, NULL, &sc);
390 #endif
391 + }
392
393 if (r != 0) {
394 switch (security_getenforce()) {

admin@fedoraproject.org
ViewVC Help
Powered by ViewVC 1.1.2