| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
#include <zlib.h> |
| 31 |
|
| 32 |
#include "conf.h" |
| 33 |
#include "privs.h" |
| 34 |
|
| 35 |
#define MOD_DEFLATE_VERSION "mod_deflate/0.6" |
| 36 |
|
| 37 |
|
| 38 |
#if PROFTPD_VERSION_NUMBER < 0x0001030604 |
| 39 |
# error "ProFTPD 1.3.6 or later required" |
| 40 |
#endif |
| 41 |
|
| 42 |
module deflate_module; |
| 43 |
|
| 44 |
static int deflate_sess_init(void); |
| 45 |
|
| 46 |
static int deflate_enabled = FALSE; |
| 47 |
static int deflate_engine = FALSE; |
| 48 |
static int deflate_logfd = -1; |
| 49 |
static pr_netio_t *deflate_netio = NULL; |
| 50 |
static pr_netio_t *deflate_next_netio = NULL; |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
static int (*deflate_next_netio_close)(pr_netio_stream_t *) = NULL; |
| 56 |
static pr_netio_stream_t *(*deflate_next_netio_open)(pr_netio_stream_t *, int, int) = NULL; |
| 57 |
static int (*deflate_next_netio_read)(pr_netio_stream_t *, char *, size_t) = NULL; |
| 58 |
static int (*deflate_next_netio_shutdown)(pr_netio_stream_t *, int) = NULL; |
| 59 |
static int (*deflate_next_netio_write)(pr_netio_stream_t *, char *, size_t) = NULL; |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
#define MOD_DEFLATE_DEFAULT_COMPRESS_LEVEL 7 |
| 74 |
static int deflate_compression_level = MOD_DEFLATE_DEFAULT_COMPRESS_LEVEL; |
| 75 |
|
| 76 |
#define MOD_DEFLATE_DEFAULT_MEM_LEVEL 8 |
| 77 |
static int deflate_mem_level = MOD_DEFLATE_DEFAULT_MEM_LEVEL; |
| 78 |
|
| 79 |
#define MOD_DEFLATE_DEFAULT_STRATEGY Z_DEFAULT_STRATEGY |
| 80 |
static int deflate_strategy = MOD_DEFLATE_DEFAULT_STRATEGY; |
| 81 |
|
| 82 |
#define MOD_DEFLATE_DEFAULT_WINDOW_BITS 15 |
| 83 |
static int deflate_window_bits = MOD_DEFLATE_DEFAULT_WINDOW_BITS; |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
static Byte *deflate_zbuf_ptr = NULL; |
| 90 |
static Byte *deflate_zbuf = NULL; |
| 91 |
static size_t deflate_zbuflen = 0; |
| 92 |
static size_t deflate_zbufsz = 0; |
| 93 |
|
| 94 |
static Byte *deflate_rbuf = NULL; |
| 95 |
static size_t deflate_rbuflen = 0; |
| 96 |
static size_t deflate_rbufsz = 0; |
| 97 |
|
| 98 |
#define DEFLATE_NETIO_NOTE "mod_deflate.z_stream" |
| 99 |
static int deflate_zerrno = 0; |
| 100 |
|
| 101 |
static const char *trace_channel = "deflate"; |
| 102 |
|
| 103 |
static const char *deflate_zstrerror(int zerrno) { |
| 104 |
const char *zstr = "unknown"; |
| 105 |
|
| 106 |
switch (zerrno) { |
| 107 |
case Z_OK: |
| 108 |
zstr = "OK"; |
| 109 |
break; |
| 110 |
|
| 111 |
case Z_STREAM_END: |
| 112 |
return "End of stream"; |
| 113 |
break; |
| 114 |
|
| 115 |
case Z_NEED_DICT: |
| 116 |
return "Need dictionary"; |
| 117 |
break; |
| 118 |
|
| 119 |
case Z_ERRNO: |
| 120 |
zstr = strerror(errno); |
| 121 |
break; |
| 122 |
|
| 123 |
case Z_DATA_ERROR: |
| 124 |
zstr = "Data error"; |
| 125 |
break; |
| 126 |
|
| 127 |
case Z_MEM_ERROR: |
| 128 |
zstr = "Memory error"; |
| 129 |
break; |
| 130 |
|
| 131 |
case Z_BUF_ERROR: |
| 132 |
zstr = "Buffer error"; |
| 133 |
break; |
| 134 |
|
| 135 |
case Z_VERSION_ERROR: |
| 136 |
zstr = "Version error"; |
| 137 |
break; |
| 138 |
} |
| 139 |
|
| 140 |
return zstr; |
| 141 |
} |
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
static int deflate_netio_close_cb(pr_netio_stream_t *nstrm) { |
| 147 |
int res = 0; |
| 148 |
|
| 149 |
if (nstrm->strm_type == PR_NETIO_STRM_DATA) { |
| 150 |
z_stream *zstrm; |
| 151 |
|
| 152 |
zstrm = (z_stream *) pr_table_get(nstrm->notes, DEFLATE_NETIO_NOTE, NULL); |
| 153 |
if (zstrm == NULL) { |
| 154 |
int xerrno = 0; |
| 155 |
|
| 156 |
res = 0; |
| 157 |
|
| 158 |
if (deflate_next_netio_close != NULL) { |
| 159 |
res = (deflate_next_netio_close)(nstrm); |
| 160 |
xerrno = errno; |
| 161 |
|
| 162 |
if (res < 0) { |
| 163 |
pr_trace_msg(trace_channel, 1, "error calling next netio close: %s", |
| 164 |
strerror(xerrno)); |
| 165 |
} |
| 166 |
} |
| 167 |
|
| 168 |
errno = xerrno; |
| 169 |
return res; |
| 170 |
} |
| 171 |
|
| 172 |
if (nstrm->strm_mode == PR_NETIO_IO_WR) { |
| 173 |
if (zstrm->total_in > 0) { |
| 174 |
float ratio; |
| 175 |
|
| 176 |
ratio = ((float) zstrm->total_out / (float) zstrm->total_in); |
| 177 |
|
| 178 |
(void) pr_log_writefile(deflate_logfd, MOD_DEFLATE_VERSION, |
| 179 |
"%s: deflated %lu bytes to %lu bytes (%0.2lf%% compression)", |
| 180 |
session.curr_cmd, zstrm->total_in, zstrm->total_out, |
| 181 |
(1.0 - ratio) * 100.0); |
| 182 |
} |
| 183 |
|
| 184 |
res = deflateEnd(zstrm); |
| 185 |
if (res != Z_OK) { |
| 186 |
pr_trace_msg(trace_channel, 3, |
| 187 |
"close: error closing deflating netio: [%d] %s", res, |
| 188 |
zstrm->msg ? zstrm->msg : deflate_zstrerror(res)); |
| 189 |
|
| 190 |
(void) pr_log_writefile(deflate_logfd, MOD_DEFLATE_VERSION, |
| 191 |
"error closing deflating netio: [%d] %s", res, |
| 192 |
zstrm->msg ? zstrm->msg : deflate_zstrerror(res)); |
| 193 |
} |
| 194 |
|
| 195 |
} else if (nstrm->strm_mode == PR_NETIO_IO_RD) { |
| 196 |
if (zstrm->total_in > 0) { |
| 197 |
float ratio; |
| 198 |
|
| 199 |
ratio = ((float) zstrm->total_in / (float) zstrm->total_out); |
| 200 |
|
| 201 |
(void) pr_log_writefile(deflate_logfd, MOD_DEFLATE_VERSION, |
| 202 |
"%s: inflated %lu bytes to %lu bytes (%0.2lf%% compression)", |
| 203 |
session.curr_cmd, zstrm->total_in, zstrm->total_out, |
| 204 |
(1.0 - ratio) * 100.0); |
| 205 |
} |
| 206 |
|
| 207 |
res = inflateEnd(zstrm); |
| 208 |
if (res != Z_OK) { |
| 209 |
pr_trace_msg(trace_channel, 3, |
| 210 |
"close: error closing inflating netio: [%d] %s", res, |
| 211 |
zstrm->msg ? zstrm->msg : deflate_zstrerror(res)); |
| 212 |
|
| 213 |
(void) pr_log_writefile(deflate_logfd, MOD_DEFLATE_VERSION, |
| 214 |
"error closing inflating netio: [%d] %s", res, |
| 215 |
zstrm->msg ? zstrm->msg : deflate_zstrerror(res)); |
| 216 |
} |
| 217 |
} |
| 218 |
|
| 219 |
if (deflate_next_netio == NULL) { |
| 220 |
res = close(nstrm->strm_fd); |
| 221 |
nstrm->strm_fd = -1; |
| 222 |
} |
| 223 |
|
| 224 |
pr_table_remove(nstrm->notes, DEFLATE_NETIO_NOTE, NULL); |
| 225 |
} |
| 226 |
|
| 227 |
if (deflate_next_netio_close != NULL) { |
| 228 |
if ((deflate_next_netio_close)(nstrm) < 0) { |
| 229 |
pr_trace_msg(trace_channel, 1, "error calling next netio close: %s", |
| 230 |
strerror(errno)); |
| 231 |
} |
| 232 |
} |
| 233 |
|
| 234 |
return res; |
| 235 |
} |
| 236 |
|
| 237 |
static pr_netio_stream_t *deflate_netio_open_cb(pr_netio_stream_t *nstrm, |
| 238 |
int fd, int mode) { |
| 239 |
|
| 240 |
nstrm->strm_fd = fd; |
| 241 |
nstrm->strm_mode = mode; |
| 242 |
|
| 243 |
if (deflate_next_netio_open != NULL) { |
| 244 |
if ((deflate_next_netio_open)(nstrm, fd, mode) == NULL) { |
| 245 |
int xerrno = errno; |
| 246 |
|
| 247 |
pr_trace_msg(trace_channel, 1, "error calling next netio open: %s", |
| 248 |
strerror(xerrno)); |
| 249 |
errno = xerrno; |
| 250 |
return NULL; |
| 251 |
} |
| 252 |
} |
| 253 |
|
| 254 |
if (nstrm->strm_type == PR_NETIO_STRM_DATA) { |
| 255 |
int res; |
| 256 |
z_stream *zstrm; |
| 257 |
|
| 258 |
|
| 259 |
zstrm = pcalloc(nstrm->strm_pool, sizeof(z_stream)); |
| 260 |
zstrm->zalloc = Z_NULL; |
| 261 |
zstrm->zfree = Z_NULL; |
| 262 |
zstrm->opaque = Z_NULL; |
| 263 |
zstrm->next_in = Z_NULL; |
| 264 |
zstrm->next_out = Z_NULL; |
| 265 |
zstrm->avail_in = 0; |
| 266 |
zstrm->avail_out = 0; |
| 267 |
|
| 268 |
if (pr_table_add(nstrm->notes, |
| 269 |
pstrdup(nstrm->strm_pool, DEFLATE_NETIO_NOTE), zstrm, |
| 270 |
sizeof(z_stream *)) < 0) { |
| 271 |
if (errno != EEXIST) { |
| 272 |
(void) pr_log_writefile(deflate_logfd, MOD_DEFLATE_VERSION, |
| 273 |
"error stashing '%s' note: %s", DEFLATE_NETIO_NOTE, strerror(errno)); |
| 274 |
} |
| 275 |
} |
| 276 |
|
| 277 |
memset(deflate_zbuf_ptr, '\0', deflate_zbufsz); |
| 278 |
deflate_zbuf = deflate_zbuf_ptr; |
| 279 |
|
| 280 |
if (nstrm->strm_mode == PR_NETIO_IO_WR) { |
| 281 |
|
| 282 |
res = deflateInit2(zstrm, deflate_compression_level, Z_DEFLATED, |
| 283 |
deflate_window_bits, deflate_mem_level, deflate_strategy); |
| 284 |
|
| 285 |
switch (res) { |
| 286 |
case Z_OK: |
| 287 |
zstrm->next_out = deflate_zbuf; |
| 288 |
zstrm->avail_out = deflate_zbufsz; |
| 289 |
break; |
| 290 |
|
| 291 |
case Z_MEM_ERROR: |
| 292 |
case Z_STREAM_ERROR: |
| 293 |
pr_trace_msg(trace_channel, 3, |
| 294 |
"open: error initializing for deflation: [%d] %s", res, |
| 295 |
zstrm->msg ? zstrm->msg : deflate_zstrerror(res)); |
| 296 |
|
| 297 |
(void) pr_log_writefile(deflate_logfd, MOD_DEFLATE_VERSION, |
| 298 |
"error initializing for deflation: [%d] %s", res, |
| 299 |
zstrm->msg ? zstrm->msg : deflate_zstrerror(res)); |
| 300 |
|
| 301 |
errno = EINVAL; |
| 302 |
return NULL; |
| 303 |
} |
| 304 |
|
| 305 |
} else if (nstrm->strm_mode == PR_NETIO_IO_RD) { |
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
res = inflateInit2(zstrm, deflate_window_bits + 32); |
| 312 |
|
| 313 |
switch (res) { |
| 314 |
case Z_OK: |
| 315 |
zstrm->next_out = deflate_zbuf; |
| 316 |
zstrm->avail_out = deflate_zbufsz; |
| 317 |
break; |
| 318 |
|
| 319 |
case Z_MEM_ERROR: |
| 320 |
case Z_STREAM_ERROR: |
| 321 |
pr_trace_msg(trace_channel, 3, |
| 322 |
"open: error initializing for inflation: [%d] %s", res, |
| 323 |
zstrm->msg ? zstrm->msg : deflate_zstrerror(res)); |
| 324 |
|
| 325 |
(void) pr_log_writefile(deflate_logfd, MOD_DEFLATE_VERSION, |
| 326 |
"error initializing for inflation: [%d] %s", res, |
| 327 |
zstrm->msg ? zstrm->msg : deflate_zstrerror(res)); |
| 328 |
|
| 329 |
errno = EINVAL; |
| 330 |
return NULL; |
| 331 |
} |
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
deflate_rbuflen = 0; |
| 337 |
deflate_zbuflen = 0; |
| 338 |
} |
| 339 |
} |
| 340 |
|
| 341 |
return nstrm; |
| 342 |
} |
| 343 |
|
| 344 |
static int deflate_netio_read_cb(pr_netio_stream_t *nstrm, char *buf, |
| 345 |
size_t bufsz) { |
| 346 |
|
| 347 |
if (bufsz == 0) { |
| 348 |
return 0; |
| 349 |
} |
| 350 |
|
| 351 |
if (nstrm->strm_type == PR_NETIO_STRM_DATA) { |
| 352 |
int datalen = 0, nread = 0, res, xerrno; |
| 353 |
z_stream *zstrm; |
| 354 |
|
| 355 |
zstrm = (z_stream *) pr_table_get(nstrm->notes, DEFLATE_NETIO_NOTE, NULL); |
| 356 |
if (zstrm == NULL) { |
| 357 |
pr_trace_msg(trace_channel, 2, |
| 358 |
"no zstream found in stream data for reading"); |
| 359 |
errno = EIO; |
| 360 |
return -1; |
| 361 |
} |
| 362 |
|
| 363 |
res = 0; |
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
if (deflate_zbuflen > 0) { |
| 371 |
if (bufsz >= deflate_zbuflen) { |
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
pr_trace_msg(trace_channel, 9, "read: returning %lu bytes of " |
| 377 |
"previously uncompressed data; no data read from client", |
| 378 |
(unsigned long) deflate_zbuflen); |
| 379 |
|
| 380 |
memcpy(buf, deflate_zbuf, deflate_zbuflen); |
| 381 |
res = deflate_zbuflen; |
| 382 |
|
| 383 |
|
| 384 |
deflate_zbuf = deflate_zbuf_ptr; |
| 385 |
deflate_zbuflen = 0; |
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
session.total_raw_in -= res; |
| 397 |
|
| 398 |
return res; |
| 399 |
} |
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
pr_trace_msg(trace_channel, 9, "read: returning %lu bytes of previously " |
| 406 |
"uncompressed data (of %lu bytes total); no data read from client", |
| 407 |
(unsigned long) bufsz, (unsigned long) deflate_zbuflen); |
| 408 |
|
| 409 |
memcpy(buf, deflate_zbuf, bufsz); |
| 410 |
res = bufsz; |
| 411 |
|
| 412 |
deflate_zbuf += bufsz; |
| 413 |
deflate_zbuflen -= bufsz; |
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
session.total_raw_in -= res; |
| 425 |
|
| 426 |
return res; |
| 427 |
} |
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
if (zstrm->avail_in == 0) { |
| 441 |
|
| 442 |
datalen = deflate_rbufsz - deflate_rbuflen; |
| 443 |
|
| 444 |
if (deflate_next_netio_read != NULL) { |
| 445 |
nread = (deflate_next_netio_read)(nstrm, (char *) deflate_rbuf, |
| 446 |
datalen); |
| 447 |
|
| 448 |
} else { |
| 449 |
|
| 450 |
nread = read(nstrm->strm_fd, deflate_rbuf, datalen); |
| 451 |
} |
| 452 |
|
| 453 |
if (nread < 0) { |
| 454 |
xerrno = errno; |
| 455 |
|
| 456 |
(void) pr_log_writefile(deflate_logfd, MOD_DEFLATE_VERSION, |
| 457 |
"error reading from socket %d: %s", nstrm->strm_fd, strerror(xerrno)); |
| 458 |
|
| 459 |
errno = xerrno; |
| 460 |
return -1; |
| 461 |
} |
| 462 |
|
| 463 |
if (nread == 0) { |
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
pr_trace_msg(trace_channel, 8, |
| 469 |
"read: read EOF from client, returning 0"); |
| 470 |
return 0; |
| 471 |
} |
| 472 |
|
| 473 |
pr_trace_msg(trace_channel, 9, |
| 474 |
"read: read %d bytes of compressed data from client", nread); |
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
session.total_raw_in += nread; |
| 480 |
|
| 481 |
datalen = nread; |
| 482 |
zstrm->next_in = deflate_rbuf; |
| 483 |
zstrm->avail_in = datalen; |
| 484 |
|
| 485 |
} else { |
| 486 |
pr_trace_msg(trace_channel, 9, |
| 487 |
"read: processing %d bytes of leftover compressed data from client", |
| 488 |
zstrm->avail_in); |
| 489 |
} |
| 490 |
|
| 491 |
zstrm->next_out = deflate_zbuf; |
| 492 |
zstrm->avail_out = deflate_zbufsz; |
| 493 |
|
| 494 |
pr_trace_msg(trace_channel, 19, |
| 495 |
"read: pre-inflate zstream state: avail_in = %d, avail_out = %d", |
| 496 |
zstrm->avail_in, zstrm->avail_out); |
| 497 |
|
| 498 |
deflate_zerrno = inflate(zstrm, Z_SYNC_FLUSH); |
| 499 |
xerrno = errno; |
| 500 |
|
| 501 |
pr_trace_msg(trace_channel, 19, |
| 502 |
"read: post-inflate zstream state: avail_in = %d, avail_out = %d " |
| 503 |
"(zerrno = %s)", zstrm->avail_in, zstrm->avail_out, |
| 504 |
deflate_zstrerror(deflate_zerrno)); |
| 505 |
|
| 506 |
errno = xerrno; |
| 507 |
|
| 508 |
switch (deflate_zerrno) { |
| 509 |
case Z_OK: |
| 510 |
case Z_STREAM_END: |
| 511 |
break; |
| 512 |
|
| 513 |
default: |
| 514 |
pr_trace_msg(trace_channel, 3, |
| 515 |
"read: error inflating %lu bytes of data: [%d] %s: %s", |
| 516 |
(unsigned long) datalen, deflate_zerrno, |
| 517 |
deflate_zstrerror(deflate_zerrno), |
| 518 |
zstrm->msg ? zstrm->msg : "unavailable"); |
| 519 |
|
| 520 |
errno = xerrno; |
| 521 |
(void) pr_log_writefile(deflate_logfd, MOD_DEFLATE_VERSION, |
| 522 |
"error inflating %lu bytes of data: [%d] %s", |
| 523 |
(unsigned long) datalen, deflate_zerrno, |
| 524 |
zstrm->msg ? zstrm->msg : deflate_zstrerror(deflate_zerrno)); |
| 525 |
|
| 526 |
errno = EIO; |
| 527 |
return -1; |
| 528 |
} |
| 529 |
|
| 530 |
deflate_zbuflen = deflate_zbufsz - zstrm->avail_out; |
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
errno = EAGAIN; |
| 537 |
return -1; |
| 538 |
} |
| 539 |
|
| 540 |
return read(nstrm->strm_fd, buf, bufsz); |
| 541 |
} |
| 542 |
|
| 543 |
static int deflate_netio_shutdown_cb(pr_netio_stream_t *nstrm, int how) { |
| 544 |
|
| 545 |
if (nstrm->strm_type == PR_NETIO_STRM_DATA) { |
| 546 |
int res = 0; |
| 547 |
z_stream *zstrm; |
| 548 |
|
| 549 |
zstrm = (z_stream *) pr_table_get(nstrm->notes, DEFLATE_NETIO_NOTE, NULL); |
| 550 |
if (zstrm == NULL) { |
| 551 |
return 0; |
| 552 |
} |
| 553 |
|
| 554 |
if (nstrm->strm_mode == PR_NETIO_IO_WR) { |
| 555 |
zstrm->next_in = Z_NULL; |
| 556 |
zstrm->avail_in = 0; |
| 557 |
|
| 558 |
pr_trace_msg(trace_channel, 19, |
| 559 |
"shutdown: pre-deflate zstream state: avail_in = %d, avail_out = %d", |
| 560 |
zstrm->avail_in, zstrm->avail_out); |
| 561 |
|
| 562 |
deflate_zerrno = deflate(zstrm, Z_FINISH); |
| 563 |
|
| 564 |
pr_trace_msg(trace_channel, 19, |
| 565 |
"shutdown: post-inflate zstream state: avail_in = %d, avail_out = %d " |
| 566 |
"(zerrno = %s)", zstrm->avail_in, zstrm->avail_out, |
| 567 |
deflate_zstrerror(deflate_zerrno)); |
| 568 |
|
| 569 |
if (deflate_zerrno != Z_OK && |
| 570 |
deflate_zerrno != Z_STREAM_END) { |
| 571 |
pr_trace_msg(trace_channel, 3, |
| 572 |
"shutdown: error deflating data: [%d] %s: %s", deflate_zerrno, |
| 573 |
deflate_zstrerror(deflate_zerrno), |
| 574 |
zstrm->msg ? zstrm->msg : "unavailable"); |
| 575 |
|
| 576 |
(void) pr_log_writefile(deflate_logfd, MOD_DEFLATE_VERSION, |
| 577 |
"error deflating data: [%d] %s", deflate_zerrno, |
| 578 |
zstrm->msg ? zstrm->msg : deflate_zstrerror(deflate_zerrno)); |
| 579 |
|
| 580 |
} else { |
| 581 |
size_t datalen, offset; |
| 582 |
|
| 583 |
datalen = deflate_zbufsz - zstrm->avail_out; |
| 584 |
offset = 0; |
| 585 |
|
| 586 |
while (datalen > 0) { |
| 587 |
if (deflate_next_netio_write != NULL) { |
| 588 |
res = (deflate_next_netio_write)(nstrm, |
| 589 |
(char *) (deflate_zbuf + offset), datalen); |
| 590 |
|
| 591 |
} else { |
| 592 |
res = write(nstrm->strm_fd, deflate_zbuf + offset, datalen); |
| 593 |
} |
| 594 |
|
| 595 |
if (res < 0) { |
| 596 |
if (errno == EINTR || |
| 597 |
errno == EAGAIN) { |
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
pr_signals_handle(); |
| 602 |
continue; |
| 603 |
} |
| 604 |
|
| 605 |
(void) pr_log_writefile(deflate_logfd, MOD_DEFLATE_VERSION, |
| 606 |
"error writing to socket %d: %s", nstrm->strm_fd, |
| 607 |
strerror(errno)); |
| 608 |
return -1; |
| 609 |
} |
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
session.total_raw_out += res; |
| 615 |
|
| 616 |
|
| 617 |
if ((size_t) res == datalen) { |
| 618 |
break; |
| 619 |
} |
| 620 |
|
| 621 |
offset += res; |
| 622 |
datalen -= res; |
| 623 |
} |
| 624 |
} |
| 625 |
|
| 626 |
if (deflate_next_netio_shutdown != NULL) { |
| 627 |
res = (deflate_next_netio_shutdown)(nstrm, how); |
| 628 |
|
| 629 |
} else { |
| 630 |
res = shutdown(nstrm->strm_fd, how); |
| 631 |
} |
| 632 |
|
| 633 |
return res; |
| 634 |
} |
| 635 |
} |
| 636 |
|
| 637 |
return shutdown(nstrm->strm_fd, how); |
| 638 |
} |
| 639 |
|
| 640 |
static int deflate_netio_write_cb(pr_netio_stream_t *nstrm, char *buf, |
| 641 |
size_t buflen) { |
| 642 |
|
| 643 |
if (buflen == 0) { |
| 644 |
return 0; |
| 645 |
} |
| 646 |
|
| 647 |
if (nstrm->strm_type == PR_NETIO_STRM_DATA) { |
| 648 |
int res = 0, xerrno; |
| 649 |
size_t datalen, offset = 0; |
| 650 |
z_stream *zstrm; |
| 651 |
|
| 652 |
zstrm = (z_stream *) pr_table_get(nstrm->notes, DEFLATE_NETIO_NOTE, NULL); |
| 653 |
if (zstrm == NULL) { |
| 654 |
pr_trace_msg(trace_channel, 2, |
| 655 |
"no zstream found in stream data for writing"); |
| 656 |
errno = EIO; |
| 657 |
return -1; |
| 658 |
} |
| 659 |
|
| 660 |
|
| 661 |
zstrm->next_in = (Bytef *) buf; |
| 662 |
zstrm->avail_in = buflen; |
| 663 |
|
| 664 |
pr_trace_msg(trace_channel, 19, |
| 665 |
"write: pre-deflate zstream state: avail_in = %d, avail_out = %d", |
| 666 |
zstrm->avail_in, zstrm->avail_out); |
| 667 |
|
| 668 |
deflate_zerrno = deflate(zstrm, Z_SYNC_FLUSH); |
| 669 |
xerrno = errno; |
| 670 |
|
| 671 |
pr_trace_msg(trace_channel, 19, |
| 672 |
"write: post-inflate zstream state: avail_in = %d, avail_out = %d " |
| 673 |
"(zerrno = %s)", zstrm->avail_in, zstrm->avail_out, |
| 674 |
deflate_zstrerror(deflate_zerrno)); |
| 675 |
|
| 676 |
errno = xerrno; |
| 677 |
|
| 678 |
if (deflate_zerrno != Z_OK) { |
| 679 |
pr_trace_msg(trace_channel, 3, "write: error deflating data: [%d] %s: %s", |
| 680 |
deflate_zerrno, deflate_zstrerror(deflate_zerrno), |
| 681 |
zstrm->msg ? zstrm->msg : "unavailable"); |
| 682 |
|
| 683 |
errno = xerrno; |
| 684 |
|
| 685 |
(void) pr_log_writefile(deflate_logfd, MOD_DEFLATE_VERSION, |
| 686 |
"error deflating data: [%d] %s", deflate_zerrno, |
| 687 |
zstrm->msg ? zstrm->msg : deflate_zstrerror(deflate_zerrno)); |
| 688 |
|
| 689 |
errno = EIO; |
| 690 |
return -1; |
| 691 |
} |
| 692 |
|
| 693 |
datalen = deflate_zbufsz - zstrm->avail_out; |
| 694 |
|
| 695 |
while (datalen > 0) { |
| 696 |
pr_signals_handle(); |
| 697 |
|
| 698 |
if (deflate_next_netio_write != NULL) { |
| 699 |
res = (deflate_next_netio_write)(nstrm, |
| 700 |
(char *) (deflate_zbuf + offset), datalen); |
| 701 |
|
| 702 |
} else { |
| 703 |
res = write(nstrm->strm_fd, deflate_zbuf + offset, datalen); |
| 704 |
} |
| 705 |
|
| 706 |
if (res < 0) { |
| 707 |
if (errno == EINTR || |
| 708 |
errno == EAGAIN) { |
| 709 |
|
| 710 |
|
| 711 |
|
| 712 |
pr_signals_handle(); |
| 713 |
continue; |
| 714 |
} |
| 715 |
|
| 716 |
(void) pr_log_writefile(deflate_logfd, MOD_DEFLATE_VERSION, |
| 717 |
"error writing to socket %d: %s", nstrm->strm_fd, strerror(errno)); |
| 718 |
return -1; |
| 719 |
} |
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
session.total_raw_out += res; |
| 725 |
|
| 726 |
(void) pr_log_writefile(deflate_logfd, MOD_DEFLATE_VERSION, |
| 727 |
"wrote %d (of %lu) bytes of compressed of data to socket %d", res, |
| 728 |
(unsigned long) datalen, nstrm->strm_fd); |
| 729 |
|
| 730 |
|
| 731 |
if ((size_t) res == datalen) { |
| 732 |
zstrm->next_out = deflate_zbuf; |
| 733 |
zstrm->avail_out = deflate_zbufsz; |
| 734 |
break; |
| 735 |
|
| 736 |
} else { |
| 737 |
offset += res; |
| 738 |
datalen -= res; |
| 739 |
} |
| 740 |
} |
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
|
| 746 |
|
| 747 |
|
| 748 |
|
| 749 |
|
| 750 |
|
| 751 |
|
| 752 |
res = (buflen - zstrm->avail_in); |
| 753 |
session.total_raw_out -= res; |
| 754 |
|
| 755 |
pr_trace_msg(trace_channel, 9, "write: returning %d for %lu bytes", |
| 756 |
res, (unsigned long) buflen); |
| 757 |
return res; |
| 758 |
} |
| 759 |
|
| 760 |
return write(nstrm->strm_fd, buf, buflen); |
| 761 |
} |
| 762 |
|
| 763 |
|
| 764 |
|
| 765 |
|
| 766 |
|
| 767 |
MODRET set_deflateengine(cmd_rec *cmd) { |
| 768 |
int engine; |
| 769 |
config_rec *c; |
| 770 |
|
| 771 |
CHECK_ARGS(cmd, 1); |
| 772 |
CHECK_CONF(cmd, CONF_ROOT|CONF_VIRTUAL|CONF_GLOBAL); |
| 773 |
|
| 774 |
engine = get_boolean(cmd, 1); |
| 775 |
if (engine == -1) { |
| 776 |
CONF_ERROR(cmd, "expected Boolean parameter"); |
| 777 |
} |
| 778 |
|
| 779 |
c = add_config_param(cmd->argv[0], 1, NULL); |
| 780 |
c->argv[0] = pcalloc(c->pool, sizeof(unsigned int)); |
| 781 |
*((unsigned int *) c->argv[0]) = engine; |
| 782 |
|
| 783 |
return PR_HANDLED(cmd); |
| 784 |
} |
| 785 |
|
| 786 |
|
| 787 |
MODRET set_deflatelog(cmd_rec *cmd) { |
| 788 |
char *path; |
| 789 |
|
| 790 |
CHECK_ARGS(cmd, 1); |
| 791 |
CHECK_CONF(cmd, CONF_ROOT|CONF_VIRTUAL|CONF_GLOBAL); |
| 792 |
|
| 793 |
path = cmd->argv[1]; |
| 794 |
if (pr_fs_valid_path(path) < 0) { |
| 795 |
CONF_ERROR(cmd, pstrcat(cmd->tmp_pool, ": ", path, " is not a valid path", |
| 796 |
NULL)); |
| 797 |
} |
| 798 |
|
| 799 |
add_config_param_str(cmd->argv[0], 1, path); |
| 800 |
return PR_HANDLED(cmd); |
| 801 |
} |
| 802 |
|
| 803 |
|
| 804 |
|
| 805 |
|
| 806 |
MODRET deflate_opts(cmd_rec *cmd) { |
| 807 |
if (deflate_engine == FALSE) { |
| 808 |
return PR_DECLINED(cmd); |
| 809 |
} |
| 810 |
|
| 811 |
if (cmd->argc < 3) { |
| 812 |
return PR_DECLINED(cmd); |
| 813 |
} |
| 814 |
|
| 815 |
if (strcasecmp(cmd->argv[1], "Z") == 0) { |
| 816 |
|
| 817 |
|
| 818 |
|
| 819 |
if (cmd->argc == 3) { |
| 820 |
|
| 821 |
|
| 822 |
|
| 823 |
deflate_compression_level = MOD_DEFLATE_DEFAULT_COMPRESS_LEVEL; |
| 824 |
deflate_mem_level = MOD_DEFLATE_DEFAULT_MEM_LEVEL; |
| 825 |
deflate_strategy = MOD_DEFLATE_DEFAULT_STRATEGY; |
| 826 |
deflate_window_bits = MOD_DEFLATE_DEFAULT_WINDOW_BITS; |
| 827 |
|
| 828 |
pr_response_add(R_200, _("%s OK"), (char *) cmd->argv[0]); |
| 829 |
return PR_HANDLED(cmd); |
| 830 |
|
| 831 |
} else { |
| 832 |
register unsigned int i; |
| 833 |
|
| 834 |
if (cmd->argc % 2 != 0) { |
| 835 |
pr_response_add_err(R_501, _("Bad number of parameters")); |
| 836 |
|
| 837 |
pr_cmd_set_errno(cmd, EINVAL); |
| 838 |
errno = EINVAL; |
| 839 |
return PR_ERROR(cmd); |
| 840 |
} |
| 841 |
|
| 842 |
for (i = 2; i < cmd->argc; i += 2) { |
| 843 |
char *key, *val; |
| 844 |
|
| 845 |
key = cmd->argv[i]; |
| 846 |
val = cmd->argv[i+1]; |
| 847 |
|
| 848 |
if (strcasecmp(key, "blocksize") == 0 || |
| 849 |
strcasecmp(key, "engine") == 0) { |
| 850 |
pr_response_add_err(R_501, _("%s: unsupported MODE Z option: %s"), |
| 851 |
(char *) cmd->argv[0], key); |
| 852 |
|
| 853 |
pr_cmd_set_errno(cmd, ENOSYS); |
| 854 |
errno = ENOSYS; |
| 855 |
return PR_ERROR(cmd); |
| 856 |
|
| 857 |
} else if (strcasecmp(key, "level") == 0) { |
| 858 |
int level; |
| 859 |
|
| 860 |
level = atoi(val); |
| 861 |
if (level < 0 || |
| 862 |
level > 9) { |
| 863 |
pr_response_add_err(R_501, _("%s: bad MODE Z option value: %s %s"), |
| 864 |
(char *) cmd->argv[0], key, val); |
| 865 |
|
| 866 |
pr_cmd_set_errno(cmd, EINVAL); |
| 867 |
errno = EINVAL; |
| 868 |
return PR_ERROR(cmd); |
| 869 |
} |
| 870 |
|
| 871 |
deflate_compression_level = level; |
| 872 |
|
| 873 |
} else { |
| 874 |
pr_response_add_err(R_501, _("%s: unknown MODE Z option: %s"), |
| 875 |
(char *) cmd->argv[0], key); |
| 876 |
|
| 877 |
pr_cmd_set_errno(cmd, EINVAL); |
| 878 |
errno = EINVAL; |
| 879 |
return PR_ERROR(cmd); |
| 880 |
} |
| 881 |
} |
| 882 |
} |
| 883 |
|
| 884 |
pr_response_add(R_200, _("OPTS MODE Z OK")); |
| 885 |
return PR_HANDLED(cmd); |
| 886 |
} |
| 887 |
|
| 888 |
return PR_DECLINED(cmd); |
| 889 |
} |
| 890 |
|
| 891 |
MODRET deflate_mode(cmd_rec *cmd) { |
| 892 |
char *mode; |
| 893 |
|
| 894 |
if (deflate_engine == FALSE) { |
| 895 |
return PR_DECLINED(cmd); |
| 896 |
} |
| 897 |
|
| 898 |
if (cmd->argc != 2) { |
| 899 |
(void) pr_log_writefile(deflate_logfd, MOD_DEFLATE_VERSION, |
| 900 |
"declining MODE Z (wrong number of parameters: %d)", cmd->argc); |
| 901 |
return PR_DECLINED(cmd); |
| 902 |
} |
| 903 |
|
| 904 |
mode = cmd->argv[1]; |
| 905 |
|
| 906 |
if (PR_ISALPHA((int) mode[0])) { |
| 907 |
mode[0] = toupper(mode[0]); |
| 908 |
} |
| 909 |
|
| 910 |
if (mode[0] == 'Z') { |
| 911 |
if (session.rfc2228_mech != NULL) { |
| 912 |
if (strcasecmp(session.rfc2228_mech, "tls") != 0) { |
| 913 |
(void) pr_log_writefile(deflate_logfd, MOD_DEFLATE_VERSION, |
| 914 |
"declining MODE Z (RFC2228 mechanism '%s' in effect)", |
| 915 |
session.rfc2228_mech); |
| 916 |
pr_log_debug(DEBUG2, MOD_DEFLATE_VERSION |
| 917 |
": declining MODE Z (RFC2228 mechanism '%s' in effect)", |
| 918 |
session.rfc2228_mech); |
| 919 |
|
| 920 |
pr_response_add_err(R_504, _("Unable to handle MODE Z at this time")); |
| 921 |
|
| 922 |
pr_cmd_set_errno(cmd, EPERM); |
| 923 |
errno = EPERM; |
| 924 |
return PR_ERROR(cmd); |
| 925 |
} |
| 926 |
} |
| 927 |
|
| 928 |
if (deflate_enabled == TRUE) { |
| 929 |
pr_response_add(R_200, _("OK")); |
| 930 |
return PR_HANDLED(cmd); |
| 931 |
} |
| 932 |
|
| 933 |
deflate_next_netio = pr_get_netio(PR_NETIO_STRM_DATA); |
| 934 |
if (deflate_next_netio != NULL) { |
| 935 |
|
| 936 |
|
| 937 |
|
| 938 |
|
| 939 |
|
| 940 |
|
| 941 |
|
| 942 |
pr_trace_msg(trace_channel, 9, "overriding existing %s NetIO callbacks", |
| 943 |
deflate_next_netio->owner_name? deflate_next_netio->owner_name : |
| 944 |
deflate_next_netio->owner->name); |
| 945 |
|
| 946 |
deflate_next_netio_close = deflate_next_netio->close; |
| 947 |
deflate_next_netio->close = deflate_netio_close_cb; |
| 948 |
|
| 949 |
deflate_next_netio_open = deflate_next_netio->open; |
| 950 |
deflate_next_netio->open = deflate_netio_open_cb; |
| 951 |
|
| 952 |
deflate_next_netio_read = deflate_next_netio->read; |
| 953 |
deflate_next_netio->read = deflate_netio_read_cb; |
| 954 |
|
| 955 |
deflate_next_netio_shutdown = deflate_next_netio->shutdown; |
| 956 |
deflate_next_netio->shutdown = deflate_netio_shutdown_cb; |
| 957 |
|
| 958 |
deflate_next_netio_write = deflate_next_netio->write; |
| 959 |
deflate_next_netio->write = deflate_netio_write_cb; |
| 960 |
|
| 961 |
} else { |
| 962 |
|
| 963 |
|
| 964 |
|
| 965 |
deflate_netio = pr_alloc_netio2(session.pool, &deflate_module, NULL); |
| 966 |
deflate_netio->close = deflate_netio_close_cb; |
| 967 |
deflate_netio->open = deflate_netio_open_cb; |
| 968 |
deflate_netio->read = deflate_netio_read_cb; |
| 969 |
deflate_netio->shutdown = deflate_netio_shutdown_cb; |
| 970 |
deflate_netio->write = deflate_netio_write_cb; |
| 971 |
|
| 972 |
if (pr_register_netio(deflate_netio, PR_NETIO_STRM_DATA) < 0) { |
| 973 |
(void) pr_log_writefile(deflate_logfd, MOD_DEFLATE_VERSION, |
| 974 |
"error registering netio: %s", strerror(errno)); |
| 975 |
} |
| 976 |
} |
| 977 |
|
| 978 |
deflate_enabled = TRUE; |
| 979 |
|
| 980 |
pr_response_add(R_200, _("OK")); |
| 981 |
return PR_HANDLED(cmd); |
| 982 |
|
| 983 |
} else { |
| 984 |
if (deflate_enabled) { |
| 985 |
|
| 986 |
|
| 987 |
if (deflate_next_netio != NULL) { |
| 988 |
deflate_next_netio->close = deflate_next_netio_close; |
| 989 |
deflate_next_netio_close = NULL; |
| 990 |
|
| 991 |
deflate_next_netio->open = deflate_next_netio_open; |
| 992 |
deflate_next_netio_open = NULL; |
| 993 |
|
| 994 |
deflate_next_netio->read = deflate_next_netio_read; |
| 995 |
deflate_next_netio_read = NULL; |
| 996 |
|
| 997 |
deflate_next_netio->shutdown = deflate_next_netio_shutdown; |
| 998 |
deflate_next_netio_shutdown = NULL; |
| 999 |
|
| 1000 |
deflate_next_netio->write = deflate_next_netio_write; |
| 1001 |
deflate_next_netio_write = NULL; |
| 1002 |
|
| 1003 |
deflate_next_netio = NULL; |
| 1004 |
|
| 1005 |
} else { |
| 1006 |
if (pr_unregister_netio(PR_NETIO_STRM_DATA) < 0) { |
| 1007 |
(void) pr_log_writefile(deflate_logfd, MOD_DEFLATE_VERSION, |
| 1008 |
"error unregistering netio: %s", strerror(errno)); |
| 1009 |
|
| 1010 |
} else { |
| 1011 |
(void) pr_log_writefile(deflate_logfd, MOD_DEFLATE_VERSION, |
| 1012 |
"%s %s: unregistered netio", (char *) cmd->argv[0], |
| 1013 |
(char *) cmd->argv[1]); |
| 1014 |
} |
| 1015 |
|
| 1016 |
if (deflate_netio != NULL) { |
| 1017 |
destroy_pool(deflate_netio->pool); |
| 1018 |
deflate_netio = NULL; |
| 1019 |
} |
| 1020 |
} |
| 1021 |
|
| 1022 |
deflate_enabled = FALSE; |
| 1023 |
} |
| 1024 |
} |
| 1025 |
|
| 1026 |
return PR_DECLINED(cmd); |
| 1027 |
} |
| 1028 |
|
| 1029 |
|
| 1030 |
|
| 1031 |
|
| 1032 |
static void deflate_sess_reinit_ev(const void *event_data, void *user_data) { |
| 1033 |
int res; |
| 1034 |
|
| 1035 |
|
| 1036 |
|
| 1037 |
pr_event_unregister(&deflate_module, "core.session-reinit", |
| 1038 |
deflate_sess_reinit_ev); |
| 1039 |
|
| 1040 |
deflate_engine = FALSE; |
| 1041 |
pr_feat_remove("MODE Z"); |
| 1042 |
(void) close(deflate_logfd); |
| 1043 |
deflate_logfd = -1; |
| 1044 |
|
| 1045 |
res = deflate_sess_init(); |
| 1046 |
if (res < 0) { |
| 1047 |
pr_session_disconnect(&deflate_module, |
| 1048 |
PR_SESS_DISCONNECT_SESSION_INIT_FAILED, NULL); |
| 1049 |
} |
| 1050 |
} |
| 1051 |
|
| 1052 |
|
| 1053 |
|
| 1054 |
|
| 1055 |
static int deflate_init(void) { |
| 1056 |
pr_log_debug(DEBUG5, MOD_DEFLATE_VERSION ": using zlib " ZLIB_VERSION); |
| 1057 |
return 0; |
| 1058 |
} |
| 1059 |
|
| 1060 |
static int deflate_sess_init(void) { |
| 1061 |
config_rec *c; |
| 1062 |
|
| 1063 |
pr_event_register(&deflate_module, "core.session-reinit", |
| 1064 |
deflate_sess_reinit_ev, NULL); |
| 1065 |
|
| 1066 |
c = find_config(main_server->conf, CONF_PARAM, "DeflateEngine", FALSE); |
| 1067 |
if (c && |
| 1068 |
*((unsigned int *) c->argv[0]) == TRUE) { |
| 1069 |
deflate_engine = TRUE; |
| 1070 |
|
| 1071 |
} else { |
| 1072 |
return 0; |
| 1073 |
} |
| 1074 |
|
| 1075 |
|
| 1076 |
|
| 1077 |
|
| 1078 |
|
| 1079 |
pr_feat_add("MODE Z"); |
| 1080 |
|
| 1081 |
c = find_config(main_server->conf, CONF_PARAM, "DeflateLog", FALSE); |
| 1082 |
if (c && |
| 1083 |
strcasecmp(c->argv[0], "none") != 0) { |
| 1084 |
int res, xerrno = 0; |
| 1085 |
|
| 1086 |
pr_signals_block(); |
| 1087 |
PRIVS_ROOT |
| 1088 |
res = pr_log_openfile(c->argv[0], &deflate_logfd, PR_LOG_SYSTEM_MODE); |
| 1089 |
xerrno = errno; |
| 1090 |
PRIVS_RELINQUISH |
| 1091 |
pr_signals_unblock(); |
| 1092 |
|
| 1093 |
switch (res) { |
| 1094 |
case -1: |
| 1095 |
pr_log_pri(PR_LOG_NOTICE, MOD_DEFLATE_VERSION |
| 1096 |
": notice: unable to open DeflateLog '%s': %s", |
| 1097 |
(char *) c->argv[0], strerror(xerrno)); |
| 1098 |
break; |
| 1099 |
|
| 1100 |
case PR_LOG_WRITABLE_DIR: |
| 1101 |
pr_log_pri(PR_LOG_WARNING, MOD_DEFLATE_VERSION |
| 1102 |
": notice: unable to use DeflateLog '%s': parent directory is " |
| 1103 |
"world-writable", (char *) c->argv[0]); |
| 1104 |
break; |
| 1105 |
|
| 1106 |
case PR_LOG_SYMLINK: |
| 1107 |
pr_log_pri(PR_LOG_WARNING, MOD_DEFLATE_VERSION |
| 1108 |
": notice: unable to use DeflateLog '%s': cannot log to a symlink", |
| 1109 |
(char *) c->argv[0]); |
| 1110 |
break; |
| 1111 |
} |
| 1112 |
} |
| 1113 |
|
| 1114 |
|
| 1115 |
|
| 1116 |
|
| 1117 |
|
| 1118 |
if (deflate_zbuf == NULL) { |
| 1119 |
deflate_zbufsz = pr_config_get_xfer_bufsz() * 8; |
| 1120 |
deflate_zbuf_ptr = deflate_zbuf = pcalloc(session.pool, deflate_zbufsz); |
| 1121 |
deflate_zbuflen = 0; |
| 1122 |
} |
| 1123 |
|
| 1124 |
if (deflate_rbuf == NULL) { |
| 1125 |
deflate_rbufsz = pr_config_get_xfer_bufsz(); |
| 1126 |
deflate_rbuf = palloc(session.pool, deflate_rbufsz); |
| 1127 |
deflate_rbuflen = 0; |
| 1128 |
} |
| 1129 |
|
| 1130 |
return 0; |
| 1131 |
} |
| 1132 |
|
| 1133 |
|
| 1134 |
|
| 1135 |
|
| 1136 |
static conftable deflate_conftab[] = { |
| 1137 |
{ "DeflateEngine", set_deflateengine, NULL }, |
| 1138 |
{ "DeflateLog", set_deflatelog, NULL }, |
| 1139 |
{ NULL } |
| 1140 |
}; |
| 1141 |
|
| 1142 |
static cmdtable deflate_cmdtab[] = { |
| 1143 |
{ CMD, C_OPTS "_MODE", G_NONE, deflate_opts, FALSE, FALSE, CL_MISC }, |
| 1144 |
{ CMD, C_MODE, G_NONE, deflate_mode, FALSE, FALSE, CL_MISC }, |
| 1145 |
{ 0, NULL } |
| 1146 |
}; |
| 1147 |
|
| 1148 |
module deflate_module = { |
| 1149 |
NULL, NULL, |
| 1150 |
|
| 1151 |
|
| 1152 |
0x20, |
| 1153 |
|
| 1154 |
|
| 1155 |
"deflate", |
| 1156 |
|
| 1157 |
|
| 1158 |
deflate_conftab, |
| 1159 |
|
| 1160 |
|
| 1161 |
deflate_cmdtab, |
| 1162 |
|
| 1163 |
|
| 1164 |
NULL, |
| 1165 |
|
| 1166 |
|
| 1167 |
deflate_init, |
| 1168 |
|
| 1169 |
|
| 1170 |
deflate_sess_init, |
| 1171 |
|
| 1172 |
|
| 1173 |
MOD_DEFLATE_VERSION |
| 1174 |
}; |