Merge lp:~iahmad/libpam-freerdp/improved-test-coverage into lp:libpam-freerdp
- improved-test-coverage
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | I Ahmad |
Approved revision: | 40 |
Merged at revision: | 39 |
Proposed branch: | lp:~iahmad/libpam-freerdp/improved-test-coverage |
Merge into: | lp:libpam-freerdp |
Diff against target: |
631 lines (+344/-193) 7 files modified
src/Makefile.am (+2/-1) src/pam-freerdp-children.c (+231/-0) src/pam-freerdp-children.h (+30/-0) src/pam-freerdp.c (+6/-192) tests/mock_guest.c (+71/-0) tests/mock_guest.h (+2/-0) tests/test-freerdp-wrapper.cc (+2/-0) |
To merge this branch: | bzr merge lp:~iahmad/libpam-freerdp/improved-test-coverage |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
PS Jenkins bot (community) | continuous-integration | Needs Fixing | |
David Barth (community) | Approve | ||
Review via email: mp+129845@code.launchpad.net |
Commit message
Improving the test coverage.
Description of the change
PS Jenkins bot (ps-jenkins) wrote : | # |
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:39
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:40
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
David Barth (dbarth) wrote : | # |
The code changes look fine to me.
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Autolanding.
No commit message was specified.
http://
Executed test runs:
SUCCESS: http://
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Autolanding.
No commit message was specified.
http://
Executed test runs:
SUCCESS: http://
Preview Diff
1 | === modified file 'src/Makefile.am' |
2 | --- src/Makefile.am 2012-09-25 15:59:04 +0000 |
3 | +++ src/Makefile.am 2012-10-16 11:18:22 +0000 |
4 | @@ -23,7 +23,8 @@ |
5 | libfreerdpcore.la |
6 | |
7 | libfreerdpcore_la_SOURCES = \ |
8 | - pam-freerdp.c |
9 | + pam-freerdp.c \ |
10 | + pam-freerdp-children.c |
11 | libfreerdpcore_la_CFLAGS = \ |
12 | -Wall -Werror \ |
13 | $(COVERAGE_CFLAGS) |
14 | |
15 | === added file 'src/pam-freerdp-children.c' |
16 | --- src/pam-freerdp-children.c 1970-01-01 00:00:00 +0000 |
17 | +++ src/pam-freerdp-children.c 2012-10-16 11:18:22 +0000 |
18 | @@ -0,0 +1,231 @@ |
19 | +/* |
20 | + * Copyright © 2012 Canonical Ltd. |
21 | + * |
22 | + * This program is free software: you can redistribute it and/or modify it |
23 | + * under the terms of the GNU General Public License version 3, as |
24 | + * published by the Free Software Foundation. |
25 | + * |
26 | + * This program is distributed in the hope that it will be useful, but |
27 | + * WITHOUT ANY WARRANTY; without even the implied warranties of |
28 | + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
29 | + * PURPOSE. See the GNU General Public License for more details. |
30 | + * |
31 | + * You should have received a copy of the GNU General Public License along |
32 | + * with this program. If not, see <http://www.gnu.org/licenses/>. |
33 | + * |
34 | + * Author: Ted Gould <ted@canonical.com> |
35 | + */ |
36 | + |
37 | +#include <stdlib.h> |
38 | +#include <stdio.h> |
39 | +#include <string.h> |
40 | +#include <unistd.h> |
41 | +#include <sys/wait.h> |
42 | +#include <sys/types.h> |
43 | +#include <sys/socket.h> |
44 | +#include <sys/stat.h> |
45 | +#include <sys/mman.h> |
46 | +#include <sys/un.h> |
47 | +#include <pwd.h> |
48 | +#include <grp.h> |
49 | +#include <errno.h> |
50 | + |
51 | +#include <security/pam_modules.h> |
52 | +#include <security/pam_modutil.h> |
53 | +#include <security/pam_appl.h> |
54 | + |
55 | +#include "pam-freerdp-children.h" |
56 | +#include "auth-check-path.h" |
57 | + |
58 | +void |
59 | +pam_sm_authenticate_helper (int *stdinpipe, const char* username, const char* rhost, const char* ruser, const char* rdomain) |
60 | +{ |
61 | + |
62 | + dup2(stdinpipe[0], 0); |
63 | + |
64 | + char * args[5]; |
65 | + |
66 | + args[0] = (char *)auth_check_path; |
67 | + args[1] = (char *)rhost; |
68 | + args[2] = (char *)ruser; |
69 | + args[3] = (char *)rdomain; |
70 | + args[4] = NULL; |
71 | + |
72 | + struct passwd * pwdent = getpwnam(username); |
73 | + if (pwdent == NULL) { |
74 | + _exit(EXIT_FAILURE); |
75 | + } |
76 | + |
77 | + /* Setting groups, but allowing EPERM as if we're not 100% root |
78 | + we might not be able to do this */ |
79 | + if (setgroups(1, &pwdent->pw_gid) != 0 && errno != EPERM) { |
80 | + _exit(EXIT_FAILURE); |
81 | + } |
82 | + |
83 | + if (setgid(pwdent->pw_gid) < 0 || setuid(pwdent->pw_uid) < 0 || |
84 | + setegid(pwdent->pw_gid) < 0 || seteuid(pwdent->pw_uid) < 0) { |
85 | + _exit(EXIT_FAILURE); |
86 | + } |
87 | + |
88 | + if (clearenv() != 0) { |
89 | + _exit(EXIT_FAILURE); |
90 | + } |
91 | + |
92 | + if (chdir(pwdent->pw_dir) != 0) { |
93 | + _exit(EXIT_FAILURE); |
94 | + } |
95 | + |
96 | + setenv("HOME", pwdent->pw_dir, 1); |
97 | + |
98 | + execvp(args[0], args); |
99 | + _exit(0); |
100 | +} |
101 | + |
102 | +int |
103 | +session_socket_handler (struct passwd * pwdent, int readypipe, const char * ruser, const char * rhost, const char * rdomain, const char * password) |
104 | +{ |
105 | + /* Socket stuff */ |
106 | + int socketfd = 0; |
107 | + struct sockaddr_un socket_addr; |
108 | + |
109 | + /* Connected user */ |
110 | + socklen_t connected_addr_size; |
111 | + int connectfd = 0; |
112 | + struct sockaddr_un connected_addr; |
113 | + |
114 | + /* Our buffer */ |
115 | + char * buffer = NULL; |
116 | + int buffer_len = 0; |
117 | + int buffer_fill = 0; |
118 | + |
119 | + /* Track write out */ |
120 | + int writedata = 0; |
121 | + |
122 | + /* Track ready writing */ |
123 | + int readywrite = 0; |
124 | + |
125 | + /* Setting groups, but allowing EPERM as if we're not 100% root |
126 | + we might not be able to do this */ |
127 | + if (setgroups(1, &pwdent->pw_gid) != 0 && errno != EPERM) { |
128 | + _exit(EXIT_FAILURE); |
129 | + } |
130 | + |
131 | + if (setgid(pwdent->pw_gid) < 0 || setuid(pwdent->pw_uid) < 0 || |
132 | + setegid(pwdent->pw_gid) < 0 || seteuid(pwdent->pw_uid) < 0) { |
133 | + /* Don't need to clean up yet */ |
134 | + return EXIT_FAILURE; |
135 | + } |
136 | + |
137 | + if (clearenv() != 0) { |
138 | + /* Don't need to clean up yet */ |
139 | + return EXIT_FAILURE; |
140 | + } |
141 | + |
142 | + if (chdir(pwdent->pw_dir) != 0) { |
143 | + /* Don't need to clean up yet */ |
144 | + return EXIT_FAILURE; |
145 | + } |
146 | + |
147 | + if (rdomain[0] == '\0') { |
148 | + rdomain = "."; |
149 | + } |
150 | + |
151 | + /* Build this up as a buffer so we can just write it and see that |
152 | + very, very clearly */ |
153 | + buffer_len += strlen(ruser) + 1; /* Add one for the space */ |
154 | + buffer_len += strlen(rhost) + 1; /* Add one for the space */ |
155 | + buffer_len += strlen(rdomain) + 1; /* Add one for the space */ |
156 | + buffer_len += strlen(password) + 1; /* Add one for the NULL */ |
157 | + |
158 | + if (buffer_len < 5) { |
159 | + /* Don't need to clean up yet */ |
160 | + return EXIT_FAILURE; |
161 | + } |
162 | + |
163 | + buffer = malloc(buffer_len); |
164 | + |
165 | + if (buffer == NULL) { |
166 | + /* Don't need to clean up yet */ |
167 | + return EXIT_FAILURE; |
168 | + } |
169 | + |
170 | + /* Lock the buffer before writing */ |
171 | + if (mlock(buffer, buffer_len) != 0) { |
172 | + /* We can't lock, we go home */ |
173 | + goto cleanup; |
174 | + } |
175 | + |
176 | + buffer_fill = snprintf(buffer, buffer_len, "%s %s %s %s", ruser, password, rdomain, rhost); |
177 | + if (buffer_fill > buffer_len) { |
178 | + /* This really shouldn't happen, but if for some reason we have an |
179 | + difference between they way that the lengths are calculated we want |
180 | + to catch that. */ |
181 | + goto cleanup; |
182 | + } |
183 | + |
184 | + /* Make our socket and bind it */ |
185 | + socketfd = socket(AF_UNIX, SOCK_STREAM, 0); |
186 | + if (socketfd < 0) { |
187 | + goto cleanup; |
188 | + } |
189 | + |
190 | + memset(&socket_addr, 0, sizeof(struct sockaddr_un)); |
191 | + socket_addr.sun_family = AF_UNIX; |
192 | + strncpy(socket_addr.sun_path, pwdent->pw_dir, sizeof(socket_addr.sun_path) - 1); |
193 | + strncpy(socket_addr.sun_path + strlen(pwdent->pw_dir), "/.freerdp-socket", (sizeof(socket_addr.sun_path) - strlen(pwdent->pw_dir)) - 1); |
194 | + |
195 | + /* We bind the socket before forking so that we ensure that |
196 | + there isn't a race condition to get to it. Things will block |
197 | + otherwise. */ |
198 | + if (bind(socketfd, (struct sockaddr *)&socket_addr, sizeof(struct sockaddr_un)) < 0) { |
199 | + goto cleanup; |
200 | + } |
201 | + |
202 | + /* Set the socket file permissions to be 600 and the user and group |
203 | + to be the guest user. NOTE: This won't protect on BSD */ |
204 | + if (chmod(socket_addr.sun_path, S_IRUSR | S_IWUSR) != 0 || |
205 | + chown(socket_addr.sun_path, pwdent->pw_uid, pwdent->pw_gid) != 0) { |
206 | + goto cleanup; |
207 | + } |
208 | + |
209 | + if (listen(socketfd, 1) < 0) { |
210 | + goto cleanup; |
211 | + } |
212 | + |
213 | + readywrite = write(readypipe, ALL_GOOD_SIGNAL, strlen(ALL_GOOD_SIGNAL) + 1); |
214 | + if (readywrite != strlen(ALL_GOOD_SIGNAL) + 1) { |
215 | + goto cleanup; |
216 | + } |
217 | + |
218 | + connected_addr_size = sizeof(struct sockaddr_un); |
219 | + connectfd = accept(socketfd, (struct sockaddr *)&connected_addr, &connected_addr_size); |
220 | + if (connectfd < 0) { |
221 | + goto cleanup; |
222 | + } |
223 | + |
224 | + writedata = write(connectfd, buffer, buffer_len); |
225 | + |
226 | +cleanup: |
227 | + if (socketfd != 0) { |
228 | + close(socketfd); |
229 | + } |
230 | + if (connectfd != 0) { |
231 | + close(connectfd); |
232 | + } |
233 | + |
234 | + if (buffer != NULL) { |
235 | + memset(buffer, 0, buffer_len); |
236 | + munlock(buffer, buffer_len); |
237 | + free(buffer); |
238 | + buffer = NULL; |
239 | + } |
240 | + |
241 | + /* This should be only true on the write, so we can use this to check |
242 | + out as writedata is init to 0 */ |
243 | + if (writedata == buffer_len) { |
244 | + _exit (0); |
245 | + } |
246 | + |
247 | + _exit(EXIT_FAILURE); |
248 | +} |
249 | + |
250 | |
251 | === added file 'src/pam-freerdp-children.h' |
252 | --- src/pam-freerdp-children.h 1970-01-01 00:00:00 +0000 |
253 | +++ src/pam-freerdp-children.h 2012-10-16 11:18:22 +0000 |
254 | @@ -0,0 +1,30 @@ |
255 | +/* |
256 | + * Copyright © 2012 Canonical Ltd. |
257 | + * |
258 | + * This program is free software: you can redistribute it and/or modify it |
259 | + * under the terms of the GNU General Public License version 3, as |
260 | + * published by the Free Software Foundation. |
261 | + * |
262 | + * This program is distributed in the hope that it will be useful, but |
263 | + * WITHOUT ANY WARRANTY; without even the implied warranties of |
264 | + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
265 | + * PURPOSE. See the GNU General Public License for more details. |
266 | + * |
267 | + * You should have received a copy of the GNU General Public License along |
268 | + * with this program. If not, see <http://www.gnu.org/licenses/>. |
269 | + * |
270 | + * Author: Ted Gould <ted@canonical.com> |
271 | + */ |
272 | + |
273 | +#ifndef _PAM_FREERDP_CHILDREN_H_ |
274 | +#define _PAM_FREERDP_CHILDREN_H_ |
275 | + |
276 | +#define PAM_TYPE_DOMAIN 1234 |
277 | +#define ALL_GOOD_SIGNAL "Ar, ready to authenticate cap'n" |
278 | + |
279 | +void |
280 | +pam_sm_authenticate_helper (int *stdinpipe, const char* username, const char* rhost, const char* ruser, const char* rdomain); |
281 | + |
282 | +int |
283 | +session_socket_handler (struct passwd * pwdent, int readypipe, const char * ruser, const char * rhost, const char * rdomain, const char * password); |
284 | +#endif //_PAM_FREERDP_CHILDREN_H_ |
285 | |
286 | === modified file 'src/pam-freerdp.c' |
287 | --- src/pam-freerdp.c 2012-09-20 08:39:53 +0000 |
288 | +++ src/pam-freerdp.c 2012-10-16 11:18:22 +0000 |
289 | @@ -34,11 +34,9 @@ |
290 | #include <security/pam_modutil.h> |
291 | #include <security/pam_appl.h> |
292 | |
293 | +#include "pam-freerdp-children.h" |
294 | #include "auth-check-path.h" |
295 | |
296 | -#define PAM_TYPE_DOMAIN 1234 |
297 | -#define ALL_GOOD_SIGNAL "Ar, ready to authenticate cap'n" |
298 | - |
299 | static int unpriveleged_kill (struct passwd * pwdent); |
300 | |
301 | static char * global_domain = NULL; |
302 | @@ -236,44 +234,7 @@ |
303 | pid_t pid; |
304 | switch (pid = fork()) { |
305 | case 0: { /* child */ |
306 | - dup2(stdinpipe[0], 0); |
307 | - |
308 | - char * args[5]; |
309 | - |
310 | - args[0] = (char *)auth_check_path; |
311 | - args[1] = rhost; |
312 | - args[2] = ruser; |
313 | - args[3] = rdomain; |
314 | - args[4] = NULL; |
315 | - |
316 | - struct passwd * pwdent = getpwnam(username); |
317 | - if (pwdent == NULL) { |
318 | - _exit(EXIT_FAILURE); |
319 | - } |
320 | - |
321 | - /* Setting groups, but allowing EPERM as if we're not 100% root |
322 | - we might not be able to do this */ |
323 | - if (setgroups(1, &pwdent->pw_gid) != 0 && errno != EPERM) { |
324 | - _exit(EXIT_FAILURE); |
325 | - } |
326 | - |
327 | - if (setgid(pwdent->pw_gid) < 0 || setuid(pwdent->pw_uid) < 0 || |
328 | - setegid(pwdent->pw_gid) < 0 || seteuid(pwdent->pw_uid) < 0) { |
329 | - _exit(EXIT_FAILURE); |
330 | - } |
331 | - |
332 | - if (clearenv() != 0) { |
333 | - _exit(EXIT_FAILURE); |
334 | - } |
335 | - |
336 | - if (chdir(pwdent->pw_dir) != 0) { |
337 | - _exit(EXIT_FAILURE); |
338 | - } |
339 | - |
340 | - setenv("HOME", pwdent->pw_dir, 1); |
341 | - |
342 | - execvp(args[0], args); |
343 | - _exit(EXIT_FAILURE); |
344 | + pam_sm_authenticate_helper (stdinpipe, username, rhost, ruser, rdomain); |
345 | break; |
346 | } |
347 | case -1: { /* fork'n error! */ |
348 | @@ -304,153 +265,7 @@ |
349 | return retval; |
350 | } |
351 | |
352 | -static int |
353 | -session_socket_handler (struct passwd * pwdent, int readypipe, const char * ruser, const char * rhost, const char * rdomain, const char * password) |
354 | -{ |
355 | - /* Socket stuff */ |
356 | - int socketfd = 0; |
357 | - struct sockaddr_un socket_addr; |
358 | - |
359 | - /* Connected user */ |
360 | - socklen_t connected_addr_size; |
361 | - int connectfd = 0; |
362 | - struct sockaddr_un connected_addr; |
363 | - |
364 | - /* Our buffer */ |
365 | - char * buffer = NULL; |
366 | - int buffer_len = 0; |
367 | - int buffer_fill = 0; |
368 | - |
369 | - /* Track write out */ |
370 | - int writedata = 0; |
371 | - |
372 | - /* Track ready writing */ |
373 | - int readywrite = 0; |
374 | - |
375 | - /* Setting groups, but allowing EPERM as if we're not 100% root |
376 | - we might not be able to do this */ |
377 | - if (setgroups(1, &pwdent->pw_gid) != 0 && errno != EPERM) { |
378 | - _exit(EXIT_FAILURE); |
379 | - } |
380 | - |
381 | - if (setgid(pwdent->pw_gid) < 0 || setuid(pwdent->pw_uid) < 0 || |
382 | - setegid(pwdent->pw_gid) < 0 || seteuid(pwdent->pw_uid) < 0) { |
383 | - /* Don't need to clean up yet */ |
384 | - return EXIT_FAILURE; |
385 | - } |
386 | - |
387 | - if (clearenv() != 0) { |
388 | - /* Don't need to clean up yet */ |
389 | - return EXIT_FAILURE; |
390 | - } |
391 | - |
392 | - if (chdir(pwdent->pw_dir) != 0) { |
393 | - /* Don't need to clean up yet */ |
394 | - return EXIT_FAILURE; |
395 | - } |
396 | - |
397 | - if (rdomain[0] == '\0') { |
398 | - rdomain = "."; |
399 | - } |
400 | - |
401 | - /* Build this up as a buffer so we can just write it and see that |
402 | - very, very clearly */ |
403 | - buffer_len += strlen(ruser) + 1; /* Add one for the space */ |
404 | - buffer_len += strlen(rhost) + 1; /* Add one for the space */ |
405 | - buffer_len += strlen(rdomain) + 1; /* Add one for the space */ |
406 | - buffer_len += strlen(password) + 1; /* Add one for the NULL */ |
407 | - |
408 | - if (buffer_len < 5) { |
409 | - /* Don't need to clean up yet */ |
410 | - return EXIT_FAILURE; |
411 | - } |
412 | - |
413 | - buffer = malloc(buffer_len); |
414 | - |
415 | - if (buffer == NULL) { |
416 | - /* Don't need to clean up yet */ |
417 | - return EXIT_FAILURE; |
418 | - } |
419 | - |
420 | - /* Lock the buffer before writing */ |
421 | - if (mlock(buffer, buffer_len) != 0) { |
422 | - /* We can't lock, we go home */ |
423 | - goto cleanup; |
424 | - } |
425 | - |
426 | - buffer_fill = snprintf(buffer, buffer_len, "%s %s %s %s", ruser, password, rdomain, rhost); |
427 | - if (buffer_fill > buffer_len) { |
428 | - /* This really shouldn't happen, but if for some reason we have an |
429 | - difference between they way that the lengths are calculated we want |
430 | - to catch that. */ |
431 | - goto cleanup; |
432 | - } |
433 | - |
434 | - /* Make our socket and bind it */ |
435 | - socketfd = socket(AF_UNIX, SOCK_STREAM, 0); |
436 | - if (socketfd < 0) { |
437 | - goto cleanup; |
438 | - } |
439 | - |
440 | - memset(&socket_addr, 0, sizeof(struct sockaddr_un)); |
441 | - socket_addr.sun_family = AF_UNIX; |
442 | - strncpy(socket_addr.sun_path, pwdent->pw_dir, sizeof(socket_addr.sun_path) - 1); |
443 | - strncpy(socket_addr.sun_path + strlen(pwdent->pw_dir), "/.freerdp-socket", (sizeof(socket_addr.sun_path) - strlen(pwdent->pw_dir)) - 1); |
444 | - |
445 | - /* We bind the socket before forking so that we ensure that |
446 | - there isn't a race condition to get to it. Things will block |
447 | - otherwise. */ |
448 | - if (bind(socketfd, (struct sockaddr *)&socket_addr, sizeof(struct sockaddr_un)) < 0) { |
449 | - goto cleanup; |
450 | - } |
451 | - |
452 | - /* Set the socket file permissions to be 600 and the user and group |
453 | - to be the guest user. NOTE: This won't protect on BSD */ |
454 | - if (chmod(socket_addr.sun_path, S_IRUSR | S_IWUSR) != 0 || |
455 | - chown(socket_addr.sun_path, pwdent->pw_uid, pwdent->pw_gid) != 0) { |
456 | - goto cleanup; |
457 | - } |
458 | - |
459 | - if (listen(socketfd, 1) < 0) { |
460 | - goto cleanup; |
461 | - } |
462 | - |
463 | - readywrite = write(readypipe, ALL_GOOD_SIGNAL, strlen(ALL_GOOD_SIGNAL) + 1); |
464 | - if (readywrite != strlen(ALL_GOOD_SIGNAL) + 1) { |
465 | - goto cleanup; |
466 | - } |
467 | - |
468 | - connected_addr_size = sizeof(struct sockaddr_un); |
469 | - connectfd = accept(socketfd, (struct sockaddr *)&connected_addr, &connected_addr_size); |
470 | - if (connectfd < 0) { |
471 | - goto cleanup; |
472 | - } |
473 | - |
474 | - writedata = write(connectfd, buffer, buffer_len); |
475 | - |
476 | -cleanup: |
477 | - if (socketfd != 0) { |
478 | - close(socketfd); |
479 | - } |
480 | - if (connectfd != 0) { |
481 | - close(connectfd); |
482 | - } |
483 | - |
484 | - if (buffer != NULL) { |
485 | - memset(buffer, 0, buffer_len); |
486 | - munlock(buffer, buffer_len); |
487 | - free(buffer); |
488 | - buffer = NULL; |
489 | - } |
490 | - |
491 | - /* This should be only true on the write, so we can use this to check |
492 | - out as writedata is init to 0 */ |
493 | - if (writedata == buffer_len) { |
494 | - return 0; |
495 | - } |
496 | - |
497 | - return EXIT_FAILURE; |
498 | -} |
499 | + |
500 | |
501 | pid_t session_pid = 0; |
502 | /* Open Session. Here we need to fork a little process so that we can |
503 | @@ -492,12 +307,11 @@ |
504 | |
505 | pid_t pid = fork(); |
506 | if (pid == 0) { |
507 | - int retval = 0; |
508 | - |
509 | - retval = session_socket_handler(pwdent, sessionready[1], ruser, rhost, rdomain, password); |
510 | + |
511 | + int ret = session_socket_handler(pwdent, sessionready[1], ruser, rhost, rdomain, password); |
512 | |
513 | close(sessionready[1]); |
514 | - _exit(retval); |
515 | + _exit(ret); |
516 | } else if (pid < 0) { |
517 | close(sessionready[0]); |
518 | close(sessionready[1]); |
519 | |
520 | === modified file 'tests/mock_guest.c' |
521 | --- tests/mock_guest.c 2012-09-19 19:35:36 +0000 |
522 | +++ tests/mock_guest.c 2012-10-16 11:18:22 +0000 |
523 | @@ -9,6 +9,11 @@ |
524 | #include <errno.h> |
525 | #include <unistd.h> |
526 | #include <sys/stat.h> |
527 | +#include <stdlib.h> |
528 | +#include <sys/types.h> |
529 | +#include <sys/socket.h> |
530 | +#include <sys/un.h> |
531 | +#include <stdio.h> |
532 | |
533 | static struct passwd guest = { "guest", |
534 | "password", |
535 | @@ -49,3 +54,69 @@ |
536 | int chown(const char *path, uid_t owner, gid_t group) |
537 | { return 0; } |
538 | |
539 | +int execvp(const char *file, char *const argv[]) |
540 | +{ |
541 | + return 0; |
542 | +} |
543 | +/* wrap _exit, to make sure the gcov_exit function installed with atexit() |
544 | + is really called to collect coverage statistics */ |
545 | +void _exit (int exitcode) |
546 | +{ |
547 | + exit (exitcode); |
548 | +} |
549 | + |
550 | + |
551 | +#define BUFFER_SIZE 512 |
552 | + |
553 | +/*Borrowed this code form socket-sucker.c in lightdm-remote-session-freerdp*/ |
554 | +int |
555 | +socket_sucker () |
556 | +{ |
557 | + int socket_fd = 0; |
558 | + int servlen = 0; |
559 | + struct sockaddr_un serv_addr; |
560 | + |
561 | + bzero((char *)&serv_addr, sizeof(serv_addr)); |
562 | + |
563 | + const char * home = getenv("HOME"); |
564 | + if (home == NULL) { |
565 | + return -1; |
566 | + } |
567 | + |
568 | + serv_addr.sun_family = AF_UNIX; |
569 | + |
570 | + int printsize = snprintf(serv_addr.sun_path, sizeof(serv_addr.sun_path) - 1, "%s/%s", home, ".freerdp-socket"); |
571 | + if (printsize > sizeof(serv_addr.sun_path) - 1 || printsize < 0) { |
572 | + return -1; |
573 | + } |
574 | + |
575 | + servlen = strlen(serv_addr.sun_path) + sizeof(serv_addr.sun_family); |
576 | + |
577 | + if ((socket_fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) { |
578 | + return -1; |
579 | + } |
580 | + |
581 | + if (connect(socket_fd, (struct sockaddr *)&serv_addr, servlen) < 0) { |
582 | + return -1; |
583 | + } |
584 | + |
585 | + char buffer[BUFFER_SIZE + 2]; |
586 | + int in = 0; |
587 | + int out = 0; |
588 | + |
589 | + in = read(socket_fd, buffer, BUFFER_SIZE); |
590 | + |
591 | + if (in > 0) { |
592 | + out = write(1, buffer, in); |
593 | + } |
594 | + |
595 | + close(socket_fd); |
596 | + |
597 | + if (in > 0 && out > 0 && in == out) { |
598 | + return 0; |
599 | + } else { |
600 | + return -1; |
601 | + } |
602 | +} |
603 | + |
604 | + |
605 | |
606 | === modified file 'tests/mock_guest.h' |
607 | --- tests/mock_guest.h 2012-09-19 19:35:36 +0000 |
608 | +++ tests/mock_guest.h 2012-10-16 11:18:22 +0000 |
609 | @@ -20,5 +20,7 @@ |
610 | int seteuid(uid_t uid); |
611 | int chmod(const char *path, mode_t mode); |
612 | int chown(const char *path, uid_t owner, gid_t group); |
613 | +int execvp(const char *file, char *const argv[]); |
614 | +int socket_sucker(); |
615 | |
616 | #endif |
617 | |
618 | === modified file 'tests/test-freerdp-wrapper.cc' |
619 | --- tests/test-freerdp-wrapper.cc 2012-09-20 04:32:08 +0000 |
620 | +++ tests/test-freerdp-wrapper.cc 2012-10-16 11:18:22 +0000 |
621 | @@ -67,8 +67,10 @@ |
622 | pam_sm_authenticate (pamh, 0, 0, argv)); |
623 | EXPECT_EQ (PAM_SUCCESS, |
624 | pam_sm_setcred (pamh, 0, 0, argv)); |
625 | + |
626 | EXPECT_EQ (PAM_SUCCESS, |
627 | pam_sm_open_session (pamh, 0, 0, argv)); |
628 | + EXPECT_EQ(0, socket_sucker()); |
629 | EXPECT_EQ (PAM_SUCCESS, |
630 | pam_sm_close_session (pamh, 0, 0, argv)); |
631 | } |
FAILED: Continuous integration, rev:39 jenkins. qa.ubuntu. com/job/ libpam- freerdp- ci/17/ jenkins. qa.ubuntu. com/job/ libpam- freerdp- ci/./label= precise/ 17/console
http://
Executed test runs:
FAILURE: http://