Debian Codegraph @

contrib/mod_wrap2/mod_wrap2.c

raw symbols SCIP
1 /*
2 * ProFTPD: mod_wrap2 -- tcpwrappers-like access control
3 * Copyright (c) 2000-2025 TJ Saunders
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, TJ Saunders gives permission to link this program
20 * with OpenSSL, and distribute the resulting executable, without including
21 * the source code for OpenSSL in the source distribution.
22 */
23
24 #include "mod_wrap2.h"
25
26 #if defined(WRAP2_USE_NIS)
27 #include <rpc/rpc.h>
28 #include <rpcsvc/ypclnt.h>
29 #endif /* WRAP2_USE_NIS */
30
31 typedef struct regtab_obj {
32 struct regtab_obj *prev, *next;
33
34 /* Table source type name */
35 const char *regtab_name;
36
37 /* Initialization function for this type of table source */
38 wrap2_table_t *(*regtab_open)(pool *, const char *);
39
40 } wrap2_regtab_t;
41
42 module wrap2_module;
43 unsigned long wrap2_opts = 0UL;
44
45 /* Wrap tables for the current session */
46 static char *wrap2_allow_table = NULL;
47 static char *wrap2_deny_table = NULL;
48
49 /* Memory pool for this module */
50 static pool *wrap2_pool = NULL;
51
52 /* List of registered quotatab sources */
53 static wrap2_regtab_t *wrap2_regtab_list = NULL;
54
55 /* Logging data */
56 static int wrap2_logfd = -1;
57 static const char *wrap2_logname = NULL;
58
59 static int wrap2_engine = FALSE;
60 static const char *wrap2_service_name = WRAP2_DEFAULT_SERVICE_NAME;
61 static const char *wrap2_client_name = NULL;
62 static config_rec *wrap2_ctxt = NULL;
63
64 /* Access check variables */
65
66 #define WRAP2_UNKNOWN "unknown"
67 #define WRAP2_PARANOID "paranoid"
68
69 #define WRAP2_IS_KNOWN_HOSTNAME(s) \
70 (strcasecmp((s), WRAP2_UNKNOWN) != 0 && strcasecmp((s), WRAP2_PARANOID))
71
72 #define WRAP2_IS_NOT_INADDR(s) \
73 (s[strspn(s,"01234567890./")] != 0)
74
75 #define WRAP2_GET_DAEMON(r) \
76 ((r)->daemon)
77
78 /* Data structures */
79
80 typedef struct host_info {
81 char name[WRAP2_BUFFER_SIZE];
82 char addr[WRAP2_BUFFER_SIZE];
83 struct sockaddr_in *sin; /* socket address or 0 */
84 struct t_unitdata *unit; /* TLI transport address or 0 */
85 struct conn_info *connection; /* for shared information */
86
87 } wrap2_host_t;
88
89 typedef struct conn_info {
90 int sock_fd; /* socket handle */
91 char user[WRAP2_BUFFER_SIZE]; /* access via eval_user(request) */
92 char daemon[WRAP2_BUFFER_SIZE]; /* access via eval_daemon(request) */
93 struct host_info client[1]; /* client endpoint info */
94 struct host_info server[1]; /* server endpoint info */
95 void (*sink) (int); /* datagram sink function or 0 */
96 void (*hostname) (struct host_info *); /* address to printable hostname */
97 void (*hostaddr) (struct host_info *); /* address to printable address */
98 void (*cleanup) (struct conn_info *); /* cleanup function or 0 */
99 struct netconfig *config; /* netdir handle */
100
101 } wrap2_conn_t;
102
103 #define WRAP2_CONN_SOCK_FD 1 /* socket descriptor */
104 #define WRAP2_CONN_DAEMON 2 /* server process (argv[0]) */
105
106 #ifndef INADDR_NONE
107 #define INADDR_NONE 0xffffffff
108 #endif
109
110 static const char *trace_channel = "wrap2";
111
112 /* Necessary prototypes. */
113 static unsigned char wrap2_match_includes(const char *path, wrap2_host_t *host);
114 static int wrap2_sess_init(void);
115
116 /* Logging routines */
117
118 static int wrap2_closelog(void) {
119 if (wrap2_logfd != -1) {
120 close(wrap2_logfd);
121 wrap2_logfd = -1;
122 wrap2_logname = NULL;
123 }
124
125 return 0;
126 }
127
128 int wrap2_log(const char *fmt, ...) {
129 va_list msg;
130 int res;
131
132 if (!wrap2_logname)
133 return 0;
134
135 va_start(msg, fmt);
136 res = pr_log_vwritefile(wrap2_logfd, MOD_WRAP2_VERSION, fmt, msg);
137 va_end(msg);
138
139 return res;
140 }
141
142 static int wrap2_openlog(void) {
143 int res = 0, xerrno;
144
145 /* Sanity check */
146 wrap2_logname = get_param_ptr(main_server->conf, "WrapLog", FALSE);
147 if (wrap2_logname == NULL)
148 return 0;
149
150 /* Check for "none" */
151 if (strcasecmp(wrap2_logname, "none") == 0) {
152 wrap2_logname = NULL;
153 return 0;
154 }
155
156 pr_signals_block();
157 PRIVS_ROOT
158 res = pr_log_openfile(wrap2_logname, &wrap2_logfd, PR_LOG_SYSTEM_MODE);
159 xerrno = errno;
160 PRIVS_RELINQUISH
161 pr_signals_unblock();
162
163 errno = xerrno;
164 return res;
165 }
166
167 /* Table routines */
168
169 static int wrap2_close_table(wrap2_table_t *tab) {
170 return tab->tab_close(tab);
171 }
172
173 static wrap2_table_t *wrap2_open_table(char *name) {
174 char *info = NULL, *ptr = NULL;
175 unsigned char have_type = FALSE;
176 register wrap2_regtab_t *regtab = NULL;
177 wrap2_table_t *tab = NULL;
178
179 info = ptr = strchr(name, ':');
180 if (info == NULL) {
181 errno = EINVAL;
182 return NULL;
183 }
184
185 *info++ = '\0';
186
187 /* Look up the table source open routine by name, and invoke it */
188 for (regtab = wrap2_regtab_list; regtab; regtab = regtab->next) {
189 if (strcmp(regtab->regtab_name, name) == 0) {
190 tab = regtab->regtab_open(wrap2_pool, info);
191 if (tab == NULL) {
192 *ptr = ':';
193 return NULL;
194 }
195
196 have_type = TRUE;
197 *ptr = ':';
198 break;
199 }
200 }
201
202 if (!have_type) {
203 wrap2_log("unsupported table source: '%s'", name);
204 errno = EINVAL;
205 return NULL;
206 }
207
208 return tab;
209 }
210
211 /* Information structure routines */
212
213 static wrap2_conn_t *wrap2_conn_update(wrap2_conn_t *conn, va_list ap) {
214 int key = 0;
215 char *val = NULL;
216
217 while ((key = va_arg(ap, int)) > 0) {
218 switch (key) {
219
220 default:
221 wrap2_log("invalid key: %d", key);
222 return conn;
223
224 case WRAP2_CONN_SOCK_FD:
225 conn->sock_fd = va_arg(ap, int);
226 continue;
227
228 #if 0
229 case WRAP2_CONN_CLIENT_SIN:
230 conn->client->sin = va_arg(ap, struct sockaddr_in *);
231 continue;
232
233 case WRAP2_CONN_SERVER_SIN:
234 conn->server->sin = va_arg(ap, struct sockaddr_in *);
235 continue;
236 #endif
237
238 case WRAP2_CONN_DAEMON:
239 val = conn->daemon;
240 break;
241
242 #if 0
243 case WRAP2_CONN_USER:
244 val = conn->user;
245 break;
246
247 case WRAP2_CONN_CLIENT_NAME:
248 val = conn->client->name;
249 break;
250
251 case WRAP2_CONN_CLIENT_ADDR:
252 val = conn->client->addr;
253 break;
254
255 case WRAP2_CONN_SERVER_NAME:
256 val = conn->server->name;
257 break;
258
259 case WRAP2_CONN_SERVER_ADDR:
260 val = conn->server->addr;
261 break;
262 #endif
263 }
264
265 /* Copy in the string */
266 sstrncpy(val, va_arg(ap, char *), WRAP2_BUFFER_SIZE);
267 }
268
269 return conn;
270 }
271
272 static wrap2_conn_t *wrap2_conn_set(wrap2_conn_t *conn, ...) {
273 static wrap2_conn_t default_conn;
274 wrap2_conn_t *c = NULL;
275 va_list ap;
276
277 /* Initialize the data members. We do not assign default callbacks,
278 * to avoid pulling in the whole socket module when it is not really
279 * needed.
280 */
281 va_start(ap, conn);
282
283 *conn = default_conn;
284
285 conn->sock_fd = -1;
286 sstrncpy(conn->daemon, WRAP2_UNKNOWN, sizeof(conn->daemon));
287
288 conn->client->connection = conn;
289 conn->server->connection = conn;
290
291 c = wrap2_conn_update(conn, ap);
292 va_end(ap);
293
294 return c;
295 }
296
297 static char *wrap2_get_user(wrap2_conn_t *conn) {
298
299 if (*conn->user == '\0') {
300 const char *rfc1413_ident;
301
302 /* RFC1413 lookups may have already been done by the mod_ident module.
303 * If so, use the ident name stashed; otherwise, use the user name issued
304 * by the client.
305 */
306
307 rfc1413_ident = pr_table_get(session.notes, "mod_ident.rfc1413-ident",
308 NULL);
309 if (rfc1413_ident != NULL) {
310 sstrncpy(conn->user, rfc1413_ident, sizeof(conn->user));
311
312 } else {
313 const char *user;
314
315 user = pr_table_get(session.notes, "mod_auth.orig-user", NULL);
316 if (user != NULL) {
317 sstrncpy(conn->user, user, sizeof(conn->user));
318 }
319 }
320 }
321
322 return conn->user;
323 }
324
325 static char *wrap2_get_hostaddr(wrap2_host_t *host) {
326 if (*host->addr == '\0') {
327 sstrncpy(host->addr, pr_netaddr_get_ipstr(session.c->remote_addr),
328 sizeof(host->addr));
329 }
330
331 return host->addr;
332 }
333
334 static char *wrap2_get_hostname(wrap2_host_t *host) {
335
336 if (*host->name == '\0') {
337 int reverse_dns;
338
339 reverse_dns = pr_netaddr_set_reverse_dns(TRUE);
340 if (reverse_dns) {
341 size_t namelen;
342 pr_netaddr_t *remote_addr;
343
344 /* If UseReverseDNS is on, then clear any caches, so that we really do
345 * use the DNS name here if possible.
346 */
347 pr_netaddr_clear_cache();
348
349 remote_addr = (pr_netaddr_t *) session.c->remote_addr;
350 remote_addr->na_have_dnsstr = FALSE;
351
352 sstrncpy(host->name, pr_netaddr_get_dnsstr(session.c->remote_addr),
353 sizeof(host->name));
354
355 /* If the retrieved hostname ends in a trailing period, trim it off. */
356 namelen = strlen(host->name);
357 if (host->name[namelen-1] == '.') {
358 host->name[namelen-1] = '\0';
359 }
360
361 pr_netaddr_set_reverse_dns(reverse_dns);
362 remote_addr->na_have_dnsstr = TRUE;
363
364 } else {
365 /* In order to probe the current UseReverseDNS value, we had to enable
366 * earlier. Make sure we restore that previous value.
367 */
368 pr_netaddr_set_reverse_dns(reverse_dns);
369
370 wrap2_log("'UseReverseDNS off' in effect, NOT resolving %s to DNS name "
371 "for comparison", pr_netaddr_get_ipstr(session.c->remote_addr));
372
373 sstrncpy(host->name, pr_netaddr_get_dnsstr(session.c->remote_addr),
374 sizeof(host->name));
375 }
376 }
377
378 return host->name;
379 }
380
381 static char *wrap2_get_hostinfo(wrap2_host_t *host) {
382 char *hostname;
383
384 hostname = wrap2_get_hostname(host);
385
386 if (WRAP2_IS_KNOWN_HOSTNAME(hostname))
387 return hostname;
388
389 return wrap2_get_hostaddr(host);
390 }
391
392 static char *wrap2_get_client(wrap2_conn_t *conn) {
393 static char both[WRAP2_BUFFER_SIZE] = {'\0'};
394 char *hostinfo;
395
396 hostinfo = wrap2_get_hostinfo(conn->client);
397
398 if (strcasecmp(wrap2_get_user(conn), WRAP2_UNKNOWN) != 0) {
399 pr_snprintf(both, sizeof(both), "%s@%s", conn->user, hostinfo);
400 both[sizeof(both)-1] = '\0';
401 return both;
402 }
403
404 return hostinfo;
405 }
406
407 /* Access checking routines */
408
409 char *wrap2_strsplit(char *str, int delim) {
410 char *tmp = NULL;
411
412 tmp = strchr(str, delim);
413 if (tmp != NULL)
414 *tmp++ = '\0';
415
416 return tmp;
417 }
418
419 static char *wrap2_skip_whitespace(char *str) {
420 register unsigned int i;
421 char *tmp;
422
423 /* Skip any leading whitespace. */
424 tmp = str;
425 for (i = 0; str[i]; i++) {
426 if (PR_ISSPACE(str[i])) {
427 tmp = &str[i+1];
428 continue;
429 }
430
431 break;
432 }
433
434 return tmp;
435 }
436
437 static unsigned char wrap2_match_string(const char *tok, const char *str) {
438 size_t len;
439
440 if (tok[0] == '.') {
441 /* Suffix */
442 len = strlen(str) - strlen(tok);
443 return (len > 0 && (strcasecmp(tok, str + len) == 0));
444
445 } else if (strcasecmp(tok, "ALL") == 0) {
446 /* ALL: match any */
447 return TRUE;
448
449 } else if (strcasecmp(tok, "KNOWN") == 0) {
450 /* Not unknown */
451 return (strcasecmp(str, WRAP2_UNKNOWN) != 0);
452
453 } else if (tok[(len = strlen(tok)) - 1] == '.') {
454 /* Prefix */
455 return (strncasecmp(tok, str, len) == 0);
456 }
457
458 /* Exact match */
459 return (strcasecmp(tok, str) == 0);
460 }
461
462 static unsigned long wrap2_addr_a2n(const char *str) {
463 unsigned char within_run = FALSE;
464 unsigned int nruns = 0;
465 const char *cp = str;
466
467 /* Count the number of runs of non-dot characters. */
468
469 while (*cp) {
470 if (*cp == '.') {
471 within_run = FALSE;
472
473 } else if (within_run == FALSE) {
474 within_run = TRUE;
475 nruns++;
476 }
477 cp++;
478 }
479
480 return (nruns == 4 ? inet_addr(str) : INADDR_NONE);
481 }
482
483 static unsigned char wrap2_match_netmask(const char *net_tok,
484 const char *mask_tok, const char *str) {
485 unsigned long net = 0UL;
486 unsigned long mask = 0UL;
487 unsigned long addr = 0UL;
488
489 /* Disallow forms other than dotted quad: the treatment that inet_addr()
490 * gives to forms with less than four components is inconsistent with the
491 * access control language. John P. Rouillard <[email protected]>.
492 */
493
494 addr = wrap2_addr_a2n(str);
495 if (addr == INADDR_NONE) {
496 return FALSE;
497 }
498
499 net = wrap2_addr_a2n(net_tok);
500 mask = wrap2_addr_a2n(mask_tok);
501 if (net == INADDR_NONE ||
502 mask == INADDR_NONE) {
503 wrap2_log("warning: bad net/mask expression: '%s/%s'", net_tok, mask_tok);
504 return FALSE;
505 }
506
507 return ((addr & mask) == net);
508 }
509
510 static unsigned char wrap2_match_host(char *tok, wrap2_host_t *host) {
511 char *mask = NULL;
512 size_t len;
513
514 tok = wrap2_skip_whitespace(tok);
515
516 /* This code looks a little hairy because we want to avoid unnecessary
517 * hostname lookups.
518 *
519 * The KNOWN pattern requires that both address AND name be known; some
520 * patterns are specific to host names or to host addresses; all other
521 * patterns are satisfied when either the address OR the name match.
522 */
523
524 if (tok[0] == '@') {
525 #if defined(WRAP2_USE_NIS)
526 /* netgroup: look it up. */
527 static char *mydomain = NULL;
528
529 if (mydomain == NULL)
530 yp_get_default_domain(&mydomain);
531
532 return (innetgr(tok + 1, wrap2_get_hostname(host), NULL, mydomain));
533 #else
534 wrap2_log("warning: '%s': NIS support is not enabled", tok);
535 return FALSE;
536 #endif /* WRAP2_USE_NIS */
537
538 } else if (strcasecmp(tok, "ALL") == 0) {
539 /* Matches everything */
540 wrap2_log("comparing client hostname '%s' against ALL",
541 wrap2_get_hostname(host));
542 return TRUE;
543
544 } else if (strcasecmp(tok, "KNOWN") == 0) {
545 char *name;
546
547 /* Check address and name. */
548 name = wrap2_get_hostname(host);
549 return ((strcasecmp(wrap2_get_hostaddr(host), WRAP2_UNKNOWN) != 0) &&
550 WRAP2_IS_KNOWN_HOSTNAME(name));
551
552 } else if (strcasecmp(tok, "LOCAL") == 0) {
553 char *name;
554
555 /* Local: no dots in name. */
556 name = wrap2_get_hostname(host);
557 return (strchr(name, '.') == NULL && WRAP2_IS_KNOWN_HOSTNAME(name));
558
559 } else if (tok[(len = strlen(tok)) - 1] == '.') {
560 const char *ip_str;
561
562 /* Prefix */
563
564 ip_str = wrap2_get_hostaddr(host);
565 return (strncasecmp(tok, ip_str, len) == 0);
566
567 } else if (tok[0] == '.') {
568 char *primary_name;
569 array_header *dns_names;
570
571 /* Suffix */
572 primary_name = wrap2_get_hostname(host);
573 len = strlen(primary_name) - strlen(tok);
574
575 wrap2_log("comparing client hostname '%s' (part %s) against DNS "
576 "pattern '%s'", primary_name, primary_name+len, tok);
577
578 if (len > 0 &&
579 strcasecmp(tok, primary_name + len) == 0) {
580 return TRUE;
581 }
582
583 if (!(wrap2_opts & WRAP_OPT_CHECK_ALL_NAMES)) {
584 return FALSE;
585 }
586
587 dns_names = pr_netaddr_get_dnsstr_list(session.pool,
588 session.c->remote_addr);
589 if (dns_names != NULL &&
590 dns_names->nelts > 0) {
591 register unsigned int i;
592 char **names;
593
594 names = dns_names->elts;
595 for (i = 0; i < dns_names->nelts; i++) {
596 char *name;
597
598 name = names[i];
599 if (name != NULL) {
600 len = strlen(name) - strlen(tok);
601
602 wrap2_log("comparing client hostname '%s' (part %s) against DNS "
603 "pattern '%s'", name, name+len, tok);
604
605 if (len > 0 &&
606 strcasecmp(tok, name + len) == 0) {
607 return TRUE;
608 }
609 }
610 }
611 }
612
613 return FALSE;
614
615 #if defined(PR_USE_IPV6)
616 } else if (pr_netaddr_use_ipv6() &&
617 *tok == '[') {
618 char *cp;
619 const pr_netaddr_t *acl_addr;
620
621 /* IPv6 address */
622
623 if (pr_netaddr_get_family(session.c->remote_addr) == AF_INET) {
624 /* No need to try to match an IPv6 address against an IPv4 client. */
625 return FALSE;
626 }
627
628 /* Find the terminating ']'. */
629 cp = strchr(tok, ']');
630 if (cp == NULL) {
631 wrap2_log("bad IPv6 address syntax: '%s'", tok);
632 return FALSE;
633 }
634
635 *cp = '\0';
636
637 /* Lookup a netaddr for the IPv6 address. */
638 acl_addr = pr_netaddr_get_addr(wrap2_pool, tok + 1, NULL);
639 if (acl_addr == NULL) {
640 wrap2_log("unable to resolve IPv6 address '%s'", tok + 1);
641 return FALSE;
642 }
643
644 if (*(cp + 1) != '/') {
645 if (pr_netaddr_cmp(session.c->remote_addr, acl_addr) == 0) {
646 return TRUE;
647 }
648
649 return FALSE;
650
651 } else {
652 unsigned int nmaskbits;
653 char *tmp;
654
655 /* Netmask */
656
657 /* Determine the number of mask bits. */
658 nmaskbits = strtol(cp + 2, &tmp, 10);
659 if (tmp && *tmp) {
660 wrap2_log("bad mask syntax: '%s'", tmp);
661 return FALSE;
662 }
663
664 return (pr_netaddr_ncmp(session.c->remote_addr, acl_addr,
665 nmaskbits) == 0);
666 }
667 #endif /* PR_USE_IPV6 */
668
669 } else if (*tok == '/') {
670 /* Include file */
671 return (wrap2_match_includes(tok, host));
672
673 } else if ((mask = wrap2_strsplit(tok, '/')) != 0) {
674 /* Net/mask */
675 return (wrap2_match_netmask(tok, mask, wrap2_get_hostaddr(host)));
676
677 } else {
678 const pr_netaddr_t *acl_addr;
679
680 /* Anything else.
681 *
682 * In order to properly compare IP addresses (and to handle cases of
683 * handling IPv4-mapped IPv6 addresses compared against IPv4 addresses),
684 * we need to use pr_netaddr_cmp(), rather than doing the string
685 * comparison that libwrap used.
686 */
687
688 acl_addr = pr_netaddr_get_addr(wrap2_pool, tok, NULL);
689 if (acl_addr == NULL) {
690 if (wrap2_match_string(tok, wrap2_get_hostname(host))) {
691 return TRUE;
692 }
693
694 wrap2_log("unable to handle address '%s'", tok);
695
696 } else {
697 if (pr_netaddr_cmp(session.c->remote_addr, acl_addr) == 0) {
698 return TRUE;
699 }
700 }
701
702 if (WRAP2_IS_NOT_INADDR(tok)) {
703 char *primary_name;
704 array_header *dns_names;
705
706 primary_name = wrap2_get_hostname(host);
707 wrap2_log("comparing client hostname '%s' against DNS name '%s'",
708 primary_name, tok);
709
710 if (wrap2_match_string(tok, primary_name)) {
711 return TRUE;
712 }
713
714 if (!(wrap2_opts & WRAP_OPT_CHECK_ALL_NAMES)) {
715 return FALSE;
716 }
717
718 dns_names = pr_netaddr_get_dnsstr_list(session.pool,
719 session.c->remote_addr);
720 if (dns_names != NULL &&
721 dns_names->nelts > 0) {
722 register unsigned int i;
723 char **names;
724
725 names = dns_names->elts;
726 for (i = 0; i < dns_names->nelts; i++) {
727 char *name;
728
729 name = names[i];
730 if (name != NULL) {
731 wrap2_log("comparing client hostname '%s' against DNS name '%s'",
732 name, tok);
733
734 if (wrap2_match_string(tok, name)) {
735 return TRUE;
736 }
737 }
738 }
739 }
740 }
741 }
742
743 return FALSE;
744 }
745
746 static unsigned char wrap2_match_includes(const char *path,
747 wrap2_host_t *host) {
748 pr_fh_t *fh;
749 int xerrno;
750 char buf[PR_TUNABLE_BUFFER_SIZE+1], *line;
751
752 PRIVS_ROOT
753 fh = pr_fsio_open(path, O_RDONLY);
754 xerrno = errno;
755 PRIVS_RELINQUISH
756
757 if (fh == NULL) {
758 wrap2_log("error opening include file '%s': %s", path, strerror(xerrno));
759 return FALSE;
760 }
761
762 memset(buf, '\0', sizeof(buf));
763 line = pr_fsio_getline(buf, sizeof(buf)-1, fh, NULL);
764 while (line != NULL) {
765 unsigned char match = FALSE;
766
767 pr_signals_handle();
768
769 /* If `line` itself starts with `/`, log/ignore it. No recursive loops. */
770 if (*line != '/') {
771 char *next;
772
773 next = strsep(&line, " \t\r\n");
774 while (next != NULL) {
775 pr_signals_handle();
776
777 match = wrap2_match_host(next, host);
778 if (match) {
779 pr_fsio_close(fh);
780 return match;
781 }
782
783 next = strsep(&line, " \t\r\n");
784 while (next != NULL &&
785 *next == '\0') {
786 next = strsep(&line, " \t\r\n");
787 }
788 }
789
790 } else {
791 wrap2_log("ignoring include pattern '%s' from include file '%s'",
792 line, path);
793 }
794
795 memset(buf, '\0', sizeof(buf));
796 line = pr_fsio_getline(buf, sizeof(buf)-1, fh, NULL);
797 }
798
799 pr_fsio_close(fh);
800 return FALSE;
801 }
802
803 static unsigned char wrap2_match_client(char *tok, wrap2_conn_t *conn) {
804 unsigned char match = FALSE;
805 char *host = NULL;
806
807 pr_trace_msg(trace_channel, 9, "matching client token '%s'", tok);
808
809 host = wrap2_strsplit(tok + 1, '@');
810 if (host == 0) {
811 /* Plain host */
812 match = wrap2_match_host(tok, conn->client);
813
814 if (match) {
815 wrap2_log("client matches '%s'", tok);
816 }
817
818 } else {
819 /* user@host */
820 match = (wrap2_match_host(host, conn->client) &&
821 wrap2_match_string(tok, wrap2_get_user(conn)));
822
823 if (match) {
824 wrap2_log("client matches '%s@%s'", tok, host);
825 }
826 }
827
828 return match;
829 }
830
831 static unsigned char wrap2_match_daemon(char *tok, wrap2_conn_t *conn) {
832 unsigned char match = FALSE;
833 char *host = NULL;
834
835 host = wrap2_strsplit(tok + 1, '@');
836 if (host == 0) {
837 /* Plain daemon */
838 match = wrap2_match_string(tok, WRAP2_GET_DAEMON(conn));
839
840 if (match) {
841 wrap2_log("daemon matches '%s'", tok);
842 }
843
844 } else {
845 /* daemon@host */
846 match = (wrap2_match_string(tok, WRAP2_GET_DAEMON(conn)) &&
847 wrap2_match_host(host, conn->server));
848
849 if (match) {
850 wrap2_log("daemon matches '%s@%s'", tok, host);
851 }
852 }
853
854 return match;
855 }
856
857 static unsigned char wrap2_match_list(array_header *list, wrap2_conn_t *conn,
858 unsigned char (*match_token)(char *, wrap2_conn_t *),
859 unsigned int list_idx) {
860 register unsigned int i;
861 char **tokens = NULL;
862
863 if (list == NULL) {
864 return FALSE;
865 }
866
867 tokens = list->elts;
868
869 /* Process tokens one at a time. We have exhausted all possible matches
870 * when we reach an "EXCEPT" token or the end of the list. If we do find
871 * a match, look for an "EXCEPT" list and recurse to determine whether
872 * the match is affected by any exceptions.
873 */
874
875 for (i = list_idx; i < list->nelts; i++) {
876 char *token;
877
878 /* It's possible that the token string is actually NULL; handle this
879 * case gracefully.
880 */
881 if (tokens[i] == NULL) {
882 continue;
883 }
884
885 token = wrap2_skip_whitespace(tokens[i]);
886
887 if (strcasecmp(token, "EXCEPT") == 0) {
888 /* EXCEPT -- give up now. */
889 return FALSE;
890 }
891
892 if (match_token(token, conn)) {
893 register unsigned int j;
894
895 /* If yes, look for exceptions */
896 for (j = i + 1; j < list->nelts; j++) {
897 token = wrap2_skip_whitespace(tokens[j]);
898 if (strcasecmp(token, "EXCEPT") == 0) {
899 return (wrap2_match_list(list, conn, match_token, j+1) == 0);
900 }
901 }
902
903 return TRUE;
904 }
905 }
906
907 return FALSE;
908 }
909
910 #if defined(WRAP2_USE_OPTIONS)
911
912 #define WRAP2_WHITESPACE " \t\r\n"
913
914 /* Options flag for requiring a value. */
915 #define WRAP2_OF_NEED_ARG (1 << 1)
916
917 /* Options flag specifying the option must be last in the list. */
918 #define WRAP2_OF_USE_LAST (1 << 2)
919
920 /* Options flag allowing for optional values. */
921 #define WRAP2_OF_OPT_ARG (1 << 3)
922
923 #define WRAP2_OPT_NEEDS_VAL(o) \
924 ((o)->flags & WRAP2_OF_NEED_ARG)
925 #define WRAP2_OPT_ALLOWS_VAL(o) \
926 ((o)->flags & (WRAP2_OF_NEED_ARG|WRAP2_OF_OPT_ARG))
927 #define WRAP2_OPT_NEEDS_LAST(o) \
928 ((o)->flags & WRAP2_OF_USE_LAST)
929
930 #define WRAP2_OPT_ALLOW 4
931 #define WRAP2_OPT_DENY -4
932
933 /* Options routines */
934
935 static char *wrap2_opt_trim_string(char *string) {
936 char *start = NULL, *end = NULL, *cp = NULL;
937
938 for (cp = string; *cp; cp++) {
939 if (!PR_ISSPACE(*cp)) {
940 if (*start == '\0') {
941 start = cp;
942 }
943 end = cp;
944 }
945 }
946
947 return (start ? (end[1] = '\0', start) : cp);
948 }
949
950 static char *wrap2_opt_get_field(array_header *opts, unsigned int *opt_idx) {
951 static char *last = "";
952 char *src = NULL, *dst = NULL, *res = NULL;
953 char c = 0;
954
955 char *string = ((char **) opts->elts)[*opt_idx];
956
957 /* This function returns pointers to successive fields within a given
958 * string. ":" is the field separator; warn if the rule ends in one. It
959 * replaces a "\:" sequence by ":", without treating the result of
960 * substitution as field terminator. A null argument means resume search
961 * where the previous call terminated. This function destroys its
962 * argument.
963 *
964 * Work from explicit source or from memory. While processing \: we
965 * overwrite the input. This way we do not have to maintain buffers for
966 * copies of input fields.
967 */
968
969 src = dst = res = (string ? string : last);
970
971 if (*src == '\0') {
972 return NULL;
973 }
974
975 while ((c = *src)) {
976 if (c == ':') {
977 if (*++src == '\0') {
978 wrap2_log("option rule ends in ':'");
979 }
980
981 break;
982 }
983
984 if (c == '\\' && src[1] == ':') {
985 src++;
986 }
987
988 *dst++ = *src++;
989 }
990
991 last = src;
992 *dst = '\0';
993
994 (*opt_idx)++;
995 return res;
996 }
997
998 /* "allow" option - grant access */
999 static int wrap2_opt_allow(char *val) {
1000 return WRAP2_OPT_ALLOW;
1001 }
1002
1003 /* "deny" option - deny access */
1004 static int wrap2_opt_deny(char *val) {
1005 return WRAP2_OPT_DENY;
1006 }
1007
1008 /* "nice" option - set process nice value */
1009 static int wrap2_opt_nice(char *val) {
1010 int niceness = 10;
1011 char *tmp = NULL;
1012
1013 if (val != 0) {
1014 niceness = (int) strtol(val, &tmp, 10);
1015
1016 if (niceness < 0 ||
1017 (tmp && *tmp)) {
1018 wrap2_log("bad nice value: '%s'", val);
1019 return 0;
1020 }
1021 }
1022
1023 if (nice(niceness) < 0) {
1024 wrap2_log("error handling nice option: %s", strerror(errno));
1025 }
1026
1027 return 0;
1028 }
1029
1030 /* "setenv" option - set environment variable */
1031 static int wrap2_opt_setenv(char *val) {
1032 char *value = NULL;
1033
1034 if (*(value = val + strcspn(val, WRAP2_WHITESPACE))) {
1035 *value++ = '\0';
1036 }
1037
1038 if (pr_env_set(session.pool, wrap2_opt_trim_string(val),
1039 wrap2_opt_trim_string(value)) < 0) {
1040 wrap2_log("error handling setenv option: %s", strerror(errno));
1041 }
1042
1043 return 0;
1044 }
1045
1046 struct wrap2_opt {
1047 /* Keyword name (case-insensitive) */
1048 char *name;
1049
1050 /* Options handler */
1051 int (*func)(char *);
1052
1053 /* Modifying flags */
1054 int flags;
1055 };
1056
1057 static const struct wrap2_opt options_tab[] = {
1058 { "setenv", wrap2_opt_setenv, WRAP2_OF_NEED_ARG },
1059 { "nice", wrap2_opt_nice, WRAP2_OF_OPT_ARG },
1060 { "allow", wrap2_opt_allow, WRAP2_OF_USE_LAST },
1061 { "deny", wrap2_opt_deny, WRAP2_OF_USE_LAST },
1062 { NULL, NULL, 0 }
1063 };
1064
1065 static int wrap2_handle_opts(array_header *options, wrap2_conn_t *conn) {
1066 char *key = NULL, *value = NULL;
1067 char *curr_opt = NULL, *next_opt = NULL;
1068 const struct wrap2_opt *opt = NULL;
1069 unsigned int opt_idx = 0;
1070
1071 for (curr_opt = wrap2_opt_get_field(options, &opt_idx); curr_opt;
1072 curr_opt = next_opt) {
1073 int res = 0;
1074 next_opt = wrap2_opt_get_field(options, &opt_idx);
1075
1076 /* Separate the option into name and value parts. For backwards
1077 * compatibility we ignore exactly one '=' between name and value.
1078 */
1079 curr_opt = wrap2_opt_trim_string(curr_opt);
1080
1081 if (*(value = curr_opt + strcspn(curr_opt, "=" WRAP2_WHITESPACE))) {
1082 if (*value != '=') {
1083 *value++ = '\0';
1084 value += strspn(value, WRAP2_WHITESPACE);
1085 }
1086
1087 if (*value == '=') {
1088 *value++ = '\0';
1089 value += strspn(value, WRAP2_WHITESPACE);
1090 }
1091 }
1092
1093 if (*value == '\0') {
1094 value = NULL;
1095 }
1096
1097 key = curr_opt;
1098
1099 /* Disallow missing option names (and empty option fields). */
1100 if (*key == '\0') {
1101 wrap2_log("warning: missing option name");
1102 continue;
1103 }
1104
1105 /* Lookup the option-specific info and do some common error checks.
1106 * Delegate option-specific processing to the specific functions.
1107 */
1108
1109 /* Advance to the matching option table entry. */
1110 for (opt = options_tab; opt->name && strcasecmp(opt->name, key) != 0;
1111 opt++);
1112
1113 if (opt->name == 0) {
1114 wrap2_log("unknown option name: '%s'", key);
1115 continue;
1116 }
1117
1118 if (value == NULL &&
1119 WRAP2_OPT_NEEDS_VAL(opt)) {
1120 wrap2_log("option '%s' requires value", key);
1121 continue;
1122 }
1123
1124 if (value != NULL &&
1125 !WRAP2_OPT_ALLOWS_VAL(opt)) {
1126 wrap2_log("option '%s' requires no value", key);
1127 continue;
1128 }
1129
1130 if (next_opt != NULL &&
1131 WRAP2_OPT_NEEDS_LAST(opt)) {
1132 wrap2_log("option '%s' must be the last option in the list", key);
1133 continue;
1134 }
1135
1136 wrap2_log("processing option: '%s %s'", key, value ? value : "");
1137
1138 res = opt->func(value);
1139 if (res != 0) {
1140 return res;
1141 }
1142 }
1143
1144 return 0;
1145 }
1146 #endif /* WRAP2_USE_OPTIONS */
1147
1148 #define WRAP2_TAB_ALLOW 2
1149 #define WRAP2_TAB_MATCH 1
1150 #define WRAP2_TAB_DENY -1
1151
1152 static int wrap2_match_table(wrap2_table_t *tab, wrap2_conn_t *conn) {
1153 register unsigned int i;
1154 int res;
1155 array_header *daemon_list = NULL, *client_list = NULL, *options_list = NULL;
1156
1157 /* Build daemon list. */
1158 daemon_list = tab->tab_fetch_daemons(tab, wrap2_service_name);
1159 if (daemon_list == NULL ||
1160 daemon_list->nelts == 0) {
1161 wrap2_log("%s", "daemon list is empty");
1162 return 0;
1163 }
1164
1165 wrap2_log("table daemon list:");
1166 for (i = 0; i < daemon_list->nelts; i++) {
1167 char **daemons = daemon_list->elts;
1168 wrap2_log(" %s", daemons[i] ? daemons[i] : "<null>");
1169 }
1170
1171 /* Build client list. */
1172 client_list = tab->tab_fetch_clients(tab, wrap2_client_name);
1173 if (client_list == NULL ||
1174 client_list->nelts == 0) {
1175 wrap2_log("%s", "client list is empty");
1176 return 0;
1177 }
1178
1179 wrap2_log("table client list:");
1180 for (i = 0; i < client_list->nelts; i++) {
1181 char **clients = client_list->elts;
1182 wrap2_log(" %s", clients[i] ? clients[i] : "<null>");
1183 }
1184
1185 /* Build options list. */
1186 options_list = tab->tab_fetch_options(tab, wrap2_client_name);
1187 if (options_list &&
1188 options_list->nelts > 0) {
1189 wrap2_log("table options list:");
1190 for (i = 0; i < options_list->nelts; i++) {
1191 char **opts = options_list->elts;
1192 wrap2_log(" %s", opts[i] ? opts[i] : "<null>");
1193 }
1194 }
1195
1196 res = wrap2_match_list(daemon_list, conn, wrap2_match_daemon, 0);
1197 if (res == FALSE) {
1198 return 0;
1199 }
1200
1201 res = wrap2_match_list(client_list, conn, wrap2_match_client, 0);
1202 if (res == FALSE) {
1203 return 0;
1204 }
1205
1206 #if defined(WRAP2_USE_OPTIONS)
1207 res = wrap2_handle_opts(options_list, conn);
1208 if (res == WRAP2_OPT_ALLOW) {
1209 return WRAP2_TAB_ALLOW;
1210 }
1211
1212 if (res == WRAP2_OPT_DENY) {
1213 return WRAP2_TAB_DENY;
1214 }
1215 #endif /* WRAP2_USE_OPTIONS */
1216
1217 return WRAP2_TAB_MATCH;
1218 }
1219
1220 static unsigned char wrap2_allow_access(wrap2_conn_t *conn) {
1221 wrap2_table_t *allow_tab = NULL, *deny_tab = NULL;
1222 int res;
1223
1224 /* If the (daemon, client) pair is matched by an entry in the allow
1225 * table, access is granted. Otherwise, if the (daemon, client) pair is
1226 * matched by an entry in the deny table, access is denied. Otherwise,
1227 * access is granted. A non-existent access-control table is treated as an
1228 * empty table.
1229 */
1230
1231 /* Open allow table. */
1232 allow_tab = wrap2_open_table(wrap2_allow_table);
1233 if (allow_tab != NULL) {
1234 /* Check the allow table. */
1235 wrap2_log("%s", "checking allow table rules");
1236 res = wrap2_match_table(allow_tab, conn);
1237
1238 /* Close allow table. */
1239 wrap2_close_table(allow_tab);
1240 destroy_pool(allow_tab->tab_pool);
1241 allow_tab = NULL;
1242
1243 /* No need to check the deny table if the verdict is to explicitly allow. */
1244 if (res == WRAP2_TAB_ALLOW ||
1245 res == WRAP2_TAB_MATCH) {
1246 wrap2_allow_table = wrap2_deny_table = NULL;
1247 return TRUE;
1248 }
1249
1250 if (res == WRAP2_TAB_DENY) {
1251 wrap2_allow_table = wrap2_deny_table = NULL;
1252 return FALSE;
1253 }
1254
1255 } else {
1256 wrap2_log("error opening allow table: %s", strerror(errno));
1257 }
1258
1259 /* Open deny table. */
1260 deny_tab = wrap2_open_table(wrap2_deny_table);
1261 if (deny_tab != NULL) {
1262
1263 /* Check the deny table. */
1264 wrap2_log("%s", "checking deny table rules");
1265 res = wrap2_match_table(deny_tab, conn);
1266
1267 /* Close the deny table. */
1268 wrap2_close_table(deny_tab);
1269 destroy_pool(deny_tab->tab_pool);
1270 deny_tab = NULL;
1271
1272 if (res == WRAP2_TAB_DENY ||
1273 res == WRAP2_TAB_MATCH) {
1274 wrap2_allow_table = wrap2_deny_table = NULL;
1275 return FALSE;
1276 }
1277
1278 } else {
1279 wrap2_log("error opening deny table: %s", strerror(errno));
1280 }
1281
1282 wrap2_allow_table = wrap2_deny_table = NULL;
1283 return TRUE;
1284 }
1285
1286 /* Boolean OR expression evaluation, returning TRUE if any element in the
1287 * expression matches, FALSE otherwise.
1288 */
1289 static unsigned char wrap2_eval_or_expression(char **acl, array_header *creds) {
1290 unsigned char found = FALSE;
1291 char *elem = NULL, **list = NULL;
1292
1293 if (!acl || !*acl || !creds) {
1294 return FALSE;
1295 }
1296
1297 list = (char **) creds->elts;
1298
1299 for (; *acl; acl++) {
1300 register unsigned int i = 0;
1301 elem = *acl;
1302 found = FALSE;
1303
1304 if (*elem == '!') {
1305 found = !found;
1306 elem++;
1307 }
1308
1309 for (i = 0; i < creds->nelts; i++) {
1310 if (strcmp(elem, "*") == 0 || (list[i] && strcmp(elem, list[i]) == 0)) {
1311 found = !found;
1312 break;
1313 }
1314 }
1315
1316 if (found) {
1317 return TRUE;
1318 }
1319 }
1320
1321 return FALSE;
1322 }
1323
1324 /* Boolean AND expression evaluation, returning TRUE if every element in the
1325 * expression matches, FALSE otherwise.
1326 */
1327 static unsigned char wrap2_eval_and_expression(char **acl,
1328 array_header *creds) {
1329 unsigned char found = FALSE;
1330 char *elem = NULL, **list = NULL;
1331
1332 if (!acl || !*acl || !creds) {
1333 return FALSE;
1334 }
1335
1336 list = (char **) creds->elts;
1337
1338 for (; *acl; acl++) {
1339 register unsigned int i = 0;
1340 elem = *acl;
1341 found = FALSE;
1342
1343 if (*elem == '!') {
1344 found = !found;
1345 elem++;
1346 }
1347
1348 for (i = 0; i < creds->nelts; i++) {
1349 if (list[i] && strcmp(list[i], elem) == 0) {
1350 found = !found;
1351 break;
1352 }
1353 }
1354
1355 if (!found) {
1356 return FALSE;
1357 }
1358 }
1359
1360 return TRUE;
1361 }
1362
1363 int wrap2_register(const char *srcname,
1364 wrap2_table_t *(*srcopen)(pool *, const char *)) {
1365
1366 /* Note: I know that use of permanent_pool is discouraged as much as
1367 * possible, but in this particular instance, I need a pool that
1368 * persists across rehashes.
1369 *
1370 * Ideally, the wrap2_regtab_t struct would have a subpool member;
1371 * the objects would have their own pools which could then be
1372 * destroyed upon unregistration.
1373 */
1374 wrap2_regtab_t *regtab = pcalloc(permanent_pool, sizeof(wrap2_regtab_t));
1375
1376 regtab->regtab_name = pstrdup(permanent_pool, srcname);
1377 regtab->regtab_open = srcopen;
1378
1379 /* Add this object to the list. */
1380 if (wrap2_regtab_list) {
1381 wrap2_regtab_list->prev = regtab;
1382 regtab->next = wrap2_regtab_list;
1383 }
1384
1385 wrap2_regtab_list = regtab;
1386 return 0;
1387 }
1388
1389 int wrap2_unregister(const char *srcname) {
1390 if (wrap2_regtab_list) {
1391 register wrap2_regtab_t *regtab = NULL;
1392
1393 for (regtab = wrap2_regtab_list; regtab; regtab = regtab->next) {
1394 if (strcmp(regtab->regtab_name, srcname) == 0) {
1395
1396 if (regtab->prev) {
1397 regtab->prev->next = regtab->next;
1398
1399 } else {
1400 wrap2_regtab_list = regtab->next;
1401 }
1402
1403 if (regtab->next) {
1404 regtab->next->prev = regtab->prev;
1405 }
1406
1407 regtab->prev = regtab->next = NULL;
1408
1409 /* NOTE: a counter should be kept of the number of unregistrations,
1410 * as the memory for a registration is not freed on unregistration.
1411 */
1412 return 0;
1413 }
1414 }
1415
1416 errno = ENOENT;
1417 return -1;
1418 }
1419
1420 errno = EPERM;
1421 return -1;
1422 }
1423
1424 /* "builtin" source callbacks. */
1425
1426 static int builtin_close_cb(wrap2_table_t *tab) {
1427 return 0;
1428 }
1429
1430 static array_header *builtin_fetch_clients_cb(wrap2_table_t *tab,
1431 const char *name) {
1432 array_header *list = make_array(tab->tab_pool, 1, sizeof(char *));
1433
1434 *((char **) push_array(list)) = pstrdup(tab->tab_pool, "ALL");
1435 return list;
1436 }
1437
1438 static array_header *builtin_fetch_daemons_cb(wrap2_table_t *tab,
1439 const char *name) {
1440 array_header *list = make_array(tab->tab_pool, 1, sizeof(char *));
1441
1442 *((char **) push_array(list)) = pstrdup(tab->tab_pool, name);
1443 return list;
1444 }
1445
1446 static array_header *builtin_fetch_options_cb(wrap2_table_t *tab,
1447 const char *name) {
1448 return NULL;
1449 }
1450
1451 static wrap2_table_t *builtin_open_cb(pool *parent_pool, const char *srcinfo) {
1452 wrap2_table_t *tab = NULL;
1453 pool *tab_pool = make_sub_pool(parent_pool);
1454
1455 /* Do not allow any parameters other than 'all. */
1456 if (strcasecmp(srcinfo, "all") != 0) {
1457 wrap2_log("error: unknown builtin parameter: '%s'", srcinfo);
1458 destroy_pool(tab_pool);
1459 errno = EINVAL;
1460 return NULL;
1461 }
1462
1463 tab = (wrap2_table_t *) pcalloc(tab_pool, sizeof(wrap2_table_t));
1464 tab->tab_pool = tab_pool;
1465
1466 tab->tab_name = "builtin";
1467
1468 /* Set the necessary callbacks. */
1469 tab->tab_close = builtin_close_cb;
1470 tab->tab_fetch_clients = builtin_fetch_clients_cb;
1471 tab->tab_fetch_daemons = builtin_fetch_daemons_cb;
1472 tab->tab_fetch_options = builtin_fetch_options_cb;
1473
1474 return tab;
1475 }
1476
1477 /* Configuration handlers
1478 */
1479
1480 /* usage: Wrap{Allow,Deny}Msg mesg */
1481 MODRET set_wrapmsg(cmd_rec *cmd) {
1482 config_rec *c = NULL;
1483
1484 CHECK_ARGS(cmd, 1);
1485 CHECK_CONF(cmd, CONF_ROOT|CONF_VIRTUAL|CONF_GLOBAL|CONF_ANON);
1486
1487 c = add_config_param_str(cmd->argv[0], 1, cmd->argv[1]);
1488 c->flags |= CF_MERGEDOWN;
1489
1490 return PR_HANDLED(cmd);
1491 }
1492
1493 /* usage: WrapEngine on|off */
1494 MODRET set_wrapengine(cmd_rec *cmd) {
1495 int engine = -1;
1496 config_rec *c = NULL;
1497
1498 CHECK_ARGS(cmd, 1);
1499 CHECK_CONF(cmd, CONF_ROOT|CONF_VIRTUAL|CONF_GLOBAL);
1500
1501 engine = get_boolean(cmd, 1);
1502 if (engine == -1) {
1503 CONF_ERROR(cmd, "expecting Boolean parameter");
1504 }
1505
1506 c = add_config_param(cmd->argv[0], 1, NULL);
1507 c->argv[0] = pcalloc(c->pool, sizeof(int));
1508 *((int *) c->argv[0]) = engine;
1509
1510 return PR_HANDLED(cmd);
1511 }
1512
1513 /* usage: WrapGroupTables group-and-expression allow-table deny-table */
1514 MODRET set_wrapgrouptables(cmd_rec *cmd) {
1515 register wrap2_regtab_t *regtab = NULL;
1516 register unsigned int i = 0;
1517 unsigned char have_registration = FALSE;
1518 config_rec *c = NULL;
1519 unsigned int argc = 1;
1520 void **argv = NULL;
1521 array_header *acl = NULL;
1522
1523 CHECK_ARGS(cmd, 3);
1524 CHECK_CONF(cmd, CONF_ROOT|CONF_VIRTUAL|CONF_GLOBAL|CONF_ANON);
1525
1526 /* Verify that the requested source types have been registered. */
1527 for (i = 2; i < cmd->argc-1; i++) {
1528 char *tmp = NULL;
1529
1530 tmp = strchr(cmd->argv[i], ':');
1531 if (tmp == NULL) {
1532 CONF_ERROR(cmd, pstrcat(cmd->tmp_pool, "bad table parameter: '",
1533 (char *) cmd->argv[i], "'", NULL));
1534 }
1535
1536 *tmp = '\0';
1537
1538 for (regtab = wrap2_regtab_list; regtab; regtab = regtab->next) {
1539 if (strcmp(regtab->regtab_name, cmd->argv[i]) == 0) {
1540 have_registration = TRUE;
1541 break;
1542 }
1543 }
1544
1545 if (have_registration == FALSE) {
1546 CONF_ERROR(cmd, pstrcat(cmd->tmp_pool, "unsupported table source type: '",
1547 (char *) cmd->argv[i], "'", NULL));
1548 }
1549
1550 *tmp = ':';
1551 }
1552
1553 c = add_config_param(cmd->argv[0], 0);
1554 acl = pr_expr_create(cmd->tmp_pool, &argc, (char **) &cmd->argv[0]);
1555
1556 /* Build the desired config_rec manually. */
1557 c->argc = argc + 2;
1558 c->argv = pcalloc(c->pool, (argc + 3) * sizeof(void *));
1559 argv = c->argv;
1560
1561 /* The tables are the first two parameters */
1562 *argv++ = pstrdup(c->pool, cmd->argv[2]);
1563 *argv++ = pstrdup(c->pool, cmd->argv[3]);
1564
1565 /* Now populate the group-expression names */
1566 if (argc && acl) {
1567 while (argc--) {
1568 *argv++ = pstrdup(c->pool, *((char **) acl->elts));
1569 acl->elts = ((char **) acl->elts) + 1;
1570 }
1571 }
1572
1573 /* Do not forget the terminating NULL */
1574 *argv = NULL;
1575
1576 c->flags |= CF_MERGEDOWN;
1577 return PR_HANDLED(cmd);
1578 }
1579
1580 /* usage: WrapLog file|"none" */
1581 MODRET set_wraplog(cmd_rec *cmd) {
1582 CHECK_ARGS(cmd, 1);
1583 CHECK_CONF(cmd, CONF_ROOT|CONF_VIRTUAL|CONF_GLOBAL);
1584
1585 add_config_param_str(cmd->argv[0], 1, cmd->argv[1]);
1586 return PR_HANDLED(cmd);
1587 }
1588
1589 /* usage: WrapOptions opt1 ... optN */
1590 MODRET set_wrapoptions(cmd_rec *cmd) {
1591 config_rec *c = NULL;
1592 register unsigned int i = 0;
1593 unsigned long opts = 0UL;
1594
1595 if (cmd->argc-1 == 0) {
1596 CONF_ERROR(cmd, "wrong number of parameters");
1597 }
1598
1599 CHECK_CONF(cmd, CONF_ROOT|CONF_VIRTUAL|CONF_GLOBAL);
1600
1601 c = add_config_param(cmd->argv[0], 1, NULL);
1602
1603 for (i = 1; i < cmd->argc; i++) {
1604 if (strcmp(cmd->argv[i], "CheckOnConnect") == 0) {
1605 opts |= WRAP_OPT_CHECK_ON_CONNECT;
1606
1607 } else if (strcmp(cmd->argv[i], "CheckAllNames") == 0) {
1608 opts |= WRAP_OPT_CHECK_ALL_NAMES;
1609
1610 } else {
1611 CONF_ERROR(cmd, pstrcat(cmd->tmp_pool, ": unknown WrapOption '",
1612 cmd->argv[i], "'", NULL));
1613 }
1614 }
1615
1616 c->argv[0] = pcalloc(c->pool, sizeof(unsigned long));
1617 *((unsigned long *) c->argv[0]) = opts;
1618
1619 if (pr_module_exists("mod_ifsession.c")) {
1620 /* These are needed in case this directive is used with mod_ifsession
1621 * configuration.
1622 */
1623 c->flags |= CF_MULTI;
1624 }
1625
1626 return PR_HANDLED(cmd);
1627 }
1628
1629 /* usage: WrapServiceName <name> */
1630 MODRET set_wrapservicename(cmd_rec *cmd) {
1631 CHECK_ARGS(cmd, 1);
1632 CHECK_CONF(cmd, CONF_ROOT|CONF_VIRTUAL|CONF_GLOBAL);
1633
1634 add_config_param_str(cmd->argv[0], 1, cmd->argv[1]);
1635 return PR_HANDLED(cmd);
1636 }
1637
1638 /* usage: WrapTables allow-table deny-table */
1639 MODRET set_wraptables(cmd_rec *cmd) {
1640 register wrap2_regtab_t *regtab = NULL;
1641 register unsigned int i = 0;
1642 unsigned char have_registration = FALSE;
1643 config_rec *c = NULL;
1644
1645 CHECK_ARGS(cmd, 2);
1646 CHECK_CONF(cmd, CONF_ROOT|CONF_VIRTUAL|CONF_GLOBAL|CONF_ANON);
1647
1648 /* Verify that the requested source types have been registered. */
1649 for (i = 1; i < cmd->argc-1; i++) {
1650 char *tmp = NULL;
1651
1652 tmp = strchr(cmd->argv[i], ':');
1653 if (tmp == NULL) {
1654 CONF_ERROR(cmd, pstrcat(cmd->tmp_pool, "bad table parameter: '",
1655 cmd->argv[i], "'", NULL));
1656 }
1657
1658 *tmp = '\0';
1659
1660 for (regtab = wrap2_regtab_list; regtab; regtab = regtab->next) {
1661 if (strcmp(regtab->regtab_name, cmd->argv[i]) == 0) {
1662 have_registration = TRUE;
1663 break;
1664 }
1665 }
1666
1667 if (have_registration == FALSE) {
1668 CONF_ERROR(cmd, pstrcat(cmd->tmp_pool, "unsupported table source type: '",
1669 cmd->argv[i], "'", NULL));
1670 }
1671
1672 *tmp = ':';
1673 }
1674
1675 c = add_config_param_str(cmd->argv[0], 2, cmd->argv[1], cmd->argv[2]);
1676 c->flags |= CF_MERGEDOWN;
1677
1678 return PR_HANDLED(cmd);
1679 }
1680
1681 /* usage: WrapUserTables user-or-expression allow-table deny-table */
1682 MODRET set_wrapusertables(cmd_rec *cmd) {
1683 register wrap2_regtab_t *regtab = NULL;
1684 register unsigned int i = 0;
1685 unsigned char have_registration = FALSE;
1686 config_rec *c = NULL;
1687 unsigned int argc = 1;
1688 void **argv = NULL;
1689 array_header *acl = NULL;
1690
1691 CHECK_ARGS(cmd, 3);
1692 CHECK_CONF(cmd, CONF_ROOT|CONF_VIRTUAL|CONF_GLOBAL|CONF_ANON);
1693
1694 /* Verify that the requested source types have been registered. */
1695 for (i = 2; i < cmd->argc-1; i++) {
1696 char *tmp = NULL;
1697
1698 tmp = strchr(cmd->argv[i], ':');
1699 if (tmp == NULL) {
1700 CONF_ERROR(cmd, pstrcat(cmd->tmp_pool, "bad table parameter: '",
1701 (char *) cmd->argv[i], "'", NULL));
1702 }
1703
1704 *tmp = '\0';
1705
1706 for (regtab = wrap2_regtab_list; regtab; regtab = regtab->next) {
1707 if (strcmp(regtab->regtab_name, cmd->argv[i]) == 0) {
1708 have_registration = TRUE;
1709 break;
1710 }
1711 }
1712
1713 if (have_registration == FALSE) {
1714 CONF_ERROR(cmd, pstrcat(cmd->tmp_pool, "unsupported table source type: '",
1715 (char *) cmd->argv[i], "'", NULL));
1716 }
1717
1718 *tmp = ':';
1719 }
1720
1721 c = add_config_param(cmd->argv[0], 0);
1722 acl = pr_expr_create(cmd->tmp_pool, &argc, (char **) &cmd->argv[0]);
1723
1724 /* Build the desired config_rec manually. */
1725 c->argc = argc + 2;
1726 c->argv = pcalloc(c->pool, (argc + 3) * sizeof(void *));
1727 argv = c->argv;
1728
1729 /* The tables are the first two parameters */
1730 *argv++ = pstrdup(c->pool, cmd->argv[2]);
1731 *argv++ = pstrdup(c->pool, cmd->argv[3]);
1732
1733 /* Now populate the user-expression names */
1734 if (argc && acl) {
1735 while (argc--) {
1736 *argv++ = pstrdup(c->pool, *((char **) acl->elts));
1737 acl->elts = ((char **) acl->elts) + 1;
1738 }
1739 }
1740
1741 /* Do not forget the terminating NULL */
1742 *argv = NULL;
1743
1744 c->flags |= CF_MERGEDOWN;
1745 return PR_HANDLED(cmd);
1746 }
1747
1748 /* Command handlers
1749 */
1750
1751 MODRET wrap2_pre_pass(cmd_rec *cmd) {
1752 wrap2_conn_t conn;
1753 unsigned char have_tables = FALSE;
1754 const char *user = NULL;
1755 config_rec *c = NULL;
1756
1757 if (wrap2_engine == FALSE) {
1758 return PR_DECLINED(cmd);
1759 }
1760
1761 /* Hide passwords */
1762 session.hide_password = TRUE;
1763
1764 user = pr_table_get(session.notes, "mod_auth.orig-user", NULL);
1765 if (user == NULL) {
1766 return PR_DECLINED(cmd);
1767 }
1768
1769 wrap2_ctxt = pr_auth_get_anon_config(cmd->pool, &user, NULL, NULL);
1770
1771 if (user == NULL) {
1772 return PR_DECLINED(cmd);
1773 }
1774
1775 {
1776 /* Cheat a little here, and pre-populate some of session's members. Do
1777 * not worry: these values are only temporary, and will be overwritten
1778 * during the login process. This needs to be done here, before the
1779 * call to wrap2_allow_access(), for that function does the opening of
1780 * the tables.
1781 */
1782 struct passwd *pw = NULL;
1783
1784 pw = pr_auth_getpwnam(cmd->pool, user);
1785 if (pw != NULL) {
1786 struct group *gr = NULL;
1787
1788 /* For the dir_realpath() function to work, some session members need to
1789 * be set.
1790 */
1791 session.user = pstrdup(cmd->pool, pw->pw_name);
1792
1793 session.login_uid = pw->pw_uid;
1794 session.login_gid = pw->pw_gid;
1795
1796 gr = pr_auth_getgrgid(cmd->pool, session.login_gid);
1797 if (gr != NULL) {
1798 session.group = pstrdup(cmd->pool, gr->gr_name);
1799
1800 } else {
1801 wrap2_log("unable to resolve GID for '%s'", user);
1802 }
1803
1804 } else {
1805 wrap2_log("unable to resolve UID for '%s'", user);
1806 return PR_DECLINED(cmd);
1807 }
1808 }
1809
1810 /* Search first for user-specific access tables. Multiple WrapUserTables
1811 * directives are allowed.
1812 */
1813
1814 c = find_config(wrap2_ctxt ? wrap2_ctxt->subset : main_server->conf,
1815 CONF_PARAM, "WrapUserTables", FALSE);
1816 while (c != NULL) {
1817 array_header *user_array;
1818
1819 pr_signals_handle();
1820
1821 user_array = make_array(cmd->tmp_pool, 0, sizeof(char *));
1822 *((char **) push_array(user_array)) = pstrdup(cmd->tmp_pool, user);
1823
1824 /* Check the user OR expression. Do not forget the offset, to skip
1825 * the table name strings in c->argv.
1826 */
1827 if (wrap2_eval_or_expression((char **) &c->argv[2], user_array)) {
1828 wrap2_log("matched WrapUserTables expression for user '%s'", user);
1829
1830 wrap2_allow_table = c->argv[0];
1831 wrap2_deny_table = c->argv[1];
1832 wrap2_client_name = session.user;
1833
1834 have_tables = TRUE;
1835 c = NULL;
1836
1837 break;
1838 }
1839
1840 c = find_config_next(c, c->next, CONF_PARAM, "WrapUserTables", FALSE);
1841 }
1842
1843 /* Next, search for group-specific access tables. Multiple WrapGroupTables
1844 * directives are allowed.
1845 */
1846 if (!have_tables) {
1847 c = find_config(wrap2_ctxt ? wrap2_ctxt->subset : main_server->conf,
1848 CONF_PARAM, "WrapGroupTables", FALSE);
1849 }
1850
1851 while (c) {
1852 array_header *gid_array, *group_array;
1853
1854 pr_signals_handle();
1855
1856 gid_array = make_array(cmd->pool, 0, sizeof(gid_t));
1857 group_array = make_array(cmd->pool, 0, sizeof(char *));
1858
1859 if (pr_auth_getgroups(cmd->pool, user, &gid_array, &group_array) < 1) {
1860 wrap2_log("no supplemental groups found for user '%s'", user);
1861
1862 } else {
1863
1864 /* Check the group AND expression. Do not forget the offset, to skip
1865 * the table names strings in c->argv.
1866 */
1867 if (wrap2_eval_and_expression((char **) &c->argv[2], group_array)) {
1868 wrap2_log("matched WrapGroupTables expression for user '%s'", user);
1869
1870 wrap2_allow_table = c->argv[0];
1871 wrap2_deny_table = c->argv[1];
1872 wrap2_client_name = session.group;
1873
1874 have_tables = TRUE;
1875 c = NULL;
1876
1877 break;
1878 }
1879 }
1880
1881 c = find_config_next(c, c->next, CONF_PARAM, "WrapGroupTables", FALSE);
1882 }
1883
1884 /* Finally for globally-applicable access files. Only one such directive
1885 * is allowed.
1886 */
1887 if (!have_tables) {
1888 c = find_config(wrap2_ctxt ? wrap2_ctxt->subset : main_server->conf,
1889 CONF_PARAM, "WrapTables", FALSE);
1890 }
1891
1892 if (c) {
1893 wrap2_allow_table = c->argv[0];
1894 wrap2_deny_table = c->argv[1];
1895
1896 wrap2_client_name = "";
1897 have_tables = TRUE;
1898 }
1899
1900 if (have_tables) {
1901 /* Log the names of the allow/deny tables being used. */
1902 wrap2_log("using '%s' for allow table", wrap2_allow_table);
1903 wrap2_log("using '%s' for deny table", wrap2_deny_table);
1904
1905 } else {
1906 wrap2_log("no tables configured, allowing connection");
1907 return PR_DECLINED(cmd);
1908 }
1909
1910 wrap2_log("looking under service name '%s'", wrap2_service_name);
1911
1912 memset(&conn, '\0', sizeof(conn));
1913
1914 wrap2_conn_set(&conn, WRAP2_CONN_DAEMON, wrap2_service_name,
1915 WRAP2_CONN_SOCK_FD, session.c->rfd, 0);
1916
1917 wrap2_log("%s", "checking access rules for connection");
1918
1919 if (wrap2_allow_access(&conn) == FALSE) {
1920 const char *msg = NULL;
1921
1922 /* Log the denied connection */
1923 wrap2_log("refused connection from %s", wrap2_get_client(&conn));
1924
1925 /* Broadcast this event to any interested listeners. We use the same
1926 * event name as mod_wrap for consistency.
1927 */
1928 pr_event_generate("mod_wrap.connection-denied", NULL);
1929
1930 /* Check for a configured WrapDenyMsg. If not present, then use the
1931 * default denied message.
1932 */
1933 msg = get_param_ptr(wrap2_ctxt ? wrap2_ctxt->subset : main_server->conf,
1934 "WrapDenyMsg", FALSE);
1935 if (msg != NULL) {
1936 msg = sreplace(cmd->tmp_pool, msg, "%u", user, NULL);
1937 }
1938
1939 pr_response_send(R_530, "%s", msg ? msg : _("Access denied"));
1940 pr_session_disconnect(&wrap2_module, PR_SESS_DISCONNECT_MODULE_ACL, NULL);
1941 }
1942
1943 wrap2_log("allowed connection from %s", wrap2_get_client(&conn));
1944 return PR_DECLINED(cmd);
1945 }
1946
1947 MODRET wrap2_post_pass(cmd_rec *cmd) {
1948 const char *msg = NULL;
1949
1950 if (wrap2_engine == FALSE) {
1951 return PR_DECLINED(cmd);
1952 }
1953
1954 /* Check for a configured WrapAllowMsg. If the connection were denied,
1955 * it would have been terminated before reaching this command handler.
1956 */
1957 msg = get_param_ptr(wrap2_ctxt ? wrap2_ctxt->subset : main_server->conf,
1958 "WrapAllowMsg", FALSE);
1959 if (msg != NULL) {
1960 const char *user;
1961
1962 user = pr_table_get(session.notes, "mod_auth.orig-user", NULL);
1963 msg = sreplace(cmd->tmp_pool, msg, "%u", user, NULL);
1964 pr_response_add(R_DUP, "%s", msg);
1965 }
1966
1967 return PR_DECLINED(cmd);
1968 }
1969
1970 MODRET wrap2_post_pass_err(cmd_rec *cmd) {
1971 if (wrap2_engine == FALSE) {
1972 return PR_DECLINED(cmd);
1973 }
1974
1975 /* Clear the values from the session struct as well, specifically
1976 * session.user. Failure to do so caused Bug#3727.
1977 */
1978 session.user = NULL;
1979 session.group = NULL;
1980
1981 wrap2_ctxt = NULL;
1982 wrap2_allow_table = NULL;
1983 wrap2_deny_table = NULL;
1984 wrap2_client_name = NULL;
1985
1986 return PR_DECLINED(cmd);
1987 }
1988
1989 /* Event handlers
1990 */
1991
1992 static void wrap2_exit_ev(const void *event_data, void *user_data) {
1993 wrap2_closelog();
1994 return;
1995 }
1996
1997 #if defined(PR_SHARED_MODULE)
1998 static void wrap2_mod_unload_ev(const void *event_data, void *user_data) {
1999 if (strcmp("mod_wrap2.c", (const char *) event_data) == 0) {
2000 /* Unregister ourselves from all events. */
2001 pr_event_unregister(&wrap2_module, NULL, NULL);
2002
2003 wrap2_unregister("builtin");
2004
2005 if (wrap2_pool) {
2006 destroy_pool(wrap2_pool);
2007 wrap2_pool = NULL;
2008 }
2009
2010 close(wrap2_logfd);
2011 wrap2_logfd = -1;
2012 }
2013 }
2014
2015 #endif /* PR_SHARED_MODULE */
2016
2017 static void wrap2_restart_ev(const void *event_data, void *user_data) {
2018
2019 /* Bounce the log file descriptor. */
2020 wrap2_closelog();
2021 wrap2_openlog();
2022
2023 /* Reset the module's memory pool. */
2024 destroy_pool(wrap2_pool);
2025 wrap2_pool = make_sub_pool(permanent_pool);
2026 pr_pool_tag(wrap2_pool, MOD_WRAP2_VERSION);
2027 }
2028
2029 static void wrap2_sess_reinit_ev(const void *event_data, void *user_data) {
2030 int res;
2031
2032 /* A HOST command changed the main_server pointer; reinitialize ourselves. */
2033
2034 pr_event_unregister(&wrap2_module, "core.exit", wrap2_exit_ev);
2035 pr_event_unregister(&wrap2_module, "core.session-reinit",
2036 wrap2_sess_reinit_ev);
2037
2038 /* Reset defaults. */
2039 wrap2_engine = FALSE;
2040 (void) close(wrap2_logfd);
2041 wrap2_logfd = -1;
2042 wrap2_logname = NULL;
2043 wrap2_service_name = WRAP2_DEFAULT_SERVICE_NAME;
2044 wrap2_opts = 0UL;
2045 wrap2_allow_table = NULL;
2046 wrap2_deny_table = NULL;
2047 wrap2_client_name = NULL;
2048
2049 res = wrap2_sess_init();
2050 if (res < 0) {
2051 pr_session_disconnect(&wrap2_module,
2052 PR_SESS_DISCONNECT_SESSION_INIT_FAILED, NULL);
2053 }
2054 }
2055
2056 /* Initialization routines
2057 */
2058
2059 static int wrap2_init(void) {
2060
2061 /* Initialize the module's memory pool. */
2062 if (!wrap2_pool) {
2063 wrap2_pool = make_sub_pool(permanent_pool);
2064 pr_pool_tag(wrap2_pool, MOD_WRAP2_VERSION);
2065 }
2066
2067 #if defined(PR_SHARED_MODULE)
2068 pr_event_register(&wrap2_module, "core.module-unload", wrap2_mod_unload_ev,
2069 NULL);
2070 #endif /* PR_SHARED_MODULE */
2071 pr_event_register(&wrap2_module, "core.restart", wrap2_restart_ev, NULL);
2072
2073 /* Initialize the source object for type "builtin". */
2074 wrap2_register("builtin", builtin_open_cb);
2075
2076 return 0;
2077 }
2078
2079 static int wrap2_sess_init(void) {
2080 config_rec *c;
2081
2082 pr_event_register(&wrap2_module, "core.session-reinit", wrap2_sess_reinit_ev,
2083 NULL);
2084
2085 c = find_config(main_server->conf, CONF_PARAM, "WrapEngine", FALSE);
2086 if (c != NULL) {
2087 wrap2_engine = *((int *) c->argv[0]);
2088 }
2089
2090 if (wrap2_engine == FALSE) {
2091 return 0;
2092 }
2093
2094 wrap2_openlog();
2095
2096 /* Look up any configured WrapServiceName */
2097 wrap2_service_name = get_param_ptr(main_server->conf, "WrapServiceName",
2098 FALSE);
2099 if (wrap2_service_name == NULL)
2100 wrap2_service_name = WRAP2_DEFAULT_SERVICE_NAME;
2101
2102 /* Make sure that tables will be closed when the child exits. */
2103 pr_event_register(&wrap2_module, "core.exit", wrap2_exit_ev, NULL);
2104
2105 c = find_config(main_server->conf, CONF_PARAM, "WrapOptions", FALSE);
2106 while (c != NULL) {
2107 unsigned long opts;
2108
2109 pr_signals_handle();
2110
2111 opts = *((unsigned long *) c->argv[0]);
2112 wrap2_opts |= opts;
2113
2114 c = find_config_next(c, c->next, CONF_PARAM, "WrapOptions", FALSE);
2115 }
2116
2117 if (wrap2_opts & WRAP_OPT_CHECK_ON_CONNECT) {
2118 c = find_config(main_server->conf, CONF_PARAM, "WrapTables", FALSE);
2119 if (c) {
2120 wrap2_conn_t conn;
2121
2122 wrap2_allow_table = c->argv[0];
2123 wrap2_deny_table = c->argv[1];
2124 wrap2_client_name = "";
2125
2126 wrap2_log("using '%s' for allow table", wrap2_allow_table);
2127 wrap2_log("using '%s' for deny table", wrap2_deny_table);
2128 wrap2_log("looking under service name '%s'", wrap2_service_name);
2129
2130 memset(&conn, '\0', sizeof(conn));
2131 wrap2_conn_set(&conn, WRAP2_CONN_DAEMON, wrap2_service_name,
2132 WRAP2_CONN_SOCK_FD, session.c->rfd, 0);
2133
2134 wrap2_log("%s", "checking access rules for connection");
2135
2136 if (wrap2_allow_access(&conn) == FALSE) {
2137 const char *msg = NULL;
2138
2139 /* Log the denied connection */
2140 wrap2_log("refused connection from %s", wrap2_get_client(&conn));
2141
2142 /* Broadcast this event to any interested listeners. We use the same
2143 * event name as mod_wrap for consistency.
2144 */
2145 pr_event_generate("mod_wrap.connection-denied", NULL);
2146
2147 /* Check for a configured WrapDenyMsg. If not present, then use the
2148 * default denied message.
2149 */
2150 msg = get_param_ptr(main_server->conf, "WrapDenyMsg", FALSE);
2151 if (msg != NULL) {
2152 msg = sreplace(session.pool, msg, "%u", "unknown", NULL);
2153 }
2154
2155 pr_response_send(R_530, "%s", msg ? msg : _("Access denied"));
2156 pr_session_disconnect(&wrap2_module, PR_SESS_DISCONNECT_MODULE_ACL,
2157 NULL);
2158 }
2159 }
2160 }
2161
2162 return 0;
2163 }
2164
2165 /* Module API tables
2166 */
2167
2168 static conftable wrap2_conftab[] = {
2169 { "WrapAllowMsg", set_wrapmsg, NULL },
2170 { "WrapDenyMsg", set_wrapmsg, NULL },
2171 { "WrapEngine", set_wrapengine, NULL },
2172 { "WrapGroupTables", set_wrapgrouptables, NULL },
2173 { "WrapLog", set_wraplog, NULL },
2174 { "WrapOptions", set_wrapoptions, NULL },
2175 { "WrapServiceName", set_wrapservicename, NULL },
2176 { "WrapTables", set_wraptables, NULL },
2177 { "WrapUserTables", set_wrapusertables, NULL },
2178 { NULL }
2179 };
2180
2181 static cmdtable wrap2_cmdtab[] = {
2182 { PRE_CMD, C_PASS, G_NONE, wrap2_pre_pass, FALSE, FALSE },
2183 { POST_CMD, C_PASS, G_NONE, wrap2_post_pass, FALSE, FALSE },
2184 { POST_CMD_ERR,C_PASS,G_NONE, wrap2_post_pass_err, FALSE, FALSE },
2185 { 0, NULL }
2186 };
2187
2188 module wrap2_module = {
2189 NULL, NULL,
2190
2191 /* Module API version 2.0 */
2192 0x20,
2193
2194 /* Module name */
2195 "wrap2",
2196
2197 /* Mmodule configuration handler table */
2198 wrap2_conftab,
2199
2200 /* Module command handler table */
2201 wrap2_cmdtab,
2202
2203 /* Module authentication handler table */
2204 NULL,
2205
2206 /* Module initialization */
2207 wrap2_init,
2208
2209 /* Session initialization */
2210 wrap2_sess_init,
2211
2212 /* Module version */
2213 MOD_WRAP2_VERSION
2214 };