Debian Codegraph @

tests/api/jot.c

raw symbols SCIP
1 /*
2 * ProFTPD - FTP server testsuite
3 * Copyright (c) 2020-2023 The ProFTPD Project team
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
18 *
19 * As a special exemption, The ProFTPD Project team and other respective
20 * copyright holders give permission to link this program with OpenSSL, and
21 * distribute the resulting executable, without including the source code for
22 * OpenSSL in the source distribution.
23 */
24
25 /* Jot API tests. */
26
27 #include "tests.h"
28 #include "logfmt.h"
29 #include "json.h"
30 #include "jot.h"
31
32 extern pr_response_t *resp_list;
33
34 static pool *p = NULL;
35
36 static void set_up(void) {
37 if (p == NULL) {
38 p = permanent_pool = make_sub_pool(NULL);
39 }
40
41 if (getenv("TEST_VERBOSE") != NULL) {
42 pr_trace_set_levels("jot", 1, 20);
43 }
44
45 init_fs();
46 (void) var_init();
47 }
48
49 static void tear_down(void) {
50 if (session.c != NULL) {
51 pr_inet_close(p, session.c);
52 session.c = NULL;
53 }
54
55 if (getenv("TEST_VERBOSE") != NULL) {
56 pr_trace_set_levels("jot", 0, 0);
57 }
58
59 (void) var_free();
60
61 if (p != NULL) {
62 destroy_pool(p);
63 p = permanent_pool = NULL;
64 }
65 }
66
67 /* Tests */
68
69 static void assert_jot_class_filter(const char *class_name) {
70 pr_jot_filters_t *filters;
71 const char *rules;
72
73 rules = class_name;
74
75 mark_point();
76 filters = pr_jot_filters_create(p, rules, PR_JOT_FILTER_TYPE_CLASSES, 0);
77 ck_assert_msg(filters != NULL, "Failed to create filters from '%s': %s",
78 rules, strerror(errno));
79 (void) pr_jot_filters_destroy(filters);
80
81 rules = pstrcat(p, "!", class_name, NULL);
82
83 mark_point();
84 filters = pr_jot_filters_create(p, rules, PR_JOT_FILTER_TYPE_CLASSES, 0);
85 ck_assert_msg(filters != NULL, "Failed to create filters from '%s': %s",
86 rules, strerror(errno));
87 (void) pr_jot_filters_destroy(filters);
88 }
89
90 static void assert_jot_command_with_class_filter(const char *rules) {
91 pr_jot_filters_t *filters;
92
93 mark_point();
94 filters = pr_jot_filters_create(p, rules,
95 PR_JOT_FILTER_TYPE_COMMANDS_WITH_CLASSES, 0);
96 ck_assert_msg(filters != NULL, "Failed to create filters from '%s': %s",
97 rules, strerror(errno));
98 (void) pr_jot_filters_destroy(filters);
99 }
100
101 START_TEST (jot_filters_create_test) {
102 pr_jot_filters_t *filters;
103 const char *rules;
104
105 mark_point();
106 filters = pr_jot_filters_create(NULL, NULL, 0, 0);
107 ck_assert_msg(filters == NULL, "Failed to handle null pool");
108 ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
109 strerror(errno), errno);
110
111 mark_point();
112 filters = pr_jot_filters_create(p, NULL, 0, 0);
113 ck_assert_msg(filters == NULL, "Failed to handle null rules");
114 ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
115 strerror(errno), errno);
116
117 rules = "foo";
118
119 mark_point();
120 filters = pr_jot_filters_create(p, rules, -1, 0);
121 ck_assert_msg(filters == NULL, "Failed to handle invalid rules type");
122 ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
123 strerror(errno), errno);
124
125 /* Class rules */
126
127 mark_point();
128 filters = pr_jot_filters_create(p, rules, PR_JOT_FILTER_TYPE_CLASSES, 0);
129 ck_assert_msg(filters == NULL, "Failed to handle invalid class name '%s'",
130 rules);
131 ck_assert_msg(errno == ENOENT, "Expected ENOENT (%d), got %s (%d)", ENOENT,
132 strerror(errno), errno);
133
134 assert_jot_class_filter("NONE");
135 assert_jot_class_filter("ALL");
136 assert_jot_class_filter("AUTH");
137 assert_jot_class_filter("INFO");
138 assert_jot_class_filter("DIRS");
139 assert_jot_class_filter("READ");
140 assert_jot_class_filter("WRITE");
141 assert_jot_class_filter("SEC");
142 assert_jot_class_filter("SECURE");
143 assert_jot_class_filter("CONNECT");
144 assert_jot_class_filter("EXIT");
145 assert_jot_class_filter("DISCONNECT");
146 assert_jot_class_filter("SSH");
147 assert_jot_class_filter("SFTP");
148
149 rules = "AUTH,!INFO";
150
151 mark_point();
152 filters = pr_jot_filters_create(p, rules, PR_JOT_FILTER_TYPE_CLASSES, 0);
153 ck_assert_msg(filters != NULL, "Failed to create filters from '%s': %s",
154 rules, strerror(errno));
155 (void) pr_jot_filters_destroy(filters);
156
157 rules = "!INFO|AUTH";
158
159 mark_point();
160 filters = pr_jot_filters_create(p, rules, PR_JOT_FILTER_TYPE_CLASSES, 0);
161 ck_assert_msg(filters != NULL, "Failed to create filters from '%s': %s",
162 rules, strerror(errno));
163 (void) pr_jot_filters_destroy(filters);
164
165 /* Command rules */
166
167 rules = "FOO,BAR";
168 mark_point();
169 filters = pr_jot_filters_create(p, rules, PR_JOT_FILTER_TYPE_COMMANDS, 0);
170 ck_assert_msg(filters != NULL, "Failed to create filters from '%s': %s",
171 rules, strerror(errno));
172 (void) pr_jot_filters_destroy(filters);
173
174 rules = "APPE,RETR,STOR,STOU";
175 mark_point();
176 filters = pr_jot_filters_create(p, rules, PR_JOT_FILTER_TYPE_COMMANDS, 0);
177 ck_assert_msg(filters != NULL, "Failed to create filters from '%s': %s",
178 rules, strerror(errno));
179 (void) pr_jot_filters_destroy(filters);
180
181 /* Rules with commands and classes */
182
183 rules = "CONNECT,RETR,STOR,DISCONNECT";
184 assert_jot_command_with_class_filter(rules);
185
186 rules = "RETR,STOR,AUTH";
187 assert_jot_command_with_class_filter(rules);
188
189 rules = "RETR,STOR,DIRS";
190 assert_jot_command_with_class_filter(rules);
191
192 rules = "RETR,STOR,INFO";
193 assert_jot_command_with_class_filter(rules);
194
195 rules = "RETR,STOR,MISC";
196 assert_jot_command_with_class_filter(rules);
197
198 rules = "READ,RETR,STOR";
199 assert_jot_command_with_class_filter(rules);
200
201 rules = "RETR,SEC,STOR";
202 assert_jot_command_with_class_filter(rules);
203
204 rules = "RETR,SFTP,STOR";
205 assert_jot_command_with_class_filter(rules);
206
207 rules = "RETR,SSH,STOR";
208 assert_jot_command_with_class_filter(rules);
209
210 rules = "RETR,STOR,WRITE";
211 assert_jot_command_with_class_filter(rules);
212
213 rules = "ALL";
214 mark_point();
215 filters = pr_jot_filters_create(p, rules,
216 PR_JOT_FILTER_TYPE_COMMANDS_WITH_CLASSES, 0);
217 ck_assert_msg(filters != NULL, "Failed to create filters from '%s': %s",
218 rules, strerror(errno));
219 (void) pr_jot_filters_destroy(filters);
220
221 /* Flags */
222
223 rules = "ALL";
224 mark_point();
225 filters = pr_jot_filters_create(p, rules,
226 PR_JOT_FILTER_TYPE_COMMANDS_WITH_CLASSES, PR_JOT_FILTER_FL_ALL_INCL_ALL);
227 ck_assert_msg(filters != NULL, "Failed to create filters from '%s': %s",
228 rules, strerror(errno));
229 (void) pr_jot_filters_destroy(filters);
230 }
231 END_TEST
232
233 START_TEST (jot_filters_destroy_test) {
234 int res;
235 pr_jot_filters_t *filters;
236
237 mark_point();
238 res = pr_jot_filters_destroy(NULL);
239 ck_assert_msg(res < 0, "Failed to handle null filters");
240 ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
241 strerror(errno), errno);
242
243 filters = pr_jot_filters_create(p, "NONE", PR_JOT_FILTER_TYPE_CLASSES, 0);
244
245 mark_point();
246 res = pr_jot_filters_destroy(filters);
247 ck_assert_msg(res == 0, "Failed to destroy filters: %s", strerror(errno));
248 }
249 END_TEST
250
251 START_TEST (jot_filters_include_classes_test) {
252 int res;
253 pr_jot_filters_t *filters;
254
255 mark_point();
256 res = pr_jot_filters_include_classes(NULL, 0);
257 ck_assert_msg(res < 0, "Failed to handle null filters");
258 ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
259 strerror(errno), errno);
260
261 filters = pr_jot_filters_create(p, "NONE", PR_JOT_FILTER_TYPE_CLASSES, 0);
262
263 res = pr_jot_filters_include_classes(filters, CL_ALL);
264 ck_assert_msg(res == FALSE, "Expected FALSE, got %d", res);
265
266 res = pr_jot_filters_include_classes(filters, CL_NONE);
267 ck_assert_msg(res == TRUE, "Expected TRUE, got %d", res);
268
269 res = pr_jot_filters_destroy(filters);
270 ck_assert_msg(res == 0, "Failed to destroy filters: %s", strerror(errno));
271 }
272 END_TEST
273
274 static unsigned int parse_on_meta_count = 0;
275 static unsigned int parse_on_unknown_count = 0;
276 static unsigned int parse_on_other_count = 0;
277
278 static int parse_on_meta(pool *jot_pool, pr_jot_ctx_t *jot_ctx,
279 unsigned char logfmt_id, const char *text, size_t text_len) {
280 parse_on_meta_count++;
281 return 0;
282 }
283
284 static int parse_on_unknown(pool *jot_pool, pr_jot_ctx_t *jot_ctx,
285 const char *text, size_t text_len) {
286 parse_on_unknown_count++;
287 return 0;
288 }
289
290 static int parse_on_other(pool *jot_pool, pr_jot_ctx_t *jot_ctx, char ch) {
291 parse_on_other_count++;
292 return 0;
293 }
294
295 START_TEST (jot_parse_on_meta_test) {
296 int res;
297 pr_jot_ctx_t *jot_ctx;
298 pr_jot_parsed_t *jot_parsed;
299
300 mark_point();
301 res = pr_jot_parse_on_meta(p, NULL, 0, NULL, 0);
302 ck_assert_msg(res < 0, "Failed to handle null jot_ctx");
303 ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
304 strerror(errno), errno);
305
306 jot_ctx = pcalloc(p, sizeof(pr_jot_ctx_t));
307
308 mark_point();
309 res = pr_jot_parse_on_meta(p, jot_ctx, 0, NULL, 0);
310 ck_assert_msg(res < 0, "Failed to handle null jot_ctx->log");
311 ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
312 strerror(errno), errno);
313
314 jot_parsed = pcalloc(p, sizeof(pr_jot_parsed_t));
315 jot_ctx->log = jot_parsed;
316
317 mark_point();
318 res = pr_jot_parse_on_meta(p, jot_ctx, 0, NULL, 0);
319 ck_assert_msg(res == 0, "Failed to handle parse_on_meta callback: %s",
320 strerror(errno));
321 }
322 END_TEST
323
324 START_TEST (jot_parse_on_unknown_test) {
325 int res;
326 pr_jot_ctx_t *jot_ctx;
327 pr_jot_parsed_t *jot_parsed;
328
329 mark_point();
330 res = pr_jot_parse_on_unknown(p, NULL, NULL, 0);
331 ck_assert_msg(res < 0, "Failed to handle null jot_ctx");
332 ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
333 strerror(errno), errno);
334
335 jot_ctx = pcalloc(p, sizeof(pr_jot_ctx_t));
336
337 mark_point();
338 res = pr_jot_parse_on_unknown(p, jot_ctx, NULL, 0);
339 ck_assert_msg(res < 0, "Failed to handle null jot_ctx->log");
340 ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
341 strerror(errno), errno);
342
343 jot_parsed = pcalloc(p, sizeof(pr_jot_parsed_t));
344 jot_ctx->log = jot_parsed;
345
346 mark_point();
347 res = pr_jot_parse_on_unknown(p, jot_ctx, NULL, 0);
348 ck_assert_msg(res == 0, "Failed to handle parse_on_unknown callback: %s",
349 strerror(errno));
350 }
351 END_TEST
352
353 START_TEST (jot_parse_on_other_test) {
354 int res;
355 pr_jot_ctx_t *jot_ctx;
356 pr_jot_parsed_t *jot_parsed;
357
358 mark_point();
359 res = pr_jot_parse_on_other(p, NULL, 0);
360 ck_assert_msg(res < 0, "Failed to handle null jot_ctx");
361 ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
362 strerror(errno), errno);
363
364 jot_ctx = pcalloc(p, sizeof(pr_jot_ctx_t));
365
366 mark_point();
367 res = pr_jot_parse_on_other(p, jot_ctx, 0);
368 ck_assert_msg(res < 0, "Failed to handle null jot_ctx->log");
369 ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
370 strerror(errno), errno);
371
372 jot_parsed = pcalloc(p, sizeof(pr_jot_parsed_t));
373 jot_ctx->log = jot_parsed;
374
375 mark_point();
376 res = pr_jot_parse_on_other(p, jot_ctx, 0);
377 ck_assert_msg(res == 0, "Failed to handle parse_on_other callback: %s",
378 strerror(errno));
379 }
380 END_TEST
381
382 START_TEST (jot_parse_logfmt_test) {
383 int res;
384 const char *text;
385 size_t text_len;
386 pr_jot_ctx_t *jot_ctx;
387
388 mark_point();
389 res = pr_jot_parse_logfmt(NULL, NULL, NULL, NULL, NULL, NULL, 0);
390 ck_assert_msg(res < 0, "Failed to handle null pool");
391 ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
392 strerror(errno), errno);
393
394 mark_point();
395 res = pr_jot_parse_logfmt(p, NULL, NULL, NULL, NULL, NULL, 0);
396 ck_assert_msg(res < 0, "Failed to handle null text");
397 ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
398 strerror(errno), errno);
399
400 text = "Hello, World!";
401
402 mark_point();
403 res = pr_jot_parse_logfmt(p, text, NULL, NULL, NULL, NULL, 0);
404 ck_assert_msg(res < 0, "Failed to handle null ctx");
405 ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
406 strerror(errno), errno);
407
408 jot_ctx = pcalloc(p, sizeof(pr_jot_ctx_t));
409
410 mark_point();
411 res = pr_jot_parse_logfmt(p, text, jot_ctx, NULL, NULL, NULL, 0);
412 ck_assert_msg(res < 0, "Failed to handle null on_meta");
413 ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
414 strerror(errno), errno);
415
416 parse_on_meta_count = parse_on_unknown_count = parse_on_other_count = 0;
417
418 mark_point();
419 res = pr_jot_parse_logfmt(p, text, jot_ctx, parse_on_meta, NULL, NULL, 0);
420 ck_assert_msg(res == 0, "Failed to parse text '%s': %s", text, strerror(errno));
421 ck_assert_msg(parse_on_meta_count == 0,
422 "Expected on_meta count 0, got %u", parse_on_meta_count);
423 ck_assert_msg(parse_on_unknown_count == 0,
424 "Expected on_unknown count 0, got %u", parse_on_unknown_count);
425 ck_assert_msg(parse_on_other_count == 0,
426 "Expected on_other count 0, got %u", parse_on_other_count);
427
428 parse_on_meta_count = parse_on_unknown_count = parse_on_other_count = 0;
429 text_len = strlen(text);
430
431 mark_point();
432 res = pr_jot_parse_logfmt(p, text, jot_ctx, parse_on_meta, NULL,
433 parse_on_other, 0);
434 ck_assert_msg(res == 0, "Failed to parse text '%s': %s", text, strerror(errno));
435 ck_assert_msg(parse_on_meta_count == 0,
436 "Expected on_meta count 0, got %u", parse_on_meta_count);
437 ck_assert_msg(parse_on_unknown_count == 0,
438 "Expected on_unknown count 0, got %u", parse_on_unknown_count);
439 ck_assert_msg((unsigned long) parse_on_other_count == text_len,
440 "Expected on_other count %lu, got %u", (unsigned long) text_len,
441 parse_on_other_count);
442
443 parse_on_meta_count = parse_on_unknown_count = parse_on_other_count = 0;
444 text = "%A %b %{epoch} %{unknown key here}, boo!";
445 text_len = strlen(text);
446
447 mark_point();
448 res = pr_jot_parse_logfmt(p, text, jot_ctx, parse_on_meta, parse_on_unknown,
449 parse_on_other, 0);
450 ck_assert_msg(res == 0, "Failed to parse text '%s': %s", text, strerror(errno));
451 ck_assert_msg(parse_on_meta_count == 3,
452 "Expected on_meta count 0, got %u", parse_on_meta_count);
453 ck_assert_msg(parse_on_unknown_count == 1,
454 "Expected on_unknown count 0, got %u", parse_on_unknown_count);
455 ck_assert_msg(parse_on_other_count == 9,
456 "Expected on_other count 9, got %u", parse_on_other_count);
457
458 parse_on_meta_count = parse_on_unknown_count = parse_on_other_count = 0;
459 text = "%A %b %{epoch} %{unknown key here}, %{not closed";
460 text_len = strlen(text);
461
462 mark_point();
463 res = pr_jot_parse_logfmt(p, text, jot_ctx, parse_on_meta, parse_on_unknown,
464 parse_on_other, 0);
465 ck_assert_msg(res == 0, "Failed to parse text '%s': %s", text, strerror(errno));
466 ck_assert_msg(parse_on_meta_count == 3,
467 "Expected on_meta count 0, got %u", parse_on_meta_count);
468 ck_assert_msg(parse_on_unknown_count == 1,
469 "Expected on_unknown count 0, got %u", parse_on_unknown_count);
470 ck_assert_msg(parse_on_other_count == 17,
471 "Expected on_other count 17, got %u", parse_on_other_count);
472 }
473 END_TEST
474
475 START_TEST (jot_parse_logfmt_short_vars_test) {
476 register unsigned int i;
477 int res;
478 unsigned int text_count = 0;
479 pr_jot_ctx_t *jot_ctx;
480 const char *text;
481 const char *texts[] = {
482 "%A",
483 "%D",
484 "%E",
485 "%F",
486 "%H",
487 "%I",
488 "%J",
489 "%L",
490 "%O",
491 "%R",
492 "%S",
493 "%T",
494 "%U",
495 "%V",
496 "%a",
497 "%b",
498 "%c",
499 "%d",
500 "%f",
501 "%g",
502 "%h",
503 "%l",
504 "%m",
505 "%p",
506 "%r",
507 "%s",
508 "%u",
509 "%v",
510 "%w",
511 NULL
512 };
513
514 jot_ctx = pcalloc(p, sizeof(pr_jot_ctx_t));
515 text = "%X";
516 parse_on_meta_count = parse_on_unknown_count = parse_on_other_count = 0;
517
518 /* Here we expect an other count of 2, for the '%' and the 'X'. This is
519 * not a recognized/supported short variable, and definitely not a long
520 * variable, and thus the entire text is treated as "other", for each
521 * character.
522 */
523
524 mark_point();
525 res = pr_jot_parse_logfmt(p, text, jot_ctx, parse_on_meta, NULL,
526 parse_on_other, 0);
527 ck_assert_msg(res == 0, "Failed to parse text '%s': %s", text, strerror(errno));
528 ck_assert_msg(parse_on_meta_count == 0, "Expected on_meta count 0, got %u",
529 parse_on_meta_count);
530 ck_assert_msg(parse_on_other_count == 2, "Expected on_other count 2, got %u",
531 parse_on_other_count);
532
533 text = "%{0}";
534 parse_on_meta_count = parse_on_unknown_count = parse_on_other_count = 0;
535
536 mark_point();
537 res = pr_jot_parse_logfmt(p, text, jot_ctx, parse_on_meta, parse_on_unknown,
538 parse_on_other, 0);
539 ck_assert_msg(res == 0, "Failed to parse text '%s': %s", text, strerror(errno));
540 ck_assert_msg(parse_on_meta_count == 0,
541 "Expected on_meta count 0, got %u", parse_on_meta_count);
542 ck_assert_msg(parse_on_unknown_count == 1,
543 "Expected on_unknown count 1, got %u", parse_on_unknown_count);
544 ck_assert_msg(parse_on_other_count == 0,
545 "Expected on_other count 0, got %u", parse_on_other_count);
546
547 parse_on_meta_count = parse_on_unknown_count = parse_on_other_count = 0;
548 text_count = 0;
549
550 for (i = 0; texts[i]; i++) {
551 text = (const char *) texts[i];
552 text_count++;
553
554 mark_point();
555 res = pr_jot_parse_logfmt(p, text, jot_ctx, parse_on_meta, parse_on_unknown,
556 parse_on_other, 0);
557 ck_assert_msg(res == 0, "Failed to parse text '%s': %s", text,
558 strerror(errno));
559 }
560
561 ck_assert_msg(parse_on_meta_count == text_count,
562 "Expected on_meta count %d, got %u", text_count, parse_on_meta_count);
563 ck_assert_msg(parse_on_unknown_count == 0,
564 "Expected on_unknown count 0, got %u", parse_on_unknown_count);
565 ck_assert_msg(parse_on_other_count == 0,
566 "Expected on_other count 0, got %u", parse_on_other_count);
567 }
568 END_TEST
569
570 static int long_on_meta(pool *jot_pool, pr_jot_ctx_t *jot_ctx,
571 unsigned char logfmt_id, const char *text, size_t text_len) {
572 if (strncmp(text, "FOOBAR", text_len) == 0) {
573 parse_on_meta_count++;
574 }
575
576 return 0;
577 }
578
579 START_TEST (jot_parse_logfmt_long_vars_test) {
580 register unsigned int i;
581 int res;
582 unsigned int text_count = 0;
583 pr_jot_ctx_t *jot_ctx;
584 const char *text;
585 const char *texts[] = {
586 "%{basename}",
587 "%{epoch}",
588 "%{file-modified}",
589 "%{file-offset}",
590 "%{file-size}",
591 "%{gid}",
592 "%{iso8601}",
593 "%{microsecs}",
594 "%{millisecs}",
595 "%{protocol}",
596 "%{remote-port}",
597 "%{transfer-failure}",
598 "%{transfer-millisecs}",
599 "%{transfer-port}",
600 "%{transfer-speed}",
601 "%{transfer-status}",
602 "%{transfer-type}",
603 "%{uid}",
604 "%{version}",
605 NULL
606 };
607
608 jot_ctx = pcalloc(p, sizeof(pr_jot_ctx_t));
609 text = "%{env:FOOBAR}!";
610 parse_on_meta_count = parse_on_unknown_count = parse_on_other_count = 0;
611
612 mark_point();
613 res = pr_jot_parse_logfmt(p, text, jot_ctx, long_on_meta, NULL,
614 parse_on_other, 0);
615 ck_assert_msg(res == 0, "Failed to parse text '%s': %s", text, strerror(errno));
616 ck_assert_msg(parse_on_meta_count == 1, "Expected on_meta count 1, got %u",
617 parse_on_meta_count);
618 ck_assert_msg(parse_on_other_count == 1, "Expected on_other count 1, got %u",
619 parse_on_other_count);
620
621 text = "%{note:FOOBAR}!";
622 parse_on_meta_count = parse_on_unknown_count = parse_on_other_count = 0;
623
624 mark_point();
625 res = pr_jot_parse_logfmt(p, text, jot_ctx, long_on_meta, NULL,
626 parse_on_other, 0);
627 ck_assert_msg(res == 0, "Failed to parse text '%s': %s", text, strerror(errno));
628 ck_assert_msg(parse_on_meta_count == 1, "Expected on_meta count 1, got %u",
629 parse_on_meta_count);
630 ck_assert_msg(parse_on_other_count == 1, "Expected on_other count 1, got %u",
631 parse_on_other_count);
632
633 text = "%{time:FOOBAR}!";
634 parse_on_meta_count = parse_on_unknown_count = parse_on_other_count = 0;
635
636 mark_point();
637 res = pr_jot_parse_logfmt(p, text, jot_ctx, long_on_meta, NULL,
638 parse_on_other, 0);
639 ck_assert_msg(res == 0, "Failed to parse text '%s': %s", text, strerror(errno));
640 ck_assert_msg(parse_on_meta_count == 1, "Expected on_meta count 1, got %u",
641 parse_on_meta_count);
642 ck_assert_msg(parse_on_other_count == 1, "Expected on_other count 1, got %u",
643 parse_on_other_count);
644
645 parse_on_meta_count = parse_on_unknown_count = parse_on_other_count = 0;
646 text_count = 0;
647
648 for (i = 0; texts[i]; i++) {
649 text = (const char *) texts[i];
650 text_count++;
651
652 mark_point();
653 res = pr_jot_parse_logfmt(p, text, jot_ctx, parse_on_meta, NULL,
654 parse_on_other, 0);
655 ck_assert_msg(res == 0, "Failed to parse text '%s': %s", text,
656 strerror(errno));
657 }
658
659 ck_assert_msg(parse_on_meta_count == text_count,
660 "Expected on_meta count %d, got %u", text_count, parse_on_meta_count);
661 ck_assert_msg(parse_on_other_count == 0, "Expected on_other count 0, got %u",
662 parse_on_other_count);
663
664 text = "%{FOOBAR}e";
665 parse_on_meta_count = parse_on_unknown_count = parse_on_other_count = 0;
666
667 mark_point();
668 res = pr_jot_parse_logfmt(p, text, jot_ctx, long_on_meta, NULL,
669 parse_on_other, 0);
670 ck_assert_msg(res == 0, "Failed to parse text '%s': %s", text, strerror(errno));
671 ck_assert_msg(parse_on_meta_count == 1, "Expected on_meta count 1, got %u",
672 parse_on_meta_count);
673 ck_assert_msg(parse_on_other_count == 0, "Expected on_other count 0, got %u",
674 parse_on_other_count);
675
676 text = "%{FOOBAR}t";
677 parse_on_meta_count = parse_on_unknown_count = parse_on_other_count = 0;
678
679 mark_point();
680 res = pr_jot_parse_logfmt(p, text, jot_ctx, long_on_meta, NULL,
681 parse_on_other, 0);
682 ck_assert_msg(res == 0, "Failed to parse text '%s': %s", text, strerror(errno));
683 ck_assert_msg(parse_on_meta_count == 1, "Expected on_meta count 1, got %u",
684 parse_on_meta_count);
685 ck_assert_msg(parse_on_other_count == 0, "Expected on_other count 0, got %u",
686 parse_on_other_count);
687
688 text = "%{FOOBAR}T";
689 parse_on_meta_count = parse_on_unknown_count = parse_on_other_count = 0;
690
691 /* Here we should see 1 unknown for "%{FOOBAR}", and 1 other for the
692 * trailing "T".
693 */
694
695 mark_point();
696 res = pr_jot_parse_logfmt(p, text, jot_ctx, long_on_meta, parse_on_unknown,
697 parse_on_other, 0);
698 ck_assert_msg(res == 0, "Failed to parse text '%s': %s", text, strerror(errno));
699 ck_assert_msg(parse_on_meta_count == 0,
700 "Expected on_meta count 0, got %u", parse_on_meta_count);
701 ck_assert_msg(parse_on_unknown_count == 1,
702 "Expected on_unknown count 1, got %u", parse_on_unknown_count);
703 ck_assert_msg(parse_on_other_count == 1,
704 "Expected on_other count 1, got %u", parse_on_other_count);
705 }
706 END_TEST
707
708 START_TEST (jot_parse_logfmt_custom_vars_test) {
709 int res;
710 pr_jot_ctx_t *jot_ctx;
711 const char *text;
712
713 jot_ctx = pcalloc(p, sizeof(pr_jot_ctx_t));
714 text = "%{0}";
715 parse_on_meta_count = parse_on_unknown_count = parse_on_other_count = 0;
716
717 mark_point();
718 res = pr_jot_parse_logfmt(p, text, jot_ctx, parse_on_meta, parse_on_unknown,
719 parse_on_other, 0);
720 ck_assert_msg(res == 0, "Failed to parse text '%s': %s", text, strerror(errno));
721 ck_assert_msg(parse_on_meta_count == 0,
722 "Expected on_meta count 0, got %u", parse_on_meta_count);
723 ck_assert_msg(parse_on_unknown_count == 1,
724 "Expected on_unknown count 1, got %u", parse_on_unknown_count);
725 ck_assert_msg(parse_on_other_count == 0,
726 "Expected on_other count 0, got %u", parse_on_other_count);
727
728 parse_on_meta_count = parse_on_unknown_count = parse_on_other_count = 0;
729
730 mark_point();
731 res = pr_jot_parse_logfmt(p, text, jot_ctx, parse_on_meta, parse_on_unknown,
732 parse_on_other, PR_JOT_LOGFMT_PARSE_FL_UNKNOWN_AS_CUSTOM);
733 ck_assert_msg(res == 0, "Failed to parse text '%s': %s", text, strerror(errno));
734 ck_assert_msg(parse_on_meta_count == 1,
735 "Expected on_meta count 1, got %u", parse_on_meta_count);
736 ck_assert_msg(parse_on_unknown_count == 0,
737 "Expected on_unknown count 0, got %u", parse_on_unknown_count);
738 ck_assert_msg(parse_on_other_count == 0,
739 "Expected on_other count 0, got %u", parse_on_other_count);
740 }
741 END_TEST
742
743 static unsigned int resolve_on_meta_count = 0;
744 static unsigned int resolve_on_default_count = 0;
745 static unsigned int resolve_on_other_count = 0;
746
747 static int resolve_id_on_meta(pool *jot_pool, pr_jot_ctx_t *jot_ctx,
748 unsigned char logfmt_id, const char *jot_hint, const void *jot_val) {
749 resolve_on_meta_count++;
750 return 0;
751 }
752
753 static int resolve_id_on_default(pool *jot_pool, pr_jot_ctx_t *jot_ctx,
754 unsigned char logfmt_id) {
755 resolve_on_default_count++;
756 return 0;
757 }
758
759 START_TEST (jot_resolve_logfmt_id_test) {
760 int res;
761 cmd_rec *cmd;
762 unsigned char logfmt_id;
763
764 mark_point();
765 res = pr_jot_resolve_logfmt_id(NULL, NULL, NULL, 0, NULL, 0, NULL, NULL,
766 NULL);
767 ck_assert_msg(res < 0, "Failed to handle null pool");
768 ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
769 strerror(errno), errno);
770
771 mark_point();
772 res = pr_jot_resolve_logfmt_id(p, NULL, NULL, 0, NULL, 0, NULL, NULL, NULL);
773 ck_assert_msg(res < 0, "Failed to handle null cmd");
774 ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
775 strerror(errno), errno);
776
777 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
778
779 mark_point();
780 res = pr_jot_resolve_logfmt_id(p, cmd, NULL, 0, NULL, 0, NULL, NULL, NULL);
781 ck_assert_msg(res < 0, "Failed to handle null on_meta");
782 ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
783 strerror(errno), errno);
784
785 logfmt_id = 0;
786
787 mark_point();
788 res = pr_jot_resolve_logfmt_id(p, cmd, NULL, logfmt_id, NULL, 0, NULL,
789 resolve_id_on_meta, NULL);
790 ck_assert_msg(res < 0, "Failed to handle invalid logfmt_id %u", logfmt_id);
791 ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
792 strerror(errno), errno);
793
794 logfmt_id = LOGFMT_META_START;
795
796 mark_point();
797 res = pr_jot_resolve_logfmt_id(p, cmd, NULL, logfmt_id, NULL, 0, NULL,
798 resolve_id_on_meta, NULL);
799 ck_assert_msg(res < 0, "Failed to handle invalid logfmt_id %u", logfmt_id);
800 ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
801 strerror(errno), errno);
802
803 logfmt_id = LOGFMT_META_ARG_END;
804
805 mark_point();
806 res = pr_jot_resolve_logfmt_id(p, cmd, NULL, logfmt_id, NULL, 0, NULL,
807 resolve_id_on_meta, NULL);
808 ck_assert_msg(res < 0, "Failed to handle invalid logfmt_id %u", logfmt_id);
809 ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
810 strerror(errno), errno);
811 }
812 END_TEST
813
814 START_TEST (jot_resolve_logfmt_id_on_default_test) {
815 int res;
816 cmd_rec *cmd;
817 unsigned char logfmt_id;
818
819 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
820 logfmt_id = LOGFMT_META_BASENAME;
821 resolve_on_meta_count = resolve_on_default_count = 0;
822
823 mark_point();
824 res = pr_jot_resolve_logfmt_id(p, cmd, NULL, logfmt_id, NULL, 0, NULL,
825 resolve_id_on_meta, resolve_id_on_default);
826 ck_assert_msg(res == 0, "Failed to handle logfmt_id %u: %s", logfmt_id,
827 strerror(errno));
828 ck_assert_msg(resolve_on_meta_count == 0,
829 "Expected on_meta count 0, got %u", resolve_on_meta_count);
830 ck_assert_msg(resolve_on_default_count == 1,
831 "Expected on_default count 1, got %u", resolve_on_default_count);
832 }
833 END_TEST
834
835 START_TEST (jot_resolve_logfmt_id_filters_test) {
836 int res;
837 cmd_rec *cmd;
838 pr_jot_filters_t *jot_filters;
839 unsigned char logfmt_id;
840
841 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
842 cmd->cmd_class = CL_CONNECT;
843 logfmt_id = LOGFMT_META_CONNECT;
844
845 /* No filters; should be implicitly jottable. */
846 resolve_on_meta_count = resolve_on_default_count = 0;
847 jot_filters = NULL;
848
849 mark_point();
850 res = pr_jot_resolve_logfmt_id(p, cmd, jot_filters, logfmt_id, NULL, 0, NULL,
851 resolve_id_on_meta, NULL);
852 ck_assert_msg(res == 0, "Failed to handle logfmt_id %u: %s", logfmt_id,
853 strerror(errno));
854 ck_assert_msg(resolve_on_meta_count == 1,
855 "Expected on_meta count 1, got %u", resolve_on_meta_count);
856 ck_assert_msg(resolve_on_default_count == 0,
857 "Expected on_default count 0, got %u", resolve_on_default_count);
858
859 /* With an ALL filter, and no command class. */
860 cmd->cmd_class = 0;
861 logfmt_id = LOGFMT_META_COMMAND;
862 resolve_on_meta_count = resolve_on_default_count = 0;
863 jot_filters = pr_jot_filters_create(p, "ALL",
864 PR_JOT_FILTER_TYPE_CLASSES, PR_JOT_FILTER_FL_ALL_INCL_ALL);
865
866 mark_point();
867 res = pr_jot_resolve_logfmt_id(p, cmd, jot_filters, logfmt_id, NULL, 0, NULL,
868 resolve_id_on_meta, NULL);
869 ck_assert_msg(res == 0, "Failed to handle logfmt_id %u: %s", logfmt_id,
870 strerror(errno));
871 ck_assert_msg(resolve_on_meta_count == 1,
872 "Expected on_meta count 1, got %u", resolve_on_meta_count);
873 ck_assert_msg(resolve_on_default_count == 0,
874 "Expected on_default count 0, got %u", resolve_on_default_count);
875
876 /* With explicit filters that allow the class. */
877 cmd->cmd_class = CL_CONNECT;
878 logfmt_id = LOGFMT_META_CONNECT;
879 resolve_on_meta_count = resolve_on_default_count = 0;
880 jot_filters = pr_jot_filters_create(p, "CONNECT",
881 PR_JOT_FILTER_TYPE_CLASSES, 0);
882
883 mark_point();
884 res = pr_jot_resolve_logfmt_id(p, cmd, jot_filters, logfmt_id, NULL, 0, NULL,
885 resolve_id_on_meta, NULL);
886 ck_assert_msg(res == 0, "Failed to handle logfmt_id %u: %s", logfmt_id,
887 strerror(errno));
888 ck_assert_msg(resolve_on_meta_count == 1,
889 "Expected on_meta count 1, got %u", resolve_on_meta_count);
890 ck_assert_msg(resolve_on_default_count == 0,
891 "Expected on_default count 0, got %u", resolve_on_default_count);
892
893 /* With explicit filters that ignore the class. */
894 resolve_on_meta_count = resolve_on_default_count = 0;
895 jot_filters = pr_jot_filters_create(p, "!CONNECT",
896 PR_JOT_FILTER_TYPE_CLASSES, 0);
897
898 mark_point();
899 res = pr_jot_resolve_logfmt_id(p, cmd, jot_filters, logfmt_id, NULL, 0, NULL,
900 resolve_id_on_meta, NULL);
901 ck_assert_msg(res < 0, "Failed to handle filtered logfmt_id %u", logfmt_id);
902 ck_assert_msg(errno == EPERM, "Expected EPERM (%d), got %s (%d)", EPERM,
903 strerror(errno), errno);
904 ck_assert_msg(resolve_on_meta_count == 0,
905 "Expected on_meta count 0, got %u", resolve_on_meta_count);
906
907 /* With explicit filters that do not match the class. */
908 resolve_on_meta_count = resolve_on_default_count = 0;
909 jot_filters = pr_jot_filters_create(p, "DISCONNECT",
910 PR_JOT_FILTER_TYPE_CLASSES, 0);
911
912 mark_point();
913 res = pr_jot_resolve_logfmt_id(p, cmd, jot_filters, logfmt_id, NULL, 0, NULL,
914 resolve_id_on_meta, NULL);
915 ck_assert_msg(res < 0, "Failed to handle filtered logfmt_id %u", logfmt_id);
916 ck_assert_msg(errno == EPERM, "Expected EPERM (%d), got %s (%d)", EPERM,
917 strerror(errno), errno);
918 ck_assert_msg(resolve_on_meta_count == 0,
919 "Expected on_meta count 0, got %u", resolve_on_meta_count);
920
921 /* With explicit filters that allow the command. Note that this REQUIRES
922 * that we use a known command, since allowed command comparisons are done
923 * by ID.
924 */
925 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "RANG"));
926 cmd->cmd_class = CL_CONNECT;
927 resolve_on_meta_count = resolve_on_default_count = 0;
928 jot_filters = pr_jot_filters_create(p, "RANG",
929 PR_JOT_FILTER_TYPE_COMMANDS, 0);
930
931 mark_point();
932 res = pr_jot_resolve_logfmt_id(p, cmd, jot_filters, logfmt_id, NULL, 0, NULL,
933 resolve_id_on_meta, NULL);
934 ck_assert_msg(res == 0, "Failed to handle logfmt_id %u: %s", logfmt_id,
935 strerror(errno));
936 ck_assert_msg(resolve_on_meta_count == 1,
937 "Expected on_meta count 1, got %u", resolve_on_meta_count);
938 ck_assert_msg(resolve_on_default_count == 0,
939 "Expected on_default count 0, got %u", resolve_on_default_count);
940
941 /* With explicit filters that ignore the command. */
942 resolve_on_meta_count = resolve_on_default_count = 0;
943 jot_filters = pr_jot_filters_create(p, "!RANG",
944 PR_JOT_FILTER_TYPE_COMMANDS, 0);
945
946 mark_point();
947 res = pr_jot_resolve_logfmt_id(p, cmd, jot_filters, logfmt_id, NULL, 0, NULL,
948 resolve_id_on_meta, NULL);
949 ck_assert_msg(res < 0, "Failed to handle filtered logfmt_id %u", logfmt_id);
950 ck_assert_msg(errno == EPERM, "Expected EPERM (%d), got %s (%d)", EPERM,
951 strerror(errno), errno);
952 ck_assert_msg(resolve_on_meta_count == 0,
953 "Expected on_meta count 0, got %u", resolve_on_meta_count);
954
955 /* With explicit filters that do not match the command. */
956 resolve_on_meta_count = resolve_on_default_count = 0;
957 jot_filters = pr_jot_filters_create(p, "FOO",
958 PR_JOT_FILTER_TYPE_COMMANDS, 0);
959
960 mark_point();
961 res = pr_jot_resolve_logfmt_id(p, cmd, jot_filters, logfmt_id, NULL, 0, NULL,
962 resolve_id_on_meta, NULL);
963 ck_assert_msg(res < 0, "Failed to handle filtered logfmt_id %u", logfmt_id);
964 ck_assert_msg(errno == EPERM, "Expected EPERM (%d), got %s (%d)", EPERM,
965 strerror(errno), errno);
966 ck_assert_msg(resolve_on_meta_count == 0,
967 "Expected on_meta count 0, got %u", resolve_on_meta_count);
968 }
969 END_TEST
970
971 START_TEST (jot_resolve_logfmt_id_connect_test) {
972 int res;
973 cmd_rec *cmd;
974 unsigned char logfmt_id;
975
976 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
977 cmd->cmd_class = CL_CONNECT;
978 logfmt_id = LOGFMT_META_CONNECT;
979
980 resolve_on_meta_count = resolve_on_default_count = 0;
981
982 mark_point();
983 res = pr_jot_resolve_logfmt_id(p, cmd, NULL, logfmt_id, NULL, 0, NULL,
984 resolve_id_on_meta, NULL);
985 ck_assert_msg(res == 0, "Failed to handle logfmt_id %u: %s", logfmt_id,
986 strerror(errno));
987 ck_assert_msg(resolve_on_meta_count == 1,
988 "Expected on_meta count 1, got %u", resolve_on_meta_count);
989 ck_assert_msg(resolve_on_default_count == 0,
990 "Expected on_default count 0, got %u", resolve_on_default_count);
991
992 resolve_on_meta_count = resolve_on_default_count = 0;
993 cmd->cmd_class = CL_DISCONNECT;
994
995 mark_point();
996 res = pr_jot_resolve_logfmt_id(p, cmd, NULL, logfmt_id, NULL, 0, NULL,
997 resolve_id_on_meta, NULL);
998 ck_assert_msg(res == 0, "Failed to handle logfmt_id %u: %s", logfmt_id,
999 strerror(errno));
1000 ck_assert_msg(resolve_on_meta_count == 0,
1001 "Expected on_meta count 0, got %u", resolve_on_meta_count);
1002 ck_assert_msg(resolve_on_default_count == 0,
1003 "Expected on_default count 0, got %u", resolve_on_default_count);
1004 }
1005 END_TEST
1006
1007 START_TEST (jot_resolve_logfmt_id_disconnect_test) {
1008 int res;
1009 cmd_rec *cmd;
1010 unsigned char logfmt_id;
1011
1012 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
1013 cmd->cmd_class = CL_DISCONNECT;
1014 logfmt_id = LOGFMT_META_DISCONNECT;
1015
1016 resolve_on_meta_count = resolve_on_default_count = 0;
1017
1018 mark_point();
1019 res = pr_jot_resolve_logfmt_id(p, cmd, NULL, logfmt_id, NULL, 0, NULL,
1020 resolve_id_on_meta, NULL);
1021 ck_assert_msg(res == 0, "Failed to handle logfmt_id %u: %s", logfmt_id,
1022 strerror(errno));
1023 ck_assert_msg(resolve_on_meta_count == 1,
1024 "Expected on_meta count 1, got %u", resolve_on_meta_count);
1025 ck_assert_msg(resolve_on_default_count == 0,
1026 "Expected on_default count 0, got %u", resolve_on_default_count);
1027
1028 resolve_on_meta_count = resolve_on_default_count = 0;
1029 cmd->cmd_class = CL_CONNECT;
1030
1031 mark_point();
1032 res = pr_jot_resolve_logfmt_id(p, cmd, NULL, logfmt_id, NULL, 0, NULL,
1033 resolve_id_on_meta, NULL);
1034 ck_assert_msg(res == 0, "Failed to handle logfmt_id %u: %s", logfmt_id,
1035 strerror(errno));
1036 ck_assert_msg(resolve_on_meta_count == 0,
1037 "Expected on_meta count 0, got %u", resolve_on_meta_count);
1038 ck_assert_msg(resolve_on_default_count == 0,
1039 "Expected on_default count 0, got %u", resolve_on_default_count);
1040 }
1041 END_TEST
1042
1043 START_TEST (jot_resolve_logfmt_id_custom_test) {
1044 int res;
1045 cmd_rec *cmd;
1046 unsigned char logfmt_id;
1047 const char *custom_data;
1048 size_t custom_datalen;
1049
1050 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
1051 cmd->cmd_class = CL_MISC;
1052 logfmt_id = LOGFMT_META_CUSTOM;
1053
1054 resolve_on_meta_count = resolve_on_default_count = 0;
1055 custom_data = "%{0}";
1056 custom_datalen = strlen(custom_data);
1057
1058 mark_point();
1059 res = pr_jot_resolve_logfmt_id(p, cmd, NULL, logfmt_id, custom_data,
1060 custom_datalen, NULL, resolve_id_on_meta, NULL);
1061 ck_assert_msg(res == 0, "Failed to handle logfmt_id %u: %s", logfmt_id,
1062 strerror(errno));
1063 ck_assert_msg(resolve_on_meta_count == 1,
1064 "Expected on_meta count 1, got %u", resolve_on_meta_count);
1065 ck_assert_msg(resolve_on_default_count == 0,
1066 "Expected on_default count 0, got %u", resolve_on_default_count);
1067 }
1068 END_TEST
1069
1070 START_TEST (jot_resolve_logfmt_ids_test) {
1071 register unsigned char i;
1072 int res;
1073 cmd_rec *cmd;
1074 unsigned char logfmt_id;
1075
1076 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
1077 resolve_on_meta_count = resolve_on_default_count = 0;
1078
1079 /* Currently, the max known LogFormat meta/ID is 53 (DISCONNECT). */
1080 for (i = 1; i < 54; i++) {
1081 logfmt_id = i;
1082
1083 mark_point();
1084 res = pr_jot_resolve_logfmt_id(p, cmd, NULL, logfmt_id, NULL, 0, NULL,
1085 resolve_id_on_meta, resolve_id_on_default);
1086 ck_assert_msg(res == 0, "Failed to handle logfmt_id %u: %s", logfmt_id,
1087 strerror(errno));
1088 }
1089
1090 ck_assert_msg(resolve_on_meta_count == 20,
1091 "Expected on_meta count 20, got %u", resolve_on_meta_count);
1092 ck_assert_msg(resolve_on_default_count == 28,
1093 "Expected on_default count 28, got %u", resolve_on_default_count);
1094 }
1095 END_TEST
1096
1097 static int resolve_on_meta(pool *jot_pool, pr_jot_ctx_t *jot_ctx,
1098 unsigned char logfmt_id, const char *jot_hint, const void *val) {
1099 resolve_on_meta_count++;
1100 return 0;
1101 }
1102
1103 static int resolve_on_default(pool *jot_pool, pr_jot_ctx_t *jot_ctx,
1104 unsigned char logfmt_id) {
1105 resolve_on_default_count++;
1106 return 0;
1107 }
1108
1109 static int resolve_on_other(pool *jot_pool, pr_jot_ctx_t *jot_ctx,
1110 unsigned char *text, size_t text_len) {
1111 resolve_on_other_count++;
1112 return 0;
1113 }
1114
1115 START_TEST (jot_resolve_logfmt_invalid_test) {
1116 int res;
1117 cmd_rec *cmd;
1118 unsigned char *logfmt;
1119
1120 mark_point();
1121 res = pr_jot_resolve_logfmt(NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
1122 ck_assert_msg(res < 0, "Failed to handle null pool");
1123 ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1124 strerror(errno), errno);
1125
1126 mark_point();
1127 res = pr_jot_resolve_logfmt(p, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
1128 ck_assert_msg(res < 0, "Failed to handle null cmd");
1129 ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1130 strerror(errno), errno);
1131
1132 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
1133
1134 mark_point();
1135 res = pr_jot_resolve_logfmt(p, cmd, NULL, NULL, NULL, NULL, NULL, NULL);
1136 ck_assert_msg(res < 0, "Failed to handle null logfmt");
1137 ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1138 strerror(errno), errno);
1139
1140 logfmt = (unsigned char *) "";
1141
1142 mark_point();
1143 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL, NULL, NULL, NULL);
1144 ck_assert_msg(res < 0, "Failed to handle null on_meta");
1145 ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1146 strerror(errno), errno);
1147
1148 mark_point();
1149 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL, resolve_on_meta,
1150 NULL, NULL);
1151 ck_assert_msg(res == 0, "Failed to handle empty logfmt: %s", strerror(errno));
1152 }
1153 END_TEST
1154
1155 START_TEST (jot_resolve_logfmt_basename_test) {
1156 int res;
1157 cmd_rec *cmd;
1158 unsigned char logfmt[3];
1159
1160 logfmt[0] = LOGFMT_META_START;
1161 logfmt[1] = LOGFMT_META_BASENAME;
1162 logfmt[2] = 0;
1163
1164 mark_point();
1165 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
1166 cmd->cmd_class = CL_MISC;
1167 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1168 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1169 resolve_on_meta, resolve_on_default, resolve_on_other);
1170 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1171 ck_assert_msg(resolve_on_meta_count == 0,
1172 "Expected on_meta count 0, got %u", resolve_on_meta_count);
1173 ck_assert_msg(resolve_on_default_count == 1,
1174 "Expected on_default count 1, got %u", resolve_on_default_count);
1175 ck_assert_msg(resolve_on_other_count == 0,
1176 "Expected on_other count 0, got %u", resolve_on_other_count);
1177
1178 mark_point();
1179 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "RNTO"));
1180 cmd->cmd_class = CL_MISC;
1181 cmd->arg = pstrdup(p, "/foo/bar");
1182 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1183 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1184 resolve_on_meta, resolve_on_default, resolve_on_other);
1185 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1186 ck_assert_msg(resolve_on_meta_count == 1,
1187 "Expected on_meta count 1, got %u", resolve_on_meta_count);
1188 ck_assert_msg(resolve_on_default_count == 0,
1189 "Expected on_default count 0, got %u", resolve_on_default_count);
1190 ck_assert_msg(resolve_on_other_count == 0,
1191 "Expected on_other count 0, got %u", resolve_on_other_count);
1192
1193 mark_point();
1194 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "RETR"));
1195 cmd->cmd_class = CL_MISC;
1196 pr_table_add_dup(cmd->notes, "mod_xfer.retr-path", "foo", 0);
1197 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1198 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1199 resolve_on_meta, resolve_on_default, resolve_on_other);
1200 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1201 ck_assert_msg(resolve_on_meta_count == 1,
1202 "Expected on_meta count 1, got %u", resolve_on_meta_count);
1203 ck_assert_msg(resolve_on_default_count == 0,
1204 "Expected on_default count 0, got %u", resolve_on_default_count);
1205 ck_assert_msg(resolve_on_other_count == 0,
1206 "Expected on_other count 0, got %u", resolve_on_other_count);
1207
1208 mark_point();
1209 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "APPE"));
1210 cmd->cmd_class = CL_MISC;
1211 pr_table_add_dup(cmd->notes, "mod_xfer.store-path", "foo", 0);
1212 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1213 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1214 resolve_on_meta, resolve_on_default, resolve_on_other);
1215 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1216 ck_assert_msg(resolve_on_meta_count == 1,
1217 "Expected on_meta count 1, got %u", resolve_on_meta_count);
1218 ck_assert_msg(resolve_on_default_count == 0,
1219 "Expected on_default count 0, got %u", resolve_on_default_count);
1220 ck_assert_msg(resolve_on_other_count == 0,
1221 "Expected on_other count 0, got %u", resolve_on_other_count);
1222
1223 mark_point();
1224 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "STOR"));
1225 cmd->cmd_class = CL_MISC;
1226 pr_table_add_dup(cmd->notes, "mod_xfer.store-path", "foo", 0);
1227 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1228 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1229 resolve_on_meta, resolve_on_default, resolve_on_other);
1230 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1231 ck_assert_msg(resolve_on_meta_count == 1,
1232 "Expected on_meta count 1, got %u", resolve_on_meta_count);
1233 ck_assert_msg(resolve_on_default_count == 0,
1234 "Expected on_default count 0, got %u", resolve_on_default_count);
1235 ck_assert_msg(resolve_on_other_count == 0,
1236 "Expected on_other count 0, got %u", resolve_on_other_count);
1237
1238 mark_point();
1239 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
1240 cmd->cmd_class = CL_MISC;
1241 session.xfer.p = p;
1242 session.xfer.path = pstrdup(p, "/foo/bar/baz");
1243 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1244 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1245 resolve_on_meta, resolve_on_default, resolve_on_other);
1246 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1247 ck_assert_msg(resolve_on_meta_count == 1,
1248 "Expected on_meta count 1, got %u", resolve_on_meta_count);
1249 ck_assert_msg(resolve_on_default_count == 0,
1250 "Expected on_default count 0, got %u", resolve_on_default_count);
1251 ck_assert_msg(resolve_on_other_count == 0,
1252 "Expected on_other count 0, got %u", resolve_on_other_count);
1253
1254 session.xfer.p = NULL;
1255 session.xfer.path = NULL;
1256
1257 mark_point();
1258 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "CDUP"));
1259 cmd->cmd_class = CL_MISC;
1260 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1261 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1262 resolve_on_meta, resolve_on_default, resolve_on_other);
1263 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1264 ck_assert_msg(resolve_on_meta_count == 1,
1265 "Expected on_meta count 1, got %u", resolve_on_meta_count);
1266 ck_assert_msg(resolve_on_default_count == 0,
1267 "Expected on_default count 0, got %u", resolve_on_default_count);
1268 ck_assert_msg(resolve_on_other_count == 0,
1269 "Expected on_other count 0, got %u", resolve_on_other_count);
1270
1271 mark_point();
1272 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "XCUP"));
1273 cmd->cmd_class = CL_MISC;
1274 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1275 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1276 resolve_on_meta, resolve_on_default, resolve_on_other);
1277 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1278 ck_assert_msg(resolve_on_meta_count == 1,
1279 "Expected on_meta count 1, got %u", resolve_on_meta_count);
1280 ck_assert_msg(resolve_on_default_count == 0,
1281 "Expected on_default count 0, got %u", resolve_on_default_count);
1282 ck_assert_msg(resolve_on_other_count == 0,
1283 "Expected on_other count 0, got %u", resolve_on_other_count);
1284
1285 mark_point();
1286 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "PWD"));
1287 cmd->cmd_class = CL_MISC;
1288 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1289 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1290 resolve_on_meta, resolve_on_default, resolve_on_other);
1291 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1292 ck_assert_msg(resolve_on_meta_count == 1,
1293 "Expected on_meta count 1, got %u", resolve_on_meta_count);
1294 ck_assert_msg(resolve_on_default_count == 0,
1295 "Expected on_default count 0, got %u", resolve_on_default_count);
1296 ck_assert_msg(resolve_on_other_count == 0,
1297 "Expected on_other count 0, got %u", resolve_on_other_count);
1298
1299 mark_point();
1300 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "XPWD"));
1301 cmd->cmd_class = CL_MISC;
1302 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1303 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1304 resolve_on_meta, resolve_on_default, resolve_on_other);
1305 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1306 ck_assert_msg(resolve_on_meta_count == 1,
1307 "Expected on_meta count 1, got %u", resolve_on_meta_count);
1308 ck_assert_msg(resolve_on_default_count == 0,
1309 "Expected on_default count 0, got %u", resolve_on_default_count);
1310 ck_assert_msg(resolve_on_other_count == 0,
1311 "Expected on_other count 0, got %u", resolve_on_other_count);
1312
1313 mark_point();
1314 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "CWD"));
1315 cmd->cmd_class = CL_MISC;
1316 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1317 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1318 resolve_on_meta, resolve_on_default, resolve_on_other);
1319 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1320 ck_assert_msg(resolve_on_meta_count == 1,
1321 "Expected on_meta count 1, got %u", resolve_on_meta_count);
1322 ck_assert_msg(resolve_on_default_count == 0,
1323 "Expected on_default count 0, got %u", resolve_on_default_count);
1324 ck_assert_msg(resolve_on_other_count == 0,
1325 "Expected on_other count 0, got %u", resolve_on_other_count);
1326
1327 mark_point();
1328 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "XCWD"));
1329 cmd->cmd_class = CL_MISC;
1330 session.chroot_path = "/foo/bar";
1331 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1332 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1333 resolve_on_meta, resolve_on_default, resolve_on_other);
1334 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1335 ck_assert_msg(resolve_on_meta_count == 1,
1336 "Expected on_meta count 1, got %u", resolve_on_meta_count);
1337 ck_assert_msg(resolve_on_default_count == 0,
1338 "Expected on_default count 0, got %u", resolve_on_default_count);
1339 ck_assert_msg(resolve_on_other_count == 0,
1340 "Expected on_other count 0, got %u", resolve_on_other_count);
1341
1342 session.chroot_path = NULL;
1343
1344 mark_point();
1345 cmd = pr_cmd_alloc(p, 4, pstrdup(p, "SITE"), pstrdup(p, "chgrp"),
1346 pstrdup(p, "foo"), pstrdup(p, "bar"));
1347 cmd->cmd_class = CL_MISC;
1348 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1349 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1350 resolve_on_meta, resolve_on_default, resolve_on_other);
1351 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1352 ck_assert_msg(resolve_on_meta_count == 1,
1353 "Expected on_meta count 1, got %u", resolve_on_meta_count);
1354 ck_assert_msg(resolve_on_default_count == 0,
1355 "Expected on_default count 0, got %u", resolve_on_default_count);
1356 ck_assert_msg(resolve_on_other_count == 0,
1357 "Expected on_other count 0, got %u", resolve_on_other_count);
1358
1359 mark_point();
1360 cmd = pr_cmd_alloc(p, 4, pstrdup(p, "SITE"), pstrdup(p, "chmod"),
1361 pstrdup(p, "foo"), pstrdup(p, "bar"));
1362 cmd->cmd_class = CL_MISC;
1363 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1364 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1365 resolve_on_meta, resolve_on_default, resolve_on_other);
1366 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1367 ck_assert_msg(resolve_on_meta_count == 1,
1368 "Expected on_meta count 1, got %u", resolve_on_meta_count);
1369 ck_assert_msg(resolve_on_default_count == 0,
1370 "Expected on_default count 0, got %u", resolve_on_default_count);
1371 ck_assert_msg(resolve_on_other_count == 0,
1372 "Expected on_other count 0, got %u", resolve_on_other_count);
1373
1374 mark_point();
1375 cmd = pr_cmd_alloc(p, 4, pstrdup(p, "SITE"), pstrdup(p, "UTIME"),
1376 pstrdup(p, "foo"), pstrdup(p, "bar"));
1377 cmd->cmd_class = CL_MISC;
1378 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1379 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1380 resolve_on_meta, resolve_on_default, resolve_on_other);
1381 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1382 ck_assert_msg(resolve_on_meta_count == 1,
1383 "Expected on_meta count 1, got %u", resolve_on_meta_count);
1384 ck_assert_msg(resolve_on_default_count == 0,
1385 "Expected on_default count 0, got %u", resolve_on_default_count);
1386 ck_assert_msg(resolve_on_other_count == 0,
1387 "Expected on_other count 0, got %u", resolve_on_other_count);
1388
1389 mark_point();
1390 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "DELE"));
1391 cmd->cmd_class = CL_MISC;
1392 cmd->arg = pstrdup(p, "/");
1393 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1394 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1395 resolve_on_meta, resolve_on_default, resolve_on_other);
1396 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1397 ck_assert_msg(resolve_on_meta_count == 1,
1398 "Expected on_meta count 1, got %u", resolve_on_meta_count);
1399 ck_assert_msg(resolve_on_default_count == 0,
1400 "Expected on_default count 0, got %u", resolve_on_default_count);
1401 ck_assert_msg(resolve_on_other_count == 0,
1402 "Expected on_other count 0, got %u", resolve_on_other_count);
1403
1404 mark_point();
1405 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "LIST"));
1406 cmd->cmd_class = CL_MISC;
1407 cmd->arg = pstrdup(p, "/foo/bar/");
1408 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1409 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1410 resolve_on_meta, resolve_on_default, resolve_on_other);
1411 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1412 ck_assert_msg(resolve_on_meta_count == 1,
1413 "Expected on_meta count 1, got %u", resolve_on_meta_count);
1414 ck_assert_msg(resolve_on_default_count == 0,
1415 "Expected on_default count 0, got %u", resolve_on_default_count);
1416 ck_assert_msg(resolve_on_other_count == 0,
1417 "Expected on_other count 0, got %u", resolve_on_other_count);
1418
1419 mark_point();
1420 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "MDTM"));
1421 cmd->cmd_class = CL_MISC;
1422 cmd->arg = pstrdup(p, "foo/bar");
1423 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1424 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1425 resolve_on_meta, resolve_on_default, resolve_on_other);
1426 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1427 ck_assert_msg(resolve_on_meta_count == 1,
1428 "Expected on_meta count 1, got %u", resolve_on_meta_count);
1429 ck_assert_msg(resolve_on_default_count == 0,
1430 "Expected on_default count 0, got %u", resolve_on_default_count);
1431 ck_assert_msg(resolve_on_other_count == 0,
1432 "Expected on_other count 0, got %u", resolve_on_other_count);
1433
1434 mark_point();
1435 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "MKD"));
1436 cmd->cmd_class = CL_MISC;
1437 cmd->arg = pstrdup(p, "foo/bar");
1438 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1439 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1440 resolve_on_meta, resolve_on_default, resolve_on_other);
1441 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1442 ck_assert_msg(resolve_on_meta_count == 1,
1443 "Expected on_meta count 1, got %u", resolve_on_meta_count);
1444 ck_assert_msg(resolve_on_default_count == 0,
1445 "Expected on_default count 0, got %u", resolve_on_default_count);
1446 ck_assert_msg(resolve_on_other_count == 0,
1447 "Expected on_other count 0, got %u", resolve_on_other_count);
1448
1449 mark_point();
1450 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "MLSD"));
1451 cmd->cmd_class = CL_MISC;
1452 cmd->arg = pstrdup(p, "foo/bar");
1453 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1454 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1455 resolve_on_meta, resolve_on_default, resolve_on_other);
1456 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1457 ck_assert_msg(resolve_on_meta_count == 1,
1458 "Expected on_meta count 1, got %u", resolve_on_meta_count);
1459 ck_assert_msg(resolve_on_default_count == 0,
1460 "Expected on_default count 0, got %u", resolve_on_default_count);
1461 ck_assert_msg(resolve_on_other_count == 0,
1462 "Expected on_other count 0, got %u", resolve_on_other_count);
1463
1464 mark_point();
1465 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "MLST"));
1466 cmd->cmd_class = CL_MISC;
1467 cmd->arg = pstrdup(p, "foo/bar");
1468 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1469 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1470 resolve_on_meta, resolve_on_default, resolve_on_other);
1471 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1472 ck_assert_msg(resolve_on_meta_count == 1,
1473 "Expected on_meta count 1, got %u", resolve_on_meta_count);
1474 ck_assert_msg(resolve_on_default_count == 0,
1475 "Expected on_default count 0, got %u", resolve_on_default_count);
1476 ck_assert_msg(resolve_on_other_count == 0,
1477 "Expected on_other count 0, got %u", resolve_on_other_count);
1478
1479 mark_point();
1480 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "NLST"));
1481 cmd->cmd_class = CL_MISC;
1482 cmd->arg = pstrdup(p, "foo/bar");
1483 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1484 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1485 resolve_on_meta, resolve_on_default, resolve_on_other);
1486 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1487 ck_assert_msg(resolve_on_meta_count == 1,
1488 "Expected on_meta count 1, got %u", resolve_on_meta_count);
1489 ck_assert_msg(resolve_on_default_count == 0,
1490 "Expected on_default count 0, got %u", resolve_on_default_count);
1491 ck_assert_msg(resolve_on_other_count == 0,
1492 "Expected on_other count 0, got %u", resolve_on_other_count);
1493
1494 mark_point();
1495 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "RMD"));
1496 cmd->cmd_class = CL_MISC;
1497 cmd->arg = pstrdup(p, "foo/bar");
1498 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1499 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1500 resolve_on_meta, resolve_on_default, resolve_on_other);
1501 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1502 ck_assert_msg(resolve_on_meta_count == 1,
1503 "Expected on_meta count 1, got %u", resolve_on_meta_count);
1504 ck_assert_msg(resolve_on_default_count == 0,
1505 "Expected on_default count 0, got %u", resolve_on_default_count);
1506 ck_assert_msg(resolve_on_other_count == 0,
1507 "Expected on_other count 0, got %u", resolve_on_other_count);
1508
1509 mark_point();
1510 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "XMKD"));
1511 cmd->cmd_class = CL_MISC;
1512 cmd->arg = pstrdup(p, "foo/bar");
1513 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1514 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1515 resolve_on_meta, resolve_on_default, resolve_on_other);
1516 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1517 ck_assert_msg(resolve_on_meta_count == 1,
1518 "Expected on_meta count 1, got %u", resolve_on_meta_count);
1519 ck_assert_msg(resolve_on_default_count == 0,
1520 "Expected on_default count 0, got %u", resolve_on_default_count);
1521 ck_assert_msg(resolve_on_other_count == 0,
1522 "Expected on_other count 0, got %u", resolve_on_other_count);
1523
1524 mark_point();
1525 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "XRMD"));
1526 cmd->cmd_class = CL_MISC;
1527 cmd->arg = pstrdup(p, "foo/bar");
1528 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1529 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1530 resolve_on_meta, resolve_on_default, resolve_on_other);
1531 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1532 ck_assert_msg(resolve_on_meta_count == 1,
1533 "Expected on_meta count 1, got %u", resolve_on_meta_count);
1534 ck_assert_msg(resolve_on_default_count == 0,
1535 "Expected on_default count 0, got %u", resolve_on_default_count);
1536 ck_assert_msg(resolve_on_other_count == 0,
1537 "Expected on_other count 0, got %u", resolve_on_other_count);
1538
1539 mark_point();
1540 cmd = pr_cmd_alloc(p, 3, pstrdup(p, "MFMT"), pstrdup(p, "foo"),
1541 pstrdup(p, "BAR"));
1542 cmd->cmd_class = CL_MISC;
1543 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1544 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1545 resolve_on_meta, resolve_on_default, resolve_on_other);
1546 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1547 ck_assert_msg(resolve_on_meta_count == 1,
1548 "Expected on_meta count 1, got %u", resolve_on_meta_count);
1549 ck_assert_msg(resolve_on_default_count == 0,
1550 "Expected on_default count 0, got %u", resolve_on_default_count);
1551 ck_assert_msg(resolve_on_other_count == 0,
1552 "Expected on_other count 0, got %u", resolve_on_other_count);
1553 }
1554 END_TEST
1555
1556 START_TEST (jot_resolve_logfmt_bytes_sent_test) {
1557 int res;
1558 cmd_rec *cmd;
1559 unsigned char logfmt[3];
1560
1561 logfmt[0] = LOGFMT_META_START;
1562 logfmt[1] = LOGFMT_META_BYTES_SENT;
1563 logfmt[2] = 0;
1564
1565 mark_point();
1566 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
1567 cmd->cmd_class = CL_MISC;
1568 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1569 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1570 resolve_on_meta, resolve_on_default, resolve_on_other);
1571 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1572 ck_assert_msg(resolve_on_meta_count == 0,
1573 "Expected on_meta count 0, got %u", resolve_on_meta_count);
1574 ck_assert_msg(resolve_on_default_count == 1,
1575 "Expected on_default count 1, got %u", resolve_on_default_count);
1576 ck_assert_msg(resolve_on_other_count == 0,
1577 "Expected on_other count 0, got %u", resolve_on_other_count);
1578
1579 mark_point();
1580 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1581 session.xfer.p = p;
1582 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1583 resolve_on_meta, resolve_on_default, resolve_on_other);
1584 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1585 ck_assert_msg(resolve_on_meta_count == 1,
1586 "Expected on_meta count 1, got %u", resolve_on_meta_count);
1587 ck_assert_msg(resolve_on_default_count == 0,
1588 "Expected on_default count 0, got %u", resolve_on_default_count);
1589 ck_assert_msg(resolve_on_other_count == 0,
1590 "Expected on_other count 0, got %u", resolve_on_other_count);
1591
1592 session.xfer.p = NULL;
1593
1594 mark_point();
1595 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1596 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "DELE"));
1597 cmd->cmd_class = CL_MISC;
1598 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1599 resolve_on_meta, resolve_on_default, resolve_on_other);
1600 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1601 ck_assert_msg(resolve_on_meta_count == 1,
1602 "Expected on_meta count 1, got %u", resolve_on_meta_count);
1603 ck_assert_msg(resolve_on_default_count == 0,
1604 "Expected on_default count 0, got %u", resolve_on_default_count);
1605 ck_assert_msg(resolve_on_other_count == 0,
1606 "Expected on_other count 0, got %u", resolve_on_other_count);
1607 }
1608 END_TEST
1609
1610 START_TEST (jot_resolve_logfmt_filename_test) {
1611 int res;
1612 cmd_rec *cmd;
1613 unsigned char logfmt[3];
1614
1615 logfmt[0] = LOGFMT_META_START;
1616 logfmt[1] = LOGFMT_META_FILENAME;
1617 logfmt[2] = 0;
1618
1619 mark_point();
1620 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1621 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
1622 cmd->cmd_class = CL_MISC;
1623 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1624 resolve_on_meta, resolve_on_default, resolve_on_other);
1625 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1626 ck_assert_msg(resolve_on_meta_count == 0,
1627 "Expected on_meta count 0, got %u", resolve_on_meta_count);
1628 ck_assert_msg(resolve_on_default_count == 1,
1629 "Expected on_default count 1, got %u", resolve_on_default_count);
1630 ck_assert_msg(resolve_on_other_count == 0,
1631 "Expected on_other count 0, got %u", resolve_on_other_count);
1632
1633 mark_point();
1634 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1635 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "RNTO"));
1636 cmd->cmd_class = CL_MISC;
1637 cmd->arg = pstrdup(p, "foo");
1638 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1639 resolve_on_meta, resolve_on_default, resolve_on_other);
1640 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1641 ck_assert_msg(resolve_on_meta_count == 1,
1642 "Expected on_meta count 1, got %u", resolve_on_meta_count);
1643 ck_assert_msg(resolve_on_default_count == 0,
1644 "Expected on_default count 0, got %u", resolve_on_default_count);
1645 ck_assert_msg(resolve_on_other_count == 0,
1646 "Expected on_other count 0, got %u", resolve_on_other_count);
1647
1648 mark_point();
1649 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1650 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "RETR"));
1651 cmd->cmd_class = CL_MISC;
1652 pr_table_add_dup(cmd->notes, "mod_xfer.retr-path", "foobar", 0);
1653 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1654 resolve_on_meta, resolve_on_default, resolve_on_other);
1655 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1656 ck_assert_msg(resolve_on_meta_count == 1,
1657 "Expected on_meta count 1, got %u", resolve_on_meta_count);
1658 ck_assert_msg(resolve_on_default_count == 0,
1659 "Expected on_default count 0, got %u", resolve_on_default_count);
1660 ck_assert_msg(resolve_on_other_count == 0,
1661 "Expected on_other count 0, got %u", resolve_on_other_count);
1662
1663 mark_point();
1664 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1665 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "APPE"));
1666 cmd->cmd_class = CL_MISC;
1667 pr_table_add_dup(cmd->notes, "mod_xfer.store-path", "foobar", 0);
1668 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1669 resolve_on_meta, resolve_on_default, resolve_on_other);
1670 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1671 ck_assert_msg(resolve_on_meta_count == 1,
1672 "Expected on_meta count 1, got %u", resolve_on_meta_count);
1673 ck_assert_msg(resolve_on_default_count == 0,
1674 "Expected on_default count 0, got %u", resolve_on_default_count);
1675 ck_assert_msg(resolve_on_other_count == 0,
1676 "Expected on_other count 0, got %u", resolve_on_other_count);
1677
1678 mark_point();
1679 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1680 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "STOR"));
1681 cmd->cmd_class = CL_MISC;
1682 pr_table_add_dup(cmd->notes, "mod_xfer.store-path", "foobar", 0);
1683 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1684 resolve_on_meta, resolve_on_default, resolve_on_other);
1685 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1686 ck_assert_msg(resolve_on_meta_count == 1,
1687 "Expected on_meta count 1, got %u", resolve_on_meta_count);
1688 ck_assert_msg(resolve_on_default_count == 0,
1689 "Expected on_default count 0, got %u", resolve_on_default_count);
1690 ck_assert_msg(resolve_on_other_count == 0,
1691 "Expected on_other count 0, got %u", resolve_on_other_count);
1692
1693 mark_point();
1694 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1695 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
1696 cmd->cmd_class = CL_MISC;
1697 session.xfer.p = p;
1698 session.xfer.path = pstrdup(p, "foobar");
1699 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1700 resolve_on_meta, resolve_on_default, resolve_on_other);
1701 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1702 ck_assert_msg(resolve_on_meta_count == 1,
1703 "Expected on_meta count 1, got %u", resolve_on_meta_count);
1704 ck_assert_msg(resolve_on_default_count == 0,
1705 "Expected on_default count 0, got %u", resolve_on_default_count);
1706 ck_assert_msg(resolve_on_other_count == 0,
1707 "Expected on_other count 0, got %u", resolve_on_other_count);
1708
1709 session.xfer.p = NULL;
1710 session.xfer.path = NULL;
1711
1712 mark_point();
1713 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1714 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "CDUP"));
1715 cmd->cmd_class = CL_MISC;
1716 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1717 resolve_on_meta, resolve_on_default, resolve_on_other);
1718 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1719 ck_assert_msg(resolve_on_meta_count == 1,
1720 "Expected on_meta count 1, got %u", resolve_on_meta_count);
1721 ck_assert_msg(resolve_on_default_count == 0,
1722 "Expected on_default count 0, got %u", resolve_on_default_count);
1723 ck_assert_msg(resolve_on_other_count == 0,
1724 "Expected on_other count 0, got %u", resolve_on_other_count);
1725
1726 mark_point();
1727 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1728 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "PWD"));
1729 cmd->cmd_class = CL_MISC;
1730 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1731 resolve_on_meta, resolve_on_default, resolve_on_other);
1732 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1733 ck_assert_msg(resolve_on_meta_count == 1,
1734 "Expected on_meta count 1, got %u", resolve_on_meta_count);
1735 ck_assert_msg(resolve_on_default_count == 0,
1736 "Expected on_default count 0, got %u", resolve_on_default_count);
1737 ck_assert_msg(resolve_on_other_count == 0,
1738 "Expected on_other count 0, got %u", resolve_on_other_count);
1739
1740 mark_point();
1741 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1742 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "XCUP"));
1743 cmd->cmd_class = CL_MISC;
1744 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1745 resolve_on_meta, resolve_on_default, resolve_on_other);
1746 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1747 ck_assert_msg(resolve_on_meta_count == 1,
1748 "Expected on_meta count 1, got %u", resolve_on_meta_count);
1749 ck_assert_msg(resolve_on_default_count == 0,
1750 "Expected on_default count 0, got %u", resolve_on_default_count);
1751 ck_assert_msg(resolve_on_other_count == 0,
1752 "Expected on_other count 0, got %u", resolve_on_other_count);
1753
1754 mark_point();
1755 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1756 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "XPWD"));
1757 cmd->cmd_class = CL_MISC;
1758 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1759 resolve_on_meta, resolve_on_default, resolve_on_other);
1760 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1761 ck_assert_msg(resolve_on_meta_count == 1,
1762 "Expected on_meta count 1, got %u", resolve_on_meta_count);
1763 ck_assert_msg(resolve_on_default_count == 0,
1764 "Expected on_default count 0, got %u", resolve_on_default_count);
1765 ck_assert_msg(resolve_on_other_count == 0,
1766 "Expected on_other count 0, got %u", resolve_on_other_count);
1767
1768 mark_point();
1769 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1770 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "CWD"));
1771 cmd->cmd_class = CL_MISC;
1772 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1773 resolve_on_meta, resolve_on_default, resolve_on_other);
1774 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1775 ck_assert_msg(resolve_on_meta_count == 1,
1776 "Expected on_meta count 1, got %u", resolve_on_meta_count);
1777 ck_assert_msg(resolve_on_default_count == 0,
1778 "Expected on_default count 0, got %u", resolve_on_default_count);
1779 ck_assert_msg(resolve_on_other_count == 0,
1780 "Expected on_other count 0, got %u", resolve_on_other_count);
1781
1782 mark_point();
1783 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1784 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "XCWD"));
1785 cmd->cmd_class = CL_MISC;
1786 session.chroot_path = "/foo/bar/baz";
1787 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1788 resolve_on_meta, resolve_on_default, resolve_on_other);
1789 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1790 ck_assert_msg(resolve_on_meta_count == 1,
1791 "Expected on_meta count 1, got %u", resolve_on_meta_count);
1792 ck_assert_msg(resolve_on_default_count == 0,
1793 "Expected on_default count 0, got %u", resolve_on_default_count);
1794 ck_assert_msg(resolve_on_other_count == 0,
1795 "Expected on_other count 0, got %u", resolve_on_other_count);
1796
1797 session.chroot_path = NULL;
1798
1799 mark_point();
1800 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1801 cmd = pr_cmd_alloc(p, 4, pstrdup(p, "SITE"), pstrdup(p, "CHGRP"),
1802 pstrdup(p, "foo"), pstrdup(p, "bar"));
1803 cmd->cmd_class = CL_MISC;
1804 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1805 resolve_on_meta, resolve_on_default, resolve_on_other);
1806 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1807 ck_assert_msg(resolve_on_meta_count == 1,
1808 "Expected on_meta count 1, got %u", resolve_on_meta_count);
1809 ck_assert_msg(resolve_on_default_count == 0,
1810 "Expected on_default count 0, got %u", resolve_on_default_count);
1811 ck_assert_msg(resolve_on_other_count == 0,
1812 "Expected on_other count 0, got %u", resolve_on_other_count);
1813
1814 mark_point();
1815 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1816 cmd = pr_cmd_alloc(p, 4, pstrdup(p, "SITE"), pstrdup(p, "CHMOD"),
1817 pstrdup(p, "foo"), pstrdup(p, "bar"));
1818 cmd->cmd_class = CL_MISC;
1819 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1820 resolve_on_meta, resolve_on_default, resolve_on_other);
1821 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1822 ck_assert_msg(resolve_on_meta_count == 1,
1823 "Expected on_meta count 1, got %u", resolve_on_meta_count);
1824 ck_assert_msg(resolve_on_default_count == 0,
1825 "Expected on_default count 0, got %u", resolve_on_default_count);
1826 ck_assert_msg(resolve_on_other_count == 0,
1827 "Expected on_other count 0, got %u", resolve_on_other_count);
1828
1829 mark_point();
1830 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1831 cmd = pr_cmd_alloc(p, 4, pstrdup(p, "SITE"), pstrdup(p, "UTIME"),
1832 pstrdup(p, "foo"), pstrdup(p, "bar"));
1833 cmd->cmd_class = CL_MISC;
1834 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1835 resolve_on_meta, resolve_on_default, resolve_on_other);
1836 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1837 ck_assert_msg(resolve_on_meta_count == 1,
1838 "Expected on_meta count 1, got %u", resolve_on_meta_count);
1839 ck_assert_msg(resolve_on_default_count == 0,
1840 "Expected on_default count 0, got %u", resolve_on_default_count);
1841 ck_assert_msg(resolve_on_other_count == 0,
1842 "Expected on_other count 0, got %u", resolve_on_other_count);
1843
1844 mark_point();
1845 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1846 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "DELE"));
1847 cmd->cmd_class = CL_MISC;
1848 cmd->arg = pstrdup(p, "foo bar");
1849 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1850 resolve_on_meta, resolve_on_default, resolve_on_other);
1851 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1852 ck_assert_msg(resolve_on_meta_count == 1,
1853 "Expected on_meta count 1, got %u", resolve_on_meta_count);
1854 ck_assert_msg(resolve_on_default_count == 0,
1855 "Expected on_default count 0, got %u", resolve_on_default_count);
1856 ck_assert_msg(resolve_on_other_count == 0,
1857 "Expected on_other count 0, got %u", resolve_on_other_count);
1858
1859 mark_point();
1860 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1861 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "LIST"));
1862 cmd->cmd_class = CL_MISC;
1863 cmd->arg = pstrdup(p, "foo bar");
1864 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1865 resolve_on_meta, resolve_on_default, resolve_on_other);
1866 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1867 ck_assert_msg(resolve_on_meta_count == 1,
1868 "Expected on_meta count 1, got %u", resolve_on_meta_count);
1869 ck_assert_msg(resolve_on_default_count == 0,
1870 "Expected on_default count 0, got %u", resolve_on_default_count);
1871 ck_assert_msg(resolve_on_other_count == 0,
1872 "Expected on_other count 0, got %u", resolve_on_other_count);
1873
1874 mark_point();
1875 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1876 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "MDTM"));
1877 cmd->cmd_class = CL_MISC;
1878 cmd->arg = pstrdup(p, "foo bar");
1879 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1880 resolve_on_meta, resolve_on_default, resolve_on_other);
1881 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1882 ck_assert_msg(resolve_on_meta_count == 1,
1883 "Expected on_meta count 1, got %u", resolve_on_meta_count);
1884 ck_assert_msg(resolve_on_default_count == 0,
1885 "Expected on_default count 0, got %u", resolve_on_default_count);
1886 ck_assert_msg(resolve_on_other_count == 0,
1887 "Expected on_other count 0, got %u", resolve_on_other_count);
1888
1889 mark_point();
1890 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1891 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "MKD"));
1892 cmd->cmd_class = CL_MISC;
1893 cmd->arg = pstrdup(p, "foo bar");
1894 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1895 resolve_on_meta, resolve_on_default, resolve_on_other);
1896 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1897 ck_assert_msg(resolve_on_meta_count == 1,
1898 "Expected on_meta count 1, got %u", resolve_on_meta_count);
1899 ck_assert_msg(resolve_on_default_count == 0,
1900 "Expected on_default count 0, got %u", resolve_on_default_count);
1901 ck_assert_msg(resolve_on_other_count == 0,
1902 "Expected on_other count 0, got %u", resolve_on_other_count);
1903
1904 mark_point();
1905 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1906 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "MLSD"));
1907 cmd->cmd_class = CL_MISC;
1908 cmd->arg = pstrdup(p, "foo bar");
1909 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1910 resolve_on_meta, resolve_on_default, resolve_on_other);
1911 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1912 ck_assert_msg(resolve_on_meta_count == 1,
1913 "Expected on_meta count 1, got %u", resolve_on_meta_count);
1914 ck_assert_msg(resolve_on_default_count == 0,
1915 "Expected on_default count 0, got %u", resolve_on_default_count);
1916 ck_assert_msg(resolve_on_other_count == 0,
1917 "Expected on_other count 0, got %u", resolve_on_other_count);
1918
1919 mark_point();
1920 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1921 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "MLST"));
1922 cmd->cmd_class = CL_MISC;
1923 cmd->arg = pstrdup(p, "foo bar");
1924 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1925 resolve_on_meta, resolve_on_default, resolve_on_other);
1926 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1927 ck_assert_msg(resolve_on_meta_count == 1,
1928 "Expected on_meta count 1, got %u", resolve_on_meta_count);
1929 ck_assert_msg(resolve_on_default_count == 0,
1930 "Expected on_default count 0, got %u", resolve_on_default_count);
1931 ck_assert_msg(resolve_on_other_count == 0,
1932 "Expected on_other count 0, got %u", resolve_on_other_count);
1933
1934 mark_point();
1935 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1936 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "NLST"));
1937 cmd->cmd_class = CL_MISC;
1938 cmd->arg = pstrdup(p, "foo bar");
1939 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1940 resolve_on_meta, resolve_on_default, resolve_on_other);
1941 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1942 ck_assert_msg(resolve_on_meta_count == 1,
1943 "Expected on_meta count 1, got %u", resolve_on_meta_count);
1944 ck_assert_msg(resolve_on_default_count == 0,
1945 "Expected on_default count 0, got %u", resolve_on_default_count);
1946 ck_assert_msg(resolve_on_other_count == 0,
1947 "Expected on_other count 0, got %u", resolve_on_other_count);
1948
1949 mark_point();
1950 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1951 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "RMD"));
1952 cmd->cmd_class = CL_MISC;
1953 cmd->arg = pstrdup(p, "foo bar");
1954 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1955 resolve_on_meta, resolve_on_default, resolve_on_other);
1956 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1957 ck_assert_msg(resolve_on_meta_count == 1,
1958 "Expected on_meta count 1, got %u", resolve_on_meta_count);
1959 ck_assert_msg(resolve_on_default_count == 0,
1960 "Expected on_default count 0, got %u", resolve_on_default_count);
1961 ck_assert_msg(resolve_on_other_count == 0,
1962 "Expected on_other count 0, got %u", resolve_on_other_count);
1963
1964 mark_point();
1965 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1966 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "XMKD"));
1967 cmd->cmd_class = CL_MISC;
1968 cmd->arg = pstrdup(p, "foo bar");
1969 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1970 resolve_on_meta, resolve_on_default, resolve_on_other);
1971 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1972 ck_assert_msg(resolve_on_meta_count == 1,
1973 "Expected on_meta count 1, got %u", resolve_on_meta_count);
1974 ck_assert_msg(resolve_on_default_count == 0,
1975 "Expected on_default count 0, got %u", resolve_on_default_count);
1976 ck_assert_msg(resolve_on_other_count == 0,
1977 "Expected on_other count 0, got %u", resolve_on_other_count);
1978
1979 mark_point();
1980 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1981 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "XRMD"));
1982 cmd->cmd_class = CL_MISC;
1983 cmd->arg = pstrdup(p, "foo bar");
1984 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
1985 resolve_on_meta, resolve_on_default, resolve_on_other);
1986 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
1987 ck_assert_msg(resolve_on_meta_count == 1,
1988 "Expected on_meta count 1, got %u", resolve_on_meta_count);
1989 ck_assert_msg(resolve_on_default_count == 0,
1990 "Expected on_default count 0, got %u", resolve_on_default_count);
1991 ck_assert_msg(resolve_on_other_count == 0,
1992 "Expected on_other count 0, got %u", resolve_on_other_count);
1993
1994 mark_point();
1995 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
1996 cmd = pr_cmd_alloc(p, 3, pstrdup(p, "MFMT"), pstrdup(p, "foo"),
1997 pstrdup(p, "BAR"));
1998 cmd->cmd_class = CL_MISC;
1999 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
2000 resolve_on_meta, resolve_on_default, resolve_on_other);
2001 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
2002 ck_assert_msg(resolve_on_meta_count == 1,
2003 "Expected on_meta count 1, got %u", resolve_on_meta_count);
2004 ck_assert_msg(resolve_on_default_count == 0,
2005 "Expected on_default count 0, got %u", resolve_on_default_count);
2006 ck_assert_msg(resolve_on_other_count == 0,
2007 "Expected on_other count 0, got %u", resolve_on_other_count);
2008 }
2009 END_TEST
2010
2011 START_TEST (jot_resolve_logfmt_file_modified_test) {
2012 int res;
2013 cmd_rec *cmd;
2014 unsigned char logfmt[3];
2015 char *modified;
2016
2017 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
2018 cmd->cmd_class = CL_MISC;
2019 logfmt[0] = LOGFMT_META_START;
2020 logfmt[1] = LOGFMT_META_FILE_MODIFIED;
2021 logfmt[2] = 0;
2022
2023 /* First, without the "mod_xfer.file-modified" note. */
2024 mark_point();
2025 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
2026 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
2027 resolve_on_meta, resolve_on_default, resolve_on_other);
2028 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
2029 ck_assert_msg(resolve_on_meta_count == 1,
2030 "Expected on_meta count 1, got %u", resolve_on_meta_count);
2031 ck_assert_msg(resolve_on_default_count == 0,
2032 "Expected on_default count 0, got %u", resolve_on_default_count);
2033 ck_assert_msg(resolve_on_other_count == 0,
2034 "Expected on_other count 0, got %u", resolve_on_other_count);
2035
2036 /* Now, with the "mod_xfer.file-modified" note. */
2037 mark_point();
2038 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
2039 modified = "true";
2040 pr_table_add_dup(cmd->notes, "mod_xfer.file-modified", modified, 0);
2041 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
2042 resolve_on_meta, resolve_on_default, resolve_on_other);
2043 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
2044 ck_assert_msg(resolve_on_meta_count == 1,
2045 "Expected on_meta count 1, got %u", resolve_on_meta_count);
2046 ck_assert_msg(resolve_on_default_count == 0,
2047 "Expected on_default count 0, got %u", resolve_on_default_count);
2048 ck_assert_msg(resolve_on_other_count == 0,
2049 "Expected on_other count 0, got %u", resolve_on_other_count);
2050 }
2051 END_TEST
2052
2053 START_TEST (jot_resolve_logfmt_file_offset_test) {
2054 int res;
2055 cmd_rec *cmd;
2056 unsigned char logfmt[3];
2057 double file_offset;
2058
2059 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
2060 cmd->cmd_class = CL_MISC;
2061 logfmt[0] = LOGFMT_META_START;
2062 logfmt[1] = LOGFMT_META_FILE_OFFSET;
2063 logfmt[2] = 0;
2064
2065 /* First, without the "mod_xfer.file-offset" note. */
2066 mark_point();
2067 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
2068 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
2069 resolve_on_meta, resolve_on_default, resolve_on_other);
2070 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
2071 ck_assert_msg(resolve_on_meta_count == 0,
2072 "Expected on_meta count 0, got %u", resolve_on_meta_count);
2073 ck_assert_msg(resolve_on_default_count == 1,
2074 "Expected on_default count 1, got %u", resolve_on_default_count);
2075 ck_assert_msg(resolve_on_other_count == 0,
2076 "Expected on_other count 0, got %u", resolve_on_other_count);
2077
2078 /* Now, with the "mod_xfer.file-offset" note. */
2079 mark_point();
2080 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
2081 file_offset = 2.0;
2082 pr_table_add(cmd->notes, "mod_xfer.file-offset", &file_offset,
2083 sizeof(file_offset));
2084 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
2085 resolve_on_meta, resolve_on_default, resolve_on_other);
2086 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
2087 ck_assert_msg(resolve_on_meta_count == 1,
2088 "Expected on_meta count 1, got %u", resolve_on_meta_count);
2089 ck_assert_msg(resolve_on_default_count == 0,
2090 "Expected on_default count 0, got %u", resolve_on_default_count);
2091 ck_assert_msg(resolve_on_other_count == 0,
2092 "Expected on_other count 0, got %u", resolve_on_other_count);
2093 }
2094 END_TEST
2095
2096 START_TEST (jot_resolve_logfmt_file_size_test) {
2097 int res;
2098 cmd_rec *cmd;
2099 unsigned char logfmt[3];
2100 off_t file_size;
2101
2102 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
2103 cmd->cmd_class = CL_MISC;
2104 logfmt[0] = LOGFMT_META_START;
2105 logfmt[1] = LOGFMT_META_FILE_SIZE;
2106 logfmt[2] = 0;
2107
2108 /* First, without the "mod_xfer.file-size" note. */
2109 mark_point();
2110 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
2111 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
2112 resolve_on_meta, resolve_on_default, resolve_on_other);
2113 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
2114 ck_assert_msg(resolve_on_meta_count == 0,
2115 "Expected on_meta count 0, got %u", resolve_on_meta_count);
2116 ck_assert_msg(resolve_on_default_count == 1,
2117 "Expected on_default count 1, got %u", resolve_on_default_count);
2118 ck_assert_msg(resolve_on_other_count == 0,
2119 "Expected on_other count 0, got %u", resolve_on_other_count);
2120
2121 /* Now, with the "mod_xfer.file-size" note. */
2122 mark_point();
2123 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
2124 file_size = 2.0;
2125 pr_table_add(cmd->notes, "mod_xfer.file-size", &file_size, sizeof(file_size));
2126 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
2127 resolve_on_meta, resolve_on_default, resolve_on_other);
2128 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
2129 ck_assert_msg(resolve_on_meta_count == 1,
2130 "Expected on_meta count 1, got %u", resolve_on_meta_count);
2131 ck_assert_msg(resolve_on_default_count == 0,
2132 "Expected on_default count 0, got %u", resolve_on_default_count);
2133 ck_assert_msg(resolve_on_other_count == 0,
2134 "Expected on_other count 0, got %u", resolve_on_other_count);
2135 }
2136 END_TEST
2137
2138 START_TEST (jot_resolve_logfmt_env_var_test) {
2139 int res;
2140 cmd_rec *cmd;
2141 unsigned char logfmt[9];
2142 const char *key, *val;
2143
2144 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
2145 cmd->cmd_class = CL_MISC;
2146 logfmt[0] = LOGFMT_META_START;
2147 logfmt[1] = LOGFMT_META_ENV_VAR;
2148 logfmt[2] = 0;
2149
2150 mark_point();
2151 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
2152 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
2153 resolve_on_meta, resolve_on_default, resolve_on_other);
2154 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
2155 ck_assert_msg(resolve_on_meta_count == 0,
2156 "Expected on_meta count 0, got %u", resolve_on_meta_count);
2157 ck_assert_msg(resolve_on_default_count == 0,
2158 "Expected on_default count 0, got %u", resolve_on_default_count);
2159 ck_assert_msg(resolve_on_other_count == 0,
2160 "Expected on_other count 0, got %u", resolve_on_other_count);
2161
2162 mark_point();
2163 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
2164 logfmt[0] = LOGFMT_META_START;
2165 logfmt[1] = LOGFMT_META_ENV_VAR;
2166 logfmt[2] = LOGFMT_META_START;
2167 logfmt[3] = LOGFMT_META_ARG;
2168 logfmt[4] = 'k';
2169 logfmt[5] = 'e';
2170 logfmt[6] = 'y';
2171 logfmt[7] = LOGFMT_META_ARG_END;
2172 logfmt[8] = 0;
2173 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
2174 resolve_on_meta, resolve_on_default, resolve_on_other);
2175 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
2176 ck_assert_msg(resolve_on_meta_count == 0,
2177 "Expected on_meta count 0, got %u", resolve_on_meta_count);
2178 ck_assert_msg(resolve_on_default_count == 1,
2179 "Expected on_default count 1, got %u", resolve_on_default_count);
2180 ck_assert_msg(resolve_on_other_count == 0,
2181 "Expected on_other count 0, got %u", resolve_on_other_count);
2182
2183 mark_point();
2184 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
2185 key = "key";
2186 val = "val";
2187 pr_env_set(p, key, val);
2188 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
2189 resolve_on_meta, resolve_on_default, resolve_on_other);
2190 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
2191 ck_assert_msg(resolve_on_meta_count == 1,
2192 "Expected on_meta count 1, got %u", resolve_on_meta_count);
2193 ck_assert_msg(resolve_on_default_count == 0,
2194 "Expected on_default count 0, got %u", resolve_on_default_count);
2195 ck_assert_msg(resolve_on_other_count == 0,
2196 "Expected on_other count 0, got %u", resolve_on_other_count);
2197 pr_env_unset(p, key);
2198 }
2199 END_TEST
2200
2201 START_TEST (jot_resolve_logfmt_note_test) {
2202 int res;
2203 cmd_rec *cmd;
2204 unsigned char logfmt[9];
2205 const char *key, *val;
2206
2207 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
2208 cmd->cmd_class = CL_MISC;
2209 logfmt[0] = LOGFMT_META_START;
2210 logfmt[1] = LOGFMT_META_NOTE_VAR;
2211 logfmt[2] = 0;
2212
2213 mark_point();
2214 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
2215 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
2216 resolve_on_meta, resolve_on_default, resolve_on_other);
2217 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
2218 ck_assert_msg(resolve_on_meta_count == 0,
2219 "Expected on_meta count 0, got %u", resolve_on_meta_count);
2220 ck_assert_msg(resolve_on_default_count == 0,
2221 "Expected on_default count 0, got %u", resolve_on_default_count);
2222 ck_assert_msg(resolve_on_other_count == 0,
2223 "Expected on_other count 0, got %u", resolve_on_other_count);
2224
2225 mark_point();
2226 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
2227 logfmt[0] = LOGFMT_META_START;
2228 logfmt[1] = LOGFMT_META_NOTE_VAR;
2229 logfmt[2] = LOGFMT_META_START;
2230 logfmt[3] = LOGFMT_META_ARG;
2231 logfmt[4] = 'k';
2232 logfmt[5] = 'e';
2233 logfmt[6] = 'y';
2234 logfmt[7] = LOGFMT_META_ARG_END;
2235 logfmt[8] = 0;
2236 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
2237 resolve_on_meta, resolve_on_default, resolve_on_other);
2238 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
2239 ck_assert_msg(resolve_on_meta_count == 0,
2240 "Expected on_meta count 0, got %u", resolve_on_meta_count);
2241 ck_assert_msg(resolve_on_default_count == 1,
2242 "Expected on_default count 1, got %u", resolve_on_default_count);
2243 ck_assert_msg(resolve_on_other_count == 0,
2244 "Expected on_other count 0, got %u", resolve_on_other_count);
2245
2246 mark_point();
2247 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
2248 key = "key";
2249 val = "val";
2250 session.notes = pr_table_alloc(p, 0);
2251 pr_table_add_dup(session.notes, key, val, 0);
2252 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
2253 resolve_on_meta, resolve_on_default, resolve_on_other);
2254 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
2255 ck_assert_msg(resolve_on_meta_count == 1,
2256 "Expected on_meta count 1, got %u", resolve_on_meta_count);
2257 ck_assert_msg(resolve_on_default_count == 0,
2258 "Expected on_default count 0, got %u", resolve_on_default_count);
2259 ck_assert_msg(resolve_on_other_count == 0,
2260 "Expected on_other count 0, got %u", resolve_on_other_count);
2261
2262 mark_point();
2263 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
2264 pr_table_add_dup(cmd->notes, key, val, 0);
2265 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
2266 resolve_on_meta, resolve_on_default, resolve_on_other);
2267 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
2268 ck_assert_msg(resolve_on_meta_count == 1,
2269 "Expected on_meta count 1, got %u", resolve_on_meta_count);
2270 ck_assert_msg(resolve_on_default_count == 0,
2271 "Expected on_default count 0, got %u", resolve_on_default_count);
2272 ck_assert_msg(resolve_on_other_count == 0,
2273 "Expected on_other count 0, got %u", resolve_on_other_count);
2274
2275 pr_table_empty(session.notes);
2276 pr_table_free(session.notes);
2277 session.notes = NULL;
2278 }
2279 END_TEST
2280
2281 START_TEST (jot_resolve_logfmt_var_test) {
2282 int res;
2283 cmd_rec *cmd;
2284 unsigned char logfmt[9];
2285 const char *key, *val;
2286
2287 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
2288 cmd->cmd_class = CL_MISC;
2289 logfmt[0] = LOGFMT_META_START;
2290 logfmt[1] = LOGFMT_META_VAR_VAR;
2291 logfmt[2] = 0;
2292
2293 mark_point();
2294 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
2295 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
2296 resolve_on_meta, resolve_on_default, resolve_on_other);
2297 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
2298 ck_assert_msg(resolve_on_meta_count == 0,
2299 "Expected on_meta count 0, got %u", resolve_on_meta_count);
2300 ck_assert_msg(resolve_on_default_count == 0,
2301 "Expected on_default count 0, got %u", resolve_on_default_count);
2302 ck_assert_msg(resolve_on_other_count == 0,
2303 "Expected on_other count 0, got %u", resolve_on_other_count);
2304
2305 mark_point();
2306 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
2307 logfmt[0] = LOGFMT_META_START;
2308 logfmt[1] = LOGFMT_META_VAR_VAR;
2309 logfmt[2] = LOGFMT_META_START;
2310 logfmt[3] = LOGFMT_META_ARG;
2311 logfmt[4] = 'k';
2312 logfmt[5] = 'e';
2313 logfmt[6] = 'y';
2314 logfmt[7] = LOGFMT_META_ARG_END;
2315 logfmt[8] = 0;
2316 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
2317 resolve_on_meta, resolve_on_default, resolve_on_other);
2318 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
2319 ck_assert_msg(resolve_on_meta_count == 0,
2320 "Expected on_meta count 0, got %u", resolve_on_meta_count);
2321 ck_assert_msg(resolve_on_default_count == 1,
2322 "Expected on_default count 1, got %u", resolve_on_default_count);
2323 ck_assert_msg(resolve_on_other_count == 0,
2324 "Expected on_other count 0, got %u", resolve_on_other_count);
2325
2326 mark_point();
2327 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
2328 key = "%{key}";
2329 val = "val";
2330
2331 res = pr_var_set(p, key, "Jot VAR test", PR_VAR_TYPE_STR, (void *) val,
2332 NULL, 0);
2333 ck_assert_msg(res == 0, "Failed to set variable: %s", strerror(errno));
2334
2335 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
2336 resolve_on_meta, resolve_on_default, resolve_on_other);
2337 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
2338 ck_assert_msg(resolve_on_meta_count == 1,
2339 "Expected on_meta count 1, got %u", resolve_on_meta_count);
2340 ck_assert_msg(resolve_on_default_count == 0,
2341 "Expected on_default count 0, got %u", resolve_on_default_count);
2342 ck_assert_msg(resolve_on_other_count == 0,
2343 "Expected on_other count 0, got %u", resolve_on_other_count);
2344
2345 res = pr_var_delete(key);
2346 ck_assert_msg(res == 0, "Failed to delete variable: %s", strerror(errno));
2347 }
2348 END_TEST
2349
2350 START_TEST (jot_resolve_logfmt_remote_port_test) {
2351 int res;
2352 cmd_rec *cmd;
2353 unsigned char logfmt[3];
2354 conn_t *conn;
2355 const pr_netaddr_t *addr;
2356
2357 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
2358 cmd->cmd_class = CL_MISC;
2359 logfmt[0] = LOGFMT_META_START;
2360 logfmt[1] = LOGFMT_META_REMOTE_PORT;
2361 logfmt[2] = 0;
2362
2363 /* First, without a session remote address. */
2364 mark_point();
2365 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
2366 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
2367 resolve_on_meta, resolve_on_default, resolve_on_other);
2368 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
2369 ck_assert_msg(resolve_on_meta_count == 0,
2370 "Expected on_meta count 0, got %u", resolve_on_meta_count);
2371 ck_assert_msg(resolve_on_default_count == 1,
2372 "Expected on_default count 1, got %u", resolve_on_default_count);
2373 ck_assert_msg(resolve_on_other_count == 0,
2374 "Expected on_other count 0, got %u", resolve_on_other_count);
2375
2376 /* Now, with a session remote address. */
2377 mark_point();
2378 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
2379
2380 mark_point();
2381 conn = pr_inet_create_conn(p, -1, NULL, INPORT_ANY, FALSE);
2382 session.c = conn;
2383 addr = pr_netaddr_get_addr(p, "127.0.0.1", NULL);
2384 ck_assert_msg(addr != NULL, "Failed to get address: %s", strerror(errno));
2385 pr_netaddr_set_port2((pr_netaddr_t *) addr, 2476);
2386 session.c->remote_addr = addr;
2387 pr_netaddr_set_sess_addrs();
2388
2389 mark_point();
2390 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
2391 resolve_on_meta, resolve_on_default, resolve_on_other);
2392 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
2393 ck_assert_msg(resolve_on_meta_count == 1,
2394 "Expected on_meta count 1, got %u", resolve_on_meta_count);
2395 ck_assert_msg(resolve_on_default_count == 0,
2396 "Expected on_default count 0, got %u", resolve_on_default_count);
2397 ck_assert_msg(resolve_on_other_count == 0,
2398 "Expected on_other count 0, got %u", resolve_on_other_count);
2399
2400 pr_inet_close(p, session.c);
2401 session.c = NULL;
2402 }
2403 END_TEST
2404
2405 START_TEST (jot_resolve_logfmt_rfc1413_ident_test) {
2406 int res;
2407 cmd_rec *cmd;
2408 unsigned char logfmt[3];
2409 char *ident_user;
2410
2411 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
2412 cmd->cmd_class = CL_MISC;
2413 logfmt[0] = LOGFMT_META_START;
2414 logfmt[1] = LOGFMT_META_IDENT_USER;
2415 logfmt[2] = 0;
2416
2417 /* First, without the "mod_ident.rfc1413-ident" note. */
2418 mark_point();
2419 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
2420 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
2421 resolve_on_meta, resolve_on_default, resolve_on_other);
2422 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
2423 ck_assert_msg(resolve_on_meta_count == 0,
2424 "Expected on_meta count 0, got %u", resolve_on_meta_count);
2425 ck_assert_msg(resolve_on_default_count == 1,
2426 "Expected on_default count 1, got %u", resolve_on_default_count);
2427 ck_assert_msg(resolve_on_other_count == 0,
2428 "Expected on_other count 0, got %u", resolve_on_other_count);
2429
2430 /* Now, with the "mod_ident.rfc1413-ident" note. */
2431 mark_point();
2432 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
2433 ident_user = "FOOBAR";
2434 session.notes = pr_table_alloc(p, 0);
2435 pr_table_add_dup(session.notes, "mod_ident.rfc1413-ident", ident_user, 0);
2436 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
2437 resolve_on_meta, resolve_on_default, resolve_on_other);
2438 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
2439 ck_assert_msg(resolve_on_meta_count == 1,
2440 "Expected on_meta count 1, got %u", resolve_on_meta_count);
2441 ck_assert_msg(resolve_on_default_count == 0,
2442 "Expected on_default count 0, got %u", resolve_on_default_count);
2443 ck_assert_msg(resolve_on_other_count == 0,
2444 "Expected on_other count 0, got %u", resolve_on_other_count);
2445
2446 pr_table_empty(session.notes);
2447 pr_table_free(session.notes);
2448 session.notes = NULL;
2449 }
2450 END_TEST
2451
2452 START_TEST (jot_resolve_logfmt_xfer_secs_test) {
2453 int res;
2454 cmd_rec *cmd;
2455 unsigned char logfmt[3];
2456
2457 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
2458 cmd->cmd_class = CL_MISC;
2459 logfmt[0] = LOGFMT_META_START;
2460 logfmt[1] = LOGFMT_META_SECONDS;
2461 logfmt[2] = 0;
2462
2463 /* First, without the sess.xfer.p pool. */
2464 mark_point();
2465 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
2466 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
2467 resolve_on_meta, resolve_on_default, resolve_on_other);
2468 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
2469 ck_assert_msg(resolve_on_meta_count == 0,
2470 "Expected on_meta count 0, got %u", resolve_on_meta_count);
2471 ck_assert_msg(resolve_on_default_count == 1,
2472 "Expected on_default count 1, got %u", resolve_on_default_count);
2473 ck_assert_msg(resolve_on_other_count == 0,
2474 "Expected on_other count 0, got %u", resolve_on_other_count);
2475
2476 /* Now, with the session.xfer.p pool, but no transfer times. */
2477 mark_point();
2478 session.xfer.p = p;
2479 session.xfer.start_time.tv_sec = session.xfer.start_time.tv_usec = 0;
2480 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
2481 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
2482 resolve_on_meta, resolve_on_default, resolve_on_other);
2483 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
2484 ck_assert_msg(resolve_on_meta_count == 0,
2485 "Expected on_meta count 0, got %u", resolve_on_meta_count);
2486 ck_assert_msg(resolve_on_default_count == 1,
2487 "Expected on_default count 1, got %u", resolve_on_default_count);
2488 ck_assert_msg(resolve_on_other_count == 0,
2489 "Expected on_other count 0, got %u", resolve_on_other_count);
2490
2491 mark_point();
2492 session.xfer.p = p;
2493 session.xfer.start_time.tv_sec = 0;
2494 session.xfer.start_time.tv_usec = 200000;
2495 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
2496 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
2497 resolve_on_meta, resolve_on_default, resolve_on_other);
2498 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
2499 ck_assert_msg(resolve_on_meta_count == 1,
2500 "Expected on_meta count 1, got %u", resolve_on_meta_count);
2501 ck_assert_msg(resolve_on_default_count == 0,
2502 "Expected on_default count 0, got %u", resolve_on_default_count);
2503 ck_assert_msg(resolve_on_other_count == 0,
2504 "Expected on_other count 0, got %u", resolve_on_other_count);
2505
2506 mark_point();
2507 session.xfer.p = p;
2508 session.xfer.start_time.tv_sec = 20;
2509 session.xfer.start_time.tv_usec = 200;
2510 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
2511 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
2512 resolve_on_meta, resolve_on_default, resolve_on_other);
2513 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
2514 ck_assert_msg(resolve_on_meta_count == 1,
2515 "Expected on_meta count 1, got %u", resolve_on_meta_count);
2516 ck_assert_msg(resolve_on_default_count == 0,
2517 "Expected on_default count 0, got %u", resolve_on_default_count);
2518 ck_assert_msg(resolve_on_other_count == 0,
2519 "Expected on_other count 0, got %u", resolve_on_other_count);
2520
2521 session.xfer.p = NULL;
2522 session.xfer.start_time.tv_sec = session.xfer.start_time.tv_usec = 0;
2523 }
2524 END_TEST
2525
2526 START_TEST (jot_resolve_logfmt_xfer_ms_test) {
2527 int res;
2528 cmd_rec *cmd;
2529 unsigned char logfmt[3];
2530
2531 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
2532 cmd->cmd_class = CL_MISC;
2533 logfmt[0] = LOGFMT_META_START;
2534 logfmt[1] = LOGFMT_META_XFER_MS;
2535 logfmt[2] = 0;
2536
2537 /* First, without the sess.xfer.p pool. */
2538 mark_point();
2539 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
2540 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
2541 resolve_on_meta, resolve_on_default, resolve_on_other);
2542 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
2543 ck_assert_msg(resolve_on_meta_count == 0,
2544 "Expected on_meta count 0, got %u", resolve_on_meta_count);
2545 ck_assert_msg(resolve_on_default_count == 1,
2546 "Expected on_default count 1, got %u", resolve_on_default_count);
2547 ck_assert_msg(resolve_on_other_count == 0,
2548 "Expected on_other count 0, got %u", resolve_on_other_count);
2549
2550 /* Now, with the session.xfer.p pool, but no transfer times. */
2551 mark_point();
2552 session.xfer.p = p;
2553 session.xfer.start_time.tv_sec = session.xfer.start_time.tv_usec = 0;
2554 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
2555 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
2556 resolve_on_meta, resolve_on_default, resolve_on_other);
2557 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
2558 ck_assert_msg(resolve_on_meta_count == 0,
2559 "Expected on_meta count 0, got %u", resolve_on_meta_count);
2560 ck_assert_msg(resolve_on_default_count == 1,
2561 "Expected on_default count 1, got %u", resolve_on_default_count);
2562 ck_assert_msg(resolve_on_other_count == 0,
2563 "Expected on_other count 0, got %u", resolve_on_other_count);
2564
2565 mark_point();
2566 session.xfer.p = p;
2567 session.xfer.start_time.tv_sec = 0;
2568 session.xfer.start_time.tv_usec = 200000;
2569 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
2570 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
2571 resolve_on_meta, resolve_on_default, resolve_on_other);
2572 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
2573 ck_assert_msg(resolve_on_meta_count == 1,
2574 "Expected on_meta count 1, got %u", resolve_on_meta_count);
2575 ck_assert_msg(resolve_on_default_count == 0,
2576 "Expected on_default count 0, got %u", resolve_on_default_count);
2577 ck_assert_msg(resolve_on_other_count == 0,
2578 "Expected on_other count 0, got %u", resolve_on_other_count);
2579
2580 mark_point();
2581 session.xfer.p = p;
2582 session.xfer.start_time.tv_sec = 20;
2583 session.xfer.start_time.tv_usec = 200;
2584 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
2585 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
2586 resolve_on_meta, resolve_on_default, resolve_on_other);
2587 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
2588 ck_assert_msg(resolve_on_meta_count == 1,
2589 "Expected on_meta count 1, got %u", resolve_on_meta_count);
2590 ck_assert_msg(resolve_on_default_count == 0,
2591 "Expected on_default count 0, got %u", resolve_on_default_count);
2592 ck_assert_msg(resolve_on_other_count == 0,
2593 "Expected on_other count 0, got %u", resolve_on_other_count);
2594
2595 session.xfer.p = NULL;
2596 session.xfer.start_time.tv_sec = session.xfer.start_time.tv_usec = 0;
2597 }
2598 END_TEST
2599
2600 START_TEST (jot_resolve_logfmt_command_test) {
2601 int res;
2602 cmd_rec *cmd;
2603 unsigned char logfmt[3];
2604
2605 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
2606 logfmt[0] = LOGFMT_META_START;
2607 logfmt[1] = LOGFMT_META_COMMAND;
2608 logfmt[2] = 0;
2609
2610 mark_point();
2611 cmd->cmd_class = CL_CONNECT;
2612 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
2613 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
2614 resolve_on_meta, resolve_on_default, resolve_on_other);
2615 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
2616 ck_assert_msg(resolve_on_meta_count == 0,
2617 "Expected on_meta count 0, got %u", resolve_on_meta_count);
2618 ck_assert_msg(resolve_on_default_count == 1,
2619 "Expected on_default count 1, got %u", resolve_on_default_count);
2620 ck_assert_msg(resolve_on_other_count == 0,
2621 "Expected on_other count 0, got %u", resolve_on_other_count);
2622
2623 mark_point();
2624 cmd->cmd_class = CL_DISCONNECT;
2625 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
2626 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
2627 resolve_on_meta, resolve_on_default, resolve_on_other);
2628 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
2629 ck_assert_msg(resolve_on_meta_count == 0,
2630 "Expected on_meta count 0, got %u", resolve_on_meta_count);
2631 ck_assert_msg(resolve_on_default_count == 1,
2632 "Expected on_default count 1, got %u", resolve_on_default_count);
2633 ck_assert_msg(resolve_on_other_count == 0,
2634 "Expected on_other count 0, got %u", resolve_on_other_count);
2635
2636 mark_point();
2637 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "PASS"));
2638 cmd->cmd_class = CL_AUTH;
2639 session.hide_password = TRUE;
2640 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
2641 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
2642 resolve_on_meta, resolve_on_default, resolve_on_other);
2643 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
2644 ck_assert_msg(resolve_on_meta_count == 1,
2645 "Expected on_meta count 1, got %u", resolve_on_meta_count);
2646 ck_assert_msg(resolve_on_default_count == 0,
2647 "Expected on_default count 0, got %u", resolve_on_default_count);
2648 ck_assert_msg(resolve_on_other_count == 0,
2649 "Expected on_other count 0, got %u", resolve_on_other_count);
2650
2651 mark_point();
2652 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "PASS"));
2653 cmd->cmd_class = CL_AUTH;
2654 session.hide_password = FALSE;
2655 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
2656 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
2657 resolve_on_meta, resolve_on_default, resolve_on_other);
2658 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
2659 ck_assert_msg(resolve_on_meta_count == 1,
2660 "Expected on_meta count 1, got %u", resolve_on_meta_count);
2661 ck_assert_msg(resolve_on_default_count == 0,
2662 "Expected on_default count 0, got %u", resolve_on_default_count);
2663 ck_assert_msg(resolve_on_other_count == 0,
2664 "Expected on_other count 0, got %u", resolve_on_other_count);
2665
2666 mark_point();
2667 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "ADAT"));
2668 cmd->cmd_class = CL_SEC;
2669 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
2670 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
2671 resolve_on_meta, resolve_on_default, resolve_on_other);
2672 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
2673 ck_assert_msg(resolve_on_meta_count == 1,
2674 "Expected on_meta count 1, got %u", resolve_on_meta_count);
2675 ck_assert_msg(resolve_on_default_count == 0,
2676 "Expected on_default count 0, got %u", resolve_on_default_count);
2677 ck_assert_msg(resolve_on_other_count == 0,
2678 "Expected on_other count 0, got %u", resolve_on_other_count);
2679
2680 mark_point();
2681 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
2682 cmd->cmd_class = CL_MISC;
2683 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
2684 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
2685 resolve_on_meta, resolve_on_default, resolve_on_other);
2686 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
2687 ck_assert_msg(resolve_on_meta_count == 1,
2688 "Expected on_meta count 1, got %u", resolve_on_meta_count);
2689 ck_assert_msg(resolve_on_default_count == 0,
2690 "Expected on_default count 0, got %u", resolve_on_default_count);
2691 ck_assert_msg(resolve_on_other_count == 0,
2692 "Expected on_other count 0, got %u", resolve_on_other_count);
2693 }
2694 END_TEST
2695
2696 START_TEST (jot_resolve_logfmt_local_name_test) {
2697 int res;
2698 cmd_rec *cmd;
2699 server_rec *server;
2700 unsigned char logfmt[3];
2701
2702 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
2703 cmd->cmd_class = CL_MISC;
2704 logfmt[0] = LOGFMT_META_START;
2705 logfmt[1] = LOGFMT_META_LOCAL_NAME;
2706 logfmt[2] = 0;
2707
2708 mark_point();
2709 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
2710 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
2711 resolve_on_meta, resolve_on_default, resolve_on_other);
2712 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
2713 ck_assert_msg(resolve_on_meta_count == 0,
2714 "Expected on_meta count 0, got %u", resolve_on_meta_count);
2715 ck_assert_msg(resolve_on_default_count == 1,
2716 "Expected on_default count 1, got %u", resolve_on_default_count);
2717 ck_assert_msg(resolve_on_other_count == 0,
2718 "Expected on_other count 0, got %u", resolve_on_other_count);
2719
2720 mark_point();
2721 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
2722 server = pcalloc(p, sizeof(server_rec));
2723 server->ServerName = "FOOBAR";
2724 cmd->server = server;
2725 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
2726 resolve_on_meta, resolve_on_default, resolve_on_other);
2727 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
2728 ck_assert_msg(resolve_on_meta_count == 1,
2729 "Expected on_meta count 1, got %u", resolve_on_meta_count);
2730 ck_assert_msg(resolve_on_default_count == 0,
2731 "Expected on_default count 0, got %u", resolve_on_default_count);
2732 ck_assert_msg(resolve_on_other_count == 0,
2733 "Expected on_other count 0, got %u", resolve_on_other_count);
2734 }
2735 END_TEST
2736
2737 START_TEST (jot_resolve_logfmt_local_port_test) {
2738 int res;
2739 cmd_rec *cmd;
2740 server_rec *server;
2741 unsigned char logfmt[3];
2742
2743 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
2744 cmd->cmd_class = CL_MISC;
2745 logfmt[0] = LOGFMT_META_START;
2746 logfmt[1] = LOGFMT_META_LOCAL_PORT;
2747 logfmt[2] = 0;
2748
2749 mark_point();
2750 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
2751 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
2752 resolve_on_meta, resolve_on_default, resolve_on_other);
2753 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
2754 ck_assert_msg(resolve_on_meta_count == 0,
2755 "Expected on_meta count 0, got %u", resolve_on_meta_count);
2756 ck_assert_msg(resolve_on_default_count == 1,
2757 "Expected on_default count 1, got %u", resolve_on_default_count);
2758 ck_assert_msg(resolve_on_other_count == 0,
2759 "Expected on_other count 0, got %u", resolve_on_other_count);
2760
2761 mark_point();
2762 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
2763 server = pcalloc(p, sizeof(server_rec));
2764 server->ServerPort = 2121;
2765 cmd->server = server;
2766 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
2767 resolve_on_meta, resolve_on_default, resolve_on_other);
2768 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
2769 ck_assert_msg(resolve_on_meta_count == 1,
2770 "Expected on_meta count 1, got %u", resolve_on_meta_count);
2771 ck_assert_msg(resolve_on_default_count == 0,
2772 "Expected on_default count 0, got %u", resolve_on_default_count);
2773 ck_assert_msg(resolve_on_other_count == 0,
2774 "Expected on_other count 0, got %u", resolve_on_other_count);
2775 }
2776 END_TEST
2777
2778 START_TEST (jot_resolve_logfmt_user_test) {
2779 int res;
2780 cmd_rec *cmd;
2781 unsigned char logfmt[3];
2782
2783 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
2784 cmd->cmd_class = CL_MISC;
2785 logfmt[0] = LOGFMT_META_START;
2786 logfmt[1] = LOGFMT_META_USER;
2787 logfmt[2] = 0;
2788
2789 mark_point();
2790 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
2791 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
2792 resolve_on_meta, resolve_on_default, resolve_on_other);
2793 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
2794 ck_assert_msg(resolve_on_meta_count == 0,
2795 "Expected on_meta count 0, got %u", resolve_on_meta_count);
2796 ck_assert_msg(resolve_on_default_count == 1,
2797 "Expected on_default count 1, got %u", resolve_on_default_count);
2798 ck_assert_msg(resolve_on_other_count == 0,
2799 "Expected on_other count 0, got %u", resolve_on_other_count);
2800
2801 mark_point();
2802 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
2803 session.user = "FOOBAR";
2804 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
2805 resolve_on_meta, resolve_on_default, resolve_on_other);
2806 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
2807 ck_assert_msg(resolve_on_meta_count == 1,
2808 "Expected on_meta count 1, got %u", resolve_on_meta_count);
2809 ck_assert_msg(resolve_on_default_count == 0,
2810 "Expected on_default count 0, got %u", resolve_on_default_count);
2811 ck_assert_msg(resolve_on_other_count == 0,
2812 "Expected on_other count 0, got %u", resolve_on_other_count);
2813
2814 session.user = NULL;
2815 }
2816 END_TEST
2817
2818 START_TEST (jot_resolve_logfmt_uid_test) {
2819 int res;
2820 cmd_rec *cmd;
2821 unsigned char logfmt[3];
2822
2823 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
2824 cmd->cmd_class = CL_MISC;
2825 logfmt[0] = LOGFMT_META_START;
2826 logfmt[1] = LOGFMT_META_UID;
2827 logfmt[2] = 0;
2828
2829 mark_point();
2830 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
2831 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
2832 resolve_on_meta, resolve_on_default, resolve_on_other);
2833 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
2834 ck_assert_msg(resolve_on_meta_count == 1,
2835 "Expected on_meta count 1, got %u", resolve_on_meta_count);
2836 ck_assert_msg(resolve_on_default_count == 0,
2837 "Expected on_default count 0, got %u", resolve_on_default_count);
2838 ck_assert_msg(resolve_on_other_count == 0,
2839 "Expected on_other count 0, got %u", resolve_on_other_count);
2840
2841 mark_point();
2842 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
2843 session.auth_mech = "mod_auth_file.c";
2844 session.login_uid = 400;
2845 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
2846 resolve_on_meta, resolve_on_default, resolve_on_other);
2847 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
2848 ck_assert_msg(resolve_on_meta_count == 1,
2849 "Expected on_meta count 1, got %u", resolve_on_meta_count);
2850 ck_assert_msg(resolve_on_default_count == 0,
2851 "Expected on_default count 0, got %u", resolve_on_default_count);
2852 ck_assert_msg(resolve_on_other_count == 0,
2853 "Expected on_other count 0, got %u", resolve_on_other_count);
2854
2855 session.auth_mech = NULL;
2856 session.login_uid = 0;
2857 }
2858 END_TEST
2859
2860 START_TEST (jot_resolve_logfmt_group_test) {
2861 int res;
2862 cmd_rec *cmd;
2863 unsigned char logfmt[3];
2864
2865 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
2866 cmd->cmd_class = CL_MISC;
2867 logfmt[0] = LOGFMT_META_START;
2868 logfmt[1] = LOGFMT_META_GROUP;
2869 logfmt[2] = 0;
2870
2871 mark_point();
2872 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
2873 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
2874 resolve_on_meta, resolve_on_default, resolve_on_other);
2875 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
2876 ck_assert_msg(resolve_on_meta_count == 0,
2877 "Expected on_meta count 0, got %u", resolve_on_meta_count);
2878 ck_assert_msg(resolve_on_default_count == 1,
2879 "Expected on_default count 1, got %u", resolve_on_default_count);
2880 ck_assert_msg(resolve_on_other_count == 0,
2881 "Expected on_other count 0, got %u", resolve_on_other_count);
2882
2883 mark_point();
2884 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
2885 session.group = "FOOBAR";
2886 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
2887 resolve_on_meta, resolve_on_default, resolve_on_other);
2888 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
2889 ck_assert_msg(resolve_on_meta_count == 1,
2890 "Expected on_meta count 1, got %u", resolve_on_meta_count);
2891 ck_assert_msg(resolve_on_default_count == 0,
2892 "Expected on_default count 0, got %u", resolve_on_default_count);
2893 ck_assert_msg(resolve_on_other_count == 0,
2894 "Expected on_other count 0, got %u", resolve_on_other_count);
2895
2896 session.group = NULL;
2897 }
2898 END_TEST
2899
2900 START_TEST (jot_resolve_logfmt_gid_test) {
2901 int res;
2902 cmd_rec *cmd;
2903 unsigned char logfmt[3];
2904
2905 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
2906 cmd->cmd_class = CL_MISC;
2907 logfmt[0] = LOGFMT_META_START;
2908 logfmt[1] = LOGFMT_META_GID;
2909 logfmt[2] = 0;
2910
2911 mark_point();
2912 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
2913 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
2914 resolve_on_meta, resolve_on_default, resolve_on_other);
2915 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
2916 ck_assert_msg(resolve_on_meta_count == 1,
2917 "Expected on_meta count 1, got %u", resolve_on_meta_count);
2918 ck_assert_msg(resolve_on_default_count == 0,
2919 "Expected on_default count 0, got %u", resolve_on_default_count);
2920 ck_assert_msg(resolve_on_other_count == 0,
2921 "Expected on_other count 0, got %u", resolve_on_other_count);
2922
2923 mark_point();
2924 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
2925 session.auth_mech = "mod_auth_file.c";
2926 session.login_gid = 400;
2927 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
2928 resolve_on_meta, resolve_on_default, resolve_on_other);
2929 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
2930 ck_assert_msg(resolve_on_meta_count == 1,
2931 "Expected on_meta count 1, got %u", resolve_on_meta_count);
2932 ck_assert_msg(resolve_on_default_count == 0,
2933 "Expected on_default count 0, got %u", resolve_on_default_count);
2934 ck_assert_msg(resolve_on_other_count == 0,
2935 "Expected on_other count 0, got %u", resolve_on_other_count);
2936
2937 session.auth_mech = NULL;
2938 session.login_gid = 0;
2939 }
2940 END_TEST
2941
2942 START_TEST (jot_resolve_logfmt_original_user_test) {
2943 int res;
2944 cmd_rec *cmd;
2945 unsigned char logfmt[3];
2946 char *orig_user;
2947
2948 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
2949 cmd->cmd_class = CL_MISC;
2950 logfmt[0] = LOGFMT_META_START;
2951 logfmt[1] = LOGFMT_META_ORIGINAL_USER;
2952 logfmt[2] = 0;
2953
2954 /* First, without the "mod_auth.orig-user" note. */
2955 mark_point();
2956 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
2957 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
2958 resolve_on_meta, resolve_on_default, resolve_on_other);
2959 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
2960 ck_assert_msg(resolve_on_meta_count == 0,
2961 "Expected on_meta count 0, got %u", resolve_on_meta_count);
2962 ck_assert_msg(resolve_on_default_count == 1,
2963 "Expected on_default count 1, got %u", resolve_on_default_count);
2964 ck_assert_msg(resolve_on_other_count == 0,
2965 "Expected on_other count 0, got %u", resolve_on_other_count);
2966
2967 /* Now, with the "mod_auth.orig-user" note. */
2968 mark_point();
2969 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
2970 orig_user = "FOOBAR";
2971 session.notes = pr_table_alloc(p, 0);
2972 pr_table_add_dup(session.notes, "mod_auth.orig-user", orig_user, 0);
2973 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
2974 resolve_on_meta, resolve_on_default, resolve_on_other);
2975 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
2976 ck_assert_msg(resolve_on_meta_count == 1,
2977 "Expected on_meta count 1, got %u", resolve_on_meta_count);
2978 ck_assert_msg(resolve_on_default_count == 0,
2979 "Expected on_default count 0, got %u", resolve_on_default_count);
2980 ck_assert_msg(resolve_on_other_count == 0,
2981 "Expected on_other count 0, got %u", resolve_on_other_count);
2982
2983 pr_table_empty(session.notes);
2984 pr_table_free(session.notes);
2985 session.notes = NULL;
2986 }
2987 END_TEST
2988
2989 START_TEST (jot_resolve_logfmt_response_code_test) {
2990 int res;
2991 cmd_rec *cmd;
2992 unsigned char logfmt[3];
2993
2994 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
2995 cmd->cmd_class = CL_MISC;
2996 logfmt[0] = LOGFMT_META_START;
2997 logfmt[1] = LOGFMT_META_RESPONSE_CODE;
2998 logfmt[2] = 0;
2999
3000 mark_point();
3001 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
3002 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3003 resolve_on_meta, resolve_on_default, resolve_on_other);
3004 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3005 ck_assert_msg(resolve_on_meta_count == 0,
3006 "Expected on_meta count 0, got %u", resolve_on_meta_count);
3007 ck_assert_msg(resolve_on_default_count == 1,
3008 "Expected on_default count 1, got %u", resolve_on_default_count);
3009 ck_assert_msg(resolve_on_other_count == 0,
3010 "Expected on_other count 0, got %u", resolve_on_other_count);
3011
3012 mark_point();
3013 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "QUIT"));
3014 cmd->cmd_class = CL_MISC;
3015 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
3016 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3017 resolve_on_meta, resolve_on_default, resolve_on_other);
3018 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3019 ck_assert_msg(resolve_on_meta_count == 1,
3020 "Expected on_meta count 1, got %u", resolve_on_meta_count);
3021 ck_assert_msg(resolve_on_default_count == 0,
3022 "Expected on_default count 0, got %u", resolve_on_default_count);
3023 ck_assert_msg(resolve_on_other_count == 0,
3024 "Expected on_other count 0, got %u", resolve_on_other_count);
3025
3026 mark_point();
3027 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
3028 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
3029 cmd->cmd_class = CL_MISC;
3030
3031 pr_response_set_pool(p);
3032 pr_response_add("200", "foo %s", "bar");
3033 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3034 resolve_on_meta, resolve_on_default, resolve_on_other);
3035 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3036 ck_assert_msg(resolve_on_meta_count == 1,
3037 "Expected on_meta count 1, got %u", resolve_on_meta_count);
3038 ck_assert_msg(resolve_on_default_count == 0,
3039 "Expected on_default count 0, got %u", resolve_on_default_count);
3040 ck_assert_msg(resolve_on_other_count == 0,
3041 "Expected on_other count 0, got %u", resolve_on_other_count);
3042
3043 pr_response_clear(&resp_list);
3044 pr_response_set_pool(NULL);
3045 }
3046 END_TEST
3047
3048 START_TEST (jot_resolve_logfmt_response_text_test) {
3049 int res;
3050 cmd_rec *cmd;
3051 unsigned char logfmt[3];
3052
3053 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
3054 cmd->cmd_class = CL_MISC;
3055 logfmt[0] = LOGFMT_META_START;
3056 logfmt[1] = LOGFMT_META_RESPONSE_STR;
3057 logfmt[2] = 0;
3058
3059 mark_point();
3060 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
3061 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3062 resolve_on_meta, resolve_on_default, resolve_on_other);
3063 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3064 ck_assert_msg(resolve_on_meta_count == 0,
3065 "Expected on_meta count 0, got %u", resolve_on_meta_count);
3066 ck_assert_msg(resolve_on_default_count == 1,
3067 "Expected on_default count 1, got %u", resolve_on_default_count);
3068 ck_assert_msg(resolve_on_other_count == 0,
3069 "Expected on_other count 0, got %u", resolve_on_other_count);
3070
3071 mark_point();
3072 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
3073
3074 pr_response_set_pool(p);
3075 pr_response_add("200", "foo %s", "bar");
3076 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3077 resolve_on_meta, resolve_on_default, resolve_on_other);
3078 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3079 ck_assert_msg(resolve_on_meta_count == 1,
3080 "Expected on_meta count 1, got %u", resolve_on_meta_count);
3081 ck_assert_msg(resolve_on_default_count == 0,
3082 "Expected on_default count 0, got %u", resolve_on_default_count);
3083 ck_assert_msg(resolve_on_other_count == 0,
3084 "Expected on_other count 0, got %u", resolve_on_other_count);
3085
3086 pr_response_clear(&resp_list);
3087 pr_response_set_pool(NULL);
3088 }
3089 END_TEST
3090
3091 START_TEST (jot_resolve_logfmt_response_ms_test) {
3092 int res;
3093 cmd_rec *cmd;
3094 unsigned char logfmt[3];
3095 uint64_t start_ms;
3096
3097 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
3098 cmd->cmd_class = CL_MISC;
3099 logfmt[0] = LOGFMT_META_START;
3100 logfmt[1] = LOGFMT_META_RESPONSE_MS;
3101 logfmt[2] = 0;
3102
3103 /* First, without the "start_ms" note. */
3104 mark_point();
3105 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
3106 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3107 resolve_on_meta, resolve_on_default, resolve_on_other);
3108 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3109 ck_assert_msg(resolve_on_meta_count == 0,
3110 "Expected on_meta count 0, got %u", resolve_on_meta_count);
3111 ck_assert_msg(resolve_on_default_count == 1,
3112 "Expected on_default count 1, got %u", resolve_on_default_count);
3113 ck_assert_msg(resolve_on_other_count == 0,
3114 "Expected on_other count 0, got %u", resolve_on_other_count);
3115
3116 /* Now, with the "start_ms" note. */
3117 mark_point();
3118 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
3119 start_ms = 123456;
3120 pr_table_add(cmd->notes, "start_ms", &start_ms, sizeof(start_ms));
3121 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3122 resolve_on_meta, resolve_on_default, resolve_on_other);
3123 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3124 ck_assert_msg(resolve_on_meta_count == 1,
3125 "Expected on_meta count 1, got %u", resolve_on_meta_count);
3126 ck_assert_msg(resolve_on_default_count == 0,
3127 "Expected on_default count 0, got %u", resolve_on_default_count);
3128 ck_assert_msg(resolve_on_other_count == 0,
3129 "Expected on_other count 0, got %u", resolve_on_other_count);
3130 }
3131 END_TEST
3132
3133 START_TEST (jot_resolve_logfmt_class_test) {
3134 int res;
3135 cmd_rec *cmd;
3136 unsigned char logfmt[3];
3137
3138 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
3139 cmd->cmd_class = CL_MISC;
3140 logfmt[0] = LOGFMT_META_START;
3141 logfmt[1] = LOGFMT_META_CLASS;
3142 logfmt[2] = 0;
3143
3144 mark_point();
3145 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
3146 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3147 resolve_on_meta, resolve_on_default, resolve_on_other);
3148 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3149 ck_assert_msg(resolve_on_meta_count == 0,
3150 "Expected on_meta count 0, got %u", resolve_on_meta_count);
3151 ck_assert_msg(resolve_on_default_count == 1,
3152 "Expected on_default count 1, got %u", resolve_on_default_count);
3153 ck_assert_msg(resolve_on_other_count == 0,
3154 "Expected on_other count 0, got %u", resolve_on_other_count);
3155
3156 mark_point();
3157 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
3158 session.conn_class = pcalloc(p, sizeof(pr_class_t));
3159 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3160 resolve_on_meta, resolve_on_default, resolve_on_other);
3161 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3162 ck_assert_msg(resolve_on_meta_count == 1,
3163 "Expected on_meta count 1, got %u", resolve_on_meta_count);
3164 ck_assert_msg(resolve_on_default_count == 0,
3165 "Expected on_default count 0, got %u", resolve_on_default_count);
3166 ck_assert_msg(resolve_on_other_count == 0,
3167 "Expected on_other count 0, got %u", resolve_on_other_count);
3168
3169 session.conn_class = NULL;
3170 }
3171 END_TEST
3172
3173 START_TEST (jot_resolve_logfmt_anon_passwd_test) {
3174 int res;
3175 cmd_rec *cmd;
3176 unsigned char logfmt[3];
3177 char *anon_passwd;
3178
3179 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
3180 cmd->cmd_class = CL_MISC;
3181 logfmt[0] = LOGFMT_META_START;
3182 logfmt[1] = LOGFMT_META_ANON_PASS;
3183 logfmt[2] = 0;
3184
3185 /* First, without the "mod_auth.anon-passwd" note. */
3186 mark_point();
3187 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
3188 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3189 resolve_on_meta, resolve_on_default, resolve_on_other);
3190 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3191 ck_assert_msg(resolve_on_meta_count == 0,
3192 "Expected on_meta count 0, got %u", resolve_on_meta_count);
3193 ck_assert_msg(resolve_on_default_count == 1,
3194 "Expected on_default count 1, got %u", resolve_on_default_count);
3195 ck_assert_msg(resolve_on_other_count == 0,
3196 "Expected on_other count 0, got %u", resolve_on_other_count);
3197
3198 /* Now, with the "mod_auth.anon-passwd" note. */
3199 mark_point();
3200 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
3201 anon_passwd = "FOOBAR";
3202 session.notes = pr_table_alloc(p, 0);
3203 pr_table_add_dup(session.notes, "mod_auth.anon-passwd", anon_passwd, 0);
3204 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3205 resolve_on_meta, resolve_on_default, resolve_on_other);
3206 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3207 ck_assert_msg(resolve_on_meta_count == 1,
3208 "Expected on_meta count 1, got %u", resolve_on_meta_count);
3209 ck_assert_msg(resolve_on_default_count == 0,
3210 "Expected on_default count 0, got %u", resolve_on_default_count);
3211 ck_assert_msg(resolve_on_other_count == 0,
3212 "Expected on_other count 0, got %u", resolve_on_other_count);
3213
3214 pr_table_empty(session.notes);
3215 pr_table_free(session.notes);
3216 session.notes = NULL;
3217 }
3218 END_TEST
3219
3220 START_TEST (jot_resolve_logfmt_method_test) {
3221 int res;
3222 cmd_rec *cmd;
3223 unsigned char logfmt[3];
3224
3225 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
3226 cmd->cmd_class = CL_CONNECT;
3227 logfmt[0] = LOGFMT_META_START;
3228 logfmt[1] = LOGFMT_META_METHOD;
3229 logfmt[2] = 0;
3230
3231 mark_point();
3232 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
3233 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3234 resolve_on_meta, resolve_on_default, resolve_on_other);
3235 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3236 ck_assert_msg(resolve_on_meta_count == 0,
3237 "Expected on_meta count 0, got %u", resolve_on_meta_count);
3238 ck_assert_msg(resolve_on_default_count == 1,
3239 "Expected on_default count 1, got %u", resolve_on_default_count);
3240 ck_assert_msg(resolve_on_other_count == 0,
3241 "Expected on_other count 0, got %u", resolve_on_other_count);
3242
3243 mark_point();
3244 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
3245 cmd->cmd_class = CL_MISC;
3246 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3247 resolve_on_meta, resolve_on_default, resolve_on_other);
3248 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3249 ck_assert_msg(resolve_on_meta_count == 1,
3250 "Expected on_meta count 1, got %u", resolve_on_meta_count);
3251 ck_assert_msg(resolve_on_default_count == 0,
3252 "Expected on_default count 0, got %u", resolve_on_default_count);
3253 ck_assert_msg(resolve_on_other_count == 0,
3254 "Expected on_other count 0, got %u", resolve_on_other_count);
3255
3256 mark_point();
3257 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
3258 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "SITE"));
3259 cmd->cmd_class = CL_MISC;
3260 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3261 resolve_on_meta, resolve_on_default, resolve_on_other);
3262 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3263 ck_assert_msg(resolve_on_meta_count == 0,
3264 "Expected on_meta count 0, got %u", resolve_on_meta_count);
3265 ck_assert_msg(resolve_on_default_count == 1,
3266 "Expected on_default count 1, got %u", resolve_on_default_count);
3267 ck_assert_msg(resolve_on_other_count == 0,
3268 "Expected on_other count 0, got %u", resolve_on_other_count);
3269
3270 mark_point();
3271 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
3272 cmd = pr_cmd_alloc(p, 2, pstrdup(p, "SITE"), pstrdup(p, "foobar"));
3273 cmd->cmd_class = CL_MISC;
3274 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3275 resolve_on_meta, resolve_on_default, resolve_on_other);
3276 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3277 ck_assert_msg(resolve_on_meta_count == 1,
3278 "Expected on_meta count 1, got %u", resolve_on_meta_count);
3279 ck_assert_msg(resolve_on_default_count == 0,
3280 "Expected on_default count 0, got %u", resolve_on_default_count);
3281 ck_assert_msg(resolve_on_other_count == 0,
3282 "Expected on_other count 0, got %u", resolve_on_other_count);
3283 }
3284 END_TEST
3285
3286 START_TEST (jot_resolve_logfmt_xfer_path_test) {
3287 int res;
3288 cmd_rec *cmd;
3289 unsigned char logfmt[3];
3290
3291 logfmt[0] = LOGFMT_META_START;
3292 logfmt[1] = LOGFMT_META_XFER_PATH;
3293 logfmt[2] = 0;
3294
3295 mark_point();
3296 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
3297 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
3298 cmd->cmd_class = CL_MISC;
3299 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3300 resolve_on_meta, resolve_on_default, resolve_on_other);
3301 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3302 ck_assert_msg(resolve_on_meta_count == 0,
3303 "Expected on_meta count 0, got %u", resolve_on_meta_count);
3304 ck_assert_msg(resolve_on_default_count == 1,
3305 "Expected on_default count 1, got %u", resolve_on_default_count);
3306 ck_assert_msg(resolve_on_other_count == 0,
3307 "Expected on_other count 0, got %u", resolve_on_other_count);
3308
3309 mark_point();
3310 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
3311 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "RNTO"));
3312 cmd->cmd_class = CL_MISC;
3313 cmd->arg = pstrdup(p, "foo");
3314 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3315 resolve_on_meta, resolve_on_default, resolve_on_other);
3316 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3317 ck_assert_msg(resolve_on_meta_count == 1,
3318 "Expected on_meta count 1, got %u", resolve_on_meta_count);
3319 ck_assert_msg(resolve_on_default_count == 0,
3320 "Expected on_default count 0, got %u", resolve_on_default_count);
3321 ck_assert_msg(resolve_on_other_count == 0,
3322 "Expected on_other count 0, got %u", resolve_on_other_count);
3323
3324 mark_point();
3325 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
3326 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
3327 cmd->cmd_class = CL_MISC;
3328 session.xfer.p = p;
3329 session.xfer.path = pstrdup(p, "foo/bar");
3330 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3331 resolve_on_meta, resolve_on_default, resolve_on_other);
3332 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3333 ck_assert_msg(resolve_on_meta_count == 1,
3334 "Expected on_meta count 1, got %u", resolve_on_meta_count);
3335 ck_assert_msg(resolve_on_default_count == 0,
3336 "Expected on_default count 0, got %u", resolve_on_default_count);
3337 ck_assert_msg(resolve_on_other_count == 0,
3338 "Expected on_other count 0, got %u", resolve_on_other_count);
3339
3340 session.xfer.p = NULL;
3341 session.xfer.path = NULL;
3342
3343 mark_point();
3344 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
3345 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "DELE"));
3346 cmd->cmd_class = CL_MISC;
3347 cmd->arg = pstrdup(p, "foo/bar");
3348 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3349 resolve_on_meta, resolve_on_default, resolve_on_other);
3350 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3351 ck_assert_msg(resolve_on_meta_count == 1,
3352 "Expected on_meta count 1, got %u", resolve_on_meta_count);
3353 ck_assert_msg(resolve_on_default_count == 0,
3354 "Expected on_default count 0, got %u", resolve_on_default_count);
3355 ck_assert_msg(resolve_on_other_count == 0,
3356 "Expected on_other count 0, got %u", resolve_on_other_count);
3357
3358 mark_point();
3359 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
3360 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "MKD"));
3361 cmd->cmd_class = CL_MISC;
3362 cmd->arg = pstrdup(p, "foo/bar");
3363 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3364 resolve_on_meta, resolve_on_default, resolve_on_other);
3365 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3366 ck_assert_msg(resolve_on_meta_count == 1,
3367 "Expected on_meta count 1, got %u", resolve_on_meta_count);
3368 ck_assert_msg(resolve_on_default_count == 0,
3369 "Expected on_default count 0, got %u", resolve_on_default_count);
3370 ck_assert_msg(resolve_on_other_count == 0,
3371 "Expected on_other count 0, got %u", resolve_on_other_count);
3372
3373 mark_point();
3374 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
3375 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "XMKD"));
3376 cmd->cmd_class = CL_MISC;
3377 cmd->arg = pstrdup(p, "foo/bar");
3378 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3379 resolve_on_meta, resolve_on_default, resolve_on_other);
3380 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3381 ck_assert_msg(resolve_on_meta_count == 1,
3382 "Expected on_meta count 1, got %u", resolve_on_meta_count);
3383 ck_assert_msg(resolve_on_default_count == 0,
3384 "Expected on_default count 0, got %u", resolve_on_default_count);
3385 ck_assert_msg(resolve_on_other_count == 0,
3386 "Expected on_other count 0, got %u", resolve_on_other_count);
3387
3388 mark_point();
3389 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
3390 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "RMD"));
3391 cmd->cmd_class = CL_MISC;
3392 cmd->arg = pstrdup(p, "foo/bar");
3393 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3394 resolve_on_meta, resolve_on_default, resolve_on_other);
3395 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3396 ck_assert_msg(resolve_on_meta_count == 1,
3397 "Expected on_meta count 1, got %u", resolve_on_meta_count);
3398 ck_assert_msg(resolve_on_default_count == 0,
3399 "Expected on_default count 0, got %u", resolve_on_default_count);
3400 ck_assert_msg(resolve_on_other_count == 0,
3401 "Expected on_other count 0, got %u", resolve_on_other_count);
3402
3403 mark_point();
3404 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
3405 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "XRMD"));
3406 cmd->cmd_class = CL_MISC;
3407 cmd->arg = pstrdup(p, "foo/bar");
3408 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3409 resolve_on_meta, resolve_on_default, resolve_on_other);
3410 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3411 ck_assert_msg(resolve_on_meta_count == 1,
3412 "Expected on_meta count 1, got %u", resolve_on_meta_count);
3413 ck_assert_msg(resolve_on_default_count == 0,
3414 "Expected on_default count 0, got %u", resolve_on_default_count);
3415 ck_assert_msg(resolve_on_other_count == 0,
3416 "Expected on_other count 0, got %u", resolve_on_other_count);
3417 }
3418 END_TEST
3419
3420 START_TEST (jot_resolve_logfmt_xfer_port_test) {
3421 int res;
3422 cmd_rec *cmd;
3423 unsigned char logfmt[3];
3424
3425 logfmt[0] = LOGFMT_META_START;
3426 logfmt[1] = LOGFMT_META_XFER_PORT;
3427 logfmt[2] = 0;
3428
3429 mark_point();
3430 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
3431 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
3432 cmd->cmd_class = CL_MISC;
3433 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3434 resolve_on_meta, resolve_on_default, resolve_on_other);
3435 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3436 ck_assert_msg(resolve_on_meta_count == 0,
3437 "Expected on_meta count 0, got %u", resolve_on_meta_count);
3438 ck_assert_msg(resolve_on_default_count == 1,
3439 "Expected on_default count 1, got %u", resolve_on_default_count);
3440 ck_assert_msg(resolve_on_other_count == 0,
3441 "Expected on_other count 0, got %u", resolve_on_other_count);
3442
3443 mark_point();
3444 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
3445 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "PASV"));
3446 cmd->cmd_class = CL_MISC;
3447 session.data_port = 7777;
3448 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3449 resolve_on_meta, resolve_on_default, resolve_on_other);
3450 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3451 ck_assert_msg(resolve_on_meta_count == 1,
3452 "Expected on_meta count 1, got %u", resolve_on_meta_count);
3453 ck_assert_msg(resolve_on_default_count == 0,
3454 "Expected on_default count 0, got %u", resolve_on_default_count);
3455 ck_assert_msg(resolve_on_other_count == 0,
3456 "Expected on_other count 0, got %u", resolve_on_other_count);
3457
3458 mark_point();
3459 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
3460 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "PORT"));
3461 cmd->cmd_class = CL_MISC;
3462 session.data_port = 7777;
3463 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3464 resolve_on_meta, resolve_on_default, resolve_on_other);
3465 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3466 ck_assert_msg(resolve_on_meta_count == 1,
3467 "Expected on_meta count 1, got %u", resolve_on_meta_count);
3468 ck_assert_msg(resolve_on_default_count == 0,
3469 "Expected on_default count 0, got %u", resolve_on_default_count);
3470 ck_assert_msg(resolve_on_other_count == 0,
3471 "Expected on_other count 0, got %u", resolve_on_other_count);
3472
3473 mark_point();
3474 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
3475 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "EPRT"));
3476 cmd->cmd_class = CL_MISC;
3477 session.data_port = 7777;
3478 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3479 resolve_on_meta, resolve_on_default, resolve_on_other);
3480 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3481 ck_assert_msg(resolve_on_meta_count == 1,
3482 "Expected on_meta count 1, got %u", resolve_on_meta_count);
3483 ck_assert_msg(resolve_on_default_count == 0,
3484 "Expected on_default count 0, got %u", resolve_on_default_count);
3485 ck_assert_msg(resolve_on_other_count == 0,
3486 "Expected on_other count 0, got %u", resolve_on_other_count);
3487
3488 mark_point();
3489 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
3490 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "EPSV"));
3491 cmd->cmd_class = CL_MISC;
3492 session.data_port = 7777;
3493 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3494 resolve_on_meta, resolve_on_default, resolve_on_other);
3495 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3496 ck_assert_msg(resolve_on_meta_count == 1,
3497 "Expected on_meta count 1, got %u", resolve_on_meta_count);
3498 ck_assert_msg(resolve_on_default_count == 0,
3499 "Expected on_default count 0, got %u", resolve_on_default_count);
3500 ck_assert_msg(resolve_on_other_count == 0,
3501 "Expected on_other count 0, got %u", resolve_on_other_count);
3502
3503 mark_point();
3504 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
3505 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "APPE"));
3506 cmd->cmd_class = CL_MISC;
3507 session.data_port = 7777;
3508 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3509 resolve_on_meta, resolve_on_default, resolve_on_other);
3510 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3511 ck_assert_msg(resolve_on_meta_count == 1,
3512 "Expected on_meta count 1, got %u", resolve_on_meta_count);
3513 ck_assert_msg(resolve_on_default_count == 0,
3514 "Expected on_default count 0, got %u", resolve_on_default_count);
3515 ck_assert_msg(resolve_on_other_count == 0,
3516 "Expected on_other count 0, got %u", resolve_on_other_count);
3517
3518 mark_point();
3519 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
3520 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "LIST"));
3521 cmd->cmd_class = CL_MISC;
3522 session.data_port = 7777;
3523 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3524 resolve_on_meta, resolve_on_default, resolve_on_other);
3525 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3526 ck_assert_msg(resolve_on_meta_count == 1,
3527 "Expected on_meta count 1, got %u", resolve_on_meta_count);
3528 ck_assert_msg(resolve_on_default_count == 0,
3529 "Expected on_default count 0, got %u", resolve_on_default_count);
3530 ck_assert_msg(resolve_on_other_count == 0,
3531 "Expected on_other count 0, got %u", resolve_on_other_count);
3532
3533 mark_point();
3534 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
3535 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "MLSD"));
3536 cmd->cmd_class = CL_MISC;
3537 session.data_port = 7777;
3538 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3539 resolve_on_meta, resolve_on_default, resolve_on_other);
3540 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3541 ck_assert_msg(resolve_on_meta_count == 1,
3542 "Expected on_meta count 1, got %u", resolve_on_meta_count);
3543 ck_assert_msg(resolve_on_default_count == 0,
3544 "Expected on_default count 0, got %u", resolve_on_default_count);
3545 ck_assert_msg(resolve_on_other_count == 0,
3546 "Expected on_other count 0, got %u", resolve_on_other_count);
3547
3548 mark_point();
3549 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
3550 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "NLST"));
3551 cmd->cmd_class = CL_MISC;
3552 session.data_port = 7777;
3553 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3554 resolve_on_meta, resolve_on_default, resolve_on_other);
3555 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3556 ck_assert_msg(resolve_on_meta_count == 1,
3557 "Expected on_meta count 1, got %u", resolve_on_meta_count);
3558 ck_assert_msg(resolve_on_default_count == 0,
3559 "Expected on_default count 0, got %u", resolve_on_default_count);
3560 ck_assert_msg(resolve_on_other_count == 0,
3561 "Expected on_other count 0, got %u", resolve_on_other_count);
3562
3563 mark_point();
3564 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
3565 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "RETR"));
3566 cmd->cmd_class = CL_MISC;
3567 session.data_port = 7777;
3568 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3569 resolve_on_meta, resolve_on_default, resolve_on_other);
3570 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3571 ck_assert_msg(resolve_on_meta_count == 1,
3572 "Expected on_meta count 1, got %u", resolve_on_meta_count);
3573 ck_assert_msg(resolve_on_default_count == 0,
3574 "Expected on_default count 0, got %u", resolve_on_default_count);
3575 ck_assert_msg(resolve_on_other_count == 0,
3576 "Expected on_other count 0, got %u", resolve_on_other_count);
3577
3578 mark_point();
3579 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
3580 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "STOR"));
3581 cmd->cmd_class = CL_MISC;
3582 session.data_port = 7777;
3583 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3584 resolve_on_meta, resolve_on_default, resolve_on_other);
3585 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3586 ck_assert_msg(resolve_on_meta_count == 1,
3587 "Expected on_meta count 1, got %u", resolve_on_meta_count);
3588 ck_assert_msg(resolve_on_default_count == 0,
3589 "Expected on_default count 0, got %u", resolve_on_default_count);
3590 ck_assert_msg(resolve_on_other_count == 0,
3591 "Expected on_other count 0, got %u", resolve_on_other_count);
3592
3593 mark_point();
3594 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
3595 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "STOU"));
3596 cmd->cmd_class = CL_MISC;
3597 session.data_port = 7777;
3598 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3599 resolve_on_meta, resolve_on_default, resolve_on_other);
3600 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3601 ck_assert_msg(resolve_on_meta_count == 1,
3602 "Expected on_meta count 1, got %u", resolve_on_meta_count);
3603 ck_assert_msg(resolve_on_default_count == 0,
3604 "Expected on_default count 0, got %u", resolve_on_default_count);
3605 ck_assert_msg(resolve_on_other_count == 0,
3606 "Expected on_other count 0, got %u", resolve_on_other_count);
3607
3608 session.data_port = 0;
3609 }
3610 END_TEST
3611
3612 START_TEST (jot_resolve_logfmt_xfer_type_test) {
3613 int res;
3614 cmd_rec *cmd;
3615 unsigned char logfmt[3];
3616
3617 logfmt[0] = LOGFMT_META_START;
3618 logfmt[1] = LOGFMT_META_XFER_TYPE;
3619 logfmt[2] = 0;
3620
3621 mark_point();
3622 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
3623 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
3624 cmd->cmd_class = CL_MISC;
3625 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3626 resolve_on_meta, resolve_on_default, resolve_on_other);
3627 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3628 ck_assert_msg(resolve_on_meta_count == 0,
3629 "Expected on_meta count 0, got %u", resolve_on_meta_count);
3630 ck_assert_msg(resolve_on_default_count == 1,
3631 "Expected on_default count 1, got %u", resolve_on_default_count);
3632 ck_assert_msg(resolve_on_other_count == 0,
3633 "Expected on_other count 0, got %u", resolve_on_other_count);
3634
3635 mark_point();
3636 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
3637 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "APPE"));
3638 cmd->cmd_class = CL_MISC;
3639 session.sf_flags = SF_ASCII;
3640 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3641 resolve_on_meta, resolve_on_default, resolve_on_other);
3642 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3643 ck_assert_msg(resolve_on_meta_count == 1,
3644 "Expected on_meta count 1, got %u", resolve_on_meta_count);
3645 ck_assert_msg(resolve_on_default_count == 0,
3646 "Expected on_default count 0, got %u", resolve_on_default_count);
3647 ck_assert_msg(resolve_on_other_count == 0,
3648 "Expected on_other count 0, got %u", resolve_on_other_count);
3649
3650 mark_point();
3651 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
3652 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "LIST"));
3653 cmd->cmd_class = CL_MISC;
3654 session.sf_flags = SF_ASCII_OVERRIDE;
3655 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3656 resolve_on_meta, resolve_on_default, resolve_on_other);
3657 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3658 ck_assert_msg(resolve_on_meta_count == 1,
3659 "Expected on_meta count 1, got %u", resolve_on_meta_count);
3660 ck_assert_msg(resolve_on_default_count == 0,
3661 "Expected on_default count 0, got %u", resolve_on_default_count);
3662 ck_assert_msg(resolve_on_other_count == 0,
3663 "Expected on_other count 0, got %u", resolve_on_other_count);
3664
3665 session.sf_flags = 0;
3666
3667 mark_point();
3668 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
3669 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "MLSD"));
3670 cmd->cmd_class = CL_MISC;
3671 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3672 resolve_on_meta, resolve_on_default, resolve_on_other);
3673 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3674 ck_assert_msg(resolve_on_meta_count == 1,
3675 "Expected on_meta count 1, got %u", resolve_on_meta_count);
3676 ck_assert_msg(resolve_on_default_count == 0,
3677 "Expected on_default count 0, got %u", resolve_on_default_count);
3678 ck_assert_msg(resolve_on_other_count == 0,
3679 "Expected on_other count 0, got %u", resolve_on_other_count);
3680
3681 mark_point();
3682 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
3683 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "RETR"));
3684 cmd->cmd_class = CL_MISC;
3685 tests_stubs_set_protocol("sftp");
3686 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3687 resolve_on_meta, resolve_on_default, resolve_on_other);
3688 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3689 ck_assert_msg(resolve_on_meta_count == 1,
3690 "Expected on_meta count 1, got %u", resolve_on_meta_count);
3691 ck_assert_msg(resolve_on_default_count == 0,
3692 "Expected on_default count 0, got %u", resolve_on_default_count);
3693 ck_assert_msg(resolve_on_other_count == 0,
3694 "Expected on_other count 0, got %u", resolve_on_other_count);
3695
3696 mark_point();
3697 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
3698 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "STOR"));
3699 cmd->cmd_class = CL_MISC;
3700 tests_stubs_set_protocol("scp");
3701 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3702 resolve_on_meta, resolve_on_default, resolve_on_other);
3703 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3704 ck_assert_msg(resolve_on_meta_count == 1,
3705 "Expected on_meta count 1, got %u", resolve_on_meta_count);
3706 ck_assert_msg(resolve_on_default_count == 0,
3707 "Expected on_default count 0, got %u", resolve_on_default_count);
3708 ck_assert_msg(resolve_on_other_count == 0,
3709 "Expected on_other count 0, got %u", resolve_on_other_count);
3710
3711 tests_stubs_set_protocol(NULL);
3712 }
3713 END_TEST
3714
3715 START_TEST (jot_resolve_logfmt_xfer_status_test) {
3716 int res;
3717 cmd_rec *cmd;
3718 unsigned char logfmt[3];
3719
3720 logfmt[0] = LOGFMT_META_START;
3721 logfmt[1] = LOGFMT_META_XFER_STATUS;
3722 logfmt[2] = 0;
3723
3724 mark_point();
3725 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
3726 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
3727 cmd->cmd_class = CL_MISC;
3728 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3729 resolve_on_meta, resolve_on_default, resolve_on_other);
3730 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3731 ck_assert_msg(resolve_on_meta_count == 0,
3732 "Expected on_meta count 0, got %u", resolve_on_meta_count);
3733 ck_assert_msg(resolve_on_default_count == 1,
3734 "Expected on_default count 1, got %u", resolve_on_default_count);
3735 ck_assert_msg(resolve_on_other_count == 0,
3736 "Expected on_other count 0, got %u", resolve_on_other_count);
3737
3738 mark_point();
3739 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
3740 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "RETR"));
3741 cmd->cmd_class = CL_MISC;
3742 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3743 resolve_on_meta, resolve_on_default, resolve_on_other);
3744 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3745 ck_assert_msg(resolve_on_meta_count == 1,
3746 "Expected on_meta count 1, got %u", resolve_on_meta_count);
3747 ck_assert_msg(resolve_on_default_count == 0,
3748 "Expected on_default count 0, got %u", resolve_on_default_count);
3749 ck_assert_msg(resolve_on_other_count == 0,
3750 "Expected on_other count 0, got %u", resolve_on_other_count);
3751
3752 mark_point();
3753 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
3754 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "RETR"));
3755 cmd->cmd_class = CL_MISC;
3756 tests_stubs_set_protocol("ftps");
3757 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3758 resolve_on_meta, resolve_on_default, resolve_on_other);
3759 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3760 ck_assert_msg(resolve_on_meta_count == 1,
3761 "Expected on_meta count 1, got %u", resolve_on_meta_count);
3762 ck_assert_msg(resolve_on_default_count == 0,
3763 "Expected on_default count 0, got %u", resolve_on_default_count);
3764 ck_assert_msg(resolve_on_other_count == 0,
3765 "Expected on_other count 0, got %u", resolve_on_other_count);
3766
3767 tests_stubs_set_protocol(NULL);
3768
3769 /* 5xx response */
3770 mark_point();
3771 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
3772 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "RETR"));
3773 cmd->cmd_class = CL_MISC;
3774 pr_response_set_pool(p);
3775 pr_response_add("500", "foo %s", "bar");
3776 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3777 resolve_on_meta, resolve_on_default, resolve_on_other);
3778 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3779 ck_assert_msg(resolve_on_meta_count == 1,
3780 "Expected on_meta count 1, got %u", resolve_on_meta_count);
3781 ck_assert_msg(resolve_on_default_count == 0,
3782 "Expected on_default count 0, got %u", resolve_on_default_count);
3783 ck_assert_msg(resolve_on_other_count == 0,
3784 "Expected on_other count 0, got %u", resolve_on_other_count);
3785
3786 pr_response_clear(&resp_list);
3787
3788 /* 1xx response */
3789 mark_point();
3790 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
3791 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "RETR"));
3792 cmd->cmd_class = CL_MISC;
3793 pr_response_set_pool(p);
3794 pr_response_add("123", "foo %s", "bar");
3795 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3796 resolve_on_meta, resolve_on_default, resolve_on_other);
3797 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3798 ck_assert_msg(resolve_on_meta_count == 1,
3799 "Expected on_meta count 1, got %u", resolve_on_meta_count);
3800 ck_assert_msg(resolve_on_default_count == 0,
3801 "Expected on_default count 0, got %u", resolve_on_default_count);
3802 ck_assert_msg(resolve_on_other_count == 0,
3803 "Expected on_other count 0, got %u", resolve_on_other_count);
3804
3805 pr_response_clear(&resp_list);
3806
3807 /* 2xx response */
3808 mark_point();
3809 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
3810 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "RETR"));
3811 cmd->cmd_class = CL_MISC;
3812 pr_response_set_pool(p);
3813 pr_response_add("234", "foo %s", "bar");
3814 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3815 resolve_on_meta, resolve_on_default, resolve_on_other);
3816 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3817 ck_assert_msg(resolve_on_meta_count == 1,
3818 "Expected on_meta count 1, got %u", resolve_on_meta_count);
3819 ck_assert_msg(resolve_on_default_count == 0,
3820 "Expected on_default count 0, got %u", resolve_on_default_count);
3821 ck_assert_msg(resolve_on_other_count == 0,
3822 "Expected on_other count 0, got %u", resolve_on_other_count);
3823
3824 pr_response_clear(&resp_list);
3825
3826 /* ABOR */
3827 mark_point();
3828 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
3829 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "ABOR"));
3830 cmd->cmd_class = CL_MISC;
3831 pr_response_set_pool(p);
3832 pr_response_add("234", "foo %s", "bar");
3833 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3834 resolve_on_meta, resolve_on_default, resolve_on_other);
3835 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3836 ck_assert_msg(resolve_on_meta_count == 1,
3837 "Expected on_meta count 1, got %u", resolve_on_meta_count);
3838 ck_assert_msg(resolve_on_default_count == 0,
3839 "Expected on_default count 0, got %u", resolve_on_default_count);
3840 ck_assert_msg(resolve_on_other_count == 0,
3841 "Expected on_other count 0, got %u", resolve_on_other_count);
3842
3843 pr_response_clear(&resp_list);
3844
3845 /* SF_ABORT */
3846 mark_point();
3847 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
3848 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "RETR"));
3849 cmd->cmd_class = CL_MISC;
3850 session.sf_flags = SF_ABORT;
3851 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3852 resolve_on_meta, resolve_on_default, resolve_on_other);
3853 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3854 ck_assert_msg(resolve_on_meta_count == 1,
3855 "Expected on_meta count 1, got %u", resolve_on_meta_count);
3856 ck_assert_msg(resolve_on_default_count == 0,
3857 "Expected on_default count 0, got %u", resolve_on_default_count);
3858 ck_assert_msg(resolve_on_other_count == 0,
3859 "Expected on_other count 0, got %u", resolve_on_other_count);
3860
3861 session.sf_flags = 0;
3862 pr_response_clear(&resp_list);
3863 pr_response_set_pool(NULL);
3864
3865 mark_point();
3866 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
3867 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "RETR"));
3868 cmd->cmd_class = CL_MISC;
3869 tests_stubs_set_protocol("sftp");
3870 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3871 resolve_on_meta, resolve_on_default, resolve_on_other);
3872 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3873 ck_assert_msg(resolve_on_meta_count == 1,
3874 "Expected on_meta count 1, got %u", resolve_on_meta_count);
3875 ck_assert_msg(resolve_on_default_count == 0,
3876 "Expected on_default count 0, got %u", resolve_on_default_count);
3877 ck_assert_msg(resolve_on_other_count == 0,
3878 "Expected on_other count 0, got %u", resolve_on_other_count);
3879
3880 mark_point();
3881 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
3882 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "STOR"));
3883 cmd->cmd_class = CL_MISC;
3884 pr_table_add_dup(cmd->notes, "mod_sftp.file-status", "FOO!", 0);
3885 tests_stubs_set_protocol("sftp");
3886 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3887 resolve_on_meta, resolve_on_default, resolve_on_other);
3888 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3889 ck_assert_msg(resolve_on_meta_count == 1,
3890 "Expected on_meta count 1, got %u", resolve_on_meta_count);
3891 ck_assert_msg(resolve_on_default_count == 0,
3892 "Expected on_default count 0, got %u", resolve_on_default_count);
3893 ck_assert_msg(resolve_on_other_count == 0,
3894 "Expected on_other count 0, got %u", resolve_on_other_count);
3895
3896 tests_stubs_set_protocol(NULL);
3897 }
3898 END_TEST
3899
3900 START_TEST (jot_resolve_logfmt_xfer_failure_test) {
3901 int res;
3902 cmd_rec *cmd;
3903 unsigned char logfmt[3];
3904
3905 logfmt[0] = LOGFMT_META_START;
3906 logfmt[1] = LOGFMT_META_XFER_FAILURE;
3907 logfmt[2] = 0;
3908
3909 mark_point();
3910 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
3911 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
3912 cmd->cmd_class = CL_MISC;
3913 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3914 resolve_on_meta, resolve_on_default, resolve_on_other);
3915 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3916 ck_assert_msg(resolve_on_meta_count == 0,
3917 "Expected on_meta count 0, got %u", resolve_on_meta_count);
3918 ck_assert_msg(resolve_on_default_count == 1,
3919 "Expected on_default count 1, got %u", resolve_on_default_count);
3920 ck_assert_msg(resolve_on_other_count == 0,
3921 "Expected on_other count 0, got %u", resolve_on_other_count);
3922
3923 mark_point();
3924 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
3925 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "RETR"));
3926 cmd->cmd_class = CL_MISC;
3927 tests_stubs_set_protocol("ftps");
3928 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3929 resolve_on_meta, resolve_on_default, resolve_on_other);
3930 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3931 ck_assert_msg(resolve_on_meta_count == 1,
3932 "Expected on_meta count 1, got %u", resolve_on_meta_count);
3933 ck_assert_msg(resolve_on_default_count == 0,
3934 "Expected on_default count 0, got %u", resolve_on_default_count);
3935 ck_assert_msg(resolve_on_other_count == 0,
3936 "Expected on_other count 0, got %u", resolve_on_other_count);
3937
3938 tests_stubs_set_protocol(NULL);
3939
3940 /* SF_ABORT */
3941 mark_point();
3942 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
3943 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "RETR"));
3944 cmd->cmd_class = CL_MISC;
3945 session.sf_flags = SF_ABORT;
3946 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3947 resolve_on_meta, resolve_on_default, resolve_on_other);
3948 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3949 ck_assert_msg(resolve_on_meta_count == 1,
3950 "Expected on_meta count 1, got %u", resolve_on_meta_count);
3951 ck_assert_msg(resolve_on_default_count == 0,
3952 "Expected on_default count 0, got %u", resolve_on_default_count);
3953 ck_assert_msg(resolve_on_other_count == 0,
3954 "Expected on_other count 0, got %u", resolve_on_other_count);
3955
3956 session.sf_flags = 0;
3957
3958 /* 5xx response */
3959 mark_point();
3960 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
3961 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "RETR"));
3962 cmd->cmd_class = CL_MISC;
3963 pr_response_set_pool(p);
3964 pr_response_add("543", "foo %s", "BAR BAZ");
3965 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3966 resolve_on_meta, resolve_on_default, resolve_on_other);
3967 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3968 ck_assert_msg(resolve_on_meta_count == 1,
3969 "Expected on_meta count 1, got %u", resolve_on_meta_count);
3970 ck_assert_msg(resolve_on_default_count == 0,
3971 "Expected on_default count 0, got %u", resolve_on_default_count);
3972 ck_assert_msg(resolve_on_other_count == 0,
3973 "Expected on_other count 0, got %u", resolve_on_other_count);
3974
3975 pr_response_clear(&resp_list);
3976 pr_response_set_pool(NULL);
3977
3978 /* 1xx response */
3979 mark_point();
3980 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
3981 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "RETR"));
3982 cmd->cmd_class = CL_MISC;
3983 pr_response_set_pool(p);
3984 pr_response_add("123", "foo %s", "BAR BAZ");
3985 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
3986 resolve_on_meta, resolve_on_default, resolve_on_other);
3987 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
3988 ck_assert_msg(resolve_on_meta_count == 0,
3989 "Expected on_meta count 0, got %u", resolve_on_meta_count);
3990 ck_assert_msg(resolve_on_default_count == 1,
3991 "Expected on_default count 1, got %u", resolve_on_default_count);
3992 ck_assert_msg(resolve_on_other_count == 0,
3993 "Expected on_other count 0, got %u", resolve_on_other_count);
3994
3995 pr_response_clear(&resp_list);
3996 pr_response_set_pool(NULL);
3997
3998 /* 2xx response */
3999 mark_point();
4000 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
4001 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "RETR"));
4002 cmd->cmd_class = CL_MISC;
4003 pr_response_set_pool(p);
4004 pr_response_add("234", "foo %s", "BAR BAZ");
4005 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4006 resolve_on_meta, resolve_on_default, resolve_on_other);
4007 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4008 ck_assert_msg(resolve_on_meta_count == 0,
4009 "Expected on_meta count 0, got %u", resolve_on_meta_count);
4010 ck_assert_msg(resolve_on_default_count == 1,
4011 "Expected on_default count 1, got %u", resolve_on_default_count);
4012 ck_assert_msg(resolve_on_other_count == 0,
4013 "Expected on_other count 0, got %u", resolve_on_other_count);
4014
4015 pr_response_clear(&resp_list);
4016 pr_response_set_pool(NULL);
4017
4018 mark_point();
4019 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
4020 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "RETR"));
4021 cmd->cmd_class = CL_MISC;
4022 tests_stubs_set_protocol("sftp");
4023 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4024 resolve_on_meta, resolve_on_default, resolve_on_other);
4025 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4026 ck_assert_msg(resolve_on_meta_count == 1,
4027 "Expected on_meta count 1, got %u", resolve_on_meta_count);
4028 ck_assert_msg(resolve_on_default_count == 0,
4029 "Expected on_default count 0, got %u", resolve_on_default_count);
4030 ck_assert_msg(resolve_on_other_count == 0,
4031 "Expected on_other count 0, got %u", resolve_on_other_count);
4032
4033 tests_stubs_set_protocol(NULL);
4034 }
4035 END_TEST
4036
4037 START_TEST (jot_resolve_logfmt_dir_name_test) {
4038 int res;
4039 cmd_rec *cmd;
4040 unsigned char logfmt[3];
4041
4042 logfmt[0] = LOGFMT_META_START;
4043 logfmt[1] = LOGFMT_META_DIR_NAME;
4044 logfmt[2] = 0;
4045
4046 mark_point();
4047 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
4048 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
4049 cmd->cmd_class = CL_MISC;
4050 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4051 resolve_on_meta, resolve_on_default, resolve_on_other);
4052 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4053 ck_assert_msg(resolve_on_meta_count == 1,
4054 "Expected on_meta count 1, got %u", resolve_on_meta_count);
4055 ck_assert_msg(resolve_on_default_count == 0,
4056 "Expected on_default count 0, got %u", resolve_on_default_count);
4057 ck_assert_msg(resolve_on_other_count == 0,
4058 "Expected on_other count 0, got %u", resolve_on_other_count);
4059
4060 mark_point();
4061 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
4062 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "CDUP"));
4063 cmd->cmd_class = CL_MISC;
4064 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4065 resolve_on_meta, resolve_on_default, resolve_on_other);
4066 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4067 ck_assert_msg(resolve_on_meta_count == 0,
4068 "Expected on_meta count 0, got %u", resolve_on_meta_count);
4069 ck_assert_msg(resolve_on_default_count == 1,
4070 "Expected on_default count 1, got %u", resolve_on_default_count);
4071 ck_assert_msg(resolve_on_other_count == 0,
4072 "Expected on_other count 0, got %u", resolve_on_other_count);
4073
4074 mark_point();
4075 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
4076 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "CWD"));
4077 cmd->cmd_class = CL_MISC;
4078 cmd->arg = pstrdup(p, "foo");
4079 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4080 resolve_on_meta, resolve_on_default, resolve_on_other);
4081 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4082 ck_assert_msg(resolve_on_meta_count == 1,
4083 "Expected on_meta count 1, got %u", resolve_on_meta_count);
4084 ck_assert_msg(resolve_on_default_count == 0,
4085 "Expected on_default count 0, got %u", resolve_on_default_count);
4086 ck_assert_msg(resolve_on_other_count == 0,
4087 "Expected on_other count 0, got %u", resolve_on_other_count);
4088
4089 mark_point();
4090 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
4091 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "LIST"));
4092 cmd->cmd_class = CL_MISC;
4093 cmd->arg = pstrdup(p, "/foo");
4094 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4095 resolve_on_meta, resolve_on_default, resolve_on_other);
4096 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4097 ck_assert_msg(resolve_on_meta_count == 1,
4098 "Expected on_meta count 1, got %u", resolve_on_meta_count);
4099 ck_assert_msg(resolve_on_default_count == 0,
4100 "Expected on_default count 0, got %u", resolve_on_default_count);
4101 ck_assert_msg(resolve_on_other_count == 0,
4102 "Expected on_other count 0, got %u", resolve_on_other_count);
4103
4104 mark_point();
4105 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
4106 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "MLSD"));
4107 cmd->cmd_class = CL_MISC;
4108 cmd->arg = pstrdup(p, "/foo/");
4109 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4110 resolve_on_meta, resolve_on_default, resolve_on_other);
4111 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4112 ck_assert_msg(resolve_on_meta_count == 1,
4113 "Expected on_meta count 1, got %u", resolve_on_meta_count);
4114 ck_assert_msg(resolve_on_default_count == 0,
4115 "Expected on_default count 0, got %u", resolve_on_default_count);
4116 ck_assert_msg(resolve_on_other_count == 0,
4117 "Expected on_other count 0, got %u", resolve_on_other_count);
4118
4119 mark_point();
4120 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
4121 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "MKD"));
4122 cmd->cmd_class = CL_MISC;
4123 cmd->arg = pstrdup(p, "foo/");
4124 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4125 resolve_on_meta, resolve_on_default, resolve_on_other);
4126 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4127 ck_assert_msg(resolve_on_meta_count == 1,
4128 "Expected on_meta count 1, got %u", resolve_on_meta_count);
4129 ck_assert_msg(resolve_on_default_count == 0,
4130 "Expected on_default count 0, got %u", resolve_on_default_count);
4131 ck_assert_msg(resolve_on_other_count == 0,
4132 "Expected on_other count 0, got %u", resolve_on_other_count);
4133
4134 mark_point();
4135 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
4136 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "NLST"));
4137 cmd->cmd_class = CL_MISC;
4138 cmd->arg = pstrdup(p, "foo/");
4139 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4140 resolve_on_meta, resolve_on_default, resolve_on_other);
4141 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4142 ck_assert_msg(resolve_on_meta_count == 1,
4143 "Expected on_meta count 1, got %u", resolve_on_meta_count);
4144 ck_assert_msg(resolve_on_default_count == 0,
4145 "Expected on_default count 0, got %u", resolve_on_default_count);
4146 ck_assert_msg(resolve_on_other_count == 0,
4147 "Expected on_other count 0, got %u", resolve_on_other_count);
4148
4149 mark_point();
4150 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
4151 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "RMD"));
4152 cmd->cmd_class = CL_MISC;
4153 cmd->arg = pstrdup(p, "foo/");
4154 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4155 resolve_on_meta, resolve_on_default, resolve_on_other);
4156 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4157 ck_assert_msg(resolve_on_meta_count == 1,
4158 "Expected on_meta count 1, got %u", resolve_on_meta_count);
4159 ck_assert_msg(resolve_on_default_count == 0,
4160 "Expected on_default count 0, got %u", resolve_on_default_count);
4161 ck_assert_msg(resolve_on_other_count == 0,
4162 "Expected on_other count 0, got %u", resolve_on_other_count);
4163
4164 mark_point();
4165 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
4166 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "XCWD"));
4167 cmd->cmd_class = CL_MISC;
4168 cmd->arg = pstrdup(p, "foo/");
4169 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4170 resolve_on_meta, resolve_on_default, resolve_on_other);
4171 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4172 ck_assert_msg(resolve_on_meta_count == 1,
4173 "Expected on_meta count 1, got %u", resolve_on_meta_count);
4174 ck_assert_msg(resolve_on_default_count == 0,
4175 "Expected on_default count 0, got %u", resolve_on_default_count);
4176 ck_assert_msg(resolve_on_other_count == 0,
4177 "Expected on_other count 0, got %u", resolve_on_other_count);
4178
4179 mark_point();
4180 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
4181 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "XCUP"));
4182 cmd->cmd_class = CL_MISC;
4183 cmd->arg = pstrdup(p, "foo/");
4184 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4185 resolve_on_meta, resolve_on_default, resolve_on_other);
4186 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4187 ck_assert_msg(resolve_on_meta_count == 1,
4188 "Expected on_meta count 1, got %u", resolve_on_meta_count);
4189 ck_assert_msg(resolve_on_default_count == 0,
4190 "Expected on_default count 0, got %u", resolve_on_default_count);
4191 ck_assert_msg(resolve_on_other_count == 0,
4192 "Expected on_other count 0, got %u", resolve_on_other_count);
4193
4194 mark_point();
4195 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
4196 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "XMKD"));
4197 cmd->cmd_class = CL_MISC;
4198 cmd->arg = pstrdup(p, "foo/");
4199 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4200 resolve_on_meta, resolve_on_default, resolve_on_other);
4201 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4202 ck_assert_msg(resolve_on_meta_count == 1,
4203 "Expected on_meta count 1, got %u", resolve_on_meta_count);
4204 ck_assert_msg(resolve_on_default_count == 0,
4205 "Expected on_default count 0, got %u", resolve_on_default_count);
4206 ck_assert_msg(resolve_on_other_count == 0,
4207 "Expected on_other count 0, got %u", resolve_on_other_count);
4208
4209 mark_point();
4210 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
4211 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "XRMD"));
4212 cmd->cmd_class = CL_MISC;
4213 cmd->arg = pstrdup(p, "foo/");
4214 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4215 resolve_on_meta, resolve_on_default, resolve_on_other);
4216 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4217 ck_assert_msg(resolve_on_meta_count == 1,
4218 "Expected on_meta count 1, got %u", resolve_on_meta_count);
4219 ck_assert_msg(resolve_on_default_count == 0,
4220 "Expected on_default count 0, got %u", resolve_on_default_count);
4221 ck_assert_msg(resolve_on_other_count == 0,
4222 "Expected on_other count 0, got %u", resolve_on_other_count);
4223 }
4224 END_TEST
4225
4226 START_TEST (jot_resolve_logfmt_dir_path_test) {
4227 int res;
4228 cmd_rec *cmd;
4229 unsigned char logfmt[3];
4230
4231 logfmt[0] = LOGFMT_META_START;
4232 logfmt[1] = LOGFMT_META_DIR_PATH;
4233 logfmt[2] = 0;
4234
4235 mark_point();
4236 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
4237 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
4238 cmd->cmd_class = CL_MISC;
4239 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4240 resolve_on_meta, resolve_on_default, resolve_on_other);
4241 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4242 ck_assert_msg(resolve_on_meta_count == 0,
4243 "Expected on_meta count 0, got %u", resolve_on_meta_count);
4244 ck_assert_msg(resolve_on_default_count == 1,
4245 "Expected on_default count 1, got %u", resolve_on_default_count);
4246 ck_assert_msg(resolve_on_other_count == 0,
4247 "Expected on_other count 0, got %u", resolve_on_other_count);
4248
4249 mark_point();
4250 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
4251 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "CDUP"));
4252 cmd->cmd_class = CL_MISC;
4253 cmd->arg = pstrdup(p, "/foo/bar/baz");
4254 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4255 resolve_on_meta, resolve_on_default, resolve_on_other);
4256 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4257 ck_assert_msg(resolve_on_meta_count == 1,
4258 "Expected on_meta count 1, got %u", resolve_on_meta_count);
4259 ck_assert_msg(resolve_on_default_count == 0,
4260 "Expected on_default count 0, got %u", resolve_on_default_count);
4261 ck_assert_msg(resolve_on_other_count == 0,
4262 "Expected on_other count 0, got %u", resolve_on_other_count);
4263
4264 mark_point();
4265 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
4266 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "LIST"));
4267 cmd->cmd_class = CL_MISC;
4268 cmd->arg = pstrdup(p, "/foo/bar/baz");
4269 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4270 resolve_on_meta, resolve_on_default, resolve_on_other);
4271 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4272 ck_assert_msg(resolve_on_meta_count == 1,
4273 "Expected on_meta count 1, got %u", resolve_on_meta_count);
4274 ck_assert_msg(resolve_on_default_count == 0,
4275 "Expected on_default count 0, got %u", resolve_on_default_count);
4276 ck_assert_msg(resolve_on_other_count == 0,
4277 "Expected on_other count 0, got %u", resolve_on_other_count);
4278
4279 mark_point();
4280 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
4281 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "MKD"));
4282 cmd->cmd_class = CL_MISC;
4283 cmd->arg = pstrdup(p, "/foo/bar/baz");
4284 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4285 resolve_on_meta, resolve_on_default, resolve_on_other);
4286 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4287 ck_assert_msg(resolve_on_meta_count == 1,
4288 "Expected on_meta count 1, got %u", resolve_on_meta_count);
4289 ck_assert_msg(resolve_on_default_count == 0,
4290 "Expected on_default count 0, got %u", resolve_on_default_count);
4291 ck_assert_msg(resolve_on_other_count == 0,
4292 "Expected on_other count 0, got %u", resolve_on_other_count);
4293
4294 mark_point();
4295 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
4296 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "MLSD"));
4297 cmd->cmd_class = CL_MISC;
4298 cmd->arg = pstrdup(p, "/foo/bar/baz");
4299 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4300 resolve_on_meta, resolve_on_default, resolve_on_other);
4301 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4302 ck_assert_msg(resolve_on_meta_count == 1,
4303 "Expected on_meta count 1, got %u", resolve_on_meta_count);
4304 ck_assert_msg(resolve_on_default_count == 0,
4305 "Expected on_default count 0, got %u", resolve_on_default_count);
4306 ck_assert_msg(resolve_on_other_count == 0,
4307 "Expected on_other count 0, got %u", resolve_on_other_count);
4308
4309 mark_point();
4310 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
4311 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "NLST"));
4312 cmd->cmd_class = CL_MISC;
4313 cmd->arg = pstrdup(p, "/foo/bar/baz");
4314 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4315 resolve_on_meta, resolve_on_default, resolve_on_other);
4316 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4317 ck_assert_msg(resolve_on_meta_count == 1,
4318 "Expected on_meta count 1, got %u", resolve_on_meta_count);
4319 ck_assert_msg(resolve_on_default_count == 0,
4320 "Expected on_default count 0, got %u", resolve_on_default_count);
4321 ck_assert_msg(resolve_on_other_count == 0,
4322 "Expected on_other count 0, got %u", resolve_on_other_count);
4323
4324 mark_point();
4325 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
4326 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "RMD"));
4327 cmd->cmd_class = CL_MISC;
4328 cmd->arg = pstrdup(p, "/foo/bar/baz");
4329 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4330 resolve_on_meta, resolve_on_default, resolve_on_other);
4331 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4332 ck_assert_msg(resolve_on_meta_count == 1,
4333 "Expected on_meta count 1, got %u", resolve_on_meta_count);
4334 ck_assert_msg(resolve_on_default_count == 0,
4335 "Expected on_default count 0, got %u", resolve_on_default_count);
4336 ck_assert_msg(resolve_on_other_count == 0,
4337 "Expected on_other count 0, got %u", resolve_on_other_count);
4338
4339 mark_point();
4340 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
4341 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "XCUP"));
4342 cmd->cmd_class = CL_MISC;
4343 cmd->arg = pstrdup(p, "/foo/bar/baz");
4344 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4345 resolve_on_meta, resolve_on_default, resolve_on_other);
4346 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4347 ck_assert_msg(resolve_on_meta_count == 1,
4348 "Expected on_meta count 1, got %u", resolve_on_meta_count);
4349 ck_assert_msg(resolve_on_default_count == 0,
4350 "Expected on_default count 0, got %u", resolve_on_default_count);
4351 ck_assert_msg(resolve_on_other_count == 0,
4352 "Expected on_other count 0, got %u", resolve_on_other_count);
4353
4354 mark_point();
4355 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
4356 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "XMKD"));
4357 cmd->cmd_class = CL_MISC;
4358 cmd->arg = pstrdup(p, "/foo/bar/baz");
4359 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4360 resolve_on_meta, resolve_on_default, resolve_on_other);
4361 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4362 ck_assert_msg(resolve_on_meta_count == 1,
4363 "Expected on_meta count 1, got %u", resolve_on_meta_count);
4364 ck_assert_msg(resolve_on_default_count == 0,
4365 "Expected on_default count 0, got %u", resolve_on_default_count);
4366 ck_assert_msg(resolve_on_other_count == 0,
4367 "Expected on_other count 0, got %u", resolve_on_other_count);
4368
4369 mark_point();
4370 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
4371 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "XRMD"));
4372 cmd->cmd_class = CL_MISC;
4373 cmd->arg = pstrdup(p, "/foo/bar/baz");
4374 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4375 resolve_on_meta, resolve_on_default, resolve_on_other);
4376 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4377 ck_assert_msg(resolve_on_meta_count == 1,
4378 "Expected on_meta count 1, got %u", resolve_on_meta_count);
4379 ck_assert_msg(resolve_on_default_count == 0,
4380 "Expected on_default count 0, got %u", resolve_on_default_count);
4381 ck_assert_msg(resolve_on_other_count == 0,
4382 "Expected on_other count 0, got %u", resolve_on_other_count);
4383
4384 mark_point();
4385 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
4386 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "CWD"));
4387 cmd->cmd_class = CL_MISC;
4388 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4389 resolve_on_meta, resolve_on_default, resolve_on_other);
4390 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4391 ck_assert_msg(resolve_on_meta_count == 1,
4392 "Expected on_meta count 1, got %u", resolve_on_meta_count);
4393 ck_assert_msg(resolve_on_default_count == 0,
4394 "Expected on_default count 0, got %u", resolve_on_default_count);
4395 ck_assert_msg(resolve_on_other_count == 0,
4396 "Expected on_other count 0, got %u", resolve_on_other_count);
4397
4398 mark_point();
4399 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
4400 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "CWD"));
4401 cmd->cmd_class = CL_MISC;
4402 session.chroot_path = "/foo/bar/baz/";
4403 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4404 resolve_on_meta, resolve_on_default, resolve_on_other);
4405 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4406 ck_assert_msg(resolve_on_meta_count == 1,
4407 "Expected on_meta count 1, got %u", resolve_on_meta_count);
4408 ck_assert_msg(resolve_on_default_count == 0,
4409 "Expected on_default count 0, got %u", resolve_on_default_count);
4410 ck_assert_msg(resolve_on_other_count == 0,
4411 "Expected on_other count 0, got %u", resolve_on_other_count);
4412
4413 session.chroot_path = NULL;
4414 }
4415 END_TEST
4416
4417 START_TEST (jot_resolve_logfmt_cmd_params_test) {
4418 int res;
4419 cmd_rec *cmd;
4420 unsigned char logfmt[3];
4421
4422 logfmt[0] = LOGFMT_META_START;
4423 logfmt[1] = LOGFMT_META_CMD_PARAMS;
4424 logfmt[2] = 0;
4425
4426 mark_point();
4427 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
4428 cmd->cmd_class = CL_CONNECT;
4429 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
4430 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4431 resolve_on_meta, resolve_on_default, resolve_on_other);
4432 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4433 ck_assert_msg(resolve_on_meta_count == 0,
4434 "Expected on_meta count 0, got %u", resolve_on_meta_count);
4435 ck_assert_msg(resolve_on_default_count == 1,
4436 "Expected on_default count 1, got %u", resolve_on_default_count);
4437 ck_assert_msg(resolve_on_other_count == 0,
4438 "Expected on_other count 0, got %u", resolve_on_other_count);
4439
4440 mark_point();
4441 cmd->cmd_class = CL_DISCONNECT;
4442 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
4443 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4444 resolve_on_meta, resolve_on_default, resolve_on_other);
4445 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4446 ck_assert_msg(resolve_on_meta_count == 0,
4447 "Expected on_meta count 0, got %u", resolve_on_meta_count);
4448 ck_assert_msg(resolve_on_default_count == 1,
4449 "Expected on_default count 1, got %u", resolve_on_default_count);
4450 ck_assert_msg(resolve_on_other_count == 0,
4451 "Expected on_other count 0, got %u", resolve_on_other_count);
4452
4453 mark_point();
4454 cmd->cmd_class = CL_MISC;
4455 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
4456 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4457 resolve_on_meta, resolve_on_default, resolve_on_other);
4458 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4459 ck_assert_msg(resolve_on_meta_count == 0,
4460 "Expected on_meta count 0, got %u", resolve_on_meta_count);
4461 ck_assert_msg(resolve_on_default_count == 1,
4462 "Expected on_default count 1, got %u", resolve_on_default_count);
4463 ck_assert_msg(resolve_on_other_count == 0,
4464 "Expected on_other count 0, got %u", resolve_on_other_count);
4465
4466 mark_point();
4467 cmd = pr_cmd_alloc(p, 2, pstrdup(p, "FOO"), pstrdup(p, "bar"));
4468 cmd->arg = pstrdup(p, "baz");
4469 cmd->cmd_class = CL_MISC;
4470 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
4471 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4472 resolve_on_meta, resolve_on_default, resolve_on_other);
4473 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4474 ck_assert_msg(resolve_on_meta_count == 1,
4475 "Expected on_meta count 1, got %u", resolve_on_meta_count);
4476 ck_assert_msg(resolve_on_default_count == 0,
4477 "Expected on_default count 0, got %u", resolve_on_default_count);
4478 ck_assert_msg(resolve_on_other_count == 0,
4479 "Expected on_other count 0, got %u", resolve_on_other_count);
4480
4481 mark_point();
4482 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "ADAT"));
4483 cmd->cmd_class = CL_SEC;
4484 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
4485 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4486 resolve_on_meta, resolve_on_default, resolve_on_other);
4487 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4488 ck_assert_msg(resolve_on_meta_count == 1,
4489 "Expected on_meta count 1, got %u", resolve_on_meta_count);
4490 ck_assert_msg(resolve_on_default_count == 0,
4491 "Expected on_default count 0, got %u", resolve_on_default_count);
4492 ck_assert_msg(resolve_on_other_count == 0,
4493 "Expected on_other count 0, got %u", resolve_on_other_count);
4494
4495 mark_point();
4496 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "PASS"));
4497 cmd->cmd_class = CL_AUTH;
4498 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
4499 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4500 resolve_on_meta, resolve_on_default, resolve_on_other);
4501 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4502 ck_assert_msg(resolve_on_meta_count == 1,
4503 "Expected on_meta count 1, got %u", resolve_on_meta_count);
4504 ck_assert_msg(resolve_on_default_count == 0,
4505 "Expected on_default count 0, got %u", resolve_on_default_count);
4506 ck_assert_msg(resolve_on_other_count == 0,
4507 "Expected on_other count 0, got %u", resolve_on_other_count);
4508 }
4509 END_TEST
4510
4511 START_TEST (jot_resolve_logfmt_rename_from_test) {
4512 int res;
4513 cmd_rec *cmd;
4514 unsigned char logfmt[3];
4515 char *rnfr_path;
4516
4517 logfmt[0] = LOGFMT_META_START;
4518 logfmt[1] = LOGFMT_META_RENAME_FROM;
4519 logfmt[2] = 0;
4520
4521 mark_point();
4522 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
4523 cmd->cmd_class = CL_MISC;
4524 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
4525 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4526 resolve_on_meta, resolve_on_default, resolve_on_other);
4527 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4528 ck_assert_msg(resolve_on_meta_count == 0,
4529 "Expected on_meta count 0, got %u", resolve_on_meta_count);
4530 ck_assert_msg(resolve_on_default_count == 1,
4531 "Expected on_default count 1, got %u", resolve_on_default_count);
4532 ck_assert_msg(resolve_on_other_count == 0,
4533 "Expected on_other count 0, got %u", resolve_on_other_count);
4534
4535 mark_point();
4536 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "RNTO"));
4537 cmd->cmd_class = CL_MISC;
4538 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
4539 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4540 resolve_on_meta, resolve_on_default, resolve_on_other);
4541 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4542 ck_assert_msg(resolve_on_meta_count == 0,
4543 "Expected on_meta count 0, got %u", resolve_on_meta_count);
4544 ck_assert_msg(resolve_on_default_count == 1,
4545 "Expected on_default count 1, got %u", resolve_on_default_count);
4546 ck_assert_msg(resolve_on_other_count == 0,
4547 "Expected on_other count 0, got %u", resolve_on_other_count);
4548
4549 mark_point();
4550 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
4551 rnfr_path = "FOOBAR";
4552 session.notes = pr_table_alloc(p, 0);
4553 pr_table_add_dup(session.notes, "mod_core.rnfr-path", rnfr_path, 0);
4554 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4555 resolve_on_meta, resolve_on_default, resolve_on_other);
4556 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4557 ck_assert_msg(resolve_on_meta_count == 1,
4558 "Expected on_meta count 1, got %u", resolve_on_meta_count);
4559 ck_assert_msg(resolve_on_default_count == 0,
4560 "Expected on_default count 0, got %u", resolve_on_default_count);
4561 ck_assert_msg(resolve_on_other_count == 0,
4562 "Expected on_other count 0, got %u", resolve_on_other_count);
4563
4564 pr_table_empty(session.notes);
4565 pr_table_free(session.notes);
4566 session.notes = NULL;
4567 }
4568 END_TEST
4569
4570 START_TEST (jot_resolve_logfmt_eos_reason_test) {
4571 int res;
4572 cmd_rec *cmd;
4573 unsigned char logfmt[3];
4574
4575 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
4576 cmd->cmd_class = CL_MISC;
4577 logfmt[0] = LOGFMT_META_START;
4578 logfmt[1] = LOGFMT_META_EOS_REASON;
4579 logfmt[2] = 0;
4580
4581 mark_point();
4582 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
4583 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4584 resolve_on_meta, resolve_on_default, resolve_on_other);
4585 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4586 ck_assert_msg(resolve_on_meta_count == 0,
4587 "Expected on_meta count 0, got %u", resolve_on_meta_count);
4588 ck_assert_msg(resolve_on_default_count == 1,
4589 "Expected on_default count 1, got %u", resolve_on_default_count);
4590 ck_assert_msg(resolve_on_other_count == 0,
4591 "Expected on_other count 0, got %u", resolve_on_other_count);
4592
4593 mark_point();
4594 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
4595 session.disconnect_reason = -1;
4596 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4597 resolve_on_meta, resolve_on_default, resolve_on_other);
4598 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4599 ck_assert_msg(resolve_on_meta_count == 0,
4600 "Expected on_meta count 0, got %u", resolve_on_meta_count);
4601 ck_assert_msg(resolve_on_default_count == 1,
4602 "Expected on_default count 1, got %u", resolve_on_default_count);
4603 ck_assert_msg(resolve_on_other_count == 0,
4604 "Expected on_other count 0, got %u", resolve_on_other_count);
4605
4606 mark_point();
4607 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
4608 session.disconnect_reason = PR_SESS_DISCONNECT_BANNED;
4609 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4610 resolve_on_meta, resolve_on_default, resolve_on_other);
4611 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4612 ck_assert_msg(resolve_on_meta_count == 1,
4613 "Expected on_meta count 1, got %u", resolve_on_meta_count);
4614 ck_assert_msg(resolve_on_default_count == 0,
4615 "Expected on_default count 0, got %u", resolve_on_default_count);
4616 ck_assert_msg(resolve_on_other_count == 0,
4617 "Expected on_other count 0, got %u", resolve_on_other_count);
4618
4619 session.disconnect_reason = 0;
4620 }
4621 END_TEST
4622
4623 START_TEST (jot_resolve_logfmt_vhost_ip_test) {
4624 int res;
4625 cmd_rec *cmd;
4626 server_rec *server;
4627 unsigned char logfmt[3];
4628
4629 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
4630 cmd->cmd_class = CL_MISC;
4631 logfmt[0] = LOGFMT_META_START;
4632 logfmt[1] = LOGFMT_META_VHOST_IP;
4633 logfmt[2] = 0;
4634
4635 mark_point();
4636 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
4637 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4638 resolve_on_meta, resolve_on_default, resolve_on_other);
4639 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4640 ck_assert_msg(resolve_on_meta_count == 0,
4641 "Expected on_meta count 0, got %u", resolve_on_meta_count);
4642 ck_assert_msg(resolve_on_default_count == 1,
4643 "Expected on_default count 1, got %u", resolve_on_default_count);
4644 ck_assert_msg(resolve_on_other_count == 0,
4645 "Expected on_other count 0, got %u", resolve_on_other_count);
4646
4647 mark_point();
4648 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
4649 server = pcalloc(p, sizeof(server_rec));
4650 server->ServerAddress = "FOOBAR";
4651 cmd->server = server;
4652 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4653 resolve_on_meta, resolve_on_default, resolve_on_other);
4654 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4655 ck_assert_msg(resolve_on_meta_count == 1,
4656 "Expected on_meta count 1, got %u", resolve_on_meta_count);
4657 ck_assert_msg(resolve_on_default_count == 0,
4658 "Expected on_default count 0, got %u", resolve_on_default_count);
4659 ck_assert_msg(resolve_on_other_count == 0,
4660 "Expected on_other count 0, got %u", resolve_on_other_count);
4661 }
4662 END_TEST
4663
4664 START_TEST (jot_resolve_logfmt_filters_test) {
4665 int res;
4666 cmd_rec *cmd;
4667 pr_jot_filters_t *jot_filters;
4668 unsigned char logfmt[3];
4669
4670 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
4671 cmd->cmd_class = CL_CONNECT;
4672
4673 /* No filters; should be implicitly jottable. */
4674 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
4675 jot_filters = NULL;
4676 logfmt[0] = LOGFMT_META_START;
4677 logfmt[1] = LOGFMT_META_CONNECT;
4678 logfmt[2] = 0;
4679
4680 mark_point();
4681 res = pr_jot_resolve_logfmt(p, cmd, jot_filters, logfmt, NULL,
4682 resolve_on_meta, NULL, NULL);
4683 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4684 ck_assert_msg(resolve_on_meta_count == 1,
4685 "Expected on_meta count 1, got %u", resolve_on_meta_count);
4686
4687 /* With an ALL filter, and no command class. */
4688 cmd->cmd_class = 0;
4689 logfmt[1] = LOGFMT_META_COMMAND;
4690 resolve_on_meta_count = resolve_on_default_count = 0;
4691 jot_filters = pr_jot_filters_create(p, "ALL",
4692 PR_JOT_FILTER_TYPE_CLASSES, PR_JOT_FILTER_FL_ALL_INCL_ALL);
4693
4694 mark_point();
4695 res = pr_jot_resolve_logfmt(p, cmd, jot_filters, logfmt, NULL,
4696 resolve_on_meta, NULL, NULL);
4697 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4698 ck_assert_msg(resolve_on_meta_count == 1,
4699 "Expected on_meta count 1, got %u", resolve_on_meta_count);
4700
4701 /* With explicit filters that allow the class. */
4702 cmd->cmd_class = CL_CONNECT;
4703 logfmt[1] = LOGFMT_META_CONNECT;
4704 resolve_on_meta_count = resolve_on_default_count = 0;
4705 jot_filters = pr_jot_filters_create(p, "CONNECT",
4706 PR_JOT_FILTER_TYPE_CLASSES, 0);
4707
4708 mark_point();
4709 res = pr_jot_resolve_logfmt(p, cmd, jot_filters, logfmt, NULL,
4710 resolve_on_meta, NULL, NULL);
4711 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4712 ck_assert_msg(resolve_on_meta_count == 1,
4713 "Expected on_meta count 1, got %u", resolve_on_meta_count);
4714
4715 /* With explicit filters that ignore the class. */
4716 resolve_on_meta_count = resolve_on_default_count = 0;
4717 jot_filters = pr_jot_filters_create(p, "!CONNECT",
4718 PR_JOT_FILTER_TYPE_CLASSES, 0);
4719
4720 mark_point();
4721 res = pr_jot_resolve_logfmt(p, cmd, jot_filters, logfmt, NULL,
4722 resolve_on_meta, NULL, NULL);
4723 ck_assert_msg(res < 0, "Failed to handle filtered logfmt");
4724 ck_assert_msg(errno == EPERM, "Expected EPERM (%d), got %s (%d)", EPERM,
4725 strerror(errno), errno);
4726 ck_assert_msg(resolve_on_meta_count == 0,
4727 "Expected on_meta count 0, got %u", resolve_on_meta_count);
4728
4729 /* With explicit filters that do not match the class. */
4730 resolve_on_meta_count = resolve_on_default_count = 0;
4731 jot_filters = pr_jot_filters_create(p, "DISCONNECT",
4732 PR_JOT_FILTER_TYPE_CLASSES, 0);
4733
4734 mark_point();
4735 res = pr_jot_resolve_logfmt(p, cmd, jot_filters, logfmt, NULL,
4736 resolve_on_meta, NULL, NULL);
4737 ck_assert_msg(res < 0, "Failed to handle filtered logfmt");
4738 ck_assert_msg(errno == EPERM, "Expected EPERM (%d), got %s (%d)", EPERM,
4739 strerror(errno), errno);
4740 ck_assert_msg(resolve_on_meta_count == 0,
4741 "Expected on_meta count 0, got %u", resolve_on_meta_count);
4742
4743 /* With explicit filters that allow the command. Note that this REQUIRES
4744 * that we use a known command, since allowed command comparisons are done
4745 * by ID.
4746 */
4747 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "RANG"));
4748 cmd->cmd_class = CL_CONNECT;
4749 resolve_on_meta_count = resolve_on_default_count = 0;
4750 jot_filters = pr_jot_filters_create(p, "RANG",
4751 PR_JOT_FILTER_TYPE_COMMANDS, 0);
4752
4753 mark_point();
4754 res = pr_jot_resolve_logfmt(p, cmd, jot_filters, logfmt, NULL,
4755 resolve_on_meta, NULL, NULL);
4756 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4757 ck_assert_msg(resolve_on_meta_count == 1,
4758 "Expected on_meta count 1, got %u", resolve_on_meta_count);
4759
4760 /* With explicit filters that ignore the command. */
4761 resolve_on_meta_count = resolve_on_default_count = 0;
4762 jot_filters = pr_jot_filters_create(p, "!RANG",
4763 PR_JOT_FILTER_TYPE_COMMANDS, 0);
4764
4765 mark_point();
4766 res = pr_jot_resolve_logfmt(p, cmd, jot_filters, logfmt, NULL,
4767 resolve_on_meta, NULL, NULL);
4768 ck_assert_msg(res < 0, "Failed to handle filtered logfmt");
4769 ck_assert_msg(errno == EPERM, "Expected EPERM (%d), got %s (%d)", EPERM,
4770 strerror(errno), errno);
4771 ck_assert_msg(resolve_on_meta_count == 0,
4772 "Expected on_meta count 0, got %u", resolve_on_meta_count);
4773
4774 /* With explicit filters that do not match the command. */
4775 resolve_on_meta_count = resolve_on_default_count = 0;
4776 jot_filters = pr_jot_filters_create(p, "FOO",
4777 PR_JOT_FILTER_TYPE_COMMANDS, 0);
4778
4779 mark_point();
4780 res = pr_jot_resolve_logfmt(p, cmd, jot_filters, logfmt, NULL,
4781 resolve_on_meta, NULL, NULL);
4782 ck_assert_msg(res < 0, "Failed to handle filtered logfmt");
4783 ck_assert_msg(errno == EPERM, "Expected EPERM (%d), got %s (%d)", EPERM,
4784 strerror(errno), errno);
4785 ck_assert_msg(resolve_on_meta_count == 0,
4786 "Expected on_meta count 0, got %u", resolve_on_meta_count);
4787 }
4788 END_TEST
4789
4790 START_TEST (jot_resolve_logfmt_on_default_test) {
4791 int res;
4792 cmd_rec *cmd;
4793 unsigned char logfmt[3];
4794
4795 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
4796 logfmt[0] = LOGFMT_META_START;
4797 logfmt[1] = LOGFMT_META_BASENAME;
4798 logfmt[2] = 0;
4799 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
4800
4801 mark_point();
4802 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4803 resolve_on_meta, resolve_on_default, NULL);
4804 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4805 ck_assert_msg(resolve_on_meta_count == 0,
4806 "Expected on_meta count 0, got %u", resolve_on_meta_count);
4807 ck_assert_msg(resolve_on_default_count == 1,
4808 "Expected on_default count 1, got %u", resolve_on_default_count);
4809 }
4810 END_TEST
4811
4812 START_TEST (jot_resolve_logfmt_on_other_test) {
4813 int res;
4814 cmd_rec *cmd;
4815 unsigned char logfmt[3];
4816
4817 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
4818 logfmt[0] = 'A';
4819 logfmt[1] = '!';
4820 logfmt[2] = 0;
4821 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
4822
4823 mark_point();
4824 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4825 resolve_on_meta, resolve_on_default, resolve_on_other);
4826 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4827 ck_assert_msg(resolve_on_meta_count == 0,
4828 "Expected on_meta count 0, got %u", resolve_on_meta_count);
4829 ck_assert_msg(resolve_on_default_count == 0,
4830 "Expected on_default count 0, got %u", resolve_on_default_count);
4831 ck_assert_msg(resolve_on_other_count == 1,
4832 "Expected on_other count 1, got %u", resolve_on_other_count);
4833 }
4834 END_TEST
4835
4836 START_TEST (jot_resolve_logfmt_connect_test) {
4837 int res;
4838 cmd_rec *cmd;
4839 unsigned char logfmt[3];
4840
4841 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
4842 cmd->cmd_class = CL_CONNECT;
4843 logfmt[0] = LOGFMT_META_START;
4844 logfmt[1] = LOGFMT_META_CONNECT;
4845 logfmt[2] = 0;
4846
4847 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
4848
4849 mark_point();
4850 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4851 resolve_on_meta, resolve_on_default, resolve_on_other);
4852 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4853 ck_assert_msg(resolve_on_meta_count == 1,
4854 "Expected on_meta count 1, got %u", resolve_on_meta_count);
4855 ck_assert_msg(resolve_on_default_count == 0,
4856 "Expected on_default count 0, got %u", resolve_on_default_count);
4857 ck_assert_msg(resolve_on_other_count == 0,
4858 "Expected on_other count 0, got %u", resolve_on_other_count);
4859
4860 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
4861 cmd->cmd_class = CL_DISCONNECT;
4862
4863 mark_point();
4864 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4865 resolve_on_meta, resolve_on_default, resolve_on_other);
4866 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4867 ck_assert_msg(resolve_on_meta_count == 0,
4868 "Expected on_meta count 0, got %u", resolve_on_meta_count);
4869 ck_assert_msg(resolve_on_default_count == 0,
4870 "Expected on_default count 0, got %u", resolve_on_default_count);
4871 ck_assert_msg(resolve_on_other_count == 0,
4872 "Expected on_other count 0, got %u", resolve_on_other_count);
4873 }
4874 END_TEST
4875
4876 START_TEST (jot_resolve_logfmt_disconnect_test) {
4877 int res;
4878 cmd_rec *cmd;
4879 unsigned char logfmt[3];
4880
4881 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
4882 cmd->cmd_class = CL_DISCONNECT;
4883 logfmt[0] = LOGFMT_META_START;
4884 logfmt[1] = LOGFMT_META_DISCONNECT;
4885 logfmt[2] = 0;
4886
4887 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
4888
4889 mark_point();
4890 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4891 resolve_on_meta, resolve_on_default, resolve_on_other);
4892 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4893 ck_assert_msg(resolve_on_meta_count == 1,
4894 "Expected on_meta count 1, got %u", resolve_on_meta_count);
4895 ck_assert_msg(resolve_on_default_count == 0,
4896 "Expected on_default count 0, got %u", resolve_on_default_count);
4897 ck_assert_msg(resolve_on_other_count == 0,
4898 "Expected on_other count 0, got %u", resolve_on_other_count);
4899
4900 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
4901 cmd->cmd_class = CL_CONNECT;
4902
4903 mark_point();
4904 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4905 resolve_on_meta, resolve_on_default, resolve_on_other);
4906 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4907 ck_assert_msg(resolve_on_meta_count == 0,
4908 "Expected on_meta count 0, got %u", resolve_on_meta_count);
4909 ck_assert_msg(resolve_on_default_count == 0,
4910 "Expected on_default count 0, got %u", resolve_on_default_count);
4911 ck_assert_msg(resolve_on_other_count == 0,
4912 "Expected on_other count 0, got %u", resolve_on_other_count);
4913 }
4914 END_TEST
4915
4916 START_TEST (jot_resolve_logfmt_custom_test) {
4917 int res;
4918 cmd_rec *cmd;
4919 unsigned char logfmt[10];
4920
4921 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
4922 cmd->cmd_class = CL_MISC;
4923 logfmt[0] = LOGFMT_META_START;
4924 logfmt[1] = LOGFMT_META_CUSTOM;
4925 logfmt[2] = LOGFMT_META_START;
4926 logfmt[3] = LOGFMT_META_ARG;
4927 logfmt[4] = '%';
4928 logfmt[5] = '{';
4929 logfmt[6] = '0';
4930 logfmt[7] = '}';
4931 logfmt[8] = LOGFMT_META_ARG_END;
4932 logfmt[9] = 0;
4933
4934 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
4935
4936 mark_point();
4937 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4938 resolve_on_meta, resolve_on_default, resolve_on_other);
4939 ck_assert_msg(res == 0, "Failed to handle logfmt: %s", strerror(errno));
4940 ck_assert_msg(resolve_on_meta_count == 1,
4941 "Expected on_meta count 1, got %u", resolve_on_meta_count);
4942 ck_assert_msg(resolve_on_default_count == 0,
4943 "Expected on_default count 0, got %u", resolve_on_default_count);
4944 ck_assert_msg(resolve_on_other_count == 0,
4945 "Expected on_other count 0, got %u", resolve_on_other_count);
4946 }
4947 END_TEST
4948
4949 START_TEST (jot_resolve_logfmts_test) {
4950 register unsigned char i;
4951 int res;
4952 cmd_rec *cmd;
4953 unsigned char logfmt[3];
4954
4955 cmd = pr_cmd_alloc(p, 1, pstrdup(p, "FOO"));
4956 logfmt[0] = LOGFMT_META_START;
4957 logfmt[2] = 0;
4958 resolve_on_meta_count = resolve_on_default_count = resolve_on_other_count = 0;
4959
4960 /* Currently, the max known LogFormat meta/ID is 53 (DISCONNECT). */
4961 for (i = 1; i < 54; i++) {
4962 logfmt[1] = i;
4963
4964 mark_point();
4965 res = pr_jot_resolve_logfmt(p, cmd, NULL, logfmt, NULL,
4966 resolve_on_meta, resolve_on_default, resolve_on_other);
4967 ck_assert_msg(res == 0, "Failed to handle logfmt_id %u: %s", logfmt[1],
4968 strerror(errno));
4969 }
4970
4971 ck_assert_msg(resolve_on_meta_count == 20,
4972 "Expected on_meta count 20, got %u", resolve_on_meta_count);
4973 ck_assert_msg(resolve_on_default_count == 28,
4974 "Expected on_default count 28, got %u", resolve_on_default_count);
4975 ck_assert_msg(resolve_on_other_count == 0,
4976 "Expected on_other count 0, got %u", resolve_on_other_count);
4977 }
4978 END_TEST
4979
4980 static unsigned int scan_on_meta_count = 0;
4981
4982 static int scan_on_meta(pool *jot_pool, pr_jot_ctx_t *jot_ctx,
4983 unsigned char logfmt_id, const char *logfmt_data, size_t logfmt_datalen) {
4984 scan_on_meta_count++;
4985 return 0;
4986 }
4987
4988 START_TEST (jot_scan_logfmt_test) {
4989 int res;
4990 unsigned char logfmt[12];
4991
4992 mark_point();
4993 res = pr_jot_scan_logfmt(NULL, NULL, 0, NULL, NULL, 0);
4994 ck_assert_msg(res < 0, "Failed to handle null pool");
4995 ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
4996 strerror(errno), errno);
4997
4998 mark_point();
4999 res = pr_jot_scan_logfmt(p, NULL, 0, NULL, NULL, 0);
5000 ck_assert_msg(res < 0, "Failed to handle null logfmt");
5001 ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
5002 strerror(errno), errno);
5003
5004 logfmt[0] = LOGFMT_META_START;
5005 logfmt[1] = LOGFMT_META_CUSTOM;
5006 logfmt[2] = LOGFMT_META_START;
5007 logfmt[3] = LOGFMT_META_ARG;
5008 logfmt[4] = '%';
5009 logfmt[5] = '{';
5010 logfmt[6] = 'f';
5011 logfmt[7] = 'o';
5012 logfmt[8] = 'o';
5013 logfmt[9] = '}';
5014 logfmt[10] = LOGFMT_META_ARG_END;
5015 logfmt[11] = 0;
5016
5017 mark_point();
5018 res = pr_jot_scan_logfmt(p, logfmt, 0, NULL, NULL, 0);
5019 ck_assert_msg(res < 0, "Failed to handle null on_meta");
5020 ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
5021 strerror(errno), errno);
5022
5023 mark_point();
5024 res = pr_jot_scan_logfmt(p, logfmt, 0, NULL, scan_on_meta, 0);
5025 ck_assert_msg(res < 0, "Failed to handle invalid LogFormat ID");
5026 ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
5027 strerror(errno), errno);
5028
5029 scan_on_meta_count = 0;
5030
5031 mark_point();
5032 res = pr_jot_scan_logfmt(p, logfmt, LOGFMT_META_ENV_VAR, NULL, scan_on_meta,
5033 0);
5034 ck_assert_msg(res == 0, "Failed to scan logmt for ENV_VAR: %s",
5035 strerror(errno));
5036 ck_assert_msg(scan_on_meta_count == 0, "Expected scan_on_meta 0, got %u",
5037 scan_on_meta_count);
5038
5039 scan_on_meta_count = 0;
5040
5041 mark_point();
5042 res = pr_jot_scan_logfmt(p, logfmt, LOGFMT_META_CUSTOM, NULL, scan_on_meta,
5043 0);
5044 ck_assert_msg(res == 0, "Failed to scan logmt for CUSTOM: %s",
5045 strerror(errno));
5046 ck_assert_msg(scan_on_meta_count == 1, "Expected scan_on_meta 1, got %u",
5047 scan_on_meta_count);
5048 }
5049 END_TEST
5050
5051 START_TEST (jot_on_json_test) {
5052 pr_jot_ctx_t *ctx;
5053 pr_json_object_t *json;
5054 double num;
5055 int res, truth;
5056 const char *text;
5057
5058 mark_point();
5059 res = pr_jot_on_json(NULL, NULL, 0, NULL, NULL);
5060 ck_assert_msg(res < 0, "Failed to handle null pool");
5061 ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
5062 strerror(errno), errno);
5063
5064 mark_point();
5065 res = pr_jot_on_json(p, NULL, 0, NULL, NULL);
5066 ck_assert_msg(res < 0, "Failed to handle null ctx");
5067 ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
5068 strerror(errno), errno);
5069
5070 ctx = pcalloc(p, sizeof(pr_jot_ctx_t));
5071
5072 mark_point();
5073 res = pr_jot_on_json(p, ctx, 0, NULL, NULL);
5074 ck_assert_msg(res < 0, "Failed to handle null val");
5075 ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
5076 strerror(errno), errno);
5077
5078 mark_point();
5079 res = pr_jot_on_json(p, ctx, 0, NULL, &num);
5080 ck_assert_msg(res < 0, "Failed to handle null ctx->log");
5081 ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
5082 strerror(errno), errno);
5083
5084 json = pr_json_object_alloc(p);
5085 ctx->log = json;
5086
5087 mark_point();
5088 res = pr_jot_on_json(p, ctx, 0, NULL, &num);
5089 ck_assert_msg(res < 0, "Failed to handle null ctx->user_data");
5090 ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
5091 strerror(errno), errno);
5092
5093 ctx->user_data = pr_table_alloc(p, 0);
5094
5095 mark_point();
5096 res = pr_jot_on_json(p, ctx, 0, NULL, &num);
5097 ck_assert_msg(res < 0, "Failed to handle null JSON info");
5098 ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
5099 strerror(errno), errno);
5100
5101 ctx->user_data = pr_jot_get_logfmt2json(p);
5102
5103 mark_point();
5104 truth = FALSE;
5105 res = pr_jot_on_json(p, ctx, LOGFMT_META_CONNECT, NULL, &truth);
5106 ck_assert_msg(res == 0, "Failed to handle LOGFMT_META_CONNECT: %s",
5107 strerror(errno));
5108
5109 mark_point();
5110 num = 2476;
5111 res = pr_jot_on_json(p, ctx, LOGFMT_META_PID, NULL, &num);
5112 ck_assert_msg(res == 0, "Failed to handle LOGFMT_META_PID: %s",
5113 strerror(errno));
5114
5115 mark_point();
5116 text = "lorem ipsum";
5117 res = pr_jot_on_json(p, ctx, LOGFMT_META_IDENT_USER, NULL, text);
5118 ck_assert_msg(res == 0, "Failed to handle LOGFMT_META_IDENT_USER: %s",
5119 strerror(errno));
5120
5121 mark_point();
5122 text = "alef bet vet";
5123 res = pr_jot_on_json(p, ctx, LOGFMT_META_USER, "USER_KEY", text);
5124 ck_assert_msg(res == 0, "Failed to handle LOGFMT_META_USER: %s",
5125 strerror(errno));
5126
5127 (void) pr_json_object_free(json);
5128 }
5129 END_TEST
5130
5131 START_TEST (jot_get_logfmt2json_test) {
5132 pr_table_t *res;
5133
5134 mark_point();
5135 res = pr_jot_get_logfmt2json(NULL);
5136 ck_assert_msg(res == NULL, "Failed to handle null pool");
5137 ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
5138 strerror(errno), errno);
5139
5140 mark_point();
5141 res = pr_jot_get_logfmt2json(p);
5142 ck_assert_msg(res != NULL, "Failed to get map: %s", strerror(errno));
5143 }
5144 END_TEST
5145
5146 START_TEST (jot_get_logfmt_id_name_test) {
5147 register unsigned char i;
5148 const char *res;
5149
5150 mark_point();
5151 res = pr_jot_get_logfmt_id_name(0);
5152 ck_assert_msg(res == NULL, "Failed to handle invalid logfmt_id");
5153 ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
5154 strerror(errno), errno);
5155
5156 /* Currently, the max known LogFormat meta/ID is 54 (XFER_PORT). */
5157 for (i = 2; i < 55; i++) {
5158 mark_point();
5159 res = pr_jot_get_logfmt_id_name(i);
5160 ck_assert_msg(res != NULL, "Failed to get name for LogFormat ID %u: %s",
5161 i, strerror(errno));
5162 }
5163
5164 res = pr_jot_get_logfmt_id_name(LOGFMT_META_CUSTOM);
5165 ck_assert_msg(res != NULL, "Failed to get name for LogFormat ID %u: %s",
5166 LOGFMT_META_CUSTOM, strerror(errno));
5167 }
5168 END_TEST
5169
5170 Suite *tests_get_jot_suite(void) {
5171 Suite *suite;
5172 TCase *testcase;
5173
5174 suite = suite_create("jot");
5175 testcase = tcase_create("base");
5176 tcase_add_checked_fixture(testcase, set_up, tear_down);
5177
5178 tcase_add_test(testcase, jot_filters_create_test);
5179 tcase_add_test(testcase, jot_filters_destroy_test);
5180 tcase_add_test(testcase, jot_filters_include_classes_test);
5181
5182 tcase_add_test(testcase, jot_parse_on_meta_test);
5183 tcase_add_test(testcase, jot_parse_on_unknown_test);
5184 tcase_add_test(testcase, jot_parse_on_other_test);
5185 tcase_add_test(testcase, jot_parse_logfmt_test);
5186 tcase_add_test(testcase, jot_parse_logfmt_short_vars_test);
5187 tcase_add_test(testcase, jot_parse_logfmt_long_vars_test);
5188 tcase_add_test(testcase, jot_parse_logfmt_custom_vars_test);
5189
5190 tcase_add_test(testcase, jot_resolve_logfmt_id_test);
5191 tcase_add_test(testcase, jot_resolve_logfmt_id_on_default_test);
5192 tcase_add_test(testcase, jot_resolve_logfmt_id_filters_test);
5193 tcase_add_test(testcase, jot_resolve_logfmt_id_connect_test);
5194 tcase_add_test(testcase, jot_resolve_logfmt_id_disconnect_test);
5195 tcase_add_test(testcase, jot_resolve_logfmt_id_custom_test);
5196 tcase_add_test(testcase, jot_resolve_logfmt_ids_test);
5197 tcase_add_test(testcase, jot_resolve_logfmt_invalid_test);
5198 tcase_add_test(testcase, jot_resolve_logfmt_basename_test);
5199 tcase_add_test(testcase, jot_resolve_logfmt_bytes_sent_test);
5200 tcase_add_test(testcase, jot_resolve_logfmt_filename_test);
5201 tcase_add_test(testcase, jot_resolve_logfmt_file_modified_test);
5202 tcase_add_test(testcase, jot_resolve_logfmt_file_offset_test);
5203 tcase_add_test(testcase, jot_resolve_logfmt_file_size_test);
5204 tcase_add_test(testcase, jot_resolve_logfmt_env_var_test);
5205 tcase_add_test(testcase, jot_resolve_logfmt_note_test);
5206 tcase_add_test(testcase, jot_resolve_logfmt_var_test);
5207 tcase_add_test(testcase, jot_resolve_logfmt_remote_port_test);
5208 tcase_add_test(testcase, jot_resolve_logfmt_rfc1413_ident_test);
5209 tcase_add_test(testcase, jot_resolve_logfmt_xfer_secs_test);
5210 tcase_add_test(testcase, jot_resolve_logfmt_xfer_ms_test);
5211 tcase_add_test(testcase, jot_resolve_logfmt_command_test);
5212 tcase_add_test(testcase, jot_resolve_logfmt_local_name_test);
5213 tcase_add_test(testcase, jot_resolve_logfmt_local_port_test);
5214 tcase_add_test(testcase, jot_resolve_logfmt_user_test);
5215 tcase_add_test(testcase, jot_resolve_logfmt_uid_test);
5216 tcase_add_test(testcase, jot_resolve_logfmt_group_test);
5217 tcase_add_test(testcase, jot_resolve_logfmt_gid_test);
5218 tcase_add_test(testcase, jot_resolve_logfmt_original_user_test);
5219 tcase_add_test(testcase, jot_resolve_logfmt_response_code_test);
5220 tcase_add_test(testcase, jot_resolve_logfmt_response_text_test);
5221 tcase_add_test(testcase, jot_resolve_logfmt_response_ms_test);
5222 tcase_add_test(testcase, jot_resolve_logfmt_class_test);
5223 tcase_add_test(testcase, jot_resolve_logfmt_anon_passwd_test);
5224 tcase_add_test(testcase, jot_resolve_logfmt_method_test);
5225 tcase_add_test(testcase, jot_resolve_logfmt_xfer_path_test);
5226 tcase_add_test(testcase, jot_resolve_logfmt_xfer_port_test);
5227 tcase_add_test(testcase, jot_resolve_logfmt_xfer_type_test);
5228 tcase_add_test(testcase, jot_resolve_logfmt_xfer_status_test);
5229 tcase_add_test(testcase, jot_resolve_logfmt_xfer_failure_test);
5230 tcase_add_test(testcase, jot_resolve_logfmt_dir_name_test);
5231 tcase_add_test(testcase, jot_resolve_logfmt_dir_path_test);
5232 tcase_add_test(testcase, jot_resolve_logfmt_cmd_params_test);
5233 tcase_add_test(testcase, jot_resolve_logfmt_rename_from_test);
5234 tcase_add_test(testcase, jot_resolve_logfmt_eos_reason_test);
5235 tcase_add_test(testcase, jot_resolve_logfmt_vhost_ip_test);
5236 tcase_add_test(testcase, jot_resolve_logfmt_filters_test);
5237 tcase_add_test(testcase, jot_resolve_logfmt_on_default_test);
5238 tcase_add_test(testcase, jot_resolve_logfmt_on_other_test);
5239 tcase_add_test(testcase, jot_resolve_logfmt_connect_test);
5240 tcase_add_test(testcase, jot_resolve_logfmt_disconnect_test);
5241 tcase_add_test(testcase, jot_resolve_logfmt_custom_test);
5242 tcase_add_test(testcase, jot_resolve_logfmts_test);
5243
5244 tcase_add_test(testcase, jot_scan_logfmt_test);
5245 tcase_add_test(testcase, jot_on_json_test);
5246 tcase_add_test(testcase, jot_get_logfmt2json_test);
5247 tcase_add_test(testcase, jot_get_logfmt_id_name_test);
5248
5249 suite_add_tcase(suite, testcase);
5250 return suite;
5251 }