3
* LLNL security test to validate SLURM's wiki interface security
5
* Compilation line varies by system.
7
* cc -L/usr/lib64 -lslurm -osecurity_2_8 security_2_8.c
8
* For most Linux system:
9
* cc -lslurm -osecurity_2_8 security_2_8.c
15
* Bad checksum reported
24
#include <slurm/slurm.h>
25
#include <sys/types.h>
26
#include <sys/socket.h>
30
static int _conn_wiki_port(char *host, int port)
33
struct sockaddr_in wiki_addr;
36
hptr = gethostbyname(host);
38
perror("gethostbyname");
41
if ((sock_fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
45
bzero((char *) &wiki_addr, sizeof(wiki_addr));
46
wiki_addr.sin_family = AF_INET;
47
wiki_addr.sin_port = htons(port);
48
memcpy(&wiki_addr.sin_addr.s_addr, hptr->h_addr, hptr->h_length);
49
sock_fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
50
if (connect(sock_fd, (struct sockaddr *) &wiki_addr,
58
static size_t _read_bytes(int fd, char *buf, const size_t size)
60
size_t bytes_remaining, bytes_read;
63
bytes_remaining = size;
65
while (bytes_remaining > 0) {
66
bytes_read = read(fd, ptr, bytes_remaining);
69
bytes_remaining -= bytes_read;
76
static size_t _write_bytes(int fd, char *buf, const size_t size)
78
size_t bytes_remaining, bytes_written;
81
bytes_remaining = size;
83
while (bytes_remaining > 0) {
84
bytes_written = write(fd, ptr, bytes_remaining);
85
if (bytes_written < 0)
87
bytes_remaining -= bytes_written;
93
static size_t _send_msg(int fd, char *buf, size_t size)
98
(void) sprintf(header, "%08lu\n", (uint32_t) size);
99
if (_write_bytes(fd, header, 9) != 9) {
100
perror("writing message header");
104
data_sent = _write_bytes(fd, buf, size);
105
if (data_sent != size) {
106
perror("writing message");
113
static char *_recv_msg(int fd)
119
if (_read_bytes(fd, header, 9) != 9) {
120
perror("reading message header");
123
if (sscanf(header, "%ul", &size) != 1) {
124
perror("parsing message header");
127
buf = calloc(1, (size+1)); /* need '\0' on end to print */
132
if (_read_bytes(fd, buf, size) != size) {
133
perror("reading message");
139
main(int argc, char **argv)
141
int wiki=0, sched_port=0, wiki_fd;
142
char control_addr[1024];
143
char *in_msg, out_msg[1024], *resp;
146
* Get current SLURM configuration
148
slurm_ctl_conf_t *conf_ptr;
149
slurm_load_ctl_conf((time_t) 0, &conf_ptr);
150
if (strcasecmp(conf_ptr->schedtype, "sched/wiki2") == 0)
152
strncpy(control_addr, conf_ptr->control_addr, sizeof(control_addr));
153
sched_port = conf_ptr->schedport;
154
slurm_free_ctl_conf(conf_ptr);
157
printf("SLURM's Wiki2 plugin not configured, nothing to test\n");
162
printf("SLURM's Wiki2 configured on %s:%d\n", control_addr, sched_port);
166
* Build a Wiki request with arbitrary encryption key
168
snprintf(out_msg, sizeof(out_msg),
169
"CK=1234567812345678 TS=%u AUTH=root DT=CMD=GETJOBS ARG=0:ALL",
170
(uint32_t) time(NULL));
173
* Send the message and get the response from SLURM
176
printf("Sending message: %s\n", out_msg);
178
wiki_fd = _conn_wiki_port(control_addr, sched_port);
179
_send_msg(wiki_fd, out_msg, strlen(out_msg));
180
in_msg = _recv_msg(wiki_fd);
182
printf("Received message: %s\n", in_msg);
186
* Parse the results for desired error
188
resp = strstr(in_msg, "RESPONSE=bad checksum");
190
printf("Bad checksum reported\n");
194
printf("Bad response: %s\n", in_msg);