1 | /* |
---|
2 | * Test suite for continued commands. |
---|
3 | * |
---|
4 | * Written by Russ Allbery <rra@stanford.edu> |
---|
5 | * Copyright 2006, 2009 Board of Trustees, Leland Stanford Jr. University |
---|
6 | * |
---|
7 | * See LICENSE for licensing terms. |
---|
8 | */ |
---|
9 | |
---|
10 | #include <config.h> |
---|
11 | #include <portable/system.h> |
---|
12 | |
---|
13 | #include <signal.h> |
---|
14 | #include <sys/wait.h> |
---|
15 | |
---|
16 | #include <client/internal.h> |
---|
17 | #include <client/remctl.h> |
---|
18 | #include <tests/tap/basic.h> |
---|
19 | #include <tests/tap/kerberos.h> |
---|
20 | #include <tests/tap/remctl.h> |
---|
21 | #include <util/util.h> |
---|
22 | |
---|
23 | |
---|
24 | int |
---|
25 | main(void) |
---|
26 | { |
---|
27 | char *principal, *config, *path; |
---|
28 | struct remctl *r; |
---|
29 | struct remctl_output *output; |
---|
30 | pid_t remctld; |
---|
31 | static const char prefix_first[] = { 2, MESSAGE_COMMAND, 1, 1 }; |
---|
32 | static const char prefix_next[] = { 2, MESSAGE_COMMAND, 1, 2 }; |
---|
33 | static const char prefix_last[] = { 2, MESSAGE_COMMAND, 1, 3 }; |
---|
34 | static const char data[] = { |
---|
35 | 0, 0, 0, 3, |
---|
36 | 0, 0, 0, 4, 't', 'e', 's', 't', |
---|
37 | 0, 0, 0, 6, 's', 't', 'a', 't', 'u', 's', |
---|
38 | 0, 0, 0, 1, '2' |
---|
39 | }; |
---|
40 | char buffer[BUFSIZ]; |
---|
41 | gss_buffer_desc token; |
---|
42 | OM_uint32 major, minor; |
---|
43 | int status; |
---|
44 | |
---|
45 | /* Unless we have Kerberos available, we can't really do anything. */ |
---|
46 | if (chdir(getenv("SOURCE")) < 0) |
---|
47 | bail("can't chdir to SOURCE"); |
---|
48 | principal = kerberos_setup(); |
---|
49 | if (principal == NULL) |
---|
50 | skip_all("Kerberos tests not configured"); |
---|
51 | plan(9); |
---|
52 | config = concatpath(getenv("SOURCE"), "data/conf-simple"); |
---|
53 | path = concatpath(getenv("BUILD"), "../server/remctld"); |
---|
54 | remctld = remctld_start(path, principal, config); |
---|
55 | |
---|
56 | /* Open a connection. */ |
---|
57 | r = remctl_new(); |
---|
58 | ok(r != NULL, "remctl_new"); |
---|
59 | ok(remctl_open(r, "localhost", 14373, principal), "remctl_open"); |
---|
60 | |
---|
61 | /* Send the command broken in the middle of protocol elements. */ |
---|
62 | token.value = buffer; |
---|
63 | memcpy(buffer, prefix_first, sizeof(prefix_first)); |
---|
64 | memcpy(buffer + sizeof(prefix_first), data, 2); |
---|
65 | token.length = sizeof(prefix_first) + 2; |
---|
66 | status = token_send_priv(r->fd, r->context, TOKEN_DATA | TOKEN_PROTOCOL, |
---|
67 | &token, &major, &minor); |
---|
68 | is_int(TOKEN_OK, status, "first token sent okay"); |
---|
69 | memcpy(buffer, prefix_next, sizeof(prefix_next)); |
---|
70 | memcpy(buffer + sizeof(prefix_next), data + 2, 4); |
---|
71 | token.length = sizeof(prefix_next) + 4; |
---|
72 | status = token_send_priv(r->fd, r->context, TOKEN_DATA | TOKEN_PROTOCOL, |
---|
73 | &token, &major, &minor); |
---|
74 | is_int(TOKEN_OK, status, "second token sent okay"); |
---|
75 | memcpy(buffer, prefix_next, sizeof(prefix_next)); |
---|
76 | memcpy(buffer + sizeof(prefix_next), data + 6, 13); |
---|
77 | token.length = sizeof(prefix_next) + 13; |
---|
78 | status = token_send_priv(r->fd, r->context, TOKEN_DATA | TOKEN_PROTOCOL, |
---|
79 | &token, &major, &minor); |
---|
80 | is_int(TOKEN_OK, status, "third token sent okay"); |
---|
81 | memcpy(buffer, prefix_last, sizeof(prefix_last)); |
---|
82 | memcpy(buffer + sizeof(prefix_last), data + 19, sizeof(data) - 19); |
---|
83 | token.length = sizeof(prefix_next) + sizeof(data) - 19; |
---|
84 | status = token_send_priv(r->fd, r->context, TOKEN_DATA | TOKEN_PROTOCOL, |
---|
85 | &token, &major, &minor); |
---|
86 | is_int(TOKEN_OK, status, "fourth token sent okay"); |
---|
87 | r->ready = 1; |
---|
88 | output = remctl_output(r); |
---|
89 | ok(output != NULL, "got output"); |
---|
90 | is_int(REMCTL_OUT_STATUS, output->type, "...of type status"); |
---|
91 | is_int(2, output->status, "...with correct status"); |
---|
92 | remctl_close(r); |
---|
93 | |
---|
94 | remctld_stop(remctld); |
---|
95 | kerberos_cleanup(); |
---|
96 | return 0; |
---|
97 | } |
---|