Debian Codegraph @

modules/mod_ctrls.c

raw symbols SCIP
1 /*
2 * ProFTPD: mod_ctrls -- a module implementing the ftpdctl local socket
3 * server, as well as several utility functions for other Controls
4 * modules
5 * Copyright (c) 2000-2024 TJ Saunders
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
20 *
21 * As a special exemption, TJ Saunders and other respective copyright holders
22 * give permission to link this program with OpenSSL, and distribute the
23 * resulting executable, without including the source code for OpenSSL in the
24 * source distribution.
25 *
26 * This is mod_ctrls, contrib software for proftpd 1.3.x and above.
27 * For more information contact TJ Saunders <[email protected]>.
28 */
29
30 #include "conf.h"
31 #include "privs.h"
32 #include "mod_ctrls.h"
33
34 #define MOD_CTRLS_VERSION "mod_ctrls/0.9.5"
35
36 #ifndef PR_USE_CTRLS
37 # error "Controls support required (use --enable-ctrls)"
38 #endif
39
40 /* Master daemon in standalone mode? (from src/main.c) */
41 extern unsigned char is_master;
42
43 module ctrls_module;
44 static ctrls_acttab_t ctrls_acttab[];
45
46 static const char *trace_channel = "ctrls";
47
48 /* Hard-coded Controls timer IDs. Need two, one for the initial timer, one
49 * to identify the user-configured-interval timer
50 */
51 #define CTRLS_TIMER_ID 24075
52
53 static unsigned int ctrls_interval = 10;
54
55 /* Controls listening socket fd */
56 static int ctrls_sockfd = -1;
57
58 #define MOD_CTRLS_DEFAULT_SOCK PR_RUN_DIR "/proftpd.sock"
59 static char *ctrls_sock_file = MOD_CTRLS_DEFAULT_SOCK;
60
61 /* User/group ownership of the control socket */
62 static uid_t ctrls_sock_uid = 0;
63 static gid_t ctrls_sock_gid = 0;
64
65 /* Pool for this module's use */
66 static pool *ctrls_pool = NULL;
67
68 /* Required "freshness" of client credential sockets */
69 static unsigned int ctrls_cl_freshness = 10;
70
71 /* Start of the client list */
72 static pr_ctrls_cl_t *cl_list = NULL;
73 static unsigned int cl_listlen = 0;
74 static unsigned int cl_maxlistlen = 5;
75
76 /* Controls access control list. This is for ACLs on the control socket
77 * itself, rather than on individual actions.
78 */
79 static ctrls_acl_t ctrls_sock_acl;
80
81 static unsigned char ctrls_engine = TRUE;
82
83 /* Necessary prototypes */
84 static int ctrls_setblock(int sockfd);
85 static int ctrls_setnonblock(int sockfd);
86
87 static const char *ctrls_logname = NULL;
88
89 /* Support routines
90 */
91
92 /* Controls logging routines
93 */
94
95 static int ctrls_closelog(void) {
96 if (ctrls_logname != NULL) {
97 pr_ctrls_set_logfd(-1);
98 ctrls_logname = NULL;
99 }
100
101 return 0;
102 }
103
104 static int ctrls_openlog(void) {
105 int logfd, res = 0, xerrno = 0;
106
107 /* Sanity check */
108 if (ctrls_logname == NULL) {
109 return 0;
110 }
111
112 PRIVS_ROOT
113 res = pr_log_openfile(ctrls_logname, &logfd, PR_LOG_SYSTEM_MODE);
114 xerrno = errno;
115 PRIVS_RELINQUISH
116
117 if (res == 0) {
118 pr_ctrls_set_logfd(logfd);
119
120 } else {
121 if (res == -1) {
122 pr_log_pri(PR_LOG_NOTICE, MOD_CTRLS_VERSION
123 ": unable to open ControlsLog '%s': %s", ctrls_logname,
124 strerror(xerrno));
125
126 } else if (res == PR_LOG_WRITABLE_DIR) {
127 pr_log_pri(PR_LOG_WARNING, MOD_CTRLS_VERSION
128 ": unable to open ControlsLog '%s': "
129 "parent directory is world-writable", ctrls_logname);
130
131 } else if (res == PR_LOG_SYMLINK) {
132 pr_log_pri(PR_LOG_WARNING, MOD_CTRLS_VERSION
133 ": unable to open ControlsLog '%s': %s is a symbolic link",
134 ctrls_logname, ctrls_logname);
135 }
136 }
137
138 return res;
139 }
140
141 /* Controls client routines
142 */
143
144 static pr_ctrls_cl_t *ctrls_new_cl(void) {
145 pool *cl_pool = NULL;
146
147 if (cl_list == NULL) {
148
149 /* Our first client */
150 cl_pool = make_sub_pool(ctrls_pool);
151 pr_pool_tag(cl_pool, "Controls client pool");
152
153 cl_list = (pr_ctrls_cl_t *) pcalloc(cl_pool, sizeof(pr_ctrls_cl_t));
154
155 cl_list->cl_pool = cl_pool;
156 cl_list->cl_fd = -1;
157 cl_list->cl_uid = 0;
158 cl_list->cl_user = NULL;
159 cl_list->cl_gid = 0;
160 cl_list->cl_group = NULL;
161 cl_list->cl_pid = 0;
162 cl_list->cl_ctrls = make_array(cl_pool, 0, sizeof(pr_ctrls_t *));
163
164 cl_list->cl_next = NULL;
165 cl_list->cl_prev = NULL;
166
167 cl_listlen = 1;
168
169 } else {
170 pr_ctrls_cl_t *cl = NULL;
171
172 /* Add another victim to the list */
173 cl_pool = make_sub_pool(ctrls_pool);
174 pr_pool_tag(cl_pool, "Controls client pool");
175
176 cl = (pr_ctrls_cl_t *) pcalloc(cl_pool, sizeof(pr_ctrls_cl_t));
177
178 cl->cl_pool = cl_pool;
179 cl->cl_fd = -1;
180 cl->cl_uid = 0;
181 cl->cl_user = NULL;
182 cl->cl_gid = 0;
183 cl->cl_group = NULL;
184 cl->cl_pid = 0;
185 cl->cl_ctrls = make_array(cl->cl_pool, 0, sizeof(pr_ctrls_t *));
186
187 cl->cl_next = cl_list;
188 cl->cl_prev = NULL;
189
190 cl_list->cl_prev = cl;
191 cl_list = cl;
192
193 cl_listlen++;
194 }
195
196 return cl_list;
197 }
198
199 /* Add a new client to the set */
200 static pr_ctrls_cl_t *ctrls_add_cl(int cl_fd, uid_t cl_uid, gid_t cl_gid,
201 pid_t cl_pid, unsigned long cl_flags) {
202 pr_ctrls_cl_t *cl = NULL;
203
204 /* Make sure there's an empty entry available */
205 cl = ctrls_new_cl();
206
207 cl->cl_fd = cl_fd;
208 cl->cl_uid = cl_uid;
209 cl->cl_user = pr_auth_uid2name(cl->cl_pool, cl->cl_uid);
210 cl->cl_gid = cl_gid;
211 cl->cl_group = pr_auth_gid2name(cl->cl_pool, cl->cl_gid);
212 cl->cl_pid = cl_pid;
213 cl->cl_flags = cl_flags;
214
215 pr_ctrls_log(MOD_CTRLS_VERSION,
216 "accepted connection from %s/%s client", cl->cl_user, cl->cl_group);
217
218 return cl;
219 }
220
221 /* Remove a client from the set */
222 static void ctrls_del_cl(pr_ctrls_cl_t *cl) {
223
224 /* Remove this ctr_cl_t from the list, and free it */
225 if (cl->cl_next) {
226 cl->cl_next->cl_prev = cl->cl_prev;
227 }
228
229 if (cl->cl_prev) {
230 cl->cl_prev->cl_next = cl->cl_next;
231
232 } else {
233 cl_list = cl->cl_next;
234 }
235
236 (void) close(cl->cl_fd);
237 cl->cl_fd = -1;
238
239 destroy_pool(cl->cl_pool);
240 cl_listlen--;
241 }
242
243 /* Controls socket routines
244 */
245
246 /* Iterate through any readable descriptors, reading each into appropriate
247 * client objects
248 */
249 static void ctrls_cls_read(void) {
250 pr_ctrls_cl_t *cl;
251
252 cl = cl_list;
253 while (cl != NULL) {
254 int res, xerrno;
255
256 pr_signals_handle();
257
258 res = pr_ctrls_recv_request(cl);
259 xerrno = errno;
260
261 if (res < 0) {
262 switch (xerrno) {
263 case EOF:
264 break;
265
266 case EINVAL:
267 /* Unsupported action requested */
268 if (cl->cl_flags == 0) {
269 cl->cl_flags = PR_CTRLS_CL_NOACTION;
270 }
271
272 pr_ctrls_log(MOD_CTRLS_VERSION,
273 "recvd from %s/%s client: (invalid action)", cl->cl_user,
274 cl->cl_group);
275 break;
276
277 case EAGAIN:
278 #if defined(EAGAIN) && \
279 defined(EWOULDBLOCK) && \
280 EWOULDBLOCK != EAGAIN
281 case EWOULDBLOCK:
282 #endif
283 /* Malicious/blocked client */
284 if (cl->cl_flags == 0) {
285 cl->cl_flags = PR_CTRLS_CL_BLOCKED;
286 }
287 break;
288
289 default:
290 pr_ctrls_log(MOD_CTRLS_VERSION,
291 "error: unable to receive client request: %s", strerror(errno));
292 break;
293 }
294
295 } else {
296 pr_ctrls_t *ctrl;
297 char *request;
298
299 ctrl = *((pr_ctrls_t **) cl->cl_ctrls->elts);
300 request = (char *) ctrl->ctrls_action;
301
302 /* Request successfully read. Flag this client as being in such a
303 * state.
304 */
305 if (cl->cl_flags == 0) {
306 cl->cl_flags = PR_CTRLS_CL_HAVEREQ;
307 }
308
309 if (ctrl->ctrls_cb_args != NULL) {
310 unsigned int reqargc;
311 char **reqargv;
312
313 /* Reconstruct the original request string from the client for
314 * logging.
315 */
316
317 reqargc = ctrl->ctrls_cb_args->nelts;
318 reqargv = ctrl->ctrls_cb_args->elts;
319
320 while (reqargc--) {
321 request = pstrcat(cl->cl_pool, request, " ", *reqargv++, NULL);
322 }
323
324 pr_ctrls_log(MOD_CTRLS_VERSION,
325 "recvd from %s/%s client: '%s'", cl->cl_user, cl->cl_group,
326 request);
327 }
328 }
329
330 cl = cl->cl_next;
331 }
332 }
333
334 /* Iterate through any writable descriptors, writing out the responses to the
335 * appropriate client objects
336 */
337 static int ctrls_cls_write(void) {
338 pr_ctrls_cl_t *cl;
339
340 cl = cl_list;
341 while (cl != NULL) {
342 pr_ctrls_cl_t *tmp_cl;
343
344 /* Necessary to keep track of the next client in the list while
345 * the list is being modified.
346 */
347 tmp_cl = cl->cl_next;
348
349 pr_signals_handle();
350
351 /* This client has something to hear */
352 if (cl->cl_flags == PR_CTRLS_CL_NOACCESS) {
353 char *msg = "access denied";
354
355 /* ACL-denied access */
356 if (pr_ctrls_send_response(ctrls_pool, cl->cl_fd,
357 PR_CTRLS_STATUS_ACCESS_DENIED, 1, &msg) < 0) {
358 pr_ctrls_log(MOD_CTRLS_VERSION,
359 "error: unable to send response to %s/%s client: %s",
360 cl->cl_user, cl->cl_group, strerror(errno));
361
362 } else {
363 pr_ctrls_log(MOD_CTRLS_VERSION, "sent to %s/%s client: '%s'",
364 cl->cl_user, cl->cl_group, msg);
365 }
366
367 } else if (cl->cl_flags == PR_CTRLS_CL_NOACTION) {
368 char *msg = "unsupported action requested";
369
370 /* Unsupported action -- no matching controls */
371 if (pr_ctrls_send_response(ctrls_pool, cl->cl_fd,
372 PR_CTRLS_STATUS_UNSUPPORTED_OPERATION, 1, &msg) < 0) {
373 pr_ctrls_log(MOD_CTRLS_VERSION,
374 "error: unable to send response to %s/%s client: %s",
375 cl->cl_user, cl->cl_group, strerror(errno));
376
377 } else {
378 pr_ctrls_log(MOD_CTRLS_VERSION, "sent to %s/%s client: '%s'",
379 cl->cl_user, cl->cl_group, msg);
380 }
381
382 } else if (cl->cl_flags == PR_CTRLS_CL_BLOCKED) {
383 char *msg = "blocked connection";
384
385 if (pr_ctrls_send_response(ctrls_pool, cl->cl_fd,
386 PR_CTRLS_STATUS_INTERNAL_ERROR, 1, &msg) < 0) {
387 pr_ctrls_log(MOD_CTRLS_VERSION,
388 "error: unable to send response to %s/%s client: %s",
389 cl->cl_user, cl->cl_group, strerror(errno));
390
391 } else {
392 pr_ctrls_log(MOD_CTRLS_VERSION, "sent to %s/%s client: '%s'",
393 cl->cl_user, cl->cl_group, msg);
394 }
395
396 } else if (cl->cl_flags == PR_CTRLS_CL_HAVEREQ) {
397 if (cl->cl_ctrls != NULL &&
398 cl->cl_ctrls->nelts > 0) {
399 register unsigned int i = 0;
400 pr_ctrls_t **ctrlv = NULL;
401
402 ctrlv = (pr_ctrls_t **) cl->cl_ctrls->elts;
403
404 for (i = 0; i < cl->cl_ctrls->nelts; i++) {
405 if ((ctrlv[i])->ctrls_cb_retval < 1) {
406
407 /* Make sure the callback(s) added responses */
408 if ((ctrlv[i])->ctrls_cb_resps != NULL) {
409 if (pr_ctrls_send_response(ctrls_pool, cl->cl_fd,
410 (ctrlv[i])->ctrls_cb_retval,
411 (ctrlv[i])->ctrls_cb_resps->nelts,
412 (char **) (ctrlv[i])->ctrls_cb_resps->elts) < 0) {
413 pr_ctrls_log(MOD_CTRLS_VERSION,
414 "error: unable to send response to %s/%s "
415 "client: %s", cl->cl_user, cl->cl_group, strerror(errno));
416
417 } else {
418 /* For logging/accounting purposes */
419 register unsigned int j = 0;
420 int respval = (ctrlv[i])->ctrls_cb_retval;
421 unsigned int respargc = (ctrlv[i])->ctrls_cb_resps->nelts;
422 char **respargv = (ctrlv[i])->ctrls_cb_resps->elts;
423
424 pr_ctrls_log(MOD_CTRLS_VERSION,
425 "sent to %s/%s client: return value: %d",
426 cl->cl_user, cl->cl_group, respval);
427
428 for (j = 0; j < respargc; j++) {
429 pr_ctrls_log(MOD_CTRLS_VERSION,
430 "sent to %s/%s client: '%s'", cl->cl_user, cl->cl_group,
431 respargv[j]);
432 }
433 }
434
435 } else {
436 /* No responses added by callbacks */
437 pr_ctrls_log(MOD_CTRLS_VERSION,
438 "notice: no responses given for %s/%s client: "
439 "check controls handlers", cl->cl_user, cl->cl_group);
440 }
441 }
442 }
443 }
444 }
445
446 pr_ctrls_log(MOD_CTRLS_VERSION,
447 "closed connection to %s/%s client", cl->cl_user, cl->cl_group);
448
449 /* Remove the client from the list */
450 ctrls_del_cl(cl);
451 cl = tmp_cl;
452 }
453
454 return 0;
455 }
456
457 /* Create a listening local socket */
458 static int ctrls_listen(const char *sock_file) {
459 int sockfd = -1, len = 0;
460 struct sockaddr_un sock;
461 #if !defined(SO_PEERCRED) && !defined(HAVE_GETPEEREID) && \
462 !defined(HAVE_GETPEERUCRED) && defined(LOCAL_CREDS)
463 int opt = 1;
464 socklen_t optlen = sizeof(opt);
465 #endif /* !LOCAL_CREDS */
466
467 /* No interruptions */
468 pr_signals_block();
469
470 /* Create the Unix domain socket */
471 sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
472 if (sockfd < 0) {
473 int xerrno = errno;
474
475 pr_signals_unblock();
476 pr_log_pri(PR_LOG_NOTICE, MOD_CTRLS_VERSION
477 ": error: unable to create local socket: %s", strerror(xerrno));
478
479 errno = xerrno;
480 return -1;
481 }
482
483 /* Ensure that the socket used is not one of the major three fds (stdin,
484 * stdout, or stderr).
485 */
486 if (sockfd <= STDERR_FILENO) {
487 int res;
488
489 res = pr_fs_get_usable_fd(sockfd);
490 if (res < 0) {
491 int xerrno = errno;
492
493 pr_signals_unblock();
494 pr_log_pri(PR_LOG_NOTICE, MOD_CTRLS_VERSION
495 ": error duplicating ctrls socket: %s", strerror(xerrno));
496 (void) close(sockfd);
497
498 errno = xerrno;
499 return -1;
500 }
501
502 (void) close(sockfd);
503 sockfd = res;
504 }
505
506 if (fcntl(sockfd, F_SETFD, FD_CLOEXEC) < 0) {
507 int xerrno = errno;
508
509 pr_signals_unblock();
510 pr_log_pri(PR_LOG_WARNING,
511 "unable to set CLO_EXEC on ctrls socket fd %d: %s", sockfd,
512 strerror(xerrno));
513
514 (void) close(sockfd);
515 errno = xerrno;
516 return -1;
517 }
518
519 /* Make sure the path to which we want to bind this socket doesn't already
520 * exist.
521 */
522 (void) unlink(sock_file);
523
524 /* Fill in the socket structure fields */
525 memset(&sock, 0, sizeof(sock));
526
527 sock.sun_family = AF_UNIX;
528 sstrncpy(sock.sun_path, sock_file, sizeof(sock.sun_path));
529
530 len = sizeof(sock);
531
532 /* Bind the name to the descriptor */
533 pr_trace_msg(trace_channel, 1, "binding ctrls socket fd %d to path '%s'",
534 sockfd, sock.sun_path);
535 if (bind(sockfd, (struct sockaddr *) &sock, len) < 0) {
536 int xerrno = errno;
537
538 pr_signals_unblock();
539 (void) close(sockfd);
540
541 errno = xerrno;
542 pr_log_pri(PR_LOG_NOTICE, MOD_CTRLS_VERSION
543 ": error: unable to bind to local socket: %s", strerror(xerrno));
544 pr_trace_msg(trace_channel, 1, "unable to bind to local socket: %s",
545 strerror(xerrno));
546
547 errno = xerrno;
548 return -1;
549 }
550
551 /* Start listening to the socket */
552 if (listen(sockfd, 5) < 0) {
553 int xerrno = errno;
554
555 pr_signals_unblock();
556 (void) close(sockfd);
557
558 errno = xerrno;
559 pr_log_pri(PR_LOG_NOTICE, MOD_CTRLS_VERSION
560 ": error: unable to listen on local socket '%s': %s", sock.sun_path,
561 strerror(xerrno));
562 pr_trace_msg(trace_channel, 1, "unable to listen on local socket '%s': %s",
563 sock.sun_path, strerror(xerrno));
564
565 errno = xerrno;
566 return -1;
567 }
568
569 #if !defined(SO_PEERCRED) && !defined(HAVE_GETPEEREID) && \
570 !defined(HAVE_GETPEERUCRED) && defined(LOCAL_CREDS)
571 /* Set the LOCAL_CREDS socket option. */
572 if (setsockopt(sockfd, 0, LOCAL_CREDS, &opt, optlen) < 0) {
573 pr_log_debug(DEBUG0, MOD_CTRLS_VERSION ": error enabling LOCAL_CREDS: %s",
574 strerror(errno));
575 }
576 #endif /* !LOCAL_CREDS */
577
578 /* Change the permissions on the socket, so that users can connect */
579 if (chmod(sock.sun_path, (mode_t) PR_CTRLS_MODE) < 0) {
580 int xerrno = errno;
581
582 pr_signals_unblock();
583 (void) close(sockfd);
584
585 errno = xerrno;
586 pr_log_pri(PR_LOG_NOTICE, MOD_CTRLS_VERSION
587 ": error: unable to chmod local socket: %s", strerror(xerrno));
588 pr_trace_msg(trace_channel, 1, "unable to chmod local socket: %s",
589 strerror(xerrno));
590
591 errno = xerrno;
592 return -1;
593 }
594
595 pr_signals_unblock();
596 return sockfd;
597 }
598
599 static int ctrls_recv_cl_reqs(void) {
600 fd_set cl_rset;
601 struct timeval timeout;
602 uid_t cl_uid;
603 gid_t cl_gid;
604 pid_t cl_pid;
605 unsigned long cl_flags = 0;
606 int cl_fd, max_fd;
607
608 timeout.tv_usec = 500L;
609 timeout.tv_sec = 0L;
610
611 /* look for any pending client connections */
612 while (cl_listlen < cl_maxlistlen) {
613 int res = 0, xerrno;
614
615 pr_signals_handle();
616
617 if (ctrls_sockfd < 0) {
618 break;
619 }
620
621 FD_ZERO(&cl_rset);
622 FD_SET(ctrls_sockfd, &cl_rset);
623 max_fd = ctrls_sockfd + 1;
624
625 res = select(max_fd + 1, &cl_rset, NULL, NULL, &timeout);
626 xerrno = errno;
627
628 if (res == 0) {
629 /* Go through the client list */
630 ctrls_cls_read();
631
632 return 0;
633 }
634
635 if (res < 0) {
636 if (xerrno == EINTR) {
637 pr_signals_handle();
638 continue;
639 }
640
641 pr_ctrls_log(MOD_CTRLS_VERSION,
642 "error: unable to select on local socket: %s", strerror(xerrno));
643
644 errno = xerrno;
645 return res;
646 }
647
648 if (FD_ISSET(ctrls_sockfd, &cl_rset)) {
649 /* Make sure the ctrl socket is non-blocking */
650 if (ctrls_setnonblock(ctrls_sockfd) < 0) {
651 xerrno = errno;
652
653 pr_ctrls_log(MOD_CTRLS_VERSION,
654 "error: unable to set nonblocking on local socket: %s",
655 strerror(xerrno));
656
657 errno = xerrno;
658 return -1;
659 }
660
661 /* Accept pending connections */
662 cl_fd = pr_ctrls_accept(ctrls_sockfd, &cl_uid, &cl_gid, &cl_pid,
663 ctrls_cl_freshness);
664 xerrno = errno;
665
666 if (cl_fd < 0) {
667 if (xerrno != ETIMEDOUT) {
668 pr_ctrls_log(MOD_CTRLS_VERSION,
669 "error: unable to accept connection: %s", strerror(xerrno));
670 }
671
672 continue;
673 }
674
675 /* Restore blocking mode to the ctrl socket */
676 if (ctrls_setblock(ctrls_sockfd) < 0) {
677 pr_ctrls_log(MOD_CTRLS_VERSION,
678 "error: unable to set blocking on local socket: %s",
679 strerror(errno));
680 }
681
682 /* Set this socket as non-blocking */
683 if (ctrls_setnonblock(cl_fd) < 0) {
684 pr_ctrls_log(MOD_CTRLS_VERSION,
685 "error: unable to set nonblocking on client socket: %s",
686 strerror(errno));
687 (void) close(cl_fd);
688 continue;
689 }
690
691 if (pr_ctrls_check_user_acl(cl_uid, &ctrls_sock_acl.acl_users) != TRUE &&
692 pr_ctrls_check_group_acl(cl_gid, &ctrls_sock_acl.acl_groups) != TRUE) {
693 cl_flags = PR_CTRLS_CL_NOACCESS;
694 }
695
696 /* Add the client to the list */
697 ctrls_add_cl(cl_fd, cl_uid, cl_gid, cl_pid, cl_flags);
698 }
699 }
700
701 /* Go through the client list */
702 ctrls_cls_read();
703
704 return 0;
705 }
706
707 static int ctrls_send_cl_resps(void) {
708
709 /* Go through the client list */
710 ctrls_cls_write();
711
712 return 0;
713 }
714
715 static int ctrls_setblock(int sockfd) {
716 int flags = 0;
717 int res = -1;
718
719 /* default error */
720 errno = EBADF;
721
722 flags = fcntl(sockfd, F_GETFL);
723 res = fcntl(sockfd, F_SETFL, flags & (U32BITS ^ O_NONBLOCK));
724
725 return res;
726 }
727
728 static int ctrls_setnonblock(int sockfd) {
729 int flags = 0;
730 int res = -1;
731
732 /* default error */
733 errno = EBADF;
734
735 flags = fcntl(sockfd, F_GETFL);
736 res = fcntl(sockfd, F_SETFL, flags | O_NONBLOCK);
737
738 return res;
739 }
740
741 static int ctrls_timer_cb(CALLBACK_FRAME) {
742 static unsigned char first_time = TRUE;
743
744 /* If the ControlsEngine is not to run, do nothing from here on out */
745 if (ctrls_engine == FALSE) {
746 (void) close(ctrls_sockfd);
747 ctrls_sockfd = -1;
748
749 if (is_master) {
750 /* Remove the local socket path as well */
751 (void) unlink(ctrls_sock_file);
752 }
753
754 return 0;
755 }
756
757 if (first_time == TRUE) {
758 /* Change the ownership on the socket to that configured by the admin */
759 PRIVS_ROOT
760 if (chown(ctrls_sock_file, ctrls_sock_uid, ctrls_sock_gid) < 0) {
761 pr_log_pri(PR_LOG_NOTICE, MOD_CTRLS_VERSION
762 ": unable to chown local socket %s: %s", ctrls_sock_file,
763 strerror(errno));
764 }
765 PRIVS_RELINQUISH
766
767 first_time = FALSE;
768 }
769
770 /* Please no alarms while doing this. */
771 pr_alarms_block();
772
773 /* Process pending requests. */
774 ctrls_recv_cl_reqs();
775
776 /* Run through the controls */
777 pr_run_ctrls(NULL, NULL);
778
779 /* Process pending responses */
780 ctrls_send_cl_resps();
781
782 /* Reset controls */
783 pr_ctrls_reset();
784
785 pr_alarms_unblock();
786 return 1;
787 }
788
789 /* Controls handlers
790 */
791
792 static int respcmp(const void *a, const void *b) {
793 return strcmp(*((char **) a), *((char **) b));
794 }
795
796 static int ctrls_handle_help(pr_ctrls_t *ctrl, int reqargc,
797 char **reqargv) {
798
799 /* Run through the list of registered controls, and add them to the
800 * response, including the module in which they appear.
801 */
802
803 if (reqargc != 0) {
804 pr_ctrls_add_response(ctrl, "wrong number of parameters");
805 return PR_CTRLS_STATUS_WRONG_PARAMETERS;
806 }
807
808 if (pr_get_registered_actions(ctrl, CTRLS_GET_DESC) < 0) {
809 pr_ctrls_add_response(ctrl, "unable to get actions: %s", strerror(errno));
810 return PR_CTRLS_STATUS_INTERNAL_ERROR;
811 }
812
813 /* Be nice, and sort the directives lexicographically */
814 qsort(ctrl->ctrls_cb_resps->elts, ctrl->ctrls_cb_resps->nelts,
815 sizeof(char *), respcmp);
816
817 return PR_CTRLS_STATUS_OK;
818 }
819
820 static int ctrls_handle_insctrl(pr_ctrls_t *ctrl, int reqargc,
821 char **reqargv) {
822 module *m = ANY_MODULE;
823 int res, xerrno;
824
825 /* Enable a control into the registered controls list. This requires the
826 * action and, optionally, the module of the control to be enabled.
827 */
828
829 /* Check the insctrl ACL */
830 if (pr_ctrls_check_acl(ctrl, ctrls_acttab, "insctrl") != TRUE) {
831
832 /* Access denied */
833 pr_ctrls_add_response(ctrl, "access denied");
834 return PR_CTRLS_STATUS_ACCESS_DENIED;
835 }
836
837 if (reqargc < 1 ||
838 reqargc > 2) {
839 pr_ctrls_add_response(ctrl, "wrong number of parameters");
840 return PR_CTRLS_STATUS_WRONG_PARAMETERS;
841 }
842
843 /* If the optional second parameter, a module name, is used, lookup
844 * the module pointer matching the name.
845 */
846 if (reqargc == 2) {
847 m = pr_module_get(reqargv[1]);
848 }
849
850 res = pr_set_registered_actions(m, reqargv[0], FALSE, 0);
851 xerrno = errno;
852
853 if (res < 0) {
854 if (xerrno == ENOENT) {
855 pr_ctrls_add_response(ctrl, "no such control: '%s'", reqargv[0]);
856 return PR_CTRLS_STATUS_SUBJECT_NOT_FOUND;
857 }
858
859 pr_ctrls_add_response(ctrl, "unable to enable '%s': %s", reqargv[0],
860 strerror(errno));
861 return PR_CTRLS_STATUS_INTERNAL_ERROR;
862 }
863
864 pr_ctrls_add_response(ctrl, "'%s' control enabled", reqargv[0]);
865 return PR_CTRLS_STATUS_OK;
866 }
867
868 static int ctrls_handle_lsctrl(pr_ctrls_t *ctrl, int reqargc,
869 char **reqargv) {
870
871 /* Run through the list of registered controls, and add them to the
872 * response, including the module in which they appear.
873 */
874
875 /* Check the lsctrl ACL */
876 if (pr_ctrls_check_acl(ctrl, ctrls_acttab, "lsctrl") != TRUE) {
877
878 /* Access denied */
879 pr_ctrls_add_response(ctrl, "access denied");
880 return PR_CTRLS_STATUS_ACCESS_DENIED;
881 }
882
883 if (reqargc != 0) {
884 pr_ctrls_add_response(ctrl, "wrong number of parameters");
885 return PR_CTRLS_STATUS_WRONG_PARAMETERS;
886 }
887
888 if (pr_get_registered_actions(ctrl, CTRLS_GET_ACTION_ENABLED) < 0) {
889 pr_ctrls_add_response(ctrl, "unable to get actions: %s", strerror(errno));
890 return PR_CTRLS_STATUS_INTERNAL_ERROR;
891 }
892
893 /* Be nice, and sort the actions lexicographically */
894 qsort(ctrl->ctrls_cb_resps->elts, ctrl->ctrls_cb_resps->nelts,
895 sizeof(char *), respcmp);
896
897 return PR_CTRLS_STATUS_OK;
898 }
899
900 static int ctrls_handle_rmctrl(pr_ctrls_t *ctrl, int reqargc,
901 char **reqargv) {
902 module *m = ANY_MODULE;
903 int res, xerrno;
904
905 /* Disable a control from the registered controls list. This requires the
906 * action and, optionally, the module of the control to be removed.
907 */
908
909 /* Check the rmctrl ACL */
910 if (pr_ctrls_check_acl(ctrl, ctrls_acttab, "rmctrl") != TRUE) {
911
912 /* Access denied */
913 pr_ctrls_add_response(ctrl, "access denied");
914 return PR_CTRLS_STATUS_ACCESS_DENIED;
915 }
916
917 if (reqargc < 1 ||
918 reqargc > 2) {
919 pr_ctrls_add_response(ctrl, "wrong number of parameters");
920 return PR_CTRLS_STATUS_WRONG_PARAMETERS;
921 }
922
923 /* The three controls added by this module _cannot_ be removed (at least
924 * not via this control handler).
925 */
926 if (strcmp(reqargv[0], "insctrl") == 0 ||
927 strcmp(reqargv[0], "lsctrl") == 0 ||
928 strcmp(reqargv[0], "rmctrl") == 0) {
929 pr_ctrls_add_response(ctrl, "'%s' control cannot be removed", reqargv[0]);
930 return PR_CTRLS_STATUS_OPERATION_DENIED;
931 }
932
933 /* If the optional second parameter, a module name, is used, lookup
934 * the module pointer matching the name.
935 */
936 if (reqargc == 2) {
937 m = pr_module_get(reqargv[1]);
938 }
939
940 res = pr_set_registered_actions(m, reqargv[0], FALSE, PR_CTRLS_ACT_DISABLED);
941 xerrno = errno;
942
943 if (res < 0) {
944 if (xerrno == ENOENT) {
945 pr_ctrls_add_response(ctrl, "no such control: '%s'", reqargv[0]);
946 return PR_CTRLS_STATUS_SUBJECT_NOT_FOUND;
947 }
948
949 pr_ctrls_add_response(ctrl, "unable to disable '%s': %s", reqargv[0],
950 strerror(xerrno));
951 return PR_CTRLS_STATUS_INTERNAL_ERROR;
952 }
953
954 if (strcmp(reqargv[0], "all") != 0) {
955 pr_ctrls_add_response(ctrl, "'%s' control disabled", reqargv[0]);
956
957 } else {
958 /* If all actions have been disabled, stop listening on the local
959 * socket, and turn off this module's engine.
960 */
961 pr_ctrls_add_response(ctrl, "all controls disabled");
962 pr_ctrls_add_response(ctrl, "restart the daemon to re-enable controls");
963
964 (void) close(ctrls_sockfd);
965 ctrls_sockfd = -1;
966
967 ctrls_engine = FALSE;
968 }
969
970 return PR_CTRLS_STATUS_OK;
971 }
972
973 /* Configuration handlers
974 */
975
976 /* Default behavior is to deny everyone unless an ACL has been configured */
977 MODRET set_ctrlsacls(cmd_rec *cmd) {
978 int res;
979 char **actions = NULL;
980 const char *bad_action = NULL;
981
982 CHECK_ARGS(cmd, 4);
983 CHECK_CONF(cmd, CONF_ROOT);
984
985 /* Parse the given string of actions into a char **. Then iterate
986 * through the acttab, checking to see if a given control is _not_ in
987 * the list. If not in the list, unregister that control.
988 */
989
990 actions = pr_ctrls_parse_acl(cmd->tmp_pool, cmd->argv[1]);
991
992 /* Check the second parameter to make sure it is "allow" or "deny" */
993 if (strcmp(cmd->argv[2], "allow") != 0 &&
994 strcmp(cmd->argv[2], "deny") != 0) {
995 CONF_ERROR(cmd, "second parameter must be 'allow' or 'deny'");
996 }
997
998 /* Check the third parameter to make sure it is "user" or "group" */
999 if (strcmp(cmd->argv[3], "user") != 0 &&
1000 strcmp(cmd->argv[3], "group") != 0) {
1001 CONF_ERROR(cmd, "third parameter must be 'user' or 'group'");
1002 }
1003
1004 res = pr_ctrls_set_module_acls2(ctrls_acttab, ctrls_pool, actions,
1005 cmd->argv[2], cmd->argv[3], cmd->argv[4], &bad_action);
1006 if (res < 0) {
1007 CONF_ERROR(cmd, pstrcat(cmd->tmp_pool, ": unknown action: '",
1008 bad_action, "'", NULL));
1009 }
1010
1011 return PR_HANDLED(cmd);
1012 }
1013
1014 /* default: 10 secs */
1015 MODRET set_ctrlsauthfreshness(cmd_rec *cmd) {
1016 int freshness = 0;
1017
1018 CHECK_ARGS(cmd, 1);
1019 CHECK_CONF(cmd, CONF_ROOT);
1020
1021 freshness = atoi(cmd->argv[1]);
1022 if (freshness <= 0) {
1023 CONF_ERROR(cmd, "must be a positive number");
1024 }
1025
1026 ctrls_cl_freshness = freshness;
1027 return PR_HANDLED(cmd);
1028 }
1029
1030 MODRET set_ctrlsengine(cmd_rec *cmd) {
1031 int engine = -1;
1032
1033 CHECK_ARGS(cmd, 1);
1034 CHECK_CONF(cmd, CONF_ROOT);
1035
1036 engine = get_boolean(cmd, 1);
1037 if (engine == -1) {
1038 CONF_ERROR(cmd, "expected Boolean parameter");
1039 }
1040
1041 ctrls_engine = engine;
1042 return PR_HANDLED(cmd);
1043 }
1044
1045 /* default: 10 secs */
1046 MODRET set_ctrlsinterval(cmd_rec *cmd) {
1047 int nsecs = 0;
1048
1049 CHECK_ARGS(cmd, 1);
1050 CHECK_CONF(cmd, CONF_ROOT);
1051
1052 nsecs = atoi(cmd->argv[1]);
1053 if (nsecs <= 0) {
1054 CONF_ERROR(cmd, "must be a positive number");
1055 }
1056
1057 /* Remove the existing timer, and re-install it with this new interval. */
1058 ctrls_interval = nsecs;
1059
1060 pr_timer_remove(CTRLS_TIMER_ID, &ctrls_module);
1061 pr_timer_add(ctrls_interval, CTRLS_TIMER_ID, &ctrls_module, ctrls_timer_cb,
1062 "Controls polling");
1063
1064 return PR_HANDLED(cmd);
1065 }
1066
1067 MODRET set_ctrlslog(cmd_rec *cmd) {
1068 int res = 0;
1069
1070 CHECK_ARGS(cmd, 1);
1071 CHECK_CONF(cmd, CONF_ROOT);
1072
1073 ctrls_logname = pstrdup(ctrls_pool, cmd->argv[1]);
1074
1075 res = ctrls_openlog();
1076 if (res < 0) {
1077 if (res == -1) {
1078 CONF_ERROR(cmd, pstrcat(cmd->tmp_pool, "unable to open '",
1079 (char *) cmd->argv[1], "': ", strerror(errno), NULL));
1080 }
1081
1082 if (res == -2) {
1083 CONF_ERROR(cmd, pstrcat(cmd->tmp_pool,
1084 "unable to log to a world-writable directory", NULL));
1085 }
1086 }
1087
1088 return PR_HANDLED(cmd);
1089 }
1090
1091 /* Default: 5 max clients */
1092 MODRET set_ctrlsmaxclients(cmd_rec *cmd) {
1093 int nclients = 0;
1094
1095 CHECK_ARGS(cmd, 1);
1096 CHECK_CONF(cmd, CONF_ROOT);
1097
1098 nclients = atoi(cmd->argv[1]);
1099 if (nclients <= 0) {
1100 CONF_ERROR(cmd, "must be a positive number");
1101 }
1102
1103 cl_maxlistlen = nclients;
1104 return PR_HANDLED(cmd);
1105 }
1106
1107 /* Default: var/run/proftpd.sock */
1108 MODRET set_ctrlssocket(cmd_rec *cmd) {
1109 char *path;
1110
1111 CHECK_ARGS(cmd, 1);
1112 CHECK_CONF(cmd, CONF_ROOT);
1113
1114 path = cmd->argv[1];
1115 if (*path != '/') {
1116 CONF_ERROR(cmd, "must be an absolute path");
1117 }
1118
1119 /* Close the socket. */
1120 if (ctrls_sockfd >= 0) {
1121 pr_trace_msg(trace_channel, 3, "closing ctrls socket '%s' (fd %d)",
1122 ctrls_sock_file, ctrls_sockfd);
1123 (void) unlink(ctrls_sock_file);
1124 (void) close(ctrls_sockfd);
1125 ctrls_sockfd = -1;
1126 }
1127
1128 /* Change the path. */
1129 if (strcmp(path, ctrls_sock_file) != 0) {
1130 ctrls_sock_file = pstrdup(ctrls_pool, path);
1131 }
1132
1133 return PR_HANDLED(cmd);
1134 }
1135
1136 /* Default behavior is to deny everyone unless an ACL has been configured */
1137 MODRET set_ctrlssocketacl(cmd_rec *cmd) {
1138 CHECK_ARGS(cmd, 3);
1139 CHECK_CONF(cmd, CONF_ROOT);
1140
1141 pr_ctrls_init_acl(&ctrls_sock_acl);
1142
1143 /* Check the first argument to make sure it either "allow" or "deny" */
1144 if (strcasecmp(cmd->argv[1], "allow") != 0 &&
1145 strcasecmp(cmd->argv[1], "deny") != 0) {
1146 CONF_ERROR(cmd, "first parameter must be either 'allow' or 'deny'");
1147 }
1148
1149 /* Check the second argument to see how to handle the directive */
1150 if (strcasecmp(cmd->argv[2], "user") == 0) {
1151 if (pr_ctrls_set_user_acl(ctrls_pool, &ctrls_sock_acl.acl_users,
1152 cmd->argv[1], cmd->argv[3]) < 0) {
1153 CONF_ERROR(cmd, pstrcat(cmd->tmp_pool,
1154 "error configuring user socket ACL: ", strerror(errno), NULL));
1155 }
1156
1157 } else if (strcasecmp(cmd->argv[2], "group") == 0) {
1158 if (pr_ctrls_set_group_acl(ctrls_pool, &ctrls_sock_acl.acl_groups,
1159 cmd->argv[1], cmd->argv[3]) < 0) {
1160 CONF_ERROR(cmd, pstrcat(cmd->tmp_pool,
1161 "error configuring group socket ACL: ", strerror(errno), NULL));
1162 }
1163
1164 } else {
1165 CONF_ERROR(cmd, "second parameter must be either 'user' or 'group'");
1166 }
1167
1168 return PR_HANDLED(cmd);
1169 }
1170
1171 /* Default: root root */
1172 MODRET set_ctrlssocketowner(cmd_rec *cmd) {
1173 gid_t gid = 0;
1174 uid_t uid = 0;
1175
1176 CHECK_ARGS(cmd, 2);
1177 CHECK_CONF(cmd, CONF_ROOT);
1178
1179 uid = pr_auth_name2uid(cmd->tmp_pool, cmd->argv[1]);
1180 if (uid == (uid_t) -1) {
1181 if (errno != EINVAL) {
1182 pr_log_debug(DEBUG0, "%s: %s has UID of -1", (char *) cmd->argv[0],
1183 (char *) cmd->argv[1]);
1184
1185 } else {
1186 pr_log_debug(DEBUG0, "%s: no such user '%s'", (char *) cmd->argv[0],
1187 (char *) cmd->argv[1]);
1188 }
1189
1190 } else {
1191 ctrls_sock_uid = uid;
1192 }
1193
1194 gid = pr_auth_name2gid(cmd->tmp_pool, cmd->argv[2]);
1195 if (gid == (gid_t) -1) {
1196 if (errno != EINVAL) {
1197 pr_log_debug(DEBUG0, "%s: %s has GID of -1", (char *) cmd->argv[0],
1198 (char *) cmd->argv[2]);
1199
1200 } else {
1201 pr_log_debug(DEBUG0, "%s: no such group '%s'", (char *) cmd->argv[0],
1202 (char *) cmd->argv[2]);
1203 }
1204
1205 } else {
1206 ctrls_sock_gid = gid;
1207 }
1208
1209 return PR_HANDLED(cmd);
1210 }
1211
1212 /* Event handlers
1213 */
1214
1215 static void ctrls_shutdown_ev(const void *event_data, void *user_data) {
1216 if (!is_master || !ctrls_engine)
1217 return;
1218
1219 /* Close any connected clients */
1220 if (cl_list != NULL) {
1221 pr_ctrls_cl_t *cl = NULL;
1222
1223 for (cl = cl_list; cl; cl = cl->cl_next) {
1224 if (cl->cl_fd >= 0) {
1225 (void) close(cl->cl_fd);
1226 cl->cl_fd = -1;
1227 }
1228 }
1229 }
1230
1231 (void) close(ctrls_sockfd);
1232 ctrls_sockfd = -1;
1233
1234 /* Remove the local socket path as well */
1235 (void) unlink(ctrls_sock_file);
1236 return;
1237 }
1238
1239 static void ctrls_postparse_ev(const void *event_data, void *user_data) {
1240 if (ctrls_engine == FALSE ||
1241 ServerType == SERVER_INETD) {
1242 return;
1243 }
1244
1245 /* Start listening on the ctrl socket */
1246 PRIVS_ROOT
1247 ctrls_sockfd = ctrls_listen(ctrls_sock_file);
1248 PRIVS_RELINQUISH
1249
1250 /* Start a timer for the checking/processing of the ctrl socket. */
1251 pr_timer_remove(CTRLS_TIMER_ID, &ctrls_module);
1252 pr_timer_add(ctrls_interval, CTRLS_TIMER_ID, &ctrls_module, ctrls_timer_cb,
1253 "Controls polling");
1254 }
1255
1256 static void ctrls_restart_ev(const void *event_data, void *user_data) {
1257 register unsigned int i;
1258
1259 /* Block alarms while we're preparing for the restart. */
1260 pr_alarms_block();
1261
1262 /* Close any connected clients */
1263 if (cl_list != NULL) {
1264 pr_ctrls_cl_t *cl = NULL;
1265
1266 for (cl = cl_list; cl; cl = cl->cl_next) {
1267 if (cl->cl_fd >= 0) {
1268 (void) close(cl->cl_fd);
1269 cl->cl_fd = -1;
1270 }
1271 }
1272 }
1273
1274 /* Reset the client list */
1275 cl_list = NULL;
1276 cl_listlen = 0;
1277
1278 pr_trace_msg(trace_channel, 3, "closing ctrls socket '%s' (fd %d)",
1279 ctrls_sock_file, ctrls_sockfd);
1280 (void) close(ctrls_sockfd);
1281 ctrls_sockfd = -1;
1282
1283 ctrls_closelog();
1284
1285 /* Clear the existing pool */
1286 if (ctrls_pool != NULL) {
1287 destroy_pool(ctrls_pool);
1288
1289 ctrls_logname = NULL;
1290 ctrls_sock_file = MOD_CTRLS_DEFAULT_SOCK;
1291 }
1292
1293 /* Allocate the pool for this module's use */
1294 ctrls_pool = make_sub_pool(permanent_pool);
1295 pr_pool_tag(ctrls_pool, MOD_CTRLS_VERSION);
1296
1297 /* Register the control handlers */
1298 for (i = 0; ctrls_acttab[i].act_action; i++) {
1299
1300 /* Allocate and initialize the ACL for this control. */
1301 ctrls_acttab[i].act_acl = pcalloc(ctrls_pool, sizeof(ctrls_acl_t));
1302 pr_ctrls_init_acl(ctrls_acttab[i].act_acl);
1303 }
1304
1305 pr_timer_remove(CTRLS_TIMER_ID, &ctrls_module);
1306 pr_alarms_unblock();
1307 return;
1308 }
1309
1310 /* Initialization routines
1311 */
1312
1313 static int ctrls_init(void) {
1314 register unsigned int i = 0;
1315
1316 /* Allocate the pool for this module's use */
1317 ctrls_pool = make_sub_pool(permanent_pool);
1318 pr_pool_tag(ctrls_pool, MOD_CTRLS_VERSION);
1319
1320 /* Register the control handlers */
1321 for (i = 0; ctrls_acttab[i].act_action; i++) {
1322
1323 /* Allocate and initialize the ACL for this control. */
1324 ctrls_acttab[i].act_acl = pcalloc(ctrls_pool, sizeof(ctrls_acl_t));
1325 pr_ctrls_init_acl(ctrls_acttab[i].act_acl);
1326
1327 if (pr_ctrls_register(&ctrls_module, ctrls_acttab[i].act_action,
1328 ctrls_acttab[i].act_desc, ctrls_acttab[i].act_cb) < 0) {
1329 pr_log_pri(PR_LOG_NOTICE, MOD_CTRLS_VERSION
1330 ": error registering '%s' control: %s",
1331 ctrls_acttab[i].act_action, strerror(errno));
1332 }
1333 }
1334
1335 /* Make certain the socket ACL is initialized. */
1336 pr_ctrls_init_acl(&ctrls_sock_acl);
1337
1338 pr_event_register(&ctrls_module, "core.restart", ctrls_restart_ev, NULL);
1339 pr_event_register(&ctrls_module, "core.shutdown", ctrls_shutdown_ev, NULL);
1340 pr_event_register(&ctrls_module, "core.postparse", ctrls_postparse_ev, NULL);
1341
1342 return 0;
1343 }
1344
1345 static int ctrls_sess_init(void) {
1346
1347 /* Children are not to listen for or handle control requests */
1348 ctrls_engine = FALSE;
1349 pr_timer_remove(CTRLS_TIMER_ID, &ctrls_module);
1350
1351 pr_event_unregister(&ctrls_module, "core.restart", ctrls_restart_ev);
1352
1353 /* Close the inherited socket */
1354 close(ctrls_sockfd);
1355 ctrls_sockfd = -1;
1356
1357 return 0;
1358 }
1359
1360 static ctrls_acttab_t ctrls_acttab[] = {
1361 { "help", "describe all registered controls", NULL,
1362 ctrls_handle_help },
1363 { "insctrl", "enable a disabled control", NULL,
1364 ctrls_handle_insctrl },
1365 { "lsctrl", "list all registered controls", NULL,
1366 ctrls_handle_lsctrl },
1367 { "rmctrl", "disable a registered control", NULL,
1368 ctrls_handle_rmctrl },
1369 { NULL, NULL, NULL, NULL }
1370 };
1371
1372 /* Module API tables
1373 */
1374
1375 static conftable ctrls_conftab[] = {
1376 { "ControlsACLs", set_ctrlsacls, NULL },
1377 { "ControlsAuthFreshness", set_ctrlsauthfreshness, NULL },
1378 { "ControlsEngine", set_ctrlsengine, NULL },
1379 { "ControlsInterval", set_ctrlsinterval, NULL },
1380 { "ControlsLog", set_ctrlslog, NULL },
1381 { "ControlsMaxClients", set_ctrlsmaxclients, NULL },
1382 { "ControlsSocket", set_ctrlssocket, NULL },
1383 { "ControlsSocketACL", set_ctrlssocketacl, NULL },
1384 { "ControlsSocketOwner", set_ctrlssocketowner, NULL },
1385 { NULL }
1386 };
1387
1388 module ctrls_module = {
1389 NULL, NULL,
1390
1391 /* Module API version 2.0 */
1392 0x20,
1393
1394 /* Module name */
1395 "ctrls",
1396
1397 /* Module configuration handler table */
1398 ctrls_conftab,
1399
1400 /* Module command handler table */
1401 NULL,
1402
1403 /* Module authentication handler table */
1404 NULL,
1405
1406 /* Module initialization function */
1407 ctrls_init,
1408
1409 /* Session initialization function */
1410 ctrls_sess_init,
1411
1412 /* Module version */
1413 MOD_CTRLS_VERSION
1414 };